jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r599409 - in /jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi: SessionImpl.java WorkspaceImpl.java
Date Thu, 29 Nov 2007 12:18:03 GMT
Author: jukka
Date: Thu Nov 29 04:18:03 2007
New Revision: 599409

URL: http://svn.apache.org/viewvc?rev=599409&view=rev
Log:
JCR-1181: Reverted XML import/export changes due to a regression noticed by Angela.

Modified:
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java?rev=599409&r1=599408&r2=599409&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
Thu Nov 29 04:18:03 2007
@@ -52,7 +52,6 @@
 import org.apache.jackrabbit.spi.NameFactory;
 import org.apache.jackrabbit.spi.PathFactory;
 import org.apache.jackrabbit.value.ValueFactoryQImpl;
-import org.apache.jackrabbit.commons.AbstractSession;
 import org.apache.jackrabbit.conversion.NamePathResolver;
 import org.apache.jackrabbit.conversion.NameException;
 import org.apache.jackrabbit.conversion.PathResolver;
@@ -62,6 +61,7 @@
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
 import javax.jcr.AccessDeniedException;
@@ -86,14 +86,25 @@
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.version.VersionException;
 import javax.jcr.version.Version;
-
+import javax.xml.transform.sax.SAXTransformerFactory;
+import javax.xml.transform.sax.TransformerHandler;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.TransformerException;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.ParserConfigurationException;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.security.AccessControlException;
 import java.util.Map;
 
 /**
  * <code>SessionImpl</code>...
  */
