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.log4ic.compressor.utils.MemcachedUtils.java
License:Open Source License
private static AddressConfig biludAddrMapConfig(List<Node> nodeList) { AddressConfig config = new AddressConfig(); config.addressMap = new LinkedHashMap<InetSocketAddress, InetSocketAddress>(); List<Integer> weightsList = new ArrayList<Integer>(); for (Node node : nodeList) { Node masterNode = node.selectSingleNode("master"); Node weightsNode = ((Element) node).attribute("weights"); int weights = 1; if (weightsNode != null) { try { weights = Integer.parseInt(weightsNode.getText()); } catch (Exception e) { //fuck ide }//w w w .ja v a 2s . c o m } weightsList.add(weights); InetSocketAddress masterAddr; if (masterNode != null) { masterAddr = biludAddr(masterNode); } else { masterAddr = biludAddr(node); } Node standbyNode = node.selectSingleNode("standby"); InetSocketAddress standbyAddr = null; if (standbyNode != null) { standbyAddr = biludAddr(standbyNode); } config.addressMap.put(masterAddr, standbyAddr); } config.widgets = ArrayUtils.toPrimitive(weightsList.toArray(new Integer[weightsList.size()])); return config; }
From source file:com.mindquarry.desktop.model.task.TaskTransformer.java
License:Open Source License
@Path("people/item") public void people(Node node) { Node personID = node.selectSingleNode("./person"); //$NON-NLS-1$ Node role = node.selectSingleNode("./role"); //$NON-NLS-1$ task.addPerson(personID.getText(), role.getText()); }
From source file:com.mindquarry.desktop.model.task.TaskTransformer.java
License:Open Source License
@Path("dependencies/item") public void dependencies(Node node) { Node taskID = node.selectSingleNode("./task"); //$NON-NLS-1$ Node role = node.selectSingleNode("./role"); //$NON-NLS-1$ task.addDependency(taskID.getText(), role.getText()); }
From source file:com.ming800.core.p.service.impl.JmenuManagerImpl.java
/** * ??xmlJmenu jmenuMap//from ww w .ja v a 2 s .c o m */ private static Menu initJmenuMap(Document infoDocument) { Menu menu = new Menu(); // Document infoDocument = ResourcesUtil.getDocument(xmlPath); if (infoDocument != null) { List<Node> menuNodeList = infoDocument.selectNodes("menu"); String name = menuNodeList.get(0).selectSingleNode("@name").getText(); HashMap<String, Jmenu> jmenuMap = new HashMap<>(); List<Node> jmenuNodeList = infoDocument.selectNodes("menu/jmenu"); for (Node jMenuXmlNode : jmenuNodeList) { Jmenu jmenu = new Jmenu(); jmenu.setChildren(new ArrayList<Jnode>()); String id = jMenuXmlNode.selectSingleNode("@id").getText(); jmenu.setId(id); List<Node> firstLayerList = jMenuXmlNode.selectNodes("jnode"); for (Node firstLayerXmlNode : firstLayerList) { Jnode firstLayerJnode = JmenuManagerImpl.parseXmlNodeToJavaBean(firstLayerXmlNode); firstLayerJnode.setChildren(new ArrayList<Jnode>()); List<Node> secondLayerList = firstLayerXmlNode.selectNodes("jnode"); for (Node secondLayerXmlNode : secondLayerList) { Jnode secondLayerJnode = JmenuManagerImpl.parseXmlNodeToJavaBean(secondLayerXmlNode); firstLayerJnode.getChildren().add(secondLayerJnode); } jmenu.getChildren().add(firstLayerJnode); } jmenuMap.put(jmenu.getId(), jmenu); } menu.setName(name); menu.setJmenuHashMap(jmenuMap); } return menu; }
From source file:com.ming800.core.p.service.impl.JmenuManagerImpl.java
/** * xmlNodeJnode/* w w w .j a v a 2 s .c om*/ * * @param xmlNode * @return */ private static Jnode parseXmlNodeToJavaBean(Node xmlNode) { String url = xmlNode.selectSingleNode("@url").getText(); String text_zh_CN = xmlNode.selectSingleNode("@text_zh_CN").getText(); String text_en_US = xmlNode.selectSingleNode("@text_en_US").getText(); String state = "open"; if (xmlNode.selectSingleNode("@state") != null) { state = xmlNode.selectSingleNode("@state").getText(); } // String extend = xmlNode.selectSingleNode("@extend").getText(); String setting = xmlNode.selectSingleNode("@setting").getText(); String access = xmlNode.selectSingleNode("@access").getText(); String branch = xmlNode.selectSingleNode("@branch").getText(); Jnode jnode = new Jnode(); jnode.setId(jmenuId++ + ""); jnode.setText_zh_CN(text_zh_CN); jnode.setText_en_US(text_en_US); jnode.setUrl(url); jnode.setState(state); jnode.setSetting(setting); jnode.setAccess(access); jnode.setBranch(branch); return jnode; }
From source file:com.mirth.connect.connectors.jdbc.JdbcUtils.java
License:Open Source License
public static Object[] getParams(UMOEndpointURI uri, List<String> paramNames, Object root) throws Exception { Object[] params = new Object[paramNames.size()]; for (int i = 0; i < paramNames.size(); i++) { String param = paramNames.get(i); String name = param.substring(2, param.length() - 1); Object value = null;/*from www .j a va 2 s . com*/ if ("NOW".equalsIgnoreCase(name)) { value = new Timestamp(Calendar.getInstance().getTimeInMillis()); } else if ("payload".equals(name)) { value = root; } else if (root instanceof MessageObject) { TemplateValueReplacer parser = new TemplateValueReplacer(); value = parser.replaceValues(param, (MessageObject) root); } else if (root instanceof Map) { value = ((Map) root).get(name); } else if (root instanceof org.w3c.dom.Document) { org.w3c.dom.Document x3cDoc = (org.w3c.dom.Document) root; org.dom4j.Document dom4jDoc = new DOMReader().read(x3cDoc); try { Node node = dom4jDoc.selectSingleNode(name); if (node != null) { value = node.getText(); } } catch (Exception ignored) { value = null; } } else if (root instanceof org.dom4j.Document) { org.dom4j.Document dom4jDoc = (org.dom4j.Document) root; try { Node node = dom4jDoc.selectSingleNode(name); if (node != null) { value = node.getText(); } } catch (Exception ignored) { value = null; } } else if (root instanceof org.dom4j.Node) { org.dom4j.Node dom4jNode = (org.dom4j.Node) root; try { Node node = dom4jNode.selectSingleNode(name); if (node != null) { value = node.getText(); } } catch (Exception ignored) { value = null; } } else { try { value = BeanUtils.getProperty(root, name); } catch (Exception ignored) { value = null; } } if (value == null) { value = uri.getParams().getProperty(name); } if (value == null) { throw new IllegalArgumentException("Can not retrieve argument " + name); } params[i] = value; } return params; }
From source file:com.mothsoft.alexis.engine.numeric.President2012DataSetImporter.java
License:Apache License
@SuppressWarnings("unchecked") private Map<Date, PollResults> getPage(final String after, final int pageNumber) { final Map<Date, PollResults> pageMap = new LinkedHashMap<Date, PollResults>(); HttpClientResponse httpResponse = null; try {//from ww w. j a va2s .c o m final URL url = new URL(String.format(BASE_URL, after, pageNumber)); httpResponse = NetworkingUtil.get(url, null, null); final SAXReader saxReader = new SAXReader(); org.dom4j.Document document; try { document = saxReader.read(httpResponse.getInputStream()); } catch (DocumentException e) { throw new IOException(e); } finally { httpResponse.close(); } final SimpleDateFormat format = new SimpleDateFormat(YYYY_MM_DD); final List<Node> questions = document.selectNodes(XPATH_QUESTIONS); for (final Node question : questions) { final Date endDate; final Node poll = question.selectSingleNode(ANCESTOR_POLL); final Node endDateNode = poll.selectSingleNode(END_DATE); try { endDate = format.parse(endDateNode.getText()); logger.debug(String.format("%s: %s", END_DATE, format.format(endDate))); } catch (final ParseException e) { throw new RuntimeException(e); } final List<Node> responses = question.selectNodes(XPATH_RESPONSE_FROM_QUESTION); for (final Node response : responses) { final Node choiceNode = response.selectSingleNode(CHOICE); final String choice = choiceNode.getText(); if (President2012DataSetImporter.CANDIDATE_OPTIONS.contains(choice)) { final Node valueNode = response.selectSingleNode(VALUE); final Double value = Double.valueOf(valueNode.getText()); append(pageMap, endDate, choice, value); } } } httpResponse.close(); httpResponse = null; } catch (MalformedURLException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } finally { if (httpResponse != null) { httpResponse.close(); } } return pageMap; }
From source file:com.nokia.helium.ant.data.AntComment.java
License:Open Source License
/** * Clean the whitespace of the doc text. * Trim the whole string and also remove a consistent indent from the start * of each line.//from w w w . j ava 2 s. c o m */ static String getCleanedDocNodeText(Node docNode) { Node preceedingWhitespaceNode = docNode.selectSingleNode("preceding-sibling::text()"); int indent = 0; if (preceedingWhitespaceNode != null) { String text = preceedingWhitespaceNode.getText(); String[] lines = text.split("\n"); if (lines.length > 0) { indent = lines[lines.length - 1].length(); } } String text = docNode.getText(); text = text.trim(); String[] docLines = text.split("\n"); // Do not remove from the first line, it is already trimmed. text = docLines[0] + "\n"; for (int i = 1; i < docLines.length; i++) { String line = docLines[i].replaceFirst("^[ \t]{" + indent + "}", ""); text += line + "\n"; } return text; }
From source file:com.noterik.bart.fs.fscommand.AddEventCommand.java
License:Open Source License
public String execute(String uri, String xml) { logger.debug("Add event of presentation " + uri); logger.debug("Add event xml " + xml); Document doc = XMLHelper.asDocument(xml); List<Node> events; String ticket = ""; String user = ""; if (doc == null) { logger.error("Could not parse xml"); return FSXMLBuilder.getErrorMessage("500", "No xml found", "Please provide xml", ""); } else {//w w w . j a v a2 s . com events = doc.selectNodes("/fsxml/*"); user = doc.selectSingleNode("//properties/user") == null ? "" : doc.selectSingleNode("//properties/user").getText(); user = user.toLowerCase(); ticket = doc.selectSingleNode("//properties/ticket") == null ? "" : doc.selectSingleNode("//properties/ticket").getText(); } //TODO: validate ticket // create playlist if it does not exist createPlaylistIfNotExists(uri); for (Iterator<Node> it = events.iterator(); it.hasNext();) { Node event = it.next(); if (!event.getName().equals("properties")) { logger.debug("received " + event.asXML()); String starttime = event.selectSingleNode("properties/starttime") == null ? "" : event.selectSingleNode("properties/starttime").getText(); String duration = event.selectSingleNode("properties/duration") == null ? "" : event.selectSingleNode("properties/duration").getText(); String reason = event.selectSingleNode("properties/reason") == null ? "" : event.selectSingleNode("properties/reason").getText(); logger.debug("starttime = " + starttime + " duration = " + duration + " reason = " + reason); // determine starttime relative to beginning of video long stSpringfield = determineCorrectStarttime(uri, starttime); if (starttime.equals("") || duration.equals("") || reason.equals("")) { logger.error("Not all mandatory fields where provided"); return FSXMLBuilder.getErrorMessage("500", "No all mandatory fields available", "Please provide all mandatory fields in your request", ""); } // create new 'bookmark' StringBuffer bmXml = new StringBuffer(); bmXml.append("<fsxml>"); bmXml.append("<properties>"); bmXml.append("<title><![CDATA["); bmXml.append(reason); bmXml.append("]]></title>"); bmXml.append("<description><![CDATA["); bmXml.append(reason); bmXml.append("]]></description>"); bmXml.append("<starttime>"); bmXml.append(stSpringfield); bmXml.append("</starttime>"); bmXml.append("<duration>"); bmXml.append(duration); bmXml.append("</duration>"); bmXml.append("<creator>"); bmXml.append(user); bmXml.append("</creator>"); bmXml.append("<changedby>"); bmXml.append(user); bmXml.append("</changedby>"); bmXml.append("<lastupdate>"); bmXml.append(LASTUPDATE_FORMAT.format(new Date())); bmXml.append("</lastupdate>"); bmXml.append("</properties>"); bmXml.append("</fsxml>"); String bmUri = uri + "/videoplaylist/1/bookmark"; String resp = FSXMLRequestHandler.instance().handlePOST(bmUri, bmXml.toString()); logger.debug(resp); } } return FSXMLBuilder.getFSXMLStatusMessage("The properties where successfully added", "", ""); }
From source file:com.noterik.bart.fs.fscommand.CommandHandler.java
License:Open Source License
private void initCommandList() { File file = new File(GlobalConfig.instance().getBaseDir() + "conf/" + CONFIG_FILE); logger.info("Initializing command list: " + file.getAbsolutePath()); Document doc = XMLHelper.getXmlFromFile(file); if (doc != null) { List<Node> nl = doc.selectNodes("//command"); for (Node n : nl) { if (n instanceof Element) { if (n.getName() != null && n.getName().equals("command")) { Node idn = n.selectSingleNode("./id"); Node cln = n.selectSingleNode("./class"); Node jn = n.selectSingleNode("./jar"); if (idn != null && cln != null) { String id = idn.getText(); String cl = cln.getText(); String jar = null; if (jn != null && cl != null) { jar = jn.getText(); }//from ww w. j a va 2s .c o m if (id != null && cl != null) { try { if (jar != null) { logger.info("Loading jar " + jar + " for class " + cl); Class<?> commandClass = loadJar(jar, cl); if (commandClass != null) { Command o = (Command) commandClass.newInstance(); commands.put(id, o); } } else { Class c = Class.forName(cl); Object o = c.newInstance(); if (o instanceof Command) { commands.put(id, (Command) o); } } } catch (Exception e) { System.out.println("Problem with loading " + cl); } } } } } } } }