1 package org.argeo.people.web;
2
3 import javax.jcr.Node;
4 import javax.jcr.RepositoryException;
5 import javax.jcr.Session;
6 import javax.jcr.Value;
7
8 import org.argeo.connect.resources.ResourcesService;
9 import org.argeo.connect.util.ConnectUtils;
10 import org.argeo.people.PeopleException;
11
12
13 public class PeopleWebSnippets {
14
15 public static String getTagLikeValues(ResourcesService tagService, String tagId, Node taggableNode,
16 String taggablePropName, String prefix) {
17 StringBuilder builder = new StringBuilder();
18 try {
19 Session session = taggableNode.getSession();
20 Node tagParent = tagService.getTagLikeResourceParent(session, tagId);
21
22 if (taggableNode.hasProperty(taggablePropName)) {
23 for (Value value : taggableNode.getProperty((taggablePropName)).getValues()) {
24 String valueStr = value.getString();
25 Node tag = tagService.getRegisteredTag(tagParent, valueStr);
26 builder.append(prefix);
27 builder.append("<a href=\"#" + tag.getPath() + "\">").append(valueStr).append("</a> ");
28 }
29 }
30 } catch (RepositoryException e) {
31 throw new PeopleException(
32 "Error while tag like property " + taggablePropName + " values for node " + taggableNode, e);
33 }
34 return ConnectUtils.replaceAmpersand(builder.toString().trim());
35 }
36 }