1 17 package org.alfresco.jcr.item; 18 19 import java.util.List ; 20 21 import javax.jcr.PathNotFoundException; 22 23 import org.alfresco.jcr.session.SessionImpl; 24 import org.alfresco.service.cmr.repository.NodeRef; 25 import org.alfresco.service.cmr.search.SearchService; 26 27 28 34 public class ItemResolver 35 { 36 37 46 public static ItemImpl findItem(SessionImpl context, NodeRef from, String path) 47 throws PathNotFoundException 48 { 49 ItemImpl item = null; 50 51 NodeRef nodeRef = getNodeRef(context, from, path); 52 if (nodeRef != null) 53 { 54 item = new NodeImpl(context, nodeRef); 55 } 56 else 57 { 58 } 60 61 if (item == null) 62 { 63 throw new PathNotFoundException("Path " + path + " not found."); 64 } 65 66 return item; 67 } 68 69 78 public static NodeImpl findNode(SessionImpl context, NodeRef from, String path) 79 throws PathNotFoundException 80 { 81 NodeRef nodeRef = getNodeRef(context, from, path); 82 if (nodeRef == null) 83 { 84 throw new PathNotFoundException("A node does not exist at path " + path + " relative to node " + from); 85 } 86 return new NodeImpl(context, nodeRef); 87 } 88 89 97 public static boolean itemExists(SessionImpl context, NodeRef from, String path) 98 { 99 boolean exists = nodeExists(context, from, path); 100 if (!exists) 101 { 102 } 104 return exists; 105 } 106 107 115 public static boolean nodeExists(SessionImpl context, NodeRef from, String path) 116 { 117 NodeRef nodeRef = getNodeRef(context, from, path); 118 return nodeRef != null; 119 } 120 121 129 public static NodeRef getNodeRef(SessionImpl context, NodeRef from, String path) 130 { 131 NodeRef nodeRef = null; 132 133 SearchService search = context.getRepositoryImpl().getServiceRegistry().getSearchService(); 136 List <NodeRef> nodeRefs = search.selectNodes(from, path, null, context.getNamespaceResolver(), false); 137 if (nodeRefs != null && nodeRefs.size() > 0) 138 { 139 nodeRef = nodeRefs.get(0); 140 } 141 142 return nodeRef; 143 } 144 145 } 146 | Popular Tags |