Commit 00ec1446 authored by Arthur Bogaart's avatar Arthur Bogaart

HSTCONFIGEDIT-174: Misc small fixes

 - Use JCr session from UserSession to prevent NPE
 - Added null-check in #getReferenceables
parent bd659670
......@@ -34,6 +34,7 @@ import javax.jcr.Value;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.model.IDetachable;
import org.hippoecm.frontend.model.JcrNodeModel;
import org.hippoecm.frontend.session.UserSession;
import org.hippoecm.hst.plugins.frontend.util.HstConfigurationUtils;
import org.hippoecm.repository.util.JcrUtils;
import org.slf4j.Logger;
......@@ -218,7 +219,7 @@ public class HstContext implements IDetachable {
}
try {
Session session = model.getNode().getSession();
Session session = UserSession.get().getJcrSession();
if (session.itemExists(path)) {
return path.substring(root.length() + 1);
}
......@@ -319,7 +320,6 @@ public class HstContext implements IDetachable {
log.warn("Exception while retrieving lock info", e);
}
return lockData;
}
private class LockData {
......@@ -475,19 +475,21 @@ public class HstContext implements IDetachable {
private List<String> getReferenceables(Node parent, boolean recursive) {
List<String> refs = new ArrayList<>();
try {
for (NodeIterator it = parent.getNodes(); it.hasNext(); ) {
Node child = it.nextNode();
String relPath = relativePath(child.getPath());
relPath = getReferenceablePath(relPath);
refs.add(relPath);
if (recursive) {
refs.addAll(getReferenceables(child, recursive));
if (parent != null) {
try {
for (NodeIterator it = parent.getNodes(); it.hasNext(); ) {
Node child = it.nextNode();
String relPath = relativePath(child.getPath());
relPath = getReferenceablePath(relPath);
refs.add(relPath);
if (recursive) {
refs.addAll(getReferenceables(child, recursive));
}
}
} catch (RepositoryException e) {
log.error("Error loading list of hst:component", e);
}
} catch (RepositoryException e) {
log.error("Error loading list of hst:component", e);
}
return refs;
}
......@@ -495,7 +497,7 @@ public class HstContext implements IDetachable {
public String getContainerComponentNamespace() {
return namespacesRoot + "/containercomponent";
}
}
public class HstTemplateContext extends HstNamespaceContext {
......@@ -644,12 +646,12 @@ public class HstContext implements IDetachable {
@Override
public void init(JcrNodeModel model) throws RepositoryException {
Node siteNode = model.getNode();
Session session = siteNode.getSession();
Node root;
String configurationNodePath;
if (siteNode.hasProperty("hst:configurationpath")) {
// explicitly configured hst:configurationpath. This means, that
// explicitly configured hst:configurationpath. This means, that
// the configuration path can point to a live or preview hst:configuration
configurationNodePath = siteNode.getProperty("hst:configurationpath").getString();
......@@ -687,7 +689,7 @@ public class HstContext implements IDetachable {
root = session.getNode(configurationNodePath);
}
}
}
}
else {
// an implicit configuration path: Thus, look for a configuration path constructed with the current
// siteNode name. We only support the hst configuration editor for preview site nodes when conventions are used
......@@ -717,7 +719,7 @@ public class HstContext implements IDetachable {
root = session.getNode(configurationNodePath);
}
}
this.model = new JcrNodeModel(root);
}
......@@ -773,7 +775,7 @@ public class HstContext implements IDetachable {
return namespacesRoot + "/containeritempackage";
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment