Java Code Examples for org.w3c.dom.Element#getAttributes()

The following examples show how to use org.w3c.dom.Element#getAttributes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Internalizer.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validates attributes of a <jaxb:bindings> element.
 */
private void validate( Element bindings ) {
    NamedNodeMap atts = bindings.getAttributes();
    for( int i=0; i<atts.getLength(); i++ ) {
        Attr a = (Attr)atts.item(i);
        if( a.getNamespaceURI()!=null )
            continue;   // all foreign namespace OK.
        if( a.getLocalName().equals("node") )
            continue;
        if( a.getLocalName().equals("schemaLocation"))
            continue;
        if( a.getLocalName().equals("scd") )
            continue;

        // enhancements
        if( a.getLocalName().equals("required") ) //
            continue;
        if( a.getLocalName().equals("multiple") ) //
            continue;


        // TODO: flag error for this undefined attribute
    }
}
 
Example 2
Source File: DMNReader.java    From jdmn with Apache License 2.0 6 votes vote down vote up
private DMNVersion inferDMNVersion(Document doc) {
    DMNVersion dmnVersion = null;
    Element definitions = doc.getDocumentElement();
    NamedNodeMap attributes = definitions.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Node item = attributes.item(i);
        String nodeValue = item.getNodeValue();
        for(DMNVersion version: DMNVersion.VALUES) {
            if (version.getNamespace().equals(nodeValue)) {
                dmnVersion = version;
                break;
            }
        }
    }
    if (dmnVersion == null) {
        throw new IllegalArgumentException(String.format("Cannot infer DMN version for input '%s'", doc.getDocumentURI()));
    }

    return dmnVersion;
}
 
Example 3
Source File: DOMXPathTransform.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void unmarshalParams(Element paramsElem) {
    String xPath = paramsElem.getFirstChild().getNodeValue();
    // create a Map of namespace prefixes
    NamedNodeMap attributes = paramsElem.getAttributes();
    if (attributes != null) {
        int length = attributes.getLength();
        Map<String, String> namespaceMap =
            new HashMap<String, String>(length);
        for (int i = 0; i < length; i++) {
            Attr attr = (Attr)attributes.item(i);
            String prefix = attr.getPrefix();
            if (prefix != null && prefix.equals("xmlns")) {
                namespaceMap.put(attr.getLocalName(), attr.getValue());
            }
        }
        this.params = new XPathFilterParameterSpec(xPath, namespaceMap);
    } else {
        this.params = new XPathFilterParameterSpec(xPath);
    }
}
 
Example 4
Source File: DOMXPathTransform.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void unmarshalParams(Element paramsElem) {
    String xPath = paramsElem.getFirstChild().getNodeValue();
    // create a Map of namespace prefixes
    NamedNodeMap attributes = paramsElem.getAttributes();
    if (attributes != null) {
        int length = attributes.getLength();
        Map<String, String> namespaceMap =
            new HashMap<String, String>(length);
        for (int i = 0; i < length; i++) {
            Attr attr = (Attr)attributes.item(i);
            String prefix = attr.getPrefix();
            if (prefix != null && prefix.equals("xmlns")) {
                namespaceMap.put(attr.getLocalName(), attr.getValue());
            }
        }
        this.params = new XPathFilterParameterSpec(xPath, namespaceMap);
    } else {
        this.params = new XPathFilterParameterSpec(xPath);
    }
}
 
Example 5
Source File: Bug6690015.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test() {
    try {
        FileInputStream fis = new FileInputStream(getClass().getResource("bug6690015.xml").getFile());

        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(fis));
        Element root = doc.getDocumentElement();
        NodeList textnodes = root.getElementsByTagName("text");
        int len = textnodes.getLength();
        int index = 0;
        int attindex = 0;
        int attrlen = 0;
        NamedNodeMap attrs = null;

        while (index < len) {
            Element te = (Element) textnodes.item(index);
            attrs = te.getAttributes();
            attrlen = attrs.getLength();
            attindex = 0;
            Node node = null;

            while (attindex < attrlen) {
                node = attrs.item(attindex);
                System.out.println("attr: " + node.getNodeName() + " is shown holding value: " + node.getNodeValue());
                attindex++;
            }
            index++;
            System.out.println("-------------");
        }
        fis.close();
    } catch (Exception e) {
        Assert.fail("Exception: " + e.getMessage());
    }
}
 
