how to get array values of a node property in jcr

user2000633 picture user2000633 · Jan 22, 2013 · Viewed 24.5k times · Source

Need help in getting the string[] values of node property??

for example I have a node image which has property "references" of type String[] . I need to get the first value of array.

Thanks

Answer

diffa picture diffa · Jan 22, 2013

From the Node, you can get the references property. And then call getValues to the reference values. From there, just take the first. Something like

public String getFirstReference(Node node) throws RepositoryException {
  Property references = node.getProperty("references");     
  Value[] values = references.getValues();
  return values[0].getString();     
}