Package org.xml.sax

Examples of org.xml.sax.Attributes


            TagInfo tagInfo = n.getTagInfo();
            if (tagInfo == null) {
                err.jspError(n, "jsp.error.missing.tagInfo", n.getQName());
            }
            TagAttributeInfo[] tldAttrs = tagInfo.getAttributes();
            Attributes attrs = n.getAttributes();

            boolean checkDeferred = !pageInfo.isDeferredSyntaxAllowedAsLiteral()
                && !(tagInfo.getTagLibrary().getRequiredVersion().equals("2.0")
                        || tagInfo.getTagLibrary().getRequiredVersion().equals("1.2"));

            for (int i = 0; attrs != null && i < attrs.getLength(); i++) {
                boolean found = false;
               
                boolean runtimeExpression = ((n.getRoot().isXmlSyntax() && attrs.getValue(i).startsWith("%="))
                        || (!n.getRoot().isXmlSyntax() && attrs.getValue(i).startsWith("<%=")));
                boolean elExpression = false;
                boolean deferred = false;
                boolean deferredValueIsLiteral = false;

                ELNode.Nodes el = null;
                if (!runtimeExpression) {
                    el = ELParser.parse(attrs.getValue(i));
                    Iterator<ELNode> nodes = el.iterator();
                    while (nodes.hasNext()) {
                        ELNode node = nodes.next();
                        if (node instanceof ELNode.Root) {
                            if (((ELNode.Root) node).getType() == '$') {
                                elExpression = true;
                            } else if (checkDeferred && ((ELNode.Root) node).getType() == '#') {
                                elExpression = true;
                                deferred = true;
                                if (pageInfo.isELIgnored()) {
                                    deferredValueIsLiteral = true;
                                }
                            }
                        }
                    }
                }

                boolean expression = runtimeExpression || (elExpression  && !pageInfo.isELIgnored());
               
                for (int j = 0; tldAttrs != null && j < tldAttrs.length; j++) {
                    if (attrs.getLocalName(i).equals(tldAttrs[j].getName())
                            && (attrs.getURI(i) == null
                                    || attrs.getURI(i).length() == 0 || attrs
                                    .getURI(i).equals(n.getURI()))) {
                       
                        if (tldAttrs[j].canBeRequestTime()
                                || tldAttrs[j].isDeferredMethod() || tldAttrs[j].isDeferredValue()) { // JSP 2.1
                           
                            if (!expression) {
                               
                                if (deferredValueIsLiteral && !pageInfo.isDeferredSyntaxAllowedAsLiteral()) {
                                    err.jspError(n, "jsp.error.attribute.custom.non_rt_with_expr",
                                            tldAttrs[j].getName());
                                }
                               
                                String expectedType = null;
                                if (tldAttrs[j].isDeferredMethod()) {
                                    // The String litteral must be castable to what is declared as type
                                    // for the attribute
                                    String m = tldAttrs[j].getMethodSignature();
                                    if (m != null) {
                                        int rti = m.trim().indexOf(' ');
                                        if (rti > 0) {
                                            expectedType = m.substring(0, rti).trim();
                                        }
                                    } else {
                                        expectedType = "java.lang.Object";
                                    }
                                }
                                if (tldAttrs[j].isDeferredValue()) {
                                    // The String litteral must be castable to what is declared as type
                                    // for the attribute
                                    expectedType = tldAttrs[j].getExpectedTypeName();
                                }
                                if (expectedType != null) {
                                    Class expectedClass = String.class;
                                    try {
                                        expectedClass = JspUtil.toClass(expectedType, loader);
                                    } catch (ClassNotFoundException e) {
                                        err.jspError
                                            (n, "jsp.error.unknown_attribute_type",
                                             tldAttrs[j].getName(), expectedType);
                                    }
                                    // Check casting
                                    try {
                                        ELSupport.checkType(attrs.getValue(i), expectedClass);
                                    } catch (Exception e) {
                                        err.jspError
                                            (n, "jsp.error.coerce_to_type",
                                             tldAttrs[j].getName(), expectedType, attrs.getValue(i));
                                    }
                                }

                                jspAttrs[i] = new Node.JspAttribute(tldAttrs[j],
                                        attrs.getQName(i), attrs.getURI(i), attrs
                                                .getLocalName(i),
                                        attrs.getValue(i), false, null, false);
                            } else {
                               
                                if (deferred && !tldAttrs[j].isDeferredMethod() && !tldAttrs[j].isDeferredValue()) {
                                    // No deferred expressions allowed for this attribute
                                    err.jspError(n, "jsp.error.attribute.custom.non_rt_with_expr",
                                            tldAttrs[j].getName());
                                }
                                if (!deferred && !tldAttrs[j].canBeRequestTime()) {
                                    // Only deferred expressions are allowed for this attribute
                                    err.jspError(n, "jsp.error.attribute.custom.non_rt_with_expr",
                                            tldAttrs[j].getName());
                                }
                               
                                Class expectedType = String.class;
                                try {
                                    String typeStr = tldAttrs[j].getTypeName();
                                    if (tldAttrs[j].isFragment()) {
                                        expectedType = JspFragment.class;
                                    } else if (typeStr != null) {
                                        expectedType = JspUtil.toClass(typeStr,
                                                loader);
                                    }
                                    jspAttrs[i] = getJspAttribute(tldAttrs[j],
                                            attrs.getQName(i), attrs.getURI(i),
                                            attrs.getLocalName(i), attrs
                                            .getValue(i), expectedType, n,
                                            false);
                                } catch (ClassNotFoundException e) {
                                    err.jspError
                                        (n, "jsp.error.unknown_attribute_type",
                                         tldAttrs[j].getName(), tldAttrs[j].getTypeName());
                                }
                            }
                           
                        } else {
                            // Attribute does not accept any expressions.
                            // Make sure its value does not contain any.
                            if (expression) {
                                err.jspError(n, "jsp.error.attribute.custom.non_rt_with_expr",
                                                tldAttrs[j].getName());
                            }
                            jspAttrs[i] = new Node.JspAttribute(tldAttrs[j],
                                    attrs.getQName(i), attrs.getURI(i), attrs
                                            .getLocalName(i),
                                    attrs.getValue(i), false, null, false);
                        }
                        if (jspAttrs[i].isExpression()) {
                            tagDataAttrs.put(attrs.getQName(i),
                                    TagData.REQUEST_TIME_VALUE);
                        } else {
                            tagDataAttrs.put(attrs.getQName(i), attrs
                                    .getValue(i));
                        }
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    if (tagInfo.hasDynamicAttributes()) {
                        jspAttrs[i] = getJspAttribute(null, attrs.getQName(i),
                                attrs.getURI(i), attrs.getLocalName(i), attrs
                                        .getValue(i), java.lang.Object.class,
                                n, true);
                    } else {
                        err.jspError(n, "jsp.error.bad_attribute", attrs
                                .getQName(i), n.getLocalName());
                    }
                }
            }
        }
