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.cosmosource.common.service.UserMgrManager.java

/**
 * @??: DOC//from www.j  a  va 2  s  . c om
 * @param orgId
 * @param root
 */
public void getOrgTreeDoc(Long orgId, Element root, String ctx, String orgtype) {

    List<TAcOrg> list = dao.findByHQL("select t from TAcOrg t where t.parentid=" + orgId);
    if (!orgtype.equals("3")) {
        for (TAcOrg org : list) {
            Element el = root.addElement("item");
            el.addAttribute("text", org.getOrgname());
            el.addAttribute("id", org.getOrgid() + "");
            if (org.getParentid() == 0) {
                el.addAttribute("open", "1");
            }
            Element elx = el.addElement("userdata");
            elx.addAttribute("name", "url");
            if (!org.getOrgtype().equals("3")) {
                elx.addText(ctx + "/common/userMgr/list.act?nodeId=" + org.getOrgid() + "&orgtype="
                        + org.getOrgtype());
            } else {
                elx.addText(ctx + "/common/userMgr/orgFrame.act?nodeId=" + org.getOrgid());
            }

            if ("1".equals(org.getIsbottom())) {
                getOrgTreeDoc(org.getOrgid(), el, ctx, org.getOrgtype());
            }
        }
    }
}

From source file:com.dtolabs.client.services.JobDefinitionSerializer.java

License:Apache License

/**
 * Add script dispatch content to the job element
 *
 * @param dispatchdef dispatch definition
 * @param job         job element/*from  w ww  .j a v  a2  s  .c  om*/
 * @throws java.io.IOException if the input IDispatchedScript throws it when accessing script stream input.
 */
private static void addScriptDispatch(final IDispatchedScript dispatchdef, final Element job)
        throws IOException {
    if (null == dispatchdef.getFrameworkProject()) {
        throw new IllegalArgumentException("No project is specified");
    }
    final Element ctx = job.addElement("context");
    ctx.addElement("project").addText(dispatchdef.getFrameworkProject());
    final InputStream stream = dispatchdef.getScriptAsStream();
    final Element seq = job.addElement("sequence");
    final Element cmd = seq.addElement("command");
    if (null != dispatchdef.getScript() || null != stream) {

        //full script
        final Element script = cmd.addElement("script");
        if (null != dispatchdef.getScript()) {
            script.addCDATA(dispatchdef.getScript());
        } else {
            //serialize script inputstream and add string to dom
            final StringWriter sw = new StringWriter();
            copyReader(new InputStreamReader(stream), sw, 10240);
            sw.flush();
            script.addCDATA(sw.toString());
        }
        if (null != dispatchdef.getArgs() && dispatchdef.getArgs().length > 0) {
            final Element argstring = cmd.addElement("scriptargs");
            argstring.addText(OptsUtil.join(dispatchdef.getArgs()));
        }
    } else if (null != dispatchdef.getServerScriptFilePath()) {
        //server-local script filepath
        final Element filepath = cmd.addElement("scriptfile");
        filepath.addText(dispatchdef.getServerScriptFilePath());
        if (null != dispatchdef.getArgs() && dispatchdef.getArgs().length > 0) {
            final Element argstring = cmd.addElement("scriptargs");
            argstring.addText(OptsUtil.join(dispatchdef.getArgs()));
        }
    } else if (null != dispatchdef.getArgs() && dispatchdef.getArgs().length > 0) {
        //shell command
        final Element exec = cmd.addElement("exec");
        exec.addText(OptsUtil.join(dispatchdef.getArgs()));
    } else {
        throw new IllegalArgumentException("Dispatched script did not specify a command, script or filepath");
    }

}

From source file:com.eurelis.opencms.ant.task.ManifestBuilderTask.java

License:Open Source License

