Search in sources :

Example 1 with Dom4jXPath

use of org.jaxen.dom4j.Dom4jXPath in project webanno by webanno.

the class TeiReader method nextTeiElement.

private void nextTeiElement() throws CollectionException, IOException {
    if (teiElementIterator == null) {
        currentTeiElement = null;
        return;
    }
    while (!teiElementIterator.hasNext() && super.hasNext()) {
        currentResource = nextFile();
        InputStream is = null;
        try {
            is = currentResource.getInputStream();
            if (currentResource.getPath().endsWith(".gz")) {
                is = new GZIPInputStream(is);
            }
            InputSource source = new InputSource(is);
            source.setPublicId(currentResource.getLocation());
            source.setSystemId(currentResource.getLocation());
            SAXReader reader = new SAXReader();
            Document xml = reader.read(source);
            final XPath teiPath = new Dom4jXPath("//tei:TEI");
            teiPath.addNamespace("tei", "http://www.tei-c.org/ns/1.0");
            @SuppressWarnings("unchecked") List<Element> teiElements = teiPath.selectNodes(xml);
            teiElementIterator = teiElements.iterator();
            currentTeiElementNumber = 0;
        } catch (DocumentException | JaxenException e) {
            throw new IOException(e);
        } finally {
            closeQuietly(is);
        }
    }
    currentTeiElement = teiElementIterator.hasNext() ? teiElementIterator.next() : null;
    currentTeiElementNumber++;
    if (!super.hasNext() && !teiElementIterator.hasNext()) {
        // Mark end of processing.
        teiElementIterator = null;
    }
}
Also used : Dom4jXPath(org.jaxen.dom4j.Dom4jXPath) XPath(org.jaxen.XPath) InputSource(org.xml.sax.InputSource) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) IOException(java.io.IOException) Document(org.dom4j.Document) GZIPInputStream(java.util.zip.GZIPInputStream) Dom4jXPath(org.jaxen.dom4j.Dom4jXPath) DocumentException(org.dom4j.DocumentException) JaxenException(org.jaxen.JaxenException)

Example 2 with Dom4jXPath

use of org.jaxen.dom4j.Dom4jXPath in project application by collectionspace.

the class XTmplTmpl method compileTemplate.

@SuppressWarnings("unchecked")
private void compileTemplate(Document template) throws InvalidXTmplException {
    try {
        Map<String, String> map = new HashMap<String, String>();
        map.put("xtmpl", XTMPL_URI);
        Dom4jXPath xpath = new Dom4jXPath("//.[@xtmpl:point]");
        xpath.setNamespaceContext(new SimpleNamespaceContext(map));
        List<Node> paths = xpath.selectNodes(template);
        QName attr_qname = new QName("point", new Namespace("xtmpl", XTMPL_URI));
        for (Node n : paths) {
            if (!(n instanceof Element))
                continue;
            Element e = (Element) n;
            Attribute attr = e.attribute(attr_qname);
            String key = attr.getText();
            String path = e.getPath();
            e.remove(attr);
            attach.put(key, path);
        }
        removeNamespaces(template.getDocument().getRootElement());
        document = template;
    } catch (JaxenException e) {
        throw new InvalidXTmplException("Cannot parse template file", e);
    }
}
Also used : HashMap(java.util.HashMap) Attribute(org.dom4j.Attribute) QName(org.dom4j.QName) Node(org.dom4j.Node) Element(org.dom4j.Element) Namespace(org.dom4j.Namespace) Dom4jXPath(org.jaxen.dom4j.Dom4jXPath) JaxenException(org.jaxen.JaxenException) SimpleNamespaceContext(org.jaxen.SimpleNamespaceContext)

Example 3 with Dom4jXPath

use of org.jaxen.dom4j.Dom4jXPath in project pentaho-platform by pentaho.

the class PentahoObjectsConfig method getObjectScope.

public String getObjectScope(String objectId) {
    try {
        HashMap<String, String> map = new HashMap<String, String>();
        // $NON-NLS-1$
        map.put("default", DEFAULT_NAMESPACE);
        Dom4jXPath xpath = new Dom4jXPath(BEAN_ID_XPATH);
        xpath.setNamespaceContext(new SimpleNamespaceContext(map));
        Element element = (Element) xpath.selectSingleNode(document);
        return element.attributeValue(SCOPE_ATTRIBUTE);
    } catch (JaxenException jex) {
        return null;
    }
}
Also used : Dom4jXPath(org.jaxen.dom4j.Dom4jXPath) HashMap(java.util.HashMap) Element(org.dom4j.Element) JaxenException(org.jaxen.JaxenException) SimpleNamespaceContext(org.jaxen.SimpleNamespaceContext)

Example 4 with Dom4jXPath

use of org.jaxen.dom4j.Dom4jXPath in project pentaho-platform by pentaho.

the class PentahoObjectsConfig method getObjectBeanElement.

protected Element getObjectBeanElement(String objectId) {
    try {
        String xPath = MessageFormat.format(BEAN_ID_XPATH, objectId);
        HashMap<String, String> map = new HashMap<String, String>();
        // $NON-NLS-1$
        map.put("default", DEFAULT_NAMESPACE);
        Dom4jXPath xpath = new Dom4jXPath(xPath);
        xpath.setNamespaceContext(new SimpleNamespaceContext(map));
        Element element = (Element) xpath.selectSingleNode(document);
        return element;
    } catch (JaxenException jex) {
        return null;
    }
}
Also used : Dom4jXPath(org.jaxen.dom4j.Dom4jXPath) HashMap(java.util.HashMap) Element(org.dom4j.Element) JaxenException(org.jaxen.JaxenException) SimpleNamespaceContext(org.jaxen.SimpleNamespaceContext)

Example 5 with Dom4jXPath

use of org.jaxen.dom4j.Dom4jXPath in project pentaho-platform by pentaho.

the class PentahoObjectsConfig method getObjectClassName.

public String getObjectClassName(String objectId) {
    try {
        String xPath = MessageFormat.format(BEAN_ID_XPATH, objectId);
        HashMap<String, String> map = new HashMap<String, String>();
        // $NON-NLS-1$
        map.put("default", DEFAULT_NAMESPACE);
        Dom4jXPath xpath = new Dom4jXPath(xPath);
        xpath.setNamespaceContext(new SimpleNamespaceContext(map));
        Element element = (Element) xpath.selectSingleNode(document);
        return element.attributeValue(CLASS_ATTRIBUTE);
    } catch (JaxenException jex) {
        return null;
    }
}
Also used : Dom4jXPath(org.jaxen.dom4j.Dom4jXPath) HashMap(java.util.HashMap) Element(org.dom4j.Element) JaxenException(org.jaxen.JaxenException) SimpleNamespaceContext(org.jaxen.SimpleNamespaceContext)

Aggregations

Element (org.dom4j.Element)5 JaxenException (org.jaxen.JaxenException)5 Dom4jXPath (org.jaxen.dom4j.Dom4jXPath)5 HashMap (java.util.HashMap)4 SimpleNamespaceContext (org.jaxen.SimpleNamespaceContext)4 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 Attribute (org.dom4j.Attribute)1 Document (org.dom4j.Document)1 DocumentException (org.dom4j.DocumentException)1 Namespace (org.dom4j.Namespace)1 Node (org.dom4j.Node)1 QName (org.dom4j.QName)1 SAXReader (org.dom4j.io.SAXReader)1 XPath (org.jaxen.XPath)1 InputSource (org.xml.sax.InputSource)1