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:at.jabberwocky.impl.core.io.PacketReader.java

private Document parseDocument() throws DocumentException, IOException, XmlPullParserException {
    DocumentFactory df = docFactory;//from   w w  w.  j a v a 2s  .  c o  m
    Document document = df.createDocument();
    Element parent = null;
    XmlPullParser pp = parser;
    int count = 0;
    while (true) {
        int type = -1;
        type = pp.nextToken();
        switch (type) {
        case XmlPullParser.PROCESSING_INSTRUCTION: {
            String text = pp.getText();
            int loc = text.indexOf(" ");
            if (loc >= 0) {
                document.addProcessingInstruction(text.substring(0, loc), text.substring(loc + 1));
            } else {
                document.addProcessingInstruction(text, "");
            }
            break;
        }
        case XmlPullParser.COMMENT: {
            if (parent != null) {
                parent.addComment(pp.getText());
            } else {
                document.addComment(pp.getText());
            }
            break;
        }
        case XmlPullParser.CDSECT: {
            String text = pp.getText();
            if (parent != null) {
                parent.addCDATA(text);
            } else {
                if (text.trim().length() > 0) {
                    throw new DocumentException("Cannot have text content outside of the root document");
                }
            }
            break;

        }
        case XmlPullParser.ENTITY_REF: {
            String text = pp.getText();
            if (parent != null) {
                parent.addText(text);
            } else {
                if (text.trim().length() > 0) {
                    throw new DocumentException("Cannot have an entityref outside of the root document");
                }
            }
            break;
        }
        case XmlPullParser.END_DOCUMENT: {
            return document;
        }
        case XmlPullParser.START_TAG: {
            QName qname = (pp.getPrefix() == null) ? df.createQName(pp.getName(), pp.getNamespace())
                    : df.createQName(pp.getName(), pp.getPrefix(), pp.getNamespace());
            Element newElement = null;
            // Do not include the namespace if this is the start tag of a new packet
            // This avoids including "jabber:client", "jabber:server" or
            // "jabber:component:accept"
            if ("jabber:client".equals(qname.getNamespaceURI())
                    || "jabber:server".equals(qname.getNamespaceURI())
                    || "jabber:component:accept".equals(qname.getNamespaceURI())
                    || "http://jabber.org/protocol/httpbind".equals(qname.getNamespaceURI())) {
                newElement = df.createElement(pp.getName());
            } else {
                newElement = df.createElement(qname);
            }
            int nsStart = pp.getNamespaceCount(pp.getDepth() - 1);
            int nsEnd = pp.getNamespaceCount(pp.getDepth());
            for (int i = nsStart; i < nsEnd; i++) {
                if (pp.getNamespacePrefix(i) != null) {
                    newElement.addNamespace(pp.getNamespacePrefix(i), pp.getNamespaceUri(i));
                }
            }
            for (int i = 0; i < pp.getAttributeCount(); i++) {
                QName qa = (pp.getAttributePrefix(i) == null) ? df.createQName(pp.getAttributeName(i))
                        : df.createQName(pp.getAttributeName(i), pp.getAttributePrefix(i),
                                pp.getAttributeNamespace(i));
                newElement.addAttribute(qa, pp.getAttributeValue(i));
            }
            if (parent != null) {
                parent.add(newElement);
            } else {
                document.add(newElement);
            }
            parent = newElement;
            count++;
            break;
        }
        case XmlPullParser.END_TAG: {
            if (parent != null) {
                parent = parent.getParent();
            }
            count--;
            if (count < 1) {
                return document;
            }
            break;
        }
        case XmlPullParser.TEXT: {
            String text = pp.getText();
            if (parent != null) {
                parent.addText(text);
            } else {
                if (text.trim().length() > 0) {
                    throw new DocumentException("Cannot have text content outside of the root document");
                }
            }
            break;
        }
        default:
        }
    }
}

From source file:bookmarks.buddylist.BuddyList.java

License:Open Source License

