private String requiredWorkspace;
protected JCRNodeWrapper createNode(HttpServletRequest req, Map<String, List<String>> parameters,
JCRNodeWrapper node, String nodeType, String nodeName, boolean forceCreation)
throws RepositoryException {
JCRNodeWrapper newNode;
boolean isNodeNameToBeNormalized = ServletRequestUtils.getBooleanParameter(req, Render.NORMALIZE_NODE_NAME, false);
if (StringUtils.isBlank(nodeName)) {
String nodeNameProperty = "jcr:title";
if (parameters.get(Render.NODE_NAME_PROPERTY) != null) {
nodeNameProperty = parameters.get(Render.NODE_NAME_PROPERTY).get(0);
}
if (parameters.get(nodeNameProperty) != null) {
nodeName = JCRContentUtils.generateNodeName(parameters.get(nodeNameProperty).get(0), 32);
} else {
nodeName = nodeType.substring(nodeType.lastIndexOf(":") + 1);
}
if (isNodeNameToBeNormalized) {
nodeName = JCRContentUtils.generateNodeName(nodeName, 255);
}
nodeName = JCRContentUtils.findAvailableNodeName(node, nodeName);
} else if (isNodeNameToBeNormalized) {
nodeName = JCRContentUtils.generateNodeName(nodeName, 255);
}
if(forceCreation) {
nodeName = JCRContentUtils.findAvailableNodeName(node, nodeName);
}
try {
newNode = node.getNode(nodeName);
if (!newNode.isCheckedOut()) {
newNode.checkout();
}
} catch (PathNotFoundException e) {
if (!node.isCheckedOut()) {
node.checkout();
}
newNode = node.addNode(nodeName, nodeType);
}
if (parameters.containsKey(Constants.JCR_MIXINTYPES)) {
for (Object o : ((ArrayList) parameters.get(Constants.JCR_MIXINTYPES))) {
String mixin = (String) o;
newNode.addMixin(mixin);
}
}
Set<Map.Entry<String, List<String>>> set = parameters.entrySet();
for (Map.Entry<String, List<String>> entry : set) {
String key = entry.getKey();
if (!Render.reservedParameters.contains(key)) {
List<String> values = entry.getValue();
ExtendedPropertyDefinition propertyDefinition = null;
propertyDefinition = newNode.getApplicablePropertyDefinition(key);
if (propertyDefinition == null) {
continue;
}
if (propertyDefinition.isMultiple()) {
newNode.setProperty(key, values.toArray(new String[values.size()]));
} else if (values.get(0).length() > 0) {
if (propertyDefinition.getRequiredType() == ExtendedPropertyType.DATE) {
DateTime dateTime = ISODateTimeFormat.dateOptionalTimeParser().parseDateTime(values.get(0));
newNode.setProperty(key, dateTime.toCalendar(Locale.ENGLISH));
} else {
newNode.setProperty(key, values.get(0));
}
}
}
}