javax.jcr.Item Java Examples

The following examples show how to use javax.jcr.Item. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LinkOperation.java    From sling-samples with Apache License 2.0 6 votes vote down vote up
@Override
protected void doRun(SlingHttpServletRequest request,
        HtmlResponse response, List<Modification> changes)
        throws RepositoryException {

    Session session = request.getResourceResolver().adaptTo(Session.class);
    String resourcePath = request.getResource().getPath();
    if (session.itemExists(resourcePath)) {
        Node source = (Node) session.getItem(resourcePath);

        // create a symetric link
        RequestParameter linkParam = request.getRequestParameter("target");
        if (linkParam != null) {
            String linkPath = linkParam.getString();
            if (session.itemExists(linkPath)) {
                Item targetItem = session.getItem(linkPath);
                if (targetItem.isNode()) {
                    linkHelper.createSymetricLink(source,
                        (Node) targetItem, "link");
                }
            }
        }
    }

}
 
Example #2
Source File: NodeTypeItemFilter.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * Returns {@code true} if the item is a node and if the configured
 * node type is equal to the primary type of the node. if super types are
 * respected it also returns {@code true} if the items node type
 * extends from the configured node type (Node.isNodeType() check).
 */
public boolean matches(Item item) throws RepositoryException {
    if (item.isNode()) {
        if (respectSupertype) {
            try {
                return ((Node) item).isNodeType(nodeType);
            } catch (RepositoryException e) {
                // ignore
                return false;
            }
        } else {
            return ((Node) item).getPrimaryNodeType().getName().equals(nodeType);
        }
    }
    return false;
    
}
 
Example #3
Source File: NtFileItemFilter.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @return {@code true} if the item is a nt:file or nt:resource property
 */
public boolean matches(Item item, int depth) throws RepositoryException {
    if (item.isNode()) {
        // include nt:file node
        Node node = (Node) item;
        if (depth == 0) {
            return node.isNodeType(JcrConstants.NT_FILE);
        } else if (depth == 1) {
            // include jcr:content
            return item.getName().equals(JcrConstants.JCR_CONTENT);
        } else {
            return false;
        }
    } else {
        if (depth == 1) {
            return fileNames.contains(item.getName());
        } else if (depth == 2 && item.getParent().getName().equals(JcrConstants.JCR_CONTENT)) {
            return resNames.contains(item.getName());
        } else {
            return false;
        }
    }
}
 
Example #4
Source File: FileFolderNodeFilter.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * Returns {@code true} if the item is a node of type nt:hierarchyNode
 * that has or defines a 'jcr:content' child node.
 */
