本文整理汇总了Java中org.jdom.Text类的典型用法代码示例。如果您正苦于以下问题:Java Text类的具体用法?Java Text怎么用?Java Text使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Text类属于org.jdom包,在下文中一共展示了Text类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateElement
import org.jdom.Text; //导入依赖的package包/类
/**
* Method updateElement.
*
* @param counter
* @param shouldExist
* @param name
* @param parent
* @return Element
*/
protected Element updateElement(Counter counter, Element parent, String name, boolean shouldExist)
{
Element element = parent.getChild(name, parent.getNamespace());
if (element != null && shouldExist) {
counter.increaseCount();
}
if (element == null && shouldExist) {
element = factory.element(name, parent.getNamespace());
insertAtPreferredLocation(parent, element, counter);
counter.increaseCount();
}
if (!shouldExist && element != null) {
int index = parent.indexOf(element);
if (index > 0) {
Content previous = parent.getContent(index - 1);
if (previous instanceof Text) {
Text txt = (Text)previous;
if (txt.getTextTrim().length() == 0) {
parent.removeContent(txt);
}
}
}
parent.removeContent(element);
}
return element;
}
示例2: updateElement
import org.jdom.Text; //导入依赖的package包/类
/**
* Method updateElement
*
* @param counter
* @param shouldExist
* @param name
* @param parent
*/
protected Element updateElement( Counter counter, Element parent, String name, boolean shouldExist )
{
Element element = parent.getChild( name, parent.getNamespace() );
if ( element != null && shouldExist )
{
counter.increaseCount();
}
if ( element == null && shouldExist )
{
element = factory.element( name, parent.getNamespace() );
insertAtPreferredLocation( parent, element, counter );
counter.increaseCount();
}
if ( !shouldExist && element != null )
{
int index = parent.indexOf( element );
if ( index > 0 )
{
Content previous = parent.getContent( index - 1 );
if ( previous instanceof Text )
{
Text txt = (Text) previous;
if ( txt.getTextTrim().length() == 0 )
{
parent.removeContent( txt );
}
}
}
parent.removeContent( element );
}
return element;
}
示例3: testCollectMacros
import org.jdom.Text; //导入依赖的package包/类
public void testCollectMacros() {
Element root = new Element("root");
root.addContent(new Text("$MACro1$ some text $macro2$ other text $MACRo3$"));
root.addContent(new Text("$macro4$ some text"));
root.addContent(new Text("some text$macro5$"));
root.addContent(new Text("file:$mac_ro6$"));
root.addContent(new Text("jar://$macr.o7$ "));
root.addContent(new Text("$mac-ro8$ "));
root.addContent(new Text("$$$ "));
root.addContent(new Text("$c:\\a\\b\\c$ "));
root.addContent(new Text("$Revision 1.23$"));
root.addContent(new Text("file://$root$/some/path/just$file$name.txt"));
final Set<String> macros = PathMacrosCollector.getMacroNames(root, null, new PathMacrosImpl());
UsefulTestCase.assertSameElements(macros, "MACro1", "macro4", "mac_ro6", "macr.o7", "mac-ro8", "root");
}
示例4: getTextValue
import org.jdom.Text; //导入依赖的package包/类
@NotNull
static String getTextValue(@NotNull Element element, @NotNull String defaultText) {
List<Content> content = element.getContent();
int size = content.size();
StringBuilder builder = null;
for (int i = 0; i < size; i++) {
Content child = content.get(i);
if (child instanceof Text) {
String value = child.getValue();
if (builder == null && i == (size - 1)) {
return value;
}
if (builder == null) {
builder = new StringBuilder();
}
builder.append(value);
}
}
return builder == null ? defaultText : builder.toString();
}
示例5: serializeItem
import org.jdom.Text; //导入依赖的package包/类
@Nullable
private Object serializeItem(@Nullable Object value, Object context, @NotNull SerializationFilter filter) {
if (value == null) {
LOG.warn("Collection " + myAccessor + " contains 'null' object");
return null;
}
Binding binding = XmlSerializerImpl.getBinding(value.getClass());
if (binding == null) {
Element serializedItem = new Element(annotation == null ? Constants.OPTION : annotation.elementTag());
String attributeName = annotation == null ? Constants.VALUE : annotation.elementValueAttribute();
String serialized = XmlSerializerImpl.convertToString(value);
if (attributeName.isEmpty()) {
if (!serialized.isEmpty()) {
serializedItem.addContent(new Text(serialized));
}
}
else {
serializedItem.setAttribute(attributeName, serialized);
}
return serializedItem;
}
else {
return binding.serialize(value, context, filter);
}
}
示例6: serialize
import org.jdom.Text; //导入依赖的package包/类
@Nullable
@Override
public Object serialize(@NotNull Object o, @Nullable Object context, @NotNull SerializationFilter filter) {
Object value = myAccessor.read(o);
Element serialized = new Element(myName);
if (value == null) {
return serialized;
}
if (myBinding == null) {
serialized.addContent(new Text(XmlSerializerImpl.convertToString(value)));
}
else {
Object node = myBinding.serialize(value, serialized, filter);
if (node != null && node != serialized) {
JDOMUtil.addContent(serialized, node);
}
}
return serialized;
}
示例7: testIsEmptyLine
import org.jdom.Text; //导入依赖的package包/类
@Test
public void testIsEmptyLine() {
assertEquals(false, textWrapperCreator.isBlankLineOrLines(new Text("\n sortpom\n ")));
assertEquals(false, textWrapperCreator.isBlankLineOrLines(new Text("sortpom")));
assertEquals(true, textWrapperCreator.isBlankLineOrLines(new Text("\n ")));
assertEquals(true, textWrapperCreator.isBlankLineOrLines(new Text(" \n ")));
assertEquals(true, textWrapperCreator.isBlankLineOrLines(new Text(" \n\n ")));
assertEquals(true, textWrapperCreator.isBlankLineOrLines(new Text("\n\n")));
assertEquals(true, textWrapperCreator.isBlankLineOrLines(new Text(" \r ")));
assertEquals(true, textWrapperCreator.isBlankLineOrLines(new Text(" \r\r ")));
assertEquals(true, textWrapperCreator.isBlankLineOrLines(new Text("\r\r")));
assertEquals(true, textWrapperCreator.isBlankLineOrLines(new Text(" \r\n ")));
assertEquals(true, textWrapperCreator.isBlankLineOrLines(new Text(" \r\n\r\n ")));
assertEquals(true, textWrapperCreator.isBlankLineOrLines(new Text("\r\n\r\n")));
assertEquals(false, textWrapperCreator.isBlankLineOrLines(new Text(" ")));
}
示例8: getHash
import org.jdom.Text; //导入依赖的package包/类
private static int getHash(int hash, Element element) {
hash = sumHash(hash, element.getName());
for (Object object : element.getAttributes()) {
Attribute attribute = (Attribute) object;
hash = sumHash(hash, attribute.getName());
hash = sumHash(hash, attribute.getValue());
}
for (Object o : element.getContent()) {
if (o instanceof Element) {
hash = getHash(hash, (Element) o);
} else if (o instanceof Text) {
String text = ((Text) o).getText();
if (!isNullOrWhitespace(text)) {
hash = sumHash(hash, text);
}
}
}
return hash;
}
示例9: getContentValue
import org.jdom.Text; //导入依赖的package包/类
/**
* Get the best content value for a JDOM object. For elements, the content text is returned.
* For attributes, the attribute value is returned. For namespaces, the URI is returned. Etc...
* @param jdomObject JDOM object such as Element, Attribute, Text, Namespace, Comment, ProcessingInstruction, String
* @return Content value for the specified JDOM object
* @since 4.2
*/
public static String getContentValue( Object jdomObject ) {
if(jdomObject == null) {
return null;
} else if(jdomObject instanceof String) {
return (String)jdomObject;
} else if(jdomObject instanceof Element) {
return ((Element)jdomObject).getText();
} else if(jdomObject instanceof Attribute) {
return ((Attribute)jdomObject).getValue();
} else if(jdomObject instanceof Text) {
return ((Text)jdomObject).getValue();
} else if(jdomObject instanceof Namespace) {
return ((Namespace)jdomObject).getURI();
} else if(jdomObject instanceof Comment) {
return ((Comment)jdomObject).getText();
} else if(jdomObject instanceof ProcessingInstruction) {
return ((ProcessingInstruction)jdomObject).getData();
}
// Default
return jdomObject.toString();
}
示例10: getXMLElement
import org.jdom.Text; //导入依赖的package包/类
@Override
public Element getXMLElement() {
Element result = new Element("localInvocation");
if ((directory != null) && !directory.isEmpty()){
Element directoryElement = new Element("directory");
directoryElement.addContent(new Text(directory));
result.addContent(directoryElement);
}
if ((shellPrefix != null) && !shellPrefix.isEmpty()) {
Element shellPrefixElement = new Element("shellPrefix");
shellPrefixElement.addContent(new Text(shellPrefix));
result.addContent(shellPrefixElement);
}
if ((linkCommand != null) && !linkCommand.isEmpty()) {
Element linkCommandElement = new Element("linkCommand");
linkCommandElement.addContent(new Text(linkCommand));
result.addContent(linkCommandElement);
}
if (isRetrieveData()) {
Element retrieveDataElement = new Element("retrieveData");
result.addContent(retrieveDataElement);
}
return result;
}
开发者ID:apache,项目名称:incubator-taverna-common-activities,代码行数:25,代码来源:ExternalToolLocalInvocationMechanism.java
示例11: createTreeNode
import org.jdom.Text; //导入依赖的package包/类
private XMLNode createTreeNode(Content content) {
XMLNode node = new XMLNode(content);
if (content instanceof Parent) {
Parent parent = (Parent) content;
for (Object child : parent.getContent()) {
if (child instanceof Element)
node.add(createTreeNode((Content) child));
else if (textSizeLimit != 0 && child instanceof Text) {
Text text = (Text) child;
if (!text.getTextNormalize().isEmpty())
node.add(createTreeNode(text));
}
}
}
return node;
}
示例12: getText
import org.jdom.Text; //导入依赖的package包/类
/**
* @param from
* Extract text recursively from this element and its children.
* @param insertNewlineBefore
* Insert newlines before these children.
* @return Concatenated text.
*/
private static String getText(Element from, List<String> insertNewlineBefore) {
StringBuilder sb = new StringBuilder();
for (Object child : from.getContent()) {
if (child instanceof Element) {
String childAsText = getText((Element) child, insertNewlineBefore).trim();
if (!childAsText.isEmpty()) {
if (insertNewlineBefore.contains(((Element) child).getName())) {
sb.append('\n');
} else {
sb.append(' ');
}
sb.append(childAsText);
}
} else if (child instanceof Text) {
String cont = ((Text) child).getText().trim();
if (!cont.isEmpty()) {
sb.append(' ');
sb.append(cont);
}
}
}
return sb.toString().trim();
}
示例13: testCollectMacros
import org.jdom.Text; //导入依赖的package包/类
public void testCollectMacros() {
Element root = new Element("root");
root.addContent(new Text("$MACro1$ some text $macro2$ other text $MACRo3$"));
root.addContent(new Text("$macro4$ some text"));
root.addContent(new Text("some text$macro5$"));
root.addContent(new Text("file:$mac_ro6$"));
root.addContent(new Text("jar://$macr.o7$ "));
root.addContent(new Text("$mac-ro8$ "));
root.addContent(new Text("$$$ "));
root.addContent(new Text("$c:\\a\\b\\c$ "));
root.addContent(new Text("$Revision 1.23$"));
final Set<String> macros = PathMacrosCollector.getMacroNames(root, null, new PathMacrosImpl());
assertEquals(5, macros.size());
assertTrue(macros.contains("MACro1"));
assertTrue(macros.contains("macro4"));
assertTrue(macros.contains("mac_ro6"));
assertTrue(macros.contains("macr.o7"));
assertTrue(macros.contains("mac-ro8"));
}
示例14: serialize
import org.jdom.Text; //导入依赖的package包/类
@Override
public Object serialize(Object o, Object context, SerializationFilter filter) {
Element targetElement = new Element(myTagName);
Object value = accessor.read(o);
if (!StringUtil.isEmpty(myNameAttribute)) {
targetElement.setAttribute(myNameAttribute, myName);
}
if (value == null) return targetElement;
Object node = myBinding.serialize(value, targetElement, filter);
if (node instanceof Text) {
Text text = (Text)node;
targetElement.setAttribute(myValueAttribute, text.getText());
}
else {
if (targetElement != node) {
JDOMUtil.addContent(targetElement, node);
}
}
return targetElement;
}
示例15: updateSecurityDomain
import org.jdom.Text; //导入依赖的package包/类
private static void updateSecurityDomain(ConfigContext context, boolean enable) {
List<Element> profiles = ConfigSupport.findProfileElements(context.getDocument(), NS_DOMAINS);
for (Element profile : profiles) {
Element security = profile.getChild("subsystem", NS_SECURITY);
if (security != null) {
Element domains = security.getChild("security-domains", NS_SECURITY);
ConfigSupport.assertExists(domains, "Did not find the <security-domains> element");
Element domain = ConfigSupport.findElementWithAttributeValue(domains, "security-domain", "name", "hawtio-domain", NS_SECURITY);
if (enable && domain == null) {
URL resource = WildFlyCamelConfigPlugin.class.getResource("/hawtio-security-domain.xml");
domains.addContent(new Text(" "));
domains.addContent(ConfigSupport.loadElementFrom(resource));
domains.addContent(new Text("\n "));
}
if (!enable && domain != null) {
domain.getParentElement().removeContent(domain);
}
}
}
}