import java.io.File;
import java.io.IOException;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.Map;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- String path = req.getPathInfo();
+// String path = req.getPathInfo();
+ String path = URLDecoder.decode(req.getPathInfo(), StandardCharsets.UTF_8.name());
String servletPath = req.getServletPath();
String[] p = path.split("/");
- String basePath =servletPath+'/'+p[1];
+ String basePath = servletPath + '/' + p[1];
String template = p[1] + ".ftl";
StringBuilder sb = new StringBuilder();
for (int i = 2; i < p.length; i++)
sb.append('/').append(p[i]);
-
+ String nodePath = sb.toString();
+ if ("".equals(nodePath.trim()))
+ nodePath = "/"; // root node
Session session = null;
try {
LoginContext lc = new LoginContext(NodeConstants.LOGIN_CONTEXT_USER,
}
});
- Node node = session.getNode(sb.toString());
+ Node node = session.getNode(nodePath);
Template t = cfg.getTemplate(template);
Map<String, Object> root = new HashMap<>();
resp.setContentType("text/html");
} catch (Exception e) {
- throw new CmsException("Cannot log in", e);
+ throw new CmsException("Cannot process template", e);
} finally {
JcrUtils.logoutQuietly(session);
}
package org.argeo.fm.jcr;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
if ("jcr:properties".equals(key))
return new PropertiesModel();
if ("jcr:parent".equals(key))
- return node.getParent() != null ? new JcrModel(node.getParent()) : null;
-
- Property property = node.getProperty(key);
- if (property == null)
- return null;
- return new SimpleScalar(property.getString());
+ return !"/".equals(node.getPath()) ? new JcrModel(node.getParent()) : null;
+
+ Property property;
+ if (!node.hasProperty(key)) {
+ List<Property> props = new ArrayList<>();
+ PropertyIterator pit = node.getProperties("*:" + key);
+ while (pit.hasNext())
+ props.add(pit.nextProperty());
+ if (props.size() == 0)
+ return null;
+ if (props.size() > 1)
+ throw new TemplateModelException(
+ "Too many properties match " + key + " (" + props + "), use prefix with \\: escape");
+ property = props.get(0);
+ } else
+ property = node.getProperty(key);
+ return propertyValues(property);
} catch (RepositoryException e) {
throw new TemplateModelException("Cannot get property " + key + " of " + node, e);
}