Search in sources :

Example 16 with JspWriteRuntimeException

use of org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException in project jaffa-framework by jaffa-projects.

the class HeaderTag method otherDoStartTagOperations.

/**
 * Called from the doStartTag()
 */
public void otherDoStartTagOperations() throws JspException {
    super.otherDoStartTagOperations();
    JspWriter writer = pageContext.getOut();
    StringBuffer buf = new StringBuffer();
    buf.append(getNoCacheTag());
    buf.append(getBaseTag());
    buf.append("<script type=\"text/javascript\" src=\"jaffa/js/panels/header.js\"></script>\n");
    buf.append("<script type=\"text/javascript\" src=\"jaffa/js/panels/errorpopup.js\"></script>\n");
    buf.append("<script type=\"text/javascript\" src=\"jaffa/js/rules/coreRules.js\"></script>\n");
    buf.append("<script type=\"text/javascript\" src=\"jaffa/js/rules/rulesValidator.js\"></script>\n");
    buf.append("<script type=\"text/javascript\" src=\"jaffa/js/rules/initializeRules.js\"></script>\n");
    buf.append("<script type=\"text/javascript\" src=\"jaffa/js/widgets/datetimePicker.js\"></script>\n");
    buf.append("<script type=\"text/javascript\" src=\"jaffa/js/widgets/dropdownManager.js\"></script>\n");
    buf.append("<script type=\"text/javascript\" src=\"jaffa/js/widgets/widgetCache.js\"></script>\n");
    String firstDayOfWeek = (String) ContextManagerFactory.instance().getProperty("jaffa.date.firstDayOfWeek");
    if (firstDayOfWeek != null) {
        Pattern p = Pattern.compile("[0-6]");
        Matcher m = p.matcher(firstDayOfWeek);
        if (!m.matches()) {
            firstDayOfWeek = "0";
        }
        buf.append("<script type=\"text/javascript\">" + StringHelper.convertToHTML(MessageHelper.findMessage("label.Jaffa.Widgets.Grid.ColumnHeader.firstDayOfWeek", null)) + " = " + firstDayOfWeek + " </script>\n");
    }
    if (getErrorBoxInSameWindow()) {
        buf.append("<script> var windowType = \"false\" </script>");
        pageContext.setAttribute(TagHelper.ATTRIBUTE_ERROR_BOX_IN_SAME_WINDOW, Boolean.TRUE, pageContext.REQUEST_SCOPE);
    } else {
        buf.append("<script> var windowType = \"true\" </script>");
        pageContext.setAttribute(TagHelper.ATTRIBUTE_ERROR_BOX_IN_SAME_WINDOW, Boolean.FALSE, pageContext.REQUEST_SCOPE);
    }
    buf.append(generateGetServerDateFunction());
    try {
        writer.println(buf.toString());
    } catch (IOException e) {
        String str = "Exception in writing the HeaderTag";
        log.error(str, e);
        throw new JspWriteRuntimeException(str, e);
    }
}
Also used : JspWriteRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter)

Example 17 with JspWriteRuntimeException

use of org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException in project jaffa-framework by jaffa-projects.

the class LabelTag method otherDoStartTagOperations.

/**
 * Called from the doStartTag()
 */
public void otherDoStartTagOperations() throws JspException {
    super.otherDoStartTagOperations();
    // Preprocess if within a Property widget
    lookupPropertyTag();
    // determine the key to be used for the label
    String key = null;
    if (m_key != null)
        key = m_key;
    else if (m_domain != null && m_field != null) {
        try {
            key = TagHelper.getFieldMetaData(m_domain, m_field).getLabelToken();
            if (log.isDebugEnabled())
                log.debug("LabelToken for the MetaField '" + m_field + "' is : " + key);
        } catch (Exception e) {
            String str = "Exception thrown while determining the LabelToken for the MetaField " + m_field + ". Domain=" + m_domain + ", Field=" + m_field;
            log.error(str, e);
            try {
                JspWriter out = pageContext.getOut();
                out.print(ERROR_LABEL);
            } catch (IOException ioe) {
                String str2 = "Exception in writing the " + TAG_NAME;
                log.error(str2, ioe);
                throw new JspWriteRuntimeException(str2, ioe);
            }
            return;
        // throw new JspWriteRuntimeException(str, e);
        }
    }
    // raise an error, if the key is still null
    if (key == null) {
        String str = "The " + TAG_NAME + " requires either a valid 'key' or 'domain and field' parameters to be supplied";
        log.error(str);
        throw new MissingParametersRuntimeException(str);
    }
    /* NOTE: Key can be of the following formats
         *  xyz           : Invoke MessageHelper.findMessage() to find the label for the key 'xyz'
         *  [xyz]         : Invoke MessageHelper.findMessage() to find the label for the detokenized key 'xyz'
         *  abc [xyz] efg : Invoke MessageHelper.replaceTokens to resolve the text'abc [xyz] efg'
         */
    // get the label from the resource bundle
    String label = null;
    if (MessageHelper.hasTokens(key)) {
        // Remove the begin/end token-markers
        String detokenizedKey = MessageHelper.removeTokenMarkers(key);
        // Check if there are more tokens left
        if (MessageHelper.hasTokens(detokenizedKey))
            label = MessageHelper.replaceTokens(pageContext, key);
        else
            key = detokenizedKey;
    }
    if (label == null) {
        Object[] args = null;
        if (m_arg0 != null || m_arg1 != null || m_arg2 != null || m_arg3 != null || m_arg4 != null)
            args = new Object[] { m_arg0, m_arg1, m_arg2, m_arg3, m_arg4 };
        label = MessageHelper.findMessage(pageContext, key, args);
    }
    // write the label
    try {
        JspWriter out = pageContext.getOut();
        out.print((label != null ? label : UNDEFINED_LABEL + '(' + key + ')'));
        out.print(TagHelper.getLabelEditorLink(pageContext, key));
    } catch (IOException e) {
        String str = "Exception in writing the " + TAG_NAME;
        log.error(str, e);
        throw new JspWriteRuntimeException(str, e);
    }
}
Also used : JspWriteRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter) JspWriteRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException) MissingParametersRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.MissingParametersRuntimeException) JspException(javax.servlet.jsp.JspException) IOException(java.io.IOException) MissingParametersRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.MissingParametersRuntimeException)

