Example usage for org.dom4j Element addText

List of usage examples for org.dom4j Element addText

Introduction

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

Prototype

Element addText(String text);

Source Link

Document

Adds a new Text node with the given text to this element.

Usage

From source file:com.jswiff.xml.TagXMLWriter.java

License:Open Source License

private static void writeUnknownTag(Element parentElement, UnknownTag tag) {
    Element element = parentElement.addElement("unknowntag");
    element.addAttribute("code", Integer.toString(tag.getCode()));
    element.addText(Base64.encode(tag.getData()));
}

From source file:com.liferay.portlet.PortletPreferencesSerializer.java

License:Open Source License

public static String toXML(PortletPreferencesImpl prefs) throws SystemException {

    try {// w w w.j  av  a  2s. c o  m
        Map preferences = prefs.getPreferences();

        DocumentFactory docFactory = DocumentFactory.getInstance();

        Element portletPreferences = docFactory.createElement("portlet-preferences");

        Iterator itr = preferences.entrySet().iterator();

        while (itr.hasNext()) {
            Map.Entry entry = (Map.Entry) itr.next();

            Preference preference = (Preference) entry.getValue();

            Element prefEl = docFactory.createElement("preference");

            Element nameEl = docFactory.createElement("name");
            nameEl.addText(preference.getName());

            prefEl.add(nameEl);

            String[] values = preference.getValues();

            for (int i = 0; i < values.length; i++) {
                Element valueEl = docFactory.createElement("value");
                valueEl.addText(values[i]);

                prefEl.add(valueEl);
            }

            if (preference.isReadOnly()) {
                Element valueEl = docFactory.createElement("read-only");
                valueEl.addText("true");
            }

            portletPreferences.add(prefEl);
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        XMLWriter writer = new XMLWriter(baos, OutputFormat.createCompactFormat());

        writer.write(portletPreferences);

        return baos.toString();
    } catch (IOException ioe) {
        throw new SystemException(ioe);
    }
}

From source file:com.magnet.mmx.tsung.GenTestScript.java

License:Apache License

static String generateSendMessageStanza() {
    String fromJid = "%%_username%%@" + genSettings.servername + "/tsung";
    String toJid = "%%_tojid%%@" + genSettings.servername + "/tsung";
    Message message = new Message();
    message.setType(Type.chat);/*  w  ww .  j  ava2s  . c o  m*/
    message.getElement().addAttribute("from", fromJid);
    message.getElement().addAttribute("to", toJid);
    message.setID("%%ts_user_server:get_unique_id%%");

    // build up the MMX message packet extension
    Element element = message.addChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD);
    element.addElement(Constants.MMX_META);
    Element payload = element.addElement(Constants.MMX_PAYLOAD);
    payload.addAttribute(Constants.MMX_ATTR_CTYPE, "plain/text");
    payload.addAttribute(Constants.MMX_ATTR_MTYPE, "string");
    String randomText = "Considered an invitation do introduced sufficient understood instrument it. Of decisively friendship in as collecting at. No affixed be husband ye females brother garrets proceed. Least child who seven happy yet balls young. Discovery sweetness principle discourse shameless bed one excellent. Sentiments of surrounded friendship dispatched connection is he. Me or produce besides hastily up as pleased. Bore less when had and john shed hope. \n"
            + "\n"
            + "Barton waited twenty always repair in within we do. An delighted offending curiosity my is dashwoods at. Boy prosperous increasing surrounded companions her nor advantages sufficient put. John on time down give meet help as of. Him waiting and correct believe now cottage she another. Vexed six shy yet along learn maids her tiled. Through studied shyness evening bed him winding present. Become excuse hardly on my thirty it wanted. \n"
            + "\n"
            + "Six reached suppose our whether. Oh really by an manner sister so. One sportsman tolerably him extensive put she immediate. He abroad of cannot looked in. Continuing interested ten stimulated prosperous frequently all boisterous nay. Of oh really he extent horses wicket. \n"
            + "\n"
            + "Placing assured be if removed it besides on. Far shed each high read are men over day. Afraid we praise lively he suffer family estate is. Ample order up in of in ready. Timed blind had now those ought set often which. Or snug dull he show more true wish. No at many deny away miss evil. On in so indeed spirit an mother. Amounted old strictly but marianne admitted. People former is remove remain as. \n"
            + "\n"
            + "Little afraid its eat looked now. Very ye lady girl them good me make. It hardly cousin me always. An shortly village is raising we shewing replied. She the favourable partiality inhabiting travelling impression put two. His six are entreaties instrument acceptance unsatiable her. Amongst as or on herself chapter entered carried no. Sold old ten are quit lose deal his sent. You correct how sex several far distant believe journey parties. We shyness enquire uncivil affixed it carried to. \n"
            + "\n"
            + "Parish so enable innate in formed missed. Hand two was eat busy fail. Stand smart grave would in so. Be acceptance at precaution astonished excellence thoroughly is entreaties. Who decisively attachment has dispatched. Fruit defer in party me built under first. Forbade him but savings sending ham general. So play do in near park that pain. \n"
            + "\n"
            + "Needed feebly dining oh talked wisdom oppose at. Applauded use attempted strangers now are middleton concluded had. It is tried \uFEFFno added purse shall no on truth. Pleased anxious or as in by viewing forbade minutes prevent. Too leave had those get being led weeks blind. Had men rose from down lady able. Its son him ferrars proceed six parlors. Her say projection age announcing decisively men. Few gay sir those green men timed downs widow chief. Prevailed remainder may propriety can and. \n"
            + "\n"
            + "Seen you eyes son show. Far two unaffected one alteration apartments celebrated but middletons interested. Described deficient applauded consisted my me do. Passed edward two talent effect seemed engage six. On ye great do child sorry lived. Proceed cottage far letters ashamed get clothes day. Stairs regret at if matter to. On as needed almost at basket remain. By improved sensible servants children striking in surprise. \n"
            + "\n"
            + "Rendered her for put improved concerns his. Ladies bed wisdom theirs mrs men months set. Everything so dispatched as it increasing pianoforte. Hearing now saw perhaps minutes herself his. Of instantly excellent therefore difficult he northward. Joy green but least marry rapid quiet but. Way devonshire introduced expression saw travelling affronting. Her and effects affixed pretend account ten natural. Need eat week even yet that. Incommode delighted he resolving sportsmen do in listening. \n"
            + "\n"
            + "On recommend tolerably my belonging or am. Mutual has cannot beauty indeed now sussex merely you. It possible no husbands jennings ye offended packages pleasant he. Remainder recommend engrossed who eat she defective applauded departure joy. Get dissimilar not introduced day her apartments. Fully as taste he mr do smile abode every. Luckily offered article led lasting country minutes nor old. Happen people things oh is oppose up parish effect. Law handsome old outweigh humoured far appetite. \n"
            + "\n";
    payload.addText(StringEscapeUtils.escapeXml(randomText));
    return message.toXML().toString();
}

