use of javax.jcr.Node in project jackrabbit by apache.
the class AdministratorTest method testAdminNodeCollidingWithAuthorizableFolder.
/**
* Test for collisions that would prevent from recreate the admin user.
* - an intermediate rep:AuthorizableFolder node with the same name
*/
public void testAdminNodeCollidingWithAuthorizableFolder() throws RepositoryException, NotExecutableException {
Authorizable admin = userMgr.getAuthorizable(adminId);
if (admin == null || !(admin instanceof AuthorizableImpl)) {
throw new NotExecutableException();
}
// access the node corresponding to the admin user and remove it
NodeImpl adminNode = ((AuthorizableImpl) admin).getNode();
String adminPath = adminNode.getPath();
String adminNodeName = adminNode.getName();
Node parentNode = adminNode.getParent();
Session s = adminNode.getSession();
adminNode.remove();
// use session obtained from the node as usermgr may point to a dedicated
// system workspace different from the superusers workspace.
s.save();
Session s2 = null;
String collidingPath = null;
try {
// now create a colliding node:
Node n = parentNode.addNode(adminNodeName, "rep:AuthorizableFolder");
collidingPath = n.getPath();
s.save();
// force recreation of admin user.
s2 = getHelper().getSuperuserSession();
admin = userMgr.getAuthorizable(adminId);
assertNotNull(admin);
assertEquals(adminNodeName, ((AuthorizableImpl) admin).getNode().getName());
assertFalse(adminPath.equals(((AuthorizableImpl) admin).getNode().getPath()));
} finally {
if (s2 != null) {
s2.logout();
}
// remove the extra folder and the admin user (created underneath) again.
if (collidingPath != null) {
s.getNode(collidingPath).remove();
s.save();
}
}
}
use of javax.jcr.Node in project jackrabbit by apache.
the class DefaultHandler method exportProperties.
public boolean exportProperties(PropertyExportContext exportContext, boolean isCollection) throws RepositoryException {
if (!canExport(exportContext, isCollection)) {
throw new RepositoryException("PropertyHandler " + getName() + " failed to export properties.");
}
Node cn = getContentNode(exportContext, isCollection);
try {
// export the properties common with normal I/O handling
exportProperties(exportContext, isCollection, cn);
// export all other properties as well
PropertyIterator it = cn.getProperties();
while (it.hasNext()) {
Property p = it.nextProperty();
String name = p.getName();
PropertyDefinition def = p.getDefinition();
if (def.isMultiple() || isDefinedByFilteredNodeType(def)) {
log.debug("Skip property '" + name + "': not added to webdav property set.");
continue;
}
if (JcrConstants.JCR_DATA.equals(name) || JcrConstants.JCR_MIMETYPE.equals(name) || JcrConstants.JCR_ENCODING.equals(name) || JcrConstants.JCR_LASTMODIFIED.equals(name)) {
continue;
}
DavPropertyName davName = getDavName(name, p.getSession());
exportContext.setProperty(davName, p.getValue().getString());
}
return true;
} catch (IOException e) {
// should not occur (log output see 'exportProperties')
return false;
}
}
use of javax.jcr.Node in project jackrabbit by apache.
the class DefaultHandler method exportContent.
/**
* Retrieves the content node that will be used for exporting properties and
* data and calls the corresponding methods.
*
* @param context the export context
* @param isCollection <code>true</code> if collection
* @see #exportProperties(ExportContext, boolean, Node)
* @see #exportData(ExportContext, boolean, Node)
*/
public boolean exportContent(ExportContext context, boolean isCollection) throws IOException {
if (!canExport(context, isCollection)) {
throw new IOException(getName() + ": Cannot export " + context.getExportRoot());
}
try {
Node contentNode = getContentNode(context, isCollection);
exportProperties(context, isCollection, contentNode);
if (context.hasStream()) {
exportData(context, isCollection, contentNode);
}
// else: missing stream. ignore.
return true;
} catch (RepositoryException e) {
// node must be asserted in the 'canExport' call.
throw new IOException(e.getMessage());
}
}
use of javax.jcr.Node in project jackrabbit by apache.
the class DefaultHandler method getContentNode.
/**
* Retrieves/creates the node that will be used to import properties and
* data. In case of a non-collection this includes and additional content node
* to be created beside the 'file' node.<br>
* Please note: If the jcr:content node already exists and contains child
* nodes, those will be removed in order to make sure, that the import
* really replaces the existing content of the file-node.
*
* @param context
* @param isCollection
* @return
* @throws RepositoryException
*/
protected Node getContentNode(ImportContext context, boolean isCollection) throws RepositoryException {
Node parentNode = (Node) context.getImportRoot();
String name = context.getSystemId();
if (parentNode.hasNode(name)) {
parentNode = parentNode.getNode(name);
} else {
String ntName = (isCollection) ? getCollectionNodeType() : getNodeType();
parentNode = parentNode.addNode(name, ntName);
}
Node contentNode = null;
if (isCollection) {
contentNode = parentNode;
} else {
if (parentNode.hasNode(JcrConstants.JCR_CONTENT)) {
contentNode = parentNode.getNode(JcrConstants.JCR_CONTENT);
// check if nodetype is compatible (might be update of an existing file)
if (contentNode.isNodeType(getContentNodeType()) || !forceCompatibleContentNodes()) {
// includes properties (DefaultHandler) and nodes (e.g. ZipHandler)
if (contentNode.hasNodes()) {
NodeIterator it = contentNode.getNodes();
while (it.hasNext()) {
it.nextNode().remove();
}
}
} else {
contentNode.remove();
contentNode = null;
}
}
if (contentNode == null) {
// when the underlying repository allows it to be used
if (parentNode.getPrimaryNodeType().canAddChildNode(JcrConstants.JCR_CONTENT, getContentNodeType())) {
contentNode = parentNode.addNode(JcrConstants.JCR_CONTENT, getContentNodeType());
} else {
contentNode = parentNode.addNode(JcrConstants.JCR_CONTENT);
}
}
}
return contentNode;
}
use of javax.jcr.Node in project jackrabbit by apache.
the class DefaultHandler method delete.
/**
* @see DeleteHandler#delete(DeleteContext, DavResource)
*/
public boolean delete(DeleteContext deleteContext, DavResource member) throws DavException {
try {
String itemPath = member.getLocator().getRepositoryPath();
Item item = deleteContext.getSession().getItem(itemPath);
if (item instanceof Node) {
((Node) item).removeShare();
} else {
item.remove();
}
deleteContext.getSession().save();
log.debug("default handler deleted {}", member.getResourcePath());
return true;
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
Aggregations