Search in sources :

Example 26 with PathNotFoundException

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

the class TraversingNodeResolver method findNodes.

/**
     * @inheritDoc
     */
@Override
public NodeIterator findNodes(Path relPath, String value, int authorizableType, boolean exact, long maxSize) throws RepositoryException {
    String sr = getSearchRoot(authorizableType);
    if (getSession().nodeExists(sr)) {
        try {
            String path = getNamePathResolver().getJCRPath(relPath);
            AuthorizableTypePredicate pred = getAuthorizableTypePredicate(authorizableType, relPath.getLength() > 1);
            Node root = getSession().getNode(sr);
            Map<String, Node> matchingNodes = new HashMap<String, Node>();
            collectNodes(value, path, pred, root.getNodes(), matchingNodes, exact, maxSize);
            return new NodeIteratorAdapter(matchingNodes.values());
        } catch (PathNotFoundException e) {
            // should not get here
            log.warn("Error while retrieving node " + sr);
        }
    }
    // else: searchRoot does not exist yet -> omit the search
    return NodeIteratorAdapter.EMPTY;
}
Also used : HashMap(java.util.HashMap) Node(javax.jcr.Node) NodeIteratorAdapter(org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 27 with PathNotFoundException

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

the class DocumentViewExporter method exportNode.

/**
     * Exports the given node either as XML characters (if it's an
     * <code>xml:text</code> node) or as an XML element with properties
     * mapped to XML attributes.
     */
protected void exportNode(String uri, String local, Node node) throws RepositoryException, SAXException {
    if (NamespaceHelper.JCR.equals(uri) && "xmltext".equals(local)) {
        try {
            // assume jcr:xmlcharacters is single-valued
            Property property = node.getProperty(helper.getJcrName("jcr:xmlcharacters"));
            char[] ch = property.getString().toCharArray();
            characters(ch, 0, ch.length);
        } catch (PathNotFoundException e) {
        // jcr:xmlcharacters not found, ignore this node
        }
    } else {
        // attributes (properties)
        exportProperties(node);
        // encode node name to make sure it's a valid xml name
        String encoded = ISO9075.encode(local);
        startElement(uri, encoded);
        exportNodes(node);
        endElement(uri, encoded);
    }
}
Also used : PathNotFoundException(javax.jcr.PathNotFoundException) Property(javax.jcr.Property)

Example 28 with PathNotFoundException

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

the class SysViewContentHandler method startElement.

public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    try {
        if (qName.equals(svNode)) {
            //attribute sv:name
            String nodeName = attributes.getValue(svName);
            if (noRecurse) {
                if (!testRootDone) {
                    nodeElemStack.push(currentNodeElem);
                    testRootDone = true;
                    // correct root name?
                    if (currentNodeElem.node.getDepth() == 0) {
                        checkCondition("Exported Root node has not the required " + "element name 'jcr:root'.", nodeName.equals(jcrRoot));
                    }
                // nothing else to do here
                } else // rootNode yet done
                {
                    // only the testRootNode should be exported.
                    checkCondition("Child Node Element of testRoot Node " + "element found although noRecursive is true.", !testRootDone);
                }
            } else {
                if (!testRootDone) {
                    nodeElemStack.push(currentNodeElem);
                    testRootDone = true;
                    // correct root name?
                    if (currentNodeElem.node.getDepth() == 0) {
                        checkCondition("Exported Root node has not the required " + "element name 'jcr:root'.", nodeName.equals(jcrRoot));
                    }
                // nothing else to do here
                } else // Collect the exported data in a NodeElemData object.
                // every occurrence of an opened sv:node element
                // creates such an object which will be put on the nodeElemStack.
                // As this element will be popped from the stack when the node element
                // is closed, the latest element on the stack represents the parent
                // node element of the current node element.
                {
                    parentNodeElem = (NodeElemData) nodeElemStack.pop();
                    // get the node(s) with the found nodeName
                    NodeIterator nodeIter = parentNodeElem.node.getNodes(nodeName);
                    // create a new nodeElemData for this new node elem in process
                    currentNodeElem = new NodeElemData();
                    currentNodeElem.name = nodeName;
                    long size = getSize(nodeIter);
                    if (size >= 1) {
                        // position the node elem is found in the exported tree.
                        if (parentNodeElem.childNodeElemNames.containsKey(nodeName)) {
                            ChildNodeElem child = (ChildNodeElem) parentNodeElem.childNodeElemNames.get(nodeName);
                            child.number++;
                            currentNodeElem.index = child.number;
                            // get the node
                            String relPath = currentNodeElem.name + "[" + child.number + "]";
                            currentNodeElem.node = parentNodeElem.node.getNode(relPath);
                            currentNodeElem.path = currentNodeElem.node.getPath();
                            parentNodeElem.childNodeElemNames.put(nodeName, child);
                        } else {
                            ChildNodeElem child = new ChildNodeElem();
                            child.name = nodeName;
                            child.number = 1;
                            currentNodeElem.index = child.number;
                            // get the node
                            String relPath = currentNodeElem.name + "[" + child.number + "]";
                            currentNodeElem.node = parentNodeElem.node.getNode(relPath);
                            currentNodeElem.path = currentNodeElem.node.getPath();
                            parentNodeElem.childNodeElemNames.put(nodeName, child);
                        }
                    } else {
                        // no node found, this is an error.
                        checkCondition("No child node of node " + parentNodeElem.path + " found with name:  " + nodeName, false);
                    }
                    // push the parent data and the current node element data on the stack
                    nodeElemStack.push(parentNodeElem);
                    nodeElemStack.push(currentNodeElem);
                }
            }
        } else // Collect the value(s) found in an ArrayList.
        if (qName.equals(svProperty)) {
            currentPropElem = new PropElemData();
            currentPropElem.name = attributes.getValue(svName);
            currentPropElem.typeName = attributes.getValue(svType);
            currentPropElem.type = PropertyType.valueFromName(currentPropElem.typeName);
            currentPropElem.values = new ArrayList<String>();
        } else if (qName.equals(svValue)) {
            // init
            currentValue = new StringBuffer();
        } else {
            // invalid element name is used
            checkCondition("Invalid element name " + qName + " in SysView export found", false);
        }
    } catch (PathNotFoundException pne) {
        checkCondition("Item not found during exportSysViewTest: " + pne.toString(), false);
    } catch (RepositoryException re) {
    // what here?
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 29 with PathNotFoundException

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

the class SetValueStringTest method testRemoveValueParent.

/**
     * Test the deletion of a property by assigning it a null value, saved from
     * the parent Node
     */
public void testRemoveValueParent() throws RepositoryException {
    Value sv = null;
    property1.setValue(sv);
    node.save();
    try {
        node.getProperty(propertyName1);
        fail("The property should not exist anymore, as a null Value has been assigned");
    } catch (PathNotFoundException e) {
    //success : the property has been deleted by assigning it a null value
    }
}
Also used : Value(javax.jcr.Value) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 30 with PathNotFoundException

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

the class GetPropertyTest method testGetPropertyOfRemovedAncestor.

public void testGetPropertyOfRemovedAncestor() throws RepositoryException {
    Session rw = getHelper().getReadWriteSession();
    try {
        // add modification to a property.
        Property p = (Property) rw.getItem(prop1Path);
        p.setValue("changedValue");
        // transiently remove the test root node
        rw.getItem(testRootNode.getPath()).remove();
        try {
            p.getValue();
            fail("modified property must be marked removed upon parent removal");
        } catch (InvalidItemStateException e) {
        // success
        }
        try {
            rw.getItem(prop1Path);
            fail("modified property must be marked removed upon parent removal");
        } catch (PathNotFoundException e) {
        // success
        }
        try {
            Property p2 = (Property) rw.getItem(prop2Path);
            fail("existing property must be marked removed upon parent removal");
        } catch (PathNotFoundException e) {
        // success
        }
        // revert all transient modifications
        rw.refresh(false);
        Property pAgain = (Property) rw.getItem(prop1Path);
        // TODO: for generic jsr 170 test: change assert to p.isSame(pAgain)
        assertTrue(p.isSame(pAgain));
        assertEquals("string1", p.getString());
    } finally {
        rw.logout();
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) PathNotFoundException(javax.jcr.PathNotFoundException) Property(javax.jcr.Property) Session(javax.jcr.Session)

Aggregations

PathNotFoundException (javax.jcr.PathNotFoundException)136 Node (javax.jcr.Node)58 RepositoryException (javax.jcr.RepositoryException)46 ItemNotFoundException (javax.jcr.ItemNotFoundException)24 Session (javax.jcr.Session)23 Path (org.apache.jackrabbit.spi.Path)22 AccessDeniedException (javax.jcr.AccessDeniedException)14 Property (javax.jcr.Property)14 Test (org.junit.Test)14 Item (javax.jcr.Item)11 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)10 NodeIterator (javax.jcr.NodeIterator)9 Value (javax.jcr.Value)9 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)9 Name (org.apache.jackrabbit.spi.Name)8 PropertyIterator (javax.jcr.PropertyIterator)7 NodeDelegate (org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate)7 HashSet (java.util.HashSet)6 ItemExistsException (javax.jcr.ItemExistsException)6 ValueFormatException (javax.jcr.ValueFormatException)6