Example usage for org.dom4j Element content

List of usage examples for org.dom4j Element content

Introduction

In this page you can find the example usage for org.dom4j Element content.

Prototype

List<Node> content();

Source Link

Document

Returns the content nodes of this branch as a backed List so that the content of this branch may be modified directly using the List interface.

Usage

From source file:com.globalsight.terminology.EntryUtils.java

License:Apache License

static private void mergeSourceGrp(Element p_one, Element p_two, Element p_sourceGrp, NodeComparator p_comp) {
    Element p_source = p_sourceGrp.element("source");

    if (p_source == null || !p_source.hasContent()) {
        return;//from   w ww .  j  a  va  2 s  .  c  o  m
    }

    // Find all sourceGrps in 1.
    List matches = p_one.selectNodes("sourceGrp");

    if (matches == null || matches.size() == 0) {
        // No sources exist, add the new one.
        p_one.add(p_sourceGrp);

        return;
    }

    // Check if one of the matches is the same source.
    for (int i = 0, max = matches.size(); i < max; i++) {
        Element sourceGrp = (Element) matches.get(i);
        Element source = sourceGrp.element("source");

        if (fieldEquals(source, p_source, p_comp)) {
            // could be a case/formatting-insensitive match
            source.detach();
            sourceGrp.content().add(0, p_source);

            mergeInnerGroups(sourceGrp, p_sourceGrp, p_comp);

            return;
        }
    }

    // Source does not exist, add it.
    p_one.add(p_sourceGrp);
}

From source file:com.globalsight.terminology.EntryUtils.java

License:Apache License

static private void mergeDescripGrp(Element p_one, Element p_two, Element p_descripGrp, NodeComparator p_comp) {
    Element p_descrip = p_descripGrp.element("descrip");

    if (p_descrip == null || !p_descrip.hasContent()) {
        return;//from   w ww .  j a v  a  2  s . c  o m
    }

    String type = p_descrip.attributeValue("type");

    // some descrips can occur only once per entry.
    boolean occursOnce = fieldOccursOnce(type);

    // Find nodes that match the descrip.
    List matches = p_one.selectNodes("descripGrp[descrip/@type='" + type + "']");

    if (matches == null || matches.size() == 0) {
        // descripGrp does not exist in entry 1, add.
        int index = findDescripInsertionPoint(p_one, type);
        p_one.content().add(index, p_descripGrp);

        return;
    }

    // Check if one of the matches contains the same descrip
    for (int i = 0, max = matches.size(); i < max; i++) {
        Element descripGrp = (Element) matches.get(i);
        Element descrip = descripGrp.element("descrip");

        if (fieldEquals(descrip, p_descrip, p_comp)) {
            // could be a case/formatting-insensitive match
            descrip.detach();
            descripGrp.content().add(0, p_descrip);

            mergeInnerGroups(descripGrp, p_descripGrp, p_comp);

            return;
        }
    }

    // DescripGrp was not found, add new descripGrp to old.
    if (occursOnce) {
        // DescripGrp can occur only once, merge by overwriting.
        // (Single descrips also contain just text, no HTML.)
        Element descGrp = (Element) matches.get(0);
        Element desc = descGrp.element("descrip");

        desc.setText(getInnerText(p_descrip));

        mergeInnerGroups(descGrp, p_descripGrp, p_comp);
    } else {
        // Multiple descrips may exist (for e.g., definition),
        // so add the new one after the last.
        Element last = (Element) matches.get(matches.size() - 1);

        p_one.content().add(p_one.indexOf(last) + 1, p_descripGrp);
    }
}

From source file:com.globalsight.terminology.EntryUtils.java

License:Apache License

/**
 * For descrip type="status|domain|project", finds a point at the
 * beginning, for other descrips a point at the end is returned.
 *///from w w  w . j  a v  a2 s.  com
static private int findDescripInsertionPoint(Element p_one, String p_type) {
    int result = 0;

    boolean occursOnce = fieldOccursOnce(p_type);

    List content = p_one.content();
    for (int i = 0, max = content.size(); i < max; i++) {
        Element elem = (Element) content.get(i);

        if (elem.getName().equals("languageGrp")) {
            // past descrips, bail out.
            result = i;
            break;
        }

        if (!elem.getName().equals("descripGrp")) {
            continue;
        }

        String type = elem.element("descrip").attributeValue("type");

        if (occursOnce) {
            if (!fieldOccursOnce(type)) {
                result = i;
                break;
            }
        }

        result = i;
    }

    return result;
}

From source file:com.globalsight.terminology.importer.MtfReaderThread.java

License:Apache License

private void convertToNoteGrp(Element p_elem) {
    Element noteGrp = p_elem.createCopy("noteGrp");

    // noteGrps contain no other fields, remove all child
    // nodes, remembering the <descrip type="note"> itself
    for (ListIterator lit = noteGrp.elements().listIterator(); lit.hasNext();) {
        Element child = (Element) lit.next();

        if (child.getName().equals("descrip")) {
            Element note = child.createCopy("note");
            note.remove(note.attribute("type"));

            lit.set(note);//from  www . j  a  v a 2 s  . c o  m
        } else {
            lit.remove();
        }
    }

    Element parent = p_elem.getParent();
    parent.content().set(parent.indexOf(p_elem), noteGrp);
}