Example 6
Source File: XMLConfigFileParser.java    From ymate-platform-v2 with Apache License 2.0 5 votes vote down vote up
private PairObject<String, String> __doParseNodeAttributes(List<Attribute> attributes, Element node, boolean collections, boolean textContent) {
    String _propertyName = null;
    String _propertyContent = null;
    //
    NamedNodeMap _attrNodes = node.getAttributes();
    if (_attrNodes != null && _attrNodes.getLength() > 0) {
        for (int _idy = 0; _idy < _attrNodes.getLength(); _idy++) {
            String _attrKey = _attrNodes.item(_idy).getNodeName();
            String _attrValue = _attrNodes.item(_idy).getNodeValue();
            if (collections) {
                if ("name".equals(_attrKey)) {
                    attributes.add(new Attribute(_attrValue, node.getTextContent()));
                }
            } else {
                if (textContent && StringUtils.isNotBlank(_attrValue)) {
                    _attrValue = node.getTextContent();
                }
                if ("name".equals(_attrKey)) {
                    _propertyName = _attrValue;
                } else if ("value".equals(_attrKey)) {
                    _propertyContent = _attrValue;
                } else {
                    attributes.add(new Attribute(_attrKey, _attrValue));
                }
            }
        }
    }
    if (!collections && StringUtils.isNotBlank(_propertyName)) {
        return new PairObject<String, String>(_propertyName, _propertyContent);
    }
    return null;
}
 
Example 7
Source File: RequiredElementsBuilder.java    From steady with Apache License 2.0 5 votes vote down vote up
private void addNamespaces(Node element, RequiredElements parent) {
    if (element.getParentNode() != null) {
        addNamespaces(element.getParentNode(), parent);
    }
    if (element instanceof Element) {
        Element el = (Element)element;
        NamedNodeMap map = el.getAttributes();
        for (int x = 0; x < map.getLength(); x++) {
            Attr attr = (Attr)map.item(x);
            if ("xmlns".equals(attr.getPrefix())) {
                parent.addDeclaredNamespaces(attr.getValue(), attr.getLocalName());
            }
        }
    }
}
 
Example 8
Source File: CajaTreeBuilder.java    From caja with Apache License 2.0 5 votes vote down vote up
@Override
protected Node shallowClone(Node node) {
  Node clone = node.cloneNode(false);
  if (needsDebugData) {
    Nodes.setFilePositionFor(clone, Nodes.getFilePositionFor(node));
  }
  switch (node.getNodeType()) {
    case Node.ATTRIBUTE_NODE:
      if (needsDebugData) {
        Nodes.setFilePositionForValue(
            (Attr) clone, Nodes.getFilePositionForValue((Attr) node));
      }
      break;
    case Node.ELEMENT_NODE:
      Element el = (Element) node;
      Element cloneEl = (Element) clone;
      NamedNodeMap attrs = el.getAttributes();
      for (int i = 0, n = attrs.getLength(); i < n; ++i) {
        Attr a = (Attr) attrs.item(i);
        Attr cloneA = cloneEl.getAttributeNodeNS(
            a.getNamespaceURI(), a.getLocalName());
        if (needsDebugData) {
          Nodes.setFilePositionFor(cloneA, Nodes.getFilePositionFor(a));
          Nodes.setFilePositionForValue(
              cloneA, Nodes.getFilePositionForValue(a));
        }
      }
      break;
    case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE:
      if (needsDebugData) {
        Text t = (Text) node;
        Nodes.setRawText(t, Nodes.getRawText(t));
      }
      break;
  }
  return clone;
}
 
