Search in sources :

Example 6 with TagInfo

use of javax.servlet.jsp.tagext.TagInfo in project tomcat70 by apache.

the class TagLibraryInfoImpl method createTagFileInfo.

/*
     * Parses the tag file directives of the given TagFile and turns them into a
     * TagInfo.
     * 
     * @param elem The <tag-file> element in the TLD @param uri The location of
     * the TLD, in case the tag file is specified relative to it @param jarFile
     * The JAR file, in case the tag file is packaged in a JAR
     * 
     * @return TagInfo corresponding to tag file directives
     */
private TagFileInfo createTagFileInfo(TreeNode elem, JarResource jarResource) throws JasperException {
    String name = null;
    String path = null;
    Iterator<TreeNode> list = elem.findChildren();
    while (list.hasNext()) {
        TreeNode child = list.next();
        String tname = child.getName();
        if ("name".equals(tname)) {
            name = child.getBody();
        } else if ("path".equals(tname)) {
            path = child.getBody();
        } else if ("example".equals(tname)) {
        // Ignore <example> element: Bugzilla 33538
        } else if ("tag-extension".equals(tname)) {
        // Ignore <tag-extension> element: Bugzilla 33538
        } else if ("icon".equals(tname) || "display-name".equals(tname) || "description".equals(tname)) {
        // Ignore these elements: Bugzilla 38015
        } else {
            if (log.isWarnEnabled()) {
                log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.tagfile", tname));
            }
        }
    }
    if (path == null) {
        // path is required
        err.jspError("jsp.error.tagfile.missingPath");
    } else if (path.startsWith("/META-INF/tags")) {
        // Tag file packaged in JAR
        // See https://bz.apache.org/bugzilla/show_bug.cgi?id=46471
        // This needs to be removed once all the broken code that depends on
        // it has been removed
        ctxt.setTagFileJarResource(path, jarResource);
    } else if (!path.startsWith("/WEB-INF/tags")) {
        err.jspError("jsp.error.tagfile.illegalPath", path);
    }
    TagInfo tagInfo = TagFileProcessor.parseTagFileDirectives(parserController, name, path, jarResource, this);
    return new TagFileInfo(name, path, tagInfo);
}
Also used : TagFileInfo(javax.servlet.jsp.tagext.TagFileInfo) TreeNode(org.apache.jasper.xmlparser.TreeNode) TagInfo(javax.servlet.jsp.tagext.TagInfo)

Example 7 with TagInfo

use of javax.servlet.jsp.tagext.TagInfo in project tomcat70 by apache.

the class Parser method parseCustomTag.

/*
     * # '<' CustomAction CustomActionBody
     * 
     * CustomAction ::= TagPrefix ':' CustomActionName
     * 
     * TagPrefix ::= Name
     * 
     * CustomActionName ::= Name
     * 
     * CustomActionBody ::= ( Attributes CustomActionEnd ) | <TRANSLATION_ERROR>
     * 
     * Attributes ::= ( S Attribute )* S?
     * 
     * CustomActionEnd ::= CustomActionTagDependent | CustomActionJSPContent |
     * CustomActionScriptlessContent
     * 
     * CustomActionTagDependent ::= TagDependentOptionalBody
     * 
     * CustomActionJSPContent ::= OptionalBody
     * 
     * CustomActionScriptlessContent ::= ScriptlessOptionalBody
     */
private boolean parseCustomTag(Node parent) throws JasperException {
    if (reader.peekChar() != '<') {
        return false;
    }
    // Parse 'CustomAction' production (tag prefix and custom action name)
    // skip '<'
    reader.nextChar();
    String tagName = reader.parseToken(false);
    int i = tagName.indexOf(':');
    if (i == -1) {
        reader.reset(start);
        return false;
    }
    String prefix = tagName.substring(0, i);
    String shortTagName = tagName.substring(i + 1);
    // Check if this is a user-defined tag.
    String uri = pageInfo.getURI(prefix);
    if (uri == null) {
        if (pageInfo.isErrorOnUndeclaredNamespace()) {
            err.jspError(start, "jsp.error.undeclared_namespace", prefix);
        } else {
            reader.reset(start);
            // Remember the prefix for later error checking
            pageInfo.putNonCustomTagPrefix(prefix, reader.mark());
            return false;
        }
    }
    TagLibraryInfo tagLibInfo = pageInfo.getTaglib(uri);
    TagInfo tagInfo = tagLibInfo.getTag(shortTagName);
    TagFileInfo tagFileInfo = tagLibInfo.getTagFile(shortTagName);
    if (tagInfo == null && tagFileInfo == null) {
        err.jspError(start, "jsp.error.bad_tag", shortTagName, prefix);
    }
    Class<?> tagHandlerClass = null;
    if (tagInfo != null) {
        // Must be a classic tag, load it here.
        // tag files will be loaded later, in TagFileProcessor
        String handlerClassName = tagInfo.getTagClassName();
        try {
            tagHandlerClass = ctxt.getClassLoader().loadClass(handlerClassName);
        } catch (Exception e) {
            err.jspError(start, "jsp.error.loadclass.taghandler", handlerClassName, tagName);
        }
    }
    // Parse 'CustomActionBody' production:
    // At this point we are committed - if anything fails, we produce
    // a translation error.
    // Parse 'Attributes' production:
    Attributes attrs = parseAttributes();
    reader.skipSpaces();
    // Parse 'CustomActionEnd' production:
    if (reader.matches("/>")) {
        if (tagInfo != null) {
            new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagInfo, tagHandlerClass);
        } else {
            new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagFileInfo);
        }
        return true;
    }
    // Now we parse one of 'CustomActionTagDependent',
    // 'CustomActionJSPContent', or 'CustomActionScriptlessContent'.
    // depending on body-content in TLD.
    // Looking for a body, it still can be empty; but if there is a
    // a tag body, its syntax would be dependent on the type of
    // body content declared in the TLD.
    String bc;
    if (tagInfo != null) {
        bc = tagInfo.getBodyContent();
    } else {
        bc = tagFileInfo.getTagInfo().getBodyContent();
    }
    Node tagNode = null;
    if (tagInfo != null) {
        tagNode = new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagInfo, tagHandlerClass);
    } else {
        tagNode = new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagFileInfo);
    }
    parseOptionalBody(tagNode, tagName, bc);
    return true;
}
Also used : TagFileInfo(javax.servlet.jsp.tagext.TagFileInfo) TagInfo(javax.servlet.jsp.tagext.TagInfo) Attributes(org.xml.sax.Attributes) TagLibraryInfo(javax.servlet.jsp.tagext.TagLibraryInfo) FileNotFoundException(java.io.FileNotFoundException) JasperException(org.apache.jasper.JasperException)

Example 8 with TagInfo

use of javax.servlet.jsp.tagext.TagInfo in project tomcat70 by apache.

the class Parser method getAttributeBodyType.

/**
 * Determine the body type of <jsp:attribute> from the enclosing node
 */
private String getAttributeBodyType(Node n, String name) {
    if (n instanceof Node.CustomTag) {
        TagInfo tagInfo = ((Node.CustomTag) n).getTagInfo();
        TagAttributeInfo[] tldAttrs = tagInfo.getAttributes();
        for (int i = 0; i < tldAttrs.length; i++) {
            if (name.equals(tldAttrs[i].getName())) {
                if (tldAttrs[i].isFragment()) {
                    return TagInfo.BODY_CONTENT_SCRIPTLESS;
                }
                if (tldAttrs[i].canBeRequestTime()) {
                    return TagInfo.BODY_CONTENT_JSP;
                }
            }
        }
        if (tagInfo.hasDynamicAttributes()) {
            return TagInfo.BODY_CONTENT_JSP;
        }
    } else if (n instanceof Node.IncludeAction) {
        if ("page".equals(name)) {
            return TagInfo.BODY_CONTENT_JSP;
        }
    } else if (n instanceof Node.ForwardAction) {
        if ("page".equals(name)) {
            return TagInfo.BODY_CONTENT_JSP;
        }
    } else if (n instanceof Node.SetProperty) {
        if ("value".equals(name)) {
            return TagInfo.BODY_CONTENT_JSP;
        }
    } else if (n instanceof Node.UseBean) {
        if ("beanName".equals(name)) {
            return TagInfo.BODY_CONTENT_JSP;
        }
    } else if (n instanceof Node.PlugIn) {
        if ("width".equals(name) || "height".equals(name)) {
            return TagInfo.BODY_CONTENT_JSP;
        }
    } else if (n instanceof Node.ParamAction) {
        if ("value".equals(name)) {
            return TagInfo.BODY_CONTENT_JSP;
        }
    } else if (n instanceof Node.JspElement) {
        return TagInfo.BODY_CONTENT_JSP;
    }
    return JAVAX_BODY_CONTENT_TEMPLATE_TEXT;
}
Also used : TagAttributeInfo(javax.servlet.jsp.tagext.TagAttributeInfo) TagInfo(javax.servlet.jsp.tagext.TagInfo)

