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;
}
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());
}
}
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);
}
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());
}
}
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");
}
Aggregations