You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Sudhan <s....@gmail.com> on 2007/03/13 19:16:17 UTC

Re: [JCR Browser] Is there a way to update nt:file nodes property

Hi,

Now I have a event listener which listens for event : Node_Added

session.getWorkspace().getObservationManager().addEventListener(
					this, 
					Event.NODE_ADDED,
					"/jcr:system/jcr:versionStorage", // "/",
					true, 
					null, 
					new String[] { "nt:base" }, // parent of nt:frozenNode!
					false);

I am dealing with only nt:file node and jcr:content is mixin:versionable. So
whenever a new node is created I get an event with the new version say 1.1

My code further computes and finds out the file size of this updated or
inserted node. Also i need to set a property called as fileSize on the new
version node (1.1). But when i try to do it by performing checkout,
setProperty(), save and then checkin -  i am incrementing the version node
with 1.2 version. This i do not want to have 1.2 version as it is just a
update of fileSize property on version node.

Now when i try to set a property on parent node, here it is nt:file node, it
gives ConstraintViolationException on that node type.

Is there any way so that i can update the property either on the version
node or nt:file node without actually creating  a new version or throwing a
ConstraintViolationException.(I know nt:file does not allow setting a
property fileSize)

thanks,

Sudhan

Paco Avila-2 wrote:
> 
> El lun, 12-03-2007 a las 14:49 -0700, Sudhan escribió:
>> Hi,
>> 
>> Is there a way to insert/update nt:file nodes property when jcr:content
>> node
>> is having jcr:mixintypes as mix:versionable. 
>> 
>> Meaning nt:file is non versionable node and jcr:content is versionable,
>> and
>> on updation of new version to jcr:content i need to compute the file size
>> and update a property like "size" on nt:file which is non - versionable
>> without doing checkout and checkin.
> 
> I think I don't understood you. Where is the problem?
> 
> -- 
> GIT Consultors S.L.
> c\ Francesc Rover 2-B
> 07003 Palma de Mallorca
> (Illes Balears)
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Is-there-a-way-to-update-nt%3Afile-nodes-property-tf3392506.html#a9460324
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: [JCR Browser] Is there a way to update nt:file nodes property

Posted by Tobias Bocanegra <to...@day.com>.
> Is there any other way to achive above goal.
as i said, create a own nodetype and store the file size when the
jcr:data gets changed.

regards, toby
-- 
-----------------------------------------< tobias.bocanegra@day.com >---
Tobias Bocanegra, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
T +41 61 226 98 98, F +41 61 226 98 97
-----------------------------------------------< http://www.day.com >---

Re: [JCR Browser] Is there a way to update nt:file nodes property

Posted by Paco Avila <pa...@git.es>.
El mié, 14-03-2007 a las 10:47 +0200, Jukka Zitting escribió:
> Hi,
> 
> On 3/14/07, Sudhan <s....@gmail.com> wrote:
> > Actually my application needs to store difference of file size between
> > version 1.1 and 1.0. Say i updated a file abc.txt by adding some 20 kb of
> > data. I need to see this 20 kb on version 1.1 so that I can know that how kb
> > difference exists between the present version and its predecessor.
> >
> > presently i have a listener which listens to /jcr:system/jcr:versionStorage
> > node.
> >
> > Is there any other way to achive above goal.
> 
> The version history keeps a full copy of also the binary properties of
> previous versions, so you could use the getLength() method also to
> find the previous file sizes.
> 
> The following code would print out size of the current version and of
> all the predecessor versions:
> 
>     Node file = <the checked out copy of the file>;
>     System.out.println("Current: "
>         + file.getProperty("jcr:content/jcr:data").getLength());
>     Version base = file.getBaseVersion();
>     System.out.println(base.getCreated() + ": "
>         + base.getProperty("jcr:frozenNode/jcr:content/jcr:data").getLength());
>     Version[] predecessors = base.getPredecessors();
>     for (int i = 0; i < predecessors.length; i++) {
>         System.out.println(predecessors[i].getCreated() + ": "
>             + file.getProperty("jcr:frozenNode/jcr:content/jcr:data").getLength());
>     }

The line "file.getProperty("jcr:content/jcr:data").getLength()" read the
data and calculate the lengh. I think this is slower than storing the
document size in a property when you upload it.

-- 
GIT Consultors S.L.
c\ Francesc Rover 2-B
07003 Palma de Mallorca
(Illes Balears)


Re: [JCR Browser] Is there a way to update nt:file nodes property

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 3/14/07, Jukka Zitting <ju...@gmail.com> wrote:
>     Version[] predecessors = base.getPredecessors();
>     for (int i = 0; i < predecessors.length; i++) {
>         System.out.println(predecessors[i].getCreated() + ": "
>             + file.getProperty("jcr:frozenNode/jcr:content/jcr:data").getLength());
>     }

Oops, s/file/predecessors[i]/

BR,

Jukka Zitting

Re: [JCR Browser] Is there a way to update nt:file nodes property

