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() */
}
}
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);
}
}
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;
}
use of org.geotoolkit.swe.xml.v101.Text in project CodenameOne by codenameone.
the class JDomUtils method insertContentElement.
/**
* Inserts an element with text, like <version>1.2.3</version>
*/
public static void insertContentElement(Element jdomParent, String tag, String text) {
if (text != null) {
Element jdomVersion = insertNewElement(tag, jdomParent);
jdomVersion.setContent(new Text(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();
}
}
}
}
Aggregations