Example 9 with TagInfo

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

Example 10 with TagInfo

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

the class TaglibHelper method getTagInfo.

/**
 * @param decl
 * @return the TagInfo for the TLDELementDeclaration if the declaration is
 *         valid, otherwise null
 */
private TagInfo getTagInfo(final TLDElementDeclaration decl, TagExtraInfo tei, String prefix, String uri) {
    TagLibraryInfo libInfo = new TagLibraryInfoImpl(prefix, uri, decl);
    CMNamedNodeMap attrs = decl.getAttributes();
    TagAttributeInfo[] attrInfos = new TagAttributeInfo[attrs.getLength()];
    TLDAttributeDeclaration attr = null;
    // $NON-NLS-1$
    String type = "";
    // get tag attribute infos
    for (int i = 0; i < attrs.getLength(); i++) {
        attr = (TLDAttributeDeclaration) attrs.item(i);
        type = attr.getType();
        // default value for type is String
        if (// $NON-NLS-1$
        attr.getType() == null || attr.getType().equals(""))
            // $NON-NLS-1$
            type = "java.lang.String";
        attrInfos[i] = new TagAttributeInfo(attr.getAttrName(), attr.isRequired(), type, false);
    }
    String tagName = decl.getNodeName();
    String tagClass = decl.getTagclass();
    String bodyContent = decl.getBodycontent();
    if (tagName != null && tagClass != null && bodyContent != null)
        return new TagInfo(tagName, tagClass, bodyContent, decl.getInfo(), libInfo, tei, attrInfos);
    return null;
}
Also used : TLDAttributeDeclaration(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDAttributeDeclaration) TagAttributeInfo(javax.servlet.jsp.tagext.TagAttributeInfo) TagInfo(javax.servlet.jsp.tagext.TagInfo) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) TagLibraryInfo(javax.servlet.jsp.tagext.TagLibraryInfo)

Aggregations

TagInfo (javax.servlet.jsp.tagext.TagInfo)16 TagFileInfo (javax.servlet.jsp.tagext.TagFileInfo)9 FileNotFoundException (java.io.FileNotFoundException)7 TagAttributeInfo (javax.servlet.jsp.tagext.TagAttributeInfo)5 TagLibraryInfo (javax.servlet.jsp.tagext.TagLibraryInfo)5 JasperException (org.apache.sling.scripting.jsp.jasper.JasperException)5 IOException (java.io.IOException)4 JasperException (org.apache.jasper.JasperException)4 Iterator (java.util.Iterator)3 Vector (java.util.Vector)3 TagExtraInfo (javax.servlet.jsp.tagext.TagExtraInfo)3 TreeNode (org.apache.jasper.xmlparser.TreeNode)3 Hashtable (java.util.Hashtable)2 TagVariableInfo (javax.servlet.jsp.tagext.TagVariableInfo)2 TreeNode (org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode)2 Attributes (org.xml.sax.Attributes)2 SAXException (org.xml.sax.SAXException)2 SAXParseException (org.xml.sax.SAXParseException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1