Search in sources :

Example 81 with UIContext

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);
            }
        }
    }
}
Also used : Container(com.github.bordertech.wcomponents.Container) WInvisibleContainer(com.github.bordertech.wcomponents.WInvisibleContainer) UIContext(com.github.bordertech.wcomponents.UIContext) WCardManager(com.github.bordertech.wcomponents.WCardManager) WInvisibleContainer(com.github.bordertech.wcomponents.WInvisibleContainer) WRepeater(com.github.bordertech.wcomponents.WRepeater)

Example 82 with UIContext

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());
}
Also used : Locale(java.util.Locale) UIContext(com.github.bordertech.wcomponents.UIContext)

Example 83 with UIContext

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);
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext)

Example 84 with UIContext

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);
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext)

Example 85 with UIContext

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");
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) Response(com.github.bordertech.wcomponents.Response) StringWriter(java.io.StringWriter) UIContext(com.github.bordertech.wcomponents.UIContext) PrintWriter(java.io.PrintWriter)

Aggregations

UIContext (com.github.bordertech.wcomponents.UIContext)114 Test (org.junit.Test)47 WComponent (com.github.bordertech.wcomponents.WComponent)18 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)15 SystemException (com.github.bordertech.wcomponents.util.SystemException)14 WApplication (com.github.bordertech.wcomponents.WApplication)13 UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)11 WText (com.github.bordertech.wcomponents.WText)11 PrintWriter (java.io.PrintWriter)11 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)10 SeleniumWComponentsWebDriver (com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver)9 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)7 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)7 WDropdown (com.github.bordertech.wcomponents.WDropdown)7 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)7 StringWriter (java.io.StringWriter)7 AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)6 Environment (com.github.bordertech.wcomponents.Environment)6 MockWEnvironment (com.github.bordertech.wcomponents.MockWEnvironment)6 WButton (com.github.bordertech.wcomponents.WButton)6