From source file:com.globalsight.terminology.importer.MtfReaderThread.java

License:Apache License

private void convertToSourceGrp(Element p_elem) {
    Element sourceGrp = p_elem.createCopy("sourceGrp");

    // sourceGrp contains noteGrp, remove all non-noteGrp
    // children, remembering the <descrip type="source"> itself
    for (ListIterator lit = sourceGrp.elements().listIterator(); lit.hasNext();) {
        Element child = (Element) lit.next();

        if (child.getName().equals("descrip")) {
            Element source = child.createCopy("source");
            source.remove(source.attribute("type"));

            lit.set(source);//from  ww  w.  j  ava 2 s. c om
        } else if (!child.getName().equals("noteGrp")) {
            lit.remove();
        }
    }

    Element parent = p_elem.getParent();
    parent.content().set(parent.indexOf(p_elem), sourceGrp);
}

From source file:com.ibm.cognos.API.java

License:Open Source License

/**
 * addListColumn/*w w w  .  j  av  a 2s. co m*/
 * 
 * @param p_sName
 * @param position
 *            (to insert in the default position pass 0 to this method)
 *            (default position = insert after the last child element.)
 */
public void addListColumn(String p_sName, int position) {
    Element n = null;
    n = (Element) oDocument.selectSingleNode(
            "/report/layouts/layout/reportPages/page/pageBody/contents" + "/list/listColumns");

    // Create an empty column node
    Element eCol = DocumentHelper.createElement("listColumn");

    // Prepare all the bits to contain the column title
    Element eTitle = DocumentHelper.createElement("listColumnTitle");
    Element eStyleTitle = buildStyle("lt");

    Element eTContents = DocumentHelper.createElement("contents");
    Element eTText = DocumentHelper.createElement("textItem");
    Element eTSrc = DocumentHelper.createElement("dataSource");
    Element eLabel = DocumentHelper.createElement("dataItemLabel");
    eLabel.addAttribute("refDataItem", p_sName);

    // Prepare all the bits to contain the column data
    Element eBody = DocumentHelper.createElement("listColumnBody");
    Element eStyle = buildStyle("lm");

    Element eBContents = DocumentHelper.createElement("contents");
    Element eBText = DocumentHelper.createElement("textItem");
    Element eBSrc = DocumentHelper.createElement("dataSource");
    Element eValue = DocumentHelper.createElement("dataItemValue");
    eValue.addAttribute("refDataItem", p_sName);

    // Piece the Title together in the right order
    eTSrc.add(eLabel);
    eTText.add(eTSrc);
    eTContents.add(eTText);
    eTitle.add(eStyleTitle);
    eTitle.add(eTContents);

    // Piece the Body together
    eBSrc.add(eValue);
    eBText.add(eBSrc);
    eBContents.add(eBText);
    eBody.add(eStyle);
    eBody.add(eBContents);

    // Add the title and body to the column
    eCol.add(eTitle);
    eCol.add(eBody);

    if (position > 0) {
        n.content().add(position - 1, eCol);
    } else {
        n.add(eCol);
    }
}

From source file:com.noterik.bart.fs.fscommand.dynamic.config.flash.java

License:Open Source License

private void handleIncludeExcludeNodes(Document conf, Document tmpConf) {
    List<Node> includeNodes = tmpConf
            .selectNodes("/fsxml/filesystem[@id='1']/*[@id and not(ends-with(@id,'_exclude'))]");
    List<Node> excludeNodes = tmpConf.selectNodes("/fsxml/filesystem[@id='1']/*[ends-with(@id,'_exclude')]");

    logger.debug("number of includeNodes = " + includeNodes.size());
    for (int j = 0; j < includeNodes.size(); j++) {
        logger.debug(j + " = " + includeNodes.get(j).toString());
    }// w ww  .j a v a2  s. c  o m
    logger.debug("number of excludeNodes = " + excludeNodes.size());
    for (int j = 0; j < excludeNodes.size(); j++) {
        logger.debug(j + " = " + excludeNodes.get(j).toString());
    }

    Element base = (Element) conf.selectSingleNode("/fsxml/filesystem[@id='1']");

    if (includeNodes != null) {
        for (int i = 0; i < includeNodes.size(); i++) {
            String nodename = includeNodes.get(i).getName();
            String nodeid = includeNodes.get(i).valueOf("@id");

            logger.debug("check if node exists " + nodename + " id " + nodeid);

            Node existingNode = base.selectSingleNode(nodename + "[@id='" + nodeid + "']");
            if (existingNode != null) {
                logger.debug("node exists, replace");
                List contentOfBase = base.content();
                int index = contentOfBase.indexOf(existingNode);
                contentOfBase.set(index, includeNodes.get(i).detach());
            } else {
                base.add(includeNodes.get(i).detach());
            }
        }
    }

    if (excludeNodes != null) {
        logger.debug("handling exclude nodes for user");
        for (int i = 0; i < excludeNodes.size(); i++) {
            logger.debug("handling exclude node nr " + i);
            String nodename = excludeNodes.get(i).getName();
            String nodeid = excludeNodes.get(i).valueOf("@id");
            nodeid = nodeid.substring(0, nodeid.lastIndexOf("_exclude"));

            logger.debug("about to exclude " + nodename + " with id " + nodeid);

            Node remove = base.selectSingleNode(nodename + "[@id='" + nodeid + "']");
            if (remove != null) {
                logger.debug("node to exclude found, detach");
                remove.detach();
            }
        }
    }
}

