[ 
https://issues.apache.org/jira/browse/JCR-2439?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12790761#action_12790761
 ] 

Jukka Zitting commented on JCR-2439:
------------------------------------

> Item.toString() vs JcrUtils.toString(Item)

I'd like to have something that works with any JCR backend, including all the 
remoting and decoration layers we have.

It may also be a bit troublesome to make the Item.toString() methods do more 
complex operations like retrieving the node type name or property values, since 
that may throw tools like debuggers off balance. It's best if that method is as 
"safe" as possible.

> setXxx()

I considered using getOrAddXxx() as the name, but that pattern doesn't work 
that well for the setFile() case where I'd like a method that will not just 
make sure that the file node exists, but also updates the content of the file.

If "set" sounds strange, how about "put" as in putNode(), putFolder(), 
putFile()?

> setPrimaryType()

Good point, throwing an exception instead of trying to coerce the node type 
seems like a better alternative.

> More utility methods in JcrUtils
> --------------------------------
>
>                 Key: JCR-2439
>                 URL: https://issues.apache.org/jira/browse/JCR-2439
>             Project: Jackrabbit Content Repository
>          Issue Type: Improvement
>          Components: jackrabbit-jcr-commons
>            Reporter: Jukka Zitting
>            Priority: Minor
>
> I'd like to add at least the following utility methods to JcrUtils:
> For logging:
>     // Utility method to simplify log messages and debug prints:
>     // Node -> "name [type]"
>     // Property -> "@name = value(s)"
>     String toString(Item item)
> For making sure that a node exists:
>     // Returns the identified child node. If the child does not already exist,
>     // it is added using the default node type from the parent.
>     Node setNode(Node parent, String name)
>     // Same as above, but ensures that isNodeType(type) is true for the
>     // returned node, using addNode(name, type) or setPrimaryType(type)
>     // if needed.
>     Node setNode(Node parent, String name, String type)
> For adding (or setting, see above) nt:folder nodes:
>     // Adds a new nt:folder node with the given name
>     Node addFolder(Node parent, String name)
>     // Ensures that an nt:folder node with the given name exists
>     Node setFolder(Node parent, String name)
> For adding (or setting) nt:file nodes:
>     // Adds a new nt:file/nt:resource structure
>     // If the mime type contains a charset parameter, then the jcr:encoding 
> property is also set
>     Node addFile(Node parent, String name, String mime, InputStream data)
>     Node addFile(Node parent, String name, String mime, Calendar date, 
> InputStream data)
>     // Ensures that an nt:file/nt:resource structure exists with the given 
> data.
>     // Note that the type of a potential existing jcr:content node is not 
> modified
>     Node setFile(Node parent, String name, String mime, InputStream data)
>     Node setFile(Node parent, String name, String mime, Calendar date, 
> InputStream data)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to