Java Code Examples for org.w3c.dom.NodeList

The following examples show how to use org.w3c.dom.NodeList. These examples are extracted from open source projects. 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 Project: healthcare-dicom-dicomweb-adapter   Author: GoogleCloudPlatform   File: FileFormatWriter.java    License: Apache License 2.0 8 votes vote down vote up
private int computeLength(IIOMetadataNode root) {
    NodeList list = root.getChildNodes();
    int length = 0;
    for (int i = 0; i < list.getLength(); i++) {
        IIOMetadataNode node = (IIOMetadataNode)list.item(i);
        String name = node.getNodeName();

        if (format.isLeaf(name))
            length += new Integer((String)Box.getAttribute(node, "Length")).intValue();
        else
            length += computeLength(node);

    }

    return length + (root.getNodeName().startsWith("JPEG2000") ? 8 : 0) ;
}
 
Example #2
Source Project: arcusplatform   Author: arcus-smart-home   File: BaseDefinitionReader.java    License: Apache License 2.0 6 votes vote down vote up
protected T buildModel(Element root) {
   B builder = builder();
   builder
      .withName(root.getAttribute("name"))
      .withNamespace(root.getAttribute("namespace"))
      .withVersion(root.getAttribute("version"));
   
   NodeList nodes = root.getElementsByTagNameNS(schemaURI, "description");
   if (nodes.getLength() > 0)
   {
      Element description = (Element)nodes.item(0);
      builder.withDescription(readDescription(description));
   }
   else {
      logger.warn("No description was given for the capability {}", root.getAttribute("name"));
   }

   populateDefinitionSpecificData(builder, root);

   builder.withMethods(buildMethods(root.getElementsByTagNameNS(schemaURI, "method")));
   builder.withEvents(buildEvents(root.getElementsByTagNameNS(schemaURI, "event")));
   return builder.build();
}
 
Example #3
Source Project: MogwaiERDesignerNG   Author: mirkosertic   File: XMLTableSerializer.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void deserialize(Model aModel, Document aDocument) {
	// Now, parse tables
	NodeList theElements = aDocument.getElementsByTagName(TABLE);
	for (int i = 0; i < theElements.getLength(); i++) {
		Element theElement = (Element) theElements.item(i);

		Table theTable = new Table();
		theTable.setOwner(aModel);
		deserializeProperties(theElement, theTable);

		deserializeCommentElement(theElement, theTable);

		getXMLModelSerializer().getXMLAttributeSerializer().deserialize(aModel, theTable, theElement);
		getXMLModelSerializer().getXMLIndexSerializer().deserialize(theTable, theElement);

		aModel.getTables().add(theTable);
	}
}
 
Example #4
Source Project: micro-integrator   Author: wso2   File: MicroIntegratorBaseUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static void resolveLeafNodeValue(Node node) {

        if (node != null) {
            Element element = (Element) node;
            NodeList childNodeList = element.getChildNodes();
            for (int j = 0; j < childNodeList.getLength(); j++) {
                Node chileNode = childNodeList.item(j);
                if (!chileNode.hasChildNodes()) {
                    String nodeValue = resolveSystemProperty(chileNode.getTextContent());
                    childNodeList.item(j).setTextContent(nodeValue);
                } else {
                    resolveLeafNodeValue(chileNode);
                }
            }
        }
    }
 
Example #5
Source Project: dragonwell8_jdk   Author: alibaba   File: KeyInfo.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method itemUnknownElement
 *
 * @param i index
 * @return the element number of the unknown elements
 */
public Element itemUnknownElement(int i) {
    NodeList nl = this.constructionElement.getChildNodes();
    int res = 0;

    for (int j = 0; j < nl.getLength(); j++) {
        Node current = nl.item(j);

        /**
         * $todo$ using this method, we don't see unknown Elements
         *  from Signature NS; revisit
         */
        if ((current.getNodeType() == Node.ELEMENT_NODE)
            && current.getNamespaceURI().equals(Constants.SignatureSpecNS)) {
            res++;

            if (res == i) {
                return (Element) current;
            }
        }
    }

    return null;
}
 