Example 9
Source File: DOMPrinter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected void visitElement(Element node)
    throws XMLStreamException {
    out.writeStartElement(node.getPrefix()
        , node.getLocalName()
        , node.getNamespaceURI()
    );
    NamedNodeMap attrs = node.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        visitAttr((Attr) attrs.item(i));
    }
    visitChildren(node);
    out.writeEndElement();
}
 
Example 10
Source File: XSDocumentInfo.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initialize namespace support by collecting all of the namespace
 * declarations in the root's ancestors. This is necessary to
 * support schemas fragments, i.e. schemas embedded in other
 * documents. See,
 *
 * https://jaxp.dev.java.net/issues/show_bug.cgi?id=43
 *
 * Requires the DOM to be created with namespace support enabled.
 */
private void initNamespaceSupport(Element schemaRoot) {
    fNamespaceSupport = new SchemaNamespaceSupport();
    fNamespaceSupport.reset();

    Node parent = schemaRoot.getParentNode();
    while (parent != null && parent.getNodeType() == Node.ELEMENT_NODE
            && !parent.getNodeName().equals("DOCUMENT_NODE"))
    {
        Element eparent = (Element) parent;
        NamedNodeMap map = eparent.getAttributes();
        int length = (map != null) ? map.getLength() : 0;
        for (int i = 0; i < length; i++) {
            Attr attr = (Attr) map.item(i);
            String uri = attr.getNamespaceURI();

            // Check if attribute is an ns decl -- requires ns support
            if (uri != null && uri.equals("http://www.w3.org/2000/xmlns/")) {
                String prefix = attr.getLocalName().intern();
                if (prefix == "xmlns") prefix = "";
                // Declare prefix if not set -- moving upwards
                if (fNamespaceSupport.getURI(prefix) == null) {
                    fNamespaceSupport.declarePrefix(prefix,
                            attr.getValue().intern());
                }
            }
        }
        parent = parent.getParentNode();
    }
}
 
Example 11
Source File: DOMNamespaceContext.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void addNamespaces(Node element) {
    if (element.getParentNode() != null) {
        addNamespaces(element.getParentNode());
    }
    if (element instanceof Element) {
        Element el = (Element)element;
        NamedNodeMap map = el.getAttributes();
        for (int x = 0; x < map.getLength(); x++) {
            Attr attr = (Attr)map.item(x);
            if ("xmlns".equals(attr.getPrefix())) {
                namespaceMap.put(attr.getLocalName(), attr.getValue());
            }
        }
    }
}
 
Example 12
Source File: Graph.java    From oodt with Apache License 2.0 4 votes vote down vote up
public Graph(Element graphElem, Metadata staticMetadata) throws WorkflowException {
  this();
  this.modelId = graphElem.getAttribute("id");
  this.modelName = graphElem.getAttribute("name");
  this.clazz = graphElem.getAttribute("class");
  this.modelIdRef = graphElem.getAttribute("id-ref");
  this.excused.addAll(Arrays.asList(graphElem.getAttribute("excused").split(
      ",")));
  this.alias = graphElem.getAttribute("alias");
  this.minReqSuccessfulSubProcessors = graphElem.getAttribute("min");
  this.executionType = graphElem.getAttribute("execution");
  this.timeout = Long.valueOf(graphElem.getAttribute("timeout") != null
      && !graphElem.getAttribute("timeout").equals("") ? graphElem
      .getAttribute("timeout") : "-1");
  this.optional = Boolean.valueOf(graphElem.getAttribute("optional"));

  NamedNodeMap attrMap = graphElem.getAttributes();
  for (int i = 0; i < attrMap.getLength(); i++) {
    Attr attr = (Attr) attrMap.item(i);
    if (attr.getName().startsWith("p:")) {
      staticMetadata.replaceMetadata(attr.getName().substring(2),
          attr.getValue());
    }
  }

  if ((graphElem.getNodeName().equals("workflow") || graphElem.getNodeName()
      .equals("conditions")) && this.executionType.equals("")) {
    throw new WorkflowException("workflow model '" + graphElem.getNodeName()
        + "' missing execution type");
  } else {
    this.executionType = graphElem.getNodeName();
  }

  if (!processorIds.contains(this.executionType)) {
    throw new WorkflowException("Unsupported execution type id '"
                                + this.executionType + "'");
  }

  if (!checkValue(this.modelId) && !checkValue(this.modelIdRef)) {
    this.modelId = UUID.randomUUID().toString();
  }

  if (this.alias != null && !this.alias.equals("")) {
    this.modelId = this.alias;
  }
}
 
