Example usage for org.dom4j Element getTextTrim

List of usage examples for org.dom4j Element getTextTrim

Introduction

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

Prototype

String getTextTrim();

Source Link

Document

DOCUMENT ME!

Usage

From source file:com.taobao.datasource.DataSourceConfigParser.java

License:Open Source License

private static LocalTxDataSourceDO createLocalTxDataSourceDO(Element localTxDatasource) {
    LocalTxDataSourceDO ds = new LocalTxDataSourceDO();
    ds.setJndiName(localTxDatasource.elementTextTrim(JNDI_NAME));
    ds.setConnectionURL(localTxDatasource.elementTextTrim(CONNECTION_URL));
    ds.setDriverClass(localTxDatasource.elementTextTrim(DRIVER_CLASS));
    String transactionIsolation = localTxDatasource.elementTextTrim(TRANSACTION_ISOLATION);
    ds.setTransactionIsolation(/*from  w ww  .  ja v  a 2  s .  c  o m*/
            transactionIsolation != null ? transactionIsolation : DEFAULT_TRANSACTION_ISOLATION);
    ds.setUserName(localTxDatasource.elementTextTrim(USER_NAME));
    ds.setPassword(localTxDatasource.elementTextTrim(PASSWORD));
    ds.setSecurityDomain(localTxDatasource.elementTextTrim(SECURITY_DOMAIN));
    ds.setMinPoolSize(
            NumberUtils.toInt(localTxDatasource.elementTextTrim(MIN_POOL_SIZE), DEFAULT_MIN_POOL_SIZE));
    ds.setMaxPoolSize(
            NumberUtils.toInt(localTxDatasource.elementTextTrim(MAX_POOL_SIZE), DEFAULT_MAX_POOL_SIZE));
    ds.setBlockingTimeoutMillis(NumberUtils.toInt(localTxDatasource.elementTextTrim(BLOCKING_TIMEOUT_MILLIS),
            DEFAULT_BLOCKING_TIMEOUT_MILLIS));
    ds.setBackgroundValidation(TRUE.equalsIgnoreCase(localTxDatasource.elementTextTrim(BACKGROUND_VALIDATION)));
    ds.setBackgroundValidationMinutes(
            NumberUtils.toLong(localTxDatasource.elementTextTrim(BACKGROUND_VALIDATION_MINUTES),
                    DEFAULT_BACKGROUND_VALIDATION_MINUTES));
    ds.setIdleTimeoutMinutes(NumberUtils.toLong(localTxDatasource.elementTextTrim(IDLE_TIMEOUT_MINUTES),
            DEFAULT_IDLE_TIMEOUT_MINUTES));
    ds.setValidateOnMatch(!FALSE.equalsIgnoreCase(localTxDatasource.elementTextTrim(VALIDATE_ON_MATCH)));
    ds.setNewConnectionSQL(localTxDatasource.elementTextTrim(NEW_CONNECTION_SQL));
    ds.setCheckValidConnectionSQL(localTxDatasource.elementTextTrim(CHECK_VALID_CONNECTION_SQL));
    ds.setValidConnectionCheckerClassName(
            localTxDatasource.elementTextTrim(VALID_CONNECTION_CHECKER_CLASS_NAME));
    ds.setExceptionSorterClassName(localTxDatasource.elementTextTrim(EXCEPTION_SORTER_CLASS_NAME));
    String trackStatements = localTxDatasource.elementTextTrim(TRACK_STATEMENTS);
    ds.setTrackStatements(trackStatements != null ? trackStatements : DEFAULT_TRACK_STATEMENTS);
    ds.setPrefill(TRUE.equalsIgnoreCase(localTxDatasource.elementTextTrim(PREFILL)));
    ds.setUseFastFail(TRUE.equalsIgnoreCase(localTxDatasource.elementTextTrim(USE_FAST_FAIL)));
    ds.setPreparedStatementCacheSize(
            NumberUtils.toInt(localTxDatasource.elementTextTrim(PREPARED_STATEMENT_CACHE_SIZE),
                    DEFAULT_PREPARED_STATEMENT_CACHE_SIZE));
    ds.setSharePreparedStatements(localTxDatasource.element(SHARE_PREPARED_STATEMENTS) != null);
    ds.setTxQueryTimeout(localTxDatasource.element(SET_TX_QUERY_TIMEOUT) != null);
    ds.setQueryTimeout(
            NumberUtils.toInt(localTxDatasource.elementTextTrim(QUERY_TIMEOUT), DEFAULT_QUERY_TIMEOUT));

    for (Element connectionProperty : (List<Element>) localTxDatasource.elements(CONNECTION_PROPERTY)) {
        ds.addConnectionProperty(connectionProperty.attributeValue(NAME), connectionProperty.getTextTrim());
    }

    return ds;
}

From source file:com.taobao.datasource.LoginConfigParser.java

License:Open Source License

