javax.servlet.jsp.tagext.TagLibraryInfo Java Examples

The following examples show how to use javax.servlet.jsp.tagext.TagLibraryInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PageInfo.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
PageInfo(BeanRepository beanRepository, String jspFile) {

        this.jspFile = jspFile;
	this.beanRepository = beanRepository;
	this.taglibsMap = new HashMap<String, TagLibraryInfo>();
	this.jspPrefixMapper = new HashMap<String, String>();
	this.xmlPrefixMapper = new HashMap<String, LinkedList<String>>();
        this.nonCustomTagPrefixMap = new HashMap<String, Mark>();
	this.imports = new ArrayList<String>();
        this.dependants = new ArrayList<String>();
	this.includePrelude = new ArrayList<String>();
	this.includeCoda = new ArrayList<String>();
	this.pluginDcls = new ArrayList<String>();
	this.prefixes = new HashSet<String>();

	// Enter standard imports
	for(int i = 0; i < STANDARD_IMPORTS.length; i++)
	    imports.add(STANDARD_IMPORTS[i]);
    }
 
Example #2
Source File: PageInfo.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public PageInfo(/*BeanRepository beanRepository*/
           Map<String, TagLibraryInfo> taglibsMap,
           Map<String, String> jspPrefixMapper,
           Map<String, LinkedList<String>> xmlPrefixMapper,
           Map approxXmlPrefixMapper,
           List<String> imports,
           List<String> dependants,
           List includePrelude,
           List includeCoda,
           List<String> pluginDcls,
           Set<String> prefixes
       ) {
//this.beanRepository = beanRepository;
this.taglibsMap = taglibsMap;
this.jspPrefixMapper = jspPrefixMapper;
this.xmlPrefixMapper = xmlPrefixMapper;
       this.approxXmlPrefixMapper = approxXmlPrefixMapper;
this.imports = imports;
       this.dependants = dependants;
this.includePrelude = includePrelude;
this.includeCoda = includeCoda;
this.pluginDcls = pluginDcls;
this.prefixes = prefixes;
       this.isTagFile = false;
   }
 
Example #3
Source File: TagFileProcessor.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Parses the tag file, and collects information on the directives included
 * in it. The method is used to obtain the info on the tag file, when the
 * handler that it represents is referenced. The tag file is not compiled
 * here.
 *
 * @param pc
 *            the current ParserController used in this compilation
 * @param name
 *            the tag name as specified in the TLD
 * @param path
 *            the path for the tagfile
 * @param jar
 *            the Jar resource containing the tag file
 * @param tagLibInfo
 *            the TagLibraryInfo object associated with this TagInfo
 * @return a TagInfo object assembled from the directives in the tag file.
 *
 * @throws JasperException If an error occurs during parsing
 */
@SuppressWarnings("null") // page can't be null
public static TagInfo parseTagFileDirectives(ParserController pc,
        String name, String path, Jar jar, TagLibraryInfo tagLibInfo)
        throws JasperException {


    ErrorDispatcher err = pc.getCompiler().getErrorDispatcher();

    Node.Nodes page = null;
    try {
        page = pc.parseTagFileDirectives(path, jar);
    } catch (IOException e) {
        err.jspError("jsp.error.file.not.found", path);
    }

    TagFileDirectiveVisitor tagFileVisitor = new TagFileDirectiveVisitor(pc
            .getCompiler(), tagLibInfo, name, path);
    page.visit(tagFileVisitor);
    tagFileVisitor.postCheck();

    return tagFileVisitor.getTagInfo();
}
 
Example #4
Source File: JspHyperlinkProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private FileObject getTagFile(TokenSequence<?> tokenSequence, JspSyntaxSupport jspSup) {
    Token token = tokenSequence.token();
    if (token.id() == JspTokenId.TAG) {
        String image = token.text().toString().trim();
        if (image.startsWith("<")) {                                 // NOI18N
            image = image.substring(1).trim();
        }
        if (!image.startsWith("jsp:") && image.indexOf(':') != -1) {  // NOI18N
            List l = jspSup.getTags(image);
            if (l.size() == 1) {
                TagLibraryInfo libInfo = ((TagInfo) l.get(0)).getTagLibrary();
                if (libInfo != null) {
                    TagFileInfo fileInfo = libInfo.getTagFile(getTagName(image));
                    if (fileInfo != null) {
                        return JspUtils.getFileObject(jspSup.getDocument(),
                                fileInfo.getPath());
                    }
                }
            }
        }
    }
    return null;
}
 
