Search in sources :

Example 6 with Text

use of org.geotoolkit.swe.xml.v101.Text in project wildfly-camel by wildfly-extras.

the class WildFlyCamelConfigPlugin method updateSystemProperties.

@SuppressWarnings("unchecked")
private static void updateSystemProperties(ConfigContext context, boolean enable) {
    Element rootElement = context.getDocument().getRootElement();
    Element extensions = ConfigSupport.findChildElement(rootElement, "extensions", NS_DOMAINS);
    ConfigSupport.assertExists(extensions, "Did not find the <extensions> element");
    Namespace namespace = extensions.getNamespace();
    Element element = ConfigSupport.findChildElement(rootElement, "system-properties", NS_DOMAINS);
    if (element == null) {
        element = new Element("system-properties", namespace);
        element.addContent(new Text("\n    "));
        int pos = rootElement.indexOf(extensions);
        rootElement.addContent(pos + 1, new Text("    "));
        rootElement.addContent(pos + 1, element);
        rootElement.addContent(pos + 1, new Text("\n    "));
    }
    Map<String, Element> propertiesByName = ConfigSupport.mapByAttributeName(element.getChildren(), "name");
    if (enable) {
        addProperty(element, propertiesByName, "hawtio.authenticationEnabled", "true");
        addProperty(element, propertiesByName, "hawtio.realm", "hawtio-domain");
        addProperty(element, propertiesByName, "org.apache.xml.dtm.DTMManager", "org.apache.xml.dtm.ref.DTMManagerDefault");
    } else {
        removeProperty(propertiesByName, "hawtio.authenticationEnabled");
        removeProperty(propertiesByName, "hawtio.realm");
    /* Do not remove org.apache.xml.dtm.DTMManager because we do not know whether it was added by us or by the
             * user. Leaving it there should be harmless or even beneficial for the perf of XPath.evaluate() */
    }
}
Also used : Element(org.jdom2.Element) Text(org.jdom2.Text) Namespace(org.jdom2.Namespace)

Example 7 with Text

use of org.geotoolkit.swe.xml.v101.Text in project CodenameOne by codenameone.

the class JDomUtils method rewriteValue.

/**
 * Updates the text value of the given element. The primary purpose of this method is to preserve any whitespace and
 * comments around the original text value.
 *
 * @param element The element to update, must not be <code>null</code>.
 * @param value   The text string to set, must not be <code>null</code>.
 */
public static void rewriteValue(Element element, String value) {
    Text text = null;
    if (element.getContent() != null) {
        for (Iterator<?> it = element.getContent().iterator(); it.hasNext(); ) {
            Object content = it.next();
            if ((content instanceof Text) && ((Text) content).getTextTrim().length() > 0) {
                text = (Text) content;
                while (it.hasNext()) {
                    content = it.next();
                    if (content instanceof Text) {
                        text.append((Text) content);
                        it.remove();
                    } else {
                        break;
                    }
                }
                break;
            }
        }
    }
    if (text == null) {
        element.addContent(value);
    } else {
        String chars = text.getText();
        String trimmed = text.getTextTrim();
        int idx = chars.indexOf(trimmed);
        String leadingWhitespace = chars.substring(0, idx);
        String trailingWhitespace = chars.substring(idx + trimmed.length());
        text.setText(leadingWhitespace + value + trailingWhitespace);
    }
}
Also used : Text(org.jdom2.Text)

Example 8 with Text

use of org.geotoolkit.swe.xml.v101.Text in project CodenameOne by codenameone.

the class JDomUtils method insertNewElement.

/**
 * Inserts a new child element to the given root element at the given index.
 * For details see {@link #insertNewElement(String, Element)}
 *
 * @param index the index where the element should be inserted.
 */
public static Element insertNewElement(String name, Element root, int index) {
    Element newElement;
    String indent = detectIndentation(root);
    newElement = new Element(name, root.getNamespace());
    newElement.addContent("\n" + indent);
    root.addContent(index, newElement);
    String prependingElementName = ((Element) root.getContent(max(0, index - 1))).getName();
    if (isBlankLineBetweenElements(prependingElementName, name, root)) {
        root.addContent(index, new Text("\n\n" + indent));
    } else {
        root.addContent(index, new Text("\n" + indent));
    }
    return newElement;
}
Also used : Element(org.jdom2.Element) Text(org.jdom2.Text)

