Example usage for org.jdom2 Text setText

List of usage examples for org.jdom2 Text setText

Introduction

In this page you can find the example usage for org.jdom2 Text setText.

Prototype

public Text setText(String str) 

Source Link

Document

This will set the value of this Text node.

Usage

From source file:ditatools.translate.DitaTranslator.java

License:Apache License

private void handleText(Text text) {
    if (text.getTextTrim().length() > 0) {
        try {/* w  w w.  j a v  a2 s .com*/
            Translation fromEnglish = translator.translate(text.getText(), DOC_LANGUAGE, language);

            // String translatedValue = fromEnglish.getTranslatedText();
            // System.out.println(translatedValue);
            // printCharacters(translatedValue);
            // text.setText(translatedValue);

            // XXX better handling of API errors; in particular, wait
            //  and retry when hitting a short term API rate limit.

            text.setText(fromEnglish.getTranslatedText());
        } catch (IOException e) {
            e.printStackTrace();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        } catch (TranslatorException e) {
            e.printStackTrace();
        }

    }

}

From source file:org.apache.maven.io.util.WriterUtils.java

License:Apache License

/**
 * Method insertAtPreferredLocation.//  www  . j av  a2  s  . co  m
 * 
 * @param parent
 * @param counter
 * @param child
 */
public static void insertAtPreferredLocation(final Element parent, final Element child,
        final IndentationCounter counter) {
    int contentIndex = 0;
    int elementCounter = 0;
    final Iterator it = parent.getContent().iterator();
    Text lastText = null;
    int offset = 0;
    while (it.hasNext() && elementCounter <= counter.getCurrentIndex()) {
        final Object next = it.next();
        offset = offset + 1;
        if (next instanceof Element) {
            elementCounter = elementCounter + 1;
            contentIndex = contentIndex + offset;
            offset = 0;
        }
        if (next instanceof Text && it.hasNext()) {
            lastText = (Text) next;
        }
    }
    if (lastText != null && lastText.getTextTrim().length() == 0) {
        lastText = lastText.clone();
    } else {
        String starter = lineSeparator;
        for (int i = 0; i < counter.getDepth(); i++) {
            starter = starter + INDENT; // TODO make settable?
        }
        lastText = factory.text(starter);
    }
    if (parent.getContentSize() == 0) {
        final Text finalText = lastText.clone();
        finalText.setText(finalText.getText().substring(0, finalText.getText().length() - INDENT.length()));
        parent.addContent(contentIndex, finalText);
    }
    parent.addContent(contentIndex, child);
    parent.addContent(contentIndex, lastText);
}

From source file:org.apache.maven.toolchain.model.io.jdom.MavenToolchainsJDOMWriter.java

License:Apache License

/**
 * Method insertAtPreferredLocation./*from  www  .  java 2  s.c o  m*/
 * 
 * @param parent
 * @param counter
 * @param child
 */
protected void insertAtPreferredLocation(final Element parent, final Element child,
        final IndentationCounter counter) {
    int contentIndex = 0;
    int elementCounter = 0;
    final Iterator it = parent.getContent().iterator();
    Text lastText = null;
    int offset = 0;
    while (it.hasNext() && elementCounter <= counter.getCurrentIndex()) {
        final Object next = it.next();
        offset = offset + 1;
        if (next instanceof Element) {
            elementCounter = elementCounter + 1;
            contentIndex = contentIndex + offset;
            offset = 0;
        }
        if (next instanceof Text && it.hasNext()) {
            lastText = (Text) next;
        }
    }
    if (lastText != null && lastText.getTextTrim().length() == 0) {
        lastText = lastText.clone();
    } else {
        String starter = lineSeparator;
        for (int i = 0; i < counter.getDepth(); i++) {
            starter = starter + INDENT; // TODO make settable?
        }
        lastText = factory.text(starter);
    }
    if (parent.getContentSize() == 0) {
        final Text finalText = lastText.clone();
        finalText.setText(finalText.getText().substring(0, finalText.getText().length() - INDENT.length()));
        parent.addContent(contentIndex, finalText);
    }
    parent.addContent(contentIndex, child);
    parent.addContent(contentIndex, lastText);
}

From source file:org.kdp.word.transformer.ListParagraphTransformer.java

License:Apache License

private void normalizeListItemText(Element el) {
    for (Content co : el.getContent()) {
        if (co.getCType() == CType.Text) {
            Text tco = (Text) co;
            String text = tco.getText().trim();
            tco.setText(text + " ");
        }/*  ww w .  jav a  2  s.  c o m*/
    }
}

From source file:org.kdp.word.transformer.ListParagraphTransformer.java

License:Apache License

private boolean processItemMarker(Element liItem) {
    String first = "";
    int cosize = liItem.getContentSize();
    Content co = liItem.getContent(0);/*ww w .j a  v a2  s  .c  o  m*/
    if (co.getCType() == CType.Text) {
        Text text = (Text) co;
        String value = text.getText();
        int index = value.indexOf(" ");
        first = value.substring(0, index);
        value = value.substring(index + 1);
        text.setText(value);
    } else if (cosize > 1 && co.getCType() == CType.Element) {
        Element el = (Element) co;
        first = el.getText();
        el.getParent().removeContent(co);
    }
    return first.endsWith(".");
}

From source file:org.mycore.frontend.editor.postprocessor.MCREditorPostProcessorXSL.java

License:Open Source License

public MCRJDOMContent transform(MCRContent source) throws IOException {
    try {/*w  ww. ja  v  a  2s  .c om*/
        Element root = source.asXML().getRootElement().clone();
        for (Iterator<Text> iter = root.getDescendants(Filters.text()).iterator(); iter.hasNext();) {
            Text text = iter.next();
            text.setText(MCRXMLFunctions.normalizeUnicode(text.getText()));
        }
        return new MCRJDOMContent(root);
    } catch (JDOMException ex) {
        throw new IOException(ex);
    } catch (SAXException ex) {
        throw new IOException(ex);
    }
}