Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2012 Red Hat, Inc., and individual contributors
   * as indicated by the @author tags.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.apache.jasper.compiler;
 
 import static org.jboss.web.JasperMessages.MESSAGES;
 
 import java.net.URL;
 import java.util.Map;
 
 
Implementation of the TagLibraryInfo class from the JSP spec.

Author(s):
Anil K. Vijendran
Mandar Raje
Pierre Delisle
Kin-man Chung
Jan Luehe
 
 class TagLibraryInfoImpl extends TagLibraryInfo implements TagConstants {

    
The types of URI one may specify for a tag library
 
     public static final int ABS_URI = 0;
     public static final int ROOT_REL_URI = 1;
     public static final int NOROOT_REL_URI = 2;
 
     private JspCompilationContext ctxt;
     
     private PageInfo pi;
 
     private ErrorDispatcher err;
 
 
     private final void print(String nameString valuePrintWriter w) {
         if (value != null) {
             w.print(name + " = {\n\t");
             w.print(value);
             w.print("\n}\n");
         }
     }
 
     public String toString() {
         StringWriter sw = new StringWriter();
         PrintWriter out = new PrintWriter(sw);
         print("tlibversion"out);
         print("jspversion"out);
         print("shortname"out);
         print("urn"out);
         print("info"out);
         print("uri"out);
         print("tagLibraryValidator""" + out);
 
         for (int i = 0; i < .i++)
             out.println([i].toString());
 
         for (int i = 0; i < .i++)
             out.println([i].toString());
 
        for (int i = 0; i < .i++)
            out.println([i].toString());
        return sw.toString();
    }

    
Constructor.
            String prefixString uriInString[] locationErrorDispatcher err)
            throws JasperException {
        super(prefixuriIn);
        this. = ctxt;
        this. = pc;
        this. = pi;
        this. = err;
        
        if (location == null) {
            // The URI points to the TLD itself or to a JAR file in which the
            // TLD is stored
            location = generateTLDLocation(ctxt);
            if (location != null) {
                 = location[0];
            }
        }
        URL jarFileUrl = null;
        if (location == null) {
            err.jspError(.fileNotFound(uriIn));
        }
        if (location[0] != null && location[0].endsWith(".jar")) {
            try {
                URL jarUrl = ctxt.getServletContext().getResource(location[0]);
                if (jarUrl != null) {
                    jarFileUrl = new URL("jar:" + jarUrl + "!/");
                }
            } catch (MalformedURLException ex) {
                err.jspError(.fileNotFound(uriIn));
            }
        }
        
        org.apache.catalina.deploy.jsp.TagLibraryInfo tagLibraryInfo = 
            ((HashMap<Stringorg.apache.catalina.deploy.jsp.TagLibraryInfo>) 
        if (tagLibraryInfo == null) {
            err.jspError(.fileNotFound(uriIn));
        }
        ArrayList<TagInfotagInfos = new ArrayList<TagInfo>();
        ArrayList<TagFileInfotagFileInfos = new ArrayList<TagFileInfo>();
        HashMap<StringFunctionInfofunctionInfos = new HashMap<StringFunctionInfo>();
        this. = tagLibraryInfo.getJspversion();
        this. = tagLibraryInfo.getTlibversion();
        this. = tagLibraryInfo.getShortname();
        this. = tagLibraryInfo.getUri();
        this. = tagLibraryInfo.getInfo();
        if (tagLibraryInfo.getValidator() != null) {
            this. = createValidator(tagLibraryInfo);
        }
        org.apache.catalina.deploy.jsp.TagInfo tagInfosArray[] = tagLibraryInfo.getTags();
        for (int i = 0; i < tagInfosArray.lengthi++) {
            TagInfo tagInfo = createTagInfo(tagInfosArray[i]);
            tagInfos.add(tagInfo);
        }
        org.apache.catalina.deploy.jsp.TagFileInfo tagFileInfosArray[] = tagLibraryInfo.getTagFileInfos();
        for (int i = 0; i < tagFileInfosArray.lengthi++) {
            TagFileInfo tagFileInfo = createTagFileInfo(tagFileInfosArray[i], jarFileUrl);
            tagFileInfos.add(tagFileInfo);
        }
        org.apache.catalina.deploy.jsp.FunctionInfo functionInfosArray[] = tagLibraryInfo.getFunctionInfos();
        for (int i = 0; i < functionInfosArray.lengthi++) {
            FunctionInfo functionInfo = createFunctionInfo(functionInfosArray[i]);
            if (functionInfos.containsKey(functionInfo.getName())) {
                err.jspError(.duplicateTagLibraryFunctionName(functionInfo.getName(),
                        ));
            }
            functionInfos.put(functionInfo.getName(), functionInfo);
        }
        
        if ( == null) {
            err.jspError(.missingRequiredTagLibraryElement("tlib-version"));
        }
        if ( == null) {
            err.jspError(.missingRequiredTagLibraryElement("jsp-version"));
        }
        this. = tagInfos.toArray(new TagInfo[0]);
        this. = tagFileInfos.toArray(new TagFileInfo[0]);
        this. = functionInfos.values().toArray(new FunctionInfo[0]);
    }

    

Parameters:
uri The uri of the TLD @param ctxt The compilation context
Returns:
String array whose first element denotes the path to the TLD. If the path to the TLD points to a jar file, then the second element denotes the name of the TLD entry in the jar file, which is hardcoded to META-INF/taglib.tld.
    private String[] generateTLDLocation(String uriJspCompilationContext ctxt)
            throws JasperException {
        int uriType = uriType(uri);
        if (uriType == ) {
            .jspError(.unresolvableAbsoluteUri(uri));
        } else if (uriType == ) {
            uri = ctxt.resolveRelativeUri(uri);
            if (uri != null) {
                uri = RequestUtil.normalize(uri);
            }
        }
        String[] location = new String[2];
        location[0] = uri;
        if (location[0].endsWith("jar")) {
            URL url = null;
            try {
                url = ctxt.getResource(location[0]);
            } catch (Exception ex) {
                .jspError(.errorAccessingJar(location[0]), ex);
            }
            if (url == null) {
                .jspError(.missingJar(location[0]));
            }
            location[0] = url.toString();
            location[1] = "META-INF/taglib.tld";
        }
        return location;
    }
    public TagLibraryInfo[] getTagLibraryInfos() {
        Collection coll = .getTaglibs();
        return (TagLibraryInfo[]) coll.toArray(new TagLibraryInfo[0]);
    }
    
        throws JasperException {
        ArrayList<TagAttributeInfoattributeInfos = new ArrayList<TagAttributeInfo>();
        ArrayList<TagVariableInfovariableInfos = new ArrayList<TagVariableInfo>();
        boolean dynamicAttributes = JspUtil.booleanValue(tagInfo.getDynamicAttributes());
        org.apache.catalina.deploy.jsp.TagAttributeInfo attributeInfosArray[] = tagInfo.getTagAttributeInfos();
        for (int i = 0; i < attributeInfosArray.lengthi++) {
            TagAttributeInfo attributeInfo = createTagAttributeInfo(attributeInfosArray[i]);
            attributeInfos.add(attributeInfo);
        }
        org.apache.catalina.deploy.jsp.TagVariableInfo variableInfosArray[] = tagInfo.getTagVariableInfos();
        for (int i = 0; i < variableInfosArray.lengthi++) {
            TagVariableInfo variableInfo = createTagVariableInfo(variableInfosArray[i]);
            variableInfos.add(variableInfo);
        }
        
        TagExtraInfo tei = null;
        String teiClassName = tagInfo.getTagExtraInfo();
        if (teiClassName != null && !teiClassName.equals("")) {
            try {
                Class teiClass = .getClassLoader().loadClass(teiClassName);
                tei = (TagExtraInfoteiClass.newInstance();
            } catch (Exception e) {
                .jspError(.errorLoadingTagExtraInfo(teiClassName), e);
            }
        }
        String tagBodyContent = tagInfo.getBodyContent();
        if (tagBodyContent == null) {
            tagBodyContent = .;
        }
        return new TagInfo(tagInfo.getTagName(), tagInfo.getTagClassName(), tagBodyContent
                tagInfo.getInfoString(), thisteiattributeInfos.toArray(new TagAttributeInfo[0]), 
                tagInfo.getDisplayName(), tagInfo.getSmallIcon(), tagInfo.getLargeIcon(),
                variableInfos.toArray(new TagVariableInfo[0]), dynamicAttributes);
    }
    
        String type = attributeInfo.getType();
        String expectedType = attributeInfo.getExpectedTypeName();
        String methodSignature = attributeInfo.getMethodSignature();
        boolean rtexprvalue = JspUtil.booleanValue(attributeInfo.getReqTime());
        boolean fragment = JspUtil.booleanValue(attributeInfo.getFragment());
        boolean deferredValue = JspUtil.booleanValue(attributeInfo.getDeferredValue());
        boolean deferredMethod = JspUtil.booleanValue(attributeInfo.getDeferredMethod());
        boolean required = JspUtil.booleanValue(attributeInfo.getRequired());
        
        if (type != null) {
            if ("1.2".equals()
                    && (type.equals("Boolean") || type.equals("Byte")
                            || type.equals("Character")
                            || type.equals("Double")
                            || type.equals("Float")
                            || type.equals("Integer")
                            || type.equals("Long") || type.equals("Object")
                            || type.equals("Short") || type
                            .equals("String"))) {
                type = "java.lang." + type;
            }
        }
        if (deferredValue) {
            type = "javax.el.ValueExpression";
            if (expectedType != null) {
                expectedType = expectedType.trim();
            } else {
                expectedType = "java.lang.Object";
            }
        }
        
        if (deferredMethod) {
            type = "javax.el.MethodExpression";
            if (methodSignature != null) {
                methodSignature = methodSignature.trim();
            } else {
                methodSignature = "java.lang.Object method()";
            }
        }
        if (fragment) {
            /*
             * According to JSP.C-3 ("TLD Schema Element Structure - tag"),
             * 'type' and 'rtexprvalue' must not be specified if 'fragment' has
             * been specified (this will be enforced by validating parser).
             * Also, if 'fragment' is TRUE, 'type' is fixed at
             * javax.servlet.jsp.tagext.JspFragment, and 'rtexprvalue' is fixed
             * at true. See also JSP.8.5.2.
             */
            type = "javax.servlet.jsp.tagext.JspFragment";
            rtexprvalue = true;
        }
        if (!rtexprvalue && type == null) {
            // According to JSP spec, for static values (those determined at
            // translation time) the type is fixed at java.lang.String.
            type = "java.lang.String";
        }
        
        return new TagAttributeInfo(attributeInfo.getName(), required
                typertexprvaluefragmentattributeInfo.getDescription(), 
                deferredValuedeferredMethodexpectedType,
                methodSignature);
    }
    
        int scope = .;
        String s = variableInfo.getScope();
        if (s != null) {
            if ("NESTED".equals(s)) {
                scope = .;
            } else if ("AT_BEGIN".equals(s)) {
                scope = .;
            } else if ("AT_END".equals(s)) {
                scope = .;
            }
        }
        String className = variableInfo.getClassName();
        if (className == null) {
            className = "java.lang.String";
        }
        boolean declare = true;
        if (variableInfo.getDeclare() != null) {
            declare = JspUtil.booleanValue(variableInfo.getDeclare());
        }
        return new TagVariableInfo(variableInfo.getNameGiven(), variableInfo.getNameFromAttribute(), 
                classNamedeclarescope);
    }
    protected TagFileInfo createTagFileInfo(org.apache.catalina.deploy.jsp.TagFileInfo tagFileInfoURL jarFileUrl)
        throws JasperException {
        String name = tagFileInfo.getName();
        String path = tagFileInfo.getPath();
        if (path.startsWith("/META-INF/tags")) {
            // Tag file packaged in JAR
            // See https://issues.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
            .setTagFileJarUrl(pathjarFileUrl);
        } else if (!path.startsWith("/WEB-INF/tags")) {
            .jspError(.invalidTagFileDirectory(path));
        }
        TagInfo tagInfo = TagFileProcessor.parseTagFileDirectives(
                namepathjarFileUrlthis);
        return new TagFileInfo(namepathtagInfo);
    }
    
        return new FunctionInfo(functionInfo.getName(), 
                functionInfo.getFunctionClass(), functionInfo.getFunctionSignature());
    }
    
    
    