Example #5
Source File: JasperTagInfo.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
public JasperTagInfo(String tagName,
        String tagClassName,
        String bodyContent,
        String infoString,
        TagLibraryInfo taglib,
        TagExtraInfo tagExtraInfo,
        TagAttributeInfo[] attributeInfo,
        String displayName,
        String smallIcon,
        String largeIcon,
        TagVariableInfo[] tvi,
        String mapName) {

    super(tagName, tagClassName, bodyContent, infoString, taglib,
            tagExtraInfo, attributeInfo, displayName, smallIcon, largeIcon,
            tvi);
    
    this.dynamicAttrsMapName = mapName;
}
 
Example #6
Source File: PageInfo.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
PageInfo(BeanRepository beanRepository, String jspFile, boolean isTagFile) {
    this.isTagFile = isTagFile;
    this.jspFile = jspFile;
    this.beanRepository = beanRepository;
    this.varInfoNames = new HashSet<String>();
    this.taglibsMap = new HashMap<String, TagLibraryInfo>();
    this.jspPrefixMapper = new HashMap<String, String>();
    this.xmlPrefixMapper = new HashMap<String, LinkedList<String>>();
    this.nonCustomTagPrefixMap = new HashMap<String, Mark>();
    this.imports = new Vector<String>();
    this.dependants = new HashMap<String,Long>();
    this.includePrelude = new Vector<String>();
    this.includeCoda = new Vector<String>();
    this.pluginDcls = new Vector<String>();
    this.prefixes = new HashSet<String>();

    // Enter standard imports
    imports.addAll(Constants.STANDARD_IMPORTS);
}
 
Example #7
Source File: JasperTagInfo.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public JasperTagInfo(String tagName,
        String tagClassName,
        String bodyContent,
        String infoString,
        TagLibraryInfo taglib,
        TagExtraInfo tagExtraInfo,
        TagAttributeInfo[] attributeInfo,
        String displayName,
        String smallIcon,
        String largeIcon,
        TagVariableInfo[] tvi,
        String mapName) {

    super(tagName, tagClassName, bodyContent, infoString, taglib,
            tagExtraInfo, attributeInfo, displayName, smallIcon, largeIcon,
            tvi);

    this.dynamicAttrsMapName = mapName;
}
 
Example #8
Source File: JasperTagInfo.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
public JasperTagInfo(String tagName,
        String tagClassName,
        String bodyContent,
        String infoString,
        TagLibraryInfo taglib,
        TagExtraInfo tagExtraInfo,
        TagAttributeInfo[] attributeInfo,
        String displayName,
        String smallIcon,
        String largeIcon,
        TagVariableInfo[] tvi,
        String mapName) {

    super(tagName, tagClassName, bodyContent, infoString, taglib,
            tagExtraInfo, attributeInfo, displayName, smallIcon, largeIcon,
            tvi);
    
    this.dynamicAttrsMapName = mapName;
}
 
Example #9
Source File: PageInfo.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
PageInfo(BeanRepository beanRepository, String jspFile, boolean isTagFile) {
    this.isTagFile = isTagFile;
    this.jspFile = jspFile;
    this.beanRepository = beanRepository;
    this.varInfoNames = new HashSet<String>();
    this.taglibsMap = new HashMap<String, TagLibraryInfo>();
    this.jspPrefixMapper = new HashMap<String, String>();
    this.xmlPrefixMapper = new HashMap<String, LinkedList<String>>();
    this.nonCustomTagPrefixMap = new HashMap<String, Mark>();
    this.imports = new Vector<String>();
    this.dependants = new HashMap<String,Long>();
    this.includePrelude = new Vector<String>();
    this.includeCoda = new Vector<String>();
    this.pluginDcls = new Vector<String>();
    this.prefixes = new HashSet<String>();

    // Enter standard imports
    imports.addAll(Constants.STANDARD_IMPORTS);
}
 
