Search in sources :

Example 1 with Text

use of org.omegat.filters3.Text in project jspwiki by apache.

the class CleanTextRenderer method getString.

/**
 *  {@inheritDoc}
 */
public String getString() throws IOException {
    StringBuilder sb = new StringBuilder();
    try {
        XPath xp = XPath.newInstance(ALL_TEXT_NODES);
        List nodes = xp.selectNodes(m_document.getDocument());
        for (Iterator i = nodes.iterator(); i.hasNext(); ) {
            Object el = i.next();
            if (el instanceof Text) {
                sb.append(((Text) el).getValue());
            }
        }
    } catch (JDOMException e) {
        log.error("Could not parse XPATH expression");
        throw new IOException(e.getMessage());
    }
    return sb.toString();
}
Also used : XPath(org.jdom2.xpath.XPath) Iterator(java.util.Iterator) List(java.util.List) Text(org.jdom2.Text) IOException(java.io.IOException) JDOMException(org.jdom2.JDOMException)

Example 2 with Text

use of org.omegat.filters3.Text in project jspwiki by apache.

the class CreoleRenderer method renderElement.

/**
 * Renders an element into the StringBuilder given
 * @param ce
 * @param sb
 */
private void renderElement(Element ce, StringBuilder sb) {
    String endEl = EMPTY_STRING;
    for (int i = 0; i < ELEMENTS.length; i += 3) {
        if (ELEMENTS[i].equals(ce.getName())) {
            sb.append(ELEMENTS[i + 1]);
            endEl = ELEMENTS[i + 2];
        }
    }
    if (UL.equals(ce.getName())) {
        m_listCount++;
        m_listChar = '*';
    } else if (OL.equals(ce.getName())) {
        m_listCount++;
        m_listChar = '#';
    } else if (LI.equals(ce.getName())) {
        for (int i = 0; i < m_listCount; i++) sb.append(m_listChar);
        sb.append(ONE_SPACE);
    } else if (A.equals(ce.getName())) {
        String href = ce.getAttributeValue(HREF_ATTRIBUTE);
        String text = ce.getText();
        if (href.equals(text)) {
            sb.append(HREF_START + href + HREF_END);
        } else {
            sb.append(HREF_START + href + HREF_DELIMITER + text + HREF_END);
        }
        // Do not render anything else
        return;
    } else if (PRE.equals(ce.getName())) {
        sb.append(PRE_START);
        sb.append(ce.getText());
        sb.append(PRE_END);
        return;
    }
    // 
    for (Iterator<Content> i = ce.getContent().iterator(); i.hasNext(); ) {
        Content c = i.next();
        if (c instanceof PluginContent) {
            PluginContent pc = (PluginContent) c;
            if (pc.getPluginName().equals(PLUGIN_IMAGE)) {
                sb.append(IMG_START + pc.getParameter(PARAM_SRC) + IMG_END);
            } else {
                m_plugins.add(pc);
                sb.append(PLUGIN_START + pc.getPluginName() + ONE_SPACE + m_plugins.size() + PLUGIN_END);
            }
        } else if (c instanceof Text) {
            sb.append(((Text) c).getText());
        } else if (c instanceof Element) {
            renderElement((Element) c, sb);
        }
    }
    if (UL.equals(ce.getName()) || OL.equals(ce.getName())) {
        m_listCount--;
    } else if (P.equals(ce.getName())) {
        sb.append(LINEBREAK);
    }
    sb.append(endEl);
}
Also used : PluginContent(org.apache.wiki.parser.PluginContent) Content(org.jdom2.Content) Element(org.jdom2.Element) Text(org.jdom2.Text) PluginContent(org.apache.wiki.parser.PluginContent)

Example 3 with Text

use of org.omegat.filters3.Text in project ldapchai by ldapchai.

the class ChaiResponseSet method challengeToXml.

private static Element challengeToXml(final Challenge loopChallenge, final Answer answer, final String elementName) throws ChaiOperationException {
    final Element responseElement = new Element(elementName);
    responseElement.addContent(new Element(XML_NODE_CHALLENGE).addContent(new Text(loopChallenge.getChallengeText())));
    final Element answerElement = answer.toXml();
    responseElement.addContent(answerElement);
    responseElement.setAttribute(XML_ATTRIBUTE_ADMIN_DEFINED, String.valueOf(loopChallenge.isAdminDefined()));
    responseElement.setAttribute(XML_ATTRIBUTE_REQUIRED, String.valueOf(loopChallenge.isRequired()));
    responseElement.setAttribute(XNL_ATTRIBUTE_MIN_LENGTH, String.valueOf(loopChallenge.getMinLength()));
    responseElement.setAttribute(XNL_ATTRIBUTE_MAX_LENGTH, String.valueOf(loopChallenge.getMaxLength()));
    return responseElement;
}
Also used : Element(org.jdom2.Element) Text(org.jdom2.Text)

Example 4 with Text

use of org.omegat.filters3.Text in project pwm by pwm-project.

the class StoredConfigurationImpl method writeConfigProperty.

@Override
public void writeConfigProperty(final ConfigurationProperty propertyName, final String value) {
    domModifyLock.writeLock().lock();
    try {
        final XPathExpression xp = XPathBuilder.xpathForConfigProperty(propertyName);
        final List<Element> propertyElements = xp.evaluate(document);
        for (final Element propertyElement : propertyElements) {
            propertyElement.detach();
        }
        final Element propertyElement = new Element(XML_ELEMENT_PROPERTY);
        propertyElement.setAttribute(new Attribute(XML_ATTRIBUTE_KEY, propertyName.getKey()));
        propertyElement.setContent(new Text(value));
        if (null == XPathBuilder.xpathForConfigProperties().evaluateFirst(document)) {
            final Element configProperties = new Element(XML_ELEMENT_PROPERTIES);
            configProperties.setAttribute(new Attribute(XML_ATTRIBUTE_TYPE, XML_ATTRIBUTE_VALUE_CONFIG));
            document.getRootElement().addContent(configProperties);
        }
        final XPathExpression xp2 = XPathBuilder.xpathForConfigProperties();
        final Element propertiesElement = (Element) xp2.evaluateFirst(document);
        propertyElement.setAttribute(XML_ATTRIBUTE_MODIFY_TIME, JavaHelper.toIsoDate(Instant.now()));
        propertiesElement.setAttribute(XML_ATTRIBUTE_MODIFY_TIME, JavaHelper.toIsoDate(Instant.now()));
        propertiesElement.addContent(propertyElement);
    } finally {
        domModifyLock.writeLock().unlock();
    }
}
Also used : XPathExpression(org.jdom2.xpath.XPathExpression) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Text(org.jdom2.Text)

Example 5 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.v2.Text) BeforeEach(org.junit.jupiter.api.BeforeEach)

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