Returns the type of a URI: ABS_URI ROOT_REL_URI NOROOT_REL_URI
    public static int uriType(String uri) {
        if (uri.indexOf(':') != -1) {
            return ;
        } else if (uri.startsWith("/")) {
            return ;
        } else {
            return ;
        }
    }
            throws JasperException {
        org.apache.catalina.deploy.jsp.TagLibraryValidatorInfo tlvInfo = tagLibraryInfo.getValidator();
        String validatorClass = tlvInfo.getValidatorClass();
        Map<StringObjectinitParams = tlvInfo.getInitParams();
        TagLibraryValidator tlv = null;
        if (validatorClass != null && !validatorClass.equals("")) {
            try {
                Class tlvClass = .getClassLoader()
                        .loadClass(validatorClass);
                tlv = (TagLibraryValidatortlvClass.newInstance();
            } catch (Exception e) {
                .jspError(.errorLoadingTagLibraryValidator(validatorClass), e);
            }
        }
        if (tlv != null) {
            tlv.setInitParameters(initParams);
        }
        return tlv;
    }
    // *********************************************************************
    // Until javax.servlet.jsp.tagext.TagLibraryInfo is fixed

    
The instance (if any) for the TagLibraryValidator class.

Returns:
The TagLibraryValidator instance, if any.
        return ;
    }

    
Translation-time validation of the XML document associated with the JSP page. This is a convenience method on the associated TagLibraryValidator class.

Parameters:
thePage The JSP page object
Returns:
A string indicating whether the page is valid or not.
    public ValidationMessage[] validate(PageData thePage) {
        if (tlv == null)
            return null;
        String uri = getURI();
        if (uri.startsWith("/")) {
            uri =  + uri;
        }
        return tlv.validate(getPrefixString(), urithePage);
    }
New to GrepCode? Check out our FAQ X