org.dom4j.Node.selectObject()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(133)

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

Node.selectObject介绍

[英]selectObject evaluates an XPath expression and returns the result as an Object. The object returned can either be a List of one or more Nodeinstances or a scalar object like a Stringor a Numberinstance depending on the XPath expression.
[中]selectObject计算XPath表达式并将结果作为对象返回。返回的对象可以是一个或多个NodeInstance的列表,也可以是标量对象(如Strings)或Numberinstance,具体取决于XPath表达式。

代码示例

代码示例来源:origin: com.alibaba.citrus.tool/antx-autoexpand

/**
 * 根据XML Node创建message resource项.
 *
 * @param id           resource ID
 * @param resourceNode 代表resource信息的XML Node
 * @return resource的值
 * @throws ResourceBundleCreateException 解析错误
 */
protected Object getMessageResource(String id, Node resourceNode) throws ResourceBundleCreateException {
  return resourceNode.selectObject(ResourceBundleConstant.XPATH_RESOURCE_MESSAGE_DATA);
}

代码示例来源:origin: org.craftercms/crafter-core

/**
 * Executes an XPath query to retrieve an object. Normally, if the XPath result doesn't have a result, an
 * empty collection is returned. This object checks that case and returns null accordingly.
 */
public static Object selectObject(Node node, String xpathQuery) {
  Object result = node.selectObject(xpathQuery);
  if (result != null && result instanceof Collection && ((Collection) result).isEmpty()) {
    return null;
  } else {
    return result;
  }
}

代码示例来源:origin: com.atlassian.bamboo.plugins.dotnet/atlassian-bamboo-plugin-dotnet

private String processClasses(Document document) {
  StringBuffer buffer = new StringBuffer();
  List nodes = document.selectNodes("//class");
  for (Object o : nodes) {
    Node node = (Node) o;
    Node nameAttribute = (Node) node.selectObject("@name");
    log.debug("Processing class: " + nameAttribute.getStringValue());
    Double total = (Double) node.selectObject("count(./method/seqpnt)");
    Double visited = (Double) node.selectObject("count(./method/seqpnt[not(@vc=0 or @visitcount=0)])");
    buffer.append(nameAttribute.getStringValue()).append(',');
    buffer.append(visited / total).append(
        NCoverBuildProcessor.LINE_SEPARATOR);
  }
  return buffer.toString();
}

代码示例来源:origin: com.atlassian.bamboo.plugins.dotnet/atlassian-bamboo-plugin-dotnet

private Set<String> getProcessedClasses(Document document) {
  Set<String> classes = new HashSet<>();
  List nodes = document.selectNodes("//method");
  for (Object o : nodes) {
    Node node = (Node) o;
    Node nameAttribute = (Node) node.selectObject("@class");
    classes.add(nameAttribute.getStringValue());
  }
  return classes;
}

代码示例来源:origin: com.atlassian.plugins/atlassian-plugins-core

private void evaluate(Node ctxNode, List<String> errors) {
    Object obj = ctxNode.selectObject(xpath);
    if (obj == null) {
      errors.add(errorMessage + ": " + ctxNode.asXML());
    } else if (obj instanceof Boolean && !((Boolean) obj)) {
      errors.add(errorMessage + ": " + ctxNode.asXML());
    } else if (obj instanceof List && ((List<?>) obj).isEmpty()) {
      errors.add(errorMessage + ": " + ctxNode.asXML());
    }
  }
}

代码示例来源:origin: com.alibaba.citrus.tool/antx-autoexpand

/**
 * 根据XML Node初始化一个resource项.
 *
 * @param groupNode 代表resource信息的XML Node
 * @throws ResourceBundleCreateException 解析错误
 */
protected void initGroup(Node groupNode) throws ResourceBundleCreateException {
  String enumTypeName = (String) groupNode.selectObject(ResourceBundleConstant.XPATH_GROUP_ENUM);
  Class enumType = null;
  if (enumTypeName.length() > 0) {
    try {
      enumType = ContextClassLoader.loadClass(enumTypeName);
    } catch (ClassNotFoundException e) {
      throw new ResourceBundleCreateException(ResourceBundleConstant.RB_ENUM_CLASS_NOT_FOUND, new Object[] {
          enumTypeName, ContextClassLoader.getClassLoader() }, e);
    }
  }
  for (Iterator i = groupNode.selectNodes(ResourceBundleConstant.XPATH_RESOURCES).iterator(); i.hasNext(); ) {
    Node resourceNode = (Node) i.next();
    initResource(resourceNode, enumType);
  }
}

代码示例来源:origin: com.alibaba.citrus.tool/antx-autoexpand

/**
 * 根据XML Node创建map resource项.
 *
 * @param id           resource ID
 * @param resourceNode 代表resource信息的XML Node
 * @return resource的值
 * @throws ResourceBundleCreateException 解析错误
 */
protected Object getMapResource(String id, Node resourceNode) throws ResourceBundleCreateException {
  ListMap map = new ArrayHashMap();
  for (Iterator i = resourceNode.selectNodes(ResourceBundleConstant.XPATH_RESOURCES).iterator(); i.hasNext(); ) {
    Node mapItemNode = (Node) i.next();
    Object mapKey = mapItemNode.selectObject(ResourceBundleConstant.XPATH_RESOURCE_ID);
    if (map.containsKey(id)) {
      throw new ResourceBundleCreateException(ResourceBundleConstant.RB_DUPLICATED_MAP_RESOURCE_KEY,
                          new Object[] { mapKey, id }, null);
    }
    String mapItemType = mapItemNode.getName();
    Object value = null;
    if (ResourceBundleConstant.RB_RESOURCE_TYPE_MESSAGE.equals(mapItemType)) {
      value = getMessageResource(id, mapItemNode);
    } else if (ResourceBundleConstant.RB_RESOURCE_TYPE_MAP.equals(mapItemType)) {
      value = getMapResource(id, mapItemNode);
    } else if (ResourceBundleConstant.RB_RESOURCE_TYPE_LIST.equals(mapItemType)) {
      value = getListResource(id, mapItemNode);
    }
    map.put(mapKey, value);
  }
  return Collections.unmodifiableMap(map);
}

代码示例来源:origin: com.alibaba.citrus.tool/antx-autoexpand

String id = (String) resourceNode.selectObject(ResourceBundleConstant.XPATH_RESOURCE_ID);

相关文章