View Full Code Here


        }

        private String findUri(String prefix, Node n) {

            for (Node p = n; p != null; p = p.getParent()) {
                Attributes attrs = p.getTaglibAttributes();
                if (attrs == null) {
                    continue;
                }
                for (int i = 0; i < attrs.getLength(); i++) {
                    String name = attrs.getQName(i);
                    int k = name.indexOf(':');
                    if (prefix == null && k < 0) {
                        // prefix not specified and a default ns found
                        return attrs.getValue(i);
                    }
                    if (prefix != null && k >= 0
                            && prefix.equals(name.substring(k + 1))) {
                        return attrs.getValue(i);
                    }
                }
            }
            return null;
        }
View Full Code Here

            JspUtil.checkAttributes("Page directive", n, pageDirectiveAttrs,
                    err);

            // JSP.2.10.1
            Attributes attrs = n.getAttributes();
            for (int i = 0; attrs != null && i < attrs.getLength(); i++) {
                String attr = attrs.getQName(i);
                String value = attrs.getValue(i);

                if ("language".equals(attr)) {
                    if (pageInfo.getLanguage(false) == null) {
                        pageInfo.setLanguage(value, n, err, true);
                    } else if (!pageInfo.getLanguage(false).equals(value)) {
View Full Code Here

            // when it created a TagInfo object from the
            // tag file in which the directive appeared.

            // This method does additional processing to collect page info

            Attributes attrs = n.getAttributes();
            for (int i = 0; attrs != null && i < attrs.getLength(); i++) {
                String attr = attrs.getQName(i);
                String value = attrs.getValue(i);

                if ("language".equals(attr)) {
                    if (pageInfo.getLanguage(false) == null) {
                        pageInfo.setLanguage(value, n, err, false);
                    } else if (!pageInfo.getLanguage(false).equals(value)) {
View Full Code Here

    /*
     * Parses a page directive with the following syntax: PageDirective ::= ( S
     * Attribute)*
     */
    private void parsePageDirective(Node parent) throws JasperException {
        Attributes attrs = parseAttributes();
        Node.PageDirective n = new Node.PageDirective(attrs, start, parent);

        /*
         * A page directive may contain multiple 'import' attributes, each of
         * which consists of a comma-separated list of package names. Store each
         * list with the node, where it is parsed.
         */
        for (int i = 0; i < attrs.getLength(); i++) {
            if ("import".equals(attrs.getQName(i))) {
                n.addImport(attrs.getValue(i));
            }
        }
    }
View Full Code Here

    /*
     * Parses an include directive with the following syntax: IncludeDirective
     * ::= ( S Attribute)*
     */
    private void parseIncludeDirective(Node parent) throws JasperException {
        Attributes attrs = parseAttributes();

        // Included file expanded here
        Node includeNode = new Node.IncludeDirective(attrs, start, parent);
        processIncludeDirective(attrs.getValue("file"), includeNode);
    }
View Full Code Here

     * Parses a taglib directive with the following syntax: Directive ::= ( S
     * Attribute)*
     */
    private void parseTaglibDirective(Node parent) throws JasperException {

        Attributes attrs = parseAttributes();
        String uri = attrs.getValue("uri");
        String prefix = attrs.getValue("prefix");
        if (prefix != null) {
            Mark prevMark = pageInfo.getNonCustomTagPrefix(prefix);
            if (prevMark != null) {
                err.jspError(reader.mark(), "jsp.error.prefix.use_before_dcl",
                        prefix, prevMark.getFile(), ""
                                + prevMark.getLineNumber());
            }
            if (uri != null) {
                String uriPrev = pageInfo.getURI(prefix);
                if (uriPrev != null && !uriPrev.equals(uri)) {
                    err.jspError(reader.mark(), "jsp.error.prefix.refined",
                            prefix, uri, uriPrev);
                }
                if (pageInfo.getTaglib(uri) == null) {
                    TagLibraryInfoImpl impl = null;
                    if (ctxt.getOptions().isCaching()) {
                        impl = (TagLibraryInfoImpl) ctxt.getOptions()
                                .getCache().get(uri);
                    }
                    if (impl == null) {
                        String[] location = ctxt.getTldLocation(uri);
                        impl = new TagLibraryInfoImpl(ctxt, parserController, pageInfo,
                                prefix, uri, location, err);
                        if (ctxt.getOptions().isCaching()) {
                            ctxt.getOptions().getCache().put(uri, impl);
                        }
                    } else {
                        // Current compilation context needs location of cached
                        // tag files
                        for (TagFileInfo info : impl.getTagFiles()) {
                            ctxt.setTagFileJarUrl(info.getPath(),
                                    ctxt.getTagFileJarUrl());
                        }
                    }
                    pageInfo.addTaglib(uri, impl);
                }
                pageInfo.addPrefixMapping(prefix, uri);
            } else {
                String tagdir = attrs.getValue("tagdir");
                if (tagdir != null) {
                    String urnTagdir = URN_JSPTAGDIR + tagdir;
                    if (pageInfo.getTaglib(urnTagdir) == null) {
                        pageInfo.addTaglib(urnTagdir,
                                new ImplicitTagLibraryInfo(ctxt,
View Full Code Here

    /*
     * Parses a tag directive with the following syntax: PageDirective ::= ( S
     * Attribute)*
     */
    private void parseTagDirective(Node parent) throws JasperException {
        Attributes attrs = parseAttributes();
        Node.TagDirective n = new Node.TagDirective(attrs, start, parent);

        /*
         * A page directive may contain multiple 'import' attributes, each of
         * which consists of a comma-separated list of package names. Store each
         * list with the node, where it is parsed.
         */
        for (int i = 0; i < attrs.getLength(); i++) {
            if ("import".equals(attrs.getQName(i))) {
                n.addImport(attrs.getValue(i));
            }
        }
    }
View Full Code Here

    /*
     * Parses a attribute directive with the following syntax:
     * AttributeDirective ::= ( S Attribute)*
     */
    private void parseAttributeDirective(Node parent) throws JasperException {
        Attributes attrs = parseAttributes();
        Node.AttributeDirective n = new Node.AttributeDirective(attrs, start,
                parent);
    }
View Full Code Here

    /*
     * Parses a variable directive with the following syntax: PageDirective ::= (
     * S Attribute)*
     */
    private void parseVariableDirective(Node parent) throws JasperException {
        Attributes attrs = parseAttributes();
        Node.VariableDirective n = new Node.VariableDirective(attrs, start,
                parent);
    }
View Full Code Here

TOP

Related Classes of org.xml.sax.Attributes

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.