1 13 package info.magnolia.cms.core.search; 14 15 import info.magnolia.cms.core.Content; 16 import info.magnolia.cms.core.ItemType; 17 import info.magnolia.cms.core.Path; 18 import info.magnolia.cms.security.AccessManager; 19 import info.magnolia.cms.security.Permission; 20 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 import java.util.Hashtable ; 24 import java.util.Map ; 25 26 import javax.jcr.Node; 27 import javax.jcr.NodeIterator; 28 import javax.jcr.RepositoryException; 29 30 import org.apache.commons.lang.StringUtils; 31 import org.apache.log4j.Logger; 32 33 34 38 public class QueryResultImpl implements QueryResult { 39 40 43 private static Logger log = Logger.getLogger(QueryResultImpl.class); 44 45 48 private javax.jcr.query.QueryResult result; 49 50 53 private Map objectStore = new Hashtable (); 54 55 private AccessManager accessManager; 56 57 private Map dirtyHandles = new Hashtable (); 58 59 protected QueryResultImpl(javax.jcr.query.QueryResult result, AccessManager accessManager) { 60 this.result = result; 61 this.accessManager = accessManager; 62 } 63 64 67 private void build(String nodeType, Collection collection) throws RepositoryException { 68 this.objectStore.put(nodeType, collection); 69 NodeIterator nodeIterator = this.result.getNodes(); 70 while (nodeIterator.hasNext()) { 71 Node node = nodeIterator.nextNode(); 72 try { 73 build(node, nodeType, collection); 74 } 75 catch (RepositoryException re) { 76 log.error(re.getMessage()); 77 log.debug(re); 78 } 79 } 80 } 81 82 85 private void build(Node node, String nodeType, Collection collection) throws RepositoryException { 86 89 if (node.isNodeType(nodeType)) { 90 if (this.dirtyHandles.get(node.getPath()) == null) { 91 boolean isAllowed = this.accessManager.isGranted(Path.getAbsolutePath(node.getPath()), Permission.READ); 92 if (isAllowed) { 93 collection.add(new Content(node, this.accessManager)); 94 this.dirtyHandles.put(node.getPath(), StringUtils.EMPTY); 95 } 96 } 97 return; 98 } 99 if (node.getDepth() > 0) { 100 this.build(node.getParent(), nodeType, collection); 101 } 102 } 103 104 107 public Collection getContent() { 108 return getContent(ItemType.CONTENT.getSystemName()); 109 } 110 111 114 public Collection getContent(String nodeType) { 115 Collection resultSet = (Collection ) this.objectStore.get(nodeType); 116 if (resultSet == null) { 117 118 resultSet = new ArrayList (); 119 try { 120 this.build(nodeType, resultSet); 121 } 122 catch (RepositoryException re) { 123 log.error(re.getMessage()); 124 } 125 } 126 return resultSet; 127 } 128 129 } 130 | Popular Tags |