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;
}
}
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);
}
}
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;
}
}
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;
}
}
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;
}
}
Aggregations