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

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

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

Element.getName介绍

[英]Returns the (local) name of the element (without any namespace prefix).
[中]返回元素的(本地)名称(不带任何命名空间前缀)。

代码示例

代码示例来源:origin: jaxen/jaxen

public String getElementName(Object obj)
{
  Element elem = (Element) obj;
  return elem.getName();
}

代码示例来源:origin: jaxen/jaxen

public String getElementQName(Object obj)
{
  Element elem = (Element) obj;
  String prefix = elem.getNamespacePrefix();
  if ( prefix == null || prefix.length() == 0 )
  {
    return elem.getName();
  }
  return prefix + ":" + elem.getName();
}

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

public List operate(Object node, String localName, Namespace namespace) {
      if (node instanceof Element) {
        return((Element) node).getChildren(localName, namespace);
      } else if (node instanceof Document) {
        Element root = ((Document) node).getRootElement();
        if (root != null &&
          root.getName().equals(localName) &&
          root.getNamespaceURI().equals(namespace.getURI())) {
          return Collections.singletonList(root);
        } else
          return Collections.EMPTY_LIST;
      } 
 // 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;
 /*           
      else
        throw new TemplateModelException("_namedChildren can not be applied on " + node.getClass());
*/                
    }
  }

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

public List operate(Object node) {
      if (node instanceof Element) {
        Element element = (Element) node;
        return Collections.singletonList(element.getNamespace().getURI() + element.getName());
      } else if (node instanceof Attribute) {
        Attribute attribute = (Attribute) node;
        return Collections.singletonList(attribute.getNamespace().getURI() + attribute.getName());
      }
      // 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("_cname can not be applied on " + node.getClass());
    }
  }

代码示例来源:origin: kiegroup/optaplanner

protected void assertElementName(Element element, String name) {
  if (!element.getName().equals(name)) {
    throw new IllegalStateException("Element name (" + element.getName()
        + ") should be " + name + ".");
  }
}

代码示例来源:origin: jaxen/jaxen

if (el.getName().equals(localName) == false) {
  return JaxenConstants.EMPTY_ITERATOR;

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

@Override
void getChildren(Object node, String localName, String namespaceUri, List result) {
  if (node instanceof Element) {
    Element e = (Element) node;
    if (localName == null) {
      result.addAll(e.getChildren());
    } else {
      result.addAll(e.getChildren(localName, Namespace.getNamespace("", namespaceUri)));
    }
  } else if (node instanceof Document) {
    Element root = ((Document) node).getRootElement();
    if (localName == null || (equal(root.getName(), localName) && equal(root.getNamespaceURI(), namespaceUri))) {
      result.add(root);
    }
  }
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

public String peekNextChild() {
  List list = currentElement.getChildren();
  if (null == list || list.isEmpty()) {
    return null;
  }
  return decodeNode(((Element) list.get(0)).getName());
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

public String getNodeName() {
  return decodeNode(currentElement.getName());
}

代码示例来源:origin: jaxen/jaxen

public String toString()
  {
    return ( "[xmlns:" + jdomNamespace.getPrefix() + "=\"" +
         jdomNamespace.getURI() + "\", element=" +
         jdomElement.getName() + "]" );
  }
}

代码示例来源:origin: voldemort/voldemort

public List<StoreDefinition> readStoreList(Reader input, boolean verifySchema) {
  try {
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(input);
    if(verifySchema) {
      Validator validator = schema.newValidator();
      validator.validate(new JDOMSource(doc));
    }
    Element root = doc.getRootElement();
    if(!root.getName().equals(STORES_ELMT))
      throw new MappingException("Invalid root element: "
                    + doc.getRootElement().getName());
    List<StoreDefinition> stores = new ArrayList<StoreDefinition>();
    for(Object store: root.getChildren(STORE_ELMT))
      stores.add(readStore((Element) store));
    for(Object view: root.getChildren(VIEW_ELMT))
      stores.add(readView((Element) view, stores));
    return stores;
  } catch(JDOMException e) {
    throw new MappingException(e);
  } catch(SAXException e) {
    throw new MappingException(e);
  } catch(IOException e) {
    throw new MappingException(e);
  }
}

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

public List operate(Object node) {
      if (node instanceof Element)
        return Collections.singletonList(((Element) node).getName());
      else if (node instanceof Attribute)
        return Collections.singletonList(((Attribute) node).getName());
      else if (node instanceof EntityRef)
        return Collections.singletonList(((EntityRef) node).getName());
      else if (node instanceof ProcessingInstruction)
        return Collections.singletonList(((ProcessingInstruction) node).getTarget());
      else if (node instanceof DocType)
        return Collections.singletonList(((DocType) node).getPublicID());
      else
        return null;
      // 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)
//                throw new TemplateModelException("_name can not be applied on " + node.getClass());
    }
  }

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

public Object exec(List arguments) {
    Set names = new HashSet(arguments);
    List list = new LinkedList(nodes);
    Iterator it = list.iterator();
    while (it.hasNext()) {
      Object node = it.next();
      String name = null;
      if (node instanceof Element)
        name = ((Element) node).getName();
      else if (node instanceof Attribute)
        name = ((Attribute) node).getName();
      else if (node instanceof ProcessingInstruction)
        name = ((ProcessingInstruction) node).getTarget();
      else if (node instanceof EntityRef)
        name = ((EntityRef) node).getName();
      else if (node instanceof DocType)
        name = ((DocType) node).getPublicID();
      if (name == null || !names.contains(name))
        it.remove();
    }
    return createNodeListModel(list, namespaces);
  }
}

