import java.util.List;
import javax.xml.namespace.NamespaceContext;
+import javax.xml.transform.TransformerFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import org.argeo.api.acr.Content;
import org.argeo.api.acr.ContentNotFoundException;
+import org.argeo.api.acr.CrName;
import org.argeo.api.acr.NamespaceUtils;
import org.argeo.api.acr.spi.ContentProvider;
import org.argeo.api.acr.spi.ProvidedContent;
// TODO centralise in some executor?
private final ThreadLocal<XPath> xPath;
+ private TransformerFactory transformerFactory;
+
private String mountPath;
public DomContentProvider(String mountPath, Document document) {
this.mountPath = mountPath;
this.document = document;
this.document.normalizeDocument();
+
+ transformerFactory = TransformerFactory.newInstance();
+
XPathFactory xPathFactory = XPathFactory.newInstance();
xPath = new ThreadLocal<>() {
if (nodes.getLength() > 1)
throw new IllegalArgumentException("Multiple content found for " + relativePath + " under " + mountPath);
if (nodes.getLength() == 0)
- throw new ContentNotFoundException("Path " + relativePath + " under " + mountPath + " was not found");
+ throw new ContentNotFoundException(session, mountPath + "/" + relativePath,
+ "Path " + relativePath + " under " + mountPath + " was not found");
Element element = (Element) nodes.item(0);
return new DomContent(session, this, element);
}
throw new IllegalArgumentException("Relative path cannot start with /");
String xPathExpression = '/' + relativePath;
if ("/".equals(mountPath))
- xPathExpression = "/cr:root" + xPathExpression;
+ xPathExpression = "/" + CrName.root.qName() + xPathExpression;
try {
NodeList nodes = (NodeList) xPath.get().evaluate(xPathExpression, document, XPathConstants.NODESET);
return nodes;
return Collections.unmodifiableList(res).iterator();
}
+ TransformerFactory getTransformerFactory() {
+ return transformerFactory;
+ }
+
}