List of usage examples for javax.xml.xpath XPathConstants STRING
QName STRING
To view the source code for javax.xml.xpath XPathConstants STRING.
Click Source Link
The XPath 1.0 string data type.
Maps to Java String .
From source file:org.drools.semantics.lang.dl.DL_9_CompilationTest.java
@Test public void testIncrementalCompilation() { try {//from w w w . j av a 2 s .c om OntoModel diamond = factory.buildModel("diamondX", ResourceFactory.newClassPathResource("ontologies/diamondProp.manchester.owl"), DLFactoryConfiguration.newConfiguration(OntoModel.Mode.OPTIMIZED)); compiler = new OntoModelCompiler(diamond, folder.getRoot()); List<Diagnostic<? extends JavaFileObject>> diag1 = compiler .compileOnTheFly(OntoModelCompiler.minimalOptions, OntoModelCompiler.MOJO_VARIANTS.JPA2); for (Diagnostic<?> dx : diag1) { System.out.println(dx); assertFalse(dx.getKind() == Diagnostic.Kind.ERROR); } showDirContent(folder); ClassLoader urlKL = new URLClassLoader(new URL[] { compiler.getBinDir().toURI().toURL() }, Thread.currentThread().getContextClassLoader()); OntoModel results = factory.buildModel("diamondInc", ResourceFactory.newClassPathResource("ontologies/dependency.test.owl"), DLFactoryConfiguration.newConfiguration(OntoModel.Mode.OPTIMIZED), urlKL); System.out.println(results); Class bot = Class.forName("org.jboss.drools.semantics.diamond.BottomImpl", true, urlKL); Class botIF = Class.forName("org.jboss.drools.semantics.diamond.Bottom", true, urlKL); Assert.assertNotNull(bot); Assert.assertNotNull(botIF); Object botInst = bot.newInstance(); Assert.assertNotNull(botInst); OntoModelCompiler compiler2 = new OntoModelCompiler(results, folder.getRoot()); compiler2.fixResolvedClasses(); compiler2.streamJavaInterfaces(false); compiler2.streamXSDsWithBindings(true); compiler2.mojo(OntoModelCompiler.defaultOptions, OntoModelCompiler.MOJO_VARIANTS.JPA2); showDirContent(folder); File unImplBoundLeft = new File(compiler2.getXjcDir() + File.separator + "org.jboss.drools.semantics.diamond".replace(".", File.separator) + File.separator + "Left.java"); assertFalse(unImplBoundLeft.exists()); File implBoundLeft = new File(compiler2.getXjcDir() + File.separator + "org.jboss.drools.semantics.diamond".replace(".", File.separator) + File.separator + "LeftImpl.java"); assertTrue(implBoundLeft.exists()); File leftInterface = new File(compiler2.getJavaDir() + File.separator + "org.jboss.drools.semantics.diamond".replace(".", File.separator) + File.separator + "Left.java"); assertTrue(leftInterface.exists()); List<Diagnostic<? extends JavaFileObject>> diagnostics = compiler2.doCompile(); for (Diagnostic<?> dx : diagnostics) { System.out.println(dx); assertFalse(dx.getKind() == Diagnostic.Kind.ERROR); } showDirContent(folder); Document dox = parseXML(new File(compiler2.getBinDir().getPath() + "/META-INF/persistence.xml"), false); XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression expr = xpath.compile("//persistence-unit/@name"); assertEquals("diamondX", (String) expr.evaluate(dox, XPathConstants.STRING)); File YInterface = new File(compiler2.getJavaDir() + File.separator + "org.jboss.drools.semantics.diamond".replace(".", File.separator) + File.separator + "X.java"); assertTrue(YInterface.exists()); Class colf = Class.forName("some.dependency.test.ChildOfLeftImpl", true, urlKL); Assert.assertNotNull(colf); Object colfInst = colf.newInstance(); List<String> hierarchy = getHierarchy(colf); assertTrue(hierarchy.contains("some.dependency.test.ChildOfLeftImpl")); assertTrue(hierarchy.contains("some.dependency.test.org.jboss.drools.semantics.diamond.LeftImpl")); assertTrue(hierarchy.contains("org.jboss.drools.semantics.diamond.LeftImpl")); assertTrue(hierarchy.contains("org.jboss.drools.semantics.diamond.C0Impl")); assertTrue(hierarchy.contains("org.jboss.drools.semantics.diamond.TopImpl")); assertTrue(hierarchy.contains("org.w3._2002._07.owl.ThingImpl")); Set<String> itfHierarchy = getIFHierarchy(colf); System.err.println(itfHierarchy.containsAll( Arrays.asList("org.jboss.drools.semantics.diamond.C1", "org.jboss.drools.semantics.diamond.C0", "some.dependency.test.org.jboss.drools.semantics.diamond.Left", "some.dependency.test.ChildOfLeft", "org.jboss.drools.semantics.diamond.Left", "org.jboss.drools.semantics.diamond.Top", "com.clarkparsia.empire.EmpireGenerated", "org.w3._2002._07.owl.Thing", "java.io.Serializable", "org.drools.semantics.Thing", "com.clarkparsia.empire.SupportsRdfId"))); Method getter1 = colf.getMethod("getAnotherLeftProp"); assertNotNull(getter1); Method getter2 = colf.getMethod("getImportantProp"); assertNotNull(getter2); for (Method m : colf.getMethods()) { if (m.getName().equals("addImportantProp")) { m.getName(); } } Method adder = colf.getMethod("addImportantProp", botIF); assertNotNull(adder); adder.invoke(colfInst, botInst); List l = (List) getter2.invoke(colfInst); assertEquals(1, l.size()); File off = new File(compiler2.getXjcDir() + File.separator + "org.jboss.drools.semantics.diamond".replace(".", File.separator) + File.separator + "Left_Off.java"); assertFalse(off.exists()); testPersistenceWithInstance(urlKL, "org.jboss.drools.semantics.diamond.Bottom", diamond.getName()); System.out.println(" Done"); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
From source file:org.entrystore.harvesting.oaipmh.jobs.ListRecordsJob.java
private static String getDatestamp(Element el) throws XPathExpressionException { initXpath();//from w ww . java2 s . co m expr = xpath.compile("oai:header/oai:datestamp"); return (String) expr.evaluate(el, XPathConstants.STRING); }
From source file:org.entrystore.harvesting.oaipmh.jobs.ListRecordsJob.java
private static String getIdentifier(Element el) throws XPathExpressionException { initXpath();//from www . ja v a 2 s .com expr = xpath.compile("oai:header/oai:identifier"); return (String) expr.evaluate(el, XPathConstants.STRING); }
From source file:org.eurekastreams.server.service.actions.strategies.galleryitem.PluginDefinitionPopulator.java
/** * Checks for the required plugin feature before updating the plugin def. * /*from w w w . j av a 2s. com*/ * @param inPluginDefinitionUrl * The url to the plugin definition. * @return true if the feature is found and false if not found. * @throws XPathExpressionException * not expected. * @throws ParserConfigurationException * not expected. * @throws SAXException * not expected. * @throws IOException * expected if the url is invalid. */ private boolean checkForRequiredFeature(final String inPluginDefinitionUrl) throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document doc = builder.parse(inPluginDefinitionUrl); XPath xpath = XPathFactory.newInstance().newXPath(); // this is used to get the amount of required feature we need to check. XPathExpression getFeatureAmountExpr = xpath.compile("//Module/ModulePrefs/Require"); NodeList nodeResults = (NodeList) getFeatureAmountExpr.evaluate(doc, XPathConstants.NODESET); for (int i = 1; i <= nodeResults.getLength(); i++) { XPathExpression getFeatureExpr = xpath.compile("//Module/ModulePrefs/Require[" + i + "]/@feature"); String thing = (String) getFeatureExpr.evaluate(doc, XPathConstants.STRING); if (thing.equals("eurekastreams-streamplugin")) { return true; } } return false; }
From source file:org.finra.jtaf.ewd.impl.DefaultExtWebDriver.java
@Override public String evaluateXpath(String xpath) throws Exception { XPathFactory xpathFac = XPathFactory.newInstance(); XPath theXpath = xpathFac.newXPath(); String html = getHtmlSource(); html = html.replaceAll(">\\s+<", "><"); InputStream input = new ByteArrayInputStream(html.getBytes()); XMLReader reader = new Parser(); reader.setFeature(Parser.namespacesFeature, false); Transformer transformer = TransformerFactory.newInstance().newTransformer(); DOMResult result = new DOMResult(); transformer.transform(new SAXSource(reader, new InputSource(input)), result); Node htmlNode = result.getNode(); // This code gets a Node from the // result./*from ww w.j a va2 s . c o m*/ return (String) theXpath.evaluate(xpath, htmlNode, XPathConstants.STRING); }
From source file:org.glimpse.server.news.dom.DomServerNewsChannelBuilder.java
private List<ServerEntry> getRSSEntries(Document doc) throws Exception { XPath xpath = XPathFactory.newInstance().newXPath(); List<ServerEntry> rssEntries = new LinkedList<ServerEntry>(); NodeList entries = (NodeList) xpath.evaluate("/rss/channel/item", doc, XPathConstants.NODESET); for (int i = 0; i < entries.getLength(); i++) { ServerEntry rssEntry = new ServerEntry(); Element elmEntry = (Element) entries.item(i); String id = (String) xpath.evaluate("link", elmEntry, XPathConstants.STRING); String title = (String) xpath.evaluate("title", elmEntry, XPathConstants.STRING); String entryUrl = (String) xpath.evaluate("link", elmEntry, XPathConstants.STRING); String pubDate = (String) xpath.evaluate("pubDate", elmEntry, XPathConstants.STRING); NodeList enclosureList = (NodeList) xpath.evaluate("enclosure", elmEntry, XPathConstants.NODESET); List<Enclosure> enclosures = new LinkedList<Enclosure>(); for (int j = 0; j < enclosureList.getLength(); j++) { Element elmEnclosure = (Element) enclosureList.item(j); Enclosure enclosure = new Enclosure(); enclosure.setUrl(elmEnclosure.getAttribute("url")); enclosure.setType(elmEnclosure.getAttribute("type")); enclosures.add(enclosure);/*from w ww . ja va 2 s . c o m*/ } String content = (String) xpath.evaluate("description", elmEntry, XPathConstants.STRING); content += "<p><a href=\"" + entryUrl + "\" target=\"_blank\">Lire la suite</a></p>"; if (StringUtils.isBlank(id)) { id = pubDate; } if (StringUtils.isBlank(entryUrl)) { entryUrl = getRSSLink(doc); } rssEntry.setId(id); rssEntry.setTitle(title); rssEntry.setUrl(entryUrl); rssEntry.setEnclosures(enclosures); rssEntry.setContent(content); if (StringUtils.isNotBlank(pubDate)) { SimpleDateFormat formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z"); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); formatter.setDateFormatSymbols(new DateFormatSymbols(Locale.ENGLISH)); try { Date date = formatter.parse(pubDate); rssEntry.setDate(date); } catch (Exception e) { // unparsable date logger.warn("Unable to parse date <" + pubDate + ">", e); } } if (StringUtils.isNotBlank(id) && StringUtils.isNotBlank(title) && StringUtils.isNotBlank(entryUrl)) { rssEntries.add(rssEntry); } } return rssEntries; }
From source file:org.glimpse.server.news.dom.DomServerNewsChannelBuilder.java
private List<ServerEntry> getAtomEntries(Document doc) throws Exception { XPath xpath = XPathFactory.newInstance().newXPath(); List<ServerEntry> rssEntries = new LinkedList<ServerEntry>(); NodeList entries = (NodeList) xpath.evaluate("/feed/entry", doc, XPathConstants.NODESET); for (int i = 0; i < entries.getLength(); i++) { ServerEntry rssEntry = new ServerEntry(); Element elmEntry = (Element) entries.item(i); String id = (String) xpath.evaluate("id", elmEntry, XPathConstants.STRING); String title = (String) xpath.evaluate("title", elmEntry, XPathConstants.STRING); String entryUrl = null;/* w ww. ja v a 2 s . c om*/ List<Enclosure> enclosures = new LinkedList<Enclosure>(); NodeList linkList = (NodeList) xpath.evaluate("link", elmEntry, XPathConstants.NODESET); if (linkList != null) { for (int j = 0; j < linkList.getLength(); j++) { Element elmLink = (Element) linkList.item(j); String rel = elmLink.getAttribute("rel"); if (StringUtils.isBlank(rel) || rel.equals("alternate")) { entryUrl = elmLink.getAttribute("href"); } else if (rel.equals("enclosure")) { Enclosure enclosure = new Enclosure(); enclosure.setUrl(elmLink.getAttribute("href")); enclosure.setType(elmLink.getAttribute("type")); enclosures.add(enclosure); } } } String updated = (String) xpath.evaluate("updated", elmEntry, XPathConstants.STRING); String content = (String) xpath.evaluate("content", elmEntry, XPathConstants.STRING); if (StringUtils.isBlank(content)) { content = (String) xpath.evaluate("summary", elmEntry, XPathConstants.STRING); content += "<p><a href=\"" + entryUrl + "\" target=\"_blank\">Lire la suite</a></p>"; } rssEntry.setId(id); rssEntry.setTitle(title); rssEntry.setUrl(entryUrl); rssEntry.setEnclosures(enclosures); rssEntry.setContent(content); if (StringUtils.length(updated) > 19) { try { Date date = null; if (updated.endsWith("Z")) { // No timezone SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); date = formatter.parse(updated.substring(0, 19)); } else { String timezone = updated.substring(updated.length() - 6); timezone = timezone.substring(0, 3) + timezone.substring(4); updated = updated.substring(0, 19) + timezone; SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); date = formatter.parse(updated); } if (date != null) { rssEntry.setDate(date); } } catch (Exception e) { // unparsable date logger.warn("Unable to parse date <" + updated + ">", e); } } if (StringUtils.isNotBlank(id) && StringUtils.isNotBlank(title) && StringUtils.isNotBlank(entryUrl)) { rssEntries.add(rssEntry); } } return rssEntries; }
From source file:org.glimpse.server.news.dom.DomServerNewsChannelBuilder.java
private String getRSSTitle(Document doc) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); return (String) xpath.evaluate("/rss/channel/title", doc, XPathConstants.STRING); }
From source file:org.glimpse.server.news.dom.DomServerNewsChannelBuilder.java
private String getAtomTitle(Document doc) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); return (String) xpath.evaluate("/feed/title", doc, XPathConstants.STRING); }
From source file:org.glimpse.server.news.dom.DomServerNewsChannelBuilder.java
private String getRSSLink(Document doc) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); return (String) xpath.evaluate("/rss/channel/link", doc, XPathConstants.STRING); }