List of usage examples for org.dom4j Node selectSingleNode
Node selectSingleNode(String xpathExpression);
selectSingleNode
evaluates an XPath expression and returns the result as a single Node
instance.
From source file:com.google.code.pentahoflashcharts.charts.pfcxml.ScatterChartBuilder.java
License:Open Source License
private void setupDotSize(Node root, ScatterChart se, IPentahoResultSet data, int i) { Number maxX = 0;// w w w. jav a 2 s . c o m int rowCount = data.getRowCount(); for (int j = 0; j < rowCount; j++) { Number x = (Number) data.getValueAt(j, 1); if (maxX.doubleValue() < x.doubleValue()) { maxX = x; } } if (getValue(root.selectSingleNode("/chart/dot-size")) != null) { String dotSize = getNodeValue(root.selectSingleNode("/chart/dot-size")); se.setDotSize(Integer.parseInt(dotSize)); } else { Number x = (Number) data.getValueAt(i, 1); //<max-bubble-size>100</max-bubble-size> int maxBubbleSize = 100; if (getValue(root.selectSingleNode("/chart/max-bubble-size")) != null) { maxBubbleSize = Integer.parseInt(getNodeValue(root.selectSingleNode("/chart/max-bubble-size"))); } se.setDotSize( Integer.valueOf(java.lang.Math.round(maxBubbleSize * (x.floatValue() / maxX.floatValue())))); } }
From source file:com.google.code.pentahoflashcharts.charts.pfcxml.SketchBarChartBuilder.java
License:Open Source License
protected void setupElements(Chart c, Node root, IPentahoResultSet data) { BarChart[] values = null;/*from w w w . ja v a2s . c o m*/ int rowCount = data.getRowCount(); List bars = root.selectNodes("/chart/bars/bar"); int barNum = bars.size(); values = new BarChart[barNum]; int functor = 5; for (int i = 0; i < barNum; i++) { Node bar = (Node) bars.get(i); Node textNode = bar.selectSingleNode("text"); Node colorNode = bar.selectSingleNode("color"); Node outlineColorNode = bar.selectSingleNode("outlineColor"); String color = ""; String outlineColor = ""; if (colorNode != null && colorNode.getText().length() > 0) { color = colorNode.getText().trim(); } if (outlineColorNode != null && outlineColorNode.getText().length() > 0) { outlineColor = outlineColorNode.getText().trim(); } BarChart e = new SketchBarChart(color, outlineColor, functor); setBarchartData(data, rowCount, bar, colorNode, textNode, e); setOnClick(e, root, "/chart/bars/bar/on-click"); setLink(e, root, "/chart/bars/bar/link"); values[i] = e; } c.addElements(values); }
From source file:com.googlecode.fascinator.redbox.sru.NLAIdentity.java
License:Open Source License
private List<Map<String, String>> getSourceIdentities() { List<Map<String, String>> returnList = new ArrayList<Map<String, String>>(); // Top level institution Map<String, String> idMap = new HashMap<String, String>(); Node institutionNode = eac.selectSingleNode("eac:eac-cpf/eac:control/eac:maintenanceAgency/eac:agencyName"); String institutionString = institutionNode.getText(); // Top level name Node nlaNamesNode = eac.selectSingleNode("eac:eac-cpf/eac:cpfDescription/eac:identity"); // Get all the names this ID lists List<Map<String, String>> nameList = getNames(nlaNamesNode); for (Map<String, String> name : nameList) { // Only use the longest top-level name for display purposes String oldDisplayName = idMap.get("displayName"); String thisDisplayName = name.get("displayName"); if (oldDisplayName == null || (thisDisplayName != null && thisDisplayName.length() > oldDisplayName.length())) { // Clear any old data idMap.clear();// w ww . ja v a 2 s . co m // Store this ID idMap.putAll(name); idMap.put("institution", institutionString); } } // And add to the list returnList.add(idMap); // All name entities from contributing insitutions @SuppressWarnings("unchecked") List<Node> sourceIdentities = eac.selectNodes("eac:eac-cpf/eac:cpfDescription//eac:eac-cpf"); for (Node identity : sourceIdentities) { // Insitution for this ID institutionNode = identity.selectSingleNode("*//eac:maintenanceAgency/eac:agencyName"); institutionString = institutionNode.getText(); // Any names for this ID @SuppressWarnings("unchecked") List<Node> idNodes = identity.selectNodes("*//eac:identity"); for (Node idNode : idNodes) { // A Map for each name idMap = new HashMap<String, String>(); // Get all the names this ID lists nameList = getNames(idNode); for (Map<String, String> name : nameList) { idMap.putAll(name); } // Indicate the insitution for each one idMap.put("institution", institutionString); // And add to the list returnList.add(idMap); } } // Debugging //for (Map<String, String> id : returnList) { // String display = id.get("displayName") + " (" + id.get("institution") + ")"; // log.debug("Identity: {}", display); //} return returnList; }
From source file:com.googlecode.fascinator.redbox.sru.NLAIdentity.java
License:Open Source License
private List<Map<String, String>> getNames(Node node) { List<Map<String, String>> nameList = new ArrayList<Map<String, String>>(); // Any names for this ID @SuppressWarnings("unchecked") List<Node> names = node.selectNodes("eac:nameEntry"); for (Node name : names) { Map<String, String> nameMap = new HashMap<String, String>(); String thisDisplay = null; String thisFirstName = null; String thisSurname = null; String title = null;/*from w w w. j ava 2 s . c o m*/ // First name Node firstNameNode = name .selectSingleNode("eac:part[(@localType=\"forename\") or (@localType=\"givenname\")]"); if (firstNameNode != null) { thisFirstName = firstNameNode.getText(); } // Surname Node surnameNode = name .selectSingleNode("eac:part[(@localType=\"surname\") or (@localType=\"familyname\")]"); if (surnameNode != null) { thisSurname = surnameNode.getText(); } // Title Node titleNode = name.selectSingleNode("eac:part[@localType=\"title\"]"); if (titleNode != null) { title = titleNode.getText(); } // Display Name if (thisSurname != null) { thisDisplay = thisSurname; nameMap.put("surname", thisSurname); if (thisFirstName != null) { thisDisplay += ", " + thisFirstName; nameMap.put("firstName", thisFirstName); } if (title != null) { thisDisplay += " (" + title + ")"; } nameMap.put("displayName", thisDisplay); } // Last ditch effort... we couldn't find simple name information from // recommended values. So just concatenate what we can see. if (thisDisplay == null) { // Find every part @SuppressWarnings("unchecked") List<Node> parts = name.selectNodes("eac:part"); for (Node part : parts) { // Grab the value and type of this value Element element = (Element) part; String value = element.getText(); String type = element.attributeValue("localType"); // Build a display value for this part if (type != null) { value += " (" + type + ")"; } // And add to the display name if (thisDisplay == null) { thisDisplay = value; } else { thisDisplay += ", " + value; } } nameMap.put("displayName", thisDisplay); } nameList.add(nameMap); } return nameList; }
From source file:com.lafengmaker.tool.util.XMLDataUtil.java
License:Open Source License
/** * // w ww. j ava2 s.c om * @param node * @param xPath * @param defaultValue * @return */ public static long getNodeTextAsLong(Node node, String xPath, long defaultValue) { long returnValue = 0; if (node != null) { Node tempNode = node.selectSingleNode(xPath); if (tempNode != null) { String nodeValue = tempNode.getText(); returnValue = parseLong(nodeValue, defaultValue); } else { returnValue = defaultValue; } } else { returnValue = defaultValue; } return returnValue; }
From source file:com.lafengmaker.tool.util.XMLDataUtil.java
License:Open Source License
/** * /*from w ww . j av a 2 s . c o m*/ * @param node * @param xPath * @param defaultValue * @return */ public static int getNodeTextAsInt(Node node, String xPath, int defaultValue) { int returnValue = 0; if (node != null) { Node tempNode = node.selectSingleNode(xPath); if (tempNode != null) { String nodeValue = tempNode.getText(); returnValue = parseInt(nodeValue, defaultValue); } else { returnValue = defaultValue; } } else { returnValue = defaultValue; } return returnValue; }
From source file:com.lafengmaker.tool.util.XMLDataUtil.java
License:Open Source License
public static String getNodeTextAsStringByPattern(Node node, String xPath, String defaultValue) { String returnValue = ""; if (node != null) { Node tempNode = node.selectSingleNode(xPath); if (tempNode != null) { returnValue = tempNode.getText().trim(); } else {// www. j av a2 s . c o m returnValue = defaultValue; } } else { returnValue = defaultValue; } return returnValue; }
From source file:com.lafengmaker.tool.util.XMLDataUtil.java
License:Open Source License
public static boolean setDataByPattern(Node node, String value, String pattern) { if (node != null) { Node desNode = node.selectSingleNode(pattern); if (desNode != null) { desNode.setText(value);/*from w w w . j a va 2s .com*/ return true; } else { return false; } } else { return false; } }
From source file:com.lafengmaker.tool.util.XMLDataUtil.java
License:Open Source License
public static double getNodeTextAsDouble(Node node, String xPath, long defaultValue) { double returnValue = 0; if (node != null) { Node tempNode = node.selectSingleNode(xPath); if (tempNode != null) { String nodeValue = tempNode.getText(); returnValue = parseDouble(nodeValue, defaultValue); } else {//from w w w . ja v a2s. com returnValue = defaultValue; } } else { returnValue = defaultValue; } return returnValue; }
From source file:com.log4ic.compressor.utils.MemcachedUtils.java
License:Open Source License
private static InetSocketAddress biludAddr(Node node) { Node hostNode = node.selectSingleNode("host"); Node portNode = node.selectSingleNode("port"); if (hostNode != null && StringUtils.isNotBlank(hostNode.getText()) && portNode != null && StringUtils.isNotBlank(portNode.getText())) { return new InetSocketAddress(hostNode.getText(), Integer.parseInt(portNode.getText())); }/*from w w w . j ava 2 s . c o m*/ return null; }