Example usage for org.dom4j Element add

List of usage examples for org.dom4j Element add

Introduction

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

Prototype

void add(Namespace namespace);

Source Link

Document

Adds the given Namespace to this element.

Usage

From source file:com.pureinfo.dolphin.mapping.PropertyRef.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#toXMLElement(org.dom4j.Element)
 *//*from w  w  w  .  ja  va 2  s.  c o  m*/
public void toXMLElement(Element _element) throws PureException {
    _element.addAttribute("type", m_sType);
    _element.addAttribute("key", m_sKey);
    _element.addAttribute("locator", m_sLocator);

    //to export indexes
    Element ele;
    for (int i = 1; i < m_indexes.length; i++) {
        ele = DocumentHelper.createElement("index");
        m_indexes[i].toXMLElement(ele);
        _element.add(ele);
    }
}

From source file:com.pureinfo.srm.config.notice.model.NoticeItem.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#toXMLElement(org.dom4j.Element)
 *///from   ww  w  .  j a v a 2  s .c o m
public void toXMLElement(Element _element) throws PureException {
    _element.addAttribute(ATTRIBUTE_NAME, m_sName);
    _element.addElement(ELEMENT_CHECKED).addText(String.valueOf(m_bChecked));
    _element.addElement(ELEMENT_DAY).addText(String.valueOf(m_nDay));
    _element.add(XMLUtil.createElement(ELEMENT_TEXT, m_sText, true));
}

From source file:com.rayo.core.xml.providers.ColibriProvider.java

License:Apache License

private void createColibriOfferEvent(ColibriOfferEvent event, Document document) {
    Element root = document.addElement(new QName("offer", NAMESPACE));
    root.addAttribute("muc", event.getMuc().toString());
    root.addAttribute("videobridge", event.getMuc().getNode());
    root.addAttribute("nickname", event.getNickname());
    root.addAttribute("participant", event.getParticipant().toString());
    root.add(event.getConference().createCopy());
}

From source file:com.rayo.core.xml.providers.ColibriProvider.java

License:Apache License

private void createAddSourceEvent(AddSourceEvent event, Document document) {
    Element root = document.addElement(new QName("addsource", NAMESPACE));
    root.addAttribute("muc", event.getMuc().toString());
    root.addAttribute("videobridge", event.getMuc().getNode());
    root.addAttribute("nickname", event.getNickname());
    root.addAttribute("participant", event.getParticipant().toString());
    root.add(event.getConference().createCopy());
}

From source file:com.rayo.core.xml.providers.ColibriProvider.java

License:Apache License

private void createRemoveSourceEvent(RemoveSourceEvent event, Document document) {
    Element root = document.addElement(new QName("removesource", NAMESPACE));
    root.addAttribute("muc", event.getMuc().toString());
    root.addAttribute("videobridge", event.getMuc().getNode());
    root.addAttribute("nickname", event.getNickname());
    root.addAttribute("participant", event.getParticipant().toString());
    root.addAttribute("active", event.isActive() ? "true" : "false");
    root.add(event.getConference().createCopy());
}

From source file:com.rowtheboat.gui.OptionsSingleton.java

License:Open Source License

/**
 * This method saves the options to the options.xml file
 *//*w w w .  jav  a2  s.co  m*/
public void saveOptions() throws SAXException, IOException {

    /* Start the document */
    OutputFormat format = OutputFormat.createPrettyPrint();
    XMLWriter writer = new XMLWriter(new FileWriter(optionsFile), format);
    writer.startDocument();

    /* Add the main options section */
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("Options");

    /* Standard options */
    DefaultElement standardElement = new DefaultElement("Standard");
    standardElement.addElement("FullStrokeData").addText(getFullStrokeData() + "");
    standardElement.addElement("BoatSmoothing").addText(getBoatSmoothing() + "");
    root.add(standardElement);

    /* Input options */
    DefaultElement inputElement = new DefaultElement("Input");
    inputElement.addElement("SerialPort").addText(getSerialPort());
    root.add(inputElement);

    /* Race options */
    DefaultElement raceElement = new DefaultElement("Race");
    raceElement.addElement("Countdown").addText(getDelay() + "");
    root.add(raceElement);

    /* End the document */
    writer.write(root);
    writer.endDocument();
    writer.close();
}

From source file:com.safi.workshop.sqlexplorer.history.SQLHistory.java

License:Open Source License

