List of usage examples for org.springframework.util.xml SimpleNamespaceContext SimpleNamespaceContext
SimpleNamespaceContext
From source file:org.geowebcache.jetty.RestIntegrationTest.java
@Before public void setUp() throws Exception { nsContext = new SimpleNamespaceContext(); nsContext.bindNamespaceUri("atom", "http://www.w3.org/2005/Atom"); nsContext.bindNamespaceUri("wmts", "http://www.opengis.net/wmts/1.0"); nsContext.bindNamespaceUri("ows", "http://www.opengis.net/ows/1.1"); //Reset Server configuration final String globalUpdate = "<global>\n" + " <serviceInformation>\n" + " <title>GeoWebCache</title>\n" + " <description>GeoWebCache is an advanced tile cache for WMS servers. It supports a large variety of protocols and\n" + " formats, including WMS-C, WMTS, KML, Google Maps and Virtual Earth.</description>\n" + " <keywords>\n" + " <string>WMS</string>\n" + " <string>WFS</string>\n" + " <string>WMTS</string>\n" + " <string>GEOWEBCACHE</string>\n" + " </keywords>\n" + " <serviceProvider>\n" + " <providerName>John Smith inc.</providerName>\n" + " <providerSite>http://www.example.com/</providerSite>\n" + " <serviceContact>\n" + " <individualName>John Smith</individualName>\n" + " <positionName>Geospatial Expert</positionName>\n" + " <addressType>Work</addressType>\n" + " <addressStreet>1 Bumpy St.</addressStreet>\n" + " <addressCity>Hobart</addressCity>\n" + " <addressAdministrativeArea>TAS</addressAdministrativeArea>\n" + " <addressPostalCode>7005</addressPostalCode>\n" + " <addressCountry>Australia</addressCountry>\n" + " <phoneNumber>+61 3 0000 0000</phoneNumber>\n" + " <faxNumber>+61 3 0000 0001</faxNumber>\n" + " <addressEmail>john.smith@example.com</addressEmail>\n" + " </serviceContact>\n" + " </serviceProvider>\n" + " <fees>NONE</fees>\n" + " <accessConstraints>NONE</accessConstraints>\n" + " </serviceInformation>\n" + " <runtimeStatsEnabled>true</runtimeStatsEnabled>\n" + " <wmtsCiteCompliant>false</wmtsCiteCompliant>\n" + " <backendTimeout>120</backendTimeout>\n" + "</global>"; CloseableHttpResponse response = handlePut(URI.create("/geowebcache/rest/global"), admin.getClient(), globalUpdate);/*from w w w . ja v a2 s.c om*/ assertEquals(200, response.getStatusLine().getStatusCode()); response.close(); }
From source file:com.consol.citrus.admin.service.ProjectService.java
/** * Loads Citrus project from project home. * @param projectHomeDir//w ww.j a v a2s . co m * @return */ public void load(String projectHomeDir) { Project project = new Project(projectHomeDir); if (project.getProjectInfoFile().exists()) { project.loadSettings(); } else if (!validateProject(project)) { throw new ApplicationRuntimeException("Invalid project home - not a proper Citrus project"); } if (project.isMavenProject()) { try { String pomXml = FileUtils.readToString(new FileSystemResource(project.getMavenPomFile())); SimpleNamespaceContext nsContext = new SimpleNamespaceContext(); nsContext.bindNamespaceUri("mvn", "http://maven.apache.org/POM/4.0.0"); Document pomDoc = XMLUtils.parseMessagePayload(pomXml); project.setName(evaluate(pomDoc, "/mvn:project/mvn:artifactId", nsContext)); String version = evaluate(pomDoc, "/mvn:project/mvn:version", nsContext); String parentVersion = evaluate(pomDoc, "/mvn:project/mvn:parent/mvn:version", nsContext); if (StringUtils.hasText(version)) { project.setVersion(version); } else if (StringUtils.hasText(parentVersion)) { project.setVersion(parentVersion); } project.getSettings().setBasePackage(evaluate(pomDoc, "/mvn:project/mvn:groupId", nsContext)); String citrusVersion = evaluate(pomDoc, "/mvn:project/mvn:properties/mvn:citrus.version", nsContext); if (StringUtils.hasText(citrusVersion)) { project.getSettings().setCitrusVersion(citrusVersion); } project.setDescription(evaluate(pomDoc, "/mvn:project/mvn:description", nsContext)); project.getSettings().setConnectorActive(StringUtils.hasText(evaluate(pomDoc, "/mvn:project/mvn:dependencies/mvn:dependency/mvn:artifactId[. = 'citrus-admin-connector']", nsContext))); } catch (IOException e) { throw new ApplicationRuntimeException("Unable to open Maven pom.xml file", e); } } else if (project.isAntProject()) { try { String buildXml = FileUtils.readToString(new FileSystemResource(project.getAntBuildFile())); SimpleNamespaceContext nsContext = new SimpleNamespaceContext(); Document buildDoc = XMLUtils.parseMessagePayload(buildXml); project.setName(evaluate(buildDoc, "/project/@name", nsContext)); String citrusVersion = evaluate(buildDoc, "/project/property[@name='citrus.version']/@value", nsContext); if (StringUtils.hasText(citrusVersion)) { project.getSettings().setCitrusVersion(citrusVersion); } project.setDescription(evaluate(buildDoc, "/project/@description", nsContext)); } catch (IOException e) { throw new ApplicationRuntimeException("Unable to open Apache Ant build.xml file", e); } } saveProject(project); this.project = project; if (!this.recentlyOpened.contains(projectHomeDir)) { if (projectHomeDir.endsWith("/")) { this.recentlyOpened.add(projectHomeDir.substring(0, projectHomeDir.length() - 1)); } else { this.recentlyOpened.add(projectHomeDir); } } System.setProperty(Application.PROJECT_HOME, projectHomeDir); }
From source file:com.servicelibre.jxsl.scenario.test.xspec.XspecTestScenarioRunner.java
private void init() { XPath xpath = null;//from ww w .j a v a 2s . c o m try { xpath = XPathFactory.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON).newXPath(); } catch (XPathFactoryConfigurationException e1) { logger.error("Error while creating XPathFactory", e1); return; } SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); namespaceContext.bindNamespaceUri("x", "http://www.jenitennison.com/xslt/xspec"); xpath.setNamespaceContext(namespaceContext); try { successXpath = xpath.compile("count(//x:test[@successful ='false'] ) = 0"); testFailedCount = xpath.compile("count(//x:test[@successful ='false'] )"); testCount = xpath.compile("count(//x:test)"); } catch (XPathExpressionException e) { logger.error("Error while initializing {}.", this.getClass().getName(), e); } DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); docFactory.setNamespaceAware(true); try { xmlBuilder = docFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { logger.error("Error while configuring XML parser", e); } }
From source file:com.seajas.search.utilities.web.WebPages.java
private XPath getXPathEngine() { XPath engine = xPathEngine;/* w ww . jav a2 s . c o m*/ if (engine == null) { XPathFactory factory = XPathFactory.newInstance(); engine = factory.newXPath(); SimpleNamespaceContext namespaces = new SimpleNamespaceContext(); namespaces.bindNamespaceUri("ht", "http://www.w3.org/1999/xhtml"); engine.setNamespaceContext(namespaces); xPathEngine = engine; } return engine; }
From source file:cz.strmik.cmmitool.cmmi.DefaultRatingScalesProvider.java
private List<RatingScale> readScales(String id, String lang) { List<RatingScale> scales = new ArrayList<RatingScale>(); try {/*ww w . j a va 2 s. c om*/ Document document = getScalesDocument(); XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); SimpleNamespaceContext ns = new SimpleNamespaceContext(); ns.bindNamespaceUri("s", SCALES_XML_NS); xPath.setNamespaceContext(ns); XPathExpression exprScales = xPath.compile("/s:ratings/s:rating[@id='" + id + "']/s:scale"); XPathExpression exprName = xPath.compile("s:name[@lang='" + lang + "']"); XPathExpression exprColor = xPath.compile("s:color[@type='html']"); NodeList nodes = (NodeList) exprScales.evaluate(document, XPathConstants.NODESET); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); int score = Integer.parseInt(node.getAttributes().getNamedItem("score").getTextContent()); String name = exprName.evaluate(node); String color = exprColor.evaluate(node); RatingScale rs = new RatingScale(name, i, score, color); if (i == 0) { rs.setDefaultRating(true); } scales.add(rs); } } catch (Exception ex) { _log.warn( "Unable to load default scales for id=" + id + ",lang=" + lang + " ratings from " + SCALES_XML, ex); } return scales; }
From source file:org.geoserver.kml.KMLReflectorTest.java
void initXPath(XPath xpath) { SimpleNamespaceContext ctx = new SimpleNamespaceContext(); ctx.bindNamespaceUri("kml", "http://www.opengis.net/kml/2.2"); xpath.setNamespaceContext(ctx);//w w w.j a va2s . c o m }
From source file:org.geoserver.opensearch.eo.OSEOTestSupport.java
@Before public void setupNamespaces() { this.namespaceContext = new SimpleNamespaceContext(); namespaceContext.bindNamespaceUri("os", "http://a9.com/-/spec/opensearch/1.1/"); namespaceContext.bindNamespaceUri("param", "http://a9.com/-/spec/opensearch/extensions/parameters/1.0/"); namespaceContext.bindNamespaceUri("at", "http://www.w3.org/2005/Atom"); namespaceContext.bindNamespaceUri("gml", "http://www.opengis.net/gml"); namespaceContext.bindNamespaceUri("georss", "http://www.georss.org/georss"); namespaceContext.bindNamespaceUri("eo", OpenSearchAccess.EO_NAMESPACE); namespaceContext.bindNamespaceUri("geo", OpenSearchAccess.GEO_NAMESPACE); namespaceContext.bindNamespaceUri("gmi", "http://www.isotc211.org/2005/gmi"); namespaceContext.bindNamespaceUri("gmd", "http://www.isotc211.org/2005/gmd"); namespaceContext.bindNamespaceUri("gco", "http://www.isotc211.org/2005/gco"); namespaceContext.bindNamespaceUri("time", "http://a9.com/-/opensearch/extensions/time/1.0"); namespaceContext.bindNamespaceUri("owc", "http://www.opengis.net/owc/1.0"); namespaceContext.bindNamespaceUri("dc", "http://purl.org/dc/elements/1.1/"); namespaceContext.bindNamespaceUri("media", "http://search.yahoo.com/mrss/"); for (OpenSearchAccess.ProductClass pc : OpenSearchAccess.ProductClass.values()) { namespaceContext.bindNamespaceUri(pc.getPrefix(), pc.getNamespace()); }// w w w .j a va 2 s. c o m }
From source file:org.geowebcache.jetty.RestIT.java
@Before public void setUp() { nsContext = new SimpleNamespaceContext(); nsContext.bindNamespaceUri("atom", "http://www.w3.org/2005/Atom"); nsContext.bindNamespaceUri("wmts", "http://www.opengis.net/wmts/1.0"); nsContext.bindNamespaceUri("ows", "http://www.opengis.net/ows/1.1"); }