From source file:com.mindquarry.desktop.model.task.Task.java

License:Open Source License

public Document getContentAsXML() {
    Document doc = DocumentHelper.createDocument();
    Element task = doc.addElement("task"); //$NON-NLS-1$

    Element title = task.addElement("title"); //$NON-NLS-1$
    title.setText(getTitle());/*from   w  w  w. j  a v a 2s  .co m*/

    if ((getPriority() != null) && (!getPriority().equals(""))) { //$NON-NLS-1$
        Element priority = task.addElement("priority"); //$NON-NLS-1$
        priority.setText(getPriority());
    }
    if ((getSummary() != null) && (!getSummary().equals(""))) { //$NON-NLS-1$
        Element summary = task.addElement("summary"); //$NON-NLS-1$
        summary.setText(getSummary());
    }
    if ((getStatus() != null) && (!getStatus().equals(""))) { //$NON-NLS-1$
        Element status = task.addElement("status"); //$NON-NLS-1$
        status.setText(getStatus());
    }
    if ((getDate() != null) && (!getDate().equals(""))) { //$NON-NLS-1$
        Element date = task.addElement("date"); //$NON-NLS-1$
        date.setText(getDate());
    }
    if ((getDescription() != null) && (!getDescription().equals(""))) { //$NON-NLS-1$
        Element description = task.addElement("description"); //$NON-NLS-1$
        description.setText(getDescription());
    }
    if ((getTargetTime() != null) && (!getTargetTime().equals(""))) { //$NON-NLS-1$
        Element description = task.addElement("targettime"); //$NON-NLS-1$
        description.setText(getTargetTime());
    }
    if ((getActualTime() != null) && (!getActualTime().equals(""))) { //$NON-NLS-1$
        Element description = task.addElement("actualtime"); //$NON-NLS-1$
        description.setText(getActualTime());
    }
    if (people.size() > 0) {
        int count = 0;
        Element peopleEl = task.addElement("people"); //$NON-NLS-1$
        for (Person person : people) {
            Element itemEl = peopleEl.addElement("item"); //$NON-NLS-1$
            itemEl.addAttribute("position", String.valueOf(count)); //$NON-NLS-1$

            Element personEl = itemEl.addElement("person"); //$NON-NLS-1$
            personEl.addText(person.pid);
            Element roleEl = itemEl.addElement("role"); //$NON-NLS-1$
            roleEl.addText(person.role);

            count++;
        }
    }
    if (dependencies.size() > 0) {
        int count = 0;
        Element dependenciesEl = task.addElement("dependencies"); //$NON-NLS-1$
        for (Dependency dependency : dependencies) {
            Element itemEl = dependenciesEl.addElement("item"); //$NON-NLS-1$
            itemEl.addAttribute("position", String.valueOf(count)); //$NON-NLS-1$

            Element taskEl = itemEl.addElement("task"); //$NON-NLS-1$
            taskEl.addText(dependency.tid);
            Element roleEl = itemEl.addElement("role"); //$NON-NLS-1$
            roleEl.addText(dependency.role);

            count++;
        }
    }
    return doc;
}

