You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Christian Eugster <ch...@gmx.net> on 2013/06/02 18:24:26 UTC
adding nodes programmatically: Exc
Hi,
I checked the internet resources (google, sling website etc) as good as
I can, but have not found a answer that I could follew to the following
problem:
I want to add Nodes to a sling repository by a service component. The
component references SlingRepository. After getting a Session from
loginAdministrative (thanks to Bertrand Delacretaz who showed me that
way) I check if the node in question is already added
(parent.hasNode(name). If yes, I get it (getNode(name) else I add a new
node to the parent node with addNode(name).
Because it is content I want to add the "sling:resourceType" property:
documentNode.setProperty("sling:resourceType", "thun/documents");
but get a ConstraintViolationException saying
no matching property definition found for
{http://sling.apache.org/jcr/sling/1.0}resourceType
What am I doing wrong?
Thank you
Christian
--
**************************************
Christian Eugster
Grissian 14
I-39010 Tisens
0039 0473 420 873
0041 79 594 85 45
christian.eugster@gmx.net
Re: adding nodes programmatically: Exc
Posted by Bertrand Delacretaz <bd...@apache.org>.
On Sun, Jun 2, 2013 at 8:19 PM, Eric Norman <er...@gmail.com> wrote:
> ...you would either need to use the addNode variant (see [1]) that
> specifies a primary nodetype for the new node that does allow that
> property, or add a mixin type that adds the property declaration....
Or use more permissive node types like nt:unstructured and
sling:Folder for the parent nodes.
-Bertrand
Re: adding nodes programmatically: Exc
Posted by Eric Norman <er...@gmail.com>.
The child node created by your addNode(name) call has a node type that does
not declare "sling:resourceType" as an allowed property for the node.
So you would either need to use the addNode variant (see [1]) that
specifies a primary nodetype for the new node that does allow that
property, or add a mixin type that adds the property declaration.
For example:
//use a some primary node type where 'sling:resourceType' is already
allowed
node.addNode(name, "nt:unstructured");
or:
//create a child using the default primary node type
Node child = node.addNode(name);
//add mixin type (see [2]) to make sure the 'sling:resourceType' property
is allowed
child.addMixin("sling:Resource");
1.
http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/Node.html#addNode(java.lang.String,
java.lang.String)
2,
http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/Node.html#addMixin(java.lang.String)
On Sun, Jun 2, 2013 at 9:24 AM, Christian Eugster <christian.eugster@gmx.net
> wrote:
> Hi,
>
> I checked the internet resources (google, sling website etc) as good as I
> can, but have not found a answer that I could follew to the following
> problem:
>
> I want to add Nodes to a sling repository by a service component. The
> component references SlingRepository. After getting a Session from
> loginAdministrative (thanks to Bertrand Delacretaz who showed me that way)
> I check if the node in question is already added (parent.hasNode(name). If
> yes, I get it (getNode(name) else I add a new node to the parent node with
> addNode(name).
>
> Because it is content I want to add the "sling:resourceType" property:
>
> documentNode.setProperty("**sling:resourceType", "thun/documents");
>
> but get a ConstraintViolationException saying
>
> no matching property definition found for {http://sling.apache.org/jcr/**
> sling/1.0}resourceType<http://sling.apache.org/jcr/sling/1.0%7DresourceType>
>
> What am I doing wrong?
>
> Thank you
>
> Christian
>
>
> --
> ****************************************
> Christian Eugster
> Grissian 14
> I-39010 Tisens
> 0039 0473 420 873
> 0041 79 594 85 45
> christian.eugster@gmx.net
>