Search in sources :

Example 96 with Item

use of javax.jcr.Item in project jackrabbit by apache.

the class ReorderSNSTest method testReorder3.

public void testReorder3() throws RepositoryException {
    String pathBefore = child3.getPath();
    testRootNode.orderBefore(getRelPath(child3), getRelPath(child1));
    testRootNode.save();
    Item itemIndex3 = testRootNode.getSession().getItem(pathBefore);
    assertTrue(itemIndex3.isSame(child2));
    Item item3 = testRootNode.getSession().getItem(child3.getPath());
    assertTrue(item3.isSame(child3));
}
Also used : Item(javax.jcr.Item)

Example 97 with Item

use of javax.jcr.Item in project jackrabbit by apache.

the class Save method execute.

/**
     * {@inheritDoc}
     */
public boolean execute(Context ctx) throws Exception {
    String path = (String) ctx.get(this.pathKey);
    if (path == null) {
        log.debug("saving session");
        CommandHelper.getSession(ctx).save();
    } else {
        log.debug("saving node at " + path);
        Item i = CommandHelper.getItem(ctx, path);
        i.save();
    }
    return false;
}
Also used : Item(javax.jcr.Item)

Example 98 with Item

use of javax.jcr.Item in project jackrabbit by apache.

the class Move method execute.

/**
     * {@inheritDoc}
     */
public boolean execute(Context ctx) throws Exception {
    String srcAbsPath = (String) ctx.get(this.srcAbsPathKey);
    String destAbsPath = (String) ctx.get(this.destAbsPathKey);
    boolean persistent = Boolean.valueOf((String) ctx.get(this.persistentKey)).booleanValue();
    if (!srcAbsPath.startsWith("/") || !destAbsPath.startsWith("/")) {
        throw new IllegalArgumentException(bundle.getString("exception.illegalargument") + ". " + bundle.getString("exception.only.absolute.path") + ".");
    }
    Session s = CommandHelper.getSession(ctx);
    if (log.isDebugEnabled()) {
        log.debug("moving node from " + srcAbsPath + " to " + destAbsPath);
    }
    if (destAbsPath.endsWith("/")) {
        Item source = s.getItem(srcAbsPath);
        destAbsPath = destAbsPath + source.getName();
    }
    if (persistent) {
        s.getWorkspace().move(srcAbsPath, destAbsPath);
    } else {
        s.move(srcAbsPath, destAbsPath);
    }
    return false;
}
Also used : Item(javax.jcr.Item) Session(javax.jcr.Session)

Example 99 with Item

use of javax.jcr.Item in project jackrabbit by apache.

the class RemoveItems method execute.

/**
     * {@inheritDoc}
     */
public boolean execute(Context ctx) throws Exception {
    String pattern = (String) ctx.get(this.patternKey);
    String path = (String) ctx.get(this.pathKey);
    Node n = CommandHelper.getNode(ctx, path);
    if (log.isDebugEnabled()) {
        log.debug("removing nodes from " + n.getPath() + " that match pattern " + pattern);
    }
    List children = new ArrayList();
    ChildrenCollectorFilter collector = new ChildrenCollectorFilter(pattern, children, true, true, 1);
    collector.visit(n);
    Iterator items = children.iterator();
    while (items.hasNext()) {
        Item item = (Item) items.next();
        if (item.isSame(CommandHelper.getCurrentNode(ctx)) && item.getDepth() > 0) {
            CommandHelper.setCurrentNode(ctx, item.getParent());
        }
        item.remove();
    }
    return false;
}
Also used : Item(javax.jcr.Item) ChildrenCollectorFilter(org.apache.jackrabbit.util.ChildrenCollectorFilter) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList)

Example 100 with Item

use of javax.jcr.Item in project jackrabbit by apache.

the class Copy method execute.

/**
     * {@inheritDoc}
     */
public boolean execute(Context ctx) throws Exception {
    String srcWorkspace = (String) ctx.get(this.srcWorkspaceKey);
    String srcAbsPath = (String) ctx.get(this.srcAbsPathKey);
    String destAbsPath = (String) ctx.get(this.destAbsPathKey);
    Workspace w = CommandHelper.getSession(ctx).getWorkspace();
    if (srcWorkspace == null) {
        srcWorkspace = w.getName();
    }
    if (log.isDebugEnabled()) {
        log.debug("copying node from [" + srcWorkspace + ":" + srcAbsPath + "] to [" + w.getName() + ":" + destAbsPath + "]");
    }
    if (destAbsPath.endsWith("/")) {
        Item source = CommandHelper.getSession(ctx).getItem(srcAbsPath);
        destAbsPath = destAbsPath + source.getName();
    }
    w.copy(srcWorkspace, srcAbsPath, destAbsPath);
    return false;
}
Also used : Item(javax.jcr.Item) Workspace(javax.jcr.Workspace)

Aggregations

Item (javax.jcr.Item)117 Node (javax.jcr.Node)48 RepositoryException (javax.jcr.RepositoryException)28 Property (javax.jcr.Property)19 Session (javax.jcr.Session)15 PathNotFoundException (javax.jcr.PathNotFoundException)11 ArrayList (java.util.ArrayList)7 ItemNotFoundException (javax.jcr.ItemNotFoundException)6 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)6 IOException (java.io.IOException)5 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)5 HashSet (java.util.HashSet)4 NodeIterator (javax.jcr.NodeIterator)4 Principal (java.security.Principal)3 NoSuchElementException (java.util.NoSuchElementException)3 AccessDeniedException (javax.jcr.AccessDeniedException)3 PropertyIterator (javax.jcr.PropertyIterator)3 Version (javax.jcr.version.Version)3 ResourceNotFoundException (org.apache.sling.api.resource.ResourceNotFoundException)3 OutputStreamWriter (java.io.OutputStreamWriter)2