use of com.sun.faces.io.FastStringWriter in project mojarra by eclipse-ee4j.
the class Util method checkIdUniqueness.
/**
* Utility method to validate ID uniqueness for the tree represented by <code>component</code>.
*/
public static void checkIdUniqueness(FacesContext context, UIComponent component, Set<String> componentIds) {
boolean uniquenessCheckDisabled = false;
if (context.isProjectStage(ProjectStage.Production)) {
WebConfiguration config = WebConfiguration.getInstance(context.getExternalContext());
uniquenessCheckDisabled = config.isOptionEnabled(WebConfiguration.BooleanWebContextInitParameter.DisableIdUniquenessCheck);
}
if (!uniquenessCheckDisabled) {
// deal with children/facets that are marked transient.
for (Iterator<UIComponent> kids = component.getFacetsAndChildren(); kids.hasNext(); ) {
UIComponent kid = kids.next();
// check for id uniqueness
String id = kid.getClientId(context);
if (componentIds.add(id)) {
checkIdUniqueness(context, kid, componentIds);
} else {
if (LOGGER.isLoggable(Level.SEVERE)) {
LOGGER.log(Level.SEVERE, "faces.duplicate_component_id_error", id);
FastStringWriter writer = new FastStringWriter(128);
DebugUtil.simplePrintTree(context.getViewRoot(), id, writer);
LOGGER.severe(writer.toString());
}
String message = MessageUtils.getExceptionMessageString(MessageUtils.DUPLICATE_COMPONENT_ID_ERROR_ID, id);
throw new IllegalStateException(message);
}
}
}
}
use of com.sun.faces.io.FastStringWriter in project mojarra by eclipse-ee4j.
the class WriteBehindStateWriter method getState.
/**
* Get the state.
*
* <p>
* In Faces it is required by the specification that the view state hidden input in each h:form has a unique id. So we
* have to call this method multiple times as each h:form needs to generate the element id for itself.
* </p>
*
* @param stateManager the state manager.
* @param origWriter the original response writer.
* @return the state.
* @throws IOException when an I/O error occurs.
*/
private StringBuilder getState(StateManager stateManager, ResponseWriter origWriter) throws IOException {
FastStringWriter stateWriter = new FastStringWriter(stateManager.isSavingStateInClient(context) ? bufSize : 128);
context.setResponseWriter(origWriter.cloneWithWriter(stateWriter));
if (state == null) {
String viewId = context.getViewRoot().getViewId();
ViewDeclarationLanguage vdl = context.getApplication().getViewHandler().getViewDeclarationLanguage(context, viewId);
if (vdl != null) {
Map<Object, Object> contextAttributes = context.getAttributes();
try {
contextAttributes.put(IS_SAVING_STATE, TRUE);
state = vdl.getStateManagementStrategy(context, viewId).saveView(context);
} finally {
contextAttributes.remove(IS_SAVING_STATE);
}
}
}
stateManager.writeState(context, state);
context.setResponseWriter(origWriter);
return stateWriter.getBuffer();
}
use of com.sun.faces.io.FastStringWriter in project mojarra by eclipse-ee4j.
the class MenuRenderer method renderSelect.
// Render the "select" portion..
//
protected void renderSelect(FacesContext context, UIComponent component) throws IOException {
ResponseWriter writer = context.getResponseWriter();
if (logger.isLoggable(FINER)) {
logger.log(FINER, "Rendering 'select'");
}
writer.startElement("select", component);
writeIdAttributeIfNecessary(context, writer, component);
writer.writeAttribute("name", component.getClientId(context), "clientId");
// Render styleClass attribute if present.
String styleClass;
if ((styleClass = (String) component.getAttributes().get("styleClass")) != null) {
writer.writeAttribute("class", styleClass, "styleClass");
}
if (!getMultipleText(component).equals("")) {
writer.writeAttribute("multiple", true, "multiple");
}
// Determine how many option(s) we need to render, and update
// the component's "size" attribute accordingly; The "size"
// attribute will be rendered as one of the "pass thru" attributes
SelectItemsIterator<SelectItem> items = getSelectItems(context, component);
// Render the options to a buffer now so that we can determine
// the size
FastStringWriter bufferedWriter = new FastStringWriter(128);
context.setResponseWriter(writer.cloneWithWriter(bufferedWriter));
int count = renderOptions(context, component, items);
context.setResponseWriter(writer);
// If "size" is *not* set explicitly, we have to default it correctly
Integer size = (Integer) component.getAttributes().get("size");
if (size == null || size == MIN_VALUE) {
size = count;
}
writeDefaultSize(writer, size);
renderPassThruAttributes(context, writer, component, ATTRIBUTES, getNonOnChangeBehaviors(component));
renderXHTMLStyleBooleanAttributes(writer, component);
renderOnchange(context, component, false);
// Now, write the buffered option content
writer.write(bufferedWriter.toString());
writer.endElement("select");
}
use of com.sun.faces.io.FastStringWriter in project mojarra by eclipse-ee4j.
the class HtmlResponseWriter method endDocument.
/**
* Output the text for the end of a document.
*/
@Override
public void endDocument() throws IOException {
/*
* If the FastStringWriter is kept because of an error in <script> writing we get it here and write out the result. See
* issue #3473
*/
if (writer instanceof FastStringWriter) {
FastStringWriter fastStringWriter = (FastStringWriter) writer;
String result = fastStringWriter.getBuffer().toString();
fastStringWriter.reset();
writer = origWriter;
writer.write(result);
}
writer.flush();
}
use of com.sun.faces.io.FastStringWriter in project mojarra by eclipse-ee4j.
the class HtmlResponseWriter method endElement.
/**
* <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>
*/
@Override
public void endElement(String name) throws IOException {
if (name == null) {
throw new NullPointerException(MessageUtils.getExceptionMessageString(MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "name"));
}
if ("script".equalsIgnoreCase(name)) {
withinScript = false;
}
if ("style".equalsIgnoreCase(name)) {
withinStyle = false;
}
// always turn escaping back on once an element ends
if (!withinScript && !withinStyle) {
dontEscape = false;
}
isXhtml = getContentType().equals(RIConstants.XHTML_CONTENT_TYPE);
if (isScriptOrStyle(name) && !scriptOrStyleSrc && writer instanceof FastStringWriter) {
String result = ((FastStringWriter) writer).getBuffer().toString();
writer = origWriter;
if (result != null) {
String trim = result.trim();
if (isXhtml) {
if (isScript) {
Matcher cdataStartSlashSlash = CDATA_START_SLASH_SLASH.matcher(trim), cdataEndSlashSlash = CDATA_END_SLASH_SLASH.matcher(trim), cdataStartSlashStar = CDATA_START_SLASH_STAR.matcher(trim), cdataEndSlashStar = CDATA_END_SLASH_STAR.matcher(trim);
int trimLen = trim.length(), start, end;
// case 1 start is // end is //
if (cdataStartSlashSlash.find() && cdataEndSlashSlash.find()) {
start = cdataStartSlashSlash.end() - cdataStartSlashSlash.start();
end = trimLen - (cdataEndSlashSlash.end() - cdataEndSlashSlash.start());
writer.write(trim.substring(start, end));
} else // case 2 start is // end is /* */
if (null != cdataStartSlashSlash.reset() && cdataStartSlashSlash.find() && cdataEndSlashStar.find()) {
start = cdataStartSlashSlash.end() - cdataStartSlashSlash.start();
end = trimLen - (cdataEndSlashStar.end() - cdataEndSlashStar.start());
writer.write(trim.substring(start, end));
} else // case 3 start is /* */ end is /* */
if (cdataStartSlashStar.find() && null != cdataEndSlashStar.reset() && cdataEndSlashStar.find()) {
start = cdataStartSlashStar.end() - cdataStartSlashStar.start();
end = trimLen - (cdataEndSlashStar.end() - cdataEndSlashStar.start());
writer.write(trim.substring(start, end));
} else // case 4 start is /* */ end is //
if (null != cdataStartSlashStar.reset() && cdataStartSlashStar.find() && null != cdataEndSlashStar.reset() && cdataEndSlashSlash.find()) {
start = cdataStartSlashStar.end() - cdataStartSlashStar.start();
end = trimLen - (cdataEndSlashSlash.end() - cdataEndSlashSlash.start());
writer.write(trim.substring(start, end));
} else // case 5 no commented out cdata present.
{
writer.write(result);
}
} else {
if (trim.startsWith("<![CDATA[") && trim.endsWith("]]>")) {
writer.write(trim.substring(9, trim.length() - 3));
} else {
writer.write(result);
}
}
} else {
if (trim.startsWith("<!--") && trim.endsWith("//-->")) {
writer.write(trim.substring(4, trim.length() - 5));
} else {
writer.write(result);
}
}
}
if (isXhtml) {
if (!writingCdata) {
if (isScript) {
writer.write("\n//]]>\n");
} else {
writer.write("\n]]>\n");
}
}
} else {
if (isScriptHidingEnabled) {
writer.write("\n//-->\n");
}
}
}
if (!withinScript || isScript) {
isScript = false;
} else if (!withinStyle || isStyle) {
isStyle = false;
}
if (!withinScript && !withinScript) {
dontEscape = false;
}
if ("cdata".equalsIgnoreCase(name)) {
endCDATA();
return;
}
// See if we need to close the start of the last element
if (closeStart) {
boolean isEmptyElement = HtmlUtils.isEmptyElement(name);
// spurious /> characters to appear in the output.
if (isEmptyElement) {
flushAttributes();
writer.write(" />");
closeStart = false;
popElementName(name);
return;
}
flushAttributes();
writer.write('>');
closeStart = false;
}
writer.write("</");
writer.write(popElementName(name));
writer.write('>');
}
Aggregations