Example 13
Source File: XMLUtils.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("fallthrough")
private static void getSetRec(final Node rootNode, final Set<Node> result,
                            final Node exclude, final boolean com) {
    if (rootNode == exclude) {
        return;
    }
    switch (rootNode.getNodeType()) {
    case Node.ELEMENT_NODE:
        result.add(rootNode);
        Element el = (Element)rootNode;
        if (el.hasAttributes()) {
            NamedNodeMap nl = el.getAttributes();
            for (int i = 0;i < nl.getLength(); i++) {
                result.add(nl.item(i));
            }
        }
        //no return keep working
    case Node.DOCUMENT_NODE:
        for (Node r = rootNode.getFirstChild(); r != null; r = r.getNextSibling()) {
            if (r.getNodeType() == Node.TEXT_NODE) {
                result.add(r);
                while ((r != null) && (r.getNodeType() == Node.TEXT_NODE)) {
                    r = r.getNextSibling();
                }
                if (r == null) {
                    return;
                }
            }
            getSetRec(r, result, exclude, com);
        }
        return;
    case Node.COMMENT_NODE:
        if (com) {
            result.add(rootNode);
        }
        return;
    case Node.DOCUMENT_TYPE_NODE:
        return;
    default:
        result.add(rootNode);
    }
}
 
Example 14
Source File: XMLUtils.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method is a tree-search to help prevent against wrapping attacks. It checks that no
 * two Elements have ID Attributes that match the "value" argument, if this is the case then
 * "false" is returned. Note that a return value of "true" does not necessarily mean that
 * a matching Element has been found, just that no wrapping attack has been detected.
 */
public static boolean protectAgainstWrappingAttack(Node startNode, String value) {
    Node startParent = startNode.getParentNode();
    Node processedNode = null;
    Element foundElement = null;

    String id = value.trim();
    if (id.charAt(0) == '#') {
        id = id.substring(1);
    }

    while (startNode != null) {
        if (startNode.getNodeType() == Node.ELEMENT_NODE) {
            Element se = (Element) startNode;

            NamedNodeMap attributes = se.getAttributes();
            if (attributes != null) {
                for (int i = 0; i < attributes.getLength(); i++) {
                    Attr attr = (Attr)attributes.item(i);
                    if (attr.isId() && id.equals(attr.getValue())) {
                        if (foundElement == null) {
                            // Continue searching to find duplicates
                            foundElement = attr.getOwnerElement();
                        } else {
                            log.log(java.util.logging.Level.FINE, "Multiple elements with the same 'Id' attribute value!");
                            return false;
                        }
                    }
                }
            }
        }

        processedNode = startNode;
        startNode = startNode.getFirstChild();

        // no child, this node is done.
        if (startNode == null) {
            // close node processing, get sibling
            startNode = processedNode.getNextSibling();
        }

        // no more siblings, get parent, all children
        // of parent are processed.
        while (startNode == null) {
            processedNode = processedNode.getParentNode();
            if (processedNode == startParent) {
                return true;
            }
            // close parent node processing (processed node now)
            startNode = processedNode.getNextSibling();
        }
    }
    return true;
}
 
