Commit ed25eb5a authored by Michael Metternich's avatar Michael Metternich

HSTTWO-4238 Check for rootPath in setting picker rootPath

parent 3497f0b5
......@@ -131,8 +131,9 @@ public class HstManageContentTag extends TagSupport {
return EVAL_PAGE;
}
String absoluteRootPath;
try {
checkRootPath(requestContext);
absoluteRootPath = checkRootPath(requestContext);
} catch (final RepositoryException e) {
log.error("Exception while checking rootPath parameter.", e);
return EVAL_PAGE;
......@@ -141,7 +142,7 @@ public class HstManageContentTag extends TagSupport {
final String componentValue = getComponentValue(requestContext, isRelativePathParameter);
try {
write(documentId, componentValue, jcrPath, isRelativePathParameter);
write(documentId, componentValue, jcrPath, isRelativePathParameter, absoluteRootPath);
} catch (final IOException ignore) {
throw new JspException("Manage content tag exception: cannot write to the output writer.");
}
......@@ -151,20 +152,15 @@ public class HstManageContentTag extends TagSupport {
}
}
private void checkRootPath(final HstRequestContext requestContext) throws RepositoryException {
private String checkRootPath(final HstRequestContext requestContext) throws RepositoryException {
if (rootPath == null) {
return;
return null;
}
String checkPath;
if (StringUtils.startsWith(rootPath, "/")) {
checkPath = rootPath;
} else {
checkPath = "/" + requestContext.getSiteContentBasePath() + "/" + rootPath;
}
final String absoluteRootPath = getAbsoluteRootPath(requestContext);
try {
final Node rootPathNode = requestContext.getSession().getNode(checkPath);
final Node rootPathNode = requestContext.getSession().getNode(absoluteRootPath);
if (!rootPathNode.isNodeType(HippoStdNodeType.NT_FOLDER) && !rootPathNode.isNodeType(HippoStdNodeType.NT_DIRECTORY)) {
log.error("Rootpath '{}' is not a folder node. Parameters rootPath and defaultPath are ignored.", rootPath);
rootPath = null;
......@@ -175,6 +171,15 @@ public class HstManageContentTag extends TagSupport {
rootPath = null;
defaultPath = null;
}
return absoluteRootPath;
}
private String getAbsoluteRootPath(final HstRequestContext requestContext) {
if (StringUtils.startsWith(rootPath, "/")) {
return rootPath;
} else {
return "/" + requestContext.getSiteContentBasePath() + "/" + rootPath;
}
}
private String getComponentValue(final HstRequestContext requestContext, final boolean isRelativePathParameter) {
......@@ -227,15 +232,15 @@ public class HstManageContentTag extends TagSupport {
}
private void write(final String documentId, final String componentValue, final JcrPath jcrPath,
final boolean isRelativePathParameter) throws IOException {
final boolean isRelativePathParameter, final String absoluteRootPath) throws IOException {
final JspWriter writer = pageContext.getOut();
final Map<String, Object> attributeMap = getAttributeMap(documentId, componentValue, jcrPath, isRelativePathParameter);
final Map<String, Object> attributeMap = getAttributeMap(documentId, componentValue, jcrPath, isRelativePathParameter, absoluteRootPath);
final String comment = encloseInHTMLComment(toJSONMap(attributeMap));
writer.print(comment);
}
private Map<String, Object> getAttributeMap(final String documentId, final String componentValue, final JcrPath jcrPath,
final boolean isRelativePathParameter) {
final boolean isRelativePathParameter, final String absoluteRootPath) {
final Map<String, Object> result = new LinkedHashMap<>();
writeToMap(result, ChannelManagerConstants.HST_TYPE, "MANAGE_CONTENT_LINK");
writeToMap(result, "uuid", documentId);
......@@ -253,7 +258,7 @@ public class HstManageContentTag extends TagSupport {
writeToMap(result, "pickerConfiguration", jcrPath.pickerConfiguration());
writeToMap(result, "pickerInitialPath", jcrPath.pickerInitialPath());
writeToMap(result, "pickerRemembersLastVisited", Boolean.toString(jcrPath.pickerRemembersLastVisited()));
writeToMap(result, "pickerRootPath", jcrPath.pickerRootPath());
writeToMap(result, "pickerRootPath", absoluteRootPath != null ? absoluteRootPath : jcrPath.pickerRootPath());
final String nodeTypes = Arrays.stream(jcrPath.pickerSelectableNodeTypes()).collect(Collectors.joining(","));
writeToMap(result, "pickerSelectableNodeTypes", nodeTypes);
......
......@@ -591,6 +591,33 @@ public class HstManageContentTagTest {
+ "} -->"));
}
@Test
public void pickerRootPathTest() throws Exception {
tag.setParameterName("absPath");
tag.setRootPath("relative/path");
Session jcrSession = createMock(Session.class);
hstRequestContext.setSession(jcrSession);
hstRequestContext.setSiteContentBasePath("my/channel/path");
Node folderNode = createMock(Node.class);
expect(folderNode.isNodeType(HippoStdNodeType.NT_FOLDER)).andReturn(false);
expect(folderNode.isNodeType(HippoStdNodeType.NT_DIRECTORY)).andReturn(true);
expect(jcrSession.getNode("/my/channel/path/relative/path")).andReturn(folderNode);
replay(jcrSession, folderNode);
assertThat(tag.doEndTag(), is(EVAL_PAGE));
assertThat(response.getContentAsString(), is("<!-- {"
+ "\"HST-Type\":\"MANAGE_CONTENT_LINK\","
+ "\"rootPath\":\"relative/path\","
+ "\"parameterName\":\"absPath\","
+ "\"parameterValueIsRelativePath\":\"false\","
+ "\"pickerConfiguration\":\"cms-pickers/documents\","
+ "\"pickerRemembersLastVisited\":\"true\","
+ "\"pickerRootPath\":\"/my/channel/path/relative/path\""
+ "} -->"));
}
private static void assertLogged(final Log4jInterceptor listener, final String expectedMessage) {
assertThat("expected log message '" + expectedMessage + "'", listener.messages().anyMatch((msg) -> msg.equals(expectedMessage)), is(true));
assertThat(listener.getEvents().size(), is(1));
......
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