[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 425
  • Last Modified:

How to access a Jackrabbit/JCR Nodes text content

Hi,

I am currently workling on a really trivial thing. At least it should be. Unfortuneately it isn't.
In my Jackrabbit JCR repository I have saved some Xml content. I have absolutely no problems in navigating and accessing nodes and attributes.

Unfortunately it seems to be impossible for me to get the simple text content of a node.

Lets take this example xml:
<test>huhu</test>
Let's assume I have an instance of javax.jcr.Node (To be more precise: org.apache.jackrabbit.core.NodeImpl)
With which code could I access the text string "huhu"?

Thanks in advance,
     Chris




0
ChristoferDutz
Asked:
ChristoferDutz
1 Solution
 
ChristoferDutzAuthor Commented:
Oh gee ... how I wish one day I wouldn't have to solve my problems on my own ;-)

The solution is (After digging into Jackrabbit Sourcecode and propably is valid in all JCR implementations):
The node containing the Text has a child node with the name "jcr:xmltext".
If you get this node, you have to have a look at the hidden Property with the name "jcr:xmlcharacters".

What an intuitive way to do this ;-)

So this code works for me:
Node titleNode = definitionNode.getNode("oval-def:title");
NodeImpl titleTextNode = (NodeImpl) titleNode.getNode("jcr:xmltext");
Property property = titleTextNode.getProperty("jcr:xmlcharacters");
String titleString = property.getString();

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now