Search in sources :

Example 1 with TagLibDescriptor

use of com.sun.enterprise.tools.verifier.TagLibDescriptor in project Payara by payara.

the class TagLibFactory method getTagLibDescriptors.

/**
 * This method is responsible for creating a document object from the tld
 * files and then returning the array TagLibDescriptor objects based on tld
 * version.
 *
 * @param descriptor the web bundle descriptor giving the tlds contained
 * in the war.
 * @return the tag lib descriptor array for all the tlds defined in the war.
 */
public TagLibDescriptor[] getTagLibDescriptors(WebBundleDescriptor descriptor) {
    ArrayList<TagLibDescriptor> tmp = new ArrayList<TagLibDescriptor>();
    Iterable<TaglibDescriptor> taglibConfig = null;
    if (((WebBundleDescriptorImpl) descriptor).getJspConfigDescriptor() != null) {
        taglibConfig = ((WebBundleDescriptorImpl) descriptor).getJspConfigDescriptor().getTaglibs();
    } else {
        return null;
    }
    init();
    for (TaglibDescriptor taglibDescriptor : taglibConfig) {
        // test all the Tag lib descriptors.
        String taglibLocation = taglibDescriptor.getTaglibLocation();
        Document d = null;
        try {
            d = createDocument(taglibLocation, descriptor);
        } catch (Exception e) {
            logger.log(Level.WARNING, smh.getLocalString(// NOI18N
            getClass().getName() + ".exception", // NOI18N
            "Continuing, though problem in creating taglib document. Cause: {0}", new Object[] { e.getMessage() }));
            if (e instanceof SAXParseException) {
                LogRecord logRecord = new LogRecord(Level.SEVERE, smh.getLocalString(// NOI18N
                getClass().getName() + ".exception2", // NOI18N
                "XML Error line : {0} in [ {1} ]. {2}", new Object[] { ((SAXParseException) e).getLineNumber(), taglibLocation, e.getLocalizedMessage() }));
                logRecord.setThrown(e);
                verifierFrameworkContext.getResultManager().log(logRecord);
            }
            // we are continuing with creating the next document.
            continue;
        }
        String version = getTLDSpecVersion(d);
        TagLibDescriptor taglib = null;
        taglib = new TagLibDescriptor(d, version, taglibLocation);
        tmp.add(taglib);
    }
    int count = tmp.size();
    TagLibDescriptor[] arr = new TagLibDescriptor[count];
    int i = 0;
    for (Iterator e = tmp.iterator(); e.hasNext(); i++) {
        arr[i] = (TagLibDescriptor) e.next();
    }
    return arr;
}
Also used : ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) WebBundleDescriptorImpl(org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl) LogRecord(java.util.logging.LogRecord) SAXParseException(org.xml.sax.SAXParseException) TagLibDescriptor(com.sun.enterprise.tools.verifier.TagLibDescriptor) Iterator(java.util.Iterator)

Example 2 with TagLibDescriptor

use of com.sun.enterprise.tools.verifier.TagLibDescriptor in project Payara by payara.

the class TagClassExtendsValidInterface method check.

public Result check(WebBundleDescriptor descriptor) {
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    VerifierTestContext context = getVerifierContext();
    Result result = loadWarFile(descriptor);
    TagLibDescriptor[] tlds = context.getTagLibDescriptors();
    boolean failed = false;
    boolean oneFailed = false;
    if (tlds == null) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "No tag lib files are specified"));
        return result;
    }
    for (TagLibDescriptor tld : tlds) {
        TagDescriptor[] tagDesc = tld.getTagDescriptors();
        for (TagDescriptor td : tagDesc) {
            String tagclass = td.getTagClass();
            Class c = loadClass(result, tagclass);
            if (c != null) {
                if (tld.getSpecVersion().trim().equalsIgnoreCase("2.0")) {
                    failed = !javax.servlet.jsp.tagext.JspTag.class.isAssignableFrom(c);
                } else {
                    failed = !javax.servlet.jsp.tagext.Tag.class.isAssignableFrom(c);
                }
                if (failed) {
                    oneFailed = true;
                    addErrorDetails(result, compName);
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: tag class [ {0} ] in [ {1} ] does not implements valid interface", new Object[] { c.getName(), tld.getUri() }));
                } else {
                    addGoodDetails(result, compName);
                    result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed1", "tag class [ {0} ] in [ {1} ] implements valid interface", new Object[] { c.getName(), tld.getUri() }));
                }
            }
        }
    // for
    }
    if (oneFailed)
        result.setStatus(Result.FAILED);
    else
        result.setStatus(Result.PASSED);
    return result;
}
Also used : TagDescriptor(com.sun.enterprise.tools.verifier.web.TagDescriptor) VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) Result(com.sun.enterprise.tools.verifier.Result) TagLibDescriptor(com.sun.enterprise.tools.verifier.TagLibDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 3 with TagLibDescriptor

use of com.sun.enterprise.tools.verifier.TagLibDescriptor in project Payara by payara.

the class TagNameIsUnique method check.

public Result check(WebBundleDescriptor descriptor) {
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    VerifierTestContext context = getVerifierContext();
    Result result = loadWarFile(descriptor);
    TagLibDescriptor[] tlds = context.getTagLibDescriptors();
    if (tlds == null) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "No tag lib files are specified"));
        return result;
    }
    for (TagLibDescriptor tld : tlds) {
        TagDescriptor[] tagDesc = tld.getTagDescriptors();
        List<String> name = new ArrayList<String>();
        for (TagDescriptor td : tagDesc) {
            name.add(td.getTagName());
        }
        if (name != null) {
            String[] names = (String[]) name.toArray(new String[0]);
            if (!checkForDuplicateNames(result, compName, names, tld)) {
                addGoodDetails(result, compName);
                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed1", "All 'name' elements are defined properly under tag element of [ {0} ]", new Object[] { tld.getUri() }));
            }
        }
    }
    if (oneFailed) {
        result.setStatus(Result.FAILED);
    } else {
        result.setStatus(Result.PASSED);
    }
    return result;
}
Also used : TagDescriptor(com.sun.enterprise.tools.verifier.web.TagDescriptor) VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) TagLibDescriptor(com.sun.enterprise.tools.verifier.TagLibDescriptor) ArrayList(java.util.ArrayList) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 4 with TagLibDescriptor