-public class SessionImpl extends AbstractSession implements ManagerProvider {
+public class SessionImpl implements Session, ManagerProvider {
 
     private static Logger log = LoggerFactory.getLogger(SessionImpl.class);
 
@@ -384,6 +395,35 @@
     }
 
     /**
+     * @see javax.jcr.Session#importXML(String, java.io.InputStream, int)
+     */
+    public void importXML(String parentAbsPath, InputStream in, int uuidBehavior) throws
IOException, PathNotFoundException, ItemExistsException, ConstraintViolationException, VersionException,
InvalidSerializedDataException, LockException, RepositoryException {
+        // NOTE: checks are performed by 'getImportContentHandler'
+        ImportHandler handler = (ImportHandler) getImportContentHandler(parentAbsPath, uuidBehavior);
+        try {
+            SAXParserFactory factory = SAXParserFactory.newInstance();
+            factory.setNamespaceAware(true);
+            factory.setFeature(
+                    "http://xml.org/sax/features/namespace-prefixes", false);
+
+            SAXParser parser = factory.newSAXParser();
+            parser.parse(new InputSource(in), handler);
+        } catch (SAXException se) {
+            // check for wrapped repository exception
+            Exception e = se.getException();
+            if (e != null && e instanceof RepositoryException) {
+                throw (RepositoryException) e;
+            } else {
+                String msg = "failed to parse XML stream";
+                log.debug(msg);
+                throw new InvalidSerializedDataException(msg, se);
+            }
+        } catch (ParserConfigurationException e) {
+            throw new RepositoryException("SAX parser configuration error", e);
+        }
+    }
+
+    /**
      * @see javax.jcr.Session#exportSystemView(String, org.xml.sax.ContentHandler, boolean,
boolean)
      */
     public void exportSystemView(String absPath, ContentHandler contentHandler, boolean skipBinary,
boolean noRecurse) throws PathNotFoundException, SAXException, RepositoryException {
@@ -397,6 +437,26 @@
     }
 
     /**
+     * @see javax.jcr.Session#exportSystemView(String, OutputStream, boolean, boolean)
+     */
+    public void exportSystemView(String absPath, OutputStream out, boolean skipBinary, boolean
noRecurse) throws IOException, PathNotFoundException, RepositoryException {
+        SAXTransformerFactory stf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
+        try {
+            TransformerHandler th = stf.newTransformerHandler();
+            th.getTransformer().setOutputProperty(OutputKeys.METHOD, "xml");
+            th.getTransformer().setOutputProperty(OutputKeys.ENCODING, "UTF-8");
+            th.getTransformer().setOutputProperty(OutputKeys.INDENT, "no");
+            th.setResult(new StreamResult(out));
+
+            exportSystemView(absPath, th, skipBinary, noRecurse);
+        } catch (TransformerException te) {
+            throw new RepositoryException(te);
+        } catch (SAXException se) {
+            throw new RepositoryException(se);
+        }
+    }
+
+    /**
      * @see javax.jcr.Session#exportDocumentView(String, org.xml.sax.ContentHandler, boolean,
boolean)
      */
     public void exportDocumentView(String absPath, ContentHandler contentHandler, boolean
skipBinary, boolean noRecurse) throws InvalidSerializedDataException, PathNotFoundException,
SAXException, RepositoryException {
@@ -407,6 +467,26 @@
             throw new PathNotFoundException(absPath);
         }
         new DocViewSAXEventGenerator((Node) item, noRecurse, skipBinary, contentHandler).serialize();
+    }
+
+    /**
+     * @see javax.jcr.Session#exportDocumentView(String, OutputStream, boolean, boolean)
+     */
+    public void exportDocumentView(String absPath, OutputStream out, boolean skipBinary,
boolean noRecurse) throws InvalidSerializedDataException, IOException, PathNotFoundException,
RepositoryException {
+        SAXTransformerFactory stf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
+        try {
+            TransformerHandler th = stf.newTransformerHandler();
+            th.getTransformer().setOutputProperty(OutputKeys.METHOD, "xml");
+            th.getTransformer().setOutputProperty(OutputKeys.ENCODING, "UTF-8");
+            th.getTransformer().setOutputProperty(OutputKeys.INDENT, "no");
+            th.setResult(new StreamResult(out));
+
+            exportDocumentView(absPath, th, skipBinary, noRecurse);
+        } catch (TransformerException te) {
+            throw new RepositoryException(te);
+        } catch (SAXException se) {
+            throw new RepositoryException(se);
+        }
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java?rev=599409&r1=599408&r2=599409&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
Thu Nov 29 04:18:03 2007
@@ -30,6 +30,7 @@
 import org.apache.jackrabbit.jcr2spi.operation.Copy;
 import org.apache.jackrabbit.jcr2spi.operation.Clone;
 import org.apache.jackrabbit.jcr2spi.operation.Operation;
+import org.apache.jackrabbit.jcr2spi.operation.WorkspaceImport;
 import org.apache.jackrabbit.jcr2spi.security.AccessManager;
 import org.apache.jackrabbit.jcr2spi.lock.LockManager;
 import org.apache.jackrabbit.jcr2spi.lock.LockManagerImpl;
@@ -47,7 +48,6 @@
 import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.NameFactory;
 import org.apache.jackrabbit.spi.PathFactory;
-import org.apache.jackrabbit.commons.AbstractWorkspace;
 import org.apache.jackrabbit.conversion.NameResolver;
 import org.apache.jackrabbit.conversion.PathResolver;
 import org.apache.jackrabbit.conversion.NamePathResolver;
@@ -63,6 +63,7 @@
 import javax.jcr.version.Version;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.Workspace;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.AccessDeniedException;
@@ -73,12 +74,15 @@
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.NamespaceRegistry;
+import javax.jcr.InvalidSerializedDataException;
 import javax.jcr.ValueFactory;
+import java.io.InputStream;
+import java.io.IOException;
 
 /**
  * <code>WorkspaceImpl</code>...
  */
-public class WorkspaceImpl extends AbstractWorkspace implements ManagerProvider {
+public class WorkspaceImpl implements Workspace, ManagerProvider {
 
     private static Logger log = LoggerFactory.getLogger(WorkspaceImpl.class);
 
@@ -320,6 +324,32 @@
 
             // build the content handler
             return new WorkspaceContentHandler(this, parentAbsPath, uuidBehavior);
+        } else {
+            throw new PathNotFoundException("No node at path " + parentAbsPath);
+        }
+    }
+
+    /**
+     * @see javax.jcr.Workspace#importXML(String, InputStream, int)
+     */
+    public void importXML(String parentAbsPath, InputStream in, int uuidBehavior)
+        throws IOException, PathNotFoundException, ItemExistsException,
+        ConstraintViolationException, InvalidSerializedDataException,
+        LockException, RepositoryException {
+
+        session.checkSupportedOption(Repository.LEVEL_2_SUPPORTED);
+        session.checkIsAlive();
+
+        Path parentPath = session.getQPath(parentAbsPath);
+        ItemState itemState = getHierarchyManager().getItemState(parentPath);
+        if (itemState.isNode()) {
+            // make sure the given import target is accessible, not locked and checked out.
+            NodeState parentState = (NodeState) itemState;
+            int options = ItemStateValidator.CHECK_ACCESS | ItemStateValidator.CHECK_LOCK
| ItemStateValidator.CHECK_VERSIONING;
+            getValidator().checkIsWritable(parentState, options);
+
+            // run the import
+            wspManager.execute(WorkspaceImport.create(parentState, in, uuidBehavior));
         } else {
             throw new PathNotFoundException("No node at path " + parentAbsPath);
         }



Mime
View raw message