Example #10
Source File: JspC.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
private void initServletContext() {
    try {
        context =new JspCServletContext
            (new PrintWriter(new OutputStreamWriter(System.out, "UTF-8")),

             new URL("file:" + uriRoot.replace('\\','/') + '/'));
        tldScanner = new TldScanner(context, isValidationEnabled);

        // START GlassFish 750
        taglibs = new ConcurrentHashMap<String, TagLibraryInfo>();
        context.setAttribute(Constants.JSP_TAGLIBRARY_CACHE, taglibs);

        tagFileJarUrls = new ConcurrentHashMap<String, URL>();
        context.setAttribute(Constants.JSP_TAGFILE_JAR_URLS_CACHE,
                             tagFileJarUrls);
        // END GlassFish 750
    } catch (MalformedURLException me) {
        System.out.println("**" + me);
    } catch (UnsupportedEncodingException ex) {
    }
    rctxt = new JspRuntimeContext(context, this);
    jspConfig = new JspConfig(context);
    tagPluginManager = new TagPluginManager(context);
}
 
Example #11
Source File: ImplicitTagLibraryInfo.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns an array of TagLibraryInfo objects representing the entire set
 * of tag libraries (including this TagLibraryInfo) imported by taglib
 * directives in the translation unit that references this
 * TagLibraryInfo.
 *
 * If a tag library is imported more than once and bound to different
 * prefices, only the TagLibraryInfo bound to the first prefix must be
 * included in the returned array.
 *
 * @return Array of TagLibraryInfo objects representing the entire set
 * of tag libraries (including this TagLibraryInfo) imported by taglib
 * directives in the translation unit that references this TagLibraryInfo.
 *
 * @since 2.1
 */
public TagLibraryInfo[] getTagLibraryInfos() {

    TagLibraryInfo[] taglibs = null;

    Collection c = pageInfo.getTaglibs();
    if (c != null) {
        Object[] objs = c.toArray();
        if (objs != null && objs.length > 0) {
            taglibs = new TagLibraryInfo[objs.length];
            for (int i=0; i<objs.length; i++) {
                taglibs[i] = (TagLibraryInfo) objs[i];
            }
        }
    }

    return taglibs;
}
 
Example #12
Source File: JspPaletteUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**************************************************************************/
public static String getTagLibPrefix(JTextComponent target, String tagLibUri) {
    FileObject fobj = getFileObject(target);
    if (fobj != null) {
        JspParserAPI.ParseResult result = JspContextInfo.getContextInfo(fobj).getCachedParseResult(fobj, false, true);
        if (result != null && result.getPageInfo() != null) {
             for (TagLibraryInfo tli : result.getPageInfo().getTaglibs()) {
                 if (tagLibUri.equals(tli.getURI()))
                     return tli.getPrefixString();
             }
        }
    }
    return null;
}
 
Example #13
Source File: PageInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public String tagLibraryInfoToString(TagLibraryInfo info, String indent) {
    StringBuilder sb = new StringBuilder();
    sb.append(indent).append("tlibversion : ").append(getFieldByReflection("tlibversion", info)).append('\n');  // NOI18N
    sb.append(indent).append("jspversion  : ").append(info.getRequiredVersion()).append('\n');  // NOI18N
    sb.append(indent).append("shortname   : ").append(info.getShortName()).append('\n');  // NOI18N
    sb.append(indent).append("urn         : ").append(info.getReliableURN()).append('\n');  // NOI18N
    sb.append(indent).append("info        : ").append(info.getInfoString()).append('\n');  // NOI18N
    sb.append(indent).append("uri         : ").append(info.getURI()).append('\n');  // NOI18N
    
    TagInfo tags[] = info.getTags();
    if (tags != null) {
        for (int i = 0; i < tags.length; i++)
            sb.append(tagInfoToString(tags[i], indent + "  "));  // NOI18N
    }
    
    TagFileInfo tagFiles[] = info.getTagFiles().clone();
    Arrays.sort(tagFiles, TAG_FILE_INFO_COMPARATOR);
    if (tagFiles != null) {
        for (int i = 0; i < tagFiles.length; i++)
            sb.append(tagFileToString(tagFiles[i], indent + "  "));  // NOI18N
    }
    
    FunctionInfo functions[] = info.getFunctions();
    if (functions != null) {
        for (int i = 0; i < functions.length; i++)
            sb.append(functionInfoToString(functions[i], indent + "  "));  // NOI18N
    }
    
    return sb.toString();
}
 
