List of usage examples for org.dom4j.tree DefaultElement element
public Element element(QName qName)
From source file:com.mor.blogengine.model.BlogComment.java
License:Open Source License
/** * * @param element XML node to create a comment from *//*from ww w .j ava2 s. c o m*/ public BlogComment(DefaultElement element) { mAassociatedElement = element; setDate(element.valueOf("@date")); setAuthor(element.valueOf("@author")); setWebPage(element.valueOf("@webPage")); setCommentText(element.element("CommentText").getText()); setEntityID(); setEntryID(element.valueOf("@entriID")); formatAttributesValuesAsHTML(); }
From source file:com.mor.blogengine.model.BlogEntry.java
License:Open Source License
/** * Creates a new instance of blogComment from xml node * * @param pElement l'lment XML partir duquel contruire le billet *///from w ww. j a va2s . co m public BlogEntry(DefaultElement pElement) { mAassociatedElement = pElement; setAllowComments(pElement.valueOf("@allowComments")); setDate(pElement.valueOf("@date")); setCatID(pElement.valueOf("@categoryID")); setEntityID(); setTexte(pElement.element("Text").getText()); if (pElement.element("Resume") == null) { setResume(""); } else { setResume(pElement.element("Resume").getTextTrim()); } formatAttributesValuesAsHTML(); }
From source file:com.webtide.jetty.load.generator.jenkins.AlpnBootVersions.java
License:Open Source License
private AlpnBootVersions() { Map<String, String> map = new HashMap<>(); try {//from ww w . j ava2 s.co m try (InputStream inputStream = this.getClass().getResourceAsStream("/jetty/jetty-project.pom")) { SAXReader reader = new SAXReader(); Document document = reader.read(inputStream); Map<String, String> namespaceMap = new HashMap<>(); namespaceMap.put("mvn", "http://maven.apache.org/POM/4.0.0"); XPath xpath = document.createXPath("//mvn:profiles/mvn:profile"); xpath.setNamespaceURIs(namespaceMap); List<DefaultElement> nodes = xpath.selectNodes(document); for (DefaultElement o : nodes) { if (StringUtils.startsWith((String) o.element("id").getData(), "8u")) { // olamy well a bit fragile way to parse if more than one property... //"//mvn:properties/mvn:alpn.version" // o.selectSingleNode( "//properties/alpn.version" ); Node version = o.element("properties").element("alpn.version"); //"//mvn:activation/mvn:property/mvn:value" //o.selectSingleNode( "//activation/property/value" ); Node javaVersion = o.element("activation").element("property").element("value"); map.put(javaVersion.getStringValue(), version.getStringValue()); } } } } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } jdkVersionAlpnBootVersion = Collections.unmodifiableMap(map); }
From source file:org.talend.designer.core.ui.editor.properties.controllers.RetrieveSchemaHelper.java
License:Open Source License
public static Command retrieveSchemasCommand(Node node) { IElementParameter param = node.getElementParameter("SCHEMA"); IMetadataTable inputMeta = node.getMetadataFromConnector("FLOW"); IMetadataTable inputMetaCopy = inputMeta.clone(true); IElementParameter outParam = node.getElementParameter("SCHEMA_OUT"); IMetadataTable outputMeta = node.getMetadataFromConnector(outParam.getContext()); IMetadataTable outputMetaCopy = outputMeta.clone(true); File xmlFile = new File( TalendTextUtils.removeQuotes(node.getElementParameter("PATH_JOBDEF").getValue().toString())); if (!xmlFile.exists()) try {/*w w w . j a v a 2s .c o m*/ xmlFile.createNewFile(); } catch (IOException e1) { ExceptionHandler.process(e1); } SAXReader saxReader = new SAXReader(); Document document; AutoApi a = null; try { // get the schema file from server a = new AutoApi(); String hostName = TalendTextUtils .removeQuotes(node.getElementParameter("HOSTNAME").getValue().toString()); int port = Integer .parseInt(TalendTextUtils.removeQuotes(node.getElementParameter("PORT").getValue().toString())); String mandant = TalendTextUtils .removeQuotes(node.getElementParameter("MANDANT").getValue().toString()); String userName = TalendTextUtils .removeQuotes(node.getElementParameter("USERNAME").getValue().toString()); String passWord = TalendTextUtils .removeQuotes(node.getElementParameter("PASSWORD").getValue().toString()); String jobDir = TalendTextUtils.removeQuotes(node.getElementParameter("JOB_DIR").getValue().toString()); String jobName = TalendTextUtils .removeQuotes(node.getElementParameter("JOB_NAME").getValue().toString()); String jobDef = TalendTextUtils .removeQuotes(node.getElementParameter("PATH_JOBDEF").getValue().toString()); a.openConnection(hostName, port, mandant, userName, passWord); a.getJobDefinitionFile(jobDir, jobName, jobDef); document = saxReader.read(xmlFile); List inputList = document .selectNodes("//Job//Lines//Line//Steps//Input//Sources//Source//Format//Fields//Field"); List inputMetaColumnList = new ArrayList<MetadataColumn>(); for (int i = 0; i < inputList.size(); i++) { IMetadataColumn imc = new MetadataColumn(); DefaultElement de = (DefaultElement) inputList.get(i); Element nameElement = de.element("Name"); imc.setLabel(nameElement.getData().toString()); Element lengthElement = de.element("Length"); if (!"".equals(lengthElement.getData().toString()) && !"0".equals(lengthElement.getData().toString())) { imc.setLength(Integer.parseInt(lengthElement.getData().toString())); } Element typeElement = de.element("Type"); JavaType javaType = JavaTypesManager.getJavaTypeFromName(typeElement.getData().toString()); if (javaType != null) { imc.setTalendType(javaType.getId()); } else { imc.setTalendType(JavaTypesManager.STRING.getId()); } inputMetaColumnList.add(imc); } inputMetaCopy.setListColumns(inputMetaColumnList); List outputList = document .selectNodes("//Job//Lines//Line//Steps//Output//Targets//Target//Format//Fields//Field"); List outputMetaColumnList = new ArrayList<MetadataColumn>(); for (int i = 0; i < outputList.size(); i++) { IMetadataColumn imc = new MetadataColumn(); DefaultElement de = (DefaultElement) outputList.get(i); Element nameElement = de.element("Name"); imc.setLabel(nameElement.getData().toString()); Element lengthElement = de.element("Length"); if (!"".equals(lengthElement.getData().toString()) && !"0".equals(lengthElement.getData().toString())) { imc.setLength(Integer.parseInt(lengthElement.getData().toString())); } Element typeElement = de.element("Type"); JavaType javaType = JavaTypesManager.getJavaTypeFromName(typeElement.getData().toString()); if (javaType != null) { imc.setTalendType(javaType.getId()); } else { imc.setTalendType(JavaTypesManager.STRING.getId()); } outputMetaColumnList.add(imc); } outputMetaCopy.setListColumns(outputMetaColumnList); // set advanced setting info DefaultElement de = (DefaultElement) document.selectObject( "//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//Record//FieldSeparator"); int separator = Integer.parseInt(de.getData().toString()); node.getElementParameter("IN_FIELD_SEP") .setValue(TalendTextUtils.addQuotes(new Character((char) separator).toString())); de = (DefaultElement) document.selectObject( "//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//Record//HeaderRecordCount"); node.getElementParameter("IN_HEADER_COUNT").setValue(de.getData().toString()); de = (DefaultElement) document.selectObject( "//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//FileLocation//Directory"); node.getElementParameter("IN_DIR").setValue(TalendTextUtils.addQuotes(de.getData().toString())); de = (DefaultElement) document.selectObject( "//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//FileLocation//FileName"); node.getElementParameter("IN_FILENAME").setValue(TalendTextUtils.addQuotes(de.getData().toString())); de = (DefaultElement) document.selectObject( "//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//FileLocation"); node.getElementParameter("IN_MODE").setValue(de.attribute("Mode").getValue()); de = (DefaultElement) document.selectObject( "//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//Record//FieldSeparator"); separator = Integer.parseInt(de.getData().toString()); node.getElementParameter("OUT_FIELD_SEP") .setValue(TalendTextUtils.addQuotes(new Character((char) separator).toString())); de = (DefaultElement) document.selectObject( "//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//Record//HeaderRecordCount"); node.getElementParameter("OUT_HEADER_COUNT").setValue(de.getData().toString()); de = (DefaultElement) document.selectObject( "//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//FileLocation//Directory"); node.getElementParameter("OUT_DIR").setValue(TalendTextUtils.addQuotes(de.getData().toString())); de = (DefaultElement) document.selectObject( "//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//FileLocation//FileName"); node.getElementParameter("OUT_FILENAME").setValue(TalendTextUtils.addQuotes(de.getData().toString())); de = (DefaultElement) document.selectObject( "//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//FileLocation"); node.getElementParameter("OUT_MODE").setValue(de.attribute("Mode").getValue()); } catch (Exception e) { ExceptionHandler.process(e); } finally { try { a.closeConnection(); } catch (Exception e) { ExceptionHandler.process(e); } } CompoundCommand cc = new CompoundCommand(); cc.add(new ChangeMetadataCommand(node, param, inputMeta, inputMetaCopy)); cc.add(new ChangeMetadataCommand(node, param, outputMeta, outputMetaCopy)); return cc; }