use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class JcrRemotingServlet method doGet.
@Override
protected void doGet(WebdavRequest webdavRequest, WebdavResponse webdavResponse, DavResource davResource) throws IOException, DavException {
if (canHandle(DavMethods.DAV_GET, webdavRequest, davResource)) {
// return json representation of the requested resource
DavResourceLocator locator = davResource.getLocator();
String path = locator.getRepositoryPath();
Session session = getRepositorySession(webdavRequest);
try {
Node node = session.getNode(path);
int depth = ((WrappingLocator) locator).getDepth();
webdavResponse.setContentType("text/plain;charset=utf-8");
webdavResponse.setStatus(DavServletResponse.SC_OK);
JsonWriter writer = new JsonWriter(webdavResponse.getWriter());
String[] includes = webdavRequest.getParameterValues(PARAM_INCLUDE);
if (includes == null) {
if (depth < BatchReadConfig.DEPTH_INFINITE) {
NodeType type = node.getPrimaryNodeType();
depth = brConfig.getDepth(type.getName());
}
writer.write(node, depth);
} else {
writeMultiple(writer, node, includes, depth);
}
} catch (PathNotFoundException e) {
// properties cannot be requested as json object.
throw new JcrDavException(new ItemNotFoundException("No node at " + path), DavServletResponse.SC_NOT_FOUND);
} catch (RepositoryException e) {
// should only get here if the item does not exist.
log.debug(e.getMessage());
throw new JcrDavException(e);
}
} else {
super.doGet(webdavRequest, webdavResponse, davResource);
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class AbstractItemResource method move.
/**
* Moves the underlying repository item to the indicated destination.
*
* @param destination
* @throws DavException
* @see DavResource#move(DavResource)
* @see javax.jcr.Session#move(String, String)
*/
@Override
public void move(DavResource destination) throws DavException {
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
DavResourceLocator destLocator = destination.getLocator();
if (!getLocator().isSameWorkspace(destLocator)) {
throw new DavException(DavServletResponse.SC_FORBIDDEN);
}
try {
String itemPath = getLocator().getRepositoryPath();
String destItemPath = destination.getLocator().getRepositoryPath();
if (getTransactionId() == null) {
// if not part of a transaction directly import on workspace
getRepositorySession().getWorkspace().move(itemPath, destItemPath);
} else {
// changes will not be persisted unless the tx is completed.
getRepositorySession().move(itemPath, destItemPath);
}
// no use in calling 'complete' that would fail for a moved item anyway.
} catch (PathNotFoundException e) {
// according to rfc 2518
throw new DavException(DavServletResponse.SC_CONFLICT, e.getMessage());
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class TreeComparator method init.
/**
* Makes sure that the source and target folder exist, and are empty
*/
private void init() throws RepositoryException {
root = sc.testroot;
sourceFolder = root + "/" + sc.sourceFolderName;
targetFolder = root + "/" + sc.targetFolderName;
// make sure the node does not have a and target sub node.
try {
session.getItem(sourceFolder).remove();
session.save();
} catch (PathNotFoundException e) {
// item does not exist
}
try {
Item tgt = session.getItem(targetFolder);
tgt.remove();
session.save();
} catch (PathNotFoundException e) {
// item does not exist
}
// add the source and target nodes
Node rootNode = (Node) session.getItem(root);
rootNode.addNode(sc.sourceFolderName);
rootNode.addNode(sc.targetFolderName);
session.save();
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class ValueFactoryTest method createReferenceableNode.
/**
* Create a referenceable node under the testRootNode
* or null if it is not possible to create one.
* @param name
* @return
* @throws RepositoryException
*/
public Node createReferenceableNode(String name) throws RepositoryException {
// remove a yet existing node at the target
try {
Node node = testRootNode.getNode(name);
node.remove();
session.save();
} catch (PathNotFoundException pnfe) {
// ok
}
// a referenceable node
Node n1 = testRootNode.addNode(name, testNodeType);
if (n1.canAddMixin(mixReferenceable)) {
n1.addMixin(mixReferenceable);
// make sure jcr:uuid is available
testRootNode.getSession().save();
return n1;
} else {
return null;
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class MoveSNSTest method testAccessMovedNodeByOldPath.
/**
* Test if a moved node is 'replaced' by its SNS.
*/
public void testAccessMovedNodeByOldPath() throws RepositoryException, NotExecutableException {
String oldPath = moveNode.getPath();
//move the node
doMove(oldPath, destinationPath);
try {
Item item = superuser.getItem(oldPath);
// Implementation specific:
assertTrue("A moved SNS node must be 'replaced' but is successor sibling.", item.isSame(sourceSibling));
} catch (PathNotFoundException e) {
fail("A moved SNS node must be 'replaced' but is successor sibling.");
}
}
Aggregations