Example usage for org.w3c.dom Node hasChildNodes

List of usage examples for org.w3c.dom Node hasChildNodes

Introduction

In this page you can find the example usage for org.w3c.dom Node hasChildNodes.

Prototype

public boolean hasChildNodes();

Source Link

Document

Returns whether this node has any children.

Usage

From source file:org.jmingo.parser.xml.dom.ContextDefinitionParser.java

/**
 * Parse <querySetConfig/> tag.//from  w  w  w . j av  a  2s  .c  o  m
 *
 * @param element element of XML document
 * @return set of paths queries definitions
 */
private QuerySetConfig parseQuerySetConfigTag(Element element) throws JMingoParserException {
    QuerySetConfig querySetConfig = new QuerySetConfig();
    Set<String> querySets = ImmutableSet.of();
    // expected what xml contains single <querySetConfig> tag
    // therefore take first element from node list is normal
    Node querySetConfigNode = getFirstTagOccurrence(element, QUERY_SET_CONFIG_TAG);
    if (querySetConfigNode != null && querySetConfigNode.hasChildNodes()) {
        querySets = parseQuerySets(querySetConfigNode.getChildNodes());
    }
    querySetConfig.addQuerySet(querySets);
    return querySetConfig;
}

From source file:org.jmingo.parser.xml.dom.util.DomUtil.java

/**
 * Gets child nodes with specified name including nested for specified root node.
 *//*from   w ww .  j a v a  2 s  .  co m*/
public static List<Node> getAllChildNodes(Node root, String name) {
    if (!root.hasChildNodes()) {
        return Collections.emptyList();
    }
    List<Node> nodes = new ArrayList<>();
    for (int index = 0; index < root.getChildNodes().getLength(); index++) {
        if (name.equals(root.getChildNodes().item(index).getNodeName())) {
            nodes.add(root.getChildNodes().item(index));
        }
        if (root.getChildNodes().item(index).hasChildNodes()) {
            nodes.addAll(getAllChildNodes(root.getChildNodes().item(index), name));
        }
    }
    return nodes;
}

From source file:org.jmingo.parser.xml.dom.util.DomUtil.java

/**
 * Get child nodes from dedicated node./*from  www. j av  a  2s  .  c  om*/
 *
 * @param node the node {@link Node}
 * @return child nodes. returns empty list if there are no child nodes.
 */
public static List<Node> getChildNodes(Node node) {
    if (!node.hasChildNodes()) {
        return Collections.emptyList();
    }
    List<Node> childNodes = Lists.newArrayList();
    NodeList childList = node.getChildNodes();
    for (int i = 0; i < childList.getLength(); i++) {
        childNodes.add(childList.item(i));
    }
    return childNodes;
}

From source file:org.kuali.rice.core.api.util.xml.XmlHelper.java

private static void trimElement(Node node) throws SAXException, IOException, ParserConfigurationException {

    if (node.hasChildNodes()) {
        NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if (child != null) {
                trimElement(child);/*ww  w  . j av a  2 s.c  om*/
            }
        }
    } else {
        if (node.getNodeType() == Node.TEXT_NODE) {
            String text = node.getNodeValue();
            text = StringUtils.isEmpty(text) ? "" : text.trim();
            node.setNodeValue(text);
        }
    }
}

From source file:org.kuali.rice.kew.doctype.DocumentTypeSecurity.java

/** parse <security> XML to populate security object
 * @throws ParserConfigurationException//from   w  w  w.  j a  v  a  2 s .c om
 * @throws IOException
 * @throws SAXException */