public Document createDocument() {

    document = DocumentHelper.createDocument();
    document.setXMLEncoding("UTF-8");
    Element root = document.addElement("export");

    Element info = root.addElement("info");
    if (creator != null)
        info.addElement("creator").addText(creator);
    if (opencmsversion != null)
        info.addElement("opencms_version").addText(opencmsversion);
    info.addElement("createdate").addText(dateformat.format(new Date()));
    if (project != null)
        info.addElement("infoproject").addText(project);
    if (exportversion != null)
        info.addElement("export_version").addText(exportversion);

    Element module = root.addElement("module");

    if (name != null)
        module.addElement("name").addText(name);
    if (nicename != null)
        module.addElement("nicename").addText(nicename);
    if (group != null)
        module.addElement("group").addText(group);
    if (moduleclass != null)
        module.addElement("class").addText(moduleclass);
    if (moduledescription != null)
        module.addElement("description").add(new FlyweightCDATA(moduledescription));
    if (version != null)
        module.addElement("version").addText(version);
    if (authorname != null)
        module.addElement("authorname").add(new FlyweightCDATA(authorname));
    if (authoremail != null)
        module.addElement("authoremail").add(new FlyweightCDATA(authoremail));
    module.addElement("datecreated").addText(dateformat.format(new Date()));
    module.addElement("userinstalled").addText(userinstalled);
    module.addElement("dateinstalled").addText(dateinstalled);

    Element dependenciesBlock = module.addElement("dependencies");
    for (Dependency dep : dependencies) {
        dependenciesBlock.addElement("dependency").addAttribute("name", dep.getName()).addAttribute("version",
                dep.getVersion());/*  w  w  w . ja va 2s .  c o m*/
    }

    Element exportPointsBlock = module.addElement("exportpoints");
    for (ExportPoint ep : exportpoints) {
        exportPointsBlock.addElement("exportpoint").addAttribute("uri", ep.getSrc()).addAttribute("destination",
                ep.getDst());
    }

    Element resourcesBlock = module.addElement("resources");
    for (Resource res : resources) {
        resourcesBlock.addElement("resource").addAttribute("uri", res.getUri());
    }

    Element parametersBlock = module.addElement("parameters");
    for (Parameter par : parameters) {
        parametersBlock.addElement("param").addAttribute("name", par.getName()).addText(par.getValue());
    }

    insertResourceTypes(module);
    insertExplorerTypes(module);

    if (!filesets.isEmpty()) {

        Element files = root.addElement("files");

        for (FileSet fileset : filesets) {
            DirectoryScanner ds = fileset.getDirectoryScanner(fileset.getProject());
            String[] dirs = ds.getIncludedDirectories();
            String[] filesColl = ds.getIncludedFiles();

            String[] excluDirsArray = ds.getExcludedDirectories();
            List<String> excluDirs = new ArrayList<String>();
            excluDirs.addAll(Arrays.asList(excluDirsArray));

            String[] excluFilesArray = ds.getExcludedFiles();
            List<String> excluFiles = new ArrayList<String>();
            excluFiles.addAll(Arrays.asList(excluFilesArray));

            CmsUUID.init("B4:B6:76:78:7F:3E");

            // FOLDERS MANAGEMENT
            for (int i = 0; i < dirs.length; i++) {
                String filepath = dirs[i];
                String filepathUnix = dirs[i].replace(SEPARATOR, "/");
                if (dirs[i] != "") {
                    Element tmpFile = files.addElement("file");
                    tmpFile.addElement("destination").addText(filepathUnix);

                    String folderPropertiesPath = getProject().getBaseDir() + SEPARATOR + srcfolder + SEPARATOR
                            + folderPropertiesPath(filepath);
                    String tmpType = getEurelisProperty("type", folderPropertiesPath);
                    if (null == tmpType) {
                        tmpType = "folder";
                    }
                    tmpFile.addElement("type").addText(tmpType);

                    if (generateuuids) {
                        Element uuidNode = tmpFile.addElement("uuidstructure");
                        String tmpUUID = getEurelisProperty("structureUUID", folderPropertiesPath);
                        if (null != tmpUUID)
                            uuidNode.addText(tmpUUID);
                        else
                            uuidNode.addText(new CmsUUID().toString());
                        // AJOUTER SAUVEGARDE DU NOUVEL UUID
                    }

                    long date = new File(
                            getProject().getBaseDir() + SEPARATOR + srcfolder + SEPARATOR + filepath)
                                    .lastModified();
                    if (0L == date)
                        date = new Date().getTime();
                    String formattedDate = dateformat.format(date);
                    tmpFile.addElement("datelastmodified").addText(formattedDate);
                    tmpFile.addElement("userlastmodified").addText("Admin");
                    // WARNING : CONSTANT VALUE
                    tmpFile.addElement("datecreated").addText(formattedDate);
                    // WARNING : CONSTANT VALUE
                    tmpFile.addElement("usercreated").addText("Admin");
                    tmpFile.addElement("flags").addText("0");

                    Element properties = tmpFile.addElement("properties");
                    // props detection and implementation
                    String tmpPropFile = folderPropertiesPath;
                    addPropertiesToTree(properties, tmpPropFile);

                    String tmpAccessFile = getProject().getBaseDir() + SEPARATOR + srcfolder + SEPARATOR
                            + folderAccessesPath(filepath);
                    addAccessesToTree(tmpFile, tmpAccessFile);
                }
            }
            // FILES MANAGEMENT
            for (int i = 0; i < filesColl.length; i++) {
                String filepath = filesColl[i];
                String filepathUnix = filesColl[i].replace(SEPARATOR, "/");
                if (filesColl[i] != "") {
                    Element tmpFile = files.addElement("file");
                    tmpFile.addElement("source").addText(filepathUnix);
                    tmpFile.addElement("destination").addText(filepathUnix);

                    String propertiesFilepath = getProject().getBaseDir() + SEPARATOR + srcfolder + SEPARATOR
                            + filePropertiesPath(filepath);
                    String tmpType = getEurelisProperty("type", propertiesFilepath);
                    if (null == tmpType) {
                        if (filepathUnix.endsWith(".config"))
                            tmpType = "module_config";
                        else if (filepathUnix.endsWith("main.jsp"))
                            tmpType = "containerpage_template";
                        else if (filepathUnix.endsWith(".jsp"))
                            tmpType = "jsp";
                        else if (filepathUnix.endsWith(".png") || filepathUnix.endsWith(".gif")
                                || filepathUnix.endsWith(".jpg") || filepathUnix.endsWith(".jpeg"))
                            tmpType = "image";
                        else if (filepathUnix.endsWith(".html") && filepathUnix.contains("/models/"))
                            tmpType = "containerpage";
                        else
                            tmpType = "plain";
                    }
                    tmpFile.addElement("type").addText(tmpType);

                    if (generateuuids) {
                        Element uuidNode = tmpFile.addElement("uuidresource");
                        Element uuidNode2 = tmpFile.addElement("uuidstructure");
                        String tmpUUID = getEurelisProperty("resourceUUID", propertiesFilepath);
                        if (null != tmpUUID)
                            uuidNode.addText(tmpUUID);
                        else
                            uuidNode.addText(new CmsUUID().toString());
                        tmpUUID = getEurelisProperty("structureUUID", propertiesFilepath);
                        if (null != tmpUUID)
                            uuidNode2.addText(tmpUUID);
                        else
                            uuidNode2.addText(new CmsUUID().toString());
                    }

                    long date = new File(
                            getProject().getBaseDir() + SEPARATOR + srcfolder + SEPARATOR + filepath)
                                    .lastModified();
                    if (0L == date)
                        date = new Date().getTime();
                    String formattedDate = dateformat.format(date);

                    tmpFile.addElement("datelastmodified").addText(formattedDate);
                    tmpFile.addElement("userlastmodified").addText("Admin");
                    tmpFile.addElement("datecreated").addText(formattedDate);
                    tmpFile.addElement("usercreated").addText("Admin");
                    tmpFile.addElement("flags").addText("0");
                    Element properties = tmpFile.addElement("properties");
                    String tmpPropFile = propertiesFilepath;
                    addPropertiesToTree(properties, tmpPropFile);

                    tmpFile.addElement("accesscontrol");

                }
            }
        }
    }

    return document;
}

