Example usage for org.dom4j Element getText

List of usage examples for org.dom4j Element getText

Introduction

In this page you can find the example usage for org.dom4j Element getText.

Prototype

String getText();

Source Link

Document

Returns the text value of this element without recursing through child elements.

Usage

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

private boolean agentHasResource(Element agent, String resourceText) {
    List<Element> resources = agent.selectNodes("resources/resource");
    for (Element resource : resources) {
        if (resource.getText().equals(resourceText)) {
            return true;
        }/*from   www.j  a v  a 2s . c o m*/
    }
    return false;
}

From source file:com.topsec.tsm.sim.sysconfig.web.SystemConfigController.java

@RequestMapping("/superiorConfigRegist")
@ResponseBody//from w  ww  .j a va 2 s.com
public Object superiorConfigRegist(SID sid, HttpServletRequest request) throws Exception {
    Result result = new Result(true, "??");
    String operator = request.getParameter("operator");
    String registIp = request.getParameter("registIp");
    String registName = request.getParameter("registName");
    String param = "";
    if (registIp.equals(IpAddress.getLocalIp().toString())) {
        result = new Result(false, "???");
        return result;
    }
    if (StringUtils.containsAny(registName, "<>'*?:/|\"\\")) {
        return result.buildError("?????");
    }
    Node parentNode = nodeMgrFacade.getParentNode();
    Node KernelNode = nodeMgrFacade.getKernelAuditor(false);
    try {
        if ("regist".equals(operator)) {
            if (parentNode != null) {
                return result.buildError("??");
            } else {
                //??
                param = "<Register>" + "<Ip>" + IpAddress.getLocalIp() + "</Ip>" + //?IP
                        "<Alias>" + registName + "</Alias>" + "<NodeId>" + KernelNode.getNodeId() + "</NodeId>"
                        + "<Type>register</Type>" + "</Register>";
            }
        } else if ("delete".equals(operator)) {
            if (parentNode == null) {
                return result.buildError("??");
            }
            param = "<Register>" + "<Ip>" + IpAddress.getLocalIp() + "</Ip>" + "<Type>delete</Type>"
                    + "</Register>";
        } else if ("update".equals(operator)) {
            if (parentNode == null) {
                return result.buildError("??");
            }
            try {
                nodeMgrFacade.delNode(parentNode);
                param = "<Register>" + "<Ip>" + IpAddress.getLocalIp() + "</Ip>" + "<Type>delete</Type>"
                        + "</Register>";
                String url = "https://" + parentNode.getIp() + "/resteasy/node/register";
                Map<String, String> cookies = new HashMap<String, String>();
                cookies.put("sessionid", RestUtil.getSessionId(registIp));
                String returnInfo = HttpUtil.doPostWithSSLByString(url, param, cookies, "UTF-8");
                if (StringUtils.isNotBlank(returnInfo)) {
                    log.info("?IP:" + parentNode.getIp());
                }
            } catch (ConnectException e) {
                log.warn("{}????", parentNode.getIp());
            }

            //?
            //            registNode(registIp, registName,KernelNode);
            param = "<Register>" + "<Ip>" + IpAddress.getLocalIp() + "</Ip>" + //?IP
                    "<Alias>" + registName + "</Alias>" + "<NodeId>" + KernelNode.getNodeId() + "</NodeId>"
                    + "<Type>register</Type>" + "</Register>";
        }
        String url = "https://" + registIp + "/resteasy/node/register";
        Map<String, String> cookies = new HashMap<String, String>();
        cookies.put("sessionid", RestUtil.getSessionId(registIp));
        String returnInfo = HttpUtil.doPostWithSSLByString(url, param, cookies, "UTF-8");
        if (StringUtils.isNotBlank(returnInfo)) {
            Document document = DocumentHelper.parseText(returnInfo);
            Element root = document.getRootElement();
            String successResponse = root.attribute("success").getValue();
            if ("false".equals(successResponse)) {
                Element elementMessage = root.element("Message");
                result.buildError(elementMessage.getText());
                return result;
            }
            if ("regist".equals(operator)) {
                //
                registNode(registIp, registName, KernelNode);
                log.info("?IP:" + registIp);
                result = new Result(true, "?");
                result.setResult(KernelNode.getResourceId());
            } else if ("update".equals(operator)) {
                registNode(registIp, registName, KernelNode);
                log.info("??IP:" + registIp);
                result = new Result(true, "??");
                result.setResult(KernelNode.getResourceId());
            } else {
                //
                nodeMgrFacade.delNode(parentNode);
                log.info("?IP:" + parentNode.getIp());
                result = new Result(true, "?");
            }
        } else {
            result.buildError("?");
        }
    } catch (Exception e) {
        e.printStackTrace();
        result.buildError("?");
    }
    return result;
}