/**
 * Save all the used queries into a file, so that we can reuse them next time.
 *//*from  w  w w .  ja  va2s .c  om*/
public void save() {

    try {
        File file = new File(ApplicationFiles.SQLHISTORY_FILE_NAME_V350);
        Element root = new DefaultElement(HISTORY);
        for (SQLHistoryElement elem : _history)
            root.add(elem.describeAsXml());
        XMLWriter xmlWriter = new XMLWriter(new FileWriter(file), OutputFormat.createPrettyPrint());
        xmlWriter.write(root);
        xmlWriter.flush();
        xmlWriter.close();

        // Get rid of old versions
        new File(ApplicationFiles.SQLHISTORY_FILE_NAME_V300).delete();

    } catch (IOException e) {
        SQLExplorerPlugin.error("Couldn't save sql history.", e);
    }

}

From source file:com.stratumsoft.xmlgen.SchemaTypeXmlGenerator.java

License:Open Source License

private void addRestrictedAttributesToElement(Element elementToAddOn, XmlSchemaAttribute attribute) {
    logger.debug("Adding restricted attribute: {}", attribute.getName());
    QName attrQName = attribute.getQName();
    if (attrQName != null) {
        org.dom4j.QName dom4jQName = createDom4jQName(attrQName, attribute.getForm());
        Attribute attr = elementToAddOn.attribute(dom4jQName);
        if (attr != null) {
            //already exists, so remove it, so we can add the restricted version of it
            logger.debug("Removing existing attribute\\: {} to add the restricted attribute",
                    dom4jQName.getName());
            elementToAddOn.remove(attr);
        }//from  www. jav  a  2  s  .co  m

        attr = factory.createAttribute(elementToAddOn, dom4jQName, "");
        elementToAddOn.add(attr);
    }

}

From source file:com.stratumsoft.xmlgen.SchemaTypeXmlGenerator.java

License:Open Source License

/**
 * Handle the attribute for the schema type
 *
 * @param attribute//from  ww  w.  j  a va 2  s.co  m
 * @param dom4jEl
 */
private void handleAttribute(XmlSchemaAttribute attribute, Element dom4jEl) {
    Attribute dom4jAttr = null;
    if (attribute != null) {
        if (attribute.getRef().getTarget() != null) {
            dom4jAttr = handleAttributeRef(attribute, dom4jEl);
        } else {
            dom4jAttr = handleLocalAttribute(attribute, dom4jEl);
        }

        //add this attr to this element
        if (dom4jAttr != null) {
            dom4jEl.add(dom4jAttr);
        }
    }
}

From source file:com.ten45.service.aggregator.ConfigurationServiceImpl.java

/**
 * Expand the original configuration document with the referred node.
 * It reads the referred document, finds the referred element in the same 
 * path as the original document, and moves all the children of the 
 * referred element into the original element.
 * //w w w. j  av  a2s  . co  m
 * @param doc
 * @param node
 * @return
 * @throws DocumentException
 */
private Document expandReference(Document doc, Node node) throws DocumentException {
    // Find the 'anchor' element that contains the reference declaration.
    Element anchor = node.getParent();
    XPath anchorXPath = DocumentHelper.createXPath(anchor.getPath());

    // Remove the reference declaration node from the document.
    node.detach();

    // Read the new configuration.
    String resourceName = rootPath + node.getText() + ".xml";
    log.debug("Reading resource " + resourceName);
    InputStream in = this.getClass().getResourceAsStream(resourceName);
    SAXReader reader = new SAXReader();
    try {
        Document refDoc = reader.read(in);

        Element refElement = (Element) anchorXPath.selectSingleNode(refDoc);
        if (refElement != null) {
            log.debug("Expanding " + anchorXPath.getText() + " with " + refElement.asXML());
            // Move all elements from the referenced document into the anchor.
            List children = refElement.elements();
            if (children != null && children.size() > 0) {
                for (int i = 0; i < children.size(); i++) {
                    Element child = (Element) children.get(i);
                    XPath refXPath = DocumentHelper.createXPath(child.getPath());
                    if (refXPath.selectSingleNode(doc) == null) {
                        log.debug("Adding element " + refXPath.getText());
                        child.detach();
                        anchor.add(child);
                    } else {
                        log.debug("Ignore pre-existing element " + refXPath.getText());
                    }
                }
            }
        }
    } catch (DocumentException de) {
        throw de;
    }
    return doc;
}