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

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

本文整理了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

  1. /**
  2. * 根据XML Node创建message resource项.
  3. *
  4. * @param id resource ID
  5. * @param resourceNode 代表resource信息的XML Node
  6. * @return resource的值
  7. * @throws ResourceBundleCreateException 解析错误
  8. */
  9. protected Object getMessageResource(String id, Node resourceNode) throws ResourceBundleCreateException {
  10. return resourceNode.selectObject(ResourceBundleConstant.XPATH_RESOURCE_MESSAGE_DATA);
  11. }

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

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

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

  1. private String processClasses(Document document) {
  2. StringBuffer buffer = new StringBuffer();
  3. List nodes = document.selectNodes("//class");
  4. for (Object o : nodes) {
  5. Node node = (Node) o;
  6. Node nameAttribute = (Node) node.selectObject("@name");
  7. log.debug("Processing class: " + nameAttribute.getStringValue());
  8. Double total = (Double) node.selectObject("count(./method/seqpnt)");
  9. Double visited = (Double) node.selectObject("count(./method/seqpnt[not(@vc=0 or @visitcount=0)])");
  10. buffer.append(nameAttribute.getStringValue()).append(',');
  11. buffer.append(visited / total).append(
  12. NCoverBuildProcessor.LINE_SEPARATOR);
  13. }
  14. return buffer.toString();
  15. }

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

  1. private Set<String> getProcessedClasses(Document document) {
  2. Set<String> classes = new HashSet<>();
  3. List nodes = document.selectNodes("//method");
  4. for (Object o : nodes) {
  5. Node node = (Node) o;
  6. Node nameAttribute = (Node) node.selectObject("@class");
  7. classes.add(nameAttribute.getStringValue());
  8. }
  9. return classes;
  10. }

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

  1. private void evaluate(Node ctxNode, List<String> errors) {
  2. Object obj = ctxNode.selectObject(xpath);
  3. if (obj == null) {
  4. errors.add(errorMessage + ": " + ctxNode.asXML());
  5. } else if (obj instanceof Boolean && !((Boolean) obj)) {
  6. errors.add(errorMessage + ": " + ctxNode.asXML());
  7. } else if (obj instanceof List && ((List<?>) obj).isEmpty()) {
  8. errors.add(errorMessage + ": " + ctxNode.asXML());
  9. }
  10. }
  11. }

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

  1. /**
  2. * 根据XML Node初始化一个resource项.
  3. *
  4. * @param groupNode 代表resource信息的XML Node
  5. * @throws ResourceBundleCreateException 解析错误
  6. */
  7. protected void initGroup(Node groupNode) throws ResourceBundleCreateException {
  8. String enumTypeName = (String) groupNode.selectObject(ResourceBundleConstant.XPATH_GROUP_ENUM);
  9. Class enumType = null;
  10. if (enumTypeName.length() > 0) {
  11. try {
  12. enumType = ContextClassLoader.loadClass(enumTypeName);
  13. } catch (ClassNotFoundException e) {
  14. throw new ResourceBundleCreateException(ResourceBundleConstant.RB_ENUM_CLASS_NOT_FOUND, new Object[] {
  15. enumTypeName, ContextClassLoader.getClassLoader() }, e);
  16. }
  17. }
  18. for (Iterator i = groupNode.selectNodes(ResourceBundleConstant.XPATH_RESOURCES).iterator(); i.hasNext(); ) {
  19. Node resourceNode = (Node) i.next();
  20. initResource(resourceNode, enumType);
  21. }
  22. }

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

  1. /**
  2. * 根据XML Node创建map resource项.
  3. *
  4. * @param id resource ID
  5. * @param resourceNode 代表resource信息的XML Node
  6. * @return resource的值
  7. * @throws ResourceBundleCreateException 解析错误
  8. */
  9. protected Object getMapResource(String id, Node resourceNode) throws ResourceBundleCreateException {
  10. ListMap map = new ArrayHashMap();
  11. for (Iterator i = resourceNode.selectNodes(ResourceBundleConstant.XPATH_RESOURCES).iterator(); i.hasNext(); ) {
  12. Node mapItemNode = (Node) i.next();
  13. Object mapKey = mapItemNode.selectObject(ResourceBundleConstant.XPATH_RESOURCE_ID);
  14. if (map.containsKey(id)) {
  15. throw new ResourceBundleCreateException(ResourceBundleConstant.RB_DUPLICATED_MAP_RESOURCE_KEY,
  16. new Object[] { mapKey, id }, null);
  17. }
  18. String mapItemType = mapItemNode.getName();
  19. Object value = null;
  20. if (ResourceBundleConstant.RB_RESOURCE_TYPE_MESSAGE.equals(mapItemType)) {
  21. value = getMessageResource(id, mapItemNode);
  22. } else if (ResourceBundleConstant.RB_RESOURCE_TYPE_MAP.equals(mapItemType)) {
  23. value = getMapResource(id, mapItemNode);
  24. } else if (ResourceBundleConstant.RB_RESOURCE_TYPE_LIST.equals(mapItemType)) {
  25. value = getListResource(id, mapItemNode);
  26. }
  27. map.put(mapKey, value);
  28. }
  29. return Collections.unmodifiableMap(map);
  30. }

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

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

相关文章