List of usage examples for org.dom4j Node valueOf
String valueOf(String xpathExpression);
valueOf
evaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node.
From source file:com.globalsight.everest.snippet.importer.ImportOptions.java
License:Apache License
/** * Reads and validates a ImportOptions XML string. * * Xml Format:/* w w w . j a v a 2s .co m*/ */ public void initOther(Element p_root) throws ImporterException { try { Node node = p_root.selectSingleNode("//syncOptions"); m_syncOptions.m_syncMode = node.valueOf("syncMode"); m_syncOptions.m_syncLanguage = node.valueOf("syncLanguage"); m_syncOptions.m_syncAction = node.valueOf("syncAction"); } catch (Exception e) { // cast exception and throw error(e.getMessage(), e); } }
From source file:com.globalsight.terminology.exporter.ExportOptions.java
License:Apache License
/** * Reads and validates a ExportOptions XML string. *///from w ww.j a v a 2 s . c o m protected void initOther(Element p_root) throws ExporterException { try { Node node = p_root.selectSingleNode("/exportOptions/selectOptions"); m_selectOptions.m_selectMode = node.valueOf("selectMode"); m_selectOptions.m_selectLanguage = node.valueOf("selectLanguage"); m_selectOptions.m_duplicateHandling = node.valueOf("duplicateHandling"); node = p_root.selectSingleNode("/exportOptions/filterOptions"); m_filterOptions.m_createdBy = node.valueOf("createdby"); m_filterOptions.m_modifiedBy = node.valueOf("modifiedby"); m_filterOptions.m_createdAfter = node.valueOf("createdafter"); m_filterOptions.m_createdBefore = node.valueOf("createdbefore"); m_filterOptions.m_modifiedAfter = node.valueOf("modifiedafter"); m_filterOptions.m_modifiedBefore = node.valueOf("modifiedbefore"); m_filterOptions.m_status = node.valueOf("status"); m_filterOptions.m_domain = node.valueOf("domain"); m_filterOptions.m_project = node.valueOf("project"); m_filterOptions.m_conditions.clear(); List filters = p_root.selectNodes("/exportOptions/filterOptions/conditions/condition"); for (int i = 0; i < filters.size(); ++i) { Element filter = (Element) filters.get(i); FilterCondition condition = new FilterCondition(); condition.m_level = filter.valueOf("level"); condition.m_field = filter.valueOf("field"); condition.m_operator = filter.valueOf("operator"); condition.m_value = filter.valueOf("value"); condition.m_matchcase = filter.valueOf("matchcase"); m_filterOptions.m_conditions.add(condition); } node = p_root.selectSingleNode("/exportOptions/outputOptions"); m_outputOptions.m_systemFields = node.valueOf("systemFields"); m_outputOptions.m_separator = node.valueOf("separator"); m_outputOptions.m_writeHeader = node.valueOf("writeHeader"); m_columns.clear(); List columns = p_root.selectNodes("/exportOptions/columnOptions/column"); for (int i = 0; i < columns.size(); ++i) { Element col = (Element) columns.get(i); ColumnDescriptor desc = new ColumnDescriptor(); desc.m_position = Integer.parseInt(col.attributeValue("id")); desc.m_name = col.valueOf("name"); desc.m_type = col.valueOf("type"); desc.m_termLanguage = col.valueOf("termLanguage"); desc.m_encoding = col.valueOf("encoding"); m_columns.add(desc); } } catch (Exception e) { // cast exception and throw error(e.getMessage(), e); } }
From source file:com.globalsight.terminology.LockInfo.java
License:Apache License
private void init(String p_xml) throws TermbaseException { XmlParser parser = null;//from w w w . ja v a 2 s.co m Document dom; try { parser = XmlParser.hire(); dom = parser.parseXml(p_xml); } finally { XmlParser.fire(parser); } try { Element root = dom.getRootElement(); Node lock = root.selectSingleNode("/lock"); String tbid = lock.valueOf("termbase"); String cid = lock.valueOf("conceptid"); String who = lock.valueOf("who"); String email = lock.valueOf("email"); String when = lock.valueOf("when"); String cookie = lock.valueOf("cookie"); if (tbid == null || cid == null || who == null || email == null || when == null || cookie == null) { error("null field in XML", null); } setTermbase(Long.parseLong(tbid)); setConceptId(Long.parseLong(cid)); setUser(who); setEmail(email); setDate(UTC.parse(when)); setCookie(cookie); } catch (TermbaseException e) { throw e; } catch (Exception e) { // cast exception and throw error(e.getMessage(), e); } }
From source file:com.globalsight.terminology.Validator.java
License:Apache License
/** * Validates an entry. Caller must lock Termbase object with * Termbase.addReader().//from w w w . j a v a2s . com */ static public ValidationInfo validate(Entry p_entry, Definition m_definition, long tb_id) throws TermbaseException { long cid = EntryUtils.getConceptId(p_entry); ValidationInfo result = new ValidationInfo(cid); if (CATEGORY.isDebugEnabled()) { CATEGORY.debug("Validating entry " + cid + "..."); } List langGrps = EntryUtils.getLanguageGrps(p_entry); for (int i = 0, max = langGrps.size(); i < max; i++) { Node langGrp = (Node) langGrps.get(i); String langName = langGrp.valueOf("language/@name"); Definition.Language language = m_definition.getLanguage(langName); List terms = EntryUtils.getTerms(langGrp); for (int j = 0, max2 = terms.size(); j < max2; j++) { Node termNode = (Node) terms.get(j); Node termAttribute = termNode.selectSingleNode("//term/@termId"); String termId = null; if (termAttribute != null) { termId = termAttribute.getText(); } String term = termNode.getText(); // Collect exact matches from the same language. Hitlist hits = getDuplicateTerm(tb_id, langName, term, termId); addHits(result, langName, term, hits); // Should look for fuzzy matches too. } } if (CATEGORY.isDebugEnabled()) { CATEGORY.debug("Validating entry " + cid + "... done."); } return result; }
From source file:com.google.code.pentahoflashcharts.charts.AbstractChartFactory.java
License:Open Source License
/** * Setup colors for the series and also background *//*w w w . java2s . co m*/ protected void setupColors() { Node temp = chartNode.selectSingleNode(COLOR_PALETTE_NODE_LOC); if (temp != null) { Object[] colorNodes = temp.selectNodes(COLOR_NODE_LOC).toArray(); for (int j = 0; j < colorNodes.length; j++) { colors.add(getValue((Node) colorNodes[j])); } } else { for (int i = 0; i < COLORS_DEFAULT.length; i++) { colors.add(COLORS_DEFAULT[i]); } } // Use either chart-background or plot-background (chart takes precendence) temp = chartNode.selectSingleNode(PLOT_BACKGROUND_NODE_LOC); if (getValue(temp) != null) { String type = temp.valueOf(PLOT_BACKGROUND_COLOR_XPATH); if (type != null && COLOR_TYPE.equals(type)) { chart.setBackgroundColour(getValue(temp)); chart.setInnerBackgroundColour(getValue(temp)); } } temp = chartNode.selectSingleNode(CHART_BACKGROUND_NODE_LOC); if (getValue(temp) != null) { String type = temp.valueOf(CHART_BACKGROUND_COLOR_XPATH); if (type != null && COLOR_TYPE.equals(type)) chart.setBackgroundColour(getValue(temp)); } }
From source file:com.hihframework.osplugins.dom4j.XmlParseUtil.java
License:Apache License
/** * ?// w ww.j ava 2 s .c om * * @param document * * @param nodesName * ?? ?"//??"/??" * ?//foo/barbar??? * @return ?? */ public String getNodeText(Node node, String nodeName) { String nodeText = node.valueOf(nodeName); return nodeText; }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.message.MMXPubSubItem.java
License:Apache License
private void parsePayload(Element payloadElement) { if (payloadElement != null) { Document d = payloadElement.getDocument(); Node mmxPayloadNode = d.selectSingleNode( String.format("/*[name()='%s']/*[name()='%s']", Constants.MMX_ELEMENT, Constants.MMX_PAYLOAD)); if (mmxPayloadNode != null) { String mtype = mmxPayloadNode.valueOf("@mtype"); String stamp = DateFormatUtils.format(new DateTime(mmxPayloadNode.valueOf("@stamp")).toDate(), "yyyy-MM-dd'T'HH:mm:ss'Z'", TimeZone.getTimeZone("UTC")); String data = mmxPayloadNode.getText(); payload = new MMXPubSubPayload(mtype, stamp, data); }//from w w w . j ava 2 s.c om Node mmxMetaNode = d.selectSingleNode( String.format("/*[name()='%s']/*[name()='%s']", Constants.MMX_ELEMENT, Constants.MMX_META)); if (mmxMetaNode != null) { meta = getMapFromJsonString(mmxMetaNode.getText()); } } }
From source file:com.nokia.ant.BuildStatusDef.java
License:Open Source License
public void checkTargetsProperties(Project project) { if (project.getProperty("data.model.file") != null) { SAXReader xmlReader = new SAXReader(); Document antDoc = null;//from ww w . ja v a2 s .c o m ArrayList customerProps = getCustomerProperties(project); try { File model = new File(project.getProperty("data.model.file")); antDoc = xmlReader.read(model); } catch (Exception e) { // We are Ignoring the errors as no need to fail the build. log("Not able read the data model file. " + e.getMessage(), Project.MSG_WARN); } List<Node> statements = antDoc.selectNodes("//property"); for (Node statement : statements) { if (statement.valueOf("editStatus").equals("never")) { if (customerProps.contains(statement.valueOf("name"))) { output.add("Warning: " + statement.valueOf("name") + " property has been overridden"); } } } } }
From source file:com.nokia.ant.Database.java
License:Open Source License
private void processMacro(Element macroNode, Element outProjectNode, String antFile) throws IOException, DocumentException { String macroName = macroNode.attributeValue("name"); log("Processing macro: " + macroName, Project.MSG_DEBUG); Element outmacroNode = outProjectNode.addElement("macro"); addTextElement(outmacroNode, "name", macroNode.attributeValue("name")); addTextElement(outmacroNode, "description", macroNode.attributeValue("description")); // Add location // Project project = getProject(); // Macro antmacro = (Macro) project.getTargets().get(macroName); // System.out.println(project.getMacroDefinitions()); // System.out.println(macroName); // MacroInstance antmacro = (MacroInstance) // project.getMacroDefinitions().get("http://www.nokia.com/helium:" + // macroName); // Add the location with just the file path for now and a dummy line // number.//w w w .ja v a 2s. c o m // TODO - Later we should find the line number from the XML input. addTextElement(outmacroNode, "location", antFile + ":1:"); List<Node> statements = macroNode.selectNodes("//scriptdef[@name='" + macroName + "']/attribute | //macrodef[@name='" + macroName + "']/attribute"); String usage = ""; for (Node statement : statements) { String defaultval = statement.valueOf("@default"); if (defaultval.equals("")) defaultval = "value"; else defaultval = "<i>" + defaultval + "</i>"; usage = usage + " " + statement.valueOf("@name") + "=\"" + defaultval + "\""; } String macroElements = ""; statements = macroNode.selectNodes( "//scriptdef[@name='" + macroName + "']/element | //macrodef[@name='" + macroName + "']/element"); for (Node statement : statements) { macroElements = "<" + statement.valueOf("@name") + "/>\n" + macroElements; } if (macroElements.equals("")) addTextElement(outmacroNode, "usage", "<hlm:" + macroName + " " + usage + "/>"); else addTextElement(outmacroNode, "usage", "<hlm:" + macroName + " " + usage + ">\n" + macroElements + "</hlm:" + macroName + ">"); // Add dependencies // Enumeration dependencies = antmacro.getDependencies(); // while (dependencies.hasMoreElements()) // { // String dependency = (String) dependencies.nextElement(); // Element dependencyElement = addTextElement(outmacroNode, // "dependency", dependency); // dependencyElement.addAttribute("type","direct"); // } callAntTargetVisitor(macroNode, outmacroNode, outProjectNode); // Add documentation // Get comment element before the macro element to extract macro doc List children = macroNode.selectNodes("preceding-sibling::node()"); if (children.size() > 0) { // Scan past the text nodes, which are most likely whitespace int index = children.size() - 1; Node child = (Node) children.get(index); while (index > 0 && child.getNodeType() == Node.TEXT_NODE) { index--; child = (Node) children.get(index); } // Check if there is a comment node String commentText = null; if (child.getNodeType() == Node.COMMENT_NODE) { Comment macroComment = (Comment) child; commentText = macroComment.getStringValue().trim(); log(macroName + " comment: " + commentText, Project.MSG_DEBUG); } else { log("Macro has no comment: " + macroName, Project.MSG_WARN); } insertDocumentation(outmacroNode, commentText); Node previousNode = (Node) children.get(children.size() - 1); } // Get names of all properties used in this macro ArrayList properties = new ArrayList(); Visitor visitor = new AntPropertyVisitor(properties); macroNode.accept(visitor); for (Iterator iterator = properties.iterator(); iterator.hasNext();) { String property = (String) iterator.next(); addTextElement(outmacroNode, "propertyDependency", property); } }
From source file:com.nokia.helium.ant.data.MacroMeta.java
License:Open Source License
@SuppressWarnings("unchecked") public String getUsage() { String macroName = getName(); List<Node> statements = getNode().selectNodes("//scriptdef[@name='" + macroName + "']/attribute | //macrodef[@name='" + macroName + "']/attribute"); String usage = ""; for (Node statement : statements) { String defaultval = statement.valueOf("@default"); if (defaultval.equals("")) { defaultval = "value"; }/*from w w w .j a v a 2 s .c o m*/ // else { // defaultval = "<i>" + defaultval + "</i>"; // } usage = usage + statement.valueOf("@name") + "=\"" + defaultval + "\"" + " "; } String macroElements = ""; statements = getNode().selectNodes( "//scriptdef[@name='" + macroName + "']/element | //macrodef[@name='" + macroName + "']/element"); for (Node statement : statements) { macroElements = " <" + statement.valueOf("@name") + "/>\n" + macroElements; } if (macroElements.equals("")) { return "<hlm:" + macroName + " " + usage + "/>"; } else { return "<hlm:" + macroName + " " + usage + ">\n" + macroElements + " </hlm:" + macroName + ">"; } }