You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by "Jukka Zitting (JIRA)" <ji...@apache.org> on 2009/12/15 12:03:18 UTC

[jira] Created: (JCR-2439) More utility methods in JcrUtils

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.


[jira] Commented: (JCR-2439) More utility methods in JcrUtils

Posted by "Alexander Klimetschek (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/JCR-2439?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12790716#action_12790716 ] 

Alexander Klimetschek commented on JCR-2439:
--------------------------------------------

> Couldn't we just implement NodeImpl.toString and PropertyImpl.toString ?

They are implemented in JR 2.0. But they print "node"/"property" + the path only, not the node type.

> 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.


[jira] Commented: (JCR-2439) More utility methods in JcrUtils

Posted by "Thomas Mueller (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/JCR-2439?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12790736#action_12790736 ] 

Thomas Mueller commented on JCR-2439:
-------------------------------------

> Node setNode(Node parent, String name, String type) 
> using addNode(name, type) or setPrimaryType(type) if needed.

That means, if a node exists with this name, the type of the node would be changed. Could you tell me the use case (when do you want to change the node type of an existing node)?

I probably would throw an exception if a node with this name already exists, but with a different primary type. Then I would then prefer the method name getOrAddXXX.




> 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.


[jira] Commented: (JCR-2439) More utility methods in JcrUtils

Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/JCR-2439?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12790702#action_12790702 ] 

Felix Meschberger commented on JCR-2439:
----------------------------------------

>  String toString(Item item)

Couldn't we just implement NodeImpl.toString and PropertyImpl.toString ?

> addXXX

looks reasonable

> setXXX

sounds useful, but I the "set" prefix sounds a bit strange

yet my alternative -- getOrAddXXX -- is probably not better ...

> 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.


[jira] Commented: (JCR-2439) More utility methods in JcrUtils

Posted by "Thomas Mueller (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/JCR-2439?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12790773#action_12790773 ] 

Thomas Mueller commented on JCR-2439:
-------------------------------------

+1 for JcrUtils.toString(Item) - same reason as Jukka

+1 for putNode(), putFolder(), putFile() - like Map.put


> 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.


[jira] Commented: (JCR-2439) More utility methods in JcrUtils

Posted by "Jukka Zitting (JIRA)" <ji...@apache.org>.
    [ 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.


[jira] Commented: (JCR-2439) More utility methods in JcrUtils

Posted by "Jukka Zitting (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/JCR-2439?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12790805#action_12790805 ] 

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

I've now added the following methods:

    String toString(Item item) 

    Node getOrAddNode(Node parent, String name)
    Node getOrAddNode(Node parent, String name, String type)

    Node getOrAddFolder(Node parent, String name)

    Node putFile(Node parent, String name, String mime, InputStream data)
    Node putFile(Node parent, String name, String mime, Calendar date, InputStream data)

The naming isn't as consistent as originally proposed, but I think it now better matches the conceptual difference between the putFile() operation that always writes and the getOrAdd methods that write only if the child node does not already exist.

> 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.


[jira] Resolved: (JCR-2439) More utility methods in JcrUtils

Posted by "Jukka Zitting (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JCR-2439?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jukka Zitting resolved JCR-2439.
--------------------------------

    Resolution: Fixed

Excellent point. I changed the order of arguments in revision 896513.

> 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
>            Assignee: Jukka Zitting
>            Priority: Minor
>             Fix For: 2.0-beta5
>
>
> 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.


[jira] Reopened: (JCR-2439) More utility methods in JcrUtils

Posted by "Tobias Bocanegra (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JCR-2439?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tobias Bocanegra reopened JCR-2439:
-----------------------------------


sorry, but i saw this issue too late, i would not mix the sequence of arguments in the signatures like in:

    Node putFile(Node parent, String name, String mime, InputStream data)
    Node putFile(Node parent, String name, String mime, Calendar date, InputStream data) 

but rather have:

    Node putFile(Node parent, String name, String mime, InputStream data)
    Node putFile(Node parent, String name, String mime, InputStream data, Calendar date) 

so that "optional" arguments always come at the end.

> 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
>            Assignee: Jukka Zitting
>            Priority: Minor
>             Fix For: 2.0-beta5
>
>
> 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.


[jira] Resolved: (JCR-2439) More utility methods in JcrUtils

Posted by "Jukka Zitting (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JCR-2439?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jukka Zitting resolved JCR-2439.
--------------------------------

       Resolution: Fixed
    Fix Version/s: 2.0-beta5
         Assignee: Jukka Zitting

Resolving as fixed. The methods I implemented work pretty well and the chosen method names should be a reasonable compromise that addresses all the points raised above.

> 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
>            Assignee: Jukka Zitting
>            Priority: Minor
>             Fix For: 2.0-beta5
>
>
> 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.


[jira] Commented: (JCR-2439) More utility methods in JcrUtils

Posted by "Sébastien Launay (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/JCR-2439?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12790776#action_12790776 ] 

Sébastien Launay commented on JCR-2439:
---------------------------------------

For toString() methods I found the path very useful especially for nodes.

I also prefers getOrAdd* instead of put* or set* because put and set are semantically speaking writable methods.
In some framework like Avalon [1] (RIP :)) they use an additional createNew boolean parameter to create an object if necessary and I think that the two use cases of createNew are interesting.

What is done for files can also be done for resources like:
- Node setResource(Node parent, String mime, InputStream data)
- Node setResource(Node parent, String mime, Calendar date, InputStream data)

Here use of set fits naturally as the method always modifies the node and/or parent node.

[1] http://excalibur.apache.org/apidocs/org/apache/avalon/framework/configuration/Configuration.html#getChild(java.lang.String,%20boolean)

> 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.