You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Eric Peukert <er...@mail.inf.tu-dresden.de> on 2006/07/01 16:34:07 UTC
Converting node-type
Hello,
I try to convert a node and its node-type after it was already created.
Does anyone have an idea how that can be achieved?
I tried cloning the parent-node into another workspace, the removed
the node to be changed, added a new node with the same name and a new
node-type.
Then I tried to merge the orginal parent-node and the cloned parent -
nothing changes on the original node.
I tried the whole thing with removing and copying a changed not to
the original location.
session.refresh(true);
session.getRootNode().getNode(nodePath).remove();
session.getWorkspace().copy("workingCopy",
"/"+nodePath, "/"+nodePath);
testNode= session.getRootNode().getNode(nodeName);
testNode.save();
session.save();
I do not like the whole way of doing this - so ist there a nicer and
souccessful way?
I cannot call save any more , even if I do something after the copy
command.
javax.jcr.InvalidItemStateException: /: the item cannot be saved
because it has been modified externally.
at org.apache.jackrabbit.core.ItemImpl.getTransientStates
(ItemImpl.java:343)
at org.apache.jackrabbit.core.ItemImpl.save(ItemImpl.java:1054)
at org.apache.jackrabbit.core.SessionImpl.save(SessionImpl.java:805)
at ConvertType.main(ConvertType.java:123)
thanks
Eric
Re: Converting node-type
Posted by Eric Peukert <er...@mail.inf.tu-dresden.de>.
Thanks for your answer,
I try to use the Repository for storing Files, and especially XML-
Files. Unfortunately when importing these XML-Files with WebDav some
files are not imported as nt:file/nt:unstructured but in binary
from. So I need to convert the files from binary representation to
unstructured repo-imported content.
Thats basically what I am trying to do.
Normally I would not have to bother as the xml-mime -type should
trigger the web-dav client to import my content as xml content, not
binary. But this does not work for all the files I have.
thanks
Eric
Am 02.07.2006 um 07:35 schrieb Jukka Zitting:
> Hi,
>
> On 7/1/06, Eric Peukert <er...@mail.inf.tu-dresden.de> wrote:
>> I try to convert a node and its node-type after it was already
>> created.
>>
>> Does anyone have an idea how that can be achieved?
>
> You can add or remove the mixin types of a node, but you can not
> change its primary type. The best way to achieve the what you are
> trying to do, is make an in-memory copy of the node content, remove
> the node from the workspace, and create a new node with the copied
> content but a different primary type.
>
> What is your use case for trying to do this? The primary type is a
> fundamental property of a node, even more than its name that can be
> changed with Session.move(). You can think of the primary type of a
> node as the class of a Java object, i.e. there is no way to change
> that short of making a manual copy of the instance.
>
> If this is common use case for you, you might want to consider having
> a more generic primary type and using mixin types for dynamic node
> typing.
>
> BR,
>
> Jukka Zitting
>
> --
> Yukatan - http://yukatan.fi/ - info@yukatan.fi
> Software craftsmanship, JCR consulting, and Java development
Re: Converting node-type
Posted by Jukka Zitting <ju...@gmail.com>.
Hi,
On 7/1/06, Eric Peukert <er...@mail.inf.tu-dresden.de> wrote:
> I try to convert a node and its node-type after it was already created.
>
> Does anyone have an idea how that can be achieved?
You can add or remove the mixin types of a node, but you can not
change its primary type. The best way to achieve the what you are
trying to do, is make an in-memory copy of the node content, remove
the node from the workspace, and create a new node with the copied
content but a different primary type.
What is your use case for trying to do this? The primary type is a
fundamental property of a node, even more than its name that can be
changed with Session.move(). You can think of the primary type of a
node as the class of a Java object, i.e. there is no way to change
that short of making a manual copy of the instance.
If this is common use case for you, you might want to consider having
a more generic primary type and using mixin types for dynamic node
typing.
BR,
Jukka Zitting
--
Yukatan - http://yukatan.fi/ - info@yukatan.fi
Software craftsmanship, JCR consulting, and Java development