Example #6
Source Project: TencentKona-8   Author: Tencent   File: SOFMarkerSegment.java    License: GNU General Public License v2.0 6 votes vote down vote up
void updateFromNativeNode(Node node, boolean fromScratch)
    throws IIOInvalidTreeException {
    NamedNodeMap attrs = node.getAttributes();
    int value = getAttributeValue(node, attrs, "process", 0, 2, false);
    tag = (value != -1) ? value+JPEG.SOF0 : tag;
    // If samplePrecision is present, it must be 8.
    // This just checks.  We don't bother to assign the value.
    value = getAttributeValue(node, attrs, "samplePrecision", 8, 8, false);
    value = getAttributeValue(node, attrs, "numLines", 0, 65535, false);
    numLines = (value != -1) ? value : numLines;
    value = getAttributeValue(node, attrs, "samplesPerLine", 0, 65535, false);
    samplesPerLine = (value != -1) ? value : samplesPerLine;
    int numComponents = getAttributeValue(node, attrs, "numFrameComponents",
                                          1, 4, false);
    NodeList children = node.getChildNodes();
    if (children.getLength() != numComponents) {
        throw new IIOInvalidTreeException
            ("numFrameComponents must match number of children", node);
    }
    componentSpecs = new ComponentSpec [numComponents];
    for (int i = 0; i < numComponents; i++) {
        componentSpecs[i] = new ComponentSpec(children.item(i));
    }
}
 
Example #7
Source Project: hop   Author: project-hop   File: XmlHandler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Find the value entry in a node
 *
 * @param n The node
 * @return The value entry as a string
 */
public static String getNodeValue( Node n ) {
  if ( n == null ) {
    return null;
  }

  // Find the child-nodes of this Node n:
  NodeList children = n.getChildNodes();
  for ( int i = 0; i < children.getLength(); i++ ) {
    // Try all children
    Node childnode = children.item( i );
    String retval = childnode.getNodeValue();
    if ( retval != null ) { // We found the right value
      return retval;
    }
  }
  return null;
}
 
Example #8
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: JPEGMetadata.java    License: Apache License 2.0 6 votes vote down vote up
private void mergeStandardTextNode(Node node)
    throws IIOInvalidTreeException {
    // Convert to comments.  For the moment ignore the encoding issue.
    // Ignore keywords, language, and encoding (for the moment).
    // If compression tag is present, use only entries with "none".
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        NamedNodeMap attrs = child.getAttributes();
        Node comp = attrs.getNamedItem("compression");
        boolean copyIt = true;
        if (comp != null) {
            String compString = comp.getNodeValue();
            if (!compString.equals("none")) {
                copyIt = false;
            }
        }
        if (copyIt) {
            String value = attrs.getNamedItem("value").getNodeValue();
            COMMarkerSegment com = new COMMarkerSegment(value);
            insertCOMMarkerSegment(com);
        }
    }
}
 
Example #9
Source Project: TencentKona-8   Author: Tencent   File: ExsltSets.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * The set:distinct function returns a subset of the nodes contained in the node-set NS passed
 * as the first argument. Specifically, it selects a node N if there is no node in NS that has
 * the same string value as N, and that precedes N in document order.
 *
 * @param nl NodeList for the node-set.
 * @return a NodeList with nodes from nl containing distinct string values.
 * In other words, if more than one node in nl contains the same string value,
 * only include the first such node found.
 *
 * @see <a href="http://www.exslt.org/">EXSLT</a>
 */
public static NodeList distinct(NodeList nl)
{
  NodeSet dist = new NodeSet();
  dist.setShouldCacheNodes(true);

  Map<String, Node> stringTable = new HashMap<>();

  for (int i = 0; i < nl.getLength(); i++)
  {
    Node currNode = nl.item(i);
    String key = toString(currNode);

    if (key == null)
      dist.addElement(currNode);
    else if (!stringTable.containsKey(key))
    {
      stringTable.put(key, currNode);
      dist.addElement(currNode);
    }
  }

  return dist;
}
 
Example #10
Source Project: hop   Author: project-hop   File: XmlHandler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Count nodes with a certain tag
 *
 * @param n   The node to look in
 * @param tag The tags to count
 * @return The number of nodes found with a certain tag
 */
public static int countNodes( Node n, String tag ) {
  NodeList children;
  Node childnode;

  int count = 0;

  if ( n == null ) {
    return 0;
  }

  children = n.getChildNodes();
  for ( int i = 0; i < children.getLength(); i++ ) {
    childnode = children.item( i );
    if ( childnode.getNodeName().equalsIgnoreCase( tag ) ) {
      // <file>
      count++;
    }
  }
  return count;
}
 
