use of org.apache.jackrabbit.commons.xml.ParsingContentHandler in project jackrabbit by apache.
the class UserImporterTest method doImport.
private void doImport(NodeImpl target, String xml, int uuidBehavior, int importBehavior) throws IOException, SAXException, RepositoryException {
InputStream in = new ByteArrayInputStream(xml.getBytes("UTF-8"));
SessionImporter importer = new SessionImporter(target, sImpl, uuidBehavior, new PseudoConfig(importBehavior));
ImportHandler ih = new ImportHandler(importer, sImpl);
new ParsingContentHandler(ih).parse(in);
}
use of org.apache.jackrabbit.commons.xml.ParsingContentHandler in project jackrabbit by apache.
the class UserImporterTest method doImport.
//--------------------------------------------------------------------------
private void doImport(NodeImpl target, String xml) throws IOException, SAXException, RepositoryException {
InputStream in = new ByteArrayInputStream(xml.getBytes("UTF-8"));
SessionImporter importer = new SessionImporter(target, sImpl, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW, new PseudoConfig());
ImportHandler ih = new ImportHandler(importer, sImpl);
new ParsingContentHandler(ih).parse(in);
}
use of org.apache.jackrabbit.commons.xml.ParsingContentHandler in project jackrabbit by apache.
the class AbstractWorkspace method importXML.
/**
* Parses the given input stream as an XML document and processes the
* SAX events using the {@link ContentHandler} returned by
* {@link Workspace#getImportContentHandler(String, int)}.
*
* @param parentAbsPath passed through
* @param in input stream to be parsed as XML and imported
* @param uuidBehavior passed through
* @throws IOException if an I/O error occurs
* @throws InvalidSerializedDataException if an XML parsing error occurs
* @throws RepositoryException if a repository error occurs
*/
public void importXML(String parentAbsPath, InputStream in, int uuidBehavior) throws IOException, InvalidSerializedDataException, RepositoryException {
try {
ContentHandler handler = getImportContentHandler(parentAbsPath, uuidBehavior);
new ParsingContentHandler(handler).parse(in);
} catch (SAXException e) {
Throwable exception = e.getException();
if (exception instanceof RepositoryException) {
throw (RepositoryException) exception;
} else if (exception instanceof IOException) {
throw (IOException) exception;
} else {
throw new InvalidSerializedDataException("XML parse error", e);
}
} finally {
// JCR-2903
if (in != null) {
try {
in.close();
} catch (IOException ignore) {
}
}
}
}
use of org.apache.jackrabbit.commons.xml.ParsingContentHandler in project jackrabbit-oak by apache.
the class WorkspaceImpl method importXML.
@Override
public void importXML(String parentAbsPath, InputStream in, int uuidBehavior) throws IOException, RepositoryException {
ensureIsAlive();
try {
ContentHandler handler = getImportContentHandler(parentAbsPath, uuidBehavior);
new ParsingContentHandler(handler).parse(in);
} catch (SAXException e) {
Throwable exception = e.getException();
if (exception instanceof RepositoryException) {
throw (RepositoryException) exception;
} else if (exception instanceof IOException) {
throw (IOException) exception;
} else if (exception instanceof CommitFailedException) {
throw ((CommitFailedException) exception).asRepositoryException();
} else {
throw new InvalidSerializedDataException("XML parse error", e);
}
} finally {
// JCR-2903
if (in != null) {
try {
in.close();
} catch (IOException ignore) {
}
}
}
}
use of org.apache.jackrabbit.commons.xml.ParsingContentHandler in project jackrabbit by apache.
the class AccessControlImporterTest method testImportACLRemoveACE.
/**
* Imports a resource-based ACL containing a single entry.
*
* @throws Exception
*/
public void testImportACLRemoveACE() throws Exception {
try {
NodeImpl target = (NodeImpl) testRootNode.addNode(nodeName1);
target.addMixin("rep:AccessControllable");
InputStream in = new ByteArrayInputStream(XML_POLICY_TREE_3.getBytes("UTF-8"));
SessionImporter importer = new SessionImporter(target, sImpl, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW, new PseudoConfig());
ImportHandler ih = new ImportHandler(importer, sImpl);
new ParsingContentHandler(ih).parse(in);
in = new ByteArrayInputStream(XML_POLICY_TREE_5.getBytes("UTF-8"));
importer = new SessionImporter(target, sImpl, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW, new PseudoConfig());
ih = new ImportHandler(importer, sImpl);
new ParsingContentHandler(ih).parse(in);
String path = target.getPath();
AccessControlManager acMgr = sImpl.getAccessControlManager();
AccessControlPolicy[] policies = acMgr.getPolicies(path);
assertEquals(1, policies.length);
assertTrue(policies[0] instanceof JackrabbitAccessControlList);
AccessControlEntry[] entries = ((JackrabbitAccessControlList) policies[0]).getAccessControlEntries();
assertEquals(1, entries.length);
AccessControlEntry entry = entries[0];
assertEquals("admin", entry.getPrincipal().getName());
assertEquals(1, entry.getPrivileges().length);
assertEquals(acMgr.privilegeFromName(Privilege.JCR_WRITE), entry.getPrivileges()[0]);
if (entry instanceof JackrabbitAccessControlEntry) {
assertTrue(((JackrabbitAccessControlEntry) entry).isAllow());
}
} finally {
superuser.refresh(false);
}
}
Aggregations