/* * Appends the page directive with the given attributes to the XML * view. * * Since the import attribute of the page directive is the only page * attribute that is allowed to appear multiple times within the same * document, and since XML allows only single-value attributes, * the values of multiple import attributes must be combined into one, * separated by comma. * * If the given page directive contains just 'contentType' and/or * 'pageEncoding' attributes, we ignore it, as we've already appended * a page directive containing just these two attributes. */ private void appendPageDirective(Node.PageDirective n) { boolean append = false; Attributes attrs = n.getAttributes(); int len = (attrs == null) ? 0 : attrs.getLength(); for (int i = 0; i < len; i++) { @SuppressWarnings("null") // If attrs==null, len == 0 String attrName = attrs.getQName(i); if (!"pageEncoding".equals(attrName) && !"contentType".equals(attrName)) { append = true; break; } } if (!append) { return; } buf.append("<").append(n.getQName()); buf.append("\n"); // append jsp:id buf.append(" ").append(jspIdPrefix).append(":id").append("=\""); buf.append(jspId++).append("\"\n"); // append remaining attributes for (int i = 0; i < len; i++) { @SuppressWarnings("null") // If attrs==null, len == 0 String attrName = attrs.getQName(i); if ("import".equals(attrName) || "contentType".equals(attrName) || "pageEncoding".equals(attrName)) { /* * Page directive's 'import' attribute is considered * further down, and its 'pageEncoding' and 'contentType' * attributes are ignored, since we've already appended * a new page directive containing just these two * attributes */ continue; } String value = attrs.getValue(i); buf.append(" ").append(attrName).append("=\""); buf.append(JspUtil.getExprInXml(value)).append("\"\n"); } if (n.getImports().size() > 0) { // Concatenate names of imported classes/packages boolean first = true; ListIterator<String> iter = n.getImports().listIterator(); while (iter.hasNext()) { if (first) { first = false; buf.append(" import=\""); } else { buf.append(","); } buf.append(JspUtil.getExprInXml(iter.next())); } buf.append("\"\n"); } buf.append("/>\n"); }
/* * Appends the attributes of the given Node to the XML view. */ private void printAttributes(Node n, boolean addDefaultNS) { /* * Append "xmlns" attributes that represent tag libraries */ Attributes attrs = n.getTaglibAttributes(); int len = (attrs == null) ? 0 : attrs.getLength(); for (int i = 0; i < len; i++) { @SuppressWarnings("null") // If attrs==null, len == 0 String name = attrs.getQName(i); String value = attrs.getValue(i); buf.append(" ").append(name).append("=\"").append(value).append("\"\n"); } /* * Append "xmlns" attributes that do not represent tag libraries */ attrs = n.getNonTaglibXmlnsAttributes(); len = (attrs == null) ? 0 : attrs.getLength(); boolean defaultNSSeen = false; for (int i = 0; i < len; i++) { @SuppressWarnings("null") // If attrs==null, len == 0 String name = attrs.getQName(i); String value = attrs.getValue(i); buf.append(" ").append(name).append("=\"").append(value).append("\"\n"); defaultNSSeen |= "xmlns".equals(name); } if (addDefaultNS && !defaultNSSeen) { buf.append(" xmlns=\"\"\n"); } resetDefaultNS = false; /* * Append all other attributes */ attrs = n.getAttributes(); len = (attrs == null) ? 0 : attrs.getLength(); for (int i = 0; i < len; i++) { @SuppressWarnings("null") // If attrs==null, len == 0 String name = attrs.getQName(i); String value = attrs.getValue(i); buf.append(" ").append(name).append("=\""); buf.append(JspUtil.getExprInXml(value)).append("\"\n"); } }