public boolean matches(Item item) throws RepositoryException {
    if (item.isNode()) {
        Node node = (Node) item;
        if (node.isNodeType(JcrConstants.NT_HIERARCHYNODE)) {
            if (node.hasNode(JcrConstants.JCR_CONTENT)) {
                return true;
            } else {
                for (NodeDefinition pd: node.getPrimaryNodeType().getChildNodeDefinitions()) {
                    if (pd.getName().equals(JcrConstants.JCR_CONTENT)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
Example #5
Source File: ItemFilterSet.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
/**
 * Evaluates the filters if this set does {@link #covers(String) cover} the
 * given item. otherwise {@code false} is returned.
 * The result of the evaluation is the polarity of the last matched item.
 * If no filter matches it returns {@code true}
 * if the first filter is an exclude filter or if no filter is defined;
 * {@code false} if the first filter is an include filter.
 *
 * @param item the item to check
 * @param path of the item or {@code null}
 * @param depth the depth to check
 * @return {@code true} if this set matches the item
 * @throws RepositoryException if an error occurs.
 */
public boolean contains(Item item, String path, int depth) throws RepositoryException {
    if (path == null) {
        path = item.getPath();
    }
    if (!covers(path)) {
        return false;
    }
    List<Entry<ItemFilter>> entries = getEntries();
    if (entries.isEmpty()) {
        return true;
    } else {
        boolean result = !entries.get(0).include;
        for (Entry<ItemFilter> entry: entries) {
            if (entry.filter.matches(item, depth)) {
                result = entry.include;
            }
        }
        return result;
    }
}
 
Example #6
Source File: ItemImpl.java    From jackalope with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public Item getAncestor(int depth) throws ItemNotFoundException, RepositoryException {
    int myDepth = getDepth();
    if (depth > myDepth) throw new ItemNotFoundException();
    return (depth < myDepth) ? ((NodeImpl)getParent()).getAncestor(depth) : null;
}
 
Example #7
Source File: JcrTemplate.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @see org.springframework.extensions.jcr.JcrOperations#getItem(java.lang.String)
 */
@Override
public Item getItem(final String absPath) {
    return execute(new JcrCallback<Item>() {
        /**
         * @see JcrCallback#doInJcr(javax.jcr.Session)
         */
        @Override
        public Item doInJcr(Session session) throws RepositoryException {
            return session.getItem(absPath);
        }
    }, true);
}
 
Example #8
Source File: ItemNameComparator2.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
public int compare(Item o1, Item o2) {
    try {
        return QNameComparator.INSTANCE.compare(getQName(o1.getName()), getQName(o2.getName()));
    } catch (RepositoryException e) {
        throw new IllegalStateException(e);
    }
}
 
Example #9
Source File: BaseFilter.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean matches(Item item, int depth) throws RepositoryException {
    if (item.isNode()) {
        PropertyIterator iter = ((Node) item).getProperties();
        while (iter.hasNext()) {
            String name = iter.nextProperty().getName();
            if (!validNames.contains(name)) {
                return false;
            }
        }
        return true;
    }
    return false;
}
 
Example #10
Source File: DeclaringTypeItemFilter.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * Matches if the declaring node type of the item is equal to the one
 * specified in this filter. If the item is a node and {@code propsOnly}
 * flag is {@code true} it returns {@code false}.
 */
public boolean matches(Item item) throws RepositoryException {
    if (item.isNode()) {
        return !propsOnly && ((Node) item).getDefinition().getDeclaringNodeType().getName().equals(nodeType);
    } else {
        return ((Property) item).getDefinition().getDeclaringNodeType().getName().equals(nodeType);
    }
}
 
Example #11
Source File: IsMandatoryFilter.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
public boolean matches(Item item) throws RepositoryException {
    if (item.isNode()) {
        return ((Node) item).getDefinition().isMandatory() == isMandatory;
    } else {
        return ((Property) item).getDefinition().isMandatory() == isMandatory;
    }
}
 
Example #12
Source File: NodeImpl.java    From jackalope with Apache License 2.0 5 votes vote down vote up
@Override
public PropertyIterator getProperties() throws RepositoryException {
    List<Property> children = new ArrayList<>();
    for (Item item : session.getChildren(this))
        if (!item.isNode())
            children.add((Property)item);
    return new PropertyIteratorImpl(children);
}
 
Example #13
Source File: NodeImpl.java    From jackalope with Apache License 2.0 5 votes vote down vote up
@Override
public NodeIterator getNodes() throws RepositoryException {
    List<Node> children = new ArrayList<>();
    for (Item item : session.getChildren(this))
        if (item.isNode())
            children.add((Node)item);
    return new NodeIteratorImpl(children);
}
 
Example #14
Source File: SessionImpl.java    From jackalope with Apache License 2.0 5 votes vote down vote up
List<Item> getChildren(Item parent) {
    List<Item> children = new ArrayList<>();
    for (ItemImpl item : itemStore.values())
        if (item.getParentImpl() == parent)
            children.add(item);
    return children;
}
 
Example #15
Source File: SessionImpl.java    From jackalope with Apache License 2.0 5 votes vote down vote up
Item removeItem(@Nonnull ItemImpl item) {
    changedItems.add(item.getParentImpl().getPath());
    for (ItemImpl descendant : getDescendants(item))
        itemStore.remove(descendant.getPath());
    itemStore.remove(item.getPath());
    return item;
}
 
Example #16
Source File: LinkProcessor.java    From sling-samples with Apache License 2.0 5 votes vote down vote up
public void process(SlingHttpServletRequest request,
		List<Modification> changes) throws Exception {

	Session session = request.getResourceResolver().adaptTo(Session.class);

	RequestParameter linkParam = request.getRequestParameter(":link");
	if (linkParam != null){
		String linkPath = linkParam.getString();
		// check if a new node have been created
		if (changes.size() > 0 && changes.get(0).getType() == ModificationType.CREATE) {
			// hack to get the resource path
			// is it possible to add the response to the method header ?
			String resourcePath = changes.get(0).getSource();
			Node source = (Node) session.getItem(resourcePath);

			// create a symetric link
			if (session.itemExists(linkPath)) {
				Item targetItem = session.getItem(linkPath);
				if (targetItem.isNode()) {
					linkHelper.createSymetricLink(source, (Node) targetItem, "link");
				}
			}
		}
	}


}
 
Example #17
Source File: JackrabbitSessionWrapper.java    From sling-whiteboard with Apache License 2.0 5 votes vote down vote up
@Override
public Item getItemOrNull(String absPath) throws RepositoryException {
    if (super.itemExists(absPath)) {
        return super.getItem(absPath);
    } else {
        return null;
    }
}
 
Example #18
Source File: SessionImpl.java    From jackalope with Apache License 2.0 4 votes vote down vote up
Item addItem(@Nonnull ItemImpl item) throws ItemNotFoundException, ItemExistsException {
    if (itemStore.containsKey(item.getPath())) throw new ItemExistsException();
    addedItems.add(item.getPath());
    return storeItem(item);
}
 
Example #19
Source File: RepositoryCFile.java    From jackrabbit-filevault with Apache License 2.0 4 votes vote down vote up
public RepositoryCFile(Item item) {
    this.item = item;
}
 
Example #20
Source File: NodeWrapper.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
@Override
public Item getPrimaryItem() throws ItemNotFoundException, RepositoryException {
    return sessionWrapper.getObjectWrapper().wrap(sessionWrapper, delegate.getPrimaryItem());
}
 
Example #21
Source File: ItemNameComparator.java    From jackrabbit-filevault with Apache License 2.0 4 votes vote down vote up
public int compare(Item o1, Item o2) {
    throw new UnsupportedOperationException("No longer supported, use ItemNameComparator2 instead");
}
 
Example #22
Source File: DefaultObjectWrapper.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
public Item wrap(SessionWrapper s, Item it) {
    return new ItemWrapper(s, it);
}
 
Example #23
Source File: ItemWrapper.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
@Override
public Item getAncestor(int depth) throws ItemNotFoundException, AccessDeniedException, RepositoryException {
    return this.sessionWrapper.getItem(this.delegate.getAncestor(depth).getPath());
}
 
Example #24
Source File: ItemWrapper.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isSame(Item otherItem) throws RepositoryException {
    return delegate.isSame(sessionWrapper.getObjectWrapper().unwrap(otherItem));
}
 
Example #25
Source File: SessionWrapper.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
@Override
public Item getItem(String absPath) throws PathNotFoundException, RepositoryException {
    return objectWrapper.wrap(this, wrappedSession.getItem(absPath));
}
 
Example #26
Source File: DocViewSAXImporter.java    From jackrabbit-filevault with Apache License 2.0 4 votes vote down vote up
private boolean isIncluded(Item item, int depth) throws RepositoryException {
    String path = importInfo.getRemapped().map(item.getPath());
    return wspFilter.contains(path) && (depth == 0 || filter.contains(item, path, depth));
}
 
Example #27
Source File: SessionWrapper.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
public void refresh(String path, Item item, boolean keepChanges) throws RepositoryException {
    item.refresh(keepChanges);
}
 
Example #28
Source File: ItemFilter.java    From jackrabbit-filevault with Apache License 2.0 4 votes vote down vote up
/**
 * Returns always {@code false}
 */
public boolean matches(Item item, int depth) throws RepositoryException {
    return false;
}
 
Example #29
Source File: ItemFilter.java    From jackrabbit-filevault with Apache License 2.0 4 votes vote down vote up
/**
 * Returns always {@code true}
 */
public boolean matches(Item item, int depth) throws RepositoryException {
    return true;
}
 
Example #30
Source File: ItemImpl.java    From jackalope with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isSame(Item otherItem) throws RepositoryException {
    return Objects.equals(path, otherItem.getPath())
        && (isNode() == otherItem.isNode())
        && (isNode() || getParent().isSame(otherItem.getParent()));
}