Search in sources :

Example 11 with Text

use of org.omegat.filters3.Text in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class TextIT method setupBeforeEach.

@BeforeEach
public void setupBeforeEach() throws ClientException {
    setComponentResources();
    text = new Text();
    setup();
}
Also used : Text(com.adobe.cq.wcm.core.components.it.seljup.util.components.text.v1.Text) BaseText(com.adobe.cq.wcm.core.components.it.seljup.util.components.text.BaseText) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 12 with Text

use of org.omegat.filters3.Text in project mycore by MyCoRe-Org.

the class MCRWCMSDefaultSectionProvider method getContent.

/**
 * Returns the content of an element as string. The element itself
 * is ignored.
 *
 * @param e the element to get the content from
 * @return the content as string
 */
protected String getContent(Element e) throws IOException {
    XMLOutputter out = new XMLOutputter();
    StringWriter writer = new StringWriter();
    for (Content child : e.getContent()) {
        if (child instanceof Element) {
            out.output((Element) child, writer);
        } else if (child instanceof Text) {
            Text t = (Text) child;
            String trimmedText = t.getTextTrim();
            if (!trimmedText.equals("")) {
                Text newText = new Text(trimmedText);
                out.output(newText, writer);
            }
        }
    }
    return writer.toString();
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) StringWriter(java.io.StringWriter) Content(org.jdom2.Content) JsonElement(com.google.gson.JsonElement) Element(org.jdom2.Element) Text(org.jdom2.Text)

Example 13 with Text

use of org.omegat.filters3.Text in project mycore by MyCoRe-Org.

the class MCRMetaNumberTest method xmlRoundrip.

@Test
public void xmlRoundrip() throws IOException {
    // test 0.100
    MCRMetaNumber meta_number = new MCRMetaNumber();
    Element imported = new Element("number");
    imported.setAttribute("inherited", "0");
    imported.setAttribute("dimension", "width");
    imported.setAttribute("measurement", "cm");
    imported.addContent(new Text("0.100"));
    meta_number.setFromDOM(imported);
    Element exported = meta_number.createXML();
    print_data(imported, exported);
    check_data(imported, exported);
}
Also used : Element(org.jdom2.Element) Text(org.jdom2.Text) Test(org.junit.Test)

Example 14 with Text

use of org.omegat.filters3.Text in project mycore by MyCoRe-Org.

the class MCRMetaXMLTest method xmlRoundrip.

@Test
public void xmlRoundrip() throws IOException {
    MCRMetaXML mXml = new MCRMetaXML("def.heading", "complete", 0);
    Element imported = new Element("heading");
    imported.setAttribute("lang", MCRMetaDefault.DEFAULT_LANGUAGE, Namespace.XML_NAMESPACE);
    imported.setAttribute("inherited", "0");
    imported.setAttribute("type", "complete");
    imported.addContent(new Text("This is a "));
    imported.addContent(new Element("span").setText("JUnit"));
    imported.addContent(new Text("test"));
    mXml.setFromDOM(imported);
    Element exported = mXml.createXML();
    if (LOGGER.isDebugEnabled()) {
        XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
        StringWriter sw = new StringWriter();
        StringWriter sw2 = new StringWriter();
        try {
            xout.output(imported, sw);
            LOGGER.info(sw.toString());
            xout.output(exported, sw2);
            LOGGER.info(sw2.toString());
        } catch (IOException e) {
            LOGGER.warn("Failure printing xml result", e);
        }
    }
    try {
        assertTrue(MCRXMLHelper.deepEqual(new Document(imported), new Document(exported)));
    } catch (AssertionError e) {
        XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
        out.output(imported, System.err);
        out.output(exported, System.err);
        throw e;
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) StringWriter(java.io.StringWriter) Element(org.jdom2.Element) Text(org.jdom2.Text) IOException(java.io.IOException) Document(org.jdom2.Document) Test(org.junit.Test)

Example 15 with Text

use of org.omegat.filters3.Text in project mycore by MyCoRe-Org.

the class MCRXSL2XMLTransformer method getDocument.

private Document getDocument(JDOMResult result) {
    Document resultDoc = result.getDocument();
    if (resultDoc == null) {
        // Sometimes a transformation produces whitespace strings
        // JDOM would produce a empty document if it detects those
        // So we remove them, if they exists.
        List<Content> transformResult = result.getResult();
        int origSize = transformResult.size();
        Iterator<Content> iterator = transformResult.iterator();
        while (iterator.hasNext()) {
            Content content = iterator.next();
            if (content instanceof Text) {
                String trimmedText = ((Text) content).getTextTrim();
                if (trimmedText.length() == 0) {
                    iterator.remove();
                }
            }
        }
        if (transformResult.size() < origSize) {
            JDOMFactory f = result.getFactory();
            if (f == null) {
                f = new DefaultJDOMFactory();
            }
            resultDoc = f.document(null);
            resultDoc.setContent(transformResult);
        }
    }
    return resultDoc;
}
Also used : DefaultJDOMFactory(org.jdom2.DefaultJDOMFactory) MCRContent(org.mycore.common.content.MCRContent) Content(org.jdom2.Content) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) JDOMFactory(org.jdom2.JDOMFactory) DefaultJDOMFactory(org.jdom2.DefaultJDOMFactory) Text(org.jdom2.Text) Document(org.jdom2.Document)

Aggregations

Text (org.jdom2.Text)12 Element (org.jdom2.Element)8 Document (org.jdom2.Document)4 Test (org.junit.Test)4 Content (org.jdom2.Content)3 Element (org.omegat.filters3.Element)3 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 XMLOutputter (org.jdom2.output.XMLOutputter)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ProtectedPart (org.omegat.core.data.ProtectedPart)2 XMLContentBasedTag (org.omegat.filters3.xml.XMLContentBasedTag)2 BaseText (com.adobe.cq.wcm.core.components.it.seljup.util.components.text.BaseText)1 Text (com.adobe.cq.wcm.core.components.it.seljup.util.components.text.v1.Text)1 Text (com.adobe.cq.wcm.core.components.it.seljup.util.components.text.v2.Text)1 JsonElement (com.google.gson.JsonElement)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1