Use released Argeo Maven plugin
[gpl/argeo-suite.git] / knowledge / org.argeo.support.odk / src / org / argeo / support / odk / servlet / OdkFormServlet.java
index 93f41479ded820342874e326a9ced9631af4db66..cab562cc6465fbd462d3675bec8f7b4f2e9fda27 100644 (file)
@@ -3,6 +3,8 @@ package org.argeo.support.odk.servlet;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
@@ -16,9 +18,10 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.io.FilenameUtils;
-import org.argeo.cms.auth.ServletAuthUtils;
+import org.argeo.cms.servlet.ServletAuthUtils;
 import org.argeo.jcr.Jcr;
 import org.argeo.support.odk.OdkForm;
+import org.argeo.support.odk.OdkNames;
 
 /** Retrieves a single form. */
 public class OdkFormServlet extends HttpServlet {
@@ -34,10 +37,14 @@ public class OdkFormServlet extends HttpServlet {
                Session session = ServletAuthUtils.doAs(() -> Jcr.login(repository, null), req);
 
                String pathInfo = req.getPathInfo();
+               if (pathInfo.startsWith("//"))
+                       pathInfo = pathInfo.substring(1);
 
+               boolean oldApproach = false;
                try {
-                       if (session.nodeExists(pathInfo)) {
-                               session.exportDocumentView(pathInfo + "/h:html", resp.getOutputStream(), true, false);
+                       if (!oldApproach) {
+                               String path = URLDecoder.decode(pathInfo, StandardCharsets.UTF_8);
+                               session.exportDocumentView(path + "/" + OdkNames.H_HTML, resp.getOutputStream(), true, false);
                        } else {
 
                                String fileName = FilenameUtils.getName(pathInfo);