Example 18 with JspWriteRuntimeException

use of org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException in project jaffa-framework by jaffa-projects.

the class RaiseErrorsTag method otherDoEndTagOperations.

/**
 * This generates the HTML for the tag.
 * Writes a script tag containing error message details to be added to the current jsp.
 *
 * @throws JspException if any error occurs.
 */
public void otherDoEndTagOperations() throws JspException {
    // Get the form bean from the page.
    FormBase form = TagHelper.getFormBase(pageContext);
    if (form == null) {
        String str = "The " + TAG_NAME + " should be inside a FormTag";
        log.error(str);
        throw new OuterFormTagMissingRuntimeException(str);
    }
    // get the errors from the form
    if (!FormBase.hasErrors((HttpServletRequest) pageContext.getRequest())) {
        return;
    }
    ActionMessages errors = FormBase.getErrors((HttpServletRequest) pageContext.getRequest());
    StringBuilder buf = new StringBuilder();
    buf.append("<SCRIPT type=\"text/javascript\">");
    for (Iterator itr = errors.get(); itr.hasNext(); ) {
        ActionMessage error = (ActionMessage) itr.next();
        buf.append("addMessage(\"");
        String messageHtml = StringHelper.convertToHTML(MessageHelper.findMessage(pageContext, error.getKey(), error.getValues()));
        String labelEditorLink = TagHelper.getLabelEditorLink(pageContext, error.getKey());
        // escape the message for html to prevent XSS
        String message = Encode.forHtml(messageHtml) + labelEditorLink;
        buf.append(message);
        buf.append("\");");
    }
    // delete the error so that it doesn't get re-displayed
    form.clearErrors((HttpServletRequest) pageContext.getRequest());
    buf.append("</SCRIPT>");
    // add the script tag containing the error message to the current jsp
    try {
        JspWriter w = pageContext.getOut();
        w.print(buf.toString());
    } catch (IOException e) {
        String str = "Exception in writing the " + TAG_NAME;
        log.error(str, e);
        throw new JspWriteRuntimeException(str, e);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JspWriteRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException) ActionMessages(org.apache.struts.action.ActionMessages) FormBase(org.jaffa.presentation.portlet.FormBase) Iterator(java.util.Iterator) ActionMessage(org.apache.struts.action.ActionMessage) OuterFormTagMissingRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter)

Aggregations

JspWriteRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException)18 IOException (java.io.IOException)15 JspWriter (javax.servlet.jsp.JspWriter)14 JspException (javax.servlet.jsp.JspException)8 OuterFormTagMissingRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException)8 MissingParametersRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.MissingParametersRuntimeException)7 SimpleWidgetModel (org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel)5 IPropertyRuleIntrospector (org.jaffa.rules.IPropertyRuleIntrospector)5 FormBase (org.jaffa.presentation.portlet.FormBase)2 Iterator (java.util.Iterator)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 ActionMessage (org.apache.struts.action.ActionMessage)1 ActionMessages (org.apache.struts.action.ActionMessages)1 UserSession (org.jaffa.presentation.portlet.session.UserSession)1 UserGridManager (org.jaffa.presentation.portlet.widgets.controller.UserGridManager)1 ImageModel (org.jaffa.presentation.portlet.widgets.model.ImageModel)1 TableModel (org.jaffa.presentation.portlet.widgets.model.TableModel)1 TagCannotBeEnclosedRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.TagCannotBeEnclosedRuntimeException)1