Search in sources :

Example 61 with SystemException

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

the class AjaxSetupInterceptor method serviceRequest.

/**
 * Setup the AJAX operation details.
 *
 * @param request the request being serviced.
 */
@Override
public void serviceRequest(final Request request) {
    // Get trigger id
    String triggerId = request.getParameter(WServlet.AJAX_TRIGGER_PARAM_NAME);
    if (triggerId == null) {
        throw new SystemException("No AJAX trigger id to on request");
    }
    // Find the Component for this trigger
    ComponentWithContext trigger = WebUtilities.getComponentById(triggerId, true);
    if (trigger == null) {
        throw new SystemException("No component found for AJAX trigger " + triggerId + ".");
    }
    WComponent triggerComponent = trigger.getComponent();
    // Check for an internal AJAX request (if client has flagged it as internal)
    boolean internal = request.getParameter(WServlet.AJAX_TRIGGER_INTERNAL_PARAM_NAME) != null;
    AjaxOperation ajaxOperation = null;
    if (internal) {
        if (!(triggerComponent instanceof AjaxInternalTrigger)) {
            throw new SystemException("AJAX trigger [" + triggerId + "] does not support internal actions.");
        }
        // Create internal operation
        ajaxOperation = new AjaxOperation(triggerId);
    } else {
        // Check for a registered AJAX operation
        ajaxOperation = AjaxHelper.getAjaxOperation(triggerId);
        // TODO This is only required until all components start using the Internal param flag
        if (ajaxOperation != null && "GET".equals(request.getMethod()) && triggerComponent instanceof AjaxInternalTrigger) {
            // Create internal operation
            ajaxOperation = new AjaxOperation(triggerId);
        }
    }
    // If no operation registered, check if the trigger supports internal AJAX then assume it is an Internal Action
    if (ajaxOperation == null && trigger.getComponent() instanceof AjaxInternalTrigger) {
        // Create internal operation
        ajaxOperation = new AjaxOperation(triggerId);
    }
    // No Valid operation
    if (ajaxOperation == null) {
        throw new SystemException("No AJAX operation has been registered for trigger " + triggerId + ".");
    }
    // Set current operation
    AjaxHelper.setCurrentOperationDetails(ajaxOperation, trigger);
    // Process Service Request
    super.serviceRequest(request);
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) AjaxInternalTrigger(com.github.bordertech.wcomponents.AjaxInternalTrigger) AjaxOperation(com.github.bordertech.wcomponents.AjaxOperation) SystemException(com.github.bordertech.wcomponents.util.SystemException) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Example 62 with SystemException

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

the class TargetableInterceptor method preparePaint.

/**
 * {@inheritDoc}
 */
@Override
public void preparePaint(final Request request) {
    ComponentWithContext target = WebUtilities.getComponentById(targetId, true);
    if (target == null) {
        throw new SystemException("No target component found for id " + targetId);
    }
    UIContextHolder.pushContext(target.getContext());
    try {
        super.preparePaint(request);
    } finally {
        UIContextHolder.popContext();
    }
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Example 63 with SystemException

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

the class TargetableInterceptor method serviceRequest.

/**
 * {@inheritDoc}
 */
@Override
public void serviceRequest(final Request request) {
    // Check if this is a targeted request
    targetId = request.getParameter(Environment.TARGET_ID);
    if (targetId == null) {
        throw new SystemException("No target id request parameter");
    }
    ComponentWithContext target = WebUtilities.getComponentById(targetId, true);
    if (target == null) {
        throw new SystemException("No target component found for id " + targetId);
    }
    // go straight to the target component.
    attachUI(target.getComponent());
    UIContextHolder.pushContext(target.getContext());
    try {
        super.serviceRequest(request);
    } finally {
        UIContextHolder.popContext();
    }
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Example 64 with SystemException

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

the class TemplateRenderInterceptor method getResourceBundle.

/**
 * @return the current resource bundle
 */
private static ResourceBundle getResourceBundle() {
    Locale locale = I18nUtilities.getEffectiveLocale();
    String key = locale.toString();
    // Check if we have already loaded it
    ResourceBundle bundle = RESOURCES.get(key);
    if (bundle == null) {
        try {
            bundle = ResourceBundle.getBundle(RESOUCRCE_BUNDLE_BASE_NAME, locale);
            RESOURCES.put(key, bundle);
        } catch (Exception e) {
            throw new SystemException("Could not load theme resource bundle for locale [" + key + "].");
        }
    }
    return bundle;
}
Also used : Locale(java.util.Locale) SystemException(com.github.bordertech.wcomponents.util.SystemException) ResourceBundle(java.util.ResourceBundle) SystemException(com.github.bordertech.wcomponents.util.SystemException)

Example 65 with SystemException

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

the class TransformXMLInterceptor method transform.

/**
 * Transform the UI XML to HTML using the correct XSLT from the classpath.
 *
 * @param xml The XML to transform.
 * @param uic The UIContext used to determine variables such as locale.
 * @param writer The result of the transformation will be written to this writer.
 */
private void transform(final String xml, final UIContext uic, final PrintWriter writer) {
    Transformer transformer = newTransformer();
    Source inputXml;
    try {
        inputXml = new StreamSource(new ByteArrayInputStream(xml.getBytes("utf-8")));
        StreamResult result = new StreamResult(writer);
        transformer.transform(inputXml, result);
    } catch (UnsupportedEncodingException | TransformerException ex) {
        throw new SystemException("Could not transform xml", ex);
    }
}
Also used : Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) SystemException(com.github.bordertech.wcomponents.util.SystemException) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamSource(javax.xml.transform.stream.StreamSource) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) TransformerException(javax.xml.transform.TransformerException)

Aggregations

SystemException (com.github.bordertech.wcomponents.util.SystemException)91 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)17 WComponent (com.github.bordertech.wcomponents.WComponent)15 UIContext (com.github.bordertech.wcomponents.UIContext)14 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)10 Test (org.junit.Test)9 WebElement (org.openqa.selenium.WebElement)8 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)6 IOException (java.io.IOException)5 Select (org.openqa.selenium.support.ui.Select)5 Environment (com.github.bordertech.wcomponents.Environment)4 PrintWriter (java.io.PrintWriter)4 ArrayList (java.util.ArrayList)4 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)3 Date (java.util.Date)3 List (java.util.List)3 ResourceNotFoundException (org.apache.velocity.exception.ResourceNotFoundException)3 AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)2 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)2 OptionGroup (com.github.bordertech.wcomponents.OptionGroup)2