Example #14
Source File: TagFileProcessor.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public TagFileDirectiveVisitor(Compiler compiler,
        TagLibraryInfo tagLibInfo, String name, String path) {
    err = compiler.getErrorDispatcher();
    this.tagLibInfo = tagLibInfo;
    this.name = name;
    this.path = path;
    attributeVector = new Vector<>();
    variableVector = new Vector<>();
}
 
Example #15
Source File: JspDocumentParser.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void startPrefixMapping(String prefix, String uri)
    throws SAXException {
    TagLibraryInfo taglibInfo;

    if (directivesOnly && !(JSP_URI.equals(uri))) {
        return;
    }

    try {
        taglibInfo = getTaglibInfo(prefix, uri);
    } catch (JasperException je) {
        throw new SAXParseException(
            Localizer.getMessage("jsp.error.could.not.add.taglibraries"),
            locator,
            je);
    }

    if (taglibInfo != null) {
        if (pageInfo.getTaglib(uri) == null) {
            pageInfo.addTaglib(uri, taglibInfo);
        }
        pageInfo.pushPrefixMapping(prefix, uri);
    } else {
        pageInfo.pushPrefixMapping(prefix, null);
    }
}
 
Example #16
Source File: PageInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private String taglibsMapToString(Map m, String indent) {
    StringBuilder sb = new StringBuilder();
    Iterator it = new TreeSet(m.keySet()).iterator();
    while (it.hasNext()) {
        Object key = it.next();
        sb.append(indent).append("tag library: ").append(key).append('\n');  // NOI18N
        sb.append(tagLibraryInfoToString((TagLibraryInfo)m.get(key), indent + "    "));  // NOI18N
    }
    return sb.toString();
}
 
Example #17
Source File: CacheTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void xxxtestCachedTagLibInfos() throws Exception {
    JspParserImpl jspParser = getJspParser();

    FileObject jspFo = TestUtil.getProjectFile(this, "project2", "/web/basic.jspx");
    WebModule webModule = TestUtil.getWebModule(jspFo);

    ParseResult result = jspParser.analyzePage(jspFo, webModule, JspParserAPI.ERROR_IGNORE);
    Collection<TagLibraryInfo> tagLibs1 = result.getPageInfo().getTaglibs();

    jspFo = TestUtil.getProjectFile(this, "project2", "/web/basic.jspx");
    result = jspParser.analyzePage(jspFo, webModule, JspParserAPI.ERROR_IGNORE);
    Collection<TagLibraryInfo> tagLibs2 = result.getPageInfo().getTaglibs();

    assertTrue(tagLibs1.size() > 0);
    assertTrue(tagLibs2.size() > 0);
    assertTrue(tagLibs1.size() == tagLibs2.size());

    Iterator<TagLibraryInfo> iter1 = tagLibs1.iterator();
    Iterator<TagLibraryInfo> iter2 = tagLibs2.iterator();
    while (iter1.hasNext()) {
        TagLibraryInfo tagLibraryInfo1 = iter1.next();
        TagLibraryInfo tagLibraryInfo2 = iter2.next();
        assertNotNull(tagLibraryInfo1);
        assertNotNull(tagLibraryInfo2);
        assertTrue("TagLibInfos should be exactly the same", tagLibraryInfo1 == tagLibraryInfo2);
    }
}
 
Example #18
Source File: JspDocumentParser.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public void startPrefixMapping(String prefix, String uri)
    throws SAXException {
    TagLibraryInfo taglibInfo;

    if (directivesOnly && !(JSP_URI.equals(uri))) {
        return;
    }

    try {
        taglibInfo = getTaglibInfo(prefix, uri);
    } catch (JasperException je) {
        throw new SAXParseException(
            Localizer.getMessage("jsp.error.could.not.add.taglibraries"),
            locator,
            je);
    }

    if (taglibInfo != null) {
        if (pageInfo.getTaglib(uri) == null) {
            pageInfo.addTaglib(uri, taglibInfo);
        }
        pageInfo.pushPrefixMapping(prefix, uri);
    } else {
        pageInfo.pushPrefixMapping(prefix, null);
    }
}
 
