use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class DebugStructureInterceptor method writeDebugInfo.
/**
* Writes debugging information for the given component.
*
* @param component the component to write debugging information for.
* @param xml the writer to send the debug output to.
*/
protected void writeDebugInfo(final WComponent component, final XmlStringBuilder xml) {
if (component != null && (component.isVisible() || component instanceof WInvisibleContainer)) {
xml.appendTagOpen("ui:debugInfo");
xml.appendAttribute("for", component.getId());
xml.appendAttribute("class", component.getClass().getName());
xml.appendOptionalAttribute("type", getType(component));
xml.appendClose();
xml.appendTagOpen("ui:debugDetail");
xml.appendAttribute("key", "defaultState");
xml.appendAttribute("value", component.isDefaultState());
xml.appendEnd();
xml.appendEndTag("ui:debugInfo");
if (component instanceof WRepeater) {
// special case for WRepeaters - we must paint the info for each row.
WRepeater repeater = (WRepeater) component;
List<UIContext> contexts = repeater.getRowContexts();
for (int i = 0; i < contexts.size(); i++) {
UIContextHolder.pushContext(contexts.get(i));
try {
writeDebugInfo(repeater.getRepeatedComponent(i), xml);
} finally {
UIContextHolder.popContext();
}
}
} else if (component instanceof WCardManager) {
writeDebugInfo(((WCardManager) component).getVisible(), xml);
} else if (component instanceof Container) {
final int size = ((Container) component).getChildCount();
for (int i = 0; i < size; i++) {
writeDebugInfo(((Container) component).getChildAt(i), xml);
}
}
}
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class DefaultPageShell method openDoc.
/**
* {@inheritDoc}
*/
@Override
public void openDoc(final PrintWriter writer) {
UIContext uic = UIContextHolder.getCurrent();
String title = getApplicationTitle(uic);
writer.write(XMLUtil.getXMLDeclarationWithThemeXslt(uic));
StringBuilder rootElement = new StringBuilder();
rootElement.append("\n<ui:root title=\"");
rootElement.append(WebUtilities.encode(title));
rootElement.append("\" ");
Locale locale = I18nUtilities.getEffectiveLocale();
if (locale != null) {
String lang = locale.toLanguageTag();
if (lang != null) {
rootElement.append("lang=\"");
rootElement.append(WebUtilities.encode(locale.toLanguageTag()));
rootElement.append("\" ");
}
}
rootElement.append(XMLUtil.STANDARD_NAMESPACES);
rootElement.append(">");
writer.write(rootElement.toString());
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class FormInterceptor method preparePaint.
/**
* Override preparePaint in order to perform processing specific to this interceptor.
*
* @param request the request being responded to.
*/
@Override
public void preparePaint(final Request request) {
// Reset the form encoding type before painting the content.
UIContext uic = UIContextHolder.getCurrent();
uic.getEnvironment().setFormEncType(null);
super.preparePaint(request);
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class FormInterceptor method serviceRequest.
/**
* Override serviceRequest in order to perform processing specific to this interceptor.
*
* @param request the request being responded to.
*/
@Override
public void serviceRequest(final Request request) {
// Reset the focus for this new request.
UIContext uic = UIContextHolder.getCurrent();
uic.setFocussed(null, null);
// We've hit the action phase, so we do want focus on this app.
uic.setFocusRequired(true);
super.serviceRequest(request);
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class TransformXMLInterceptor method paint.
/**
* Override paint to perform XML to HTML transformation.
*
* @param renderContext the renderContext to send the output to.
*/
@Override
public void paint(final RenderContext renderContext) {
if (!doTransform) {
super.paint(renderContext);
return;
}
if (!(renderContext instanceof WebXmlRenderContext)) {
LOG.warn("Unable to transform a " + renderContext);
super.paint(renderContext);
return;
}
LOG.debug("Transform XML Interceptor: Start");
UIContext uic = UIContextHolder.getCurrent();
// Set up a render context to buffer the XML payload.
StringWriter xmlBuffer = new StringWriter();
PrintWriter xmlWriter = new PrintWriter(xmlBuffer);
WebXmlRenderContext xmlContext = new WebXmlRenderContext(xmlWriter, uic.getLocale());
// write the XML to the buffer
super.paint(xmlContext);
// Get a handle to the true PrintWriter.
WebXmlRenderContext webRenderContext = (WebXmlRenderContext) renderContext;
PrintWriter writer = webRenderContext.getWriter();
/*
* Switch the response content-type to HTML.
* In theory the transformation could be to ANYTHING (not just HTML) so perhaps it would make more sense to
* write a new interceptor "ContentTypeInterceptor" which attempts to sniff payloads and choose the correct
* content-type. This is exactly the kind of thing IE6 loved to do, so perhaps it's a bad idea.
*/
Response response = getResponse();
response.setContentType(WebUtilities.CONTENT_TYPE_HTML);
String xml = xmlBuffer.toString();
if (isAllowCorruptCharacters() && !Util.empty(xml)) {
// Remove illegal HTML characters from the content before transforming it.
xml = removeCorruptCharacters(xml);
}
// Double encode template tokens in the XML
xml = WebUtilities.doubleEncodeBrackets(xml);
// Setup temp writer
StringWriter tempBuffer = new StringWriter();
PrintWriter tempWriter = new PrintWriter(tempBuffer);
// Perform the transformation and write the result.
transform(xml, uic, tempWriter);
// Decode Double Encoded Brackets
String tempResp = tempBuffer.toString();
tempResp = WebUtilities.doubleDecodeBrackets(tempResp);
// Write response
writer.write(tempResp);
LOG.debug("Transform XML Interceptor: Finished");
}
Aggregations