use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.
the class LocateCorrespondingNodeReport method getCorrespondingResourceHref.
/**
* Retrieve the href of the corresponding resource in the indicated workspace.
*
* @param resource
* @param session Session object used to access the {@link Node} object
* represented by the given resource.
* @param workspaceHref
* @return
* @throws RepositoryException
*/
private static String getCorrespondingResourceHref(DavResource resource, Session session, String workspaceHref) throws RepositoryException {
DavResourceLocator rLoc = resource.getLocator();
String itemPath = rLoc.getRepositoryPath();
Item item = session.getItem(itemPath);
if (item.isNode()) {
String workspaceName = rLoc.getFactory().createResourceLocator(rLoc.getPrefix(), workspaceHref).getWorkspaceName();
String corrPath = ((Node) item).getCorrespondingNodePath(workspaceName);
DavResourceLocator corrLoc = rLoc.getFactory().createResourceLocator(rLoc.getPrefix(), "/" + workspaceName, corrPath, false);
return corrLoc.getHref(true);
} else {
throw new PathNotFoundException("Node with path " + itemPath + " does not exist.");
}
}
use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.
the class VersionHistoryResourceImpl method getMembers.
//--------------------------------------------------------< DavResource >---
/**
* Show all versions of this history as members.
*
* @return
* @see DavResource#getMembers()
*/
@Override
public DavResourceIterator getMembers() {
ArrayList<DavResource> list = new ArrayList<DavResource>();
if (exists() && isCollection()) {
try {
// only display versions as members of the vh. the jcr:versionLabels
// node is an internal structure.
VersionIterator it = ((VersionHistory) getNode()).getAllVersions();
while (it.hasNext()) {
// omit item filter here. if the version history is visible
// its versions should be visible as well.
Version v = it.nextVersion();
DavResourceLocator vhLocator = getLocator();
DavResourceLocator resourceLocator = vhLocator.getFactory().createResourceLocator(vhLocator.getPrefix(), vhLocator.getWorkspacePath(), v.getPath(), false);
DavResource childRes = getFactory().createResource(resourceLocator, getSession());
list.add(childRes);
}
} catch (RepositoryException e) {
// should not occur
log.error("Unexpected error", e);
} catch (DavException e) {
// should not occur
log.error("Unexpected error", e);
}
}
return new DavResourceIteratorImpl(list);
}
use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.
the class VersionHistoryResourceImpl method getVersions.
//---------------------------------------------< VersionHistoryResource >---
/**
* Return an array of {@link org.apache.jackrabbit.webdav.version.VersionResource}s representing all versions
* present in the underlying JCR version history.
*
* @return array of {@link org.apache.jackrabbit.webdav.version.VersionResource}s representing all versions
* present in the underlying JCR version history.
* @throws org.apache.jackrabbit.webdav.DavException
* @see org.apache.jackrabbit.webdav.version.VersionHistoryResource#getVersions()
*/
public VersionResource[] getVersions() throws DavException {
try {
VersionIterator vIter = ((VersionHistory) getNode()).getAllVersions();
ArrayList<VersionResource> l = new ArrayList<VersionResource>();
while (vIter.hasNext()) {
DavResourceLocator versionLoc = getLocatorFromNode(vIter.nextVersion());
DavResource vr = createResourceFromLocator(versionLoc);
if (vr instanceof VersionResource) {
l.add((VersionResource) vr);
} else {
// severe error since resource factory doesn't behave correctly.
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
return l.toArray(new VersionResource[l.size()]);
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.
the class DeltaVResourceImpl method getReferenceResources.
/**
* Return an array of <code>DavResource</code> objects that are referenced
* by the property with the specified name.
*
* @param hrefPropertyName
* @return array of <code>DavResource</code>s
* @throws DavException
* @see DeltaVResource#getReferenceResources(org.apache.jackrabbit.webdav.property.DavPropertyName)
*/
public DavResource[] getReferenceResources(DavPropertyName hrefPropertyName) throws DavException {
DavProperty<?> prop = getProperty(hrefPropertyName);
List<DavResource> resources = new ArrayList<DavResource>();
if (prop != null && prop instanceof HrefProperty) {
HrefProperty hp = (HrefProperty) prop;
// process list of hrefs
for (String href : hp.getHrefs()) {
DavResourceLocator locator = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(), href);
resources.add(createResourceFromLocator(locator));
}
} else {
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
}
return resources.toArray(new DavResource[resources.size()]);
}
use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.
the class DefaultItemCollection method getMembers.
/**
* @see org.apache.jackrabbit.webdav.DavResource#getMembers()
*/
@Override
public DavResourceIterator getMembers() {
ArrayList<DavResource> memberList = new ArrayList<DavResource>();
if (exists()) {
try {
Node n = (Node) item;
// add all node members
NodeIterator it = n.getNodes();
while (it.hasNext()) {
Node node = it.nextNode();
DavResourceLocator loc = getLocatorFromItem(node);
memberList.add(createResourceFromLocator(loc));
}
// add all property members
PropertyIterator propIt = n.getProperties();
while (propIt.hasNext()) {
Property prop = propIt.nextProperty();
DavResourceLocator loc = getLocatorFromItem(prop);
memberList.add(createResourceFromLocator(loc));
}
} catch (RepositoryException e) {
// ignore
log.error(e.getMessage());
} catch (DavException e) {
// should never occur.
log.error(e.getMessage());
}
}
return new DavResourceIteratorImpl(memberList);
}
Aggregations