Example #19
Source File: JspColoringData.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean equalsColoringInformation(Map taglibs1, Map prefixMapper1, Map taglibs2, Map prefixMapper2) {
    if ((taglibs1 == null) != (taglibs2 == null)) {
        return false;
    }
    if ((prefixMapper1 == null) != (prefixMapper2 == null)) {
        return false;
    }
    if (prefixMapper1.size() != prefixMapper2.size()) {
        return false;
    }
    else {
        Iterator it = prefixMapper1.keySet().iterator();
        while (it.hasNext()) {
            Object prefix = it.next();
            Object key1 = prefixMapper1.get(prefix);
            Object key2 = prefixMapper2.get(prefix);
            if ((key1 == null) || (key2 == null)) {
                return false;
            }
            TagLibraryInfo tli1 = (TagLibraryInfo)taglibs1.get(key1);
            TagLibraryInfo tli2 = (TagLibraryInfo)taglibs2.get(key2);
            if ((tli1 == null) || (tli2 == null)) {
                return false;
            }
            if (!equalsColoringInformation(tli1, tli2)) {
                return false;
            }
        }
        return true;
    }
}
 
Example #20
Source File: JspColoringData.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean equalsColoringInformation(TagLibraryInfo tli1, TagLibraryInfo tli2) {
    /** PENDING
     * should be going through all tags and checking whether the value 
     * returned by tagInfo.getBodyContent() has not changed.
     */
    return true;
}
 
Example #21
Source File: TagFileProcessor.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public TagFileDirectiveVisitor(Compiler compiler,
                               TagLibraryInfo tagLibInfo,
                               String name,
                               String path) {
    err = compiler.getErrorDispatcher();
    this.tagLibInfo = tagLibInfo;
    this.name = name;
    this.path = path;
    attributeVector = new ArrayList<TagAttributeInfo>();
    variableVector = new ArrayList<TagVariableInfo>();

    jspVersionDouble = Double.valueOf(tagLibInfo.getRequiredVersion());
}
 
Example #22
Source File: JspDocumentParser.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public void startPrefixMapping(String prefix, String uri)
    throws SAXException {
    TagLibraryInfo taglibInfo;

    if (directivesOnly && !(JSP_URI.equals(uri))) {
        return;
    }

    try {
        taglibInfo = getTaglibInfo(prefix, uri);
    } catch (JasperException je) {
        throw new SAXParseException(
            Localizer.getMessage("jsp.error.could.not.add.taglibraries"),
            locator,
            je);
    }

    if (taglibInfo != null) {
        if (pageInfo.getTaglib(uri) == null) {
            pageInfo.addTaglib(uri, taglibInfo);
        }
        pageInfo.pushPrefixMapping(prefix, uri);
    } else {
        pageInfo.pushPrefixMapping(prefix, null);
    }
}
 
Example #23
Source File: TagFileProcessor.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public TagFileDirectiveVisitor(Compiler compiler,
        TagLibraryInfo tagLibInfo, String name, String path) {
    err = compiler.getErrorDispatcher();
    this.tagLibInfo = tagLibInfo;
    this.name = name;
    this.path = path;
    attributeVector = new Vector<TagAttributeInfo>();
    variableVector = new Vector<TagVariableInfo>();
}
 
Example #24
Source File: TagFileProcessor.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public TagFileDirectiveVisitor(Compiler compiler,
        TagLibraryInfo tagLibInfo, String name, String path) {
    err = compiler.getErrorDispatcher();
    this.tagLibInfo = tagLibInfo;
    this.name = name;
    this.path = path;
    attributeVector = new Vector<TagAttributeInfo>();
    variableVector = new Vector<TagVariableInfo>();
}
 