Example 15
Source File: FileConfigurationParser.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
private FederationAddressPolicyConfiguration getAddressPolicy(Element policyNod, final Configuration mainConfig) throws Exception {
   FederationAddressPolicyConfiguration config = new FederationAddressPolicyConfiguration();
   config.setName(policyNod.getAttribute("name"));

   NamedNodeMap attributes = policyNod.getAttributes();
   for (int i = 0; i < attributes.getLength(); i++) {
      Node item = attributes.item(i);
      if (item.getNodeName().equals("max-consumers")) {
         int maxConsumers = Integer.parseInt(item.getNodeValue());
         Validators.MINUS_ONE_OR_GE_ZERO.validate(item.getNodeName(), maxConsumers);
         config.setMaxHops(maxConsumers);
      } else if (item.getNodeName().equals("auto-delete")) {
         boolean autoDelete = Boolean.parseBoolean(item.getNodeValue());
         config.setAutoDelete(autoDelete);
      } else if (item.getNodeName().equals("auto-delete-delay")) {
         long autoDeleteDelay = Long.parseLong(item.getNodeValue());
         Validators.GE_ZERO.validate("auto-delete-delay", autoDeleteDelay);
         config.setAutoDeleteDelay(autoDeleteDelay);
      } else if (item.getNodeName().equals("auto-delete-message-count")) {
         long autoDeleteMessageCount = Long.parseLong(item.getNodeValue());
         Validators.MINUS_ONE_OR_GE_ZERO.validate("auto-delete-message-count", autoDeleteMessageCount);
         config.setAutoDeleteMessageCount(autoDeleteMessageCount);
      } else if (item.getNodeName().equals("transformer-ref")) {
         String transformerRef = item.getNodeValue();
         config.setTransformerRef(transformerRef);
      } else if (item.getNodeName().equals("enable-divert-bindings")) {
         boolean enableDivertBindings = Boolean.parseBoolean(item.getNodeValue());
         config.setEnableDivertBindings(enableDivertBindings);
      }
   }

   NodeList children = policyNod.getChildNodes();

   for (int j = 0; j < children.getLength(); j++) {
      Node child = children.item(j);

      if (child.getNodeName().equals("include")) {
         config.addInclude(getAddressMatcher((Element) child));
      } else if (child.getNodeName().equals("exclude")) {
         config.addExclude(getAddressMatcher((Element) child));
      }
   }


   return config;
}
 