private static void createSecureIdentityLoginModule(Map<String, SecureIdentityLoginModule> result, Node node) {
    Element applicationPolicy = (Element) node;
    String name = applicationPolicy.attributeValue(NAME);

    Element usernameElement = (Element) usernamePath.selectSingleNode(applicationPolicy);
    String username = usernameElement != null ? usernameElement.getTextTrim() : null;

    Element passwordElement = (Element) passwordPath.selectSingleNode(applicationPolicy);
    String password = passwordElement != null ? passwordElement.getTextTrim() : null;

    if (isNotBlank(name) && isNotBlank(username) && isNotBlank(password)) {
        SecureIdentityLoginModule module = new SecureIdentityLoginModule();
        module.setUserName(username);/*from  w  w  w .  j  av a  2  s .  c o m*/
        module.setPassword(password);
        result.put(name, module);
    }
}

From source file:com.taobao.itest.tb.tair.mock.TairManagerXmlStoreImpl.java

License:Open Source License

/**
 * xml?classpath//  ww w.jav a  2s. c o  m
 * 
 * @param files
 *            
 * @throws Exception
 *             exception
 */
@SuppressWarnings({ "unchecked" })
public void setXmlStoreFiles(String files) throws Exception {
    SAXReader reader = new SAXReader();
    for (String filePath : files.split("[,:]")) {
        Document doc = reader.read(this.getClass().getResourceAsStream(filePath.trim()));
        List<Element> entryElements = doc.getRootElement().elements("entry");
        for (Element entryElement : entryElements) {
            int namespace = Integer.valueOf(entryElement.attributeValue("namespace"));
            String key = entryElement.attributeValue("key");
            String content = entryElement.getTextTrim();
            if (entryElement.attributeValue("href") != null) {
                content = IOUtils
                        .toString(this.getClass().getResourceAsStream(entryElement.attributeValue("href")));
            }
            String language = entryElement.attributeValue("language");
            if ("groovy".equalsIgnoreCase(language)) {
                getNameSpaceStore(namespace).put(key, evalGroovy(content));
            } else {
                getNameSpaceStore(namespace).put(key, content);
            }
        }
    }

}

From source file:com.taobao.itest.tb.tfs.mock.TfsManagerXmlStoreImpl.java

License:Open Source License

/**
 * xml?classpath//from w w  w.  j a  v a  2  s  .c  o m
 * 
 * @param files
 *            
 * @throws Exception
 *             exception
 */
@SuppressWarnings({ "unchecked" })
public void setXmlStoreFiles(String files) throws Exception {
    SAXReader reader = new SAXReader();
    for (String filePath : files.split("[,:]")) {
        Document doc = reader.read(this.getClass().getResourceAsStream(filePath.trim()));
        List<Element> fileElements = doc.getRootElement().elements("file");
        for (Element fileElement : fileElements) {
            TfsFile tfsFile = new TfsFile();
            tfsFile.setKey(fileElement.attributeValue("key"));
            tfsFile.setHref(fileElement.attributeValue("href"));
            tfsFile.setSuffix(fileElement.attributeValue("suffix"));
            tfsFile.setDesc(fileElement.attributeValue("desc"));
            if (StringUtils.isNotEmpty(tfsFile.getHref())) {
                tfsFile.setRawContent(
                        IOUtils.toByteArray(this.getClass().getResourceAsStream(tfsFile.getHref())));
            } else {
                tfsFile.setRawContent(fileElement.getTextTrim().getBytes());
            }
            tfsStore.put(tfsFile.getKey(), tfsFile);
        }
    }

}

From source file:com.tedi.engine.XMLOutput.java

License:Open Source License

/**
 * Clean the element./*from ww  w. ja  v  a  2  s . co m*/
 * 
 * @param ele
 *            The element.
 */
private void cleanElement(Element ele) {

    if (logger.isDebugEnabled()) {
        logger.debug("Cleaning the element " + ele);
    }
    // Attribute check shouldn't be necessary since only trying to write
    // populated attributes
    // but leave for now just in case
    for (Iterator i = ele.attributes().iterator(); i.hasNext();) {
        Attribute a = (Attribute) i.next();
        if (!mapFile.isSuppressAttribIfEmpty() || a.getText().length() > 0)
            continue;
        if (!mapFile.isSuppressAttribIfHasOnlyWhitespace() || a.getText().trim().length() > 0)
            continue;
        ele.remove(a);
    }
    for (Iterator i = ele.elements().iterator(); i.hasNext();) {
        cleanElement((Element) i.next());
    }
    if (!mapFile.isSuppressElementIfHasNoChildren() || ele.elements().size() > 0)
        return;
    if (!mapFile.isSuppressElementIfHasOnlyEmptyAttribs() || ele.attributes().size() > 0)
        return;
    if (!mapFile.isSuppressElementIfEmpty() || ele.getText().length() > 0)
        return;
    if (!mapFile.isSuppressElementIfHasOnlyWhitespace() || ele.getTextTrim().length() > 0)
        return;
    ele.getParent().remove(ele);
}

