List of usage examples for javax.xml.xpath XPathFactory DEFAULT_PROPERTY_NAME
String DEFAULT_PROPERTY_NAME
To view the source code for javax.xml.xpath XPathFactory DEFAULT_PROPERTY_NAME.
Click Source Link
The default property name according to the JAXP spec.
From source file:nl.b3p.viewer.admin.stripes.ServiceUsageMatrixActionBean.java
public static XSSFWorkbook createWorkBook(String theXml) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException, XPathFactoryConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new InputSource(new StringReader(theXml))); XSSFWorkbook workbook = new XSSFWorkbook(); String tempProperty = null;//from w ww.ja v a2 s. com try { Element root = doc.getDocumentElement(); /* JSTL XML is setting the system property to use the jstl xpath facotry. * Remove the setting temporary: * see: https://java.net/jira/browse/JSTL-1 */ tempProperty = System .getProperty(XPathFactory.DEFAULT_PROPERTY_NAME + ":" + XPathFactory.DEFAULT_OBJECT_MODEL_URI); if (tempProperty != null) { System.clearProperty( XPathFactory.DEFAULT_PROPERTY_NAME + ":" + XPathFactory.DEFAULT_OBJECT_MODEL_URI); } XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xpath = xpathFactory.newXPath(); XPathExpression exprFeatureSource = xpath.compile("//featureSource"); XPathExpression exprFeatureType = xpath.compile("featureType"); XPathExpression exprApplication = xpath.compile("applications/application"); XPathExpression exprLayer = xpath.compile("layers/layer"); XPathExpression exprAppLayer = xpath.compile("applayers/applayer"); XPathExpression exprId = xpath.compile("id/text()"); XPathExpression exprAlias = xpath.compile("alias/text()"); XPathExpression exprName = xpath.compile("name/text()"); XPathExpression exprVersion = xpath.compile("version/text()"); XPathExpression exprProtocol = xpath.compile("protocol/text()"); XPathExpression exprUrl = xpath.compile("url/text()"); XSSFSheet sheet = workbook.createSheet("Sheet 1"); int rowNum = 0; Row head = sheet.createRow(rowNum++); String[] headValues = { "Bron", "Featuretype", "Applicatie", "Layernaam van service", "Application layer (kaart)" }; for (int c = 0; c < headValues.length; c++) { Cell cell = head.createCell(c); cell.setCellValue(headValues[c]); } List<String> columns = new ArrayList<String>(); for (int i = 0; i < headValues.length; i++) { columns.add(""); } NodeList featureSources = (NodeList) exprFeatureSource.evaluate(root, XPathConstants.NODESET); for (int fs = 0; fs < featureSources.getLength(); fs++) { Node featureSource = featureSources.item(fs); String fsString = (String) exprName.evaluate(featureSource, XPathConstants.STRING); fsString += " (" + (String) exprProtocol.evaluate(featureSource, XPathConstants.STRING); fsString += ":: " + (String) exprUrl.evaluate(featureSource, XPathConstants.STRING); fsString += " id: " + (String) exprId.evaluate(featureSource, XPathConstants.STRING); fsString += ")"; columns.set(0, fsString); NodeList featureTypes = (NodeList) exprFeatureType.evaluate(featureSource, XPathConstants.NODESET); for (int ft = 0; ft < featureTypes.getLength(); ft++) { Node featureType = featureTypes.item(ft); //String ftId = (String) exprId.evaluate(featureType,XPathConstants.STRING); String ftName = (String) exprName.evaluate(featureType, XPathConstants.STRING); //String ftString = ""+ftName; columns.set(1, ftName); NodeList applications = (NodeList) exprApplication.evaluate(featureType, XPathConstants.NODESET); for (int app = 0; app < applications.getLength(); app++) { Node application = applications.item(app); String appVersion = (String) exprVersion.evaluate(application, XPathConstants.STRING); String appString = (String) exprName.evaluate(application, XPathConstants.STRING); if (appVersion != null) { appString += ", version: " + appVersion; } appString += " (" + (String) exprId.evaluate(application, XPathConstants.STRING) + ")"; columns.set(2, appString); NodeList layers = (NodeList) exprLayer.evaluate(application, XPathConstants.NODESET); for (int lay = 0; lay < layers.getLength(); lay++) { Node layer = layers.item(lay); String layerString = ""; layerString += (String) exprName.evaluate(layer, XPathConstants.STRING); columns.set(3, layerString); NodeList appLayers = (NodeList) exprAppLayer.evaluate(layer, XPathConstants.NODESET); for (int al = 0; al < appLayers.getLength(); al++) { Node appLayer = appLayers.item(al); String alString = (String) exprAlias.evaluate(appLayer, XPathConstants.STRING); alString += " (" + (String) exprId.evaluate(appLayer, XPathConstants.STRING) + ")"; columns.set(4, alString); Row row = sheet.createRow(rowNum++); for (int c = 0; c < columns.size(); c++) { Cell cell = row.createCell(c); cell.setCellValue(columns.get(c)); } } } } } } } finally { if (tempProperty != null) { System.setProperty(XPathFactory.DEFAULT_PROPERTY_NAME + ":" + XPathFactory.DEFAULT_OBJECT_MODEL_URI, tempProperty); } } return workbook; }
From source file:org.apache.camel.builder.xml.XPathBuilder.java
public XPathFactory getXPathFactory() throws XPathFactoryConfigurationException { if (xpathFactory == null) { if (objectModelUri != null) { LOG.info("Using objectModelUri " + objectModelUri + " when creating XPathFactory"); xpathFactory = XPathFactory.newInstance(objectModelUri); return xpathFactory; }/* ww w .j a v a 2 s . co m*/ // read system property and see if there is a factory set Properties properties = System.getProperties(); for (Map.Entry prop : properties.entrySet()) { String key = (String) prop.getKey(); if (key.startsWith(XPathFactory.DEFAULT_PROPERTY_NAME)) { String uri = ObjectHelper.after(key, ":"); if (uri != null) { LOG.info("Using system property " + key + " with value: " + prop.getValue() + " when creating XPathFactory"); xpathFactory = XPathFactory.newInstance(uri); return xpathFactory; } } } if (xpathFactory == null) { LOG.debug("Creating default XPathFactory"); xpathFactory = XPathFactory.newInstance(); } } return xpathFactory; }