protected String generateName()

in src/main/java/org/apache/sling/servlets/post/impl/operations/AbstractCreateOperation.java [628:678]


    protected String generateName(SlingJakartaHttpServletRequest 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 (JakartaNodeNameGenerator 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;
    }