List of usage examples for org.w3c.dom Attr getValue
public String getValue();
From source file:org.apache.ode.utils.DOMUtils.java
/** * Returns the value of an attribute of an element. Returns null if the * attribute is not found (whereas Element.getAttributeNS returns "" if an * attrib is not found)./* w w w. j ava 2 s . c om*/ * * @param el Element whose attrib is looked for * @param namespaceURI namespace URI of attribute to look for * @param localPart local part of attribute to look for * * @return the attribute value */ static public String getAttributeNS(Element el, String namespaceURI, String localPart) { String sRet = null; Attr attr = el.getAttributeNodeNS(namespaceURI, localPart); if (attr != null) { sRet = attr.getValue(); } return sRet; }
From source file:org.apache.ode.utils.DOMUtils.java
/** * This method traverses the DOM and grabs namespace declarations * on parent elements with the intent of preserving them for children. <em>Note * that the DOM level 3 document method {@link Element#getAttribute(java.lang.String)} * is not desirable in this case, as it does not respect namespace prefix * bindings that may affect attribute values. (Namespaces in DOM are * uncategorically a mess, especially in the context of XML Schema.)</em> * @param el the starting element//from w w w .ja va2 s . com * @return a {@link Map} containing prefix bindings. */ public static Map<String, String> getParentNamespaces(Element el) { HashMap<String, String> pref = new HashMap<String, String>(); Map<String, String> mine = getMyNamespaces(el); Node n = el.getParentNode(); while (n != null && n.getNodeType() != Node.DOCUMENT_NODE) { if (n instanceof Element) { Element l = (Element) n; NamedNodeMap nnm = l.getAttributes(); int len = nnm.getLength(); for (int i = 0; i < len; ++i) { Attr a = (Attr) nnm.item(i); if (isNSAttribute(a)) { String key = getNSPrefixFromNSAttr(a); String uri = a.getValue(); // prefer prefix bindings that are lower down in the tree. if (pref.containsKey(key) || mine.containsKey(key)) continue; pref.put(key, uri); } } } n = n.getParentNode(); } return pref; }
From source file:org.apache.ode.utils.DOMUtils.java
public static Map<String, String> getMyNamespaces(Element el) { HashMap<String, String> mine = new HashMap<String, String>(); NamedNodeMap nnm = el.getAttributes(); int len = nnm.getLength(); for (int i = 0; i < len; ++i) { Attr a = (Attr) nnm.item(i); if (isNSAttribute(a)) { mine.put(getNSPrefixFromNSAttr(a), a.getValue()); }/*from w w w. j a v a 2 s. co m*/ } return mine; }
From source file:org.apache.openejb.server.axis.assembler.CommonsSchemaInfoBuilder.java
/** * Extract the nested component type of an Array from the XML Schema Type. * * @return the QName of the nested component type or null if the schema type can not be determined * @throws org.apache.openejb.OpenEJBException if the XML Schema Type can not represent an Array @param complexType *//*www. j av a 2s . co m*/ private static QName extractSoapArrayComponentType(XmlSchemaComplexType complexType) { // Soap arrays are based on complex content restriction if (!isSoapArray(complexType)) { return null; } XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction) complexType .getContentModel().getContent(); //First, handle case that looks like this: // <complexType name="ArrayOfstring"> // <complexContent> // <restriction base="soapenc:Array"> // <attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]"/> // </restriction> // </complexContent> // </complexType> XmlSchemaObjectCollection attributes = restriction.getAttributes(); for (Iterator iterator = attributes.getIterator(); iterator.hasNext();) { Object item = iterator.next(); if (item instanceof XmlSchemaAttribute) { XmlSchemaAttribute attribute = (XmlSchemaAttribute) item; if (attribute.getRefName().equals(SOAP_ARRAY_TYPE)) { for (Attr attr : attribute.getUnhandledAttributes()) { QName attQName = new QName(attr.getNamespaceURI(), attr.getLocalName()); if (WSDL_ARRAY_TYPE.equals(attQName)) { // value is a namespace prefixed xsd type String value = attr.getValue(); // extract local part int pos = value.lastIndexOf(":"); QName componentType; if (pos < 0) { componentType = new QName("", value); } else { String localPart = value.substring(pos + 1); // resolve the namespace prefix String prefix = value.substring(0, pos); String namespace = getNamespaceForPrefix(prefix, attr.getOwnerElement()); componentType = new QName(namespace, localPart); } log.debug("determined component type from element type"); return componentType; } } } } } // If that didn't work, try to handle case like this: // <complexType name="ArrayOfstring1"> // <complexContent> // <restriction base="soapenc:Array"> // <sequence> // <element name="string1" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/> // </sequence> // </restriction> // </complexContent> // </complexType> XmlSchemaParticle particle = restriction.getParticle(); if (particle instanceof XmlSchemaSequence) { XmlSchemaSequence sequence = (XmlSchemaSequence) particle; if (sequence.getItems().getCount() != 1) { throw new IllegalArgumentException("more than one element inside array definition: " + complexType); } XmlSchemaObject item = sequence.getItems().getItem(0); if (item instanceof XmlSchemaElement) { XmlSchemaElement element = (XmlSchemaElement) item; QName componentType = element.getSchemaTypeName(); log.debug("determined component type from element type"); return componentType; } } return null; }
From source file:org.apache.openejb.server.axis.assembler.CommonsSchemaInfoBuilder.java
private static String getNamespaceForPrefix(String prefix, Element element) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node node = attributes.item(i); if (node instanceof Attr) { Attr attr = (Attr) node; if (XML_NS_NS.equals(attr.getNamespaceURI())) { // this is a namespace declaration, is it the one we are looking for? if (attr.getLocalName().equals(prefix)) { return attr.getValue(); }//from ww w . j a va2 s .co m } } } // try parent if (element.getParentNode() instanceof Element) { return getNamespaceForPrefix(prefix, (Element) element.getParentNode()); } // didn't find it - just use prefix as the namespace return prefix; }
From source file:org.apache.openmeetings.cli.ConnectionPropertiesPatcher.java
public static ConnectionProperties getConnectionProperties(File conf) throws Exception { ConnectionProperties props = new ConnectionProperties(); Document doc = getDocument(conf); Attr attr = getConnectionProperties(doc); String[] tokens = attr.getValue().split(","); loadProperties(tokens, props);/* w ww .ja v a 2 s .c o m*/ return props; }
From source file:org.apache.openmeetings.cli.ConnectionPropertiesPatcher.java
public static void patch(ConnectionProperties props) throws Exception { ConnectionPropertiesPatcher patcher = getPatcher(props); Document doc = getDocument(OmFileHelper.getPersistence(props.getDbType())); Attr attr = getConnectionProperties(doc); String[] tokens = attr.getValue().split(","); patcher.patchAttribute(tokens);//from ww w.ja v a 2 s . co m attr.setValue(StringUtils.join(tokens, ",")); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); transformer.transform(source, new StreamResult(OmFileHelper.getPersistence().getCanonicalPath())); //this constructor is used to avoid transforming path to URI }
From source file:org.apache.servicemix.jbi.runtime.impl.utils.DOMUtil.java
/** * Copy the attribues on one element to the other */// w w w. j a v a2 s.co m public static void copyAttributes(Element from, Element to) { // lets copy across all the remainingattributes NamedNodeMap attributes = from.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr node = (Attr) attributes.item(i); to.setAttributeNS(node.getNamespaceURI(), node.getName(), node.getValue()); } }
From source file:org.apache.shindig.gadgets.rewrite.AbsolutePathReferenceVisitor.java
public VisitStatus visit(Gadget gadget, Node node) throws RewritingException { Attr nodeAttr = getUriAttributeFromNode(node, tagsToMakeAbsolute); if (nodeAttr != null) { try {//from w w w . ja v a 2 s . c o m Uri nodeUri = Uri.parse(nodeAttr.getValue()); Uri baseUri = getBaseResolutionUri(gadget, node); Uri resolved = baseUri.resolve(nodeUri); if (!resolved.equals(nodeUri)) { nodeAttr.setValue(resolved.toString()); return VisitStatus.MODIFY; } } catch (Uri.UriException e) { // UriException on illegal input. Ignore. } } return VisitStatus.BYPASS; }
From source file:org.apache.shindig.gadgets.rewrite.AbsolutePathReferenceVisitor.java
/** * Returns the uri attribute for the given node by looking up the * tag name -> uri attribute map.// w w w .j av a 2 s .c om * NOTE: This function returns the node attribute only if the attribute has a * non empty value. * @param node The node to get uri attribute for. * @param resourceTags Map from tag name -> uri attribute name. * @return Uri attribute for the node. */ public static Attr getUriAttributeFromNode(Node node, Map<String, String> resourceTags) { String nodeName = node.getNodeName().toLowerCase(); if (node.getNodeType() == Node.ELEMENT_NODE && resourceTags.containsKey(nodeName)) { if ("link".equals(nodeName)) { // Rewrite link only when it is for css. String type = ((Element) node).getAttribute("type"); String rel = ((Element) node).getAttribute("rel"); if (!"stylesheet".equalsIgnoreCase(rel) || !"text/css".equalsIgnoreCase(type)) { return null; } } Attr attr = (Attr) node.getAttributes().getNamedItem(resourceTags.get(nodeName)); String nodeUri = attr != null ? attr.getValue() : null; if (!StringUtils.isEmpty(nodeUri)) { return attr; } } return null; }