use of org.apache.sling.servlets.post.impl.helper.DefaultNodeNameGenerator in project sling by apache.
the class SlingPostServlet method configure.
@Modified
private void configure(final Config configuration) {
this.baseVersioningConfiguration = createBaseVersioningConfiguration(configuration);
final DateParser dateParser = new DateParser();
final String[] dateFormats = configuration.servlet_post_dateFormats();
for (String dateFormat : dateFormats) {
try {
dateParser.register(dateFormat);
} catch (Throwable t) {
log.warn("configure: Ignoring DateParser format {} because it is invalid: {}", dateFormat, t);
}
}
final String[] nameHints = configuration.servlet_post_nodeNameHints();
final int nameMax = configuration.servlet_post_nodeNameMaxLength();
final NodeNameGenerator nodeNameGenerator = new DefaultNodeNameGenerator(nameHints, nameMax);
final String paramMatch = configuration.servlet_post_ignorePattern();
final Pattern paramMatchPattern = Pattern.compile(paramMatch);
this.modifyOperation.setDateParser(dateParser);
this.modifyOperation.setDefaultNodeNameGenerator(nodeNameGenerator);
this.modifyOperation.setIgnoredParameterNamePattern(paramMatchPattern);
if (this.importOperation != null) {
this.importOperation.setDefaultNodeNameGenerator(nodeNameGenerator);
this.importOperation.setIgnoredParameterNamePattern(paramMatchPattern);
}
}
use of org.apache.sling.servlets.post.impl.helper.DefaultNodeNameGenerator in project sling by apache.
the class AbstractCreateOperation method generateName.
protected String generateName(SlingHttpServletRequest request, String basePath) throws PersistenceException {
// SLING-1091: If a :name parameter is supplied, the (first) value of this parameter is used unmodified as the name
// for the new node. If the name is illegally formed with respect to JCR name requirements, an exception will be
// thrown when trying to create the node. The assumption with the :name parameter is, that the caller knows what
// he (or she) is supplying and should get the exact result if possible.
RequestParameterMap parameters = request.getRequestParameterMap();
RequestParameter specialParam = parameters.getValue(SlingPostConstants.RP_NODE_NAME);
if (specialParam != null) {
if (specialParam.getString() != null && specialParam.getString().length() > 0) {
// If the path ends with a *, create a node under its parent, with
// a generated node name
basePath = basePath += "/" + specialParam.getString();
// if the resulting path already exists then report an error
if (request.getResourceResolver().getResource(basePath) != null) {
throw new PersistenceException("Collision in node names for path=" + basePath);
}
return basePath;
}
}
// no :name value was supplied, so generate a name
boolean requirePrefix = requireItemPathPrefix(request);
String generatedName = null;
if (extraNodeNameGenerators != null) {
for (NodeNameGenerator generator : extraNodeNameGenerators) {
generatedName = generator.getNodeName(request, basePath, requirePrefix, defaultNodeNameGenerator);
if (generatedName != null) {
break;
}
}
}
if (generatedName == null) {
generatedName = defaultNodeNameGenerator.getNodeName(request, basePath, requirePrefix, defaultNodeNameGenerator);
}
// If the path ends with a *, create a node under its parent, with
// a generated node name
basePath += "/" + generatedName;
basePath = ensureUniquePath(request, basePath);
return basePath;
}
Aggregations