Search in sources :

Example 41 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class TransformXMLInterceptor_Test method buildCorruptXML.

/**
 * @return XML with bad characters
 */
private static String buildCorruptXML() {
    StringBuilder data = new StringBuilder();
    for (int i = 0; i < Integer.MAX_VALUE; i++) {
        if (!Character.isValidCodePoint(i)) {
            continue;
        }
        char ch = (char) i;
        if (ch != '>' && ch != '<' && ch != '&' && ch != '"') {
            data.append(ch);
        }
    }
    String utfString = "<kung><fu>" + data.toString() + "</fu></kung>";
    String isoString = null;
    try {
        byte[] bytes = utfString.getBytes("UTF8");
        isoString = new String(bytes, "ISO-8859-1");
    } catch (final Exception e) {
        throw new SystemException("Error translating. " + e.getMessage());
    }
    return isoString;
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) SystemException(com.github.bordertech.wcomponents.util.SystemException)

Example 42 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class TargetableErrorInterceptor_Test method testHandlePreparePaintSystemError.

@Test
public void testHandlePreparePaintSystemError() throws IOException {
    final SystemException excp = new SystemException("Simulate prepare paint system error");
    // Throw system exception in chain
    InterceptorComponent chain = new InterceptorComponent() {

        @Override
        public void preparePaint(final Request request) {
            throw excp;
        }
    };
    // Setup interceptor
    TargetableErrorInterceptor interceptor = new TargetableErrorInterceptor();
    interceptor.setBackingComponent(chain);
    // Process Action
    try {
        interceptor.preparePaint(new MockRequest());
        Assert.fail("System exception not handled correctly in prepare paint");
    } catch (ErrorCodeEscape e) {
        Assert.assertTrue("Incorrect system exception message in prepare paint", e.getMessage().contains(CONTENT_ERROR));
        Assert.assertEquals("Incorrect escape code for system exception in prepare paint", HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getCode());
        Assert.assertEquals("Cause should be the original system exception in prepare paint", excp, e.getCause());
    }
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Request(com.github.bordertech.wcomponents.Request) ErrorCodeEscape(com.github.bordertech.wcomponents.ErrorCodeEscape) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 43 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class SubordinateControlOptionsExample method setupTrigger.

/**
 * Setup the trigger for the subordinate control.
 */
private void setupTrigger() {
    String label = drpTriggerType.getSelected() + " Trigger";
    WFieldLayout layout = new WFieldLayout();
    layout.setLabelWidth(LABEL_WIDTH);
    buildControlPanel.add(layout);
    switch((TriggerType) drpTriggerType.getSelected()) {
        case RADIOBUTTONGROUP:
            trigger = new RadioButtonGroup();
            WFieldSet rbSet = new WFieldSet("Select an option");
            RadioButtonGroup group = (RadioButtonGroup) trigger;
            WRadioButton rb1 = group.addRadioButton("A");
            WRadioButton rb2 = group.addRadioButton("B");
            WRadioButton rb3 = group.addRadioButton("C");
            rbSet.add(group);
            rbSet.add(rb1);
            rbSet.add(new WLabel("A", rb1));
            rbSet.add(new WText("\u00a0"));
            rbSet.add(rb2);
            rbSet.add(new WLabel("B", rb2));
            rbSet.add(new WText("\u00a0"));
            rbSet.add(rb3);
            rbSet.add(new WLabel("C", rb3));
            layout.addField(label, rbSet);
            return;
        case CHECKBOX:
            trigger = new WCheckBox();
            break;
        case CHECKBOXSELECT:
            trigger = new WCheckBoxSelect(LOOKUP_TABLE_NAME);
            break;
        case DATEFIELD:
            trigger = new WDateField();
            break;
        case DROPDOWN:
            trigger = new WDropdown(new TableWithNullOption(LOOKUP_TABLE_NAME));
            break;
        case EMAILFIELD:
            trigger = new WEmailField();
            break;
        case MULTISELECT:
            trigger = new WMultiSelect(LOOKUP_TABLE_NAME);
            break;
        case MULTISELECTPAIR:
            trigger = new WMultiSelectPair(LOOKUP_TABLE_NAME);
            break;
        case NUMBERFIELD:
            trigger = new WNumberField();
            break;
        case PARTIALDATEFIELD:
            trigger = new WPartialDateField();
            break;
        case PASSWORDFIELD:
            trigger = new WPasswordField();
            break;
        case PHONENUMBERFIELD:
            trigger = new WPhoneNumberField();
            break;
        case RADIOBUTTONSELECT:
            trigger = new WRadioButtonSelect(LOOKUP_TABLE_NAME);
            break;
        case SINGLESELECT:
            trigger = new WSingleSelect(LOOKUP_TABLE_NAME);
            break;
        case TEXTAREA:
            trigger = new WTextArea();
            ((WTextArea) trigger).setMaxLength(1000);
            break;
        case TEXTFIELD:
            trigger = new WTextField();
            break;
        default:
            throw new SystemException("Trigger type not valid");
    }
    layout.addField(label, trigger);
}
Also used : WFieldSet(com.github.bordertech.wcomponents.WFieldSet) WNumberField(com.github.bordertech.wcomponents.WNumberField) WEmailField(com.github.bordertech.wcomponents.WEmailField) WPasswordField(com.github.bordertech.wcomponents.WPasswordField) WMultiSelect(com.github.bordertech.wcomponents.WMultiSelect) WLabel(com.github.bordertech.wcomponents.WLabel) WTextArea(com.github.bordertech.wcomponents.WTextArea) WRadioButton(com.github.bordertech.wcomponents.WRadioButton) WDropdown(com.github.bordertech.wcomponents.WDropdown) SystemException(com.github.bordertech.wcomponents.util.SystemException) WText(com.github.bordertech.wcomponents.WText) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) TableWithNullOption(com.github.bordertech.wcomponents.examples.common.ExampleLookupTable.TableWithNullOption) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) WTextField(com.github.bordertech.wcomponents.WTextField) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect) WMultiSelectPair(com.github.bordertech.wcomponents.WMultiSelectPair) WPhoneNumberField(com.github.bordertech.wcomponents.WPhoneNumberField) WSingleSelect(com.github.bordertech.wcomponents.WSingleSelect) RadioButtonGroup(com.github.bordertech.wcomponents.RadioButtonGroup) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WPartialDateField(com.github.bordertech.wcomponents.WPartialDateField) WDateField(com.github.bordertech.wcomponents.WDateField)

