/** * <p>Create a new instance of this <code>ResponseWriter</code> using * a different <code>Writer</code>. * * @param writer The <code>Writer</code> that will be used to create * another <code>ResponseWriter</code>. */ public ResponseWriter cloneWithWriter(Writer writer) { try { return new HtmlResponseWriter(writer, getContentType(), getCharacterEncoding(), isScriptHidingEnabled, isScriptInAttributeValueEnabled, disableUnicodeEscaping); } catch (FacesException e) { // This should never happen throw new IllegalStateException(); } }
/** * Flush any buffered output to the contained writer. * * @throws IOException if an input/output error occurs. */ public void flush() throws IOException { // NOTE: Internal buffer's contents (the ivar "buffer") is // written to the contained writer in the HtmlUtils class - see // HtmlUtils.flushBuffer method; Buffering is done during // writeAttribute/writeText - otherwise, output is written // directly to the writer (ex: writer.write(....).. // // close any previously started element, if necessary closeStartIfNecessary(); }
appendBuffer(ESCAPEDLT); } else if (cbuf[offset] == ']') { appendBuffer(ESCAPEDSINGLEBRACKET); } else { appendBuffer(cbuf[offset]); flushBuffer(); return; appendBuffer(ESCAPEDLT); appendBuffer(cbuf[offset + 1]); } else if (cbuf[offset] == ']' && cbuf[offset + 1] == ']') { appendBuffer(ESCAPEDSINGLEBRACKET); appendBuffer(ESCAPEDSINGLEBRACKET); } else { appendBuffer(cbuf[offset]); appendBuffer(cbuf[offset + 1]); flushBuffer(); return; for (int i = offset; i < length - 2; i++) { if (cbuf[i] == '<' && cbuf[i + 1] == '!' && cbuf[i + 2] == '[') { appendBuffer(ESCAPEDSTART); i += 2; } else if (cbuf[i] == ']' && cbuf[i + 1] == ']' && cbuf[i + 2] == '>') { appendBuffer(ESCAPEDEND); i += 2; } else {
isXhtml = getContentType().equals( RIConstants.XHTML_CONTENT_TYPE); if (isScriptOrStyle(name) && !scriptOrStyleSrc && writer instanceof FastStringWriter) { endCDATA(); return; flushAttributes(); writer.write(" />"); closeStart = false; popElementName(name); return; flushAttributes(); writer.write('>'); closeStart = false; writer.write(popElementName(name)); writer.write('>');
closeStartIfNecessary(); isScriptOrStyle(name); scriptOrStyleSrc = false; if ("cdata".equalsIgnoreCase(name)) { isCdata = true; startCDATA(); return; } else if (writingCdata) { Map<String, Object> passThroughAttrs = componentForElement.getPassThroughAttributes(false); if (null != passThroughAttrs && !passThroughAttrs.isEmpty()) { considerPassThroughAttributes(passThroughAttrs); String elementName = pushElementName(name); writer.write(elementName);
flushAttributes(); writer.write('>'); closeStart = false; if (isScriptOrStyle() && !scriptOrStyleSrc) { isXhtml = getContentType().equals( RIConstants.XHTML_CONTENT_TYPE); if (isXhtml) {
MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "text")); closeStartIfNecessary(); String textStr = text.toString(); writer.write(textStr); } else if (isPartial || !writingCdata) { ensureTextBufferCapacity(textStr); HtmlUtils.writeText(writer, escapeUnicode, int textLen = textStr.length(); if (textLen > cdataTextBufferSize) { writeEscaped(textStr.toCharArray(), 0, textLen); } else if (textLen >= 16) { // >16, < cdataTextBufferSize textStr.getChars(0, textLen, cdataTextBuffer, 0); writeEscaped(cdataTextBuffer, 0, textLen); } else { // <16 for (int i=0; i < textLen; i++) { cdataTextBuffer[i] = textStr.charAt(i); writeEscaped(cdataTextBuffer, 0, textLen);
if (containsPassThroughAttribute(name)) { return; if (name.equalsIgnoreCase("src") && isScriptOrStyle()) { scriptOrStyleSrc = true; ensureTextBufferCapacity(val); HtmlUtils.writeAttribute(attributesBuffer, escapeUnicode,
if (name.equalsIgnoreCase("src") && isScriptOrStyle()) { scriptOrStyleSrc = true; ensureTextBufferCapacity(stringValue);
closeStartIfNecessary(); ensureTextBufferCapacity(str); HtmlUtils.writeText(writer, true, true, buffer, str, textBuffer); writer.write("-->");
public String createHtml(UIComponent component) { FacesContext context = FacesContext.getCurrentInstance(); ResponseWriter oldWriter = context.getResponseWriter(); try { StringWriter buffer = new StringWriter(); context.setResponseWriter(new HtmlResponseWriter(buffer, "text/html", "UTF-8")); component.encodeAll(context); context.getResponseWriter().close(); return buffer.toString(); } finally { context.setResponseWriter(oldWriter); } }
MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "name")); closeStartIfNecessary(); isScriptOrStyle(name); scriptOrStyleSrc = false; if ("cdata".equalsIgnoreCase(name)) {
/** * <p>Write a properly escaped single character, If there * is an open element that has been created by a call to * <code>startElement()</code>, that element will be closed first.</p> * <p/> * <p>All angle bracket occurrences in the argument must be escaped * using the &gt; &lt; syntax.</p> * * @param text Text to be written * * @throws IOException if an input/output error occurs */ public void writeText(char text) throws IOException { closeStartIfNecessary(); if (dontEscape) { writer.write(text); } else if (isPartial || !writingCdata) { charHolder[0] = text; HtmlUtils.writeText(writer, escapeUnicode, escapeIso, buffer, charHolder); } else { // if writingCdata assert writingCdata; charHolder[0] = text; writeEscaped(charHolder, 0, 1); } }
webConfig = getWebConfiguration(webConfig); isScriptHidingEnabled = (null == webConfig) ? BooleanWebContextInitParameter.EnableJSStyleHiding.getDefaultValue() : webConfig.isOptionEnabled( webConfig = getWebConfiguration(webConfig); isScriptInAttributeValueEnabled = (null == webConfig) ? BooleanWebContextInitParameter.EnableScriptInAttributeValue.getDefaultValue() : webConfig.isOptionEnabled( webConfig = getWebConfiguration(webConfig); disableUnicodeEscaping = WebConfiguration.DisableUnicodeEscaping.getByValue(
isXhtml = getContentType().equals( RIConstants.XHTML_CONTENT_TYPE); if (isScriptOrStyle(name) && !scriptOrStyleSrc && writer instanceof FastStringWriter) { endCDATA(); return; flushAttributes(); writer.write(" />"); closeStart = false; popElementName(name); return; flushAttributes(); writer.write('>'); closeStart = false; writer.write(popElementName(name)); writer.write('>');
closeStartIfNecessary(); isScriptOrStyle(name); scriptOrStyleSrc = false; if ("cdata".equalsIgnoreCase(name)) { isCdata = true; startCDATA(); return; } else if (writingCdata) { Map<String, Object> passThroughAttrs = componentForElement.getPassThroughAttributes(false); if (null != passThroughAttrs && !passThroughAttrs.isEmpty()) { considerPassThroughAttributes(passThroughAttrs); String elementName = pushElementName(name); writer.write(elementName);
flushAttributes(); writer.write('>'); closeStart = false; if (isScriptOrStyle() && !scriptOrStyleSrc) { isXhtml = getContentType().equals( RIConstants.XHTML_CONTENT_TYPE); if (isXhtml) {
MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "text")); closeStartIfNecessary(); String textStr = text.toString(); writer.write(textStr); } else if (isPartial || !writingCdata) { ensureTextBufferCapacity(textStr); HtmlUtils.writeText(writer, escapeUnicode, int textLen = textStr.length(); if (textLen > cdataTextBufferSize) { writeEscaped(textStr.toCharArray(), 0, textLen); } else if (textLen >= 16) { // >16, < cdataTextBufferSize textStr.getChars(0, textLen, cdataTextBuffer, 0); writeEscaped(cdataTextBuffer, 0, textLen); } else { // <16 for (int i=0; i < textLen; i++) { cdataTextBuffer[i] = textStr.charAt(i); writeEscaped(cdataTextBuffer, 0, textLen);
if (containsPassThroughAttribute(name)) { return; if (name.equalsIgnoreCase("src") && isScriptOrStyle()) { scriptOrStyleSrc = true; ensureTextBufferCapacity(val); HtmlUtils.writeAttribute(attributesBuffer, escapeUnicode,
if (name.equalsIgnoreCase("src") && isScriptOrStyle()) { scriptOrStyleSrc = true; ensureTextBufferCapacity(stringValue);