Fix search in mounted DOM content provider
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / acr / xml / DomContentProvider.java
index 66ff878d5c6a9a644445a97bafa64869e19e2cfd..20f7eb1534cbb79fb21bd17e0fe93585e17bb706 100644 (file)
@@ -57,16 +57,6 @@ public class DomContentProvider implements ContentProvider, NamespaceContext {
                };
        }
 
-//     @Override
-//     public Content get() {
-//             return new DomContent(this, document.getDocumentElement());
-//     }
-
-//     public Element createElement(String name) {
-//             return document.createElementNS(null, name);
-//
-//     }
-
        @Override
        public ProvidedContent get(ProvidedSession session, String relativePath) {
                if ("".equals(relativePath))
@@ -85,9 +75,13 @@ public class DomContentProvider implements ContentProvider, NamespaceContext {
        protected NodeList findContent(String relativePath) {
                if (relativePath.startsWith("/"))
                        throw new IllegalArgumentException("Relative path cannot start with /");
-               String xPathExpression = '/' + relativePath;
-               if ("/".equals(mountPath))
-                       xPathExpression = "/" + CrName.root.qName() + xPathExpression;
+               String xPathExpression;
+               if (Content.ROOT_PATH.equals(mountPath)) {// repository root
+                       xPathExpression = "/" + CrName.root.get() + '/' + relativePath;
+               } else {
+                       String documentNodeName = document.getDocumentElement().getNodeName();
+                       xPathExpression = '/' + documentNodeName + '/' + relativePath;
+               }
                try {
                        NodeList nodes = (NodeList) xPath.get().evaluate(xPathExpression, document, XPathConstants.NODESET);
                        return nodes;
@@ -105,6 +99,7 @@ public class DomContentProvider implements ContentProvider, NamespaceContext {
                return nodes.getLength() != 0;
        }
 
+       @Override
        public void persist(ProvidedSession session) {
                if (mountPath != null) {
                        Content mountPoint = session.getMountPoint(mountPath);