Example #11
Source Project: TencentKona-8   Author: Tencent   File: AnyTypeBeanInfo.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void serializeBody(Object element, XMLSerializer target) throws SAXException, IOException, XMLStreamException {
    NodeList childNodes = ((Element)element).getChildNodes();
    int len = childNodes.getLength();
    for( int i=0; i<len; i++ ) {
        Node child = childNodes.item(i);
        switch(child.getNodeType()) {
        case Node.CDATA_SECTION_NODE:
        case Node.TEXT_NODE:
            target.text(child.getNodeValue(),null);
            break;
        case Node.ELEMENT_NODE:
            target.writeDom((Element)child,domHandler,null,null);
            break;
        }
    }
}
 
Example #12
Source Project: wecube-platform   Author: WeBankPartners   File: PluginPackageXmlParser.java    License: Apache License 2.0 6 votes vote down vote up
private Set<PluginPackageDependency> parsePackageDependencies(NodeList packageDependencyNodes,
        PluginPackage pluginPackage) throws XPathExpressionException {
    Set<PluginPackageDependency> pluginPackageDependencies = new LinkedHashSet<>();
    for (int i = 0; i < packageDependencyNodes.getLength(); i++) {
        Node pluginPackageDependencyNode = packageDependencyNodes.item(i);

        PluginPackageDependency pluginPackageDependency = new PluginPackageDependency();
        pluginPackageDependency.setPluginPackage(pluginPackage);

        pluginPackageDependency.setDependencyPackageName(
                getNonNullStringAttribute(pluginPackageDependencyNode, "./@name", "Package dependency name"));
        pluginPackageDependency.setDependencyPackageVersion(
                getNonNullStringAttribute(pluginPackageDependencyNode, "./@version", "Package dependency version"));

        pluginPackageDependency.setPluginPackage(pluginPackage);

        pluginPackageDependencies.add(pluginPackageDependency);
    }
    return pluginPackageDependencies;
}
 
Example #13
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: SOFMarkerSegment.java    License: Apache License 2.0 6 votes vote down vote up
void updateFromNativeNode(Node node, boolean fromScratch)
    throws IIOInvalidTreeException {
    NamedNodeMap attrs = node.getAttributes();
    int value = getAttributeValue(node, attrs, "process", 0, 2, false);
    tag = (value != -1) ? value+JPEG.SOF0 : tag;
    // If samplePrecision is present, it must be 8.
    // This just checks.  We don't bother to assign the value.
    value = getAttributeValue(node, attrs, "samplePrecision", 8, 8, false);
    value = getAttributeValue(node, attrs, "numLines", 0, 65535, false);
    numLines = (value != -1) ? value : numLines;
    value = getAttributeValue(node, attrs, "samplesPerLine", 0, 65535, false);
    samplesPerLine = (value != -1) ? value : samplesPerLine;
    int numComponents = getAttributeValue(node, attrs, "numFrameComponents",
                                          1, 4, false);
    NodeList children = node.getChildNodes();
    if (children.getLength() != numComponents) {
        throw new IIOInvalidTreeException
            ("numFrameComponents must match number of children", node);
    }
    componentSpecs = new ComponentSpec [numComponents];
    for (int i = 0; i < numComponents; i++) {
        componentSpecs[i] = new ComponentSpec(children.item(i));
    }
}
 
Example #14
Source Project: mapper-generator-javafx   Author: alansun2   File: MyBatisGeneratorConfigurationParser.java    License: Apache License 2.0 6 votes vote down vote up
public Configuration parseConfiguration(Element rootNode)
        throws XMLParserException {

    Configuration configuration = new Configuration();

    NodeList nodeList = rootNode.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node childNode = nodeList.item(i);

        if (childNode.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        if ("properties".equals(childNode.getNodeName())) {
            parseProperties(childNode);
        } else if ("classPathEntry".equals(childNode.getNodeName())) {
            parseClassPathEntry(configuration, childNode);
        } else if ("context".equals(childNode.getNodeName())) {
            parseContext(configuration, childNode);
        }
    }

    return configuration;
}
 
Example #15
Source Project: mzmine3   Author: mzmine   File: XMLUtils.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static Range<Integer> parseIntegerRange(Element xmlElement, String tagName) {
  NodeList items = xmlElement.getElementsByTagName(tagName);
  if (items.getLength() == 0)
    return null;
  Element tag = (Element) items.item(0);
  items = tag.getElementsByTagName("min");
  if (items.getLength() == 0)
    return null;
  Element min = (Element) items.item(0);
  items = tag.getElementsByTagName("max");
  if (items.getLength() == 0)
    return null;
  Element max = (Element) items.item(0);

  String minText = min.getTextContent();
  String maxText = max.getTextContent();
  Range<Integer> r = Range.closed(Integer.valueOf(minText), Integer.valueOf(maxText));
  return r;
}
 
