Example usage for org.w3c.dom Node getFirstChild

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

Introduction

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

Prototype

public Node getFirstChild();

Source Link

Document

The first child of this node.

Usage

From source file:lv.coref.io.MmaxReaderWriter.java

public void readWords(Text text, String fileName) {
    try {//from  w  w w.  j ava2 s .  co  m
        File file = new File(fileName);
        DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = dBuilder.parse(file);
        NodeList markables = doc.getElementsByTagName("word");
        words = new ArrayList<String>();
        for (int i = 0; i < markables.getLength(); i++) {
            Node markable = markables.item(i);
            String word = markable.getFirstChild().getNodeValue();
            word = StringEscapeUtils.unescapeXml(word);
            // String idString = markable.getAttributes().getNamedItem("id").getNodeValue();
            words.add(word);
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, "Error reading " + fileName, e);
    }
}

From source file:com.amalto.core.history.accessor.UnaryFieldAccessor.java

private Element getElement() {
    Element element = null;//ww w  .  j  a v  a2  s .co  m
    Node parentNode = parent.getNode();
    if (parentNode != null) {
        Node current = parentNode.getFirstChild();
        while (current != null) {
            if (fieldName.equals(current.getNodeName())) {
                element = (Element) current;
                break;
            }
            current = current.getNextSibling();
        }
    }
    return element;
}

From source file:org.dozer.eclipse.plugin.sourcepage.validation.Validator.java

@SuppressWarnings("restriction")
private void checkClassNodes(NodeList nodeList, IFile file, ValidationInfo validationReport)
        throws JavaModelException, DOMException {
    int len = nodeList.getLength();
    for (int i = 0; i < len; i++) {
        Node node = nodeList.item(i);
        Node textNode = node.getFirstChild();

        if (textNode.getNodeType() == Node.TEXT_NODE) {
            String className = textNode.getNodeValue();

            IType javaType = JdtUtils.getJavaType(file.getProject(), className);
            //class not found
            if (javaType == null) {
                Integer[] location = (Integer[]) node.getUserData("location");
                validationReport.addError("Class " + className + " not found.", location[0], location[1],
                        validationReport.getFileURI());
            }/*from w w w. j av a  2  s .  c  o  m*/
        }

    }
}

From source file:cz.incad.kramerius.virtualcollections.VirtualCollectionsManager.java

public static List<VirtualCollection> getVirtualCollectionsFromFedora(FedoraAccess fedoraAccess,
        ArrayList<String> languages) throws Exception {
    try {/*from w ww .  ja v a  2 s  .  co  m*/
        IResourceIndex g = ResourceIndexService.getResourceIndexImpl();
        Document doc = g.getVirtualCollections();

        NodeList nodes = doc.getDocumentElement().getElementsByTagNameNS(SPARQL_NS, "result");
        NodeList children;
        Node child;
        String name;
        String pid;
        boolean canLeave;

        ArrayList<String> langs = new ArrayList<String>();

        if (languages == null || languages.isEmpty()) {
            String[] ls = KConfiguration.getInstance().getPropertyList("interface.languages");
            for (int i = 0; i < ls.length; i++) {
                String lang = ls[++i];
                langs.add(lang);
            }
        } else {
            langs = new ArrayList<String>(languages);
        }

        List<VirtualCollection> vcs = new ArrayList<VirtualCollection>();
        for (int i = 0; i < nodes.getLength(); i++) {
            canLeave = false;
            name = null;
            pid = null;
            Node node = nodes.item(i);
            children = node.getChildNodes();
            for (int j = 0; j < children.getLength(); j++) {
                child = children.item(j);
                if ("title".equals(child.getLocalName())) {
                    name = child.getFirstChild().getNodeValue();
                } else if ("object".equals(child.getLocalName())) {
                    pid = ((Element) child).getAttribute("uri").replaceAll("info:fedora/", "");
                } else if ("canLeave".equals(child.getLocalName())) {
                    canLeave = Boolean.parseBoolean(child.getFirstChild().getNodeValue().replaceAll("\"", "")
                            .substring(("canLeave:").length()));
                }
            }

            if (name != null && pid != null) {
                try {
                    VirtualCollection vc = new VirtualCollection(name, pid, canLeave);

                    for (String lang : langs) {
                        String dsName = TEXT_DS_PREFIX + lang;
                        String value = IOUtils.readAsString(fedoraAccess.getDataStream(pid, dsName),
                                Charset.forName("UTF8"), true);
                        vc.addDescription(lang, value);
                    }
                    vcs.add(vc);
                } catch (Exception vcex) {
                    logger.log(Level.WARNING,
                            "Could not get virtual collection for  " + pid + ": " + vcex.toString());

                }
            }
        }
        return vcs;
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Error getting virtual collections", ex);
        throw new Exception(ex);
    }
}

From source file:com.amalto.core.history.accessor.ManyFieldAccessor.java

public String get() {
    Node collectionItemNode = getCollectionItemNode();
    Node firstChild = collectionItemNode.getFirstChild();
    if (firstChild != null) {
        if (firstChild instanceof Text)
            return collectionItemNode.getTextContent();// get node value can not handle bracket well
        else/*from w ww.  j  a v  a  2 s  .  c  om*/
            return firstChild.getNodeValue();
    } else {
        return StringUtils.EMPTY;
    }
}

From source file:de.juwimm.cms.util.SmallSiteConfigReader.java

public String readValue(String xmlPath) {
    try {/*  w  w  w.j  a  va2s.  c om*/
        Document document = this.getConfdoc();
        Iterator iterator = XercesHelper.findNodes(document, "//" + xmlPath);

        while (iterator.hasNext()) {
            Node node = (Node) iterator.next();
            return node.getFirstChild().getNodeValue();
        }
        return null;
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.debug("Could not read from site config path:" + xmlPath);
        }
        return null;
    }
}

From source file:de.juwimm.cms.util.SmallSiteConfigReader.java

public List<String> readValues(String xmlPath) {
    List<String> result = new ArrayList<String>();
    try {//from  ww  w. jav a  2 s .c o m
        Document document = this.getConfdoc();
        Iterator iterator = XercesHelper.findNodes(document, "//" + xmlPath);

        while (iterator.hasNext()) {
            Node node = (Node) iterator.next();
            result.add(node.getFirstChild().getNodeValue());
        }
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.debug("Could not read from site config path:" + xmlPath);
        }
    }

    return result;
}

From source file:bridge.toolkit.commands.S1000DConverter.java

/**
 * Receive the node, the DOM object and the new name of the node
 * /*  w w  w .  java 2 s .  c  om*/
 * @param nodo
 * @param doc
 * @param newname
 */
public static Node changeNodename(Node nodo, org.w3c.dom.Document doc, String newname) {
    // Create an element with the new name
    Node element2 = doc.createElement(newname);

    // Copy the attributes to the new element
    NamedNodeMap attrs = nodo.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Attr attr2 = (Attr) doc.importNode(attrs.item(i), true);
        element2.getAttributes().setNamedItem(attr2);
    }

    // Move all the children
    while (nodo.hasChildNodes()) {
        element2.appendChild(nodo.getFirstChild());
    }

    // Replace the old node with the new node
    nodo.getParentNode().replaceChild(element2, nodo);
    return element2;

}

From source file:Main.java

/**
 * Sarches for ressources that have to be downloaded and creates a list with all download links.
 *
 * @param node to check for download links
 * @return list with all found download links
 *//*from w w  w .  j  ava 2s.c om*/
private static ArrayList<String> findUrls(Node node) {

    int type = node.getNodeType();
    ArrayList<String> result = new ArrayList<>();
    String temp = null;
    NamedNodeMap atts = node.getAttributes();
    Log.i(TAG, "parsing for ressources.  node: " + node.getNodeName() + " value: " + node.getNodeValue()
            + " atts length: " + atts.getLength() + "type: " + type);
    switch (type) {
    //Element
    case Node.ELEMENT_NODE:
        //TODO: This method is stupid. It just looks for
        // attributes named ressourcepath. What if we have to download several ressources?

        for (int j = 0; j < atts.getLength(); j++) {
            Log.i(TAG, "atts: " + atts.item(j).getNodeName() + " value: " + atts.item(j).getNodeValue());
            temp = atts.item(j).getNodeValue();

            if (temp != null) {
                result.add(temp);
                Log.i(TAG, "added path: " + temp);
            }

            Log.i(TAG, "parent node:" + node.getParentNode().getNodeName());
            Element parent = (Element) node.getParentNode();
            parent.setAttribute("TESTITEST", "dllink");

        }
        // get the pages, means the children
        for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
            ArrayList<String> childres = findUrls(child);
            if (childres.size() > 0) {
                result.addAll(childres);
            }
        }
        break;
    }
    return result;
}

From source file:com.hp.autonomy.searchcomponents.idol.view.IdolViewServerService.java

private String parseFieldValue(final String referenceField, final List<Hit> documents) {
    final Hit document = documents.get(0);

    String referenceFieldValue = null;
    // Assume the field names are case insensitive
    final DocContent documentContent = document.getContent();
    if (documentContent != null && CollectionUtils.isNotEmpty(documentContent.getContent())) {
        final NodeList fields = ((Node) documentContent.getContent().get(0)).getChildNodes();
        for (int i = 0; i < fields.getLength(); i++) {
            final Node field = fields.item(i);
            if (field.getLocalName().equalsIgnoreCase(referenceField)) {
                referenceFieldValue = field.getFirstChild() == null ? null
                        : field.getFirstChild().getNodeValue();
                break;
            }/*ww  w.j av a  2s  . c  om*/
        }
    }
    return referenceFieldValue;
}