Search in sources :

Example 6 with ValidatorResources

use of org.apache.commons.validator.ValidatorResources in project sonarqube by SonarSource.

the class JavascriptValidatorTag method renderJavascript.

/**
     * Returns fully rendered JavaScript.
     *
     * @since Struts 1.2
     */
protected String renderJavascript() throws JspException {
    StringBuffer results = new StringBuffer();
    ModuleConfig config = TagUtils.getInstance().getModuleConfig(pageContext);
    ValidatorResources resources = (ValidatorResources) pageContext.getAttribute(ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix(), PageContext.APPLICATION_SCOPE);
    if (resources == null) {
        throw new JspException("ValidatorResources not found in application scope under key \"" + ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix() + "\"");
    }
    Locale locale = TagUtils.getInstance().getUserLocale(this.pageContext, null);
    Form form = null;
    if ("true".equalsIgnoreCase(dynamicJavascript)) {
        form = resources.getForm(locale, formName);
        if (form == null) {
            throw new JspException("No form found under '" + formName + "' in locale '" + locale + "'.  A form must be defined in the " + "Commons Validator configuration when " + "dynamicJavascript=\"true\" is set.");
        }
    }
    if (form != null) {
        if ("true".equalsIgnoreCase(dynamicJavascript)) {
            results.append(this.createDynamicJavascript(config, resources, locale, form));
        } else if ("true".equalsIgnoreCase(staticJavascript)) {
            results.append(this.renderStartElement());
            if ("true".equalsIgnoreCase(htmlComment)) {
                results.append(HTML_BEGIN_COMMENT);
            }
        }
    }
    if ("true".equalsIgnoreCase(staticJavascript)) {
        results.append(getJavascriptStaticMethods(resources));
    }
    if ((form != null) && ("true".equalsIgnoreCase(dynamicJavascript) || "true".equalsIgnoreCase(staticJavascript))) {
        results.append(getJavascriptEnd());
    }
    return results.toString();
}
Also used : Locale(java.util.Locale) JspException(javax.servlet.jsp.JspException) Form(org.apache.commons.validator.Form) ValidatorResources(org.apache.commons.validator.ValidatorResources) ModuleConfig(org.apache.struts.config.ModuleConfig)

Aggregations

ValidatorResources (org.apache.commons.validator.ValidatorResources)6 Locale (java.util.Locale)4 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 StringTokenizer (java.util.StringTokenizer)2 ServletException (javax.servlet.ServletException)2 JspException (javax.servlet.jsp.JspException)2 Form (org.apache.commons.validator.Form)2 Validator (org.apache.commons.validator.Validator)2 ModuleConfig (org.apache.struts.config.ModuleConfig)2 SAXException (org.xml.sax.SAXException)2