Example #16
Source Project: hop   Author: project-hop   File: XmlHandler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get the value of a tag in a node
 *
 * @param n   The node to look in
 * @param tag The tag to look for
 * @return The value of the tag or null if nothing was found.
 */
public static String getTagValue( Node n, String tag ) {
  NodeList children;
  Node childnode;

  if ( n == null ) {
    return null;
  }

  children = n.getChildNodes();
  for ( int i = 0; i < children.getLength(); i++ ) {
    childnode = children.item( i );
    if ( childnode.getNodeName().equalsIgnoreCase( tag ) ) {
      if ( childnode.getFirstChild() != null ) {
        return childnode.getFirstChild().getNodeValue();
      }
    }
  }
  return null;
}
 
Example #17
Source Project: dragonwell8_jdk   Author: alibaba   File: SOFMarkerSegment.java    License: GNU General Public License v2.0 6 votes vote down vote up
void updateFromNativeNode(Node node, boolean fromScratch)
    throws IIOInvalidTreeException {
    NamedNodeMap attrs = node.getAttributes();
    int value = getAttributeValue(node, attrs, "process", 0, 2, false);
    tag = (value != -1) ? value+JPEG.SOF0 : tag;
    // If samplePrecision is present, it must be 8.
    // This just checks.  We don't bother to assign the value.
    value = getAttributeValue(node, attrs, "samplePrecision", 8, 8, false);
    value = getAttributeValue(node, attrs, "numLines", 0, 65535, false);
    numLines = (value != -1) ? value : numLines;
    value = getAttributeValue(node, attrs, "samplesPerLine", 0, 65535, false);
    samplesPerLine = (value != -1) ? value : samplesPerLine;
    int numComponents = getAttributeValue(node, attrs, "numFrameComponents",
                                          1, 4, false);
    NodeList children = node.getChildNodes();
    if (children.getLength() != numComponents) {
        throw new IIOInvalidTreeException
            ("numFrameComponents must match number of children", node);
    }
    componentSpecs = new ComponentSpec [numComponents];
    for (int i = 0; i < numComponents; i++) {
        componentSpecs[i] = new ComponentSpec(children.item(i));
    }
}
 
Example #18
Source Project: android-uiconductor   Author: google   File: XmlHelper.java    License: Apache License 2.0 6 votes vote down vote up
private static Node getNodeByXpath(String xml, String xPathString) throws Exception {
  DocumentBuilder builder;
  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  Document doc = null;

  try {
    builder = factory.newDocumentBuilder();
    doc = builder.parse(new InputSource(new StringReader(xml)));
  } catch (Exception e) {
    logger.warning("Failed to parse xml." + e.getMessage());
  }
  XPath xpathCompiler = XPathFactory.newInstance().newXPath();

  NodeList nodes =
      (NodeList) xpathCompiler.compile(xPathString).evaluate(doc, XPathConstants.NODESET);
  if (nodes.getLength() == 0) {
    return null;
  }
  return nodes.item(0);
}
 
Example #19
Source Project: mapper-generator-javafx   Author: alansun2   File: XmlFileMergerJaxp.java    License: Apache License 2.0 6 votes vote down vote up
private static boolean isNewFormatNode(Node node) {
    // check for new node format - if the first non-whitespace node
    // is an XML comment, and the comment includes
    // one of the old element tags,
    // then it is a generated node
    NodeList children = node.getChildNodes();
    int length = children.getLength();
    for (int i = 0; i < length; i++) {
        Node childNode = children.item(i);
        if (childNode != null && childNode.getNodeType() == Node.COMMENT_NODE) {
            String commentData = ((Comment) childNode).getData();
            return MergeConstants.comentContainsTag(commentData);
        }
    }
    
    return false;
}
 
Example #20
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: ExsltBase.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Return the string value of a Node
 *
 * @param n The Node.
 * @return The string value of the Node
 */
protected static String toString(Node n)
{
  if (n instanceof DTMNodeProxy)
       return ((DTMNodeProxy)n).getStringValue();
  else
  {
    String value = n.getNodeValue();
    if (value == null)
    {
      NodeList nodelist = n.getChildNodes();
      StringBuffer buf = new StringBuffer();
      for (int i = 0; i < nodelist.getLength(); i++)
      {
        Node childNode = nodelist.item(i);
        buf.append(toString(childNode));
      }
      return buf.toString();
    }
    else
      return value;
  }
}
 
