jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Francisco Carriedo Scher <fcarrie...@gmail.com>
Subject Re: Creating a nt:linkedFile
Date Thu, 05 Apr 2012 10:43:51 GMT
Hi there,

i am creating now nt:linkedfile nodes to nt:file nodes correctly but as i
tried to access the contents through the browser i am not getting the
content actually and getting an empty directory listing instead (the same
of accessing an empty nt:folder node. By the way i noticed that nt:file
nodes are exposed in the browser like this:

http://localhost:8080/name/repository/default/file.jpg

and linked files like this (note the ending backslash):

http://localhost:8080/name/repository/default/linkedfile.jpg*/*


The code i am using is the following and i access the repository through
Webdav:

                        *// Node to place the nt:linkedfile node*
            folderNode = session.getNode(directoryForLink);
            *// The nt:file node the new link will point to*
            fileToLink = session.getNode(pathToLink);
            *// Creating the link node...*
            newLink = folderNode.addNode(linkname,
JcrConstants.NT_LINKEDFILE);
            *// Adding the content as a reference to the "real" content*
            newLink.setProperty("jcr:content",
fileToLink.getNode("jcr:content"));
            session.save();

Is this the expected behaviour? What else should i do to get the linked
files exposing the content through the browser as if they were files?


Additionally, will the scenario described above (files, linked files,
exposing everything through Webdav) work correctly with the garbage
collection running? By working i mean than the following would go fine:

1) User A stores a photo file myPhoto.jpg
2) User B stores a link to myPhoto.jpg named BsphotoFile.jpg
3) User A decides to delete myPhoto.jpg file
4) Is B still able to access the BsphotoFile.jpg?

I expect the garbage collection to work similar to Unix links (deleting
link only deletes the file when it is the last link) but i prefer to
ensure, any info about this?


Thanks for your attention in advance!

Regards.



2012/3/22 Francisco Carriedo Scher <fcarriedos@gmail.com>

> Thank you very much David, i was trying to clone the procedure of creating
> a nt:file node, setting the REFERENCE as a property worked perfectly and
> the link is created.
>
> Thank you very much for your time!
>
>
> 2012/3/21 David Buchmann <david.buchmann@liip.ch>
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> answer is inline
>>
>> Am 20.03.2012 23:40, schrieb Francisco Carriedo Scher:
>> > Thanks Lukas for your quick response, anyway i'm affraid i am still
>> missing
>> > something...
>> >
>> > First i add the "mix:referenceable" not only to the nt:file node but to
>> > it's jcr:content node too for the nt:file to be linked later:
>> >
>> >
>> >         Node fileNode = folderNode.addNode(file.getName(), "nt:file");
>> >         fileNode.addMixin("mix:referenceable");
>> >         Node resNode = fileNode.addNode("jcr:content", "nt:resource");
>> >         resNode.addMixin("mix:referenceable");
>> >         resNode.setProperty("jcr:mimeType", mimeType);
>> >         resNode.setProperty("jcr:encoding", encoding);
>> >         resNode.setProperty("jcr:data", binary);
>> >         session.save();
>> >
>> >
>> > and then tried this code:
>> >
>> >             folderNode = session.getNode(directoryForLink);
>> >             fileToLink = session.getNode(pathToLink);
>> >
>> >             for (NodeType aux : fileToLink.getMixinNodeTypes())
>> >                 System.out.println(aux.getName());
>> >             *// PRINTS: mix:referenceable*
>> >
>> >             resNode = fileToLink.getNode("jcr:content");
>> >
>> >             for (NodeType aux : resNode.getMixinNodeTypes())
>> >                 System.out.println(aux.getName());
>> >             *// PRINTS: NOTHING*
>> >
>> >             newLink = folderNode.addNode(linkname,
>> > JcrConstants.NT_LINKEDFILE);
>> >             newLink.addNode(JcrConstants.JCR_CONTENT,
>> > resNode.getIdentifier());
>>
>> you try to add a node with the name that is in JCR_CONTENT and the type
>> of the identifier. that makes no sense for jcr. the reference is a
>> property. a child node can never be a reference.
>> you want to do something like:
>> newLink.setProperty("jcr:content", resNode);
>>
>> then you can do link.getProperty("jcr:content").getNode() to get the
>> referenced node.
>>
>> >             *// EXCEPTION RAISES (during the line above)        *
>> >             session.save();
>> >
>> > and got this exception:
>> >
>> > javax.jcr.nodetype.NoSuchNodeTypeException:
>> > {}c01df2eb-7af0-49c7-a7fd-1a4fbc3b9822
>> >
>> >
>> > Any idea? Thanks for your attention!
>> >
>> >
>> >
>> >
>> > 2012/3/20 Lukas Kahwe Smith <mls@pooteeweet.org>
>> >
>> >>
>> >> On Mar 20, 2012, at 17:31 , Francisco Carriedo Scher wrote:
>> >>
>> >>> Hello,
>> >>>
>> >>> i have been trying to create a nt:linkedFile node but i don't know
>> what
>> >> is
>> >>> "REFERENCE" in
>> >>>
>> >>> [nt:linkedFile] > nt:hierarchyNode
>> >>>  primaryitem jcr:content
>> >>>  - jcr:content (REFERENCE) mandatory
>> >>>
>> >>> I have tried with the path of the node i want to link, a reference
>> >> obtained
>> >>> through JcrUtils.getReferences(nodeToLink)... But different exceptions
>> >>> arised.
>> >>
>> >>
>> >> references work on UUID's
>> >> the target node needs to have the mixing type "mix:referenceable" which
>> >> would give it a UUID automatically on save.
>> >>
>> >> regards,
>> >> Lukas Kahwe Smith
>> >> mls@pooteeweet.org
>> >>
>> >>
>> >>
>> >>
>> >
>>
>> - --
>> Liip AG // Agile Web Development // T +41 26 422 25 11
>> CH-1700 Fribourg // PGP 0xA581808B // www.liip.ch
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v1.4.10 (GNU/Linux)
>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>>
>> iEYEARECAAYFAk9pnVwACgkQqBnXnqWBgIv48ACfUIgy5KBnVkr3NK7iRB30LIiv
>> jT4AoLNruVeXXYM1hOCuZ06Ojoy2DOYu
>> =msAN
>> -----END PGP SIGNATURE-----
>>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message