Example usage for org.dom4j.xpath DefaultXPath selectNodes

List of usage examples for org.dom4j.xpath DefaultXPath selectNodes

Introduction

In this page you can find the example usage for org.dom4j.xpath DefaultXPath selectNodes.

Prototype

public List<Node> selectNodes(Object context) 

Source Link

Usage

From source file:com.surenpi.autotest.suite.parser.XmlSuiteParser.java

License:Apache License

/**
 * ?action/*from  www  .ja va 2  s.  c o m*/
 * @param actionList
 * @param actionsEle action
 * @param afterSleep action
 * @param beforeSleep action
 */
private void parse(List<SuiteAction> actionList, final Element actionsEle, String beforeSleep,
        String afterSleep) {
    DefaultXPath xpath = new DefaultXPath("ns:action");
    xpath.setNamespaceContext(simpleNamespaceContext);

    @SuppressWarnings("unchecked")
    List<Element> actionEleList = xpath.selectNodes(actionsEle);
    for (Element actionEle : actionEleList) {
        String field = actionEle.attributeValue("field");
        String name = actionEle.attributeValue("name", "click");
        String invoker = actionEle.attributeValue("invoker");
        String actionBeforeSleep = actionEle.attributeValue("beforeSleep", beforeSleep);
        String actionAfterSleep = actionEle.attributeValue("afterSleep", afterSleep);
        String repeat = actionEle.attributeValue("repeat", "1");
        String disable = actionEle.attributeValue("disable", "false");

        if (Boolean.parseBoolean(disable)) {
            continue;
        }

        SuiteAction suiteAction = new SuiteAction(field, name);
        suiteAction.setInvoker(invoker);
        suiteAction.setBeforeSleep(Long.parseLong(actionBeforeSleep));
        suiteAction.setAfterSleep(Long.parseLong(actionAfterSleep));
        suiteAction.setRepeat(Integer.parseInt(repeat));

        parseActionParam(actionEle, suiteAction);

        actionList.add(suiteAction);
    }
}

From source file:org.suren.autotest.web.framework.code.DefaultXmlCodeGenerator.java

License:Apache License

/**
 * @param document/*from   ww  w .ja v  a2s  .c  o m*/
 */
private void read(Document doc) {
    SimpleNamespaceContext simpleNamespaceContext = new SimpleNamespaceContext();
    simpleNamespaceContext.addNamespace("ns", "http://surenpi.com");

    DefaultXPath xpath = new DefaultXPath("/ns:autotest/ns:pages");
    xpath.setNamespaceContext(simpleNamespaceContext);
    Element pagesEle = (Element) xpath.selectSingleNode(doc);
    String pagePackage = pagesEle.attributeValue("pagePackage", "");
    if (StringUtils.isNotBlank(pagePackage)) {
        pagePackage = (pagePackage.trim() + ".");
    }

    // pages parse progress
    xpath = new DefaultXPath("/ns:autotest/ns:pages/ns:page");
    xpath.setNamespaceContext(simpleNamespaceContext);
    @SuppressWarnings("unchecked")
    List<Element> pageNodes = xpath.selectNodes(doc);
    if (pageNodes != null) {
        for (Element ele : pageNodes) {
            String pageClsStr = ele.attributeValue("class");
            if (pageClsStr == null) {
                logger.warn("can not found class attribute.");
                continue;
            }

            pageClsStr = (pagePackage + pageClsStr);
            Object commentObj = ele.getData();
            if (commentObj != null) {
                pageCommentMap.put(pageClsStr, commentObj.toString().trim());
            }

            try {
                List<AutoField> fieldList = new ArrayList<AutoField>();

                pageFieldMap.put(pageClsStr, fieldList);

                parsePage(pageClsStr, ele, fieldList);
            } catch (Exception e) {
                logger.error("page element parse error.", e);
            }
        }
    }
}