Refine search
public String getElementStringValue(Object obj) { Element elem = (Element) obj; StringBuffer buf = new StringBuffer(); List content = elem.getContent(); Iterator contentIter = content.iterator(); Object each = null; while ( contentIter.hasNext() ) { each = contentIter.next(); if ( each instanceof Text ) { buf.append( ((Text)each).getText() ); } else if ( each instanceof CDATA ) { buf.append( ((CDATA)each).getText() ); } else if ( each instanceof Element ) { buf.append( getElementStringValue( each ) ); } } return buf.toString(); }
private static final Element getParent(Object node) { if (node instanceof Element) return((Element) node).getParent(); else if (node instanceof Attribute) return((Attribute) node).getParent(); else if (node instanceof Text) return((Text) node).getParent(); else if (node instanceof ProcessingInstruction) return((ProcessingInstruction) node).getParent(); else if (node instanceof Comment) return((Comment) node).getParent(); else if (node instanceof EntityRef) return((EntityRef) node).getParent(); else // With 2.1 semantics it makes more sense to just return a null and let the core // throw an InvalidReferenceException and the template writer can use ?exists etcetera. (JR) return null; // throw new TemplateModelException("_parent can not be applied on " + node.getClass()); }
private static void updateExtension(ConfigContext context, boolean enable) { Element extensions = ConfigSupport.findChildElement(context.getDocument().getRootElement(), "extensions", NS_DOMAINS); ConfigSupport.assertExists(extensions, "Did not find the <extensions> element"); Namespace namespace = extensions.getNamespace(); Element element = ConfigSupport.findElementWithAttributeValue(extensions, "extension", "module", "org.wildfly.extension.camel", NS_DOMAINS); if (enable && element == null) { extensions.addContent(new Text(" ")); extensions.addContent(new Element("extension", namespace).setAttribute("module", "org.wildfly.extension.camel")); extensions.addContent(new Text("\n ")); } if (!enable && element != null) { element.getParentElement().removeContent(element); } }
Iterator it = parent.getContent().iterator(); Text lastText = null; int offset = 0; if (lastText != null && lastText.getTextTrim().length() == 0) { lastText = (Text)lastText.clone(); } else { String starter = lineSeparator; if (parent.getContentSize() == 0) { Text finalText = (Text)lastText.clone(); finalText.setText(finalText.getText().substring(0, finalText.getText().length() - " ".length())); parent.addContent(contentIndex, finalText); parent.addContent(contentIndex, child);
Element element = parent.getChild(name, parent.getNamespace()); if (element != null && shouldExist) { counter.increaseCount(); element = factory.element(name, parent.getNamespace()); insertAtPreferredLocation(parent, element, counter); counter.increaseCount(); if (previous instanceof Text) { Text txt = (Text)previous; if (txt.getTextTrim().length() == 0) { parent.removeContent(txt);
private static void addProperty(Element systemProperties, Map<String, Element> propertiesByName, String name, String value) { Namespace namespace = systemProperties.getNamespace(); if (!propertiesByName.containsKey(name)) { systemProperties.addContent(new Text(" ")); systemProperties.addContent(new Element("property", namespace).setAttribute("name", name).setAttribute("value", value)); systemProperties.addContent(new Text("\n ")); } }
private static void updateSubsystem(ConfigContext context, boolean enable) { List<Element> profiles = ConfigSupport.findProfileElements(context.getDocument(), NS_DOMAINS); for (Element profile : profiles) { Element element = profile.getChild("subsystem", NS_CAMEL); if (enable && element == null) { URL resource = WildFlyCamelConfigPlugin.class.getResource("/camel-subsystem.xml"); profile.addContent(new Text(" ")); profile.addContent(ConfigSupport.loadElementFrom(resource)); profile.addContent(new Text("\n ")); } if (!enable && element != null) { element.getParentElement().removeContent(element); } } }
private static org.jdom.Element cleanElement (final org.jdom.Element elt) { final org.jdom.Element result = new org.jdom.Element(elt.getName()); final java.util.Iterator it = elt.getContent().iterator(); while (it.hasNext()) { final org.jdom.Content c = (org.jdom.Content)it.next(); if (c instanceof org.jdom.Text) if (((org.jdom.Text)c).getTextTrim().length() < 1) continue; //log.debug("cleanElement() adding "+XmlUtils.xmlToString(c)); result.addContent((org.jdom.Content)c.clone()); } return result; }
public static Element getVersionElement() { Element lib = new Element("lib"); Element name = new Element("name"); Element ver = new Element("version"); name.addContent(new Text("java-opendap")); lib.addContent(name); ver.addContent(new Text(version)); lib.addContent(ver); return (lib); }
if (!"".equals(text.getTextNormalize())) Element para = new Element(Para.E_PARA); para.addContent(contents); if (index >= 0) parent.addContent(index, para);
String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { ((Text) node).setText(string); nodeParent(node).removeContent((Text) node); element.getContent().clear(); addContent(valueElement.getContent()); String string = ((Text) value).getText(); element.addContent(new Text(string)); String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { element.addContent(new Text(string));
} else { try { Element me = (Element) trip.xml.clone(); if (addSchema) { me.setAttribute("schemaLocation", schemaLocation, XSI_NS); Object what = ni.next(); if (what instanceof Element) { ((Element) what).setText(checkedString(value)); } else if (what instanceof Attribute) { ((Attribute) what).setValue(checkedString(value)); } else if (what instanceof Text) { ((Text) what).setText(checkedString(value)); } else { log.warn("Got unknown object from XPath, class=" + what.getClass().getName());
/** * This adds text content to this element. It does not replace the * existing content as does <code>setText()</code>. * * @param str <code>String</code> to add * @return this element modified * @throws IllegalDataException if <code>str</code> contains an * illegal character such as a vertical tab (as determined * by {@link org.jdom.Verifier#checkCharacterData}) */ public Element addContent(final String str) { return addContent(new Text(str)); }
if ( element.getContent() != null ) for ( Iterator<?> it = element.getContent().iterator(); it.hasNext(); ) if ( ( content instanceof Text ) && ( (Text) content ).getTextTrim().length() > 0 ) if ( content instanceof Text ) text.append( (Text) content ); it.remove(); element.addContent( value ); 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 );
Object child = content.get(i); if (child instanceof Element) { child = ((Element) child).clone(); element.addContent((Element) child); child = ((Text) child).clone(); element.addContent((Text) child);
String name = StringUtils.lowerCase(elem.getName()); List<Content> children = elem.getContent(); if (children != null && children.size() > 0) { for (Content child : children) { String normalized = text.getTextNormalize(); if (StringUtils.isNotBlank(normalized)) { boolean hasText = StringUtils.isNotBlank(normalized);
List<Content> childNodes = element.getContent(); Matcher m = pat.matcher(element.getText()); StringBuffer sb = new StringBuffer(); while (m.find()) element.setText(sb.toString());
/** * Turns a JDOM content instance into a String * (with the application encoding). */ public static String toString (final org.jdom.Content c) { if (c instanceof org.jdom.Text) return ((org.jdom.Text)c).getTextTrim(); org.jdom.Element elt = (org.jdom.Element)c; final boolean hasParent = (elt.getParent() != null); if (hasParent) elt = (org.jdom.Element)elt.clone(); final String result = toString(new org.jdom.Document(elt), null); if ( ! hasParent) elt.detach(); return result; }
/** * Returns the first piece of content that is not an empty (when trimmed) * Text instance. */ public static org.jdom.Content getFirstContent (final org.jdom.Element elt) { final java.util.Iterator it = elt.getContent().iterator(); while (it.hasNext()) { final org.jdom.Content c = (org.jdom.Content)it.next(); if (c instanceof org.jdom.Element) return c; if (c instanceof org.jdom.Text) { final String s = ((org.jdom.Text)c).getTextTrim(); if (s.length() > 0) return c; } // else continue } return null; }