Example 44 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class UIRegistryClassLoaderImpl_Test method testRegisterFail.

/**
 * Test register - exception on register with key already in use.
 */
@Test
public void testRegisterFail() {
    final String key = "test123";
    WComponent component = new DefaultWComponent();
    UIRegistryClassLoaderImpl reg = new UIRegistryClassLoaderImpl();
    reg.register(key, component);
    try {
        reg.register(key, component);
        Assert.fail("attempted registration with key already used should have thrown an exception");
    } catch (SystemException e) {
        String expectedMessage = "Cannot re-register a component. Key = " + key;
        Assert.assertEquals("exceptions hould have contained message expected", expectedMessage, e.getMessage());
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) SystemException(com.github.bordertech.wcomponents.util.SystemException) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) Test(org.junit.Test)

Example 45 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class AjaxInterceptor method paintContainerResponse.

/**
 * Paint the ajax container response.
 *
 * @param renderContext the render context
 * @param operation the ajax operation
 */
private void paintContainerResponse(final RenderContext renderContext, final AjaxOperation operation) {
    WebXmlRenderContext webRenderContext = (WebXmlRenderContext) renderContext;
    XmlStringBuilder xml = webRenderContext.getWriter();
    // Get trigger's context
    ComponentWithContext trigger = AjaxHelper.getCurrentTriggerAndContext();
    if (trigger == null) {
        throw new SystemException("No context available for trigger " + operation.getTriggerId());
    }
    xml.appendTagOpen("ui:ajaxtarget");
    xml.appendAttribute("id", operation.getTargetContainerId());
    xml.appendAttribute("action", AjaxOperation.AjaxAction.REPLACE_CONTENT.getDesc());
    xml.appendClose();
    // Paint targets - Assume targets are in the same context as the trigger
    UIContextHolder.pushContext(trigger.getContext());
    try {
        for (String targetId : operation.getTargets()) {
            ComponentWithContext target;
            if (targetId.equals(operation.getTriggerId())) {
                target = trigger;
            } else {
                target = WebUtilities.getComponentById(targetId, true);
                if (target == null) {
                    LOG.warn("Could not find ajax target to render [" + targetId + "]");
                    continue;
                }
            }
            target.getComponent().paint(renderContext);
        }
    } finally {
        UIContextHolder.popContext();
    }
    xml.appendEndTag("ui:ajaxtarget");
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) SystemException(com.github.bordertech.wcomponents.util.SystemException) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Aggregations

SystemException (com.github.bordertech.wcomponents.util.SystemException)94 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)17 WComponent (com.github.bordertech.wcomponents.WComponent)15 UIContext (com.github.bordertech.wcomponents.UIContext)13 Test (org.junit.Test)12 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)10 WebElement (org.openqa.selenium.WebElement)9 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)6 IOException (java.io.IOException)5 Select (org.openqa.selenium.support.ui.Select)5 ErrorCodeEscape (com.github.bordertech.wcomponents.ErrorCodeEscape)4 Request (com.github.bordertech.wcomponents.Request)4 InputStream (java.io.InputStream)4 PrintWriter (java.io.PrintWriter)4 ArrayList (java.util.ArrayList)4 Environment (com.github.bordertech.wcomponents.Environment)3 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Date (java.util.Date)3 List (java.util.List)3