Example usage for org.dom4j Element createCopy

List of usage examples for org.dom4j Element createCopy

Introduction

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

Prototype

Element createCopy(QName qName);

Source Link

Document

Creates a deep copy of this element with the given fully qualified name.

Usage

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   w w  w.j  a  v a  2s. 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);/*  ww w  .  j av a 2  s . c  o m*/
        } else if (!child.getName().equals("noteGrp")) {
            lit.remove();
        }
    }

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

From source file:org.craftercms.search.service.impl.TokenizedElementParser.java

License:Open Source License

@Override
public boolean parse(Element element, String fieldName, String parentFieldName, SolrInputDocument solrDoc,
        ElementParserService parserService) {
    Attribute tokenizedAttribute = element.attribute(tokenizedAttributeName);
    if (tokenizedAttribute != null && BooleanUtils.toBoolean(tokenizedAttribute.getValue())) {
        logger.debug("Parsing element '{}' marked to tokenize", fieldName);

        // Remove the attribute so that at the end the element can be parsed as a normal attribute.
        element.remove(tokenizedAttribute);

        String elementName = element.getName();

        for (Map.Entry<String, String> mapping : fieldSuffixMappings.entrySet()) {
            if (elementName.endsWith(mapping.getKey())) {
                String newElementName = StringUtils.substringBefore(elementName, mapping.getKey())
                        + mapping.getValue();

                Element tokenizedElement = element.createCopy(newElementName);

                if (logger.isDebugEnabled()) {
                    logger.debug("Created new element for tokenized search: " + tokenizedElement.getName());
                }/*from w w w  .j a va  2 s.  c om*/

                parserService.parse(tokenizedElement, parentFieldName, solrDoc);

                break;
            }
        }

        parserService.parse(element, parentFieldName, solrDoc);

        return true;
    } else {
        return false;
    }
}

From source file:org.jivesoftware.openfire.plugin.Xep227Exporter.java

License:Apache License

/**
 * Adding offline messages, if there are some.
 * //from w  w  w . java 2 s.c  o  m
 * @param hostname
 *            host name
 * @param userElement
 *            DOM element
 * @param userName
 *            user name
 */
@SuppressWarnings("unchecked")
private void exportOfflineMessages(String hostname, Element userElement, String userName) {
    Collection<OfflineMessage> offlineMessages = offlineMessagesStore.getMessages(userName, false);

    if (!offlineMessages.isEmpty()) {
        Element offlineElement = userElement.addElement(OFFLINE_MESSAGES_ELEMENT_NAME);

        for (OfflineMessage offMessage : offlineMessages) {

            Element messageElement = offlineElement.addElement(new QName(MESSAGE_ELEMENT_NAME, JABBER_MSG_NS));
            for (Object att : offMessage.getElement().attributes()) {
                Attribute attribute = (Attribute) att;
                messageElement.addAttribute(attribute.getQName(), attribute.getValue());
            }

            for (Iterator<Element> iterator = offMessage.getElement().elementIterator(); iterator.hasNext();) {
                Element element = iterator.next();
                messageElement.add(element.createCopy(new QName(element.getName(),
                        (element.getNamespace() == Namespace.NO_NAMESPACE ? JABBER_MSG_NS
                                : element.getNamespace()))));

            }

            /**
             * Adding delay element
             */
            Element delayElement = messageElement.addElement("delay", "urn:xmpp:delay");
            delayElement.addAttribute(FROM_NAME, hostname);
            delayElement.addAttribute("stamp", XMPPDateTimeFormat.format(offMessage.getCreationDate()));
            delayElement.addText("Offline Storage");
        }

    }

}