Search in sources :

Example 1 with ValidationMessage

use of javax.servlet.jsp.tagext.ValidationMessage in project sling by apache.

the class Validator method validateXmlView.

// *********************************************************************
// Private (utility) methods
/**
     * Validate XML view against the TagLibraryValidator classes of all imported
     * tag libraries.
     */
private static void validateXmlView(PageData xmlView, Compiler compiler) throws JasperException {
    StringBuffer errMsg = null;
    ErrorDispatcher errDisp = compiler.getErrorDispatcher();
    for (Iterator iter = compiler.getPageInfo().getTaglibs().iterator(); iter.hasNext(); ) {
        Object o = iter.next();
        if (!(o instanceof TagLibraryInfoImpl))
            continue;
        TagLibraryInfoImpl tli = (TagLibraryInfoImpl) o;
        ValidationMessage[] errors = tli.validate(xmlView);
        if ((errors != null) && (errors.length != 0)) {
            if (errMsg == null) {
                errMsg = new StringBuffer();
            }
            errMsg.append("<h3>");
            errMsg.append(Localizer.getMessage("jsp.error.tlv.invalid.page", tli.getShortName(), compiler.getPageInfo().getJspFile()));
            errMsg.append("</h3>");
            for (int i = 0; i < errors.length; i++) {
                if (errors[i] != null) {
                    errMsg.append("<p>");
                    errMsg.append(errors[i].getId());
                    errMsg.append(": ");
                    errMsg.append(errors[i].getMessage());
                    errMsg.append("</p>");
                }
            }
        }
    }
    if (errMsg != null) {
        errDisp.jspError(errMsg.toString());
    }
}
Also used : ValidationMessage(javax.servlet.jsp.tagext.ValidationMessage) Iterator(java.util.Iterator)

Example 2 with ValidationMessage

use of javax.servlet.jsp.tagext.ValidationMessage in project webtools.sourceediting by eclipse.

the class TaglibHelper method addTEIVariables.

/**
 * Adds 1.1 style TaglibVariables (defined in a TagExtraInfo class) to the
 * results list. Also reports problems with the tag and tei classes in
 * fTranslatorProblems.
 *
 * @param customTag
 * @param results
 *            list where the <code>TaglibVariable</code> s are added
 * @param decl
 *            TLDElementDeclaration for the custom tag
 * @param prefix
 *            custom tag prefix
 * @param uri
 *            URI where the tld can be found
 */
private void addTEIVariables(IStructuredDocument document, ITextRegionCollection customTag, List results, TLDElementDeclaration decl, String prefix, String uri, List problems) {
    if (TLDElementDeclaration.SOURCE_TAG_FILE.equals(decl.getProperty(TLDElementDeclaration.TAG_SOURCE)) || fJavaProject == null)
        return;
    String teiClassname = decl.getTeiclass();
    if (teiClassname == null || teiClassname.length() == 0 || fJavaProject == null || fNotFoundClasses.contains(teiClassname))
        return;
    ClassLoader loader = getClassloader();
    Class teiClass = null;
    try {
        /*
			 * JDT could tell us about it, but loading and calling it would
			 * still take time
			 */
        teiClass = Class.forName(teiClassname, true, loader);
        if (teiClass != null) {
            Object teiObject = teiClass.newInstance();
            if (TagExtraInfo.class.isInstance(teiObject)) {
                TagExtraInfo tei = (TagExtraInfo) teiObject;
                Hashtable tagDataTable = extractTagData(customTag);
                TagInfo info = getTagInfo(decl, tei, prefix, uri);
                if (info != null) {
                    tei.setTagInfo(info);
                    // add to results
                    TagData td = new TagData(tagDataTable);
                    VariableInfo[] vInfos = tei.getVariableInfo(td);
                    if (vInfos != null) {
                        for (int i = 0; i < vInfos.length; i++) {
                            String className = vInfos[i].getClassName();
                            if (className != null) {
                                className = getVariableClass(className);
                            }
                            results.add(new TaglibVariable(className, vInfos[i].getVarName(), vInfos[i].getScope(), decl.getDescription()));
                        }
                    }
                    ValidationMessage[] messages = tei.validate(td);
                    if (messages != null && messages.length > 0) {
                        for (int i = 0; i < messages.length; i++) {
                            Object createdProblem = createValidationMessageProblem(document, customTag, messages[i].getMessage());
                            if (createdProblem != null) {
                                problems.add(createdProblem);
                            }
                        }
                    }
                }
            } else {
                Object createdProblem = createJSPProblem(document, customTag, IJSPProblem.TEIClassMisc, JSPCoreMessages.TaglibHelper_2, teiClassname, true);
                if (createdProblem != null) {
                    problems.add(createdProblem);
                }
                // this is 3rd party code, need to catch all exceptions
                if (DEBUG) {
                    // $NON-NLS-1$
                    Logger.log(Logger.WARNING, teiClassname + " is not a subclass of TaxExtraInfo");
                }
            }
        }
    } catch (ClassNotFoundException e) {
        // the class could not be found so add it to the cache
        fNotFoundClasses.add(teiClassname);
        Object createdProblem = createJSPProblem(document, customTag, IJSPProblem.TEIClassNotFound, JSPCoreMessages.TaglibHelper_0, teiClassname, true);
        if (createdProblem != null) {
            problems.add(createdProblem);
        }
        // TEI class wasn't on build path
        if (DEBUG)
            logException(teiClassname, e);
    } catch (InstantiationException e) {
        Object createdProblem = createJSPProblem(document, customTag, IJSPProblem.TEIClassNotInstantiated, JSPCoreMessages.TaglibHelper_1, teiClassname, true);
        if (createdProblem != null) {
            problems.add(createdProblem);
        }
        // TEI class couldn't be instantiated
        if (DEBUG)
            logException(teiClassname, e);
    } catch (IllegalAccessException e) {
        if (DEBUG)
            logException(teiClassname, e);
    }// }
     catch (Exception e) {
        Object createdProblem = createJSPProblem(document, customTag, IJSPProblem.TEIClassMisc, JSPCoreMessages.TaglibHelper_2, teiClassname, true);
        if (createdProblem != null) {
            problems.add(createdProblem);
        }
        // this is 3rd party code, need to catch all exceptions
        if (DEBUG)
            logException(teiClassname, e);
    } catch (Error e) {
        // this is 3rd party code, need to catch all errors
        Object createdProblem = createJSPProblem(document, customTag, IJSPProblem.TEIClassNotInstantiated, JSPCoreMessages.TaglibHelper_1, teiClassname, true);
        if (createdProblem != null) {
            problems.add(createdProblem);
        }
        if (DEBUG)
            logException(teiClassname, e);
    } finally {
    // Thread.currentThread().setContextClassLoader(oldLoader);
    }
}
Also used : ValidationMessage(javax.servlet.jsp.tagext.ValidationMessage) Hashtable(java.util.Hashtable) VariableInfo(javax.servlet.jsp.tagext.VariableInfo) InvocationTargetException(java.lang.reflect.InvocationTargetException) JavaModelException(org.eclipse.jdt.core.JavaModelException) NotImplementedException(org.eclipse.wst.sse.core.internal.NotImplementedException) TagExtraInfo(javax.servlet.jsp.tagext.TagExtraInfo) TagInfo(javax.servlet.jsp.tagext.TagInfo) TagData(javax.servlet.jsp.tagext.TagData)

Aggregations

ValidationMessage (javax.servlet.jsp.tagext.ValidationMessage)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 TagData (javax.servlet.jsp.tagext.TagData)1 TagExtraInfo (javax.servlet.jsp.tagext.TagExtraInfo)1 TagInfo (javax.servlet.jsp.tagext.TagInfo)1 VariableInfo (javax.servlet.jsp.tagext.VariableInfo)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 NotImplementedException (org.eclipse.wst.sse.core.internal.NotImplementedException)1