/** * Creates a new <code>LazyItemIterator</code> instance. * * @param itemMgr * @param hierarchyMgr * @param itemIds */ public LazyItemIterator(ItemManager itemMgr, HierarchyManager hierarchyMgr, Iterator<? extends ItemId> itemIds) throws ItemNotFoundException, RepositoryException { this.itemMgr = itemMgr; List<HierarchyEntry> entries = new ArrayList<HierarchyEntry>(); while (itemIds.hasNext()) { ItemId id = itemIds.next(); HierarchyEntry entry; if (id.denotesNode()) { entry = hierarchyMgr.getNodeEntry((NodeId) id); } else { entry = hierarchyMgr.getPropertyEntry((PropertyId) id); } entries.add(entry); } iter = entries.iterator(); size = entries.size(); pos = 0; // fetch first item next = prefetchNext(); }
/** * Creates a new <code>LazyItemIterator</code> instance. * * @param itemMgr * @param hierarchyMgr * @param itemIds */ public LazyItemIterator(ItemManager itemMgr, HierarchyManager hierarchyMgr, Iterator<? extends ItemId> itemIds) throws ItemNotFoundException, RepositoryException { this.itemMgr = itemMgr; List<HierarchyEntry> entries = new ArrayList<HierarchyEntry>(); while (itemIds.hasNext()) { ItemId id = itemIds.next(); HierarchyEntry entry; if (id.denotesNode()) { entry = hierarchyMgr.getNodeEntry((NodeId) id); } else { entry = hierarchyMgr.getPropertyEntry((PropertyId) id); } entries.add(entry); } iter = entries.iterator(); size = entries.size(); pos = 0; // fetch first item next = prefetchNext(); }
@Override public Iterator<? extends ItemInfo> getItemInfos(SessionInfo sessionInfo, ItemId itemId) throws RepositoryException { // TODO: implement batch read properly: // currently: missing 'value/values' property PropertyInfo cannot be built // currently: missing prop-names with child-NodeInfo if (itemId.denotesNode()) { List<ItemInfo> l = new ArrayList<ItemInfo>(); NodeInfo nInfo = getNodeInfo(sessionInfo, (NodeId) itemId); l.add(nInfo); // at least add propertyInfos for the meta-props already known from the // nodeInfo. l.addAll(buildPropertyInfos(nInfo)); return l.iterator(); } else { PropertyInfo pInfo = getPropertyInfo(sessionInfo, (PropertyId) itemId); return Iterators.singleton(pInfo); } }
@Override public Iterator<? extends ItemInfo> getItemInfos(SessionInfo sessionInfo, ItemId itemId) throws RepositoryException { // TODO: implement batch read properly: // currently: missing 'value/values' property PropertyInfo cannot be built // currently: missing prop-names with child-NodeInfo if (itemId.denotesNode()) { List<ItemInfo> l = new ArrayList<ItemInfo>(); NodeInfo nInfo = getNodeInfo(sessionInfo, (NodeId) itemId); l.add(nInfo); // at least add propertyInfos for the meta-props already known from the // nodeInfo. l.addAll(buildPropertyInfos(nInfo)); return l.iterator(); } else { PropertyInfo pInfo = getPropertyInfo(sessionInfo, (PropertyId) itemId); return Iterators.singleton(pInfo); } }
/** * @see javax.jcr.observation.Event#getIdentifier() */ public String getIdentifier() throws RepositoryException { ItemId itemId = event.getItemId(); if (itemId == null) { return null; } else { NodeId nodeId = (itemId.denotesNode()) ? (NodeId) itemId : ((PropertyId) itemId).getParentId(); return idFactory.toJcrIdentifier(nodeId); } }
/** * @see javax.jcr.observation.Event#getIdentifier() */ public String getIdentifier() throws RepositoryException { ItemId itemId = event.getItemId(); if (itemId == null) { return null; } else { NodeId nodeId = (itemId.denotesNode()) ? (NodeId) itemId : ((PropertyId) itemId).getParentId(); return idFactory.toJcrIdentifier(nodeId); } }
public Object run() throws RepositoryException { try { if (itemId.denotesNode()) { NodeId nodeId = calcRemoveNodeId(itemId); getNode(nodeId, sInfo).remove(); } else { getProperty((PropertyId) itemId, sInfo).remove(); } } catch (ItemNotFoundException e) { // item was present in jcr2spi but got removed on the // persistent layer in the mean time. throw new InvalidItemStateException(e); } catch (PathNotFoundException e) { // item was present in jcr2spi but got removed on the // persistent layer in the mean time. throw new InvalidItemStateException(e); } return null; } });
public Object run() throws RepositoryException { try { if (itemId.denotesNode()) { NodeId nodeId = calcRemoveNodeId(itemId); getNode(nodeId, sInfo).remove(); } else { getProperty((PropertyId) itemId, sInfo).remove(); } } catch (ItemNotFoundException e) { // item was present in jcr2spi but got removed on the // persistent layer in the mean time. throw new InvalidItemStateException(e); } catch (PathNotFoundException e) { // item was present in jcr2spi but got removed on the // persistent layer in the mean time. throw new InvalidItemStateException(e); } return null; } });
private Path getPath(ItemId itemId, SessionInfo sessionInfo, String workspaceName) throws RepositoryException { if (itemId.denotesNode()) { Path p = itemId.getPath(); String uid = itemId.getUniqueID(); if (uid == null) { return p; } else { NamePathResolver resolver = getNamePathResolver(sessionInfo); String uri = super.getItemUri(itemId, sessionInfo, workspaceName); String rootUri = getRootURI(sessionInfo); String jcrPath; if (uri.startsWith(rootUri)) { jcrPath = uri.substring(rootUri.length()); } else { log.warn("ItemURI " + uri + " doesn't start with rootURI (" + rootUri + ")."); // fallback: // calculated uri does not start with the rootURI // -> search /jcr:root and start sub-string behind. String rootSegment = Text.escapePath(JcrRemotingConstants.ROOT_ITEM_RESOURCEPATH); jcrPath = uri.substring(uri.indexOf(rootSegment) + rootSegment.length()); } jcrPath = Text.unescape(jcrPath); return resolver.getQPath(jcrPath); } } else { PropertyId pId = (PropertyId) itemId; Path parentPath = getPath(pId.getParentId(), sessionInfo, workspaceName); return getPathFactory().create(parentPath, pId.getName(), true); } }
private Path getPath(ItemId itemId, SessionInfo sessionInfo, String workspaceName) throws RepositoryException { if (itemId.denotesNode()) { Path p = itemId.getPath(); String uid = itemId.getUniqueID(); if (uid == null) { return p; } else { NamePathResolver resolver = getNamePathResolver(sessionInfo); String uri = super.getItemUri(itemId, sessionInfo, workspaceName); String rootUri = getRootURI(sessionInfo); String jcrPath; if (uri.startsWith(rootUri)) { jcrPath = uri.substring(rootUri.length()); } else { log.warn("ItemURI " + uri + " doesn't start with rootURI (" + rootUri + ")."); // fallback: // calculated uri does not start with the rootURI // -> search /jcr:root and start sub-string behind. String rootSegment = Text.escapePath(JcrRemotingConstants.ROOT_ITEM_RESOURCEPATH); jcrPath = uri.substring(uri.indexOf(rootSegment) + rootSegment.length()); } jcrPath = Text.unescape(jcrPath); return resolver.getQPath(jcrPath); } } else { PropertyId pId = (PropertyId) itemId; Path parentPath = getPath(pId.getParentId(), sessionInfo, workspaceName); return getPathFactory().create(parentPath, pId.getName(), true); } }
@Override public void remove(ItemId itemId) throws RepositoryException { assertMethod(); Path rmPath = getPath(itemId, sessionInfo); if (itemId.denotesNode()) { rmPath = calcRemovePath(rmPath); } String rmJcrPath = getNamePathResolver(sessionInfo).getJCRPath(rmPath); appendDiff(SYMBOL_REMOVE, rmJcrPath, null); // clear the uri-lookup in case the itemID contains a uniqueID part. if (itemId.getPath() == null) { clear = true; } }
@Override public void remove(ItemId itemId) throws RepositoryException { assertMethod(); Path rmPath = getPath(itemId, sessionInfo); if (itemId.denotesNode()) { rmPath = calcRemovePath(rmPath); } String rmJcrPath = getNamePathResolver(sessionInfo).getJCRPath(rmPath); appendDiff(SYMBOL_REMOVE, rmJcrPath, null); // clear the uri-lookup in case the itemID contains a uniqueID part. if (itemId.getPath() == null) { clear = true; } }
/** * Searches the child-entries of this NodeEntry for a matching child. * Since {@link #refresh(Event)} must always be called on the parent * NodeEntry, there is no need to check if a given event id would point * to this NodeEntry itself. * * @param eventId * @param eventPath * @return the entry or <code>null</code> if the matching entry has a status * <code>Status#NEW</code>. */ private HierarchyEntry lookupEntry(ItemId eventId, Path eventPath) { Name childName = eventPath.getName(); HierarchyEntry child; if (eventId.denotesNode()) { String uniqueChildID = (eventId.getPath() == null) ? eventId.getUniqueID() : null; int index = eventPath.getNormalizedIndex(); child = lookupNodeEntry(uniqueChildID, childName, index); } else { child = lookupPropertyEntry(childName); } return child; }
/** * Searches the child-entries of this NodeEntry for a matching child. * Since {@link #refresh(Event)} must always be called on the parent * NodeEntry, there is no need to check if a given event id would point * to this NodeEntry itself. * * @param eventId * @param eventPath * @return the entry or <code>null</code> if the matching entry has a status * <code>Status#NEW</code>. */ private HierarchyEntry lookupEntry(ItemId eventId, Path eventPath) { Name childName = eventPath.getName(); HierarchyEntry child; if (eventId.denotesNode()) { String uniqueChildID = (eventId.getPath() == null) ? eventId.getUniqueID() : null; int index = eventPath.getNormalizedIndex(); child = lookupNodeEntry(uniqueChildID, childName, index); } else { child = lookupPropertyEntry(childName); } return child; }
if (!itemId.denotesNode()) { PropertyInfo propertyInfo = getPropertyInfo(sessionInfo, (PropertyId) itemId); return Iterators.singleton(propertyInfo);
PropertyId buildPropertyId(NodeId parentId, MultiStatusResponse response, String workspaceName, NamePathResolver resolver) throws RepositoryException { IdURICache cache = getCache(workspaceName); if (cache.containsUri(response.getHref())) { ItemId id = cache.getItemId(response.getHref()); if (!id.denotesNode()) { return (PropertyId) id; } } try { DavPropertySet propSet = response.getProperties(DavServletResponse.SC_OK); Name name = resolver.getQName(propSet.get(JcrRemotingConstants.JCR_NAME_LN, ItemResourceConstants.NAMESPACE).getValue().toString()); PropertyId propertyId = service.getIdFactory().createPropertyId(parentId, name); cache.add(response.getHref(), propertyId); return propertyId; } catch (NameException e) { throw new RepositoryException(e); } }
PropertyId buildPropertyId(NodeId parentId, MultiStatusResponse response, String workspaceName, NamePathResolver resolver) throws RepositoryException { IdURICache cache = getCache(workspaceName); if (cache.containsUri(response.getHref())) { ItemId id = cache.getItemId(response.getHref()); if (!id.denotesNode()) { return (PropertyId) id; } } try { DavPropertySet propSet = response.getProperties(DavServletResponse.SC_OK); Name name = resolver.getQName(propSet.get(JcrRemotingConstants.JCR_NAME_LN, ItemResourceConstants.NAMESPACE).getValue().toString()); PropertyId propertyId = service.getIdFactory().createPropertyId(parentId, name); cache.add(response.getHref(), propertyId); return propertyId; } catch (NameException e) { throw new RepositoryException(e); } }
if (id.denotesNode()) { return (NodeId) id;
/** * @inheritDoc */ public PropertyId getPropertyId(String uri, SessionInfo sessionInfo) throws RepositoryException { IdURICache cache = getCache(sessionInfo.getWorkspaceName()); ItemId id = cache.getItemId(uri); if (id != null) { if (!id.denotesNode()) { return (PropertyId) id; } } // separate parent uri and property JCRName String parentUri = Text.getRelativeParent(uri, 1, true); // make sure propName is unescaped String propName = Text.unescape(Text.getName(uri, true)); // retrieve parent node id NodeId parentId = getNodeId(parentUri, sessionInfo, false); // build property id try { Name name = service.getNamePathResolver(sessionInfo).getQName(propName); PropertyId propertyId = service.getIdFactory().createPropertyId(parentId, name); cache.add(uri, propertyId); return propertyId; } catch (NameException e) { throw new RepositoryException(e); } } }
/** * @inheritDoc */ public PropertyId getPropertyId(String uri, SessionInfo sessionInfo) throws RepositoryException { IdURICache cache = getCache(sessionInfo.getWorkspaceName()); ItemId id = cache.getItemId(uri); if (id != null) { if (!id.denotesNode()) { return (PropertyId) id; } } // separate parent uri and property JCRName String parentUri = Text.getRelativeParent(uri, 1, true); // make sure propName is unescaped String propName = Text.unescape(Text.getName(uri, true)); // retrieve parent node id NodeId parentId = getNodeId(parentUri, sessionInfo, false); // build property id try { Name name = service.getNamePathResolver(sessionInfo).getQName(propName); PropertyId propertyId = service.getIdFactory().createPropertyId(parentId, name); cache.add(uri, propertyId); return propertyId; } catch (NameException e) { throw new RepositoryException(e); } } }