From source file:com.noterik.bart.fs.fscommand.dynamic.presentation.playout.flash.java

License:Open Source License

private static void handleIncludeExcludeNodes(Document conf, Document tmpConf) {
    List<Node> includeNodes = tmpConf
            .selectNodes("/fsxml/filesystem[@id='1']/*[@id and not(ends-with(@id,'_exclude'))]");
    List<Node> excludeNodes = tmpConf.selectNodes("/fsxml/filesystem[@id='1']/*[ends-with(@id,'_exclude')]");

    logger.debug("number of includeNodes = " + includeNodes.size());
    for (int j = 0; j < includeNodes.size(); j++) {
        logger.debug(j + " = " + includeNodes.get(j).toString());
    }//from   ww  w. ja va  2 s .com
    logger.debug("number of excludeNodes = " + excludeNodes.size());
    for (int j = 0; j < excludeNodes.size(); j++) {
        logger.debug(j + " = " + excludeNodes.get(j).toString());
    }

    Element base = (Element) conf.selectSingleNode("/fsxml/filesystem[@id='1']");

    if (includeNodes != null) {
        for (int i = 0; i < includeNodes.size(); i++) {
            String nodename = includeNodes.get(i).getName();
            String nodeid = includeNodes.get(i).valueOf("@id");

            logger.debug("check if node exists " + nodename + " id " + nodeid);

            Node existingNode = base.selectSingleNode(nodename + "[@id='" + nodeid + "']");
            if (existingNode != null) {
                logger.debug("node exists, replace");
                List contentOfBase = base.content();
                int index = contentOfBase.indexOf(existingNode);
                contentOfBase.set(index, includeNodes.get(i).detach());
            } else {
                base.add(includeNodes.get(i).detach());
            }
        }
    }

    if (excludeNodes != null) {
        logger.debug("handling exclude nodes for user");
        for (int i = 0; i < excludeNodes.size(); i++) {
            logger.debug("handling exclude node nr " + i);
            String nodename = excludeNodes.get(i).getName();
            String nodeid = excludeNodes.get(i).valueOf("@id");
            nodeid = nodeid.substring(0, nodeid.lastIndexOf("_exclude"));

            logger.debug("about to exclude " + nodename + " with id " + nodeid);

            Node remove = base.selectSingleNode(nodename + "[@id='" + nodeid + "']");
            if (remove != null) {
                logger.debug("node to exclude found, detach");
                remove.detach();
            }
        }
    }
}

From source file:com.thesmartweb.swebrank.Sensebot.java

License:Apache License

/**
 * Method that connects to the Sensebot url and gets the document using SAXReader
 * @param link_ur the link to read from/*from  ww  w  . java2s  .  com*/
 * @return the response in a string
 */
public String connect(URL link_ur) {
    try {
        SAXReader reader = new SAXReader();
        Document document = reader.read(link_ur);
        Element root = document.getRootElement();
        List<Node> content = root.content();
        String stringValue = "";
        if (!(content.isEmpty()) && content.size() > 1) {
            Node get = content.get(1);
            stringValue = get.getStringValue();
            DataManipulation tp = new DataManipulation();
            stringValue = tp.removeChars(stringValue).toLowerCase();
        }
        return stringValue;
    } catch (DocumentException ex) {
        Logger.getLogger(Sensebot.class.getName()).log(Level.SEVERE, null, ex);
        String output = "";
        return output;
    }

}

From source file:darks.orm.core.config.sqlmap.DMLConfigReader.java

License:Apache License

private void parseSqlTag(AbstractTag parent, Element el, String namesp) throws Exception {
    AbstractTag prevTag = null;//from  w  ww  .j av a 2  s . c  o  m
    List<Node> list = el.content();
    Iterator<Node> it = list.iterator();
    while (it.hasNext()) {
        Node node = it.next();
        switch (node.getNodeType()) {
        case Node.ELEMENT_NODE:
            Element childEl = (Element) node;
            prevTag = parseElementTag(parent, node, childEl, namesp, prevTag);
            break;
        case Node.CDATA_SECTION_NODE:
        case Node.TEXT_NODE:
            String text = node.getText().replaceAll("\n|\t", " ").trim();
            if (!"".equals(text)) {
                TextTag tag = new TextTag(text, prevTag);
                parent.addChild(tag);
                prevTag = tag;
            }
            break;
        }
    }
}