From source file:com.ewcms.content.particular.service.ProjectBasicService.java

License:Open Source License

public Document exportXml(List<Long> projectBasicIds) {
    Document document = DocumentHelper.createDocument();

    Element root = document.addElement("MetaDatas");
    Element metaViewData = root.addElement("MetaViewData");

    if (projectBasicIds.isEmpty())
        return document;

    for (Long projectBasicId : projectBasicIds) {
        ProjectBasic projectBasic = projectBasicDAO.get(projectBasicId);

        Element projects = metaViewData.addElement("PROPERTIES");

        Element code = projects.addElement("?");
        code.addText(projectBasic.getCode() == null ? "" : projectBasic.getCode());

        Element name = projects.addElement("??");
        name.addText(projectBasic.getName() == null ? "" : projectBasic.getName());

        Element buildTime = projects.addElement("");
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        if (projectBasic.getBuildTime() != null) {
            buildTime.addText(dateFormat.format(projectBasic.getBuildTime()));
        } else {//  w ww .  j a v  a2 s  .  co  m
            buildTime.addText("");
        }

        Element investmentScale = projects.addElement("");
        investmentScale
                .addText(projectBasic.getInvestmentScale() == null ? "" : projectBasic.getInvestmentScale());

        Element overview = projects.addElement("");
        overview.addText(projectBasic.getOverview() == null ? "" : projectBasic.getOverview());

        Element buildUnit = projects.addElement("??");
        buildUnit.addText(projectBasic.getBuildUnit() == null ? "" : projectBasic.getBuildUnit());

        Element unitPhone = projects.addElement("????");
        unitPhone.addText(projectBasic.getUnitPhone() == null ? "" : projectBasic.getUnitPhone());

        Element unitAddress = projects.addElement("???");
        unitAddress.addText(projectBasic.getUnitAddress() == null ? "" : projectBasic.getUnitAddress());

        Element zoningCode_code = projects.addElement("?");
        if (projectBasic.getZoningCode() != null)
            zoningCode_code.addText(projectBasic.getZoningCode().getCode() == null ? ""
                    : projectBasic.getZoningCode().getCode());
        else
            zoningCode_code.addText("");

        Element organizationCode = projects.addElement("?");
        organizationCode
                .addText(projectBasic.getOrganizationCode() == null ? "" : projectBasic.getOrganizationCode());

        Element industryCode_code = projects.addElement("?");
        if (projectBasic.getIndustryCode() != null)
            industryCode_code.addText(projectBasic.getIndustryCode().getCode() == null ? ""
                    : projectBasic.getIndustryCode().getCode());
        else
            industryCode_code.addText("");

        Element category = projects.addElement("");
        category.addText(projectBasic.getCategory() == null ? "" : projectBasic.getCategory());

        Element unitId = projects.addElement("???");
        unitId.addText(projectBasic.getUnitId() == null ? "" : projectBasic.getUnitId());

        Element approvalRecord_code = projects.addElement("?");
        if (projectBasic.getApprovalRecord() != null)
            approvalRecord_code.addText(projectBasic.getApprovalRecord().getCode() == null ? ""
                    : projectBasic.getApprovalRecord().getCode());
        else
            approvalRecord_code.addText("");

        Element address = projects.addElement("?");
        address.addText(projectBasic.getAddress() == null ? "" : projectBasic.getAddress());

        Element bildNature = projects.addElement("");
        if (projectBasic.getBildNature() != null)
            bildNature.addText(projectBasic.getBildNature().getDescription() == null ? ""
                    : projectBasic.getBildNature().getDescription());
        else
            bildNature.addText("");

        Element contact = projects.addElement("?");
        contact.addText(projectBasic.getContact() == null ? "" : projectBasic.getContact());

        Element phone = projects.addElement("??");
        phone.addText(projectBasic.getPhone() == null ? "" : projectBasic.getPhone());

        Element email = projects.addElement("??");
        email.addText(projectBasic.getEmail() == null ? "" : projectBasic.getEmail());
    }
    return document;
}

