Java源码示例:javax.servlet.jsp.tagext.TagLibraryInfo

示例1
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;
}
 
示例2
/**
 * 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();
}
 
示例3
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;
   }
 
示例4
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;
}
 
示例5
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;
}
 
示例6
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);
}
 
示例7
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;
}
 
示例8
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);
}
 
示例9
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);
}
 
示例10
/**
 * 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;
}
 
示例11
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]);
    }
 
示例12
@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);
    }
}
 
示例13
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<>();
}
 
示例14
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();
}
 
示例15
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();
}
 
示例16
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);
    }
}
 
示例17
/**************************************************************************/
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;
}
 
示例18
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;
    }
}
 
示例19
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;
}
 
示例20
@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);
    }
}
 
示例21
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>();
}
 
示例22
@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);
    }
}
 
示例23
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>();
}
 
示例24
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());
}
 
示例25
/**
 * {@inheritDoc}
 */
@Override
public Map<String, TagLibraryInfo> getCache() {
    return cache;
}
 
示例26
@Override
public Map<String, TagLibraryInfo> getCache() {
    return null;
}
 
示例27
/**
 * Validate XML view against the TagLibraryValidator classes of all imported
 * tag libraries.
 */
private static void validateXmlView(PageData xmlView, Compiler compiler)
        throws JasperException {

    StringBuilder errMsg = null;
    ErrorDispatcher errDisp = compiler.getErrorDispatcher();

    for (Iterator<TagLibraryInfo> 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 StringBuilder();
            }
            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());
    }
}
 
示例28
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;
}
 
示例29
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;
}
 
示例30
@Override
public TagLibraryInfo[] getTagLibraryInfos() {
    Collection<TagLibraryInfo> coll = pi.getTaglibs();
    return coll.toArray(new TagLibraryInfo[0]);
}