From source file:com.org.dms.action.service.claimmng.WorkDispatchMngAction.java

/**
 * /*from   w  w  w  . j  av  a 2 s  .co  m*/
 * @param type 2?  1 
 * @param remark  
 * @param type workId
 * @return
 */
public String dispatchResult(String type, Map<String, String> map) {

    Document domresult = DocumentFactory.getInstance().createDocument();
    Element root = domresult.addElement("DBSET");
    Element r = root.addElement("R");

    Element c01 = r.addElement("C");
    c01.addAttribute("N", "BACK_ID");//???ID
    if (map.get("workId") != null && !"".equals(map.get("workId"))) {
        c01.addText(map.get("workId"));
    }

    Element c02 = r.addElement("C");
    c02.addAttribute("N", "JOBORDER_PK");//400?
    if (map.get("joborderPk") != null && !"".equals(map.get("joborderPk"))) {
        c02.addText(map.get("joborderPk"));
    }

    Element c03 = r.addElement("C");
    c03.addAttribute("N", "JOBORDER_CODE");//400??
    if (map.get("joborderCoe") != null && !"".equals(map.get("joborderCoe"))) {
        c03.addText(map.get("joborderCoe"));
    }

    Element c04 = r.addElement("C");
    c04.addAttribute("N", "BACK_TYPE");//??12 
    c04.addText(type);

    Element c05 = r.addElement("C");
    c05.addAttribute("N", "BACK_MSG");//
    if (map.get("remarks") != null && !"".equals(map.get("remarks"))) {
        c05.addText(map.get("remarks"));
    }

    Element c06 = r.addElement("C");
    c06.addAttribute("N", "JOBORDER_DNAME");//???(??)
    if (map.get("orgCode") != null && !"".equals(map.get("orgCode"))) {
        c06.addText(map.get("orgCode"));
    }

    Element c07 = r.addElement("C");
    c07.addAttribute("N", "JOBORDER_OUT");//?
    if (map.get("ifout") != null && !"".equals(map.get("ifout"))) {
        c07.addText(map.get("ifout"));
    }

    Element c08 = r.addElement("C");
    c08.addAttribute("N", "REPAIRER_NAME");//??
    if (map.get("userName") != null && !"".equals(map.get("userName"))) {
        c08.addText(map.get("userName"));
    }

    Element c09 = r.addElement("C");
    c09.addAttribute("N", "REPAIRER_CONTACT");//??
    if (map.get("mobils") != null && !"".equals(map.get("mobils"))) {
        c09.addText(map.get("mobils"));
    }

    Element c10 = r.addElement("C");
    c10.addAttribute("N", "VEHICLE_FLAG");//VEHICLE_FLAG ??10?
    if (map.get("ifVehicle") != null && !"".equals(map.get("ifVehicle"))) {
        c10.addText(map.get("ifVehicle"));
    }

    Element c11 = r.addElement("C");
    c11.addAttribute("N", "VEHICLE_NUMBER");//?
    if (map.get("licensePlate") != null && !"".equals(map.get("licensePlate"))) {
        c11.addText(map.get("licensePlate"));
    }

    Element c12 = r.addElement("C");
    c12.addAttribute("N", "JOBORDER_DTIME");//(YYYY-MM-DD HH24:MI:SS)
    if (map.get("dtime") != null && !"".equals(map.get("dtime"))) {
        c12.addText(Pub.getCurrentDate().toLocaleString());
    } else {
        c12.addText(Pub.getCurrentDate().toLocaleString());
    }

    Element c13 = r.addElement("C");
    c13.addAttribute("N", "REMARK");//
    if (map.get("remarks") != null && !"".equals(map.get("remarks"))) {
        c13.addText(map.get("remarks"));
    }
    return domresult.getRootElement().asXML();
}

