Java 类org.dom4j.ElementPath 实例源码

项目:nakala    文件:SaxExample.java   
@Override
public void onStart(ElementPath path) {
    Element el = path.getCurrent();
    String elName = el.getName();
    Term term;
    log.debug(path.getCurrent());
    if (elName.equals("rules")) {
        return;
    } else if (elName.equals("rule")) {
        Rule rule = new Rule(el.attributeValue("id"));
        fRules.add(rule);
        term = rule;
    } else if (elName.equals("and")) {
        term = new AndTerm();
    } else if (elName.equals("or")) {
        term = new OrTerm();
    } else if (elName.equals("not")) {
        term = new NotTerm();
    } else if (elName.equals("expression")) {
        term = new Expression(el.attributeValue("value").equals("true"));
    } else {
        throw new RuntimeException("XML validation should have caught this!");
        // throw an error
    }

    if (fTermStack.size() > 0) {
        Term parent = fTermStack.get(0);
        if (parent instanceof CompoundTerm) {
            ((CompoundTerm) parent).getTerms().add(term);
        } else if (parent instanceof NotTerm) {
            NotTerm not = (NotTerm) parent;
            if (not.getTerm() != null) {
                throw new RuntimeException("XML validation should have caught this!");
            }
            not.setTerm(term);
        }
    }
    fTermStack.add(0, term);
}
项目:orbeon-forms    文件:LocationSAXContentHandler.java   
public void startElement(String namespaceURI, String localName, String qualifiedName, Attributes attributes) throws SAXException {
    super.startElement(namespaceURI, localName, qualifiedName, attributes);
    final ElementPath path = getElementStack();
    path.getCurrent().setData(new LocationData(locator));
}
项目:nakala    文件:SaxExample.java   
@Override
public void onEnd(ElementPath path) {
    if (fTermStack.size() > 0)
        fTermStack.remove(0);
    log.debug(path.getCurrent().getText());
}