本文整理了Java中org.jdom.Text
类的一些代码示例,展示了Text
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Text
类的具体详情如下:
包路径:org.jdom.Text
类名称:Text
[英]Character-based XML content. Provides a modular, parentable method of representing text. Text makes no guarantees about the underlying textual representation of character data, but does expose that data as a Java String.
[中]基于字符的XML内容。提供了一种模块化的、可作为父对象的文本表示方法。文本不保证字符数据的底层文本表示,但确实将该数据作为Java字符串公开。
代码示例来源:origin: jaxen/jaxen
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();
}
代码示例来源:origin: org.freemarker/freemarker
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());
}
代码示例来源:origin: wildfly-extras/wildfly-camel
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);
}
}
代码示例来源:origin: org.codehaus.mevenide/nb-mvn-embedder
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);
代码示例来源:origin: org.codehaus.mevenide/nb-mvn-embedder
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);
代码示例来源:origin: org.wildfly.camel/wildfly-camel-config
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 "));
}
}
代码示例来源:origin: org.wildfly.camel/wildfly-camel-config
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);
}
}
}
代码示例来源:origin: org.openwfe/openwfe-engine
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;
}
代码示例来源:origin: edu.ucar/opendap
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);
}
代码示例来源:origin: org.dspace/dspace-xmlui-wing
if (!"".equals(text.getTextNormalize()))
Element para = new Element(Para.E_PARA);
para.addContent(contents);
if (index >= 0)
parent.addContent(index, para);
代码示例来源:origin: commons-jxpath/commons-jxpath
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));
代码示例来源:origin: DSpace/DSpace
} 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());
代码示例来源:origin: org.jdom/jdom-legacy
/**
* 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));
}
代码示例来源:origin: apache/maven-release
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 );
代码示例来源:origin: commons-jxpath/commons-jxpath
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);
代码示例来源:origin: javasoze/meaningfulweb
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);
代码示例来源:origin: org.openwfe/openwfe-engine
/**
* Returns the tag name of the given element (null if the parameter
* is not an element).
*/
public static Text xar (final Content c)
{
final Element elt = toElement(c);
return new Text(elt.getName());
}
代码示例来源:origin: org.codehaus.cargo/cargo-core-api-module
List<Content> childNodes = element.getContent();
Matcher m = pat.matcher(element.getText());
StringBuffer sb = new StringBuffer();
while (m.find())
element.setText(sb.toString());
代码示例来源:origin: org.openwfe/openwfe-applic
/**
* 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;
}
代码示例来源:origin: org.openwfe/openwfe-applic
/**
* 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;
}
内容来源于网络,如有侵权,请联系作者删除!