Example #21
Source Project: healthcare-dicom-dicomweb-adapter   Author: GoogleCloudPlatform   File: FileTypeBox.java    License: Apache License 2.0 6 votes vote down vote up
/** Constructs a <code>FileTypeBox</code> from
 *  <code>org.w3c.dom.Node</code>.
 */
public FileTypeBox(Node node) throws IIOInvalidTreeException {
    super(node);
    NodeList children = node.getChildNodes();

    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        String name = child.getNodeName();

        if ("Brand".equals(name)) {
            brand = Box.getIntElementValue(child);
        }

        if ("MinorVersion".equals(name)) {
            minorVersion = Box.getIntElementValue(child);
        }

        if ("CompatibilityList".equals(name)) {
            compatibility = Box.getIntArrayElementValue(child);
        }
    }
}
 
Example #22
Source Project: TencentKona-8   Author: Tencent   File: XMLSchemaInternalizationLogic.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new XML Schema element of the given local name
 * and insert it as the first child of the given parent node.
 *
 * @return
 *      Newly create element.
 */
private Element insertXMLSchemaElement( Element parent, String localName ) {
    // use the same prefix as the parent node to avoid modifying
    // the namespace binding.
    String qname = parent.getTagName();
    int idx = qname.indexOf(':');
    if(idx==-1)     qname = localName;
    else            qname = qname.substring(0,idx+1)+localName;

    Element child = parent.getOwnerDocument().createElementNS( WellKnownNamespace.XML_SCHEMA, qname );

    NodeList children = parent.getChildNodes();

    if( children.getLength()==0 )
        parent.appendChild(child);
    else
        parent.insertBefore( child, children.item(0) );

    return child;
}
 
Example #23
Source Project: hop   Author: project-hop   File: XmlHandler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get the value of a tag in a node
 *
 * @param n   The node to look in
 * @param tag The tag to look for
 * @return The value of the tag or null if nothing was found.
 */
public static String getTagValueWithAttribute( Node n, String tag, String attribute ) {
  NodeList children;
  Node childnode;

  if ( n == null ) {
    return null;
  }

  children = n.getChildNodes();
  for ( int i = 0; i < children.getLength(); i++ ) {
    childnode = children.item( i );
    if ( childnode.getNodeName().equalsIgnoreCase( tag )
      && childnode.getAttributes().getNamedItem( attribute ) != null ) {
      if ( childnode.getFirstChild() != null ) {
        return childnode.getFirstChild().getNodeValue();
      }
    }
  }
  return null;
}
 
Example #24
Source Project: cstc   Author: usdAG   File: XmlSignature.java    License: GNU General Public License v3.0 6 votes vote down vote up
protected void validateIdAttributes(Document doc) throws Exception {
  String idAttribute = new String(idIdentifier.getText());
  if( idAttribute == null || idAttribute.isEmpty() ) {
    return;
  }
  XPathFactory xPathfactory = XPathFactory.newInstance();
  XPath xpath = xPathfactory.newXPath();
  XPathExpression expr = xpath.compile("descendant-or-self::*/@" + idAttribute);
  NodeList nodeList = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
  if(nodeList != null && nodeList.getLength() > 0) {
    for(int j = 0; j < nodeList.getLength(); j++) {
        Attr attr = (Attr)nodeList.item(j);
        ((Element)attr.getOwnerElement()).setIdAttributeNode(attr,true);
    }
  }
}
 
Example #25
Source Project: hop   Author: project-hop   File: XmlHandler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get nodes with a certain tag one level down
 *
 * @param n   The node to look in
 * @param tag The tags to count
 * @return The list of nodes found with the specified tag
 */
public static List<Node> getNodes( Node n, String tag ) {
  NodeList children;
  Node childnode;

  List<Node> nodes = new ArrayList<Node>();

  if ( n == null ) {
    return nodes;
  }

  children = n.getChildNodes();
  for ( int i = 0; i < children.getLength(); i++ ) {
    childnode = children.item( i );
    if ( childnode.getNodeName().equalsIgnoreCase( tag ) ) {
      // <file>
      nodes.add( childnode );
    }
  }
  return nodes;
}
 
