Hi Jan,
in the meanwhile this is the final (and tested) version.
It is thinked to run over a fully access repos..
[code]
/**
* Found the node position BETWEEN the provided content type. Position is 0
based.
*
* @param content
* @return
*/
public int getContentPosition(final Content content, final ItemType type) {
if (content != null) {
Content parent;
try {
parent = content.getParent();
if (parent != null) {
final NodeIterator it =
parent.getJCRNode().getNodes();
int position = -1;
while (it.hasNext()) {
final Node node = (Node) it.next();
if
(StringUtils.equals(node.getPrimaryNodeType().getName(), type.getSystemName()))
{
position++;
if
(StringUtils.equals(node.getUUID(), content.getUUID())) {
return position;
}
}
}
}
} catch (RepositoryException e) {
//
}
}
return -1;
}
[/code]
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Jan Haderka (via
Magnolia Forums)
Sent: martedì, 4. dicembre 2012 17:26
To: Magnolia User List
Subject: [magnolia-user] Re: Get node index / position (not same-name sibling!)
Hey Matteo,
I'm afraid there is no better solution. Pbly also because it's not mandatory
for all repo implementations to support ordering
http://www.day.com/specs/jcr/2.0/23_Orderable_Child_Nodes.html
To make the code above more efficient you should use JCR node iterators
directly rather then iterating over collection of all children. -
content.getJCRNode().getNodes() This way you at least avoid getting all
children in memory at same time.
BTW how is it w/ permissions - some users might not be allowed to see all the
siblings and then calculated index won't be same for all. Is that ok?
HTH,
Jan
--
Context is everything:
http://forum.magnolia-cms.com/forum/thread.html?threadId=c61d27c2-4d7c-4cee-8c36-92d6521d71d6
----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------
----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------