On 1/21/11 10:18 AM, Markus Joschko wrote:
>> There's actually a direct solution to this problem. Register a service
>> using the interface org.apache.sling.servlets.post.NodeNameGenerator
>> instead of a PostProcessor.
>>
>> Your NodeNameGenerator would look like this:
>>
>> @Component
>> @Service
>> public class MyNodeNameGenerator implements NodeNameGenerator {
>>   public String getNodeName(SlingHttpServletRequest request, String
>> parentPath, boolean requirePrefix, NodeNameGenerator defaultNNG) {
>>     if (parentPath.equals("/parent")) {
>>        return "folderA/" + defaultNNG.getNodeName(request, parentPath,
>> requirePrefix, defaultNNG);
>>      } else {
>>
>>         return null;
>>      }
>>   }
>> }
> 
> Sounds interesting. Is the folder autogenerated if not existant (which
> can be the case)?
Yes. Just like if you post to /some/path/which/doesntexist/*

> If yes, there is one caveat: The folder needs a special nodetype. Any
> chance to deal with that?
You could create the folder node inside your NodeNameGenerator. This is
a bit more code, but would allow you full control over how the folder is
created (which it sounds like what you want).

Justin

> 
> 
> 
>>
>> On 1/21/11 6:58 AM, Markus Joschko wrote:
>>> Hi,
>>> I face some difficulties in realizing the following case:
>>>
>>> I have a node to which I want to add children. The problem is, that
>>> (depending on the content of the to be created node) it is not added
>>> to the node directly but a folder is created to which the node is
>>> added. Like that
>>>
>>> + parent
>>>      + folderA (dynamically created)
>>>          - childABC
>>>      + folderB (dynamically created)
>>>          -childBAC
>>>
>>> Because the folders might not be available, I post to parent/* and
>>> registered a postprocessor to create the folder and move the just
>>> created child to the corresponding folder.
>>> That works fine. However the redirect url is still pointing to the
>>> previous location (parent/childABC) instead of
>>> parent/folderA/childABC.
>>> And I can't find a way to modify the location of the response within
>>> the postprocessor.
>>>
>>> So I wonder whether I am on the right track or should choose a
>>> different approach. Alternatively I could create my own postoperation
>>> but that seems to be cumbersome as extending from ModifyOperation
>>> isn't easy because of the dependencies in the constructor and
>>> AbstractCreateOperation is package private. So I would basically need
>>> to copy code directly.
>>>
>>> Any thoughts on this?
>>>
>>> Thanks,
>>>  Markus
>>
>>

Reply via email to