List of usage examples for org.dom4j Node getStringValue
String getStringValue();
From source file:com.mindquarry.desktop.model.team.TeamTransformer.java
License:Open Source License
@Path("/teamspace/name") public void name(Node node) { team.setName(node.getStringValue().trim()); }
From source file:com.mindquarry.desktop.model.team.TeamTransformer.java
License:Open Source License
@Path("/teamspace/id") public void id(Node node) { team.setId(node.getStringValue().trim()); }
From source file:com.taobao.android.builder.tools.manifest.AtlasProxy.java
License:Apache License
public static void addAtlasProxyClazz(Document document, Set<String> nonProxyChannels, Result result) { Element root = document.getRootElement();// List<? extends Node> serviceNodes = root.selectNodes("//@android:process"); String packageName = root.attribute("package").getStringValue(); Set<String> processNames = new HashSet<>(); processNames.add(packageName);// w w w. j ava 2 s. c om for (Node node : serviceNodes) { if (null != node && StringUtils.isNotEmpty(node.getStringValue())) { String value = node.getStringValue(); processNames.add(value); } } processNames.removeAll(nonProxyChannels); List<String> elementNames = Lists.newArrayList("activity", "service", "provider"); Element applicationElement = root.element("application"); for (String processName : processNames) { boolean isMainPkg = packageName.equals(processName); //boolean isMainPkg = true; String processClazzName = processName.replace(":", "").replace(".", "_"); for (String elementName : elementNames) { String fullClazzName = "ATLASPROXY_" + (isMainPkg ? "" : (packageName.replace(".", "_") + "_")) + processClazzName + "_" + StringUtils.capitalize(elementName); if ("activity".equals(elementName)) { result.proxyActivities.add(fullClazzName); } else if ("service".equals(elementName)) { result.proxyServices.add(fullClazzName); } else { result.proxyProviders.add(fullClazzName); } Element newElement = applicationElement.addElement(elementName); newElement.addAttribute("android:name", ATLAS_PROXY_PACKAGE + "." + fullClazzName); if (!packageName.equals(processName)) { newElement.addAttribute("android:process", processName); } boolean isProvider = "provider".equals(elementName); if (isProvider) { newElement.addAttribute("android:authorities", ATLAS_PROXY_PACKAGE + "." + fullClazzName); } } } }
From source file:com.thesmartweb.swebrank.Sensebot.java
License:Apache License
/** * Method that connects to the Sensebot url and gets the document using SAXReader * @param link_ur the link to read from// ww w.j a va 2s . c o m * @return the response in a string */ public String connect(URL link_ur) { try { SAXReader reader = new SAXReader(); Document document = reader.read(link_ur); Element root = document.getRootElement(); List<Node> content = root.content(); String stringValue = ""; if (!(content.isEmpty()) && content.size() > 1) { Node get = content.get(1); stringValue = get.getStringValue(); DataManipulation tp = new DataManipulation(); stringValue = tp.removeChars(stringValue).toLowerCase(); } return stringValue; } catch (DocumentException ex) { Logger.getLogger(Sensebot.class.getName()).log(Level.SEVERE, null, ex); String output = ""; return output; } }
From source file:com.vsiwest.usecase.UseCaseView.java
public void inject(File event) { Collection<UseCase> dupes; SAXReader reader = new SAXReader(); Document document = null;/* ww w . j ava 2s. c o m*/ try { document = reader.read(event); } catch (DocumentException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } assert document != null; List<? extends Object> actorsElements = document.selectNodes(ACTORS_XPATH); for (Object actorsElement : actorsElements) { Element element = (Element) actorsElement; String id = element.attributeValue("xmi.id"); String name = element.attributeValue("name"); Actor actor = new Actor(id, name); actors.put(id, actor); } List<? extends Object> usecaseElements = document.selectNodes(USECASESXPATH); for (Object usecaseElement : usecaseElements) { Element element = (Element) usecaseElement; String id = element.attributeValue("xmi.id"); String name = element.attributeValue("name"); UseCase usecase; usecase = new UseCase(id, name); usecases.put(id, usecase); } List<? extends Object> list = document.selectNodes(EXTENSIONSXPATH); for (Object aList1 : list) { Element element = (Element) aList1; String uniquePath = element.getUniquePath(); Node parent = document.selectSingleNode(uniquePath + "/UML:Extend.base/UML:UseCase/@xmi.idref"); Node child = document.selectSingleNode(uniquePath + "/UML:Extend.extension/UML:UseCase/@xmi.idref"); String stringValue = parent.getStringValue(); UseCase p = usecases.get(stringValue); UseCase c = usecases.get(child.getStringValue()); c.parents.add(p); } list = document.selectNodes(INCLUDESXPATH); for (Object aList : list) { Element element = (Element) aList; Node parent = document .selectSingleNode(element.getUniquePath() + "/UML:Include.base/UML:UseCase/@xmi.idref"); Node child = document .selectSingleNode(element.getUniquePath() + "/UML:Include.addition/UML:UseCase/@xmi.idref"); UseCase useCase = usecases.get(parent.getStringValue()); UseCase i = usecases.get(child.getStringValue()); useCase.includes.add(i); } list = document.selectNodes(ASSOCIATIONSXPATH); /* /UML:Association.connection/UML:AssociationEnd/UML:AssociationEnd.participant/UML:Actor */ for (Object aList2 : list) { Element element = (Element) aList2; Node parent = document.selectSingleNode(element.getUniquePath() + "/UML:Association.connection/UML:AssociationEnd/UML:AssociationEnd.participant/UML:Actor/@xmi.idref"); Node child = document.selectSingleNode(element.getUniquePath() + "/UML:Association.connection/UML:AssociationEnd/UML:AssociationEnd.participant/UML:UseCase/@xmi.idref"); Actor actor = actors.get(parent.getStringValue()); UseCase i = usecases.get(child.getStringValue()); actor.usecases.add(i); } document.selectNodes(ASSOCIATIONSXPATH); usecaseTree.setShowsRootHandles(true); // usecaseTree.setRootVisible(false); dupes = new HashSet<UseCase>(); for (Actor actor : actors.values()) { DefaultMutableTreeNode actorNode = new DefaultMutableTreeNode(actor); root.add(actorNode); for (UseCase useCase : actor.usecases) { decorateUseCaseNode(useCase, actorNode, dupes); } } }
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 www .j av a 2s.c o 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:de.bbe_consulting.mavento.AbstractArchetypeMojo.java
License:Apache License
protected String getXmlNodeValueFromPom(String xpathNode, Document pom) throws MojoExecutionException { DefaultXPath path = new DefaultXPath(xpathNode); Map<String, String> namespaces = new TreeMap<String, String>(); namespaces.put("x", "http://maven.apache.org/POM/4.0.0"); path.setNamespaceURIs(namespaces);//from ww w .j a va2 s . com Node n = path.selectSingleNode(pom.getRootElement()); return n.getStringValue(); }
From source file:dk.netarkivet.common.utils.SimpleXml.java
License:Open Source License
/** * Get the first entry that matches the key. Keys are constructed as a dot separated path of xml tag names. Example: * The following XML definition of a user name <dk><netarkivet><user>ssc</user> * </netarkivet></dk> is accessed using the path: "dk.netarkivet.user" * * @param key the key of the entry./*from ww w. ja va 2 s . c o m*/ * @return the first entry that matches the key. * @throws UnknownID if no element matches the key * @throws ArgumentNotValid if the key is null or empty */ public String getString(String key) { ArgumentNotValid.checkNotNullOrEmpty(key, "key"); XPath xpath = getXPath(key); List<Node> nodes = xpath.selectNodes(xmlDoc); if (nodes == null || nodes.size() == 0) { throw new UnknownID("No elements exists for the path '" + key + "' in '" + source + "'"); } Node first = nodes.get(0); return first.getStringValue().trim(); }
From source file:edu.ku.brc.specify.config.ResourceImportExportDlg.java
License:Open Source License
/** * Imports a report resource from a zip file (see writeReportResToZipFile()) * /* w w w . jav a 2 s . com*/ * If resource contains an SpReport, the SpReport's data source query will be imported * as well if an equivalent query does not exist in the database. * * @param file * @param appRes * @param dirArg * @param newResName * @return */ protected SpAppResource importSpReportZipResource(final File file, final SpAppResource appRes, final SpAppResourceDir dirArg, final String newResName) { SpAppResourceDir dir = dirArg; try { ZipInputStream zin = new ZipInputStream(new FileInputStream(file)); //Assuming they come out in the order they were put in. ZipEntry entry = zin.getNextEntry(); if (entry == null) { throw new Exception(getResourceString("RIE_ReportImportFileError")); } String app = readZipEntryToString(zin, entry); zin.closeEntry(); entry = zin.getNextEntry(); if (entry == null) { throw new Exception(getResourceString("RIE_ReportImportFileError")); } String data = readZipEntryToString(zin, entry); zin.closeEntry(); Element appRoot = XMLHelper.readStrToDOM4J(app); Node metadata = appRoot.selectSingleNode("metadata"); String metadataStr = metadata.getStringValue(); if (!metadataStr.endsWith(";")) { metadataStr += ";"; } Node mimeTypeNode = appRoot.selectSingleNode("mimetype"); String mimeTypeStr = mimeTypeNode != null ? mimeTypeNode.getStringValue().trim() : null; entry = zin.getNextEntry(); if (entry != null) { appRes.setDataAsString(data); appRes.setMetaData(metadataStr.trim()); String repType = appRes.getMetaDataMap().getProperty("reporttype"); String mimeType = mimeTypeStr != null ? mimeTypeStr : repType != null && repType.equalsIgnoreCase("label") ? "jrxml/label" : "jrxml/report"; appRes.setMimeType(mimeType); appRes.setLevel((short) 3);//XXX level????????????????? String spReport = readZipEntryToString(zin, entry); zin.closeEntry(); zin.close(); Element repElement = XMLHelper.readStrToDOM4J(spReport); SpReport report = new SpReport(); report.initialize(); report.setSpecifyUser(contextMgr.getClassObject(SpecifyUser.class)); report.fromXML(repElement, newResName != null, contextMgr); if (newResName != null) { report.setName(newResName); } appRes.setName(report.getName()); appRes.setDescription(appRes.getName()); if (newResName != null && report.getQuery() != null) { showLocalizedMsg("RIE_ReportNewQueryTitle", "RIE_ReportNewQueryMsg", report.getQuery().getName(), report.getName()); } report.setAppResource((SpAppResource) appRes); ((SpAppResource) appRes).getSpReports().add(report); DataProviderSessionIFace session = null; try { session = DataProviderFactory.getInstance().createSession(); session.beginTransaction(); if (dir.getId() != null) { dir = session.get(SpAppResourceDir.class, dir.getId()); } dir.getSpPersistedAppResources().add(appRes); appRes.setSpAppResourceDir(dir); if (report.getReportObject() != null && report.getReportObject().getId() == null) { session.saveOrUpdate(report.getReportObject()); } session.saveOrUpdate(dir); session.saveOrUpdate(appRes); session.saveOrUpdate(report); session.commit(); completeMsg = getLocalizedMessage("RIE_RES_IMPORTED", file.getName()); } catch (Exception ex) { session.rollback(); //ex.printStackTrace(); throw ex; } finally { if (session != null) session.close(); } } } catch (Exception e) { e.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ResourceImportExportDlg.class, e); return null; } return appRes; }
From source file:edu.ucsd.library.dams.jhove.MyJhoveBase.java
License:Open Source License
/** * Given INP//from w ww. j a va 2 s . c om * @param kobj * @throws DocumentException * @throws ParseException */ public void parseXml(JhoveInfo kobj, StringWriter swriter) throws DocumentException, ParseException { StringBuffer xmldata = new StringBuffer(swriter.toString()); kobj.setMetaxml(xmldata); Document jdoc = DocumentHelper.parseText(xmldata.toString()); Element root = jdoc.getRootElement(); removeNS(root); String statusstr = jdoc.valueOf("/jhove/repInfo/status"); //kobj.setStatus(statusstr); if (/*statusstr.indexOf("not valid") != -1 || */statusstr.indexOf("Not well-formed") != -1) { kobj.setValid(false); } else { kobj.setValid(true); } kobj.setCheckSum_CRC32(jdoc.valueOf("/jhove/repInfo/checksums/checksum[@type='CRC32']")); kobj.setChecksum_MD5(jdoc.valueOf("/jhove/repInfo/checksums/checksum[@type='MD5']")); kobj.setChecksum_SHA(jdoc.valueOf("/jhove/repInfo/checksums/checksum[@type='SHA-1']")); kobj.setMIMEtype(jdoc.valueOf("/jhove/repInfo/mimeType")); kobj.setSize(Long.parseLong(jdoc.valueOf("/jhove/repInfo/size"))); //try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); kobj.setDateModified(sdf.parse(jdoc.valueOf("/jhove/repInfo/lastModified"))); String format = jdoc.valueOf("/jhove/repInfo/format"); kobj.setFormat(format); if (format.equalsIgnoreCase("MP3")) { String layer = jdoc.valueOf( "/jhove/repInfo/properties/property/values/property[name='LayerDescription']/values/value"); String version = jdoc.valueOf( "/jhove/repInfo/properties/property/values/property[name='MPEG Audio Version ID']/values/value"); kobj.setVersion(version + ", Layer " + layer); } else { kobj.setVersion(jdoc.valueOf("/jhove/repInfo/version")); } kobj.setReportingModule(jdoc.valueOf("/jhove/repInfo/reportingModule")); String status = kobj.getStatus(); if ((status == null || status.length() == 0) || !"BYTESTREAM".equalsIgnoreCase(format)) kobj.setStatus(statusstr); // image resolution String imageWidth = jdoc.valueOf("//imageWidth"); String imageLength = jdoc.valueOf("//imageHeight"); if (imageWidth != null && imageLength != null && imageWidth.length() > 0) { kobj.setQuality(imageWidth + "x" + imageLength); } // WAV bit/sample/channels String abits1 = jdoc.valueOf("//bitDepth"); String afreq1 = jdoc.valueOf("//sampleRate"); String achan1 = jdoc.valueOf("//numChannels"); if (nblank(abits1) || nblank(afreq1) || nblank(achan1)) { String qual = audioQuality(abits1, afreq1, "Hz", achan1); kobj.setQuality(qual); } // MP3 bit/sample/channels String abits2 = valueOf(jdoc, "Bitrate Index"); String afreq2 = valueOf(jdoc, "Sampling rate frequency Index"); String achan2 = valueOf(jdoc, "Channel Mode"); if (nblank(abits2) || nblank(afreq2) || nblank(achan2)) { String qual = audioQuality(abits2, afreq2, "kHz", achan2); kobj.setQuality(qual); } List resultnodes = jdoc.selectNodes("/jhove/repInfo/messages/message[@severity='error']"); for (int r = 0; resultnodes != null && r < resultnodes.size(); r++) { Object noderesult = resultnodes.get(r); if (noderesult instanceof Node) { Node nt = (Node) noderesult; kobj.setMessage(nt.getStringValue()); } } }