List of usage examples for org.w3c.dom Attr getLocalName
public String getLocalName();
From source file:org.mule.config.spring.parsers.assembly.DefaultBeanAssembler.java
/** * Add a property defined by an attribute to the bean we are constructing. * * <p>Since an attribute value is always a string, we don't have to deal with complex types * here - the only issue is whether or not we have a reference. References are detected * by explicit annotation or by the "-ref" at the end of an attribute name. We do not * check the Spring repo to see if a name already exists since that could lead to * unpredictable behaviour.//from w w w . j ava2 s . com * (see {@link org.mule.config.spring.parsers.assembly.configuration.PropertyConfiguration}) * @param attribute The attribute to add */ public void extendBean(Attr attribute) { AbstractBeanDefinition beanDefinition = bean.getBeanDefinition(); String oldName = SpringXMLUtils.attributeName(attribute); String oldValue = attribute.getNodeValue(); if (attribute.getNamespaceURI() == null) { if (!beanConfig.isIgnored(oldName)) { logger.debug(attribute + " for " + beanDefinition.getBeanClassName()); String newName = bestGuessName(beanConfig, oldName, beanDefinition.getBeanClassName()); Object newValue = beanConfig.translateValue(oldName, oldValue); addPropertyWithReference(beanDefinition.getPropertyValues(), beanConfig.getSingleProperty(oldName), newName, newValue); } } else if (isAnnotationsPropertyAvailable(beanDefinition.getBeanClass())) { //Add attribute defining namespace as annotated elements. No reconciliation is done here ie new values override old ones. QName name; if (attribute.getPrefix() != null) { name = new QName(attribute.getNamespaceURI(), attribute.getLocalName(), attribute.getPrefix()); } else { name = new QName(attribute.getNamespaceURI(), attribute.getLocalName()); } Object value = beanConfig.translateValue(oldName, oldValue); addAnnotationValue(beanDefinition.getPropertyValues(), name, value); MuleContext muleContext = MuleApplicationContext.getCurrentMuleContext().get(); if (muleContext != null) { Map<QName, Set<Object>> annotations = muleContext.getConfigurationAnnotations(); Set<Object> values = annotations.get(name); if (values == null) { values = new HashSet<Object>(); annotations.put(name, values); } values.add(value); } } else { if (logger.isDebugEnabled()) { logger.debug("Cannot assign " + beanDefinition.getBeanClass() + " to " + AnnotatedObject.class); } } }
From source file:org.omg.bpmn.miwg.util.xml.diff.AbstractXmlDifferenceListener.java
/** * Vendors may introduce new namespaces and these should not be reported as * significant differences./*from w ww. j a va 2 s. com*/ * * @param difference * @return * @see https://github.com/bpmn-miwg/bpmn-miwg-tools/issues/13 */ protected boolean isCausedByAdditionalNamespace(Difference difference) { try { Attr attr = null; int len = difference.getTestNodeDetail().getNode().getAttributes().getLength(); for (int i = 0; i < len; i++) { Attr tmp = (Attr) difference.getTestNodeDetail().getNode().getAttributes().item(i); if (difference.getTestNodeDetail().getValue().equals(tmp.getLocalName())) { // this is the attribute in question attr = tmp; break; } } if (attr != null) { String uri = attr.getNamespaceURI(); if (uri != null && difference.getControlNodeDetail().getNode().getOwnerDocument() .lookupNamespaceURI(uri) == null) { // So the control document does not have this namespace // that the test doc does => OK to ignore. return true; } } } catch (NullPointerException e) { // Assume because the namespace scenario we are looking for is // not cause of difference and report it } return false; }
From source file:org.openspaces.core.config.LocalTxManagerBeanDefinitionParser.java
protected void doParse(Element element, BeanDefinitionBuilder builder) { log.warn(/*from w w w . j a v a2s . c o m*/ "Local transaction manager is deprecated, use distributed transaction manager instead ('distributed-tx-manager')"); super.doParse(element, builder); NamedNodeMap attributes = element.getAttributes(); for (int x = 0; x < attributes.getLength(); x++) { Attr attribute = (Attr) attributes.item(x); String name = attribute.getLocalName(); if (ID_ATTRIBUTE.equals(name)) { continue; } String propertyName = extractPropertyName(name); if (SPACE.equals(name)) { continue; } if (CLUSTERED.equals(name)) { continue; } Assert.state(StringUtils.hasText(propertyName), "Illegal property name returned from 'extractPropertyName(String)': cannot be null or empty."); builder.addPropertyValue(propertyName, attribute.getValue()); } }
From source file:org.osaf.cosmo.xml.DomWriter.java
private static void writeAttribute(Attr a, XMLStreamWriter writer) throws XMLStreamException { //if (log.isDebugEnabled()) //log.debug("Writing attribute " + a.getNodeName()); String local = a.getLocalName(); if (local == null) local = a.getNodeName();//from w w w.jav a 2s. co m String ns = a.getNamespaceURI(); String value = a.getValue(); // was handled by writing the default namespace in writeElement if (local.equals("xmlns")) return; if (ns != null) { String prefix = a.getPrefix(); if (prefix != null) writer.writeAttribute(prefix, ns, local, value); else writer.writeAttribute(ns, local, value); } else { writer.writeAttribute(local, value); } }
From source file:org.regenstrief.util.XMLUtil.java
/** * Strips namespaces and prefixes from a Node tree * //ww w . j av a 2s . c o m * @param n the root Node * @return the stripped Node **/ public final static Node stripNamespaces(final Node n) { if (n == null) { return null; } final Document doc = n.getOwnerDocument(); if (n instanceof Element) { final Element eOld = (Element) n; final Element eNew = doc.createElement(getLocalName(eOld)); final NamedNodeMap map = eOld.getAttributes(); for (int i = 0, size = size(map); i < size; i++) { final Attr attr = (Attr) map.item(i); String name = attr.getName(); if (name == null) { name = attr.getLocalName(); } if (!("xmlns".equals(name) || ((name != null) && name.startsWith("xmlns:")) || "xmlns".equals(attr.getPrefix()))) { final int j = name.indexOf(':'); eNew.setAttribute(j < 0 ? name : name.substring(j + 1), attr.getValue()); } } final NodeList list = n.getChildNodes(); for (int i = 0, size = size(list); i < size; i++) { appendChild(eNew, stripNamespaces(list.item(i))); } return eNew; } else if (n instanceof Attr) { return null; } return n.cloneNode(false); }
From source file:org.unitedinternet.cosmo.util.DomWriter.java
private static void writeAttribute(Attr a, XMLStreamWriter writer) throws XMLStreamException { //if (log.isDebugEnabled()) //log.debug("Writing attribute " + a.getNodeName()); String local = a.getLocalName(); if (local == null) { local = a.getNodeName();/* w w w.j av a2 s . c o m*/ } String ns = a.getNamespaceURI(); String value = a.getValue(); // was handled by writing the default namespace in writeElement if (local.equals("xmlns")) { return; } if (ns != null) { String prefix = a.getPrefix(); if (prefix != null) { writer.writeAttribute(prefix, ns, local, value); } else { writer.writeAttribute(ns, local, value); } } else { writer.writeAttribute(local, value); } }