Package org.xml.sax

Examples of org.xml.sax.Attributes


             * Write begin tag
             */
            out.printin("out.write(\"<");
            out.print(n.getQName());

            Attributes attrs = n.getNonTaglibXmlnsAttributes();
            int attrsLen = (attrs == null) ? 0 : attrs.getLength();
            for (int i = 0; i < attrsLen; i++) {
                out.print(" ");
                out.print(attrs.getQName(i));
                out.print("=");
                String quote = DOUBLE_QUOTE;
                String value = attrs.getValue(i);
                if (value.indexOf('"') != -1) {
                    quote = SINGLE_QUOTE;
                }
                out.print(quote);
                out.print(value);
                out.print(quote);
            }

            attrs = n.getAttributes();
            attrsLen = (attrs == null) ? 0 : attrs.getLength();
            Node.JspAttribute[] jspAttrs = n.getJspAttributes();
            for (int i = 0; i < attrsLen; i++) {
                out.print(" ");
                out.print(attrs.getQName(i));
                out.print("=");
                if (jspAttrs[i].isELInterpreterInput()) {
                    out.print("\\\"\" + ");
                    out.print(attributeValue(jspAttrs[i], false, String.class));
                    out.print(" + \"\\\"");
                } else {
                    String quote = DOUBLE_QUOTE;
                    String value = attrs.getValue(i);
                    if (value.indexOf('"') != -1) {
                        quote = SINGLE_QUOTE;
                    }
                    out.print(quote);
                    out.print(value);
View Full Code Here


        public void visit(Node.UninterpretedTag n) throws JasperException {
            if (n.getNamedAttributeNodes().size() != 0) {
                err.jspError(n, "jsp.error.namedAttribute.invalidUse");
            }

            Attributes attrs = n.getAttributes();
            if (attrs != null) {
                int attrSize = attrs.getLength();
                Node.JspAttribute[] jspAttrs = new Node.JspAttribute[attrSize];
                for (int i = 0; i < attrSize; i++) {
                    jspAttrs[i] = getJspAttribute(null, attrs.getQName(i),
                            attrs.getURI(i), attrs.getLocalName(i), attrs
                                    .getValue(i), java.lang.Object.class, n,
                            false);
                }
                n.setJspAttributes(jspAttrs);
            }
View Full Code Here

             * that the same attribute is not specified in both attributes or
             * named attributes.
             */
            TagAttributeInfo[] tldAttrs = tagInfo.getAttributes();
            String customActionUri = n.getURI();
            Attributes attrs = n.getAttributes();
            int attrsSize = (attrs == null) ? 0 : attrs.getLength();
            for (int i = 0; i < tldAttrs.length; i++) {
                String attr = null;
                if (attrs != null) {
                    attr = attrs.getValue(tldAttrs[i].getName());
                    if (attr == null) {
                        attr = attrs.getValue(customActionUri, tldAttrs[i]
                                .getName());
                    }
                }
                Node.NamedAttribute na = n.getNamedAttributeNode(tldAttrs[i]
                        .getName());
View Full Code Here

        }

        @Override
        public void visit(Node.JspElement n) throws JasperException {

            Attributes attrs = n.getAttributes();
            if (attrs == null) {
                err.jspError(n, "jsp.error.jspelement.missing.name");
            }
            int xmlAttrLen = attrs.getLength();

            Node.Nodes namedAttrs = n.getNamedAttributeNodes();

            // XML-style 'name' attribute, which is mandatory, must not be
            // included in JspAttribute array
            int jspAttrSize = xmlAttrLen - 1 + namedAttrs.size();

            Node.JspAttribute[] jspAttrs = new Node.JspAttribute[jspAttrSize];
            int jspAttrIndex = 0;

            // Process XML-style attributes
            for (int i = 0; i < xmlAttrLen; i++) {
                if ("name".equals(attrs.getLocalName(i))) {
                    n.setNameAttribute(getJspAttribute(null, attrs.getQName(i),
                            attrs.getURI(i), attrs.getLocalName(i), attrs
                                    .getValue(i), java.lang.String.class, n,
                            false));
                } else {
                    if (jspAttrIndex < jspAttrSize) {
                        jspAttrs[jspAttrIndex++] = getJspAttribute(null, attrs
                                .getQName(i), attrs.getURI(i), attrs
                                .getLocalName(i), attrs.getValue(i),
                                java.lang.Object.class, n, false);
                    }
                }
            }
            if (n.getNameAttribute() == null) {
View Full Code Here

            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()) {
                        if (elExpression && deferredValueIsLiteral) break;
                        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() || (!"true".equalsIgnoreCase(pageInfo.getIsELIgnored()) && checkDeferred && deferred)));

                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);
                                    }
                                    if (elExpression) {
                                        // El expression
                                        validateFunctions(el, n);
                                        jspAttrs[i] = new Node.JspAttribute(tldAttrs[j],
                                                attrs.getQName(i), attrs.getURI(i),
                                                attrs.getLocalName(i),
                                                attrs.getValue(i), false, el, false);
                                        ELContextImpl ctx = new ELContextImpl();
                                        ctx.setFunctionMapper(getFunctionMapper(el));
                                        try {
                                            jspAttrs[i].validateEL(this.pageInfo.getExpressionFactory(), ctx);
                                        } catch (ELException e) {
                                            this.err.jspError(n.getStart(),
                                                    "jsp.error.invalid.expression",
                                                    attrs.getValue(i), e.toString());
                                        }
                                    } else {
                                        // Runtime expression
                                        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 (expression) {
                            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

        in.addAttribute(null, "href", null, "CDATA", "/etc/clientlib/test.css");
        transformer.startElement(null, "link", null, in);

        verify(handler, only()).startElement(isNull(String.class), eq("link"), isNull(String.class),
                attributesCaptor.capture());
        Attributes out = attributesCaptor.getValue();
        assertEquals("/etc/clientlib/test.css", out.getValue(0));
    }
View Full Code Here

        in.addAttribute(null, "href", null, "CDATA", "/etc/clientlib/test.css");
        transformer.startElement(null, "link", null, in);

        verify(handler, only()).startElement(isNull(String.class), eq("link"), isNull(String.class),
                attributesCaptor.capture());
        Attributes out = attributesCaptor.getValue();
        assertEquals("//static.host.com/etc/clientlib/test.css", out.getValue(0));
    }
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.