Example usage for javax.xml.xpath XPathFactory DEFAULT_OBJECT_MODEL_URI

List of usage examples for javax.xml.xpath XPathFactory DEFAULT_OBJECT_MODEL_URI

Introduction

In this page you can find the example usage for javax.xml.xpath XPathFactory DEFAULT_OBJECT_MODEL_URI.

Prototype

String DEFAULT_OBJECT_MODEL_URI

To view the source code for javax.xml.xpath XPathFactory DEFAULT_OBJECT_MODEL_URI.

Click Source Link

Document

Default Object Model URI.

Usage

From source file:com.indoqa.maven.wadldoc.AbstractWadlDocumentationMojo.java

private HtmlDocument writeIndexPage(Collection<File> wadlFiles) throws MavenReportException {
    // XPath factory and namespace context
    XPathExpression expression;/*  w ww. java2  s.co  m*/
    try {
        XPath xpath = XPathFactory.newInstance(XPathFactory.DEFAULT_OBJECT_MODEL_URI).newXPath();
        xpath.setNamespaceContext(new WadlNamespaceContext());
        expression = xpath.compile("/w:application/w:doc/@title");
    } catch (Exception e) {
        throw new MavenReportException("Can't create xpath factory.", e);
    }
    List<HtmlDocument> htmlDocuments = new ArrayList<HtmlDocument>();
    for (File wadlFile : wadlFiles) {
        htmlDocuments
                .add(new HtmlDocument(getWadlDocumentName(expression, wadlFile), createOutFileName(wadlFile)));
    }
    Collections.sort(htmlDocuments, new Comparator<HtmlDocument>() {

        public int compare(HtmlDocument d1, HtmlDocument d2) {
            return d1.getName().compareTo(d2.getName());
        }
    });
    File f = new File(this.outputDirectory, "resources.html");
    FileWriter fw = null;
    try {
        fw = new FileWriter(f);
        fw.write(this.createIndexFileContent(htmlDocuments));
    } catch (IOException e) {
        throw new MavenReportException("Can't create index.html", e);
    } finally {
        IOUtils.closeQuietly(fw);
    }

    return htmlDocuments.get(0);
}

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;/*  ww w .j a  va  2s. co m*/
    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;
}