public DocumentTypeSecurity(String standardApplicationId, String documentTypeSecurityXml) {
    try {
        if (org.apache.commons.lang.StringUtils.isEmpty(documentTypeSecurityXml)) {
            return;
        }

        InputSource inputSource = new InputSource(
                new BufferedReader(new StringReader(documentTypeSecurityXml)));
        Element securityElement = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputSource)
                .getDocumentElement();

        String active = (String) xpath.evaluate("./@active", securityElement, XPathConstants.STRING);
        if (org.apache.commons.lang.StringUtils.isEmpty(active) || "true".equals(active.toLowerCase())) {
            // true is the default
            this.setActive(Boolean.valueOf(true));
        } else {
            this.setActive(Boolean.valueOf(false));
        }

        // there should only be one <initiator> tag
        NodeList initiatorNodes = (NodeList) xpath.evaluate("./initiator", securityElement,
                XPathConstants.NODESET);
        if (initiatorNodes != null && initiatorNodes.getLength() > 0) {
            Node initiatorNode = initiatorNodes.item(0);
            String value = initiatorNode.getTextContent();
            if (org.apache.commons.lang.StringUtils.isEmpty(value) || value.toLowerCase().equals("true")) {
                this.setInitiatorOk(Boolean.valueOf(true));
            } else {
                this.initiatorOk = Boolean.valueOf(false);
            }
        }

        // there should only be one <routeLogAuthenticated> tag
        NodeList routeLogAuthNodes = (NodeList) xpath.evaluate("./routeLogAuthenticated", securityElement,
                XPathConstants.NODESET);
        if (routeLogAuthNodes != null && routeLogAuthNodes.getLength() > 0) {
            Node routeLogAuthNode = routeLogAuthNodes.item(0);
            String value = routeLogAuthNode.getTextContent();
            if (org.apache.commons.lang.StringUtils.isEmpty(value) || value.toLowerCase().equals("true")) {
                this.routeLogAuthenticatedOk = Boolean.valueOf(true);
            } else {
                this.routeLogAuthenticatedOk = Boolean.valueOf(false);
            }
        }

        NodeList searchableAttributeNodes = (NodeList) xpath.evaluate("./searchableAttribute", securityElement,
                XPathConstants.NODESET);
        if (searchableAttributeNodes != null && searchableAttributeNodes.getLength() > 0) {
            for (int i = 0; i < searchableAttributeNodes.getLength(); i++) {
                Node searchableAttributeNode = searchableAttributeNodes.item(i);
                String name = (String) xpath.evaluate("./@name", searchableAttributeNode,
                        XPathConstants.STRING);
                String idType = (String) xpath.evaluate("./@idType", searchableAttributeNode,
                        XPathConstants.STRING);
                if (!org.apache.commons.lang.StringUtils.isEmpty(name)
                        && !org.apache.commons.lang.StringUtils.isEmpty(idType)) {
                    KeyValue searchableAttribute = new ConcreteKeyValue(name, idType);
                    searchableAttributes.add(searchableAttribute);
                }
            }
        }

        NodeList workgroupNodes = (NodeList) xpath.evaluate("./workgroup", securityElement,
                XPathConstants.NODESET);
        if (workgroupNodes != null && workgroupNodes.getLength() > 0) {
            LOG.warn(
                    "Document Type Security XML is using deprecated element 'workgroup', please use 'groupName' instead.");
            for (int i = 0; i < workgroupNodes.getLength(); i++) {
                Node workgroupNode = workgroupNodes.item(i);
                String value = workgroupNode.getTextContent().trim();
                if (!org.apache.commons.lang.StringUtils.isEmpty(value)) {
                    value = Utilities.substituteConfigParameters(value);
                    String namespaceCode = Utilities.parseGroupNamespaceCode(value);
                    String groupName = Utilities.parseGroupName(value);
                    Group groupObject = KimApiServiceLocator.getGroupService()
                            .getGroupByNamespaceCodeAndName(namespaceCode, groupName);
                    if (groupObject == null) {
                        throw new WorkflowException("Could not find group: " + value);
                    }
                    workgroups.add(groupObject);
                }
            }
        }

        NodeList groupNodes = (NodeList) xpath.evaluate("./groupName", securityElement, XPathConstants.NODESET);
        if (groupNodes != null && groupNodes.getLength() > 0) {
            for (int i = 0; i < groupNodes.getLength(); i++) {
                Node groupNode = groupNodes.item(i);
                if (groupNode.getNodeType() == Node.ELEMENT_NODE) {
                    String groupName = groupNode.getTextContent().trim();
                    if (!org.apache.commons.lang.StringUtils.isEmpty(groupName)) {
                        groupName = Utilities.substituteConfigParameters(groupName).trim();
                        String namespaceCode = Utilities.substituteConfigParameters(
                                ((Element) groupNode).getAttribute(XmlConstants.NAMESPACE)).trim();
                        Group groupObject = KimApiServiceLocator.getGroupService()
                                .getGroupByNamespaceCodeAndName(namespaceCode, groupName);

                        if (groupObject != null) {
                            workgroups.add(groupObject);
                        } else {
                            LOG.warn("Could not find group with name '" + groupName + "' and namespace '"
                                    + namespaceCode + "' which was defined on Document Type security");
                        }
                        //                if (groupObject == null) {
                        //                  throw new WorkflowException("Could not find group with name '" + groupName + "' and namespace '" + namespaceCode + "'");
                        //                }

                    }
                }
            }
        }

        NodeList permissionNodes = (NodeList) xpath.evaluate("./permission", securityElement,
                XPathConstants.NODESET);
        if (permissionNodes != null && permissionNodes.getLength() > 0) {
            for (int i = 0; i < permissionNodes.getLength(); i++) {
                Node permissionNode = permissionNodes.item(i);
                if (permissionNode.getNodeType() == Node.ELEMENT_NODE) {
                    SecurityPermissionInfo securityPermission = new SecurityPermissionInfo();
                    securityPermission
                            .setPermissionName(
                                    Utilities
                                            .substituteConfigParameters(
                                                    ((Element) permissionNode).getAttribute(XmlConstants.NAME))
                                            .trim());
                    securityPermission
                            .setPermissionNamespaceCode(Utilities
                                    .substituteConfigParameters(
                                            ((Element) permissionNode).getAttribute(XmlConstants.NAMESPACE))
                                    .trim());
                    if (!StringUtils.isEmpty(securityPermission.getPermissionName())
                            && !StringUtils.isEmpty(securityPermission.getPermissionNamespaceCode())) {
                        //get details and qualifications
                        if (permissionNode.hasChildNodes()) {
                            NodeList permissionChildNodes = permissionNode.getChildNodes();
                            for (int j = 0; j < permissionChildNodes.getLength(); j++) {
                                Node permissionChildNode = permissionChildNodes.item(j);
                                if (permissionChildNode.getNodeType() == Node.ELEMENT_NODE) {
                                    String childAttributeName = Utilities.substituteConfigParameters(
                                            ((Element) permissionChildNode).getAttribute(XmlConstants.NAME))
                                            .trim();
                                    String childAttributeValue = permissionChildNode.getTextContent().trim();
                                    if (!StringUtils.isEmpty(childAttributeValue)) {
                                        childAttributeValue = Utilities
                                                .substituteConfigParameters(childAttributeValue).trim();
                                    }
                                    if (!StringUtils.isEmpty(childAttributeValue)) {
                                        childAttributeValue = Utilities
                                                .substituteConfigParameters(childAttributeValue).trim();
                                    }
                                    if (permissionChildNode.getNodeName().trim().equals("permissionDetail")) {
                                        securityPermission.getPermissionDetails().put(childAttributeName,
                                                childAttributeValue);
                                    }
                                    if (permissionChildNode.getNodeName().trim().equals("qualification")) {
                                        securityPermission.getQualifications().put(childAttributeName,
                                                childAttributeValue);
                                    }
                                }
                            }
                        }

                        //if ( KimApiServiceLocator.getPermissionService().isPermissionDefined(securityPermission.getPermissionNamespaceCode(), securityPermission.getPermissionName(), securityPermission.getPermissionDetails())) {
                        permissions.add(securityPermission);
                        //} else {
                        //  LOG.warn("Could not find permission with name '" + securityPermission.getPermissionName() + "' and namespace '" + securityPermission.getPermissionNamespaceCode() + "' which was defined on Document Type security");
                        //}
                    }
                }
            }
        }

        NodeList roleNodes = (NodeList) xpath.evaluate("./role", securityElement, XPathConstants.NODESET);
        if (roleNodes != null && roleNodes.getLength() > 0) {
            for (int i = 0; i < roleNodes.getLength(); i++) {
                Element roleElement = (Element) roleNodes.item(i);
                String value = roleElement.getTextContent().trim();
                String allowedValue = roleElement.getAttribute("allowed");
                if (StringUtils.isBlank(allowedValue)) {
                    allowedValue = "true";
                }
                if (!org.apache.commons.lang.StringUtils.isEmpty(value)) {
                    if (Boolean.parseBoolean(allowedValue)) {
                        allowedRoles.add(value);
                    } else {
                        disallowedRoles.add(value);
                    }
                }
            }
        }

        NodeList attributeNodes = (NodeList) xpath.evaluate("./securityAttribute", securityElement,
                XPathConstants.NODESET);
        if (attributeNodes != null && attributeNodes.getLength() > 0) {
            for (int i = 0; i < attributeNodes.getLength(); i++) {
                Element attributeElement = (Element) attributeNodes.item(i);
                NamedNodeMap elemAttributes = attributeElement.getAttributes();
                // can be an attribute name or an actual classname
                String attributeOrClassName = null;
                String applicationId = standardApplicationId;
                if (elemAttributes.getNamedItem("name") != null) {
                    // found a name attribute so find the class name
                    String extensionName = elemAttributes.getNamedItem("name").getNodeValue().trim();
                    this.securityAttributeExtensionNames.add(extensionName);
                } else if (elemAttributes.getNamedItem("class") != null) {
                    // class name defined
                    String className = elemAttributes.getNamedItem("class").getNodeValue().trim();
                    this.securityAttributeClassNames.add(className);
                } else {
                    throw new WorkflowException(
                            "Cannot find attribute 'name' or attribute 'class' for securityAttribute Node");
                }
            }
        }
    } catch (Exception err) {
        throw new WorkflowRuntimeException(err);
    }
}

