Search in sources :

Example 6 with Text

use of com.adobe.cq.wcm.core.components.it.seljup.util.components.text.v2.Text in project jspwiki by apache.

the class XHtmlElementToWikiTranslator method print.

private void print(Object element) throws IOException, JDOMException {
    if (element instanceof Text) {
        Text t = (Text) element;
        String s = t.getText();
        if (m_preStack.isPreMode()) {
            m_out.print(s);
        } else {
            // remove all "line terminator" characters
            s = s.replaceAll("[\\r\\n\\f\\u0085\\u2028\\u2029]", "");
            m_out.print(s);
        }
    } else if (element instanceof Element) {
        Element base = (Element) element;
        String n = base.getName().toLowerCase();
        if ("imageplugin".equals(base.getAttributeValue("class"))) {
            printImage(base);
        } else if ("wikiform".equals(base.getAttributeValue("class"))) {
            // only print the children if the div's class="wikiform", but not the div itself.
            printChildren(base);
        } else {
            boolean bold = false;
            boolean italic = false;
            boolean monospace = false;
            String cssSpecial = null;
            String cssClass = base.getAttributeValue("class");
            // accomodate a FCKeditor bug with Firefox: when a link is removed, it becomes <span class="wikipage">text</span>.
            boolean ignoredCssClass = cssClass != null && cssClass.matches("wikipage|createpage|external|interwiki|attachment");
            Map styleProps = null;
            // handled as an AugmentedWikiLink instead.
            if (!n.equals("a")) {
                styleProps = getStylePropertiesLowerCase(base);
            }
            if (styleProps != null) {
                String fontFamily = (String) styleProps.get("font-family");
                String whiteSpace = (String) styleProps.get("white-space");
                if (fontFamily != null && (fontFamily.indexOf("monospace") >= 0 && whiteSpace != null && whiteSpace.indexOf("pre") >= 0)) {
                    styleProps.remove("font-family");
                    styleProps.remove("white-space");
                    monospace = true;
                }
                String weight = (String) styleProps.remove("font-weight");
                String style = (String) styleProps.remove("font-style");
                if (n.equals("p")) {
                    // change it so we can print out the css styles for <p>
                    n = "div";
                }
                italic = "oblique".equals(style) || "italic".equals(style);
                bold = "bold".equals(weight) || "bolder".equals(weight);
                if (!styleProps.isEmpty()) {
                    cssSpecial = propsToStyleString(styleProps);
                }
            }
            if (cssClass != null && !ignoredCssClass) {
                if (n.equals("div")) {
                    m_out.print("\n%%" + cssClass + " \n");
                } else if (n.equals("span")) {
                    m_out.print("%%" + cssClass + " ");
                }
            }
            if (bold) {
                m_out.print("__");
            }
            if (italic) {
                m_out.print("''");
            }
            if (monospace) {
                m_out.print("{{{");
                m_preStack.push();
            }
            if (cssSpecial != null) {
                if (n.equals("div")) {
                    m_out.print("\n%%(" + cssSpecial + " )\n");
                } else {
                    m_out.print("%%(" + cssSpecial + " )");
                }
            }
            printChildren(base);
            if (cssSpecial != null) {
                if (n.equals("div")) {
                    m_out.print("\n/%\n");
                } else {
                    m_out.print("/%");
                }
            }
            if (monospace) {
                m_preStack.pop();
                m_out.print("}}}");
            }
            if (italic) {
                m_out.print("''");
            }
            if (bold) {
                m_out.print("__");
            }
            if (cssClass != null && !ignoredCssClass) {
                if (n.equals("div")) {
                    m_out.print("\n/%\n");
                } else if (n.equals("span")) {
                    m_out.print("/%");
                }
            }
        }
    }
}
Also used : Element(org.jdom2.Element) Text(org.jdom2.Text) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 7 with Text

use of com.adobe.cq.wcm.core.components.it.seljup.util.components.text.v2.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 8 with Text

use of com.adobe.cq.wcm.core.components.it.seljup.util.components.text.v2.Text in project omegat by omegat-org.

the class DefaultXMLDialect method constructShortcuts.

/**
 * {@inheritDoc}
 */
@Override
public String constructShortcuts(List<Element> elements, List<ProtectedPart> protectedParts) {
    protectedParts.clear();
    StringBuilder r = new StringBuilder();
    for (Element el : elements) {
        String shortcut = el.toShortcut();
        r.append(shortcut);
        if (!(el instanceof Text)) {
            ProtectedPart pp = new ProtectedPart();
            pp.setTextInSourceSegment(shortcut);
            pp.setDetailsFromSourceFile(el.toOriginal());
            if (StatisticsSettings.isCountingStandardTags()) {
                pp.setReplacementWordsCountCalculation(el.toSafeCalcShortcut());
            } else {
                pp.setReplacementWordsCountCalculation(StaticUtils.TAG_REPLACEMENT);
            }
            pp.setReplacementUniquenessCalculation(StaticUtils.TAG_REPLACEMENT);
            pp.setReplacementMatchCalculation(StaticUtils.TAG_REPLACEMENT);
            protectedParts.add(pp);
        }
    }
    return r.toString();
}
Also used : ProtectedPart(org.omegat.core.data.ProtectedPart) Element(org.omegat.filters3.Element) Text(org.omegat.filters3.Text)

Example 9 with Text

use of com.adobe.cq.wcm.core.components.it.seljup.util.components.text.v2.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 10 with Text

use of com.adobe.cq.wcm.core.components.it.seljup.util.components.text.v2.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)

Aggregations

Text (org.jdom2.Text)11 Element (org.jdom2.Element)7 Document (org.jdom2.Document)4 Content (org.jdom2.Content)3 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 XMLOutputter (org.jdom2.output.XMLOutputter)2 Test (org.junit.Test)2 BeforeEach (org.junit.jupiter.api.BeforeEach)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 List (java.util.List)1 Map (java.util.Map)1 PluginContent (org.apache.wiki.parser.PluginContent)1