List of usage examples for org.dom4j Node getText
String getText();
Returns the text of this node.
From source file:com.thoughtworks.cruise.context.Configuration.java
License:Apache License
public void rememberValueAs(String xpathLocator, String alias) { CruiseConfigDom dom = provideDom();//from w w w. ja v a 2s. co m Node node = dom.getNode(xpathLocator); aliases.put(alias, node.getText()); }
From source file:com.thoughtworks.cruise.CruiseConfigVerification.java
License:Apache License
public void verifyHasParamWithValue(String paramName, String paramValue) throws Exception { Element pipeline = currentPipeline(); Node paramVal = pipeline.selectSingleNode(".//param[@name='" + paramName + "']/."); assertThat(paramVal.getText(), is(paramValue)); }
From source file:com.thoughtworks.cruise.CruiseConfigVerification.java
License:Apache License
@com.thoughtworks.gauge.Step("Verify uses template <templateName>") public void verifyUsesTemplate(String templateName) throws Exception { Node templateNode = currentPipeline().selectSingleNode("./@template"); assertThat(templateNode.getText(), is(templateName)); }
From source file:com.thoughtworks.cruise.editpipelinewizard.AlreadyOnEnvironmentVariablesPage.java
License:Apache License
@com.thoughtworks.gauge.Step("Verify that <pipelineName> has variable named <name> with value <value>") public void verifyThatHasVariableNamedWithValue(final String pipelineName, final String name, final String value) throws Exception { Assertions.waitUntil(Timeout.THIRTY_SECONDS, new Predicate() { @Override//from w w w . j a va 2 s. c o m public boolean call() throws Exception { CruiseConfigDom dom = configuration.provideDomAsAdmin(); Element pipeline = dom.getPipeline(scenarioState.pipelineNamed(pipelineName)); String xpath = String.format("//variable[@name='%s']/value", name); Node node = pipeline.selectSingleNode(xpath); if (node != null) { Assert.assertThat(node.getText(), Is.is(value)); return true; } return false; } }); }
From source file:com.thoughtworks.cruise.editpipelinewizard.AlreadyOnEnvironmentVariablesPage.java
License:Apache License
@com.thoughtworks.gauge.Step("Verify that <pipelineName> has secure variable named <name>") public void verifyThatHasSecureVariableNamed(final String pipelineName, final String name) throws Exception { Assertions.waitUntil(Timeout.THIRTY_SECONDS, new Predicate() { @Override//from ww w . j a v a 2 s.c o m public boolean call() throws Exception { CruiseConfigDom dom = configuration.provideDomAsAdmin(); Element pipeline = dom.getPipeline(scenarioState.pipelineNamed(pipelineName)); String variableXpath = String.format("//variable[@name='%s'][@secure='true']/encryptedValue", name); Node encryptedValueNode = pipeline.selectSingleNode(variableXpath); if (encryptedValueNode != null) { Assert.assertThat(encryptedValueNode.getText(), Is.is(IsNot.not(Matchers.nullValue()))); return true; } return false; } }); }
From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
/** Looks for variables of type: ${http_repo*} in REPO_URL property and replaces it. Example: * <repositories>//from w w w. j a va 2 s. c om * <repository id="repo-id" name="tw-repo"> * <pluginConfiguration id="yum" version="1"/> * <configuration> * <property> * <key>REPO_URL</key> * <value>http://192.168.0.101:8081/${http_repo1}</value> * </property> * * TO * * <repositories> * <repository id="repo-id" name="tw-repo"> * <pluginConfiguration id="yum" version="1"/> * <configuration> * <property> * <key>REPO_URL</key> * <value>http://192.168.0.101:8081/pkgrepo-RANDOM1234</value> * </property> * * AND return a map which contains: {"http_repo1" => "pkgrepo-RANDOM1234"} */ public Map<String, String> replacePackageRepositoryURIForHttpBasedRepos(Map<String, String> currentRepoNames) { Pattern httpRepoNameVariablePattern = Pattern.compile("\\$\\{(http_repo[^\\}]*)\\}"); Map<String, String> httpRepoNameInConfigToItsNameAtRuntime = new HashMap<String, String>(currentRepoNames); List<Element> allRepoUrlPropertyKeys = root() .selectNodes("/cruise//repositories/repository/configuration/property/key[text()='REPO_URL']"); for (Element repoUrlKeyElement : allRepoUrlPropertyKeys) { Node repoUrlPropertyInConfig = repoUrlKeyElement.getParent().selectSingleNode("value"); String existingValueOfRepoUrl = repoUrlPropertyInConfig.getText(); Matcher matcherForVariable = httpRepoNameVariablePattern.matcher(existingValueOfRepoUrl); if (matcherForVariable.find()) { String variableName = matcherForVariable.group(1); String replacementRepoName = httpRepoNameInConfigToItsNameAtRuntime.get(variableName); if (!httpRepoNameInConfigToItsNameAtRuntime.containsKey(variableName)) { replacementRepoName = "pkgrepo-" + RandomStringUtils.randomAlphanumeric(10); httpRepoNameInConfigToItsNameAtRuntime.put(variableName, replacementRepoName); } String replacementRepoURL = existingValueOfRepoUrl .replaceFirst(httpRepoNameVariablePattern.pattern(), replacementRepoName); repoUrlPropertyInConfig.setText(replacementRepoURL); } } return httpRepoNameInConfigToItsNameAtRuntime; }
From source file:com.u2apple.rt.tool.DeviceValidator.java
private static void init() throws DocumentException { String path = Configuration.getProductsXml(); if (StringUtils.isNotBlank(path)) { File file = new File(path); if (file.exists()) { Document document = parse(file); List<Node> productIdNodes = document.selectNodes("//Device/ProductId"); for (Node node : productIdNodes) { productIds.add(node.getText()); }/* w ww . j a va2s.c om*/ } } }
From source file:com.webslingerz.jpt.PageTemplateImpl.java
License:Open Source License
private void defaultContent(Element element, ContentHandler contentHandler, LexicalHandler lexicalHandler, Interpreter beanShell, Stack<Map<String, Slot>> slotStack) throws SAXException, PageTemplateException, IOException { // Use default template content for (Iterator i = element.nodeIterator(); i.hasNext();) { Node node = (Node) i.next(); switch (node.getNodeType()) { case Node.ELEMENT_NODE: processElement((Element) node, contentHandler, lexicalHandler, beanShell, slotStack); break; case Node.TEXT_NODE: char[] text = Expression.evaluateText(node.getText().toString(), beanShell).toCharArray(); contentHandler.characters(text, 0, text.length); break; case Node.COMMENT_NODE: char[] comment = node.getText().toCharArray(); lexicalHandler.comment(comment, 0, comment.length); break; case Node.CDATA_SECTION_NODE: lexicalHandler.startCDATA(); char[] cdata = node.getText().toCharArray(); contentHandler.characters(cdata, 0, cdata.length); lexicalHandler.endCDATA();/*from w ww .j a v a 2s . com*/ break; case Node.NAMESPACE_NODE: Namespace declared = (Namespace) node; // System.err.println( "Declared namespace: " + // declared.getPrefix() + ":" + declared.getURI() ); namespaces.put(declared.getPrefix(), declared.getURI()); // if ( declared.getURI().equals( TAL_NAMESPACE_URI ) ) { // this.talNamespacePrefix = declared.getPrefix(); // } // else if (declared.getURI().equals( METAL_NAMESPACE_URI ) ) { // this.metalNamespacePrefix = declared.getPrefix(); // } break; case Node.ATTRIBUTE_NODE: // Already handled break; case Node.DOCUMENT_TYPE_NODE: case Node.ENTITY_REFERENCE_NODE: case Node.PROCESSING_INSTRUCTION_NODE: default: // System.err.println( "WARNING: Node type not supported: " + // node.getNodeTypeName() ); } } }
From source file:com.weibo.datasys.crawler.base.factory.TaskFactory.java
License:Open Source License
/** * /* www .j av a2s.c o m*/ * ???? * * @param task * @param doc * @throws Exception */ private static void buildCrawlUnit(Task task, Document doc) throws Exception { String fetcherName = doc.selectSingleNode("//Config/Fetcher").getText().trim(); AbstractFetcher fetcher = (AbstractFetcher) Class.forName(fetcherName).newInstance(); fetcher.configWithKeyValues(getParaMap(doc.selectSingleNode("//Config/Fetcher"))); String parserName = doc.selectSingleNode("//Config/Parser").getText().trim(); AbstractParser parser = (AbstractParser) Class.forName(parserName).newInstance(); parser.configWithKeyValues(getParaMap(doc.selectSingleNode("//Config/Parser"))); String saverName = doc.selectSingleNode("//Config/Saver").getText().trim(); AbstractSaver saver = (AbstractSaver) Class.forName(saverName).newInstance(); saver.configWithKeyValues(getParaMap(doc.selectSingleNode("//Config/Saver"))); String seedProviderName = doc.selectSingleNode("//Config/SeedProvider").getText().trim(); AbstractSeedProvider seedProvider = (AbstractSeedProvider) Class.forName(seedProviderName).newInstance(); seedProvider.configWithKeyValues(getParaMap(doc.selectSingleNode("//Config/SeedProvider"))); Node deduplicatorNode = doc.selectSingleNode("//Config/Deduplicator"); AbstractDeduplicator deduplicator = new LinkDBBaseDeduplicator(); if (deduplicatorNode != null) { String deduplicatorName = deduplicatorNode.getText().trim(); if (StringUtils.isNotEmpty(deduplicatorName)) { deduplicator = (AbstractDeduplicator) Class.forName(deduplicatorName).newInstance(); } deduplicator.configWithKeyValues(getParaMap(deduplicatorNode)); } else { deduplicator.configWithKeyValues(new LinkedHashMap<String, String>()); } task.setFetcher(fetcher); task.setParser(parser); task.setSaver(saver); task.setSeedProvider(seedProvider); task.setDeduplicator(deduplicator); }
From source file:com.weibo.datasys.crawler.base.factory.TaskFactory.java
License:Open Source License
/** * //from ww w. j a va 2s .com * ???node??Map * * @param node * @return */ @SuppressWarnings("unchecked") private static Map<String, String> getParaMap(Node node) { Map<String, String> paraMap = new LinkedHashMap<String, String>(); if (node != null) { List<Node> paraNodes = node.selectNodes("parameter"); for (Node paraNode : paraNodes) { String key = paraNode.selectSingleNode("@key").getText().trim(); String value = paraNode.getText().trim(); Node valueNode = paraNode.selectSingleNode("@value"); if (valueNode != null) { value = paraNode.selectSingleNode("@value").getText().trim(); } paraMap.put(key, value); } } return paraMap; }