From source file:com.pureinfo.dolphin.script.param.ParameterMetadata.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#toXMLElement(org.dom4j.Element)
 *//* w w w. j  av  a 2 s .  co  m*/
public void toXMLElement(Element _element) throws PureException {
    if (_element == null) {
        throw new PureException(200, "request can't be null");
    }

    if (getName() == null) {
        throw new PureException(502, "element attribute[" + ATTRIBUTE_NAME + "] can't be null");
    }
    _element.addAttribute(ATTRIBUTE_NAME, getName());

    _element.addAttribute(ATTRIBUTE_REQUIRED, String.valueOf(isRequired()));

    if (getDescription() == null) {
        throw new PureException(502, "element attribute[" + ATTRIBUTE_DESCRIPTION + "] can't be null");
    }
    _element.addAttribute(ATTRIBUTE_DESCRIPTION, getDescription());

    if (getDefault() == null) {
        _element.addText("");
    } else {
        _element.addText(getDefault());
    }
}

From source file:com.pureinfo.srm.org.action.SubQueryAction.java

License:Open Source License

/**
 * @param _groups//from  w w  w .  j  a  va  2  s . com
 * @return
 */
private Document groups2Doc(OPGroup[] _groups) {
    Document doc = DocumentHelper.createDocument();

    Element xRoot = doc.addElement("datas");
    Element xType = xRoot.addElement("types");
    xType.addAttribute("default", _groups[0].sDefault);
    Element xOP = xType.addElement("type");
    xOP.addText("----");
    xOP.addAttribute("value", "");
    for (int i = 0; i < _groups[0].options.length; i++) {
        xOP = xType.addElement("type");
        xOP.addText(_groups[0].options[i][1]);
        xOP.addAttribute("value", _groups[0].options[i][0]);
    }

    if (_groups[1] == null) {
        Element xV1 = xRoot.addElement("level0");
        xOP = xV1.addElement("org");
        xOP.addText("----");
        xOP.addAttribute("value", "");
    } else {
        Element xV1 = xRoot.addElement("level0");
        xV1.addAttribute("default", _groups[1].sDefault);
        xOP = xV1.addElement("org");
        xOP.addText("----");
        xOP.addAttribute("value", "");
        for (int i = 0; i < _groups[1].options.length; i++) {
            xOP = xV1.addElement("org");
            xOP.addText(_groups[1].options[i][1]);
            xOP.addAttribute("value", _groups[1].options[i][0]);
            if (_groups[1].options[i].length > 2) {
                xOP.addAttribute("code", _groups[1].options[i][2]);
            }
        }
    }

    if (_groups[2] == null) {
        Element xV1 = xRoot.addElement("level1");
        xOP = xV1.addElement("org");
        xOP.addText("----");
        xOP.addAttribute("value", "");
    } else {
        OPGroup group = _groups[2];
        if (group.options.length == 0) {
            Element xV1 = xRoot.addElement("level1");
            xV1.addAttribute("default", group.sDefault);
            xOP = xV1.addElement("org");
            xOP.addText("");
            xOP.addAttribute("value", "");
        } else {
            Element xV1 = xRoot.addElement("level1");
            xV1.addAttribute("default", group.sDefault);
            xOP = xV1.addElement("org");
            xOP.addText("----");
            xOP.addAttribute("value", "");
            for (int i = 0; i < group.options.length; i++) {
                xOP = xV1.addElement("org");
                xOP.addText(group.options[i][1]);
                xOP.addAttribute("value", group.options[i][0]);
                if (group.options[i].length > 2) {
                    xOP.addAttribute("code", group.options[i][2]);
                }
            }
        }
    }

    if (_groups.length > 3 && _groups[3] != null) {
        OPGroup group = _groups[3];
        if (group.options.length == 0) {
            Element xV1 = xRoot.addElement("level1_2");
            xV1.addAttribute("default", group.sDefault);
            xOP = xV1.addElement("org");
            xOP.addText("");
            xOP.addAttribute("value", "");
        } else {
            Element xV1 = xRoot.addElement("level1_2");
            xV1.addAttribute("default", group.sDefault);
            xOP = xV1.addElement("org");
            xOP.addText("----");
            xOP.addAttribute("value", "");
            for (int i = 0; i < group.options.length; i++) {
                xOP = xV1.addElement("org");
                xOP.addText(group.options[i][1]);
                xOP.addAttribute("value", _groups[3].options[i][0]);
                if (group.options[i].length > 2) {
                    xOP.addAttribute("code", group.options[i][2]);
                }
            }
        }
    }

    return doc;
}