From source file:org.kuali.rice.kew.rule.xmlrouting.StandardGenericXMLRuleAttribute.java

public String getDocContent() {
    XPath xpath = XPathHelper.newXPath();
    final String findDocContent = "//routingConfig/xmlDocumentContent";
    try {// w  ww .j  a v  a  2  s.c o m
        Node xmlDocumentContent = (Node) xpath.evaluate(findDocContent, getConfigXML(), XPathConstants.NODE);

        NodeList nodes = getFields(xpath, getConfigXML(), new String[] { "ALL", "REPORT", "RULE" });
        //            if (nodes == null || nodes.getLength() == 0) {
        //                return "";
        //            }

        if (xmlDocumentContent != null && xmlDocumentContent.hasChildNodes()) {
            // Custom doc content in the routingConfig xml.
            String documentContent = "";
            NodeList customNodes = xmlDocumentContent.getChildNodes();
            for (int i = 0; i < customNodes.getLength(); i++) {
                Node childNode = customNodes.item(i);
                documentContent += XmlJotter.jotNode(childNode);
            }

            for (int i = 0; i < nodes.getLength(); i++) {
                Node field = nodes.item(i);
                NamedNodeMap fieldAttributes = field.getAttributes();
                String fieldName = fieldAttributes.getNamedItem("name").getNodeValue();
                LOG.debug("Replacing field '" + fieldName + "'");
                Map map = getParamMap();
                String fieldValue = (String) map.get(fieldName);
                if (map != null && !org.apache.commons.lang.StringUtils.isEmpty(fieldValue)) {
                    LOG.debug("Replacing %" + fieldName + "% with field value: '" + fieldValue + "'");
                    documentContent = documentContent.replaceAll("%" + fieldName + "%", fieldValue);
                } else {
                    LOG.debug("Field map is null or fieldValue is empty");
                }
            }
            return documentContent;
        } else {
            // Standard doc content if no doc content is found in the routingConfig xml.
            StringBuffer documentContent = new StringBuffer("<xmlRouting>");
            for (int i = 0; i < nodes.getLength(); i++) {
                Node field = nodes.item(i);
                NamedNodeMap fieldAttributes = field.getAttributes();
                String fieldName = fieldAttributes.getNamedItem("name").getNodeValue();
                Map map = getParamMap();
                if (map != null && !org.apache.commons.lang.StringUtils.isEmpty((String) map.get(fieldName))) {
                    documentContent.append("<field name=\"");
                    documentContent.append(fieldName);
                    documentContent.append("\"><value>");
                    documentContent.append((String) map.get(fieldName));
                    documentContent.append("</value></field>");
                }
            }
            documentContent.append("</xmlRouting>");
            return documentContent.toString();
        }
    } catch (XPathExpressionException e) {
        LOG.error("error in getDocContent ", e);
        throw new RuntimeException("Error trying to find xml content with xpath expression", e);
    } catch (Exception e) {
        LOG.error("error in getDocContent attempting to find xml doc content", e);
        throw new RuntimeException("Error trying to get xml doc content.", e);
    }
}

From source file:org.nuxeo.common.xmap.DOMHelper.java

/**
 * Parses a string containing XML and returns a DocumentFragment containing
 * the nodes of the parsed XML.// w w w.j a v  a2  s.  co  m
 */
public static void loadFragment(Element el, String fragment) {
    // Wrap the fragment in an arbitrary element
    fragment = "<fragment>" + fragment + "</fragment>";
    try {
        // Create a DOM builder and parse the fragment
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        Document d = factory.newDocumentBuilder().parse(new InputSource(new StringReader(fragment)));

        Document doc = el.getOwnerDocument();

        // Import the nodes of the new document into doc so that they
        // will be compatible with doc
        Node node = doc.importNode(d.getDocumentElement(), true);

        // Create the document fragment node to hold the new nodes
        DocumentFragment docfrag = doc.createDocumentFragment();

        // Move the nodes into the fragment
        while (node.hasChildNodes()) {
            el.appendChild(node.removeChild(node.getFirstChild()));
        }

    } catch (ParserConfigurationException e) {
        log.error(e, e);
    } catch (SAXException e) {
        log.error(e, e);
    } catch (IOException e) {
        log.error(e, e);
    }
}

From source file:org.opencastproject.mediapackage.elementbuilder.TrackBuilderPlugin.java

/**
 * @see org.opencastproject.mediapackage.elementbuilder.MediaPackageElementBuilderPlugin#elementFromManifest(org.w3c.dom.Node,
 *      org.opencastproject.mediapackage.MediaPackageSerializer)
 *///from w  w  w  . java  2s . c  o  m
public MediaPackageElement elementFromManifest(Node elementNode, MediaPackageSerializer serializer)
        throws UnsupportedElementException {

    String id = null;
    MimeType mimeType = null;
    MediaPackageElementFlavor flavor = null;
    String reference = null;
    URI url = null;
    long size = -1;
    Checksum checksum = null;

    try {
        // id
        id = (String) xpath.evaluate("@id", elementNode, XPathConstants.STRING);

        // url
        url = serializer.resolvePath(xpath.evaluate("url/text()", elementNode).trim());

        // reference
        reference = (String) xpath.evaluate("@ref", elementNode, XPathConstants.STRING);

        // size
        String trackSize = xpath.evaluate("size/text()", elementNode).trim();
        if (!"".equals(trackSize))
            size = Long.parseLong(trackSize);

        // flavor
        String flavorValue = (String) xpath.evaluate("@type", elementNode, XPathConstants.STRING);
        if (StringUtils.isNotEmpty(flavorValue))
            flavor = MediaPackageElementFlavor.parseFlavor(flavorValue);

        // checksum
        String checksumValue = (String) xpath.evaluate("checksum/text()", elementNode, XPathConstants.STRING);
        String checksumType = (String) xpath.evaluate("checksum/@type", elementNode, XPathConstants.STRING);
        if (StringUtils.isNotEmpty(checksumValue) && checksumType != null)
            checksum = Checksum.create(checksumType.trim(), checksumValue.trim());

        // mimetype
        String mimeTypeValue = (String) xpath.evaluate("mimetype/text()", elementNode, XPathConstants.STRING);
        if (StringUtils.isNotEmpty(mimeTypeValue))
            mimeType = MimeTypes.parseMimeType(mimeTypeValue);

        //
        // Build the track

        TrackImpl track = TrackImpl.fromURI(url);

        if (StringUtils.isNotBlank(id))
            track.setIdentifier(id);

        // Add url
        track.setURI(url);

        // Add reference
        if (StringUtils.isNotEmpty(reference))
            track.referTo(MediaPackageReferenceImpl.fromString(reference));

        // Set size
        if (size > 0)
            track.setSize(size);

        // Set checksum
        if (checksum != null)
            track.setChecksum(checksum);

        // Set mimetpye
        if (mimeType != null)
            track.setMimeType(mimeType);

        if (flavor != null)
            track.setFlavor(flavor);

        // description
        String description = (String) xpath.evaluate("description/text()", elementNode, XPathConstants.STRING);
        if (StringUtils.isNotBlank(description))
            track.setElementDescription(description.trim());

        // tags
        NodeList tagNodes = (NodeList) xpath.evaluate("tags/tag", elementNode, XPathConstants.NODESET);
        for (int i = 0; i < tagNodes.getLength(); i++) {
            track.addTag(tagNodes.item(i).getTextContent());
        }

        // duration
        try {
            String strDuration = (String) xpath.evaluate("duration/text()", elementNode, XPathConstants.STRING);
            if (StringUtils.isNotEmpty(strDuration)) {
                long duration = Long.parseLong(strDuration.trim());
                track.setDuration(duration);
            }
        } catch (NumberFormatException e) {
            throw new UnsupportedElementException("Duration of track " + url + " is malformatted");
        }

        // audio settings
        Node audioSettingsNode = (Node) xpath.evaluate("audio", elementNode, XPathConstants.NODE);
        if (audioSettingsNode != null && audioSettingsNode.hasChildNodes()) {
            try {
                AudioStreamImpl as = AudioStreamImpl.fromManifest(createStreamID(track), audioSettingsNode,
                        xpath);
                track.addStream(as);
            } catch (IllegalStateException e) {
                throw new UnsupportedElementException(
                        "Illegal state encountered while reading audio settings from " + url + ": "
                                + e.getMessage());
            } catch (XPathException e) {
                throw new UnsupportedElementException(
                        "Error while parsing audio settings from " + url + ": " + e.getMessage());
            }
        }

        // video settings
        Node videoSettingsNode = (Node) xpath.evaluate("video", elementNode, XPathConstants.NODE);
        if (videoSettingsNode != null && videoSettingsNode.hasChildNodes()) {
            try {
                VideoStreamImpl vs = VideoStreamImpl.fromManifest(createStreamID(track), videoSettingsNode,
                        xpath);
                track.addStream(vs);
            } catch (IllegalStateException e) {
                throw new UnsupportedElementException(
                        "Illegal state encountered while reading video settings from " + url + ": "
                                + e.getMessage());
            } catch (XPathException e) {
                throw new UnsupportedElementException(
                        "Error while parsing video settings from " + url + ": " + e.getMessage());
            }
        }

        return track;
    } catch (XPathExpressionException e) {
        throw new UnsupportedElementException(
                "Error while reading track information from manifest: " + e.getMessage());
    } catch (NoSuchAlgorithmException e) {
        throw new UnsupportedElementException("Unsupported digest algorithm: " + e.getMessage());
    } catch (URISyntaxException e) {
        throw new UnsupportedElementException(
                "Error while reading presenter track " + url + ": " + e.getMessage());
    }
}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.DocumentFactory.java

/**
 * Updates the Target Element of the given Policy
 * // w ww  .  j a v a  2 s .  c o  m
 * @param policy
 */
private void updatePolicyTargets(Node policy) {

    Node target = policy.getChildNodes().item(1);

    while (target.hasChildNodes()) {

        target.removeChild(target.getFirstChild());
    }

    Vector<Node> resourceListFromRules = new Vector<Node>();

    for (int i = 0; i < policy.getChildNodes().getLength(); i++) {

        Node n = policy.getChildNodes().item(i);

        if (n.getNodeName().equalsIgnoreCase("Rule")) {

            resourceListFromRules.add(n);
        }
    }

    Vector<Node> resourceListFromTarget = new Vector<Node>();

    for (int i = 0; i < resourceListFromRules.size(); i++) {

        Node n = resourceListFromRules.elementAt(i);
        boolean matches = false;

        for (int k = 0; k < resourceListFromTarget.size(); k++) {

            if (n.getChildNodes().item(3).getChildNodes().item(3).getChildNodes().item(1).getChildNodes()
                    .item(1).getChildNodes().item(1).getTextContent()
                    .equalsIgnoreCase(resourceListFromTarget.elementAt(k).getChildNodes().item(3)
                            .getChildNodes().item(3).getChildNodes().item(1).getChildNodes().item(1)
                            .getChildNodes().item(1).getTextContent())) {
                matches = true;
            }
        }
        if (!matches) {
            resourceListFromTarget.add(n.cloneNode(true));
        }
    }

    Document ress = null;
    try {
        ress = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(new InputSource(new java.io.StringReader("<Resources></Resources>")));
    } catch (Exception e) {
        Logger.getLogger(this.getClass()).error(e);
    }

    if (resourceListFromTarget.size() != 0) {
        Node copy = target.getOwnerDocument().importNode(ress.getDocumentElement(), true);

        target.appendChild(copy);

        for (int f = 0; f < resourceListFromTarget.size(); f++) {

            Node res = policy.getOwnerDocument().importNode(resourceListFromTarget.elementAt(f).getChildNodes()
                    .item(3).getChildNodes().item(3).getChildNodes().item(1), true);

            copy.appendChild(res);

        }
    }
}

From source file:org.openhab.habdroid.model.OpenHABItem.java

public OpenHABItem(Node startNode) {
    if (startNode.hasChildNodes()) {
        NodeList childNodes = startNode.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node childNode = childNodes.item(i);
            if (childNode.getNodeName().equals("type")) {
                this.setType(childNode.getTextContent());
            } else if (childNode.getNodeName().equals("groupType")) {
                this.setGroupType(childNode.getTextContent());
            } else if (childNode.getNodeName().equals("name")) {
                this.setName(childNode.getTextContent());
            } else if (childNode.getNodeName().equals("state")) {
                if (childNode.getTextContent().equals("Uninitialized")) {
                    this.setState(null);
                } else {
                    this.setState(childNode.getTextContent());
                }/*from  w  w  w.  j  ava 2s  .com*/
            } else if (childNode.getNodeName().equals("link")) {
                this.setLink(childNode.getTextContent());
            }
        }
    }
}