From source file:com.vmware.o11n.plugin.powershell.remote.impl.winrm.ClientState.java

License:Open Source License

private String handleStream(Document responseDocument, ResponseExtractor stream) {
    StringBuffer buffer = new StringBuffer();
    @SuppressWarnings("unchecked")
    final List<Element> streams = (List<Element>) stream.getXPath().selectNodes(responseDocument);
    if (!streams.isEmpty()) {
        final Base64 base64 = new Base64();
        Iterator<Element> itStreams = streams.iterator();
        while (itStreams.hasNext()) {
            Element e = itStreams.next();
            //TODO check performance with http://www.iharder.net/current/java/base64/
            final byte[] decode = base64.decode(e.getText().getBytes());
            buffer.append(new String(decode));
        }/* w w w .j  a v a 2  s  .  c om*/
    }
    log.debug("handleStream {} buffer {}", stream, buffer);
    return buffer.toString();

}

From source file:com.vmware.o11n.plugin.powershell.remote.impl.winrm.ClientState.java

License:Open Source License

private String getFirstElement(Document doc, ResponseExtractor extractor) {
    @SuppressWarnings("unchecked")
    final List<Element> nodes = (List<Element>) extractor.getXPath().selectNodes(doc);
    if (nodes.isEmpty())
        throw new RuntimeException("Cannot find " + extractor.getXPath() + " in " + toString(doc));

    final Element next = (Element) nodes.iterator().next();
    return next.getText();
}

From source file:com.voa.weixin.handler.HandlerManager.java

License:Open Source License

private void init() {
    chains = new HashMap<String, List<String>>();

    chains.put(MessageType.HANDLER_TYPE_TEXT, new ArrayList<String>());
    chains.put(MessageType.HANDLER_TYPE_IMAGE, new ArrayList<String>());
    chains.put(MessageType.HANDLER_TYPE_VOICE, new ArrayList<String>());
    chains.put(MessageType.HANDLER_TYPE_VIDEO, new ArrayList<String>());
    chains.put(MessageType.HANDLER_TYPE_LOCATION, new ArrayList<String>());
    chains.put(MessageType.HANDLER_TYPE_LINK, new ArrayList<String>());

    chains.put(MessageType.HANDLER_EVENT_SUBSCRIBE, new ArrayList<String>());
    chains.put(MessageType.HANDLER_EVENT_SUBSCRIBE_QRSCENE, new ArrayList<String>());
    chains.put(MessageType.HANDLER_EVENT_UNSUBSCRIBE, new ArrayList<String>());
    chains.put(MessageType.HANDLER_EVENT_SCAN, new ArrayList<String>());
    chains.put(MessageType.HANDLER_EVENT_LOCATION, new ArrayList<String>());
    chains.put(MessageType.HANDLER_EVENT_CLICK, new ArrayList<String>());

    Document doc = null;// w w  w  . jav  a 2 s  .co  m
    try {
        doc = WeixinUtils.getDocumentResource("weixin.handler.xml");
    } catch (Exception e) {
        logger.error("weixin.handler.xml parser error");
        e.printStackTrace();
        return;
    }

    Element root = doc.getRootElement();
    logger.debug(root.asXML());
    List<Element> handlerEs = root.elements();
    for (Element handlerE : handlerEs) {
        String handlerName = handlerE.elementText("name");
        logger.debug("handlerName : " + handlerName);
        List<Element> handlerClzEs = handlerE.elements("handlerclz");
        if (handlerClzEs == null || handlerClzEs.size() == 0)
            continue;

        List<String> handlerClzNames = chains.get(handlerName);
        logger.debug("handlerClzNames:" + handlerClzNames);
        if (handlerClzNames == null)
            continue;
        for (Element handlerClzE : handlerClzEs) {
            String clzName = handlerClzE.getText();
            try {
                Class.forName(clzName);
                handlerClzNames.add(clzName);
            } catch (ClassNotFoundException e) {
                logger.error(clzName + " class not fount exception");
                e.printStackTrace();
            }
        }
    }

}

From source file:com.wabacus.config.ConfigLoadManager.java

License:Open Source License

