I want to create a node but I get Invalid name or path exception while creating a node, below is the exception
javax.jcr.RepositoryException: Invalid name or path: parentCategoty/tco[a].jpg
Hence I am using JcrUtil.escapeIllegalJcrChars to sanitize the path before creating but it seems not working.
Reference - https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/assets/manage/add-a...
JcrUtil.createPath(JcrUtil.escapeIllegalJcrChars("parentCategoty/tco[a].jpg"),JcrConstants.NT_UNSTRUCTURED, session);
Can you tell me what could be the problem ? Also is there any other API that will check the path give whether the path is valid or not, basically I don't want to get the exceltopn instead i want to put all invalid path in a collection. Is this possible ?
Solved! Go to Solution.
Views
Replies
Total Likes
Do not escape the entire path, just escape the name of file here i.e. tco[a].jpg
JcrUtil.createPath("parentCategoty/" + JcrUtil.escapeIllegalJcrChars("tco[a].jpg"),JcrConstants.NT_UNSTRUCTURED, session);
If you want to validate each node name in path then
String[] nodesArray = path.split("/");
String escapedPath = "";
for (String nodeName : nodesArray) {
if (nodeName.isEmpty())
continue;
escapedPath += "/" + (JcrUtil.isValidName(nodeName)? nodeName : JcrUtil.escapeIllegalJcrChars(nodeName));
}
JcrUtil.createPath(escapedPath, JcrConstants.NT_UNSTRUCTURED, jcrSession);
Views
Likes
Replies