Search in sources :

Example 1 with ImportHandler

use of org.apache.jackrabbit.core.xml.ImportHandler in project jackrabbit by apache.

the class SessionImpl method getImportContentHandler.

/**
 * {@inheritDoc}
 */
public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior) throws PathNotFoundException, ConstraintViolationException, VersionException, LockException, RepositoryException {
    // check sanity of this session
    sanityCheck();
    NodeImpl parent;
    try {
        Path p = getQPath(parentAbsPath).getNormalizedPath();
        if (!p.isAbsolute()) {
            throw new RepositoryException("not an absolute path: " + parentAbsPath);
        }
        parent = getItemManager().getNode(p);
    } catch (NameException e) {
        String msg = parentAbsPath + ": invalid path";
        log.debug(msg);
        throw new RepositoryException(msg, e);
    } catch (AccessDeniedException ade) {
        throw new PathNotFoundException(parentAbsPath);
    }
    // verify that parent node is checked-out, not locked and not protected
    // by either node type constraints nor by some retention or hold.
    int options = ItemValidator.CHECK_LOCK | ItemValidator.CHECK_CHECKED_OUT | ItemValidator.CHECK_CONSTRAINTS | ItemValidator.CHECK_HOLD | ItemValidator.CHECK_RETENTION;
    context.getItemValidator().checkModify(parent, options, Permission.NONE);
    SessionImporter importer = new SessionImporter(parent, this, uuidBehavior, context.getWorkspace().getConfig().getImportConfig());
    return new ImportHandler(importer, this);
}
Also used : Path(org.apache.jackrabbit.spi.Path) AccessDeniedException(javax.jcr.AccessDeniedException) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) IllegalNameException(org.apache.jackrabbit.spi.commons.conversion.IllegalNameException) ImportHandler(org.apache.jackrabbit.core.xml.ImportHandler) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) SessionImporter(org.apache.jackrabbit.core.xml.SessionImporter)

Example 2 with ImportHandler

use of org.apache.jackrabbit.core.xml.ImportHandler 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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ParsingContentHandler(org.apache.jackrabbit.commons.xml.ParsingContentHandler) ImportHandler(org.apache.jackrabbit.core.xml.ImportHandler) SessionImporter(org.apache.jackrabbit.core.xml.SessionImporter)

Example 3 with ImportHandler

use of org.apache.jackrabbit.core.xml.ImportHandler 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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ParsingContentHandler(org.apache.jackrabbit.commons.xml.ParsingContentHandler) ImportHandler(org.apache.jackrabbit.core.xml.ImportHandler) SessionImporter(org.apache.jackrabbit.core.xml.SessionImporter)

Example 4 with ImportHandler

use of org.apache.jackrabbit.core.xml.ImportHandler in project jackrabbit by apache.

the class WorkspaceImpl method getImportContentHandler.

/**
 * {@inheritDoc}
 */
public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior) throws PathNotFoundException, ConstraintViolationException, VersionException, LockException, RepositoryException {
    // check state of this instance
    sanityCheck();
    Path parentPath;
    try {
        parentPath = context.getQPath(parentAbsPath).getNormalizedPath();
    } catch (NameException e) {
        String msg = "invalid path: " + parentAbsPath;
        log.debug(msg);
        throw new RepositoryException(msg, e);
    }
    if (!parentPath.isAbsolute()) {
        throw new RepositoryException("not an absolute path: " + parentAbsPath);
    }
    Importer importer = new WorkspaceImporter(parentPath, this, context, uuidBehavior, wspConfig.getImportConfig());
    return new ImportHandler(importer, getSession());
}
Also used : Path(org.apache.jackrabbit.spi.Path) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) WorkspaceImporter(org.apache.jackrabbit.core.xml.WorkspaceImporter) ImportHandler(org.apache.jackrabbit.core.xml.ImportHandler) RepositoryException(javax.jcr.RepositoryException) Importer(org.apache.jackrabbit.core.xml.Importer) WorkspaceImporter(org.apache.jackrabbit.core.xml.WorkspaceImporter)

Aggregations

ImportHandler (org.apache.jackrabbit.core.xml.ImportHandler)4 SessionImporter (org.apache.jackrabbit.core.xml.SessionImporter)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 RepositoryException (javax.jcr.RepositoryException)2 ParsingContentHandler (org.apache.jackrabbit.commons.xml.ParsingContentHandler)2 Path (org.apache.jackrabbit.spi.Path)2 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)2 AccessDeniedException (javax.jcr.AccessDeniedException)1 PathNotFoundException (javax.jcr.PathNotFoundException)1 Importer (org.apache.jackrabbit.core.xml.Importer)1 WorkspaceImporter (org.apache.jackrabbit.core.xml.WorkspaceImporter)1 IllegalNameException (org.apache.jackrabbit.spi.commons.conversion.IllegalNameException)1