/**
 * //from w  w  w  . ja  v a2  s  . c  o  m
 * @return
 * @throws SQLException 
 */
public Document toXml() throws SQLException {
    Buddy curBuddy = null;
    Document buddyList = DocumentHelper.createDocument();
    Element root = buddyList.addElement("buddylist");

    for (int i = 0; i < this.buddies.size(); i++) {
        Element buddy = root.addElement("buddy");
        Element username = buddy.addElement("username");
        Element nickname = buddy.addElement("nickname");

        curBuddy = (Buddy) this.buddies.get(i);
        username.addText(curBuddy.username);
        if (curBuddy.nickname != null)
            nickname.addText(curBuddy.nickname);
    }

    return buddyList;

}

From source file:br.mdarte.exemplo.academico.cd.CursoDAO.java

public Element xmlExportEntity(AbstractEntity entity, Element raiz) throws DAOException {
    try {//from  w  ww  . jav  a 2  s  .c o m

        CursoImpl obj = (CursoImpl) entity;

        if (obj.getCodigo() != null) {
            Element attcodigo = raiz.addElement("codigo");
            attcodigo.addText(obj.getCodigo().toString());
        }
        if (obj.getNome() != null) {
            Element attnome = raiz.addElement("nome");
            attnome.addText(obj.getNome().toString());
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return raiz;
}

From source file:br.mdarte.exemplo.academico.cd.EstudanteDAO.java

public Element xmlExportEntity(AbstractEntity entity, Element raiz) throws DAOException {
    try {/*from ww  w .j  a  v a  2s.com*/

        EstudanteImpl obj = (EstudanteImpl) entity;

        if (obj.getMatricula() != null) {
            Element attmatricula = raiz.addElement("matricula");
            attmatricula.addText(obj.getMatricula().toString());
        }
        if (obj.getNome() != null) {
            Element attnome = raiz.addElement("nome");
            attnome.addText(obj.getNome().toString());
        }

        br.mdarte.exemplo.academico.cd.CursoImpl assEntitycurso = (br.mdarte.exemplo.academico.cd.CursoImpl) obj
                .getCurso();
        Element asscurso = raiz.addElement("curso");
        if (assEntitycurso != null) {
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return raiz;
}

From source file:ca.qc.cegepoutaouais.tge.pige.server.report.ReportHelper.java

License:Open Source License

/**
 * Applique un style CSS  un document HTML.
 * La section 'head' du document HTML est extraite afin d'y insrer
 * le style CSS./*w  ww.  j a va 2s.  c  o m*/
 *
 * @param htmlDoc document HTML  traiter
 * @param style style CSS  insrer
 * @throws ReportException
 */
public static void applyStyleToHTML(Document htmlDoc, String style) throws ReportException {
    Element headerTag = (Element) htmlDoc.selectSingleNode("//head");
    Element styleTag = DocumentHelper.createElement("style");
    styleTag.addText(style);
    headerTag.add(styleTag);
}

From source file:cc.warlock.core.client.settings.internal.VariableConfigurationProvider.java

License:Open Source License

@Override
protected void saveTo(List<Element> elements) {
    Element varsElement = DocumentHelper.createElement("variables");

    for (Map.Entry<String, IVariable> entry : variables.entrySet()) {
        Element element = varsElement.addElement("variable");
        element.addAttribute("id", entry.getKey());
        element.addText(entry.getValue().getValue());

    }// w  ww.ja  v a2  s. c  o m
    elements.add(varsElement);
}

From source file:ch.epfl.codimsd.qep.QEPFactory.java

License:Open Source License

/**
 * Add an operator template to the QEP Document.
 * /*from   w ww  . j a v a  2 s  .co m*/
 * @param document dom4j document.
 * @param opNode opNode structure of the operator to build.
 * @param opID identifier of the operator.
 */
private static void createOperator(Document document, OpNode opNode, int opID) {

    Element root = document.getRootElement();
    Iterator ittRoot = root.elementIterator();
    Element qepElement = (Element) ittRoot.next();

    // create new operator xml template (attributes, name)
    Element newOp = qepElement.addElement("op:Operator").addAttribute("id", opID + "").addAttribute("prod",
            buildProducers(opNode));

    if (opNode.getType() != null)
        newOp.addAttribute("type", opNode.getType());

    Element newNameOp = newOp.addElement("Name");
    newNameOp.addText(opNode.getOpName());

    // create operator xml parameters
    if (opNode.getParams() != null) {
        if (opNode.getParams().length != 0) {
            Element newParameterList = newOp.addElement("ParameterList");
            for (int i = 0; i < opNode.getParams().length; i++) {
                Element newParam = newParameterList.addElement("Param");
                newParam.addText(opNode.getParams()[i]);
            }
        }
    }
}

From source file:cn.com.sinosoft.ebusiness.xmltransfer.AppntInfoChangeCreater.java

@Override
public Document createXml(Map<String, Object> map) {
    Document doc = null;/*from w  ww . j av a  2 s .co m*/
    doc = super.createXml(functionFlag);
    Element tTranRequest = (Element) doc.selectSingleNode(sTranRequest);
    Element tLCCont = tTranRequest.addElement("LCCont");
    Element tContNo = tLCCont.addElement("ContNo");
    Element tLCAppnt = tLCCont.addElement("LCAppnt");

    Element tAppntName = tLCAppnt.addElement("AppntName");
    Element tAppntSex = tLCAppnt.addElement("AppntSex");
    Element tAppntBirthday = tLCAppnt.addElement("AppntBirthday");
    Element tAppntIDType = tLCAppnt.addElement("AppntIDType");
    Element tAppntIDNo = tLCAppnt.addElement("AppntIDNo");
    Element tMarriage = tLCAppnt.addElement("Marriage");
    Element tNationality = tLCAppnt.addElement("Nationality");
    Element tLicenseType = tLCAppnt.addElement("LicenseType");
    Element tJobCode = tLCAppnt.addElement("JobCode");
    Element tProvince = tLCAppnt.addElement("Province");
    Element tCity = tLCAppnt.addElement("City");
    Element tCounty = tLCAppnt.addElement("County");
    Element tHomeAddress = tLCAppnt.addElement("HomeAddress");
    Element tHomeZipCode = tLCAppnt.addElement("HomeZipCode");
    Element tAppntMobile = tLCAppnt.addElement("AppntMobile");
    Element tAppntOfficePhone = tLCAppnt.addElement("AppntOfficePhone");
    Element tAppntPhone = tLCAppnt.addElement("AppntPhone");
    Element tAppntFax = tLCAppnt.addElement("AppntFax");
    Element tEmail = tLCAppnt.addElement("Email");
    Element tGrpName = tLCAppnt.addElement("GrpName");

    PersonInfo appnt = (PersonInfo) map.get("appnt");
    String contNo = (String) map.get("ContNo");

    tContNo.addText(contNo);
    tAppntName.addText(appnt.getName());
    tAppntSex.addText(appnt.getSex());
    tAppntBirthday.addText(appnt.getBirthDay());
    tAppntIDType.addText(appnt.getIdType());
    tAppntIDNo.addText(appnt.getIdNo());
    tMarriage.addText(appnt.getMarriage());
    tNationality.addText(appnt.getNationality());
    tLicenseType.addText(appnt.getLicenseType());
    tJobCode.addText(appnt.getJobCode());
    tProvince.addText(appnt.getProvince());
    tCity.addText(appnt.getCity());
    tCounty.addText(appnt.getCounty());
    tHomeAddress.addText(appnt.getHomeAddress());
    tHomeZipCode.addText(appnt.getHomeZipCode());
    tAppntMobile.addText(appnt.getMobile());
    tAppntOfficePhone.addText(appnt.getOfficePhone());
    tAppntPhone.addText(appnt.getPhone());
    tAppntFax.addText(appnt.getFax());
    tEmail.addText(appnt.getEmail());
    tGrpName.addText(appnt.getGrpName());

    return doc;
}

From source file:cn.com.sinosoft.ebusiness.xmltransfer.InsuredInfoChangeCreater.java

@Override
public Document createXml(Map<String, Object> map) {
    Document doc = null;//  w  w  w  . j a v  a2  s  . c o m
    doc = super.createXml(functionFlag);
    Element tTranRequest = (Element) doc.selectSingleNode(sTranRequest);
    Element tLCCont = tTranRequest.addElement("LCCont");
    Element tContNo = tLCCont.addElement("ContNo");
    Element tLCInsureds = tLCCont.addElement("LCInsureds");
    Element tLCInsuredCount = tLCInsureds.addElement("LCInsuredCount");
    Element tLCInsured = tLCInsureds.addElement("LCInsured");

    Element tName = tLCInsured.addElement("Name");
    Element tSex = tLCInsured.addElement("Sex");
    Element tBirthday = tLCInsured.addElement("Birthday");
    Element tIDType = tLCInsured.addElement("IDType");
    Element tIDNo = tLCInsured.addElement("IDNo");
    Element tMarriage = tLCInsured.addElement("Marriage");
    Element tNationality = tLCInsured.addElement("Nationality");
    Element tLicenseType = tLCInsured.addElement("LicenseType");
    Element tJobCode = tLCInsured.addElement("JobCode");
    Element tProvince = tLCInsured.addElement("Province");
    Element tCity = tLCInsured.addElement("City");
    Element tCounty = tLCInsured.addElement("County");
    Element tHomeAddress = tLCInsured.addElement("HomeAddress");
    Element tHomeZipCode = tLCInsured.addElement("HomeZipCode");
    Element tMobile = tLCInsured.addElement("Mobile");
    Element tOfficePhone = tLCInsured.addElement("OfficePhone");
    Element tHomePhone = tLCInsured.addElement("HomePhone");
    Element tHomeFax = tLCInsured.addElement("HomeFax");
    Element tEmail = tLCInsured.addElement("Email");
    Element tGrpName = tLCInsured.addElement("GrpName");

    PersonInfo insured = (PersonInfo) map.get("insured");
    String contNo = (String) map.get("ContNo");

    tContNo.addText(contNo);
    tLCInsuredCount.addText("1");
    tName.addText(insured.getName());
    tSex.addText(insured.getSex());
    tBirthday.addText(insured.getBirthDay());
    tIDType.addText(insured.getIdType());
    tIDNo.addText(insured.getIdNo());
    tMarriage.addText(insured.getMarriage());
    tNationality.addText(insured.getNationality());
    tLicenseType.addText(insured.getLicenseType());
    tJobCode.addText(insured.getJobCode());
    tProvince.addText(insured.getProvince());
    tCity.addText(insured.getCity());
    tCounty.addText(insured.getCounty());
    tHomeAddress.addText(insured.getHomeAddress());
    tHomeZipCode.addText(insured.getHomeZipCode());
    tMobile.addText(insured.getMobile());
    tOfficePhone.addText(insured.getOfficePhone());
    tHomePhone.addText(insured.getPhone());
    tHomeFax.addText(insured.getFax());
    tEmail.addText(insured.getEmail());
    tGrpName.addText(insured.getGrpName());

    return doc;
}

From source file:com.anite.maven.plugin.hivedoc.Dom4JRegistrySerializer.java

License:Apache License

private Element getModuleElement(ModuleDescriptor md) {
    Element module = DocumentHelper.createElement("module");

    module.addAttribute("id", md.getModuleId());
    module.addAttribute("version", md.getVersion());
    module.addAttribute("package", md.getPackageName());

    if (md.getAnnotation() != null) {
        module.addText(md.getAnnotation());
    }/*from  w  w w . j a va2 s . c  om*/

    addDependencies(module);

    addServicePoints(module);

    addConfigurationPoints(module);

    addContributions(module);

    addImplementations(module);

    addSchemas(module);

    addSubModules(module);

    return module;
}