Posted by Lubos and Alena Pochman <po...@gmail.com>.
Hmm, this does not work for me. I am getting "path does not exist" exception
when doing
predecessors[i].getProperty("jcr:frozenNode/jcr:content/jcr:data"),
but I can get the property on the current version with predecessors[i]
.getProperty("jcr:frozenNode/jcr:content/jcr:data")?

What am I doing wrong?

Lubos

On 3/14/07, Jukka Zitting <ju...@gmail.com> wrote:
>
> Hi,
>
> On 3/14/07, Sudhan <s....@gmail.com> wrote:
> > Actually my application needs to store difference of file size between
> > version 1.1 and 1.0. Say i updated a file abc.txt by adding some 20 kb
> of
> > data. I need to see this 20 kb on version 1.1 so that I can know that
> how kb
> > difference exists between the present version and its predecessor.
> >
> > presently i have a listener which listens to
> /jcr:system/jcr:versionStorage
> > node.
> >
> > Is there any other way to achive above goal.
>
> The version history keeps a full copy of also the binary properties of
> previous versions, so you could use the getLength() method also to
> find the previous file sizes.
>
> The following code would print out size of the current version and of
> all the predecessor versions:
>
>     Node file = <the checked out copy of the file>;
>     System.out.println("Current: "
>         + file.getProperty("jcr:content/jcr:data").getLength());
>     Version base = file.getBaseVersion();
>     System.out.println(base.getCreated() + ": "
>         + base.getProperty
> ("jcr:frozenNode/jcr:content/jcr:data").getLength());
>     Version[] predecessors = base.getPredecessors();
>     for (int i = 0; i < predecessors.length; i++) {
>         System.out.println(predecessors[i].getCreated() + ": "
>             + file.getProperty
> ("jcr:frozenNode/jcr:content/jcr:data").getLength());
>     }
>
> BR,
>
> Jukka Zitting
>

Re: [JCR Browser] Is there a way to update nt:file nodes property

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 3/14/07, Sudhan <s....@gmail.com> wrote:
> Actually my application needs to store difference of file size between
> version 1.1 and 1.0. Say i updated a file abc.txt by adding some 20 kb of
> data. I need to see this 20 kb on version 1.1 so that I can know that how kb
> difference exists between the present version and its predecessor.
>
> presently i have a listener which listens to /jcr:system/jcr:versionStorage
> node.
>
> Is there any other way to achive above goal.

The version history keeps a full copy of also the binary properties of
previous versions, so you could use the getLength() method also to
find the previous file sizes.

The following code would print out size of the current version and of
all the predecessor versions:

    Node file = <the checked out copy of the file>;
    System.out.println("Current: "
        + file.getProperty("jcr:content/jcr:data").getLength());
    Version base = file.getBaseVersion();
    System.out.println(base.getCreated() + ": "
        + base.getProperty("jcr:frozenNode/jcr:content/jcr:data").getLength());
    Version[] predecessors = base.getPredecessors();
    for (int i = 0; i < predecessors.length; i++) {
        System.out.println(predecessors[i].getCreated() + ": "
            + file.getProperty("jcr:frozenNode/jcr:content/jcr:data").getLength());
    }

BR,

Jukka Zitting

Re: [JCR Browser] Is there a way to update nt:file nodes property

Posted by Sudhan <s....@gmail.com>.
Hello Toby,

Thanks for  your help.

Actually my application needs to store difference of file size between
version 1.1 and 1.0. Say i updated a file abc.txt by adding some 20 kb of
data. I need to see this 20 kb on version 1.1 so that I can know that how kb
difference exists between the present version and its predecessor.

presently i have a listener which listens to /jcr:system/jcr:versionStorage
node.

Is there any other way to achive above goal.

thanks,

Sudhan


