org.jdom.Element.getTextTrim()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(537)

本文整理了Java中org.jdom.Element.getTextTrim()方法的一些代码示例,展示了Element.getTextTrim()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getTextTrim()方法的具体详情如下:
包路径:org.jdom.Element
类名称:Element
方法名:getTextTrim

Element.getTextTrim介绍

[英]Returns the textual content of this element with all surrounding whitespace removed. If no textual value exists for the element, or if only whitespace exists, the empty string is returned.
[中]返回此元素的文本内容,并删除所有周围的空白。如果元素不存在文本值,或者只有空格,则返回空字符串。

代码示例

代码示例来源:origin: org.freemarker/freemarker

public List operate(Object node) {
      if (node instanceof Element)
        return Collections.singletonList(((Element) node).getTextTrim());
      if (node instanceof Attribute)
        return Collections.singletonList(((Attribute) node).getValue());
      if (node instanceof CDATA)
        return Collections.singletonList(((CDATA) node).getText());
      if (node instanceof Comment)
        return Collections.singletonList(((Comment) node).getText());
      if (node instanceof ProcessingInstruction)
        return Collections.singletonList(((ProcessingInstruction) node).getData());
      // 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("_text can not be applied on " + node.getClass());
    }
  }

代码示例来源:origin: org.freemarker/freemarker

@Override
String getText(Object node) {
  if (node instanceof Element) {
    return ((Element) node).getTextTrim();
  }
  if (node instanceof Attribute) {
    return ((Attribute) node).getValue();
  }
  if (node instanceof CDATA) {
    return ((CDATA) node).getText();
  }
  if (node instanceof Comment) {
    return ((Comment) node).getText();
  }
  if (node instanceof ProcessingInstruction) {
    return ((ProcessingInstruction) node).getData();
  }
  return null;
}

代码示例来源:origin: banq/jdonframework

public static  Map loadMapping(String fileName, String nodeName, String keyName,
            String valueName) {
 Map map = new HashMap();
 FileLocator fileLocator = new FileLocator();
 try {
  String xmlFile = fileLocator.getConfFile(fileName);
  Debug.logVerbose("[JdonFramework] mapping file:" + xmlFile, module);
  SAXBuilder builder = new SAXBuilder();
  Document doc = builder.build(new File(xmlFile));
  Debug.logVerbose("[JdonFramework] got mapping file ", module);
  // Get the root element
  Element root = doc.getRootElement();
  List mappings = root.getChildren(nodeName);
  Iterator i = mappings.iterator();
  while (i.hasNext()) {
   Element mapping = (Element) i.next();
   String key = mapping.getChild(keyName).getTextTrim();
   String value = mapping.getChild(valueName).getTextTrim();
    Debug.logVerbose("[JdonFramework] get the " + key + "=" + value, module);
   map.put(key, value);
  }
  Debug.logVerbose("[JdonFramework] read finished", module);
 } catch (Exception ex) {
  Debug.logError("[JdonFramework] error: " + ex, module);
 }
 return map;
}

代码示例来源:origin: apache/oozie

public static String getDoneFlag(Element doneFlagElement) {
  if (doneFlagElement != null) {
    return doneFlagElement.getTextTrim();
  }
  else {
    return CoordELConstants.DEFAULT_DONE_FLAG;
  }
}

代码示例来源:origin: apache/oozie

/**
 * *f value is null, does nothing
 * If value is not null, sets actionConf value displayName to XML trimmed text value
 */
void trimAndSet(String displayName, Element value) {
  if (value != null) {
    actionConf.set(displayName, value.getTextTrim());
  }
}

代码示例来源:origin: org.codehaus.xfire/xfire-core

/**
 * @param elem
 * @return
 */
private String readDocumentations(Element elem) {
  Element documentation = elem.getChild(DOCUMENTATION_TAG);
  if (documentation == null) {
    return null;
  }
  return documentation.getTextTrim();
}

代码示例来源:origin: org.apache.oozie/oozie-core

/**
 * *f value is null, does nothing
 * If value is not null, sets actionConf value displayName to XML trimmed text value
 */
void trimAndSet(String displayName, Element value) {
  if (value != null) {
    actionConf.set(displayName, value.getTextTrim());
  }
}

代码示例来源:origin: apache/oozie

/**
 * Calls helper function to verify value not null and throw an exception if so.
 * Otherwise, set actionConf value displayName to XML trimmed text value
 */
void checkTrimAndSet(String displayName, Element value) {
  Preconditions.checkNotNull(value, "Action Configuration does not have [%s] property", displayName);
  actionConf.set(displayName, value.getTextTrim());
}

代码示例来源:origin: org.apache.oozie/oozie-core

/**
 * Calls helper function to verify value not null and throw an exception if so.
 * Otherwise, set actionConf value displayName to XML trimmed text value
 */
void checkTrimAndSet(String displayName, Element value) {
  Preconditions.checkNotNull(value, "Action Configuration does not have [%s] property", displayName);
  actionConf.set(displayName, value.getTextTrim());
}

代码示例来源:origin: uk.org.mygrid.taverna.processors/taverna-wsdl-processor

private List<String> extractBaseTypeArrayFromChildren(List<Element> children) {
  List<String> result = new ArrayList<String>();		
  for (Element child : children) {
    result.add(child.getTextTrim());
  }
  return result;
}

代码示例来源:origin: apache/oozie

private void injectConfigClass(Configuration conf, Element actionXml) {
  // Inject config-class for launcher to use for action
  Element e = actionXml.getChild("config-class", actionXml.getNamespace());
  if (e != null) {
    conf.set(LauncherAMUtils.OOZIE_ACTION_CONFIG_CLASS, e.getTextTrim());
  }
}

