use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class NodeCorruptionTest method testCopyMultiSingleValue.
public void testCopyMultiSingleValue() throws Exception {
Node root = superuser.getRootNode();
String nodeName = "testCopyMulti" + System.currentTimeMillis();
if (root.hasNode(nodeName)) {
root.getNode(nodeName).remove();
superuser.save();
}
Node test = root.addNode(nodeName);
test.setProperty("x", "Hi");
superuser.save();
String wsp = superuser.getWorkspace().getName();
String workspace2 = getAlternativeWorkspaceName();
if (workspace2 == null) {
throw new NotExecutableException();
}
Session s2 = getHelper().getSuperuserSession(workspace2);
s2.getWorkspace().clone(wsp, "/" + nodeName, "/" + nodeName, true);
Node test2 = s2.getRootNode().getNode(nodeName);
test2.setProperty("x", (Value) null);
test2.setProperty("x", new String[] {});
s2.save();
test.update(workspace2);
try {
Value[] values = test.getProperty("x").getValues();
assertEquals(0, values.length);
} catch (RepositoryException e) {
// if we get here, it's a bug, as it is a multi-valued property now
// anyway, let's see what happens if we try to read it as a single valued property
test.getProperty("x").getValue();
// even if that works: it's still a bug
throw e;
}
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class AutoFixCorruptNode method testAutoFix.
public void testAutoFix() throws Exception {
// new repository
TransientRepository rep = new TransientRepository(new File(TEST_DIR));
Session s = openSession(rep, false);
Node root = s.getRootNode();
// add nodes /test and /test/missing
Node test = root.addNode("test");
Node missing = test.addNode("missing");
missing.addMixin("mix:referenceable");
UUID id = UUID.fromString(missing.getIdentifier());
s.save();
s.logout();
destroyBundle(id, "workspaces/default");
// login and try the operation
s = openSession(rep, false);
test = s.getRootNode().getNode("test");
// try to add a node with the same name
try {
test.addNode("missing");
s.save();
} catch (RepositoryException e) {
// expected
}
s.logout();
s = openSession(rep, true);
test = s.getRootNode().getNode("test");
// iterate over all child nodes fixes the corruption
NodeIterator it = test.getNodes();
while (it.hasNext()) {
it.nextNode();
}
// try to add a node with the same name
test.addNode("missing");
s.save();
// try to delete the parent node
test.remove();
s.save();
s.logout();
rep.shutdown();
FileUtils.deleteDirectory(new File("repository"));
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class ClientSession method getImportContentHandler.
/** {@inheritDoc} */
public ContentHandler getImportContentHandler(final String path, final int mode) throws RepositoryException {
// Check that the path exists
getItem(path);
try {
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ContentHandler handler = SerializingContentHandler.getSerializer(buffer);
return new DefaultContentHandler(handler) {
public void endDocument() throws SAXException {
super.endDocument();
try {
remote.importXML(path, buffer.toByteArray(), mode);
} catch (Exception e) {
throw new SAXException("XML import failed", e);
}
}
};
} catch (SAXException e) {
throw new RepositoryException("XML serialization failed", e);
}
}
use of javax.jcr.RepositoryException 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.RepositoryException 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());
}
}
Aggregations