use of com.sun.enterprise.tools.verifier.TagLibDescriptor in project Payara by payara.

the class TagClassImplementsValidInterface method check.

public Result check(WebBundleDescriptor descriptor) {
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    VerifierTestContext context = getVerifierContext();
    Result result = getInitializedResult();
    ClassLoader cl = context.getClassLoader();
    TagLibDescriptor[] tlds = context.getTagLibDescriptors();
    if (tlds == null) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "No tag lib files are specified"));
        return result;
    }
    for (TagLibDescriptor tld : tlds) {
        if (tld.getSpecVersion().compareTo("2.0") >= 0) {
            for (TagDescriptor tagdesc : tld.getTagDescriptors()) {
                Class c = null;
                try {
                    c = Class.forName(tagdesc.getTagClass(), false, cl);
                } catch (ClassNotFoundException e) {
                // do nothing
                }
                if (tagdesc.getDynamicAttributes().equalsIgnoreCase("true") && !javax.servlet.jsp.tagext.DynamicAttributes.class.isAssignableFrom(c)) {
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: tag class [ {0} ] in [ {1} ] does not " + "implements interface " + "javax.servlet.jsp.tagext.DynamicAttributes", new Object[] { c.getName(), tld.getUri() }));
                }
            }
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed1", "All tag-class defined in the tag lib descriptor" + " files implement valid interface"));
    }
    return result;
}
Also used : TagDescriptor(com.sun.enterprise.tools.verifier.web.TagDescriptor) VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) TagLibDescriptor(com.sun.enterprise.tools.verifier.TagLibDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 5 with TagLibDescriptor

use of com.sun.enterprise.tools.verifier.TagLibDescriptor in project Payara by payara.

the class TaglibFunctionMethodTest method check.

public Result check(WebBundleDescriptor descriptor) {
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    Result result = getInitializedResult();
    VerifierTestContext context = getVerifierContext();
    TagLibDescriptor[] tlds = context.getTagLibDescriptors();
    FunctionDescriptor[] fnDesc = null;
    if (tlds == null) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "No tag lib files are specified"));
        return result;
    }
    for (TagLibDescriptor tld : tlds) {
        if (tld.getSpecVersion().compareTo("2.0") >= 0) {
            fnDesc = tld.getFunctionDescriptors();
            if (fnDesc != null)
                for (FunctionDescriptor fd : fnDesc) checkMethodExistence(result, fd, tld, compName);
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "All methods defined in the function-signature element" + "of the tag lib descriptor are properly defined."));
    }
    return result;
}
Also used : VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) TagLibDescriptor(com.sun.enterprise.tools.verifier.TagLibDescriptor) FunctionDescriptor(com.sun.enterprise.tools.verifier.web.FunctionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Aggregations

TagLibDescriptor (com.sun.enterprise.tools.verifier.TagLibDescriptor)8 Result (com.sun.enterprise.tools.verifier.Result)7 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)7 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)7 TagDescriptor (com.sun.enterprise.tools.verifier.web.TagDescriptor)3 FunctionDescriptor (com.sun.enterprise.tools.verifier.web.FunctionDescriptor)2 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 LogRecord (java.util.logging.LogRecord)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 WebBundleDescriptorImpl (org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl)1 Document (org.w3c.dom.Document)1 SAXException (org.xml.sax.SAXException)1 SAXParseException (org.xml.sax.SAXParseException)1