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

📄 htmlresponsewriterimpl.java

📁 一个使用struts+hibernate+spring开发的完的网站源代码。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            _startTagOpen = false;        }        else        {            if (s_emptyHtmlElements.contains(name.toLowerCase()))            {                if (log.isWarnEnabled())                    log.warn("HTML nesting warning on closing " + name + ": This element must not contain nested elements or text in HTML");            }            else            {                _writer.write("</");                _writer.write(name);                _writer.write('>');            }        }        _startElementName = null;        _startElementUIComponent = null;    }    public void writeAttribute(String name, Object value, String componentPropertyName) throws IOException    {        if (name == null)        {            throw new NullPointerException("attributeName name must not be null");        }        if (!_startTagOpen)        {            throw new IllegalStateException("Must be called before the start element is closed (attribute '" + name + "')");        }        if (value instanceof Boolean)        {            if (((Boolean)value).booleanValue())            {                // name as value for XHTML compatibility                _writer.write(' ');                _writer.write(name);                _writer.write("=\"");                _writer.write(name);                _writer.write('"');            }        }        else        {            String strValue = value.toString(); //TODO: Use converter for value            _writer.write(' ');            _writer.write(name);            _writer.write("=\"");            _writer.write(HTMLEncoder.encode(strValue, false, false));            _writer.write('"');        }    }    public void writeURIAttribute(String name, Object value, String componentPropertyName) throws IOException    {        if (name == null)        {            throw new NullPointerException("attributeName name must not be null");        }        if (!_startTagOpen)        {            throw new IllegalStateException("Must be called before the start element is closed (attribute '" + name + "')");        }        String strValue = value.toString(); //TODO: Use converter for value?        _writer.write(' ');        _writer.write(name);        _writer.write("=\"");        if (strValue.toLowerCase().startsWith("javascript:"))        {            _writer.write(HTMLEncoder.encode(strValue, false, false));        }        else        {            /*            if (_startElementName.equalsIgnoreCase(HTML.ANCHOR_ELEM) && //TODO: Also support image and button urls ?                name.equalsIgnoreCase(HTML.HREF_ATTR) &&                !strValue.startsWith("#"))            {                FacesContext facesContext = FacesContext.getCurrentInstance();                if (facesContext.getApplication().getStateManager().isSavingStateInClient(facesContext))                {                    //TODO/HACK: saving state in url depends on the work together                    // of 3 (theoretically) pluggable components:                    // ViewHandler, ResponseWriter and ViewTag                    // We should try to make this HtmlResponseWriterImpl able                    // to handle this alone!                    if (strValue.indexOf('?') < 0)                    {                        strValue = strValue + '?' + JspViewHandlerImpl.URL_STATE_MARKER;                    }                    else                    {                        strValue = strValue + '&' + JspViewHandlerImpl.URL_STATE_MARKER;                    }                }            }            */            _writer.write(strValue);        }        _writer.write('"');    }    public void writeComment(Object value) throws IOException    {        if (value == null)        {            throw new NullPointerException("comment name must not be null");        }        closeStartTagIfNecessary();        _writer.write("<!--");        _writer.write(value.toString());    //TODO: Escaping: must not have "-->" inside!        _writer.write("-->");    }    public void writeText(Object value, String componentPropertyName) throws IOException    {        if (value == null)        {            throw new NullPointerException("text name must not be null");        }        closeStartTagIfNecessary();        if(value == null)            return;        String strValue = value.toString(); //TODO: Use converter for value?        if (isScriptOrStyle())        {            _writer.write(UnicodeEncoder.encode(strValue, false, false));        }        else        {            _writer.write(HTMLEncoder.encode(strValue, false, false));        }    }    public void writeText(char cbuf[], int off, int len) throws IOException    {        if (cbuf == null)        {            throw new NullPointerException("cbuf name must not be null");        }        if (cbuf.length < off + len)        {            throw new IndexOutOfBoundsException((off + len) + " > " + cbuf.length);        }        closeStartTagIfNecessary();        if (isScriptOrStyle())        {            String strValue = new String(cbuf, off, len);            _writer.write(UnicodeEncoder.encode(strValue, false, false));        }        else if (isTextarea())        {            // For textareas we must *not* map successive spaces to &nbsp or Newlines to <br/>            // TODO: Make HTMLEncoder support char arrays directly            String strValue = new String(cbuf, off, len);            _writer.write(HTMLEncoder.encode(strValue, false, false));        }        else        {            // We map successive spaces to &nbsp; and Newlines to <br/>            // TODO: Make HTMLEncoder support char arrays directly            String strValue = new String(cbuf, off, len);            _writer.write(HTMLEncoder.encode(strValue, true, true));        }    }    private boolean isScriptOrStyle()    {        return _startElementName != null &&               (_startElementName.equalsIgnoreCase(HTML.SCRIPT_ELEM) ||                _startElementName.equalsIgnoreCase(HTML.STYLE_ELEM));    }    private boolean isTextarea()    {        return _startElementName != null &&               (_startElementName.equalsIgnoreCase(HTML.TEXTAREA_ELEM));    }    public ResponseWriter cloneWithWriter(Writer writer)    {        HtmlResponseWriterImpl newWriter                = new HtmlResponseWriterImpl(writer, getContentType(), getCharacterEncoding());        newWriter._writeDummyForm = _writeDummyForm;        newWriter._dummyFormParams = _dummyFormParams;        return newWriter;    }    // Writer methods    public void close() throws IOException    {        if (_startTagOpen)        {            // we will get here only if no text was written after the start element was opened            _writer.write(" />");        }        _writer.close();    }    public void write(char cbuf[], int off, int len) throws IOException    {        closeStartTagIfNecessary();        String strValue = new String(cbuf, off, len);        _writer.write(UnicodeEncoder.encode(strValue, false, false));    }    public void write(int c) throws IOException    {        closeStartTagIfNecessary();        _writer.write(c);    }    public void write(char cbuf[]) throws IOException    {        closeStartTagIfNecessary();        String strValue = new String(cbuf);        _writer.write(UnicodeEncoder.encode(strValue, false, false));    }    public void write(String str) throws IOException    {        closeStartTagIfNecessary();        // empty string commonly used to force the start tag to be closed.        // in such case, do not call down the writer chain        if (str.length() > 0)        {            _writer.write(UnicodeEncoder.encode(str, false, false));        }    }    public void write(String str, int off, int len) throws IOException    {        closeStartTagIfNecessary();        String strValue = str.substring(off, off+len);        _writer.write(UnicodeEncoder.encode(strValue, false, false));    }    // DummyFormResponseWriter support    public void setWriteDummyForm(boolean writeDummyForm)    {        _writeDummyForm = writeDummyForm;    }    public String getDummyFormName()    {        return DummyFormUtils.DUMMY_FORM_NAME;    }    public void addDummyFormParameter(String paramName)    {        if (_dummyFormParams == null)        {            _dummyFormParams = new HashSet();        }        _dummyFormParams.add(paramName);    }        public Set getDummyFormParams()    {        return _dummyFormParams;    }}

⌨️ 快捷键说明

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