⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xulresponsewriter.java

📁 一个比较好的jsf spring hibernate的例子
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. *  * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. *  * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License").  You * may not use this file except in compliance with the License. You can obtain * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific * language governing permissions and limitations under the License. *  * When distributing the software, include this License Header Notice in each * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt. * Sun designates this particular file as subject to the "Classpath" exception * as provided by Sun in the GPL Version 2 section of the License file that * accompanied this code.  If applicable, add the following below the License * Header, with the fields enclosed by brackets [] replaced by your own * identifying information: "Portions Copyrighted [year] * [name of copyright owner]" *  * Contributor(s): *  * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license."  If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above.  However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */package renderkits.renderkit.xul;import javax.faces.FacesException;import javax.faces.component.UIComponent;import javax.faces.context.ResponseWriter;import java.io.IOException;import java.io.UnsupportedEncodingException;import java.io.Writer;import renderkits.util.Util;/** * <p><strong>XULResponseWriter</strong> is an <code>XUL</code> specific implementation * of the <code>ResponseWriter</code> abstract class. */public class XULResponseWriter extends ResponseWriter {    // Content Type for this Writer.    //    private String contentType = "application/vnd.mozilla.xul+xml";    // Character encoding of that Writer - this may be null    // if the encoding isn't known.    //    private String encoding = null;    // Writer to use for output;    //    private Writer writer = null;    // True when we need to close a start tag    //    private boolean closeStart;    // True when we shouldn't be escaping output (basically,    // inside of <script> and <style> elements).    //    private boolean dontEscape;    // Internal buffer used when outputting properly escaped information    // using Util class.    //    private char[] buffer = new char[1028];    private char[] charHolder = new char[1];    /**     * Constructor sets the <code>ResponseWriter</code> and     * encoding.     *     * @param writer      the <code>ResponseWriter</code>     * @param contentType the content type.     * @param encoding    the character encoding.     *     * @throws if the encoding is not recognized.     */    public XULResponseWriter(Writer writer, String contentType, String encoding)          throws FacesException {        this.writer = writer;        if (null != contentType) {            this.contentType = contentType;        }        this.encoding = encoding;        // Check the character encoding        try {            Util.validateEncoding(encoding);        } catch (UnsupportedEncodingException e) {            // PENDING i18n            throw new IllegalArgumentException(                  "Unrecognized Character Encoding.");        }    }    /** @return the content type for this ResponseWriter. */    public String getContentType() {        return contentType;    }    /**     * @return the character encoding, such as "ISO-8859-1" for this     *         ResponseWriter.  Refer to:     *         <a href="http://www.iana.org/assignments/character-sets">theIANA</a>     *         for a list of character encodings.     */    public String getCharacterEncoding() {        return encoding;    }    /**     * <p>Write the text that should begin a response.</p>     *     * @throws IOException if an input/output error occurs     */    public void startDocument() throws IOException {        // do nothing;    }    /** Output the text for the end of a document. */    public void endDocument() throws IOException {        writer.flush();    }    /**     * Flush any buffered output to the contained writer.     *     * @throws IOException if an input/output error occurs.     */    public void flush() throws IOException {        // close any previously started element, if necessary        closeStartIfNecessary();    }    /**     * <p>Write the start of an element, up to and including the     * element name.  Clients call <code>writeAttribute()</code> or     * <code>writeURIAttribute()</code> methods to add attributes after     * calling this method.     *     * @param name                Name of the starting element     * @param componentForElement The UIComponent instance that applies to this     *                            element.  This argument may be <code>null</code>.     *     * @throws IOException          if an input/output error occurs     * @throws NullPointerException if <code>name</code>     *                              is <code>null</code>     */    public void startElement(String name, UIComponent componentForElement)          throws IOException {        if (name == null) {            // PENDING i18n            throw new NullPointerException(                  "Argument Error: One or more parameters are null.");        }        closeStartIfNecessary();        char firstChar = name.charAt(0);        if ((firstChar == 's') ||            (firstChar == 'S')) {            if ("script".equalsIgnoreCase(name) ||                "style".equalsIgnoreCase(name)) {                dontEscape = true;            }        }        //PENDING (horwat) using String as a result of Tomcat char writer        //         ArrayIndexOutOfBoundsException (3584)        writer.write("<");        writer.write(name);        closeStart = true;    }    /**     * <p>Write the end of an element. This method will first     * close any open element created by a call to     * <code>startElement()</code>.     *     * @param name Name of the element to be ended     *     * @throws IOException          if an input/output error occurs     * @throws NullPointerException if <code>name</code>     *                              is <code>null</code>     */    public void endElement(String name) throws IOException {        if (name == null) {            // PENDING - i18n            throw new NullPointerException(                  "Argument Error: One or more parameters are null.");        }        // always turn escaping back on once an element ends        dontEscape = false;        // See if we need to close the start of the last element        if (closeStart) {            writer.write(">");            closeStart = false;        }        writer.write("</");        writer.write(name);        writer.write(">");    }    /**     * <p>Write a properly escaped attribute name and the corresponding     * value.  The value text will be converted to a String if     * necessary.  This method may only be called after a call to     * <code>startElement()</code>, and before the opened element has been     * closed.</p>     *     * @param name                  Attribute name to be added     * @param value                 Attribute value to be added     * @param componentPropertyName The name of the component property to     *                              which this attribute argument applies.  This argument may be     *                              <code>null</code>.     *     * @throws IllegalStateException if this method is called when there     *                               is no currently open element     * @throws IOException           if an input/output error occurs     * @throws NullPointerException  if <code>name</code> is <code>null</code>     */    public void writeAttribute(String name, Object value,                               String componentPropertyName)          throws IOException {        if (name == null) {            // PENDING i18n            throw new NullPointerException(                  "Argument Error: One or more parameters are null.");        }        if (value == null) {            return;        }        Class valueClass = value.getClass();        // Output Boolean values specially        if (valueClass == Boolean.class) {            if (Boolean.TRUE.equals(value)) {                //PENDING (horwat) using String as a result of                //Tomcat char writer ArrayIndexOutOfBoundsException (3584)                writer.write(" ");                writer.write(name);            } else {                // Don't write anything for "false" booleans

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -