Example usage for org.dom4j Node detach

List of usage examples for org.dom4j Node detach

Introduction

In this page you can find the example usage for org.dom4j Node detach.

Prototype

Node detach();

Source Link

Document

Removes this node from its parent if there is one.

Usage

From source file:cz.fi.muni.xkremser.editor.server.newObject.PeriodicalBuilder.java

License:Open Source License

private void updateDcDoc(Document dcDoc, String pid, String signature, String sysno, DigitalObjectModel model) {
    Element dcRootEl = dcDoc.getRootElement();
    Attribute schemaLoc = dcRootEl.attribute("schemaLocation");
    dcRootEl.remove(schemaLoc);//w  ww. j a v a 2s  .com
    Namespace xsi = DocumentHelper.createNamespace("xsi2", FedoraNamespaces.SCHEMA_NAMESPACE_URI);
    dcRootEl.add(xsi);
    dcRootEl.addAttribute(new QName("schemaLocation", xsi),
            "http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd");

    XPath typeXpath = Dom4jUtils.createXPath("/oai_dc:dc/dc:identifier");
    List<? extends Node> nodes = typeXpath.selectNodes(dcDoc);
    for (Node node : nodes) {
        node.detach();
    }
    Element idUuid = dcRootEl.addElement("dc:identifier");
    idUuid.addText(pid);

    for (Node node : nodes) {
        if (node.getText() != null && !"".equals(node.getText().trim())
                && !node.getText().contains(Constants.FEDORA_UUID_PREFIX)) {
            Element temp = dcRootEl.addElement("dc:identifier");
            temp.addText(node.getText());
        }
    }

    if (signature != null) {
        Element idSignature = dcRootEl.addElement("dc:identifier");
        idSignature.addText("signature:" + signature);
    }
    if (sysno != null) {
        Element idSysno = dcRootEl.addElement("dc:identifier");
        idSysno.addText("sysno:" + sysno);
    }
    removeDcTypeElements(dcDoc);
    Element typeEl = dcRootEl.addElement("dc:type");
    typeEl.addText("model:" + model.getValue());
    Element rightsEl = dcRootEl.addElement("dc:rights");
    rightsEl.addText("policy:" + Policy.PUBLIC.toString().toLowerCase());
    updateDcLanguages(dcDoc);
}

From source file:cz.mzk.editor.server.newObject.MonographBuilder.java

License:Open Source License

@SuppressWarnings("unchecked")
private void updateDcDoc(Document dcDoc, String pid, String signature, String sysno, DigitalObjectModel model) {
    Element dcRootEl = dcDoc.getRootElement();
    Attribute schemaLoc = dcRootEl.attribute("schemaLocation");
    dcRootEl.remove(schemaLoc);/*  www  . j a  va  2 s . c o m*/
    Namespace xsi = DocumentHelper.createNamespace("xsi2", FedoraNamespaces.SCHEMA_NAMESPACE_URI);
    dcRootEl.add(xsi);
    dcRootEl.addAttribute(new QName("schemaLocation", xsi),
            "http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd");

    XPath typeXpath = Dom4jUtils.createXPath("/oai_dc:dc/dc:identifier");
    List<? extends Node> nodes = typeXpath.selectNodes(dcDoc);
    for (Node node : nodes) {
        node.detach();
    }
    Element idUuid = dcRootEl.addElement("dc:identifier");
    idUuid.addText(pid);

    for (Node node : nodes) {
        if (node.getText() != null && !"".equals(node.getText().trim())
                && !node.getText().contains(Constants.FEDORA_UUID_PREFIX)) {
            Element temp = dcRootEl.addElement("dc:identifier");
            temp.addText(node.getText());
        }
    }

    if (signature != null) {
        Element idSignature = dcRootEl.addElement("dc:identifier");
        idSignature.addText("signature:" + signature);
    }
    if (sysno != null) {
        Element idSysno = dcRootEl.addElement("dc:identifier");
        idSysno.addText("sysno:" + sysno);
    }
    removeDcTypeElements(dcDoc);
    Element typeEl = dcRootEl.addElement("dc:type");
    typeEl.addText("model:" + model.getValue());
    Element rightsEl = dcRootEl.addElement("dc:rights");
    rightsEl.addText("policy:" + getPolicy().toString().toLowerCase());
    updateDcLanguages(dcDoc);
}

From source file:cz.mzk.editor.server.newObject.MonographBuilder.java

License:Open Source License

@SuppressWarnings("unchecked")
private void removeDcTypeElements(Document doc) {
    XPath typeXpath = Dom4jUtils.createXPath("/oai_dc:dc/dc:type");
    List<? extends Node> nodes = typeXpath.selectNodes(doc);
    for (Node node : nodes) {
        node.detach();
    }/*from  w  w  w  . j  a va2  s  .  co m*/
}

From source file:dk.netarkivet.harvester.datamodel.H1HeritrixTemplate.java

License:Open Source License

@Override
public void removeDeduplicatorIfPresent() {
    Node xpathNode = template.selectSingleNode(DEDUPLICATOR_XPATH);
    if (xpathNode != null) {
        xpathNode.detach();
    }//w  w w.  j  av  a 2  s .c o m
}

From source file:dk.netarkivet.harvester.scheduler.jobgen.AbstractJobGenerator.java

License:Open Source License

/**
 * Once the job has been filled with {@link DomainConfiguration}s, performs the
 * following operations://from ww  w  . jav a2  s  . co m
 * <ol>
 * <li>Edit the harvest template to add/remove deduplicator configuration.</li>
 * <li></li>
 * </ol>
 * @param job the job
 */
protected void editJobOrderXml(Job job) {
    Document doc = job.getOrderXMLdoc();
    if (DEDUPLICATION_ENABLED) {
        // Check that the Deduplicator element is present in the
        //OrderXMl and enabled. If missing or disabled log a warning
        if (!HeritrixTemplate.isDeduplicationEnabledInTemplate(doc)) {
            if (log.isWarnEnabled()) {
                log.warn("Unable to perform deduplication for this job"
                        + " as the required DeDuplicator element is " + "disabled or missing from template");
            }
        }
    } else {
        // Remove deduplicator Element from OrderXML if present
        Node xpathNode = doc.selectSingleNode(HeritrixTemplate.DEDUPLICATOR_XPATH);
        if (xpathNode != null) {
            xpathNode.detach();
            job.setOrderXMLDoc(doc);
            if (log.isInfoEnabled()) {
                log.info("Removed DeDuplicator element because " + "Deduplication is disabled");
            }
        }
    }
}

From source file:edu.scripps.fl.pubchem.web.pug.PUGRequest.java

License:Apache License

private static void setResponseIds2(Document document, Type type, Collection<Object> ids) throws Exception {
    Node node = document.selectSingleNode("//PCT-ID-List_db");
    node.setText(type.getDatabase());/* ww  w  . ja va2 s . c o  m*/
    node = document.selectSingleNode(".//PCT-ID-List_uids");
    for (Node child : (List<Node>) node.selectNodes("*"))
        child.detach();
    for (Object id : ids) {
        Element aidElem = DocumentHelper.createElement("PCT-ID-List_uids_E");
        aidElem.setText(id.toString());
        ((Element) node).add(aidElem);
    }
}

From source file:edu.scripps.fl.pubchem.web.pug.PUGRequest.java

License:Apache License

public static void setResponseIds(Document document, Type type, Collection<Object> ids) throws Exception {
    String idTypePath = "//PCT-QueryAssayData_";
    idTypePath += Type.AID.equals(type) ? "aids" : "scids";
    Node localRoot = document.selectSingleNode(idTypePath);
    Node node = localRoot.selectSingleNode(".//PCT-ID-List_db");
    node.setText(type.getDatabase());//from ww w  .j  ava 2  s .co  m
    node = localRoot.selectSingleNode(".//PCT-ID-List_uids");
    //      if (node == null)
    //         throw new Exception("Cannot find PCT-ID-List_uids node");
    for (Node child : (List<Node>) node.selectNodes("*"))
        child.detach();
    for (Object id : ids) {
        Element aidElem = DocumentHelper.createElement("PCT-ID-List_uids_E");
        aidElem.setText(id.toString());
        ((Element) node).add(aidElem);
    }
}

From source file:edu.scripps.fl.pubchem.xml.CategorizedCommentXML.java

License:Apache License

public void buildCategorizedCommentDocument(Document document, List<CategorizedComment> cComments) {
    PubChemXMLUtils utils = new PubChemXMLUtils();
    if (cComments.size() > 0) {
        Element rootElement = (Element) document.selectSingleNode(rootString);
        Element cCommentElement = (Element) rootElement
                .selectSingleNode("PC-AssayDescription_categorized-comment");

        if (cCommentElement != null) {
            List<Node> nodes = cCommentElement.selectNodes("PC-CategorizedComment");
            for (Node nn : nodes)
                nn.detach();
        } else//  www.j  a va 2s.  c o  m
            cCommentElement = rootElement.addElement("PC-AssayDescription_categorized-comment");

        for (CategorizedComment cc : cComments) {
            Element element = cCommentElement.addElement("PC-CategorizedComment");
            element.addElement("PC-CategorizedComment_title").addText(cc.getCommentTag());
            utils.add_E("PC-CategorizedComment_comment", cc.getCommentValue(), element);
        }
    }
}

From source file:edu.scripps.fl.pubchem.xml.PanelXML.java

License:Apache License

public void buildPanelDocument(Document document, List<Panel> panelValues) throws Exception {
    Integer panel = decidePanel(panelValues);
    if (panel > 0) {
        Element root = (Element) document.selectSingleNode(rootString);
        Node node = root.selectSingleNode(panelInfo);
        if (node != null) {
            node.detach();
            root.selectSingleNode(isPanel).detach();
        }/*from w  w  w.j  a  va 2  s  .  c om*/
        root.addElement(isPanel).addAttribute("value", "true");
        Element pI = root.addElement(panelInfo);
        Element assayPanel = pI.addElement("PC-AssayPanel");
        assayPanel.addElement("PC-AssayPanel_name").addText("Assays");
        assayPanel.addElement("PC-AssayPanel_descr").addText("");
        Element assayPanelMember = assayPanel.addElement("PC-AssayPanel_member");

        for (int rr = 0; rr < panelValues.size(); rr++) {
            Panel panelValue = panelValues.get(rr);
            Element member = assayPanelMember.addElement("PC-AssayPanelMember");
            member.addElement("PC-AssayPanelMember_mid").addText(rr + 1 + "");
            member.addElement("PC-AssayPanelMember_name").addText(panelValue.getPanelName());

            List<PanelTarget> panelTargets = panelValue.getPanelTarget();
            if (null != panelTargets && panelTargets.size() > 0) {
                Element target = member.addElement("PC-AssayPanelMember_target");
                for (PanelTarget panelTarget : panelTargets) {
                    Element targetInfo = target.addElement("PC-AssayTargetInfo");
                    String name = panelTarget.getPanelTargetName();
                    String type = panelTarget.getPanelTargetType();
                    if (name != null)
                        targetInfo.addElement("PC-AssayTargetInfo_name").addText(name);
                    targetInfo.addElement("PC-AssayTargetInfo_mol-id")
                            .addText("" + panelTarget.getPanelTargetGi());
                    targetInfo.addElement("PC-AssayTargetInfo_molecule-type").addAttribute("value", type)
                            .addText("" + panelTarget.getPanelTargetTypeValue());
                }
            }
            List<Integer> taxonomies = panelValue.getPanelTaxonomy();
            List<Integer> genes = panelValue.getPanelGene();
            if (null != taxonomies | null != genes) {
                Element xref = member.addElement("PC-AssayPanelMember_xref");
                if (null != taxonomies && taxonomies.size() > 0) {
                    for (Integer taxonomy : taxonomies) {
                        Element annotatedXref = xref.addElement("PC-AnnotatedXRef");
                        Element annotatedXref_xref = annotatedXref.addElement("PC-AnnotatedXRef_xref");
                        Element XrefData = annotatedXref_xref.addElement("PC-XRefData");
                        XrefData.addElement("PC-XRefData_taxonomy").addText("" + taxonomy);
                    }
                }
                if (null != genes && genes.size() > 0) {
                    for (Integer gene : genes) {
                        Element annotatedXref = xref.addElement("PC-AnnotatedXRef");
                        Element annotatedXref_xref = annotatedXref.addElement("PC-AnnotatedXRef_xref");
                        Element XrefData = annotatedXref_xref.addElement("PC-XRefData");
                        XrefData.addElement("PC-XRefData_gene").addText("" + gene);
                    }
                }
            }
        }
    }
}

From source file:edu.scripps.fl.pubchem.xml.PubChemXMLDoc.java

License:Apache License

public void organizeXMLDoc(Document doc) {
    Element parent = (Element) doc.selectSingleNode(rootString);
    String[] nodesOrder = { name, description, protocol, comment, xref, results, revision, target,
            activityOutcome, dr, grantNumber, projectCategory, isPanel, panelInfo, categorizedComment };
    for (String nodeString : nodesOrder) {
        Node node = parent.selectSingleNode(nodeString);
        if (node != null) {
            Node clone = (Node) node.clone();
            node.detach();
            parent.add(clone);//  www. ja  v a 2 s.c om
        }
    }
    parent = (Element) doc.selectSingleNode(dbTracking);
    String[] secondNodesOrder = { "PC-DBTracking_name", "PC-DBTracking_source-id", "PC-DBTracking_date" };
    for (String nodeString : secondNodesOrder) {
        Node node = parent.selectSingleNode(nodeString);
        if (node != null) {
            Node clone = (Node) node.clone();
            node.detach();
            parent.add(clone);
        }
    }

}