Example #25
Source File: JspDocumentParser.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
private Node parseCustomAction(
    String qName,
    String localName,
    String uri,
    Attributes nonTaglibAttrs,
    Attributes nonTaglibXmlnsAttrs,
    Attributes taglibAttrs,
    Mark start,
    Node parent)
    throws SAXException {

    // Check if this is a user-defined (custom) tag
    TagLibraryInfo tagLibInfo = pageInfo.getTaglib(uri);
    if (tagLibInfo == null) {
        return null;
    }

    TagInfo tagInfo = tagLibInfo.getTag(localName);
    TagFileInfo tagFileInfo = tagLibInfo.getTagFile(localName);
    if (tagInfo == null && tagFileInfo == null) {
        throw new SAXParseException(
            Localizer.getMessage("jsp.error.xml.bad_tag", localName, uri),
            locator);
    }
    Class<?> tagHandlerClass = null;
    if (tagInfo != null) {
        String handlerClassName = tagInfo.getTagClassName();
        try {
            tagHandlerClass =
                ctxt.getClassLoader().loadClass(handlerClassName);
        } catch (Exception e) {
            throw new SAXParseException(
                Localizer.getMessage("jsp.error.loadclass.taghandler",
                                     handlerClassName,
                                     qName),
                locator, e);
        }
    }

    String prefix = getPrefix(qName);

    Node.CustomTag ret = null;
    if (tagInfo != null) {
        ret =
            new Node.CustomTag(
                qName,
                prefix,
                localName,
                uri,
                nonTaglibAttrs,
                nonTaglibXmlnsAttrs,
                taglibAttrs,
                start,
                parent,
                tagInfo,
                tagHandlerClass);
    } else {
        ret =
            new Node.CustomTag(
                qName,
                prefix,
                localName,
                uri,
                nonTaglibAttrs,
                nonTaglibXmlnsAttrs,
                taglibAttrs,
                start,
                parent,
                tagFileInfo);
    }

    return ret;
}
 
Example #26
Source File: JspDocumentParser.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
private TagLibraryInfo getTaglibInfo(String prefix, String uri)
    throws JasperException {

    TagLibraryInfo result = null;

    if (uri.startsWith(URN_JSPTAGDIR)) {
        // uri (of the form "urn:jsptagdir:path") references tag file dir
        String tagdir = uri.substring(URN_JSPTAGDIR.length());
        result =
            new ImplicitTagLibraryInfo(
                ctxt,
                parserController,
                pageInfo,
                prefix,
                tagdir,
                err);
    } else {
        // uri references TLD file
        boolean isPlainUri = false;
        if (uri.startsWith(URN_JSPTLD)) {
            // uri is of the form "urn:jsptld:path"
            uri = uri.substring(URN_JSPTLD.length());
        } else {
            isPlainUri = true;
        }

        TldResourcePath tldResourcePath = ctxt.getTldResourcePath(uri);
        if (tldResourcePath != null || !isPlainUri) {
            if (ctxt.getOptions().isCaching()) {
                result = ctxt.getOptions().getCache().get(uri);
            }
            if (result == null) {
                /*
                 * If the uri value is a plain uri, a translation error must
                 * not be generated if the uri is not found in the taglib map.
                 * Instead, any actions in the namespace defined by the uri
                 * value must be treated as uninterpreted.
                 */
                result =
                    new TagLibraryInfoImpl(
                        ctxt,
                        parserController,
                        pageInfo,
                        prefix,
                        uri,
                        tldResourcePath,
                        err);
                if (ctxt.getOptions().isCaching()) {
                    ctxt.getOptions().getCache().put(uri, result);
                }
            }
        }
    }

    return result;
}
 
Example #27
Source File: Parser.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
private boolean parseCustomTag(Node parent) throws JasperException {

        if (reader.peekChar() != '<') {
            return false;
        }

        // Parse 'CustomAction' production (tag prefix and custom action name)
        reader.nextChar(); // skip '<'
        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;
    }
 
Example #28
Source File: TagLibraryInfoImpl.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public TagLibraryInfo[] getTagLibraryInfos() {
    Collection<TagLibraryInfo> coll = pi.getTaglibs();
    return coll.toArray(new TagLibraryInfo[0]);
}
 
Example #29
Source File: ImplicitTagLibraryInfo.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public TagLibraryInfo[] getTagLibraryInfos() {
    Collection<TagLibraryInfo> coll = pi.getTaglibs();
    return coll.toArray(new TagLibraryInfo[0]);
}
 
Example #30
Source File: PageInfo.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public void addTaglib(String uri, TagLibraryInfo info) {
    taglibsMap.put(uri, info);
}