package org.apache.sling.servlets.post.impl.helper;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.request.RequestParameter;
import org.apache.sling.api.request.RequestParameterMap;
Generates a node name based on a set of well-known request parameters
like title, description, etc.
See SLING-128.
if (parameterNames == null) { this.parameterNames = new String[0];
this.parameterNames = parameterNames;
this.maxLength = (maxNameLength > 0)
: DEFAULT_MAX_NAME_LENGTH;
Get a "nice" node name, if possible, based on given request
- Parameters:
request the requestbasePath the base pathrequirePrefix true if the parameter names for
properties requires a prefixdefaultNodeNameGenerator a default generator- Returns:
- a nice node name
RequestParameterMap parameters = request.getRequestParameterMap();
String valueToUse = null;
RequestParameter specialParam = parameters.getValue(SlingPostConstants.RP_NODE_NAME);
if ( specialParam != null ) { if ( specialParam.getString() != null && specialParam.getString().length() > 0 ) { valueToUse = specialParam.getString();
if ( valueToUse == null ) { specialParam = parameters.getValue(SlingPostConstants.RP_NODE_NAME_HINT);
if ( specialParam != null ) { if ( specialParam.getString() != null && specialParam.getString().length() > 0 ) { valueToUse = specialParam.getString();
if (valueToUse == null) { for (String param : parameterNames) { if (valueToUse != null) { param = SlingPostConstants.ITEM_PREFIX_RELATIVE_CURRENT.concat(param);
final RequestParameter[] pp = parameters.get(param);
for (RequestParameter p : pp) { valueToUse = p.getString();
if (valueToUse != null && valueToUse.length() > 0) { if (valueToUse != null) { result = filter.filter(valueToUse);
result = nextCounter() + "_" + System.currentTimeMillis();
if (result.length() > maxLength) { result = result.substring(0,maxLength);