Return-Path: X-Original-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Delivered-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 346D7FFF7 for ; Tue, 26 Mar 2013 12:19:31 +0000 (UTC) Received: (qmail 80050 invoked by uid 500); 26 Mar 2013 12:19:31 -0000 Delivered-To: apmail-jackrabbit-oak-commits-archive@jackrabbit.apache.org Received: (qmail 79967 invoked by uid 500); 26 Mar 2013 12:19:28 -0000 Mailing-List: contact oak-commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: oak-dev@jackrabbit.apache.org Delivered-To: mailing list oak-commits@jackrabbit.apache.org Received: (qmail 79926 invoked by uid 99); 26 Mar 2013 12:19:27 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Mar 2013 12:19:27 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Mar 2013 12:19:23 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 5332F23889EB; Tue, 26 Mar 2013 12:19:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1461074 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: ItemImpl.java SessionImpl.java Date: Tue, 26 Mar 2013 12:19:02 -0000 To: oak-commits@jackrabbit.apache.org From: mduerig@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130326121902.5332F23889EB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mduerig Date: Tue Mar 26 12:19:01 2013 New Revision: 1461074 URL: http://svn.apache.org/r1461074 Log: OAK-247: SessionImpl should not inherit from AbstractSession copy missing methods from base classes Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java?rev=1461074&r1=1461073&r2=1461074&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java (original) +++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java Tue Mar 26 12:19:01 2013 @@ -17,8 +17,10 @@ package org.apache.jackrabbit.oak.jcr; import javax.annotation.Nonnull; +import javax.jcr.AccessDeniedException; import javax.jcr.InvalidItemStateException; import javax.jcr.Item; +import javax.jcr.ItemNotFoundException; import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.Session; @@ -27,8 +29,9 @@ import javax.jcr.nodetype.ConstraintViol import javax.jcr.nodetype.ItemDefinition; import javax.jcr.nodetype.NodeTypeManager; -import org.apache.jackrabbit.commons.AbstractItem; +import org.apache.jackrabbit.oak.commons.PathUtils; import org.apache.jackrabbit.oak.jcr.delegate.ItemDelegate; +import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate; import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate; import org.apache.jackrabbit.oak.jcr.delegate.SessionOperation; import org.apache.jackrabbit.oak.plugins.nodetype.DefinitionProvider; @@ -38,7 +41,7 @@ import org.slf4j.LoggerFactory; /** * TODO document */ -abstract class ItemImpl extends AbstractItem { +abstract class ItemImpl implements Item { protected final SessionContext sessionContext; protected final T dlg; @@ -103,6 +106,63 @@ abstract class ItemImpl() { + @Override + protected void checkPreconditions() throws RepositoryException { + checkStatus(); + } + + @Override + protected Item perform() throws RepositoryException { + if (depth < 0) { + throw new ItemNotFoundException(this + ": Invalid ancestor depth (" + depth + ')'); + } else if (depth == 0) { + NodeDelegate nd = sessionDelegate.getRootNode(); + if (nd == null) { + throw new AccessDeniedException("Root node is not accessible."); + } + return new NodeImpl(nd, sessionContext); + } + + String path = dlg.getPath(); + int slash = 0; + for (int i = 0; i < depth - 1; i++) { + slash = PathUtils.getNextSlash(path, slash + 1); + if (slash == -1) { + throw new ItemNotFoundException(this + ": Invalid ancestor depth (" + depth + ')'); + } + } + slash = PathUtils.getNextSlash(path, slash + 1); + if (slash == -1) { + return ItemImpl.this; + } + + NodeDelegate nd = sessionDelegate.getNode(path.substring(0, slash)); + if (nd == null) { + throw new AccessDeniedException(this + ": Ancestor access denied (" + depth + ')'); + } + return new NodeImpl(nd, sessionContext); + } + }); + } + + @Override + public int getDepth() throws RepositoryException { + return perform(new SessionOperation() { + @Override + protected void checkPreconditions() throws RepositoryException { + checkStatus(); + } + + @Override + public Integer perform() throws RepositoryException { + return PathUtils.getDepth(dlg.getPath()); + } + }); + } + /** * @see Item#isSame(javax.jcr.Item) */ Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java?rev=1461074&r1=1461073&r2=1461074&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java (original) +++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java Tue Mar 26 12:19:01 2013 @@ -16,6 +16,9 @@ */ package org.apache.jackrabbit.oak.jcr; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.Arrays; import java.util.HashSet; import java.util.Locale; @@ -25,6 +28,7 @@ import java.util.Set; import javax.annotation.Nonnull; import javax.jcr.AccessDeniedException; import javax.jcr.Credentials; +import javax.jcr.InvalidSerializedDataException; import javax.jcr.Item; import javax.jcr.ItemNotFoundException; import javax.jcr.NamespaceException; @@ -45,7 +49,11 @@ import javax.jcr.security.AccessControlM import org.apache.jackrabbit.api.JackrabbitSession; import org.apache.jackrabbit.api.security.principal.PrincipalManager; import org.apache.jackrabbit.api.security.user.UserManager; -import org.apache.jackrabbit.commons.AbstractSession; +import org.apache.jackrabbit.commons.xml.DocumentViewExporter; +import org.apache.jackrabbit.commons.xml.Exporter; +import org.apache.jackrabbit.commons.xml.ParsingContentHandler; +import org.apache.jackrabbit.commons.xml.SystemViewExporter; +import org.apache.jackrabbit.commons.xml.ToXmlContentHandler; import org.apache.jackrabbit.oak.api.TreeLocation; import org.apache.jackrabbit.oak.commons.PathUtils; import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate; @@ -61,11 +69,12 @@ import org.apache.jackrabbit.util.XMLCha import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; /** * TODO document */ -public class SessionImpl extends AbstractSession implements JackrabbitSession { +public class SessionImpl implements JackrabbitSession { /** * logger instance @@ -315,6 +324,11 @@ public class SessionImpl extends Abstrac } @Override + public void removeItem(String absPath) throws RepositoryException { + getItem(absPath).remove(); + } + + @Override public void save() throws RepositoryException { ensureIsAlive(); dlg.save(); @@ -356,6 +370,95 @@ public class SessionImpl extends Abstrac return new ImportHandler(getNode(parentAbsPath), sessionContext, uuidBehavior); } + @Override + public void importXML(String parentAbsPath, InputStream in, int uuidBehavior) + throws IOException, 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) {} + } + } + } + + /** + * Exports content at the given path using the given exporter. + * + * @param path of the node to be exported + * @param exporter document or system view exporter + * @throws SAXException if the SAX event handler failed + * @throws RepositoryException if another error occurs + */ + private synchronized void export(String path, Exporter exporter) + throws SAXException, RepositoryException { + Item item = getItem(path); + if (item.isNode()) { + exporter.export((Node) item); + } else { + throw new PathNotFoundException("XML export is not defined for properties: " + path); + } + } + + @Override + public void exportSystemView(String absPath, ContentHandler contentHandler, boolean skipBinary, boolean noRecurse) + throws SAXException, RepositoryException { + export(absPath, new SystemViewExporter(this, contentHandler, !noRecurse, !skipBinary)); + } + + @Override + public void exportSystemView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse) + throws IOException, RepositoryException { + try { + ContentHandler handler = new ToXmlContentHandler(out); + exportSystemView(absPath, handler, skipBinary, noRecurse); + } catch (SAXException e) { + Exception exception = e.getException(); + if (exception instanceof RepositoryException) { + throw (RepositoryException) exception; + } else if (exception instanceof IOException) { + throw (IOException) exception; + } else { + throw new RepositoryException("Error serializing system view XML", e); + } + } + } + + @Override + public void exportDocumentView(String absPath, ContentHandler contentHandler, boolean skipBinary, + boolean noRecurse) throws SAXException, RepositoryException { + export(absPath, new DocumentViewExporter(this, contentHandler, !noRecurse, !skipBinary)); + } + + @Override + public void exportDocumentView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse) + throws IOException, RepositoryException { + try { + ContentHandler handler = new ToXmlContentHandler(out); + exportDocumentView(absPath, handler, skipBinary, noRecurse); + } catch (SAXException e) { + Exception exception = e.getException(); + if (exception instanceof RepositoryException) { + throw (RepositoryException) exception; + } else if (exception instanceof IOException) { + throw (IOException) exception; + } else { + throw new RepositoryException("Error serializing document view XML", e); + } + } + } + @Nonnull private LockManager getLockManager() { return sessionContext.getLockManager();