代码示例来源:origin: apache/oozie

private void setJavaMain(Configuration actionConf, Element actionXml) {
  Namespace ns = actionXml.getNamespace();
  Element e = actionXml.getChild("main-class", ns);
  if (e != null) {
    actionConf.set(JavaMain.JAVA_MAIN_CLASS, e.getTextTrim());
  }
}

代码示例来源:origin: locationtech/geowave

public static String getStringVal(final Element e, final boolean trim) {
 if (e == null) {
  return null;
 } else {
  if (trim) {
   return e.getTextTrim();
  } else {
   return e.getText();
  }
 }
}

代码示例来源:origin: locationtech/geowave

public static String getStringValIgnoreNamespace(
  final Element parentEl,
  final String childName,
  final Namespace[] namespaces,
  final boolean tryLowerCase) {
 final Element el = getChildIgnoreNamespace(parentEl, childName, namespaces, tryLowerCase);
 if (el != null) {
  return el.getTextTrim();
 } else {
  return null;
 }
}

代码示例来源:origin: cytoscape/application

private void removeMissingIdEntries() {
  List<Element> Plugins = trackerDoc.getRootElement().getChild(PluginStatus.CURRENT.getTagName()).getChildren(pluginTag);
  List<Element> PluginsToRemove = new ArrayList<Element>();
  
  for (Element plugin: Plugins) {
    if (plugin.getChild(uniqueIdTag) == null ||
      plugin.getChild(uniqueIdTag).getTextTrim().length() <= 0) 
      PluginsToRemove.add(plugin);
  }
  
  for (Element child: PluginsToRemove) 
    trackerDoc.getRootElement().getChild(PluginStatus.CURRENT.getTagName()).removeContent(child);
  
}

代码示例来源:origin: net.sf.taverna.t2.component/component-registry

public String getExternalPackItem(String packUri, String title)
    throws RegistryException {
  for (Element externalPackItem : getResourceElements(packUri,
      "external-pack-items")) {
    String itemTitle = externalPackItem.getTextTrim();
    if (title.equals(itemTitle))
      return externalPackItem.getAttributeValue("resource");
  }
  throw new RegistryException("Item " + title
      + " not found in external-pack-items at " + packUri);
}

代码示例来源:origin: net.sf.taverna.t2.component/component-activity

@Override
public synchronized String internalGetDescription() {
  MyExperimentComponentRegistry componentRegistry = (MyExperimentComponentRegistry) this
      .getComponentRegistry();
  String result = "";
  Element descriptionElement = componentRegistry.getResourceElement(uri,
      "description");
  if (descriptionElement != null) {
    result = descriptionElement.getTextTrim();
  }
  return result;
}

代码示例来源:origin: apache/oozie

public void testCoordEndOfWeeksStartingFromPrevWeek() throws Exception {
  List<?> elementList = getSyncDatasetEvents("coord-dataset-endOfWeeks.xml", "coord:endOfWeeks(-2)",
      "coord:current(0)", "2009-08-20T01:00Z", "2009-08-20T01:00Z");
  Element e2 = (Element) elementList.get(1);
  e2 = (Element) elementList.get(1);
  // startInstance = coord:endOfWeeks(-2)
  // endInstance = coord:current(0) i.e. 2009-08-20T01:00Z
  Calendar start = DateUtils.getCalendar("2009-08-10T01:00Z", DateUtils.UTC);
  start.add(Calendar.DAY_OF_WEEK, start.getFirstDayOfWeek() - start.get(Calendar.DAY_OF_WEEK));
  checkUris(e2.getChild("uris", e2.getNamespace()).getTextTrim(), start, Calendar.DATE, 1, "YYYY/MM/dd");
}

代码示例来源:origin: apache/oozie

public void testCoordEndOfMonthsStartingFromPrevMonth() throws Exception {
  List<?> elementList = getSyncDatasetEvents("coord-dataset-endOfMonths.xml", "coord:endOfMonths(-2)",
      "coord:current(0)", "2009-08-20T01:00Z", "2009-08-20T01:00Z");
  Element e2 = (Element) elementList.get(1);
  e2 = (Element) elementList.get(1);
  // startInstance = coord:endOfMonths(-2) i.e.2009-07-01T01:00Z and
  // endInstance = coord:current(0) i.e. 2009-08-20T01:00Z
  Calendar start = DateUtils.getCalendar("2009-07-01T01:00Z", DateUtils.UTC);
  checkUris(e2.getChild("uris", e2.getNamespace()).getTextTrim(), start, Calendar.DATE, 1, "YYYY/MM/dd");
}

代码示例来源:origin: apache/oozie

public void testCoordEndOfDaysStartingFromPrevDay() throws Exception {
  List<?> elementList = getSyncDatasetEvents("coord-dataset-endOfDays.xml", "coord:endOfDays(-2)",
      "coord:current(0)", "2009-08-20T18:00Z", "2009-08-20T18:00Z");
  Element e2 = (Element) elementList.get(1);
  // startInstance = coord:endOfDays(-2) i.e 2009-08-19T01:00Z and
  // endInstance = coord:current(0) i.e. 2009-08-20T01:00Z
  Calendar start = DateUtils.getCalendar("2009-08-19T00:00Z", DateUtils.UTC);
  checkUris(e2.getChild("uris", e2.getNamespace()).getTextTrim(), start, Calendar.MINUTE, 30,
      "YYYY/MM/dd/HH/mm");
}

相关文章

微信公众号

最新文章

更多