private static void encryptDatasourcePassword() {
    if (DesEncryptTools.KEY_OBJ == null) {
        return;/*from  w  w  w. j  a  va  2 s . c  o  m*/
    }
    Document doc = XmlAssistant.getInstance().loadXmlDocument("wabacus.cfg.xml");
    String xpath = XmlAssistant.getInstance()
            .addNamespaceToXpath("//datasources/datasource/property[@name='password']");
    List lstPasswords = doc.selectNodes(xpath);
    if (lstPasswords == null || lstPasswords.size() == 0)
        return;
    Element elePasswordTmp;
    String passwordTmp;
    boolean hasEncrypted = false;
    for (int i = 0; i < lstPasswords.size(); i++) {
        elePasswordTmp = (Element) lstPasswords.get(i);
        passwordTmp = elePasswordTmp.getText();
        passwordTmp = passwordTmp == null ? "" : passwordTmp.trim();
        if (passwordTmp.equals(""))
            continue;
        if (passwordTmp.startsWith("{3DES}")) {
            if (DesEncryptTools.IS_NEWKEY) {
                throw new WabacusConfigLoadingException(
                        "??wabacus.cfg.xml????");
            }
        } else {
            hasEncrypted = true;
            passwordTmp = DesEncryptTools.encrypt(passwordTmp);//
            elePasswordTmp.setText("{3DES}" + passwordTmp);
        }
    }
    if (hasEncrypted) {
        try {
            XmlAssistant.getInstance().saveDocumentToXmlFile("wabacus.cfg.xml", doc);
        } catch (IOException e) {
            log.warn("wabacus.cfg.xml????", e);
        }
    }
}

From source file:com.wabacus.config.database.datasource.C3P0DataSource.java

License:Open Source License

public void loadConfig(Element eleDataSource) {
    super.loadConfig(eleDataSource);
    List lstEleProperties = eleDataSource.elements("property");
    if (lstEleProperties == null || lstEleProperties.size() == 0) {
        throw new WabacusConfigLoadingException(
                "??" + this.getName() + "?alias?configfile?");
    }//from  w  w  w.  j av a 2 s  .c o m
    String driver = null;
    String url = null;
    String user = null;
    String password = null;

    int minPoolSize = 1;
    int maxPoolSize = 100;
    int maxIdleTime = 0;
    int maxStatements = 0;
    int acquireIncrement = 1;
    int idleTestPeriod = 0;
    Element eleChild;
    String name;
    String value;
    for (int i = 0; i < lstEleProperties.size(); i++) {
        eleChild = (Element) lstEleProperties.get(i);
        name = eleChild.attributeValue("name");
        value = eleChild.getText();
        name = name == null ? "" : name.trim();
        value = value == null ? "" : value.trim();
        if (value.equals("")) {
            continue;
        }
        if (name.equals("max_size")) {
            maxPoolSize = Integer.parseInt(value);
        } else if (name.equals("min_size")) {
            minPoolSize = Integer.parseInt(value);
        } else if (name.equals("timeout")) {
            maxIdleTime = Integer.parseInt(value);
        } else if (name.equals("max_statements")) {
            maxStatements = Integer.parseInt(value);
        } else if (name.equals("idle_test_period")) {
            idleTestPeriod = Integer.parseInt(value);
        } else if (name.equals("acquire_increment")) {
            acquireIncrement = Integer.parseInt(value);
        } else if (name.equals("driver")) {
            driver = value;
        } else if (name.equals("url")) {
            url = value;
        } else if (name.equals("user")) {
            user = value;
        } else if (name.equals("password")) {
            password = value;
        }
    }
    if (driver.equals("") || url.equals("") || user.equals("")) {
        throw new WabacusConfigLoadingException("??" + this.getName()
                + "????driverurluser?");
    }
    PoolConfig pcfg = new PoolConfig();
    pcfg.setInitialPoolSize(minPoolSize);
    pcfg.setMinPoolSize(minPoolSize);
    pcfg.setMaxPoolSize(maxPoolSize);
    pcfg.setAcquireIncrement(acquireIncrement);
    pcfg.setMaxIdleTime(maxIdleTime);
    pcfg.setMaxStatements(maxStatements);
    pcfg.setIdleConnectionTestPeriod(idleTestPeriod);

    Properties connectionProps = new Properties();
    password = password == null ? "" : password.trim();
    if (password.startsWith("{3DES}")) {
        password = password.substring("{3DES}".length());
        if (DesEncryptTools.KEY_OBJ == null) {
            throw new WabacusConfigLoadingException(
                    "?????");
        }
        password = DesEncryptTools.decrypt(password);
    }
    connectionProps.setProperty("user", user);
    connectionProps.setProperty("password", password);
    try {
        Class.forName(driver);
        DataSource unpooled = DataSources.unpooledDataSource(url, connectionProps);
        this.ds = DataSources.pooledDataSource(unpooled, pcfg);
    } catch (Exception e) {
        throw new WabacusConfigLoadingException("??" + this.getName() + "", e);
    }
}

From source file:com.wabacus.config.database.datasource.DriverManagerDataSource.java

License:Open Source License

