/** * Return the raw value of the attribute. * * @param namespaceURI:localName or localName if the namespaceURI is null of the attribute to get * @return The Attr value as a string, or the empty string if that attribute does not have a * specified or default value */ public String getAttribute(String rawName) { AVT avt = getLiteralResultAttribute(rawName); if ((null != avt)) { return avt.getSimpleString(); } return EMPTYSTRING; }
/** * Return the raw value of the attribute. * * @param namespaceURI Namespace URI of attribute node to get * @param localName Local part of qualified name of attribute node to get * @return The Attr value as a string, or the empty string if that attribute does not have a * specified or default value */ public String getAttributeNS(String namespaceURI, String localName) { AVT avt = getLiteralResultAttributeNS(namespaceURI, localName); if ((null != avt)) { return avt.getSimpleString(); } return EMPTYSTRING; }
/** * Call the children visitors. * * @param visitor The visitor whose appropriate method will be called. */ protected void callChildVisitors(XSLTVisitor visitor, boolean callAttrs) { if (callAttrs && null != m_avts) { int nAttrs = m_avts.size(); for (int i = (nAttrs - 1); i >= 0; i--) { AVT avt = (AVT) m_avts.get(i); avt.callVisitors(visitor); } } super.callChildVisitors(visitor, callAttrs); }
/** * This function is called after everything else has been recomposed, and allows the template to * set remaining values that may be based on some other property that depends on recomposition. */ public void compose(StylesheetRoot sroot) throws TransformerException { super.compose(sroot); StylesheetRoot.ComposeState cstate = sroot.getComposeState(); java.util.Vector vnames = cstate.getVariableNames(); if (null != m_avts) { int nAttrs = m_avts.size(); for (int i = (nAttrs - 1); i >= 0; i--) { AVT avt = (AVT) m_avts.get(i); avt.fixupVariables(vnames, cstate.getGlobalsSize()); } } }
/** * Augment resolvePrefixTables, resolving the namespace aliases once the superclass has resolved * the tables. * * @throws TransformerException */ public void resolvePrefixTables() throws TransformerException { super.resolvePrefixTables(); StylesheetRoot stylesheet = getStylesheetRoot(); if ((null != m_namespace) && (m_namespace.length() > 0)) { NamespaceAlias nsa = stylesheet.getNamespaceAliasComposed(m_namespace); if (null != nsa) { m_namespace = nsa.getResultNamespace(); // String resultPrefix = nsa.getResultPrefix(); String resultPrefix = nsa.getStylesheetPrefix(); // As per xsl WG, Mike Kay if ((null != resultPrefix) && (resultPrefix.length() > 0)) m_rawName = resultPrefix + ":" + m_localName; else m_rawName = m_localName; } } if (null != m_avts) { int n = m_avts.size(); for (int i = 0; i < n; i++) { AVT avt = (AVT) m_avts.get(i); // Should this stuff be a method on AVT? String ns = avt.getURI(); if ((null != ns) && (ns.length() > 0)) { NamespaceAlias nsa = stylesheet.getNamespaceAliasComposed(m_namespace); // %REVIEW% ns? if (null != nsa) { String namespace = nsa.getResultNamespace(); // String resultPrefix = nsa.getResultPrefix(); String resultPrefix = nsa.getStylesheetPrefix(); // As per XSL WG String rawName = avt.getName(); if ((null != resultPrefix) && (resultPrefix.length() > 0)) rawName = resultPrefix + ":" + rawName; avt.setURI(namespace); avt.setRawName(rawName); } } } } }
/** * Get a literal result attribute by name. * * @param namespaceURI Namespace URI of attribute node to get * @param localName Local part of qualified name of attribute node to get * @return literal result attribute (AVT) */ public AVT getLiteralResultAttributeNS(String namespaceURI, String localName) { if (null != m_avts) { int nAttrs = m_avts.size(); for (int i = (nAttrs - 1); i >= 0; i--) { AVT avt = (AVT) m_avts.get(i); if (avt.getName().equals(localName) && avt.getURI().equals(namespaceURI)) { return avt; } } // end for } return null; }
/** * Retrieves a node specified by local name and namespace URI. * * @param namespaceURI Namespace URI of attribute node to get * @param localName Local part of qualified name of attribute node to get * @return A <code>Node</code> (of any type) with the specified <code>nodeName</code>, or <code> * null</code> if it does not identify any node in this map. */ public Node getNamedItemNS(String namespaceURI, String localName) { if (getLength() == 0) return null; Node retNode = null; Iterator eum = m_avts.iterator(); while (eum.hasNext()) { AVT avt = (AVT) eum.next(); if (localName.equals(avt.getName())) { String nsURI = avt.getURI(); if ((namespaceURI == null && nsURI == null) || (namespaceURI != null && namespaceURI.equals(nsURI))) { retNode = new Attribute(avt, ElemLiteralResult.this); break; } } } return retNode; }
/** * Get a literal result attribute by name. The name is namespaceURI:localname if namespace is not * null. * * @param name Name of literal result attribute to get * @return literal result attribute (AVT) */ public AVT getLiteralResultAttribute(String name) { if (null != m_avts) { int nAttrs = m_avts.size(); String namespace = null; for (int i = (nAttrs - 1); i >= 0; i--) { AVT avt = (AVT) m_avts.get(i); namespace = avt.getURI(); if ((namespace != null && (!namespace.equals("")) && (namespace + ":" + avt.getName()).equals(name)) || ((namespace == null || namespace.equals("")) && avt.getRawName().equals(name))) { return avt; } } // end for } return null; }
/** * Set the "xml:space" attribute. A text node is preserved if an ancestor element of the text node * has an xml:space attribute with a value of preserve, and no closer ancestor element has * xml:space with a value of default. * * @see <a href="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a> * @see <a href="http://www.w3.org/TR/xslt#section-Creating-Text">section-Creating-Text in XSLT * Specification</a> * @param avt Enumerated value, either Constants.ATTRVAL_PRESERVE or Constants.ATTRVAL_STRIP. */ public void setXmlSpace(AVT avt) { // This function is a bit-o-hack, I guess... addLiteralResultAttribute(avt); String val = avt.getSimpleString(); if (val.equals("default")) { super.setXmlSpace(Constants.ATTRVAL_STRIP); } else if (val.equals("preserve")) { super.setXmlSpace(Constants.ATTRVAL_PRESERVE); } // else maybe it's a real AVT, so we can't resolve it at this time. }
/** * Retrieves a node specified by name. * * @param name The <code>nodeName</code> of a node to retrieve. * @return A <code>Node</code> (of any type) with the specified <code>nodeName</code>, or <code> * null</code> if it does not identify any node in this map. */ public Node getNamedItem(String name) { if (getLength() == 0) return null; String uri = null; String localName = name; int index = name.indexOf(":"); if (-1 != index) { uri = name.substring(0, index); localName = name.substring(index + 1); } Node retNode = null; Iterator eum = m_avts.iterator(); while (eum.hasNext()) { AVT avt = (AVT) eum.next(); if (localName.equals(avt.getName())) { String nsURI = avt.getURI(); if ((uri == null && nsURI == null) || (uri != null && uri.equals(nsURI))) { retNode = new Attribute(avt, ElemLiteralResult.this); break; } } } return retNode; }
@Override public String toString() { return "AnonymousVariable(" + bn.toString() + ")"; }
/** @return The name of this attribute */ public String getName() { return m_attribute.getName(); }
/** @return The value of this attribute returned as string */ public String getValue() { return m_attribute.getSimpleString(); }
/** * @see org.w3c.dom.Node * @return The namespace prefix of this node, or null if it is unspecified */ public String getPrefix() { String uri = m_attribute.getURI(); String rawName = m_attribute.getRawName(); return (uri.equals("")) ? null : rawName.substring(0, rawName.indexOf(":")); }
/** * @see org.w3c.dom.Node * @return The value of the attribute * @throws DOMException */ public String getNodeValue() throws DOMException { return m_attribute.getSimpleString(); }
/** * @see org.w3c.dom.Node * @return The name of the attribute */ public String getNodeName() { String uri = m_attribute.getURI(); String localName = getLocalName(); return (uri.equals("")) ? localName : uri + ":" + localName; }
/** * @see org.w3c.dom.Node * @return The namespace URI of this node, or null if it is unspecified */ public String getNamespaceURI() { String uri = m_attribute.getURI(); return (uri.equals("")) ? null : uri; }
/** * Copy a Literal Result Element into the Result tree, copy the non-excluded namespace attributes, * copy the attributes not of the XSLT namespace, and execute the children of the LRE. * * @see <a href="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT * Specification</a> * @param transformer non-null reference to the the current transform-time state. * @throws TransformerException */ public void execute(TransformerImpl transformer) throws TransformerException { SerializationHandler rhandler = transformer.getSerializationHandler(); try { // JJK Bugzilla 3464, test namespace85 -- make sure LRE's // namespace is asserted even if default, since xsl:element // may have changed the context. rhandler.startPrefixMapping(getPrefix(), getNamespace()); // Add namespace declarations. executeNSDecls(transformer); rhandler.startElement(getNamespace(), getLocalName(), getRawName()); } catch (SAXException se) { throw new TransformerException(se); } /* * If we make it to here we have done a successful startElement() * we will do an endElement() call for balance, no matter what happens * in the middle. */ // tException remembers if we had an exception "in the middle" TransformerException tException = null; try { // Process any possible attributes from xsl:use-attribute-sets first super.execute(transformer); // xsl:version, excludeResultPrefixes??? // Process the list of avts next if (null != m_avts) { int nAttrs = m_avts.size(); for (int i = (nAttrs - 1); i >= 0; i--) { AVT avt = (AVT) m_avts.get(i); XPathContext xctxt = transformer.getXPathContext(); int sourceNode = xctxt.getCurrentNode(); String stringedValue = avt.evaluate(xctxt, sourceNode, this); if (null != stringedValue) { // Important Note: I'm not going to check for excluded namespace // prefixes here. It seems like it's too expensive, and I'm not // even sure this is right. But I could be wrong, so this needs // to be tested against other implementations. rhandler.addAttribute( avt.getURI(), avt.getName(), avt.getRawName(), "CDATA", stringedValue, false); } } // end for } // Now process all the elements in this subtree // TODO: Process m_extensionElementPrefixes && m_attributeSetsNames transformer.executeChildTemplates(this, true); } catch (TransformerException te) { // thrown in finally to prevent original exception consumed by subsequent exceptions tException = te; } catch (SAXException se) { tException = new TransformerException(se); } try { /* we need to do this endElement() to balance the * successful startElement() call even if * there was an exception in the middle. * Otherwise an exception in the middle could cause a system to hang. */ rhandler.endElement(getNamespace(), getLocalName(), getRawName()); } catch (SAXException se) { /* we did call endElement(). If thee was an exception * in the middle throw that one, otherwise if there * was an exception from endElement() throw that one. */ if (tException != null) throw tException; else throw new TransformerException(se); } /* If an exception was thrown in the middle but not with startElement() or * or endElement() then its time to let it percolate. */ if (tException != null) throw tException; unexecuteNSDecls(transformer); // JJK Bugzilla 3464, test namespace85 -- balance explicit start. try { rhandler.endPrefixMapping(getPrefix()); } catch (SAXException se) { throw new TransformerException(se); } }