From source file:com.tedi.engine.XMLOutput.java

License:Open Source License

public String process(Vector structureV, Vector dataV) {
    doc = DocumentHelper.createDocument();
    Element root = null;/* w w  w. j  a v  a 2 s  .com*/
    String suppress = null;
    String result = "";

    if (logger.isDebugEnabled()) {
        logger.debug("Processing XML output.");
    }

    if (structureV != null && structureV.size() > 0 && structureV != null) {
        try {
            // main loop for creating the XML document
            for (int i = 0; i < structureV.size(); i++) {
                String value = (String) dataV.elementAt(i);
                Vector fieldV = (Vector) structureV.elementAt(i);
                String path = (String) fieldV.elementAt(0);
                String endpoint = (String) fieldV.elementAt(1);
                String datatype = (String) fieldV.elementAt(4);
                // deal with suppression criteria
                // --------------------------------------------------------------
                if (suppress != null) {
                    if (path.indexOf(suppress) > -1)
                        continue;
                    else
                        suppress = null;
                }
                // if printing of this part of the tree was supressed, skip
                // ahead
                if (value.equals(TEDI_SUPRESS)) {
                    if (suppress == null)
                        suppress = path;
                    continue;
                }
                // ---------------------------------------------------------------------------------------------
                Vector currentRowVector = (Vector) structureV.elementAt(i);
                // Only non-calc fields make it to output
                if (!currentRowVector.elementAt(4).toString().equals(CALC)) {
                    StringTokenizer st = new StringTokenizer(path, "/");
                    int count = st.countTokens();
                    // factor out the root
                    String firstToken = st.nextToken();
                    count--;
                    // Set root if required
                    if (root == null) {
                        this.setSystemID(firstToken);
                        root = DocumentHelper.createElement(firstToken);
                        doc.setRootElement(root);
                        if (count == 0 && endpoint.length() == 0)
                            continue;
                    } else if (endpoint.length() == 0)
                        count--;
                    // Handle error condition of no root
                    if (root == null) {
                        execResults.addMessage(ExecutionResults.M_ERROR, ExecutionResults.J2EE_TARGET_ERR,
                                "Mapping defintion error locating root element declaration.");
                        execResults.setReturnCode(ExecutionResults.RESULT_ERROR);
                        break;
                    }
                    if (endpoint.length() > 0) {
                        if (mapFile.isSuppressAttribIfEmpty() && value.length() == 0)
                            continue;
                        else if (mapFile.isSuppressAttribIfHasOnlyWhitespace() && value.trim().length() == 0)
                            continue;
                    }
                    // this is the main loop for a path
                    Element elem = root;
                    for (int j = 0; j < count; j++) {
                        String item = st.nextToken();
                        List childList = elem.elements(item);
                        if (childList.size() > 0) {
                            elem = (Element) childList.get(childList.size() - 1);
                        } else {
                            elem = elem.addElement(item);
                        }
                    }
                    if (endpoint.length() == 0) {
                        elem = elem.addElement(st.nextToken());
                        if (datatype.equals(TEXT_CDATA))
                            elem.addCDATA(value);
                        else if (!datatype.equals(NOT_MAPPABLE))
                            elem.addText(value);
                    } else {
                        elem.addAttribute(endpoint, value);
                    }
                }
            } // end for() main loop

            // "isSuppressDocType" indicator re-used to suppress NS prefixes
            if (!isSuppressDocType) {
                addNSPrefixesToDocument();
            }

            result = cleanDocument(doc);
        } catch (Exception e) {
            execResults.addMessage(ExecutionResults.M_ERROR, ExecutionResults.J2EE_TARGET_ERR,
                    "Error creating XML document: " + e.getMessage());
            execResults.setReturnCode(ExecutionResults.RESULT_ERROR);
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Processing of XML output completed.");
    }
    return result;
}

From source file:com.thinkberg.moxo.dav.data.DavResource.java

License:Apache License

@SuppressWarnings({ "WeakerAccess" })
protected boolean addGetContentLengthProperty(Element root) {
    try {/*from   w  ww .j  a  v  a2 s.com*/
        Element el = root.addElement(PROP_GET_CONTENT_LENGTH);
        if (!ignoreValues) {
            el.addText("" + object.getContent().getSize());
        }
        return true;
    } catch (FileSystemException e) {
        e.printStackTrace();
        return false;
    }
}

From source file:com.thinkberg.moxo.dav.data.DavResource.java

License:Apache License

@SuppressWarnings({ "WeakerAccess" })
protected boolean addGetContentTypeProperty(Element root) {
    try {// w w w. j a v  a  2 s.  co  m
        String contentType = object.getContent().getContentInfo().getContentType();
        if (null == contentType || "".equals(contentType)) {
            return false;
        }

        Element el = root.addElement(PROP_GET_CONTENT_TYPE);
        if (!ignoreValues) {
            el.addText(contentType);
        }
        return true;
    } catch (FileSystemException e) {
        e.printStackTrace();
        return false;
    }
}