public void loadConfig(Element eleDataSource) {
    super.loadConfig(eleDataSource);
    List lstEleProperties = eleDataSource.elements("property");
    if (lstEleProperties == null || lstEleProperties.size() == 0) {
        throw new WabacusConfigLoadingException(
                "??" + this.getName() + "?driver?url?user?");
    }/*  ww w.  j  a  va  2 s  .co m*/
    Element eleChild;
    String name;
    String value;
    for (int i = 0; i < lstEleProperties.size(); i++) {
        eleChild = (Element) lstEleProperties.get(i);
        name = eleChild.attributeValue("name");
        value = eleChild.getText();
        name = name == null ? "" : name.trim();
        value = value == null ? "" : value.trim();
        if (name.equals("driver")) {
            driver = value;
        } else if (name.equals("url")) {
            url = value;
        } else if (name.equals("user")) {
            user = value;
        } else if (name.equals("password")) {
            password = value;
        }
    }
    driver = driver == null ? "" : driver.trim();
    url = url == null ? "" : url.trim();
    user = user == null ? "" : user.trim();
    password = password == null ? "" : password.trim();
    if (password.startsWith("{3DES}")) {
        password = password.substring("{3DES}".length());
        if (DesEncryptTools.KEY_OBJ == null) {
            throw new WabacusConfigLoadingException(
                    "?????");
        }
        password = DesEncryptTools.decrypt(password);
    }
    if (driver.equals("") || url.equals("") || user.equals("")) {
        throw new WabacusConfigLoadingException("??" + this.getName()
                + "????driver,url,user?");
    }
}

From source file:com.wabacus.config.database.datasource.JNDIDataSource.java

License:Open Source License

public void loadConfig(Element eleDataSource) {
    super.loadConfig(eleDataSource);
    List lstEleProperties = eleDataSource.elements("property");
    if (lstEleProperties == null || lstEleProperties.size() == 0) {
        throw new WabacusConfigLoadingException("??" + this.getName() + "?jndi?");
    }/*from  w  w  w  . j a v a2s  .  c  om*/
    Element eleChild;
    String name;
    String value;
    for (int i = 0; i < lstEleProperties.size(); i++) {
        eleChild = (Element) lstEleProperties.get(i);
        name = eleChild.attributeValue("name");
        value = eleChild.getText();
        name = name == null ? "" : name.trim();
        value = value == null ? "" : value.trim();
        if (name.equals("jndi")) {
            jndi = value;
            break;
        }
    }
    if (jndi == null || jndi.trim().equals("")) {
        throw new WabacusConfigLoadingException("??" + this.getName() + "?jndi");
    }
}

From source file:com.wabacus.config.database.datasource.ProxoolDataSource.java

License:Open Source License

public void loadConfig(Element eleDataSource) {
    super.loadConfig(eleDataSource);
    List lstEleProperties = eleDataSource.elements("property");
    if (lstEleProperties == null || lstEleProperties.size() == 0) {
        throw new WabacusConfigLoadingException(
                "??" + this.getName() + "?alias?configfile?");
    }/*from   w ww.jav  a2  s .  co  m*/
    String configfile = null;
    Element eleChild;
    String name;
    String value;
    for (int i = 0; i < lstEleProperties.size(); i++) {
        eleChild = (Element) lstEleProperties.get(i);
        name = eleChild.attributeValue("name");
        value = eleChild.getText();
        name = name == null ? "" : name.trim();
        value = value == null ? "" : value.trim();
        if (name.equals("alias")) {
            alias = value;
        } else if (name.equals("configfile")) {
            configfile = value;
        }
    }
    if (alias == null || alias.trim().equals("")) {
        throw new WabacusConfigLoadingException("??" + this.getName() + "?alias");
    }
    alias = "proxool." + alias.trim();
    if (configfile == null || configfile.trim().equals("")) {
        throw new WabacusConfigLoadingException("??" + this.getName() + "?configfile");
    }
    changePassword(configfile, false);
    BufferedInputStream bis = null;
    try {
        if (Tools.isDefineKey("classpath", Config.configpath)) {
            if (configfile.startsWith("/")) {
                configfile = configfile.substring(1);
            }
            bis = new BufferedInputStream(ConfigLoadManager.currentDynClassLoader.getResourceAsStream(
                    WabacusAssistant.getInstance().getRealFilePath(Config.configpath, configfile)));
        } else {
            bis = new BufferedInputStream(new FileInputStream(
                    new File(WabacusAssistant.getInstance().getRealFilePath(Config.configpath, configfile))));
        }
        if (!configfile.toLowerCase().endsWith(".xml")) {
            throw new WabacusConfigLoadingException("?" + configfile
                    + "???wabacus??.xml?proxool??");
        }
        JAXPConfigurator.configure(new InputStreamReader(bis), false);
    } catch (Exception e) {
        throw new WabacusConfigLoadingException("?" + configfile + "", e);
    } finally {
        if (bis != null) {
            try {
                bis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            bis = null;
        }
    }
    changePassword(configfile, true);
}