From source file:com.ewcms.util.XMLUtil.java

License:Open Source License

/**
 * //from   w w w . java 2  s . c  om
 * 
 * @param thisElement
 * @param text
 */
public void addText(Element thisElement, String text) {
    thisElement.addText(text);
}

From source file:com.flaptor.hounder.indexer.HtmlParser.java

License:Apache License

/**
 * Parses a tag to produce a field./*from  w  w w  .jav a2  s .c o m*/
 * @param doc the doc to modify
 * @throw exception on error, signaling the main method to return no document.
 */
private void processTag(Document doc, final String tagName, final String fieldName) throws Exception {
    Node bodyElement = doc.selectSingleNode("/*/" + tagName);
    if (null == bodyElement) {
        logger.warn("Content element missing from document. I was expecting a '" + tagName + "'. Will not add '"
                + fieldName + "' field.");
        return;
    }

    Node destElement = doc.selectSingleNode("//field[@name='" + fieldName + "']");
    if (null != destElement) {
        logger.warn("Parsed element '" + fieldName + "' already present in document. Will not overwrite.");
        return;
    }

    ParseOutput out = parser.parse("", bodyElement.getText().getBytes("UTF-8"), "UTF-8");

    for (String field : extraFields) {
        String content = out.getField(field);
        if (null == content) {
            logger.debug("had document without " + field + " field. Continuing with other fields.");
            continue;
        }
        Element docField = DocumentHelper.createElement("field");
        docField.addText(content);
        docField.addAttribute("name", field);
        docField.addAttribute("indexed", Boolean.toString(INDEXED));
        docField.addAttribute("stored", Boolean.toString(STORED));
        docField.addAttribute("tokenized", "true");
        bodyElement.getParent().add(docField);
    }

    String text = out.getText();
    Element field = DocumentHelper.createElement("field");
    field.addText(text);
    field.addAttribute("name", fieldName);
    field.addAttribute("indexed", Boolean.toString(INDEXED));
    field.addAttribute("stored", Boolean.toString(STORED));
    field.addAttribute("tokenized", "true");
    bodyElement.getParent().add(field);
}