Example #26
Source Project: mapper-generator-javafx   Author: alansun2   File: MyBatisGeneratorConfigurationParser.java    License: Apache License 2.0 6 votes vote down vote up
protected void parseJavaModelGenerator(Context context, Node node) {
    JavaModelGeneratorConfiguration javaModelGeneratorConfiguration = new JavaModelGeneratorConfiguration();

    context
            .setJavaModelGeneratorConfiguration(javaModelGeneratorConfiguration);

    Properties attributes = parseAttributes(node);
    String targetPackage = attributes.getProperty("targetPackage");
    String targetProject = attributes.getProperty("targetProject");

    javaModelGeneratorConfiguration.setTargetPackage(targetPackage);
    javaModelGeneratorConfiguration.setTargetProject(targetProject);

    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node childNode = nodeList.item(i);

        if (childNode.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        if ("property".equals(childNode.getNodeName())) {
            parseProperty(javaModelGeneratorConfiguration, childNode);
        }
    }
}
 
Example #27
Source Project: wecube-platform   Author: WeBankPartners   File: PluginPackageXmlParser.java    License: Apache License 2.0 5 votes vote down vote up
private Set<PluginPackageMenu> parseMenus(NodeList menuNodes, PluginPackage pluginPackage)
        throws XPathExpressionException {
    Set<PluginPackageMenu> pluginPackageMenus = new LinkedHashSet<>();

    for (int i = 0; i < menuNodes.getLength(); i++) {
        Node pluginPackageMenuNode = menuNodes.item(i);

        PluginPackageMenu pluginPackageMenu = new PluginPackageMenu();
        pluginPackageMenu
                .setCode(getNonNullStringAttribute(pluginPackageMenuNode, "./@code", "Plugin package menu code"));
        pluginPackageMenu.setCategory(
                getNonNullStringAttribute(pluginPackageMenuNode, "./@cat", "Plugin package menu category"));
        String menuDisplayName = getNonNullStringAttribute(pluginPackageMenuNode, "./@displayName",
                "Plugin package menu display name");
        pluginPackageMenu.setDisplayName(menuDisplayName);
        String localDisplayName = getStringAttribute(pluginPackageMenuNode, "./@localDisplayName");
        if (StringUtils.isNotBlank(localDisplayName)) {
            pluginPackageMenu.setLocalDisplayName(localDisplayName);
        } else {
            pluginPackageMenu.setLocalDisplayName(menuDisplayName);
        }
        pluginPackageMenu.setPath(pluginPackageMenuNode.getTextContent());
        pluginPackageMenu.setSource(pluginPackage.getId());

        pluginPackageMenu.setPluginPackage(pluginPackage);

        pluginPackageMenus.add(pluginPackageMenu);
    }

    return pluginPackageMenus;
}
 
Example #28
Source Project: JavaPackager   Author: fvarrui   File: XMLUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Removes whitespaces from nodes
 * @param node Root node
 */
public static void trimWhitespace(Node node) {
    NodeList children = node.getChildNodes();
    for(int i = 0; i < children.getLength(); ++i) {
        Node child = children.item(i);
        if(child.getNodeType() == Node.TEXT_NODE) {
            child.setTextContent(child.getTextContent().trim());
        }
        trimWhitespace(child);
    }
}
 
Example #29
Source Project: hop   Author: project-hop   File: SwitchCaseTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Load local xml data for case-value mapping, transform info.
 *
 * @return
 * @throws URISyntaxException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws IOException
 */
private static Node loadTransformXmlMetadata( String fileName ) throws URISyntaxException, ParserConfigurationException, SAXException, IOException {
  String PKG = SwitchCaseTest.class.getPackage().getName().replace( ".", "/" );
  PKG = PKG + "/";
  URL url = SwitchCaseTest.class.getClassLoader().getResource( PKG + fileName );
  File file = new File( url.toURI() );
  DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
  DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
  Document doc = dBuilder.parse( file );
  NodeList nList = doc.getElementsByTagName( "transform" );
  return nList.item( 0 );
}
 
Example #30
Source Project: Box   Author: lulululbj   File: ManifestAttributes.java    License: Apache License 2.0 5 votes vote down vote up
private void parse(Document doc) {
	NodeList nodeList = doc.getChildNodes();
	for (int count = 0; count < nodeList.getLength(); count++) {
		Node node = nodeList.item(count);
		if (node.getNodeType() == Node.ELEMENT_NODE
				&& node.hasChildNodes()) {
			parseAttrList(node.getChildNodes());
		}
	}
}