代码示例来源:origin: voldemort/voldemort

@SuppressWarnings("unchecked")
public Cluster readCluster(Reader input, boolean verifySchema) {
  try {
    SAXBuilder builder = new SAXBuilder(false);
    Document doc = builder.build(input);
    if(verifySchema) {
      Validator validator = this.schema.newValidator();
      validator.validate(new JDOMSource(doc));
    }
    Element root = doc.getRootElement();
    if(!root.getName().equals(CLUSTER_ELMT))
      throw new MappingException("Invalid root element: "
                    + doc.getRootElement().getName());
    String name = root.getChildText(CLUSTER_NAME_ELMT);
    List<Zone> zones = new ArrayList<Zone>();
    for(Element node: (List<Element>) root.getChildren(ZONE_ELMT))
      zones.add(readZone(node));
    List<Node> servers = new ArrayList<Node>();
    for(Element node: (List<Element>) root.getChildren(SERVER_ELMT))
      servers.add(readServer(node));
    return new Cluster(name, servers, zones);
  } catch(JDOMException e) {
    throw new MappingException(e);
  } catch(SAXException e) {
    throw new MappingException(e);
  } catch(IOException e) {
    throw new MappingException(e);
  }
}

代码示例来源:origin: hsz/idea-gitignore

/**
 * Loads {@link UserTemplate} objects from the {@link Element}.
 *
 * @param element source
 * @return {@link UserTemplate} list
 */
@NotNull
public static List<UserTemplate> loadTemplates(@NotNull Element element) {
  final String key = KEY.USER_TEMPLATES.toString();
  final List<UserTemplate> list = ContainerUtil.newArrayList();
  if (!key.equals(element.getName())) {
    element = element.getChild(key);
  }
  for (Element template : element.getChildren()) {
    list.add(new UserTemplate(
        template.getAttributeValue(KEY.USER_TEMPLATES_NAME.toString()),
        template.getText()
    ));
  }
  return list;
}

代码示例来源:origin: kiegroup/optaplanner

private void readRequiredEmployeeSizes(NurseRoster nurseRoster, Element coverRequirementsElement) {
  List<Element> coverRequirementElementList = (List<Element>) coverRequirementsElement.getChildren();
  for (Element element : coverRequirementElementList) {
    if (element.getName().equals("DayOfWeekCover")) {
      Element dayOfWeekElement = element.getChild("Day");
      DayOfWeek dayOfWeek = null;
    } else if (element.getName().equals("DateSpecificCover")) {
      Element dateElement = element.getChild("Date");
      List<Element> coverElementList = (List<Element>) element.getChildren("Cover");
      throw new IllegalArgumentException("Unknown cover entity (" + element.getName() + ").");

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

@Override
String getLocalName(Object node) {
  if (node instanceof Element) {
    return ((Element) node).getName();
  }
  if (node instanceof Attribute) {
    return ((Attribute) node).getName();
  }
  if (node instanceof EntityRef) {
    return ((EntityRef) node).getName();
  }
  if (node instanceof ProcessingInstruction) {
    return ((ProcessingInstruction) node).getTarget();
  }
  if (node instanceof DocType) {
    return ((DocType) node).getElementName();
  }
  return null;
}

代码示例来源:origin: jshiell/checkstyle-idea

private void extractPropertyNames(final Element element, final List<String> propertyNames) {
  if (!"property".equals(element.getName())) {
    return;
  }
  final String value = element.getAttributeValue("value");
  if (value == null) {
    return;
  }
  final int propertyStart = value.indexOf("${");
  final int propertyEnd = value.indexOf('}');
  if (propertyStart >= 0 && propertyEnd >= 0) {
    final String propertyName = value.substring(
        propertyStart + 2, propertyEnd);
    propertyNames.add(propertyName);
  }
}

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

String[] childrenNames = new String[childCount];
for (int i = 0; i < childCount; i++) {
  childrenNames[i] = ((Element) children.get(i)).getName();

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

private void checkActionNode(NodeDef node) throws WorkflowException {
  try {
    Element action = XmlUtils.parseXml(node.getConf());
    ActionService actionService = Services.get().get(ActionService.class);
    boolean supportedAction = actionService.hasActionType(action.getName());
    if (!supportedAction) {
      throw new WorkflowException(ErrorCode.E0723, node.getName(), action.getName());
    }
  } catch (JDOMException ex) {
    throw new WorkflowException(ErrorCode.E0700, "JDOMException: " + ex.getMessage());
  }
}

相关文章

微信公众号

最新文章

更多