From source file:com.globalsight.cxe.adapter.msoffice.ExcelRepairer.java

License:Apache License

private void repairExcelSharedStrings() throws Exception {
    File f = new File(path + "/xl/sharedStrings.xml");
    if (!f.exists())
        return;/* www. j a va2s. co  m*/

    String content = FileUtil.readFile(f, "utf-8");

    XmlParser parser = new XmlParser();
    org.dom4j.Document document = parser.parseXml(content);
    Element element = document.getRootElement();
    List<Element> rs = getElementByName(element, "r");
    for (Element r : rs) {
        @SuppressWarnings("rawtypes")
        List els = r.content();

        StringBuffer sb = new StringBuffer();
        Element wt = null;
        List<DefaultText> texts = new ArrayList<DefaultText>();

        for (Object el : els) {
            if (el instanceof DefaultText) {
                DefaultText text = (DefaultText) el;
                String s = text.getStringValue();
                if ("\n".equals(s))
                    continue;

                texts.add(text);
                sb.append(text.getStringValue());
            } else if (el instanceof Element) {
                Element elm = (Element) el;
                if ("t".equals(elm.getName())) {
                    wt = elm;
                    sb.append(elm.getStringValue());
                }
            }
        }

        if (wt == null) {
            wt = r.addElement("t");
            wt.addAttribute("xml:space", "preserve");
        }

        if (sb.length() == 0)
            sb.append(" ");

        wt.clearContent();
        wt.addText(sb.toString());

        for (DefaultText text : texts) {
            r.remove(text);
        }
    }

    Writer fileWriter = new OutputStreamWriter(new FileOutputStream(f), "UTF-8");
    XMLWriter xmlWriter = new XMLWriter(fileWriter);
    xmlWriter.write(document);
    xmlWriter.close();
}