From source file:com.thoughtworks.cruise.ConfigureCruiseUsingApi.java

License:Apache License

private void editPipelineGroupAdminsAdmin(final String username, final String entity) throws Exception {
    editPipelineGroup(new PipelineGroupEditAction() {

        public void applyEdit(Document group) {
            List<Element> users = group.selectNodes("//authorization//admins//" + entity);
            for (Element user : users) {
                if (user.getTextTrim().equals(username)) {
                    user.detach();//w w w  .  jav  a 2 s.c  o m
                }
            }
        }
    });
}

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

License:Apache License

private boolean stageAuthorizedEntity(String pipelineName, String stageName, String userName,
        String userOrRole) {//ww w.  j ava  2 s .c  o  m
    Element stage = getStage(pipelineName, stageName);
    for (Element element : (List<Element>) stage
            .selectNodes(String.format(".//authorization/%s", userOrRole))) {
        if (element.getTextTrim().equals(userName)) {
            return true;
        }
    }
    return false;
}

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

License:Open Source License

public List<String> loadImportsConfig(Element element) {
    Element eleImports = element.element("imports");
    List<String> lstImportPackages = new ArrayList<String>();
    if (eleImports != null) {
        List lstImports = eleImports.elements("import");
        if (lstImports != null && lstImports.size() > 0) {
            Iterator itImports = lstImports.iterator();
            while (itImports.hasNext()) {
                Element eleImport = (Element) itImports.next();
                if (eleImport != null) {
                    String valueTemp = eleImport.getTextTrim();
                    if (valueTemp == null || valueTemp.trim().equals(""))
                        continue;
                    if (valueTemp.lastIndexOf(".*") == valueTemp.length() - 2) {
                        valueTemp = valueTemp.substring(0, valueTemp.length() - 2).trim();
                    }/*  www  .  j  a va 2 s .  c om*/
                    if (valueTemp.equals("") || lstImportPackages.contains(valueTemp))
                        continue;
                    lstImportPackages.add(valueTemp);
                }
            }
        }
    }
    return lstImportPackages;
}

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

License:Open Source License

public static List<String> loadCssfiles(Element root) {
    List<String> lstCssFiles = new UniqueArrayList<String>();
    if (root == null)
        return lstCssFiles;
    List lstCssFileElements = root.elements("css-file");
    if (lstCssFileElements != null && lstCssFileElements.size() > 0) {
        Element eleCssFile;
        for (int i = 0; i < lstCssFileElements.size(); i++) {
            eleCssFile = (Element) lstCssFileElements.get(i);
            if (eleCssFile == null)
                continue;
            String cssfile = eleCssFile.getTextTrim();
            if (cssfile == null || cssfile.trim().equals(""))
                continue;
            if (!cssfile.toLowerCase().trim().startsWith("http://")) {
                cssfile = Config.webroot + "/" + cssfile.trim();
                cssfile = Tools.replaceAll(cssfile, "\\", "/");
                cssfile = Tools.replaceAll(cssfile, "//", "/");
            }// w w w.j  av  a  2 s  .com
            lstCssFiles.add(cssfile);
        }
    }
    return lstCssFiles;
}

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

License:Open Source License

public static List<JavascriptFileBean> loadJsfiles(Element root) {
    List<JavascriptFileBean> lstJsFiles = new ArrayList<JavascriptFileBean>();
    if (root == null)
        return lstJsFiles;
    List lstJsFileElements = root.elements("js-file");
    if (lstJsFileElements != null && lstJsFileElements.size() > 0) {
        String encodetype = Config.encode.toLowerCase().trim();
        if (encodetype.equalsIgnoreCase("gb2312")) {
            encodetype = "gbk";
        } else if (encodetype.equals("utf-8")) {
            encodetype = "";
        }/*from   ww w .j av a 2  s.c o  m*/
        Element eleJsFile;
        String loadorderTmp;
        for (int i = 0; i < lstJsFileElements.size(); i++) {
            eleJsFile = (Element) lstJsFileElements.get(i);
            if (eleJsFile == null)
                continue;
            String jsfile = eleJsFile.getTextTrim();
            if (jsfile == null || jsfile.trim().equals(""))
                continue;
            jsfile = Tools.replaceAll(jsfile, "%ENCODING%", encodetype);
            if (!jsfile.trim().startsWith(Config.webroot)
                    && !jsfile.toLowerCase().trim().startsWith("http://")) {
                jsfile = Config.webroot + "/" + jsfile.trim();
                jsfile = Tools.replaceAll(jsfile, "\\", "/");
                jsfile = Tools.replaceAll(jsfile, "//", "/");
            }
            loadorderTmp = eleJsFile.attributeValue("loadorder");
            lstJsFiles.add(new JavascriptFileBean(jsfile.trim(),
                    loadorderTmp == null || loadorderTmp.trim().equals("") ? 0
                            : Integer.parseInt(loadorderTmp.trim())));
        }
    }
    return lstJsFiles;
}