script
groovy
java
system names
encoding
generate systemname in java code or in a script
Question
Content is generated in java code or in a script, but the title isn't synchronized to the systemname. Is it possible to activate an automatic synchronization?
Answer
No, an automatic synchronization is not possible. This is implemented in the UI of jahia. But you can encode and set the title as systemname. For instance add a mainContent in the contents directory of the digtiall webproject:
JCRNodeWrapper node = session.getNode("/sites/digitall/contents");
String title = "My title";
String systemName = org.jahia.services.content.JCRContentUtils.generateNodeName(title);
JCRNodeWrapper subNode = node.addNode(systemName, "jnt:mainContent");
subNode.setProperty("jcr:title", title);
subNode.setProperty("body", "My body");
subNode.saveSession();
To get the right encoded systemname the method org.jahia.services.content.JCRContentUtils.generateNodeName(title);
can be used. This encodes the string to only lowercase and spaces are replaced with dashes, etc.