Search in sources :

Example 1 with TagData

use of javax.servlet.jsp.tagext.TagData 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

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