private void updateAlias(String includeOrigin, String includeDestination, File ear) throws JDOMException, IOException, JDOMException { TFile xmlTIBCO = new TFile(ear.getAbsolutePath() + File.separator + "TIBCO.xml"); String tempPath = ear.getParentFile().getAbsolutePath() + File.separator + "TIBCO.xml"; TFile xmlTIBCOTemp = new TFile(tempPath); truezip.copyFile(xmlTIBCO, xmlTIBCOTemp); File xmlTIBCOFile = new File(tempPath); SAXBuilder sxb = new SAXBuilder(); Document document = sxb.build(xmlTIBCOFile); XPath xpa = XPath.newInstance("//dd:NameValuePairs/dd:NameValuePair[starts-with(dd:name, 'tibco.alias') and dd:value='" + includeOrigin + "']/dd:value"); xpa.addNamespace("dd", "http://www.tibco.com/xmlns/dd"); Element singleNode = (Element) xpa.selectSingleNode(document); if (singleNode != null) { singleNode.setText(includeDestination); XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat().setIndent(" ")); xmlOutput.output(document, new FileWriter(xmlTIBCOFile)); truezip.copyFile(xmlTIBCOTemp, xmlTIBCO); } updateAliasInPARs(includeOrigin, includeDestination, ear); }
private void updateAliasInPARs(String includeOrigin, String includeDestination, File ear) throws IOException, JDOMException { TrueZipFileSet pars = new TrueZipFileSet(); pars.setDirectory(ear.getAbsolutePath()); pars.addInclude("*.par"); List<TFile> parsXML = truezip.list(pars); for (TFile parXML : parsXML) { TFile xmlTIBCO = new TFile(parXML, "TIBCO.xml"); String tempPath = ear.getParentFile().getAbsolutePath() + File.separator + "TIBCO.xml"; TFile xmlTIBCOTemp = new TFile(tempPath); truezip.copyFile(xmlTIBCO, xmlTIBCOTemp); File xmlTIBCOFile = new File(tempPath); SAXBuilder sxb = new SAXBuilder(); Document document = sxb.build(xmlTIBCOFile); XPath xpa = XPath.newInstance("//dd:NameValuePairs/dd:NameValuePair[dd:name='EXTERNAL_JAR_DEPENDENCY']/dd:value"); xpa.addNamespace("dd", "http://www.tibco.com/xmlns/dd"); Element singleNode = (Element) xpa.selectSingleNode(document); if (singleNode != null) { String value = singleNode.getText().replace(includeOrigin, includeDestination); singleNode.setText(value); XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat().setIndent(" ")); xmlOutput.output(document, new FileWriter(xmlTIBCOFile)); truezip.copyFile(xmlTIBCOTemp, xmlTIBCO); } } }
/** * Retrieves the text elements for a given xpath expression * * @param xPathExpression * @return */ public ArrayList<String> GetElementList(String xPathExpression) { try { ArrayList<String> values = new ArrayList<String>(); List<?> nodeList = XPath.selectNodes(this.xmlDocument, xPathExpression); Iterator<?> iter = nodeList.iterator(); while (iter.hasNext()) { org.jdom.Element element = (org.jdom.Element) iter.next(); values.add(element.getText()); } return values; } catch (Exception ex) { LOG.error("Error in handler: " + ex.getMessage(), ex); return null; } }
public double getMoleculeMass(String a_strType, boolean a_bMonoisotopic) throws Exception, ParameterException { XPath xpath = XPath.newInstance("/defaults/molecules/small_molecules"); for (Iterator t_iterPersub = xpath.selectNodes( this.m_docDefaultMasses ).iterator(); t_iterPersub.hasNext();) { Element t_objElementMain = (Element) t_iterPersub.next(); if ( t_objElementMain.getChild("name").getTextTrim().equals(a_strType) ) { Element t_objElementMass = null; if ( a_bMonoisotopic ) { t_objElementMass = t_objElementMain.getChild("mass_mono"); } else { t_objElementMass = t_objElementMain.getChild("mass_avg"); } return Double.parseDouble(t_objElementMass.getTextTrim()); } } throw new ParameterException("Unknown small molecule."); }
public double getIonMass(String a_strIon, boolean a_bMonoisotopic) throws ParameterException, Exception { XPath xpath = XPath.newInstance("/defaults/ions/ion"); for (Iterator t_iterIon = xpath.selectNodes( this.m_docDefaultMasses ).iterator(); t_iterIon.hasNext();) { Element t_objElementMain = (Element) t_iterIon.next(); if ( t_objElementMain.getChild("formula").getTextTrim().equals(a_strIon) ) { Element t_objElementMass = null; if ( a_bMonoisotopic ) { t_objElementMass = t_objElementMain.getChild("mass_mono"); } else { t_objElementMass = t_objElementMain.getChild("mass_avg"); } return (Double.parseDouble(t_objElementMass.getTextTrim()) - this.getMassE(a_bMonoisotopic)); } } throw new ParameterException("Unknown ion."); }
/** * Gives the mass of the increment * * @param a_strPerSub type of persubstitution * @param a_bMonoIsotopic true if monoisotopic mass * @return * @throws JDOMException * @throws ParameterException thrown if type of persubstitution is unknown */ public double getIncrementMass(Persubstitution a_strPerSub , boolean a_bMonoIsotopic) throws ParameterException, Exception { XPath xpath = XPath.newInstance("/defaults/persubstitutions/persubstitution"); for (Iterator t_iterPersub = xpath.selectNodes( this.m_docDefaultMasses ).iterator(); t_iterPersub.hasNext();) { Element t_objElementPersub = (Element) t_iterPersub.next(); if ( t_objElementPersub.getChild("name").getTextTrim().equals(a_strPerSub.getAbbr()) ) { Element t_objElementMass = null; if ( a_bMonoIsotopic ) { t_objElementMass = t_objElementPersub.getChild("increment_mono"); } else { t_objElementMass = t_objElementPersub.getChild("increment_avg"); } return Double.parseDouble(t_objElementMass.getTextTrim()); } } throw new ParameterException("Unknown persubstitution."); }
/** * Gives the mass of the increment for A/X fragments * * @param a_strPerSub type of persubstitution * @param a_bMonoIsotopic true if monoisotopic mass * @return * @throws JDOMException * @throws ParameterException thrown if type of persubstitution is unknown */ public double getIncrementMassAX(Persubstitution a_strPerSub , boolean a_bMonoIsotopic) throws ParameterException, Exception { XPath xpath = XPath.newInstance("/defaults/persubstitutions/persubstitution"); for (Iterator t_iterPersub = xpath.selectNodes( this.m_docDefaultMasses ).iterator(); t_iterPersub.hasNext();) { Element t_objElementPersub = (Element) t_iterPersub.next(); if ( t_objElementPersub.getChild("name").getTextTrim().equals(a_strPerSub.getAbbr()) ) { if ( a_bMonoIsotopic ) { return ( Double.parseDouble(t_objElementPersub.getChild("increment_mono").getTextTrim()) - Double.parseDouble(t_objElementPersub.getChild("mono").getTextTrim())); } else { return ( Double.parseDouble(t_objElementPersub.getChild("increment_avg").getTextTrim()) - Double.parseDouble(t_objElementPersub.getChild("avg").getTextTrim())); } } } throw new ParameterException("Unknown persubstitution."); }
public double getNonReducingDifference(Persubstitution a_objPersub, boolean a_bMonoisotopic) throws ParameterException, Exception { XPath xpath = XPath.newInstance("/defaults/persubstitutions/persubstitution"); for (Iterator t_iterPersub = xpath.selectNodes( this.m_docDefaultMasses ).iterator(); t_iterPersub.hasNext();) { Element t_objElementPersub = (Element) t_iterPersub.next(); if ( t_objElementPersub.getChild("name").getTextTrim().equals(a_objPersub.getAbbr()) ) { Element t_objElementMass = null; if ( a_bMonoisotopic ) { t_objElementMass = t_objElementPersub.getChild("ergaenzung_nonred_mono"); } else { t_objElementMass = t_objElementPersub.getChild("ergaenzung_nonred_avg"); } if ( t_objElementMass == null ) { throw new ParameterException("Unknown persubstitution type."); } return Double.parseDouble(t_objElementMass.getTextTrim()); } } throw new ParameterException("Unknown persubstitution type."); }
private void preProcessResources(Element the_manifest, DefaultHandler the_handler) { XPath path; List<Attribute> results; try { path = XPath.newInstance(FILE_QUERY); path.addNamespace(ns.getNs()); results = path.selectNodes(the_manifest); for (Attribute result : results) { the_handler.preProcessFile(result.getValue()); } } catch (JDOMException | ClassCastException e) { log.info("Error processing xpath for files", e); } }
/** * Converts XML affiliations into map of avro objects. * Never returns null. * @param source main XML element */ private static Map<String, Affiliation> convertAffiliations(Element source) { try { XPath xPath = XPath.newInstance("/article/front//contrib-group/aff"); @SuppressWarnings("unchecked") List<Element> nodeList = xPath.selectNodes(source); if (nodeList == null || nodeList.isEmpty()) { return Collections.emptyMap(); } Map<String, Affiliation> affiliations = new LinkedHashMap<String, Affiliation>(); for (Element node : nodeList) { CermineAffiliation cAff = cermineAffiliationBuilder.build(node); affiliations.put(node.getAttributeValue("id"), cermineToMetadataAffConverter.convert(cAff)); } return affiliations; } catch (JDOMException ex) { return Collections.emptyMap(); } }
@Override protected String getPortInfo() { String portInfo = getProperty("jetty.port"); if (!StringUtil.isEmptyOrSpaces(portInfo)) return portInfo; try { final String portPath = "connectors/connector/port"; List list = XPath.selectNodes(plugin.getConfigurationElement(), portPath); for (Object e : list) { Content content = (Content) e; if (!StringUtil.isEmptyOrSpaces(content.getValue())) { return content.getValue(); } } } catch (JDOMException ignore) { } return super.getPortInfo(); }
private Task[] getCases(String q) throws Exception { HttpClient client = login(getLoginMethod()); PostMethod method = new PostMethod(getUrl() + "/api.asp"); method.addParameter("token", token); method.addParameter("cmd", "search"); method.addParameter("q", q); method.addParameter("cols", "sTitle,fOpen,dtOpened,dtLastUpdated,ixCategory"); int status = client.executeMethod(method); if (status != 200) { throw new Exception("Error listing cases: " + method.getStatusLine()); } Document document = new SAXBuilder(false).build(method.getResponseBodyAsStream()).getDocument(); XPath path = XPath.newInstance("/response/cases/case"); final XPath commentPath = XPath.newInstance("events/event"); @SuppressWarnings("unchecked") final List<Element> nodes = (List<Element>)path.selectNodes(document); final List<Task> tasks = ContainerUtil.mapNotNull(nodes, new NotNullFunction<Element, Task>() { @NotNull @Override public Task fun(Element element) { return createCase(element, commentPath); } }); return tasks.toArray(new Task[tasks.size()]); }
private HttpClient login(PostMethod method) throws Exception { HttpClient client = getHttpClient(); int status = client.executeMethod(method); if (status != 200) { throw new Exception("Error logging in: " + method.getStatusLine()); } Document document = new SAXBuilder(false).build(method.getResponseBodyAsStream()).getDocument(); XPath path = XPath.newInstance("/response/token"); Element result = (Element)path.selectSingleNode(document); if (result == null) { Element error = (Element)XPath.newInstance("/response/error").selectSingleNode(document); throw new Exception(error == null ? "Error logging in" : error.getText()); } token = result.getTextTrim(); return client; }
@Test public void testVersions() throws Exception { XPath xpath = XPath.newInstance("/ns:project/ns:properties"); xpath.addNamespace(Namespace.getNamespace("ns", "http://maven.apache.org/POM/4.0.0")); Element node = (Element) xpath.selectSingleNode(wfcRoot); for (Object child : node.getChildren()) { String wfcKey = ((Element) child).getName(); String wfcVal = ((Element) child).getText(); String targetVal = getTargetValue(wfcKey); if (targetVal != null) { if (!targetVal.equals(wfcVal) && !targetVal.startsWith(wfcVal + ".redhat")) { problems.add(wfcKey + ": " + wfcVal + " => " + targetVal); } } } for (String line : problems) { System.err.println(line); } Assert.assertEquals("Mapping problems", Collections.emptyList(), problems); }
public String getTargetValue(String wfcKey) throws JDOMException { Element rootNode; if (wfcKey.startsWith("version.camel.")) { rootNode = camelRoot; } else if (wfcKey.startsWith("version.wildfly.")) { rootNode = wfRoot; } else { return null; } String targetKey = mapping.get(wfcKey); if (targetKey == null) { problems.add("Cannot find mapping for: " + wfcKey); return null; } XPath xpath = XPath.newInstance("/ns:project/ns:properties/ns:" + targetKey); xpath.addNamespace(Namespace.getNamespace("ns", "http://maven.apache.org/POM/4.0.0")); Element propNode = (Element) xpath.selectSingleNode(rootNode); if (propNode == null) { problems.add("Cannot obtain target property: " + targetKey); return null; } return propNode.getText(); }
public void removeSubmitter(Submitter submitterToRemove) { log.warn("removeSubmitter() instructed to remove submitter from document: "+submitterToRemove.getName()); SubmitterJDOM jdomSubmitter = getSubmitterJDOM(submitterToRemove.getId()); jdomSubmitter.getElement().detach(); submitters.remove(submitterToRemove.getId()); // invalidate links to this submitter try { List references = XPath.selectNodes(doc, "//*[@REF=\""+submitterToRemove.getId()+"\"]"); log.debug("while removing submitter("+submitterToRemove.getId()+"), found these references:"+references); for (Iterator iter = references.iterator(); iter.hasNext();) { Element element = (Element) iter.next(); element.detach(); } } catch (JDOMException e) { // TODO Auto-generated catch block e.printStackTrace(); } update(this, submitterToRemove); }
public void removeIndividual(Individual individualToRemove) { log.warn("removeIndividual() instructed to remove individual from document: "+individualToRemove.getFullName()); IndividualJDOM jdomIndividual = getIndividualJDOM(individualToRemove.getId()); jdomIndividual.getElement().detach(); individuals.remove(individualToRemove.getId()); if (primaryIndividual.getId().equals(individualToRemove.getId())) { chooseNewPrimaryIndividual(); } // invalidate links to this person // the only links that should exist are in family records try { List references = XPath.selectNodes(doc, "//*[@REF=\""+individualToRemove.getId()+"\"]"); log.debug("while removing individual("+individualToRemove.getId()+"), found these references:"+references); for (Iterator iter = references.iterator(); iter.hasNext();) { Element element = (Element) iter.next(); element.detach(); } } catch (JDOMException e) { // TODO Auto-generated catch block e.printStackTrace(); } update(this, individualToRemove); }
public void removeFamily (Family familyToRemove) { log.warn("removeFamily() instructed to remove family from document: "+familyToRemove.toString()); FamilyJDOM jdomFamily = getFamilyJDOM(familyToRemove.getId()); jdomFamily.getElement().detach(); families.remove(familyToRemove.getId()); // invalidate links to this person // the only links that should exist are in family records try { List references = XPath.selectNodes(doc, "//*[@REF=\""+familyToRemove.getId()+"\"]"); log.debug("while removing family("+familyToRemove.getId()+"), found these references:"+references); for (Iterator iter = references.iterator(); iter.hasNext();) { Element element = (Element) iter.next(); element.detach(); } } catch (JDOMException e) { // TODO Auto-generated catch block e.printStackTrace(); } update(this, familyToRemove); }
private List<String> findProperties(File antFile) throws Exception { SAXBuilder saxBuilder=new SAXBuilder("org.apache.xerces.parsers.SAXParser"); Document jdomDocument=saxBuilder.build(antFile); List<String> propertyNameList = new ArrayList<String>(); List nodeList =XPath.selectNodes(jdomDocument, "//property"); Iterator iter=nodeList.iterator(); while(iter.hasNext()) { Element element=(Element)iter.next(); String propertyName = element.getAttributeValue("name"); if(propertyName!=null) { System.out.println("propertyName:"+propertyName); propertyNameList.add(propertyName); } } return propertyNameList; }
/** * Checks if the path matches for the original element * * @param element * the original element * @param xPath * the path * * @return <code>true</code> if it matches, otherwise <code>false</code> */ protected boolean matchToOriginal(final Element element, final String xPath) { try { @SuppressWarnings("unchecked") final List<Object> l = XPath.selectNodes(element, xPath); for (final Object o : l) { if (element.equals(o)) { return true; } } return false; } catch (final JDOMException e) { return false; } }
private void init() throws IOException { Document request = MyUtils.toDocument(wsdlDoc .generateRequest(parentOperation)); setDocumentation(); String expression = "//*[local-name()='" + name + "'][1]/text()"; try { XPath xp = XPath.newInstance(expression); Text t = (Text) xp.selectSingleNode(request); String value = t.getText(); if (value.equals("?")) { defaultValue = ""; } else if (value.startsWith("cid:")) { binary = true; defaultValue = ""; } else { defaultValue = value; } } catch (JDOMException e) { throw new IOException("Could not read the generated SOAP using " + expression, e); } }
private void setValue() { try { SAXBuilder parser = new SAXBuilder(); Document jdomDoc = parser.build(new ByteArrayInputStream(response .getBytes())); String expression = "//*[local-name()='" + name + "'][1]/text()"; XPath xp = XPath.newInstance(expression); Text t = (Text) xp.selectSingleNode(jdomDoc); if (t != null) value = t.getText(); } catch (JDOMException | IOException e) { logger.error("Could not set value for output " + name, e); } }
/** * Extract all JAR elements from the given JDOM document and add the jars they * reference to the GateClassLoader. * * @param jdomDoc * JDOM document representing a parsed creole.xml file. */ public void addJarsToClassLoader(GateClassLoader gcl, Document jdomDoc) throws IOException { try { XPath jarXPath = XPath.newInstance("//*[translate(local-name(), 'ivy', 'IVY') = 'IVY']"); if (jarXPath.selectNodes(jdomDoc).size() > 0) { throw new IOException("Using Ivy for dependency management is no longer supported"); } } catch (JDOMException e) { throw new IOException("Unable to load plugin", e); } addJarsToClassLoader(gcl, jdomDoc.getRootElement()); }
/** * Selects operations that use interval inputs on the axes listed in the view * * @param view a string containing an ordered subset of xyzt. * @return operations a list of operation elements that use this view * @throws JDOMException * @deprecated */ public ArrayList<NameValuePair> getOperationsByView(String view) throws JDOMException { ArrayList<NameValuePair> ops = new ArrayList<NameValuePair>(); String path = "/lasdata/operations/operation[@intervals='"+view+"']"; XPath xpath = XPath.newInstance(path); for (Iterator nodes = xpath.selectNodes(this).iterator(); nodes.hasNext(); ) { Element op = (Element)nodes.next(); ops.add(new NameValuePair(op.getAttributeValue("name"), op.getAttributeValue("ID"))); } return ops; }
/** * Given the XPath to an operation return the output template that should be processed for this product * @param XPath The path to the operation element (an XPath looks like this: /lasdata/operations/operation[@ID='Plot_2D_XY_zoom'] * @return output_template The name of the template (which will be resolve using the class loader and the backend config information) * @throws JDOMException */ public String getTemplateByXPath(String XPath) throws JDOMException { Element opE = getElementByXPath(XPath); if (opE != null) { return opE.getAttributeValue("output_template"); } else { //TODO configurable default output_template. return "output"; } }
/** * A utility class that returns an element based on the XPath to that element. * @param xpathValue the XPath string of the element to be found. * @return the element specified by the XPath. * @throws JDOMException */ public Element getElementByXPath(String xpathValue) throws JDOMException { // E.g. xpathValue="/lasdata/operations/operation[@ID='Plot']" String xpv = Encode.forJava(xpathValue); Object jdomO = this; XPath xpath = XPath.newInstance(xpv); return (Element) xpath.selectSingleNode(jdomO); }
protected void cleanUpProjectForImport(@NotNull File projectPath) { File dotIdeaFolderPath = new File(projectPath, DIRECTORY_BASED_PROJECT_DIR); if (dotIdeaFolderPath.isDirectory()) { File modulesXmlFilePath = new File(dotIdeaFolderPath, "modules.xml"); if (modulesXmlFilePath.isFile()) { SAXBuilder saxBuilder = new SAXBuilder(); try { Document document = saxBuilder.build(modulesXmlFilePath); XPath xpath = XPath.newInstance("//*[@fileurl]"); //noinspection unchecked List<Element> modules = xpath.selectNodes(document); int urlPrefixSize = "file://$PROJECT_DIR$/".length(); for (Element module : modules) { String fileUrl = module.getAttributeValue("fileurl"); if (!StringUtil.isEmpty(fileUrl)) { String relativePath = toSystemDependentName(fileUrl.substring(urlPrefixSize)); File imlFilePath = new File(projectPath, relativePath); if (imlFilePath.isFile()) { delete(imlFilePath); } // It is likely that each module has a "build" folder. Delete it as well. File buildFilePath = new File(imlFilePath.getParentFile(), "build"); if (buildFilePath.isDirectory()) { delete(buildFilePath); } } } } catch (Throwable ignored) { // if something goes wrong, just ignore. Most likely it won't affect project import in any way. } } delete(dotIdeaFolderPath); } }
@NotNull @Override protected List<Object> selectTasksList(@NotNull String response, int max) throws Exception { Document document = new SAXBuilder(false).build(new StringReader(response)); Element root = document.getRootElement(); XPath xPath = lazyCompile(getSelector(TASKS).getPath()); @SuppressWarnings("unchecked") List<Object> rawTaskElements = xPath.selectNodes(root); if (!rawTaskElements.isEmpty() && !(rawTaskElements.get(0) instanceof Element)) { throw new Exception(String.format("Expression '%s' should match list of XML elements. Got '%s' instead.", xPath.getXPath(), rawTaskElements.toString())); } return rawTaskElements.subList(0, Math.min(rawTaskElements.size(), max)); }
@Nullable @Override protected String selectString(@NotNull Selector selector, @NotNull Object context) throws Exception { if (StringUtil.isEmpty(selector.getPath())) { return null; } XPath xPath = lazyCompile(selector.getPath()); String s = xPath.valueOf(context); if (s == null) { throw new Exception(String.format("XPath expression '%s' doesn't match", xPath.getXPath())); } return s; }
@NotNull private XPath lazyCompile(@NotNull String path) throws Exception { XPath xPath = myCompiledCache.get(path); if (xPath == null) { try { xPath = XPath.newInstance(path); myCompiledCache.put(path, xPath); } catch (JDOMException e) { throw new Exception(String.format("Malformed XPath expression '%s'", path)); } } return xPath; }
@SuppressWarnings("unchecked") private Task[] getCases(String q) throws Exception { loginIfNeeded(); PostMethod method = new PostMethod(getUrl() + "/api.asp"); method.addParameter("token", myToken); method.addParameter("cmd", "search"); method.addParameter("q", q); method.addParameter("cols", "sTitle,fOpen,dtOpened,dtLastUpdated,ixCategory"); int status = getHttpClient().executeMethod(method); if (status != 200) { throw new Exception("Error listing cases: " + method.getStatusLine()); } Document document = new SAXBuilder(false).build(method.getResponseBodyAsStream()).getDocument(); List<Element> errorNodes = XPath.newInstance("/response/error").selectNodes(document); if (!errorNodes.isEmpty()) { throw new Exception("Error listing cases: " + errorNodes.get(0).getText()); } final XPath commentPath = XPath.newInstance("events/event"); final List<Element> nodes = (List<Element>)XPath.newInstance("/response/cases/case").selectNodes(document); final List<Task> tasks = ContainerUtil.mapNotNull(nodes, new NotNullFunction<Element, Task>() { @NotNull @Override public Task fun(Element element) { return createCase(element, commentPath); } }); return tasks.toArray(new Task[tasks.size()]); }
private void login(@NotNull PostMethod method) throws Exception { LOG.debug("Requesting new token"); int status = getHttpClient().executeMethod(method); if (status != 200) { throw new Exception("Error logging in: " + method.getStatusLine()); } Document document = new SAXBuilder(false).build(method.getResponseBodyAsStream()).getDocument(); XPath path = XPath.newInstance("/response/token"); Element result = (Element)path.selectSingleNode(document); if (result == null) { Element error = (Element)XPath.newInstance("/response/error").selectSingleNode(document); throw new Exception(error == null ? "Error logging in" : error.getText()); } myToken = result.getTextTrim(); }
/** * Get the text for the selected element * * @param xPathExpression * The xpath expression for the element * @return The text value of the element */ public String GetElementAttr(String xPathExpression) { try { org.jdom.Attribute node = (Attribute) XPath.selectSingleNode(this.xmlDocument, xPathExpression); return node.getValue(); } catch (Exception ex) { LOG.error("Error in handler: " + ex.getMessage(), ex); return ""; } }
/** * Does an xPath expression exist * * @param xpathExpr * The xPath expression * @return TRUE if the xPath expression exists; false otherwise */ public boolean xPathExists(String xpathExpr) { try { if (XPath.selectSingleNode(this.xmlDocument, xpathExpr) == null) return false; return true; } catch (Exception ex) { return false; } }
public double getDerivatisationMass(String a_strType, Persubstitution a_enumPersubst, boolean a_bMonoisotopic) throws Exception, ParameterException { XPath xpath = XPath.newInstance("/defaults/dericatisation/derivate"); for (Iterator t_iterPersub = xpath.selectNodes( this.m_docDefaultMasses ).iterator(); t_iterPersub.hasNext();) { Element t_objElementMain = (Element) t_iterPersub.next(); if ( t_objElementMain.getAttributeValue("abbr").equals(a_strType) ) { String t_strTag = "mass"; if ( a_enumPersubst != Persubstitution.None ) { t_strTag += "_" + a_enumPersubst.getAbbr(); } if ( a_bMonoisotopic ) { t_strTag += "_mono"; } else { t_strTag += "_avg"; } Element t_objElementMass = t_objElementMain.getChild(t_strTag); return Double.parseDouble(t_objElementMass.getTextTrim()); } } throw new ParameterException("Unknown derivatisation."); }
public String resultXpathSingleAttribute (String query, String element) throws JDOMException { XPath xpath = null; xpath = XPath.newInstance(query); List resultSet = xpath.selectNodes( doc ); Iterator b = resultSet.iterator(); if (b.hasNext()) { Element oNode = (Element) b.next(); return (oNode.getAttributeValue(element)); } return null; }
protected Object xpathSelectElement(Element element, String xpath) throws JDOMException { XPath x = XPath.newInstance(xpath); x.addNamespace(MANIFEST_NS); x.addNamespace(CONTAINER_NS); x.addNamespace(EXAMPLE_NS); return x.selectSingleNode(element); }