Tobias Bocanegra wrote:
> 
> hi,
> i would create a new nodetype, lets say: my:Resource that extends
> nt:resource that additionally contains a property: my:fileSize. you
> can register an event listener that listens on changes on the jcr:data
> property. whenever it triggers, you can update the my:fileSize
> property and then afterwards checkin the nt:file node.
> 
> however, why do you want to store the file size explicitly when you
> can retrieve it via getProperty("jcr:data").getLength() ?
> 
> regards, toby
> 
> On 3/13/07, Sudhan <s....@gmail.com> wrote:
>>
>> Hi,
>>
>> Now I have a event listener which listens for event : Node_Added
>>
>> session.getWorkspace().getObservationManager().addEventListener(
>>                                         this,
>>                                         Event.NODE_ADDED,
>>                                         "/jcr:system/jcr:versionStorage",
>> // "/",
>>                                         true,
>>                                         null,
>>                                         new String[] { "nt:base" }, //
>> parent of nt:frozenNode!
>>                                         false);
>>
>> I am dealing with only nt:file node and jcr:content is mixin:versionable.
>> So
>> whenever a new node is created I get an event with the new version say
>> 1.1
>>
>> My code further computes and finds out the file size of this updated or
>> inserted node. Also i need to set a property called as fileSize on the
>> new
>> version node (1.1). But when i try to do it by performing checkout,
>> setProperty(), save and then checkin -  i am incrementing the version
>> node
>> with 1.2 version. This i do not want to have 1.2 version as it is just a
>> update of fileSize property on version node.
>>
>> Now when i try to set a property on parent node, here it is nt:file node,
>> it
>> gives ConstraintViolationException on that node type.
>>
>> Is there any way so that i can update the property either on the version
>> node or nt:file node without actually creating  a new version or throwing
>> a
>> ConstraintViolationException.(I know nt:file does not allow setting a
>> property fileSize)
>>
>> thanks,
>>
>> Sudhan
>>
>> Paco Avila-2 wrote:
>> >
>> > El lun, 12-03-2007 a las 14:49 -0700, Sudhan escribió:
>> >> Hi,
>> >>
>> >> Is there a way to insert/update nt:file nodes property when
>> jcr:content
>> >> node
>> >> is having jcr:mixintypes as mix:versionable.
>> >>
>> >> Meaning nt:file is non versionable node and jcr:content is
>> versionable,
>> >> and
>> >> on updation of new version to jcr:content i need to compute the file
>> size
>> >> and update a property like "size" on nt:file which is non -
>> versionable
>> >> without doing checkout and checkin.
>> >
>> > I think I don't understood you. Where is the problem?
>> >
>> > --
>> > GIT Consultors S.L.
>> > c\ Francesc Rover 2-B
>> > 07003 Palma de Mallorca
>> > (Illes Balears)
>> >
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Is-there-a-way-to-update-nt%3Afile-nodes-property-tf3392506.html#a9460324
>> Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> -----------------------------------------< tobias.bocanegra@day.com >---
> Tobias Bocanegra, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
> T +41 61 226 98 98, F +41 61 226 98 97
> -----------------------------------------------< http://www.day.com >---
> 
> 

-- 
View this message in context: http://www.nabble.com/Is-there-a-way-to-update-nt%3Afile-nodes-property-tf3392506.html#a9464385
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: [JCR Browser] Is there a way to update nt:file nodes property

Posted by Tobias Bocanegra <to...@day.com>.
hi,
i would create a new nodetype, lets say: my:Resource that extends
nt:resource that additionally contains a property: my:fileSize. you
can register an event listener that listens on changes on the jcr:data
property. whenever it triggers, you can update the my:fileSize
property and then afterwards checkin the nt:file node.

however, why do you want to store the file size explicitly when you
can retrieve it via getProperty("jcr:data").getLength() ?

regards, toby

On 3/13/07, Sudhan <s....@gmail.com> wrote:
>
> Hi,
>
> Now I have a event listener which listens for event : Node_Added
>
> session.getWorkspace().getObservationManager().addEventListener(
>                                         this,
>                                         Event.NODE_ADDED,
>                                         "/jcr:system/jcr:versionStorage", // "/",
>                                         true,
>                                         null,
>                                         new String[] { "nt:base" }, // parent of nt:frozenNode!
>                                         false);
>
> I am dealing with only nt:file node and jcr:content is mixin:versionable. So
> whenever a new node is created I get an event with the new version say 1.1
>
> My code further computes and finds out the file size of this updated or
> inserted node. Also i need to set a property called as fileSize on the new
> version node (1.1). But when i try to do it by performing checkout,
> setProperty(), save and then checkin -  i am incrementing the version node
> with 1.2 version. This i do not want to have 1.2 version as it is just a
> update of fileSize property on version node.
>
> Now when i try to set a property on parent node, here it is nt:file node, it
> gives ConstraintViolationException on that node type.
>
> Is there any way so that i can update the property either on the version
> node or nt:file node without actually creating  a new version or throwing a
> ConstraintViolationException.(I know nt:file does not allow setting a
> property fileSize)
>
> thanks,
>
> Sudhan
>
> Paco Avila-2 wrote:
> >
> > El lun, 12-03-2007 a las 14:49 -0700, Sudhan escribió:
> >> Hi,
> >>
> >> Is there a way to insert/update nt:file nodes property when jcr:content
> >> node
> >> is having jcr:mixintypes as mix:versionable.
> >>
> >> Meaning nt:file is non versionable node and jcr:content is versionable,
> >> and
> >> on updation of new version to jcr:content i need to compute the file size
> >> and update a property like "size" on nt:file which is non - versionable
> >> without doing checkout and checkin.
> >
> > I think I don't understood you. Where is the problem?
> >
> > --
> > GIT Consultors S.L.
> > c\ Francesc Rover 2-B
> > 07003 Palma de Mallorca
> > (Illes Balears)
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Is-there-a-way-to-update-nt%3Afile-nodes-property-tf3392506.html#a9460324
> Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
>
>


-- 
-----------------------------------------< tobias.bocanegra@day.com >---
Tobias Bocanegra, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
T +41 61 226 98 98, F +41 61 226 98 97
-----------------------------------------------< http://www.day.com >---