Example 9 with Text

use of org.geotoolkit.swe.xml.v101.Text in project CodenameOne by codenameone.

the class JDomUtils method insertContentElement.

/**
 * Inserts an element with text, like &lt;version&gt;1.2.3&lt;/version&gt;
 */
public static void insertContentElement(Element jdomParent, String tag, String text) {
    if (text != null) {
        Element jdomVersion = insertNewElement(tag, jdomParent);
        jdomVersion.setContent(new Text(text));
    }
}
Also used : Element(org.jdom2.Element) Text(org.jdom2.Text)

Example 10 with Text

use of org.geotoolkit.swe.xml.v101.Text in project CodenameOne by codenameone.

the class JDomCleanupHelper method squashMultilines.

/**
 * Squash multiple consecutive newlines into a single newline.<br>
 * Indentations are preserved.
 *
 * @param rootElement the root element.
 */
public static void squashMultilines(Element rootElement) {
    // Compute groups of consecutive sibling content with only newlines (and whitespace)
    List<List<Text>> newLineGroups = new ArrayList<>();
    List<Text> currentGroup = new ArrayList<>();
    for (Content descendant : rootElement.getDescendants()) {
        if (JDomContentHelper.hasNewlines(descendant)) {
            if (!currentGroup.isEmpty()) {
                Element parent = currentGroup.get(0).getParent();
                if (!parent.equals(descendant.getParentElement())) {
                    newLineGroups.add(currentGroup);
                    currentGroup = new ArrayList<>();
                }
            }
            currentGroup.add((Text) descendant);
        } else {
            if (!currentGroup.isEmpty()) {
                newLineGroups.add(currentGroup);
                currentGroup = new ArrayList<>();
            }
        }
    }
    if (!currentGroup.isEmpty()) {
        newLineGroups.add(currentGroup);
    }
    // Delete all other predecessor elements in the group.
    for (List<Text> group : newLineGroups) {
        int newlineCount = 0;
        for (Text text : group) {
            newlineCount += StringUtils.countMatches(text.getText(), "\n");
        }
        if (newlineCount > 2) {
            Text last = group.get(group.size() - 1);
            last.setText("\n\n" + last.getText().replaceAll("\n", ""));
            group.remove(last);
            for (Text text : group) {
                text.getParentElement().removeContent(text);
                text.detach();
            }
        }
    }
}
Also used : Content(org.jdom2.Content) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Text(org.jdom2.Text)

Aggregations

Text (org.jdom2.Text)70 Element (org.jdom2.Element)57 Test (org.junit.Test)27 ErrorResponseBuilderMigrationStep (com.mulesoft.tools.migration.library.gateway.steps.policy.http.ErrorResponseBuilderMigrationStep)11 ResponseBuilderMigrationStep (com.mulesoft.tools.migration.library.gateway.steps.policy.http.ResponseBuilderMigrationStep)11 Content (org.jdom2.Content)7 ArrayList (java.util.ArrayList)5 Document (org.jdom2.Document)5 StringWriter (java.io.StringWriter)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 URL (java.net.URL)3 Map (java.util.Map)3 AnyScalarPropertyType (org.geotoolkit.swe.xml.v101.AnyScalarPropertyType)3 DataArrayType (org.geotoolkit.swe.xml.v101.DataArrayType)3 XMLOutputter (org.jdom2.output.XMLOutputter)3 BaseText (com.adobe.cq.wcm.core.components.it.seljup.util.components.text.BaseText)2 Text (com.adobe.cq.wcm.core.components.it.seljup.util.components.text.v1.Text)2 Text (com.adobe.cq.wcm.core.components.it.seljup.util.components.text.v2.Text)2 IString (io.usethesource.vallang.IString)2 IOException (java.io.IOException)2