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.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.
 *//*from   w  w w  .  j a  va2s .  c  om*/
private 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.tm.exporter.TmxWriter.java

License:Apache License

private static void injectStandardFormattingCodes(Element p_root, Element p_element) {
    // Depth-first traversal: add embedded <sub> to the list first.
    for (int i = 0, max = p_element.nodeCount(); i < max; i++) {
        Node child = (Node) p_element.node(i);

        if (child instanceof Element) {
            injectStandardFormattingCodes(p_root, (Element) child);
        }/*from ww  w .j  a  v a  2  s .c  o  m*/
    }

    String tagName = p_element.getName();
    String typeAttr = p_element.attributeValue("type");
    String iAttr = p_element.attributeValue("i");
    String posAttr = p_element.attributeValue("pos");

    if (tagName.equals("bpt") && typeAttr != null && iAttr != null) {
        Element ept = (Element) p_root.selectSingleNode("//ept[@i='" + iAttr + "']");

        if (typeAttr.equals("bold")) {
            p_element.addText("<B>");
            ept.addText("</B>");
        } else if (typeAttr.equals("italic")) {
            p_element.addText("<I>");
            ept.addText("</I>");
        } else if (typeAttr.equals("ulined")) {
            p_element.addText("<U>");
            ept.addText("</U>");
        }
    } else if (tagName.equals("it") && typeAttr != null && posAttr != null) {
        if (typeAttr.equals("bold")) {
            if (posAttr.equals("begin")) {
                p_element.addText("<B>");
            } else {
                p_element.addText("</B>");
            }
        } else if (typeAttr.equals("italic")) {
            if (posAttr.equals("begin")) {
                p_element.addText("<I>");
            } else {
                p_element.addText("</I>");
            }
        } else if (typeAttr.equals("ulined")) {
            if (posAttr.equals("begin")) {
                p_element.addText("<U>");
            } else {
                p_element.addText("</U>");
            }
        }
    }
}

From source file:com.globalsight.everest.tm.importer.TmxReaderThread.java

License:Apache License

/**
 * Removes the given TMX 1.4 <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 ava  2  s. co  m
 */
private 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.gst.mix.service.XBRLBuilder.java

License:Apache License

Element addTaxonomy(final Element rootElement, final MixTaxonomyData taxonomy, final BigDecimal value) {

    // throw an error is start / endate is null
    if (this.startDate == null || this.endDate == null) {
        throw new XBRLMappingInvalidException("start date and end date should not be null");
    }//from   ww  w  . j av a 2 s  .  c  om

    final String prefix = taxonomy.getNamespace();
    String qname = taxonomy.getName();
    if (prefix != null && (!prefix.isEmpty())) {
        final NamespaceData ns = this.readNamespaceService.retrieveNamespaceByPrefix(prefix);
        if (ns != null) {

            this.root.addNamespace(prefix, ns.url());
        }
        qname = prefix + ":" + taxonomy.getName();

    }
    final Element xmlElement = rootElement.addElement(qname);

    final String dimension = taxonomy.getDimension();
    final SimpleDateFormat timeFormat = new SimpleDateFormat("MM_dd_yyyy");

    ContextData context = null;
    if (dimension != null) {
        final String[] dims = dimension.split(":");

        if (dims.length == 2) {
            context = new ContextData(dims[0], dims[1], taxonomy.getType());
            if (this.contextMap.containsKey(context)) {

            } else {

            }
        }
    }

    if (context == null) {
        context = new ContextData(null, null, taxonomy.getType());
    }

    if (!this.contextMap.containsKey(context)) {

        final String startDateStr = timeFormat.format(this.startDate);
        final String endDateStr = timeFormat.format(this.endDate);

        final String contextRefID = (context.getPeriodType() == 0)
                ? ("As_Of_" + endDateStr + (this.instantScenarioCounter++))
                : ("Duration_" + startDateStr + "_To_" + endDateStr + (this.durationScenarioCounter++));

        this.contextMap.put(context, contextRefID);
    }

    xmlElement.addAttribute("contextRef", this.contextMap.get(context));
    xmlElement.addAttribute("unitRef", getUnitRef(taxonomy));
    xmlElement.addAttribute("decimals", getNumberOfDecimalPlaces(value).toString());

    // add the child
    xmlElement.addText(value.toPlainString());

    return xmlElement;
}

From source file:com.gst.mix.service.XBRLBuilder.java

License:Apache License

/**
 * Adds the generic number unit//from   www .  j  a v  a 2  s  .c o m
 */
void addNumberUnit() {
    final Element numerUnit = this.root.addElement("unit");
    numerUnit.addAttribute("id", UNITID_PURE);
    final Element measure = numerUnit.addElement("measure");
    measure.addText("xbrli:pure");

}

From source file:com.gst.mix.service.XBRLBuilder.java

License:Apache License

/**
 * Adds the currency unit to the document
 * /*  w ww. jav a  2  s .  c  o m*/
 * @param currencyCode
 */
public void addCurrencyUnit(final String currencyCode) {
    final Element currencyUnitElement = this.root.addElement("unit");
    currencyUnitElement.addAttribute("id", UNITID_CUR);
    final Element measure = currencyUnitElement.addElement("measure");
    measure.addText("iso4217:" + currencyCode);

}

From source file:com.haulmont.cuba.gui.components.filter.UserSetHelper.java

License:Apache License

public static String generateSetFilter(Set ids, String entityClass, String componentId, String entityAlias) {
    Document document = DocumentHelper.createDocument();
    Element root = DocumentHelper.createElement("filter");
    Element or = root.addElement("and");

    Element condition = or.addElement("c");
    condition.addAttribute("name", "set");
    condition.addAttribute("inExpr", "true");
    condition.addAttribute("hidden", "true");
    condition.addAttribute("locCaption", "Set filter");
    condition.addAttribute("entityAlias", entityAlias);
    condition.addAttribute("class", entityClass);
    condition.addAttribute("type", ConditionType.CUSTOM.name());

    String listOfId = createIdsString(ids);
    String randomName = RandomStringUtils.randomAlphabetic(10);
    condition.addText(entityAlias + ".id in :component$" + componentId + "." + randomName);

    Element param = condition.addElement("param");
    param.addAttribute("name", "component$" + componentId + "." + randomName);
    param.addText(listOfId);/*from  w  w  w  .  j  a va  2 s  .  c  om*/

    document.add(root);
    return Dom4j.writeDocument(document, true);
}

From source file:com.jaspersoft.jasperserver.export.modules.logging.access.AccessEventsExporter.java

License:Open Source License

protected void addAccessEventIndexEntry(long counter) {
    Element indexElement = getIndexElement();
    Element tenantElement = indexElement.addElement(accessModuleConfiguration.getAccessEventIndexElement());
    tenantElement.addText(String.valueOf(counter));
}

From source file:com.jaspersoft.jasperserver.export.modules.mt.TenantExporter.java

License:Open Source License

protected void addTenantIndexEntry(Tenant tenant) {
    Element indexElement = getIndexElement();
    Element tenantElement = indexElement.addElement(moduleConfiguration.getTenantIndexElement());
    tenantElement.addText(tenant.getId());
}

From source file:com.jaspersoft.jasperserver.export.modules.repository.ResourceExporter.java

License:Open Source License

protected void addFolderIndexElement(String uri) {
    Element folderElement = getIndexElement().addElement(configuration.getFolderIndexElement());
    folderElement.addText(uri);
}