Example 16
Source File: XMLUtils.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * This is the work horse for {@link #circumventBug2650}.
 *
 * @param node
 * @see <A HREF="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2650">
 * Namespace axis resolution is not XPath compliant </A>
 */
@SuppressWarnings("fallthrough")
private static void circumventBug2650internal(Node node) {
    Node parent = null;
    Node sibling = null;
    final String namespaceNs = Constants.NamespaceSpecNS;
    do {
        switch (node.getNodeType()) {
        case Node.ELEMENT_NODE :
            Element element = (Element) node;
            if (!element.hasChildNodes()) {
                break;
            }
            if (element.hasAttributes()) {
                NamedNodeMap attributes = element.getAttributes();
                int attributesLength = attributes.getLength();

                for (Node child = element.getFirstChild(); child!=null;
                    child = child.getNextSibling()) {

                    if (child.getNodeType() != Node.ELEMENT_NODE) {
                        continue;
                    }
                    Element childElement = (Element) child;

                    for (int i = 0; i < attributesLength; i++) {
                        Attr currentAttr = (Attr) attributes.item(i);
                        if (!namespaceNs.equals(currentAttr.getNamespaceURI())) {
                            continue;
                        }
                        if (childElement.hasAttributeNS(namespaceNs,
                                                        currentAttr.getLocalName())) {
                            continue;
                        }
                        childElement.setAttributeNS(namespaceNs,
                                                    currentAttr.getName(),
                                                    currentAttr.getNodeValue());
                    }
                }
            }
        case Node.ENTITY_REFERENCE_NODE :
        case Node.DOCUMENT_NODE :
            parent = node;
            sibling = node.getFirstChild();
            break;
        }
        while ((sibling == null) && (parent != null)) {
            sibling = parent.getNextSibling();
            parent = parent.getParentNode();
        }
        if (sibling == null) {
            return;
        }

        node = sibling;
        sibling = node.getNextSibling();
    } while (true);
}
 
Example 17
Source File: DOMXPathFilter2Transform.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void unmarshalParams(Element curXPathElem) throws MarshalException
{
    List<XPathType> list = new ArrayList<XPathType>();
    while (curXPathElem != null) {
        String xPath = curXPathElem.getFirstChild().getNodeValue();
        String filterVal = DOMUtils.getAttributeValue(curXPathElem,
                                                      "Filter");
        if (filterVal == null) {
            throw new MarshalException("filter cannot be null");
        }
        XPathType.Filter filter = null;
        if (filterVal.equals("intersect")) {
            filter = XPathType.Filter.INTERSECT;
        } else if (filterVal.equals("subtract")) {
            filter = XPathType.Filter.SUBTRACT;
        } else if (filterVal.equals("union")) {
            filter = XPathType.Filter.UNION;
        } else {
            throw new MarshalException("Unknown XPathType filter type" +
                                       filterVal);
        }
        NamedNodeMap attributes = curXPathElem.getAttributes();
        if (attributes != null) {
            int length = attributes.getLength();
            Map<String, String> namespaceMap =
                new HashMap<String, String>(length);
            for (int i = 0; i < length; i++) {
                Attr attr = (Attr)attributes.item(i);
                String prefix = attr.getPrefix();
                if (prefix != null && prefix.equals("xmlns")) {
                    namespaceMap.put(attr.getLocalName(), attr.getValue());
                }
            }
            list.add(new XPathType(xPath, filter, namespaceMap));
        } else {
            list.add(new XPathType(xPath, filter));
        }

        curXPathElem = DOMUtils.getNextSiblingElement(curXPathElem);
    }
    this.params = new XPathFilter2ParameterSpec(list);
}
 
Example 18
Source File: DOMXPathFilter2Transform.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void unmarshalParams(Element curXPathElem) throws MarshalException
{
    List<XPathType> list = new ArrayList<XPathType>();
    while (curXPathElem != null) {
        String xPath = curXPathElem.getFirstChild().getNodeValue();
        String filterVal = DOMUtils.getAttributeValue(curXPathElem,
                                                      "Filter");
        if (filterVal == null) {
            throw new MarshalException("filter cannot be null");
        }
        XPathType.Filter filter = null;
        if (filterVal.equals("intersect")) {
            filter = XPathType.Filter.INTERSECT;
        } else if (filterVal.equals("subtract")) {
            filter = XPathType.Filter.SUBTRACT;
        } else if (filterVal.equals("union")) {
            filter = XPathType.Filter.UNION;
        } else {
            throw new MarshalException("Unknown XPathType filter type" +
                                       filterVal);
        }
        NamedNodeMap attributes = curXPathElem.getAttributes();
        if (attributes != null) {
            int length = attributes.getLength();
            Map<String, String> namespaceMap =
                new HashMap<String, String>(length);
            for (int i = 0; i < length; i++) {
                Attr attr = (Attr)attributes.item(i);
                String prefix = attr.getPrefix();
                if (prefix != null && prefix.equals("xmlns")) {
                    namespaceMap.put(attr.getLocalName(), attr.getValue());
                }
            }
            list.add(new XPathType(xPath, filter, namespaceMap));
        } else {
            list.add(new XPathType(xPath, filter));
        }

        curXPathElem = DOMUtils.getNextSiblingElement(curXPathElem);
    }
    this.params = new XPathFilter2ParameterSpec(list);
}
 
Example 19
Source File: DOMXPathFilter2Transform.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void unmarshalParams(Element curXPathElem) throws MarshalException
{
    List<XPathType> list = new ArrayList<XPathType>();
    while (curXPathElem != null) {
        String xPath = curXPathElem.getFirstChild().getNodeValue();
        String filterVal = DOMUtils.getAttributeValue(curXPathElem,
                                                      "Filter");
        if (filterVal == null) {
            throw new MarshalException("filter cannot be null");
        }
        XPathType.Filter filter = null;
        if (filterVal.equals("intersect")) {
            filter = XPathType.Filter.INTERSECT;
        } else if (filterVal.equals("subtract")) {
            filter = XPathType.Filter.SUBTRACT;
        } else if (filterVal.equals("union")) {
            filter = XPathType.Filter.UNION;
        } else {
            throw new MarshalException("Unknown XPathType filter type" +
                                       filterVal);
        }
        NamedNodeMap attributes = curXPathElem.getAttributes();
        if (attributes != null) {
            int length = attributes.getLength();
            Map<String, String> namespaceMap =
                new HashMap<String, String>(length);
            for (int i = 0; i < length; i++) {
                Attr attr = (Attr)attributes.item(i);
                String prefix = attr.getPrefix();
                if (prefix != null && prefix.equals("xmlns")) {
                    namespaceMap.put(attr.getLocalName(), attr.getValue());
                }
            }
            list.add(new XPathType(xPath, filter, namespaceMap));
        } else {
            list.add(new XPathType(xPath, filter));
        }

        curXPathElem = DOMUtils.getNextSiblingElement(curXPathElem);
    }
    this.params = new XPathFilter2ParameterSpec(list);
}
 
Example 20
Source File: DatasourceBeanDefinitionParser.java    From compass with Apache License 2.0 4 votes vote down vote up
/**
 * 继承prototype基类的属性配置
 * @param targetDataSourceElement
 * @param dataSourcePrototypeAttributeValue
 * @param parserContext
 * @return
 */
private AbstractBeanDefinition parseSingleTargetDatasourceBeanDefinition(
		Element targetDataSourceElement,
	    String dataSourcePrototypeAttributeValue, 
	    ParserContext parserContext) 
{
	BeanDefinitionBuilder targetDataSourceBeanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition();
	if(StringUtils.hasText(dataSourcePrototypeAttributeValue))
	{
		targetDataSourceBeanDefinitionBuilder.setParentName(dataSourcePrototypeAttributeValue.trim());
	}
	AbstractBeanDefinition targetDataSourceBeanDefinition = targetDataSourceBeanDefinitionBuilder.getBeanDefinition();
	
	List<Element> propertyElements = DomUtils.getChildElementsByTagName(targetDataSourceElement, PROPERTY);
	NamedNodeMap attributes=targetDataSourceElement.getAttributes();
		
	if (!CollectionUtils.isEmpty(propertyElements))
	{
		for (Element propertyElement : propertyElements) 
		{
			parserContext.getDelegate().parsePropertyElement(propertyElement, targetDataSourceBeanDefinition);
		}
	}
	
	if (attributes!=null && attributes.getLength() > 0) 
	{
		for (int i=0;i<attributes.getLength();i++)
		{
			Node node=attributes.item(i);
			if (!(node instanceof Attr))
			{
				continue;
			}

			Attr attr = (Attr) node;
			String attributeName = attr.getLocalName();
			String attributeValue = attr.getValue();
			MutablePropertyValues pvs = targetDataSourceBeanDefinition.getPropertyValues();
			if (pvs.contains(attributeName)) 
			{
				parserContext.getReaderContext().error("Property '" + attributeName + "' is already defined using " +
						"both <property> and inline syntax. Only one approach may be used per property.", attr);
				continue;
			}
			if (attributeName.endsWith(REF_SUFFIX)) 
			{
				attributeName = attributeName.substring(0, attributeName.length() - REF_SUFFIX.length());
				pvs.addPropertyValue(Conventions.attributeNameToPropertyName(attributeName), new RuntimeBeanReference(attributeValue));
			}
			else 
			{
				pvs.addPropertyValue(Conventions.attributeNameToPropertyName(attributeName), attributeValue);
			}


		}
	} 
	return targetDataSourceBeanDefinition;
}