From source file:com.globalsight.everest.edit.offline.page.TmxUtil.java

License:Apache License

/**
 * Removes the given <sub> element from the segment. <sub> is special since
 * it does not only surround embedded tags but also text, which must be
 * pulled out of the <sub> and added to the parent tag.
 *//*from  www .ja v  a 2 s . c om*/
public static void replaceNbsp(Element p_element) {
    Element parent = p_element.getParent();
    int index = parent.indexOf(p_element);

    // We copy the current content, clear out the parent, and then
    // re-add the old content, inserting the <sub>'s textual
    // content instead of the <sub> (this clears any embedded TMX
    // tags in the subflow).

    ArrayList newContent = new ArrayList();
    List content = parent.content();

    for (int i = content.size() - 1; i >= 0; --i) {
        Node node = (Node) content.get(i);

        newContent.add(node.detach());
    }

    Collections.reverse(newContent);
    parent.clearContent();

    for (int i = 0, max = newContent.size(); i < max; ++i) {
        Node node = (Node) newContent.get(i);

        if (i == index) {
            parent.addText("\u00A0");
        } else {
            parent.add(node);
        }
    }
}

From source file:com.globalsight.everest.edit.offline.page.TmxUtil.java

License:Apache License

/**
 * Removes the given <sub> element from the segment. <sub> is special since
 * it does not only surround embedded tags but also text, which must be
 * pulled out of the <sub> and added to the parent tag.
 *///  w ww.j a v  a  2s.  c om
public static void removeSubElement(Element p_element) {
    Element parent = p_element.getParent();
    int index = parent.indexOf(p_element);

    // We copy the current content, clear out the parent, and then
    // re-add the old content, inserting the <sub>'s textual
    // content instead of the <sub> (this clears any embedded TMX
    // tags in the subflow).

    ArrayList newContent = new ArrayList();
    List content = parent.content();

    for (int i = content.size() - 1; i >= 0; --i) {
        Node node = (Node) content.get(i);

        newContent.add(node.detach());
    }

    Collections.reverse(newContent);
    parent.clearContent();

    for (int i = 0, max = newContent.size(); i < max; ++i) {
        Node node = (Node) newContent.get(i);

        if (i == index) {
            parent.addText(p_element.getText());
        } else {
            parent.add(node);
        }
    }
}

From source file:com.globalsight.everest.tm.exporter.TmxWriter.java

License:Apache License

/**
 * Removes the given <sub> element from the segment. <sub> is special since
 * it does not only surround embedded tags but also text, which must be
 * pulled out of the <sub> and added to the parent tag.
 *///w  w  w  .j  a  v a2s  . com
private static void removeSubElement(Element p_element) {
    Element parent = p_element.getParent();
    int index = parent.indexOf(p_element);

    // We copy the current content, clear out the parent, and then
    // re-add the old content, inserting the <sub>'s textual
    // content instead of the <sub> (this clears any embedded TMX
    // tags in the subflow).

    ArrayList newContent = new ArrayList();
    List content = parent.content();

    for (int i = content.size() - 1; i >= 0; --i) {
        Node node = (Node) content.get(i);

        newContent.add(node.detach());
    }

    Collections.reverse(newContent);
    parent.clearContent();

    for (int i = 0, max = newContent.size(); i < max; ++i) {
        Node node = (Node) newContent.get(i);

        if (i == index) {
            parent.addText(p_element.getText());
        } else {
            parent.add(node);
        }
    }
}