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:org.rundeck.api.parser.SystemInfoParser.java
License:Apache License
@Override public RundeckSystemInfo parse(Node infoNode) { RundeckSystemInfo info = new RundeckSystemInfo(); String timestamp = StringUtils.trimToNull(infoNode.valueOf("timestamp/@epoch")); if (timestamp != null) { info.setDate(new Date(Long.valueOf(timestamp))); }//from w w w. j a v a2s. co m info.setVersion(StringUtils.trimToNull(infoNode.valueOf("rundeck/version"))); info.setBuild(StringUtils.trimToNull(infoNode.valueOf("rundeck/build"))); info.setNode(StringUtils.trimToNull(infoNode.valueOf("rundeck/node"))); info.setBaseDir(StringUtils.trimToNull(infoNode.valueOf("rundeck/base"))); info.setOsArch(StringUtils.trimToNull(infoNode.valueOf("os/arch"))); info.setOsName(StringUtils.trimToNull(infoNode.valueOf("os/name"))); info.setOsVersion(StringUtils.trimToNull(infoNode.valueOf("os/version"))); info.setJvmName(StringUtils.trimToNull(infoNode.valueOf("jvm/name"))); info.setJvmVendor(StringUtils.trimToNull(infoNode.valueOf("jvm/vendor"))); info.setJvmVersion(StringUtils.trimToNull(infoNode.valueOf("jvm/version"))); String startDate = StringUtils.trimToNull(infoNode.valueOf("stats/uptime/since/@epoch")); if (startDate != null) { info.setStartDate(new Date(Long.valueOf(startDate))); } info.setUptimeInMillis(Long.valueOf(infoNode.valueOf("stats/uptime/@duration"))); info.setCpuLoadAverage(StringUtils.trimToNull(infoNode.valueOf("stats/cpu/loadAverage"))); if (info.getCpuLoadAverage() != null) { info.setCpuLoadAverage(info.getCpuLoadAverage() + " %"); } info.setMaxMemoryInBytes(Long.valueOf(infoNode.valueOf("stats/memory/max"))); info.setFreeMemoryInBytes(Long.valueOf(infoNode.valueOf("stats/memory/free"))); info.setTotalMemoryInBytes(Long.valueOf(infoNode.valueOf("stats/memory/total"))); info.setRunningJobs(Integer.valueOf(infoNode.valueOf("stats/scheduler/running"))); info.setActiveThreads(Integer.valueOf(infoNode.valueOf("stats/threads/active"))); return info; }
From source file:org.saiku.plugin.resources.PentahoRepositoryResource2.java
License:Apache License
private List<IRepositoryObject> processTree(final Node tree, final String parentPath, String fileType) { final String xPathDir = "./file"; //$NON-NLS-1$ List<IRepositoryObject> repoObjects = new ArrayList<IRepositoryObject>(); List<AclMethod> defaultAcls = new ArrayList<AclMethod>(); defaultAcls.add(AclMethod.READ);/*from w ww . j a v a 2 s .c o m*/ List<IPentahoAclEntry> adminAcl = new ArrayList<IPentahoAclEntry>(); try { List nodes = tree.selectNodes(xPathDir); for (final Object node1 : nodes) { final Node node = (Node) node1; String name = node.valueOf("@name"); final String localizedName = node.valueOf("@localized-name"); final boolean visible = node.valueOf("@visible").equals("true"); final boolean isDirectory = node.valueOf("@isDirectory").equals("true"); final String path = StringUtils.isNotBlank(parentPath) ? parentPath + "/" + name : name; if (visible && isDirectory) { List<IRepositoryObject> children = new ArrayList<IRepositoryObject>(); // List<Node> fileNodes; // if (StringUtils.isBlank(fileType)) { // fileNodes = node.selectNodes("./file[@isDirectory='false']"); // } // else { // fileNodes = node.selectNodes("./file[@isDirectory='false'][ends-with(string(@name),'." + fileType + "') or ends-with(string(@name),'." + fileType + "')]"); // } // for (final Node fileNode : fileNodes) // { // boolean vis = fileNode.valueOf("@visible").equals("true"); // String t = fileNode.valueOf("@localized-name"); // String n = fileNode.valueOf("@name"); // if (vis) { // List<AclMethod> acls = getAcl(path, false); // children.add(new RepositoryFileObject(t, "#" + path + "/" + n, fileType, path + "/" + n, acls)); // } // } children.addAll(processTree(node, path, fileType)); List<AclMethod> acls = getAcl(path, true); repoObjects.add(new RepositoryFolderObject(localizedName, "#" + path, path, acls, children)); } else if (visible && !isDirectory) { if (StringUtils.isBlank(fileType) || name.endsWith(fileType)) { List<AclMethod> acls = getAcl(path, false); repoObjects.add(new RepositoryFileObject(localizedName, "#" + path, fileType, path, acls)); } } } } catch (Exception e) { e.printStackTrace(); } return repoObjects; }
From source file:org.sipfoundry.sipxconfig.vm.DistributionListsReader.java
License:Contributor Agreement License
@Override public DistributionList[] readObject(Document doc) { Node root = doc.getRootElement(); List<Element> nodeLists = root.selectNodes("//distributions/list"); DistributionList[] lists = DistributionList.createBlankList(); for (int i = 0; i < nodeLists.size(); i++) { Node listNode = nodeLists.get(i); DistributionList list = new DistributionList(); List<Node> extensionsNodes = listNode.selectNodes("destination"); String[] extensions = new String[extensionsNodes.size()]; for (int j = 0; j < extensionsNodes.size(); j++) { extensions[j] = extensionsNodes.get(j).getText(); }//from ww w. ja va 2 s . c o m list.setExtensions(extensions); int position = Integer.parseInt(listNode.valueOf("index/text()")); lists[position] = list; } return lists; }
From source file:org.sipfoundry.sipxconfig.vm.MailboxPreferencesReader.java
License:Contributor Agreement License
@Override public MailboxPreferences readObject(Document doc) { MailboxPreferences prefs = new MailboxPreferences(); Node root = doc.getRootElement(); String greetingId = root.valueOf("activegreeting"); MailboxPreferences.ActiveGreeting greeting = MailboxPreferences.ActiveGreeting.fromId(greetingId); prefs.setActiveGreeting(greeting);/*w ww . ja v a 2 s . c o m*/ List<Element> contacts = root.selectNodes("notification/contact"); String emailAddress = getEmailAddress(0, contacts); if (StringUtils.isNotBlank(emailAddress)) { prefs.setEmailAddress(emailAddress); prefs.setAttachVoicemailToEmail(AttachType.YES); prefs.setIncludeAudioAttachment(getAttachVoicemail(0, contacts)); } String alternateEmailAdress = getEmailAddress(1, contacts); if (StringUtils.isNotBlank(alternateEmailAdress)) { prefs.setAlternateEmailAddress(alternateEmailAdress); prefs.setVoicemailToAlternateEmailNotification(AttachType.YES); prefs.setIncludeAudioAttachmentAlternateEmail(getAttachVoicemail(1, contacts)); } return prefs; }
From source file:org.sipfoundry.sipxivr.MailboxPreferencesReader.java
License:Contributor Agreement License
@Override public MailboxPreferences readObject(Document doc) { MailboxPreferences prefs = new MailboxPreferences(); Node root = doc.getRootElement(); String greetingId = root.valueOf("activegreeting"); GreetingType greeting = GreetingType.valueOfById(greetingId); prefs.getActiveGreeting().setGreetingType(greeting); return prefs; }
From source file:org.springbyexample.enterprise.solr.CatalogItemMarshaller.java
License:Apache License
/** * Implementation of <code>Unmarshaller</code> *//*from w ww . j a va 2 s . c o m*/ @SuppressWarnings("unchecked") public Object unmarshal(Source source) throws XmlMappingException, IOException { List<CatalogItem> lResults = new ArrayList<CatalogItem>(); if (source instanceof StreamSource) { InputStream in = null; try { in = ((StreamSource) source).getInputStream(); SAXReader reader = new SAXReader(); Document document = reader.read(in); List<Node> lNodes = document.selectNodes("//response/result[@name='response']/doc/*"); CatalogItem item = null; // loop over all matching nodes in order, so can create a new bean // instance on the first match and add it to the results on the last for (Node node : lNodes) { if (BooleanUtils.toBoolean(node.valueOf("./@name='id'"))) { item = new CatalogItem(); item.setId(node.getText()); } else if (BooleanUtils.toBoolean(node.valueOf("./@name='inStock'"))) { item.setInStock(BooleanUtils.toBoolean(node.getText())); } else if (BooleanUtils.toBoolean(node.valueOf("./@name='manu'"))) { item.setManufacturer(node.getText()); } else if (BooleanUtils.toBoolean(node.valueOf("./@name='name'"))) { item.setName(node.getText()); } else if (BooleanUtils.toBoolean(node.valueOf("./@name='popularity'"))) { item.setPopularity(Integer.parseInt(node.getText())); } else if (BooleanUtils.toBoolean(node.valueOf("./@name='price'"))) { item.setPrice(Float.parseFloat(node.getText())); lResults.add(item); } } } catch (DocumentException e) { throw new UnmarshallingFailureException(e.getMessage(), e); } finally { IOUtils.closeQuietly(in); } logger.debug("Unmarshalled bean of size {}.", lResults.size()); } return lResults; }
From source file:org.springfield.flanders.restlet.FlandersResource.java
License:Open Source License
@Post public void handlePost(Representation representation) { String xml = ""; log.info("entering the POST!!!!!"); try {// w w w . j a va 2s .c om if (representation == null) { getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST); getResponse().setEntity("<status>Error: the request data could not be read</status>", MediaType.TEXT_XML); } else { xml = representation.getText(); } } catch (IOException e2) { e2.printStackTrace(); return; } System.out.println("REPRESENTATION: " + xml); if (representation != null && xml != null) { Document document = null; try { document = DocumentHelper.parseText(xml); } catch (DocumentException e1) { e1.printStackTrace(); } Node node = document.selectSingleNode("//root"); String mount = node.valueOf("mount"); String source = node.valueOf("source"); String stream = node.valueOf("stream"); String filename = node.valueOf("file"); String mjpegIndex = node.valueOf("index"); if (mjpegIndex != null && mjpegIndex.equals("true") && mount != null && source != null) { MountProperties mp = LazyHomer.getMountProperties(mount); if (mp != null) { String response = MjpegIndexer.extractMetaData(source, mp.getPath()); getResponse().setEntity(new StringRepresentation(response)); } else { getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); getResponse().setEntity("<status>Error: internal mount properties not found</status>", MediaType.TEXT_XML); } } else if (source != null && mount != null) { if (!mount.equals("")) { MountProperties mp = LazyHomer.getMountProperties(mount); if (mp.getProtocol().equals("file")) { source = mp.getPath() + source; } else if (mp.getProtocol().equals("ftp")) { /** get the video file from streaming machines to the the flanders server */ String fileName = source.substring(source.lastIndexOf("/") + 1); String rawUri = source.substring(0, source.lastIndexOf("/")); String vidUri = rawUri.substring(0, rawUri.lastIndexOf("/rawvideo/") + 1); if (getVideoByFtp(mp.getHostname(), mp.getAccount(), mp.getPassword(), fileName, mp.getPath(), rawUri, vidUri)) { source = mp.getPath() + vidUri + File.separator + fileName; } } } String ext = FileHelper.getFileExtension(source); if (ext != null) { String response = FfprobeMetaDataExtractor.extractMetaData(source); getResponse().setEntity(new StringRepresentation(response)); } else { getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST); getResponse().setEntity("<status>Error: incorrect parameters</status>", MediaType.TEXT_XML); } } else if (stream != null && filename != null) { String response = RtmpdumpMetadataExtractor.extractMetaData(stream, filename); getResponse().setEntity(new StringRepresentation(response)); } else { getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST); getResponse().setEntity("<status>Error: incorrect parameters</status>", MediaType.TEXT_XML); } } }
From source file:pt.lsts.neptus.mp.maneuvers.CompassCalibration.java
License:Open Source License
@Override public void loadFromXML(String xml) { try {/* w w w.ja v a 2 s .c o m*/ Document doc = DocumentHelper.parseText(xml); Node node = doc.selectSingleNode(DEFAULT_ROOT_ELEMENT + "/finalPoint/point"); if (node == null) node = doc.selectSingleNode(DEFAULT_ROOT_ELEMENT + "/initialPoint/point"); // to read old elevator specs ManeuverLocation loc = new ManeuverLocation(); loc.load(node.asXML()); setManeuverLocation(loc); Node pitchNode = doc.selectSingleNode(DEFAULT_ROOT_ELEMENT + "/pitch"); pitchDegs = Double.parseDouble(pitchNode.getText()); Node amplitudeNode = doc.selectSingleNode(DEFAULT_ROOT_ELEMENT + "/amplitude"); amplitude = Double.parseDouble(amplitudeNode.getText()); Node durationNode = doc.selectSingleNode(DEFAULT_ROOT_ELEMENT + "/duration"); duration = Integer.parseInt(durationNode.getText()); Node speedNode = doc.selectSingleNode(DEFAULT_ROOT_ELEMENT + "/speed"); speed = Double.parseDouble(speedNode.getText()); speedUnits = speedNode.valueOf("@unit"); radius = Float.parseFloat(doc.selectSingleNode(DEFAULT_ROOT_ELEMENT + "/radius").getText()); } catch (Exception e) { NeptusLog.pub().error(this, e); return; } }
From source file:pt.lsts.neptus.mp.maneuvers.ManeuversXMLUtil.java
License:Open Source License
public static Maneuver.SPEED_UNITS parseSpeedUnits(Element root) { Node speedNode = root.selectSingleNode("//speed"); if (speedNode == null) speedNode = root.selectSingleNode("//velocity"); // Is deprecated but to load old defs SPEED_UNITS speedUnits = SPEED_UNITS.parse(speedNode.valueOf("@unit")); return speedUnits; }
From source file:pt.lsts.neptus.mp.maneuvers.ManeuversXMLUtil.java
License:Open Source License
public static <M extends Maneuver> double parseSpeed(Element root, M maneuver) throws Exception { Node speedNode = root.selectSingleNode("//speed"); if (speedNode == null) speedNode = root.selectSingleNode("//velocity"); // Is deprecated but to load old defs double speed = Double.parseDouble(speedNode.getText()); SPEED_UNITS speedUnits = SPEED_UNITS.parse(speedNode.valueOf("@unit")); Field sField = getFieldByName(maneuver, "Speed"); if (sField == null) sField = getFieldByName(maneuver, "speed"); sField.set(maneuver, speed);// ww w . ja va 2s .co m Field sUField = getFieldByName(maneuver, "Speed Units"); if (sUField == null) sUField = getFieldByName(maneuver, "Speed units"); if (sUField == null) sUField = getFieldByName(maneuver, "speed units"); if (sUField == null) sUField = getFieldByName(maneuver, "speedUnits"); sUField.set(maneuver, speedUnits); return speed; }