[dna-commits] DNA SVN: r1501 - in trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector: svn and 1 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Thu Dec 31 08:46:43 EST 2009


Author: spagop
Date: 2009-12-31 08:46:43 -0500 (Thu, 31 Dec 2009)
New Revision: 1501

Added:
   trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/DeleteEntry.java
   trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/UpdateFile.java
Removed:
   trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/MergeFile.java
Modified:
   trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/scm/ScmActionFactory.java
   trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java
   trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
   trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryUtil.java
   trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/AddDirectory.java
Log:
OPEN - issue DNA-607: Delete node/folder or rather item/file from the svn repository through dna svn connector 
https://jira.jboss.org/jira/browse/DNA-607

Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/scm/ScmActionFactory.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/scm/ScmActionFactory.java	2009-12-31 13:45:57 UTC (rev 1500)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/scm/ScmActionFactory.java	2009-12-31 13:46:43 UTC (rev 1501)
@@ -23,15 +23,13 @@
  */
 package org.jboss.dna.connector.scm;
 
-/**
- */
 public interface ScmActionFactory {
 
     public ScmAction addFile( String path,
                               String file,
                               byte[] content );
 
-    public ScmAction mergeFile( String rootPath,
+    public ScmAction updateFile( String rootPath,
                                  String fileName,
                                  byte[] oldData,
                                  byte[] newData );
@@ -39,13 +37,6 @@
     public ScmAction addDirectory( String root,
                                    String path );
 
-    public ScmAction copyDirectory( String path,
-                                    String newPath,
-                                    long revision );
+    public ScmAction deleteEntry( String path);
 
-    public ScmAction deleteFile( String path,
-                                 String file );
-
-    public ScmAction deleteDirectory( String path );
-
 }

Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java	2009-12-31 13:45:57 UTC (rev 1500)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java	2009-12-31 13:46:43 UTC (rev 1501)
@@ -63,6 +63,7 @@
     public static I18n missingRequiredProperty;
     public static I18n couldNotCreateFile;
     public static I18n couldNotReadData;
+    public static I18n deleteFailed;
 
     static {
         try {

Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java	2009-12-31 13:45:57 UTC (rev 1500)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java	2009-12-31 13:46:43 UTC (rev 1501)
@@ -40,7 +40,8 @@
 import org.jboss.dna.connector.scm.ScmActionFactory;
 import org.jboss.dna.connector.svn.mgnt.AddDirectory;
 import org.jboss.dna.connector.svn.mgnt.AddFile;
-import org.jboss.dna.connector.svn.mgnt.MergeFile;
+import org.jboss.dna.connector.svn.mgnt.DeleteEntry;
+import org.jboss.dna.connector.svn.mgnt.UpdateFile;
 import org.jboss.dna.graph.DnaIntLexicon;
 import org.jboss.dna.graph.DnaLexicon;
 import org.jboss.dna.graph.ExecutionContext;
@@ -360,7 +361,7 @@
         if (parentPath == null) return;
 
         // svn connector does not support same name sibling
-        sameNameSiblingIsNotSupported(parentPath, request);
+        sameNameSiblingIsNotSupported(parentPath);
 
         SVNRepository workspaceRoot = getWorkspaceDirectory(request.inWorkspace());
         assert workspaceRoot != null;
@@ -395,30 +396,32 @@
             boolean skipWrite = false;
 
             if (request.under().getPath().isRoot()) {
-
                 if (!accessData.getRepositoryRootUrl().equals(request.inWorkspace())) {
                     newChildPath = newName;
                 } else {
                     newChildPath = "/" + newName;
                 }
             } else {
-
                 newChildPath = getPathAsString(request.under().getPath()) + "/" + newName;
-
                 if (!accessData.getRepositoryRootUrl().equals(request.inWorkspace())) {
                     newChildPath = newChildPath.substring(1);
                 }
             }
 
             // check if the new name already exist
-            if (SVNRepositoryUtil.exists(workspaceRoot, newChildPath)) {
-                if (request.conflictBehavior().equals(NodeConflictBehavior.APPEND)) {
-                    I18n msg = SVNRepositoryConnectorI18n.sameNameSiblingsAreNotAllowed;
-                    throw new InvalidRequestException(msg.text(this.getSourceName(), newName));
-                } else if (request.conflictBehavior().equals(NodeConflictBehavior.DO_NOT_REPLACE)) {
-                    skipWrite = true;
+            try {
+                if (SVNRepositoryUtil.exists(workspaceRoot, newChildPath)) {
+                    if (request.conflictBehavior().equals(NodeConflictBehavior.APPEND)) {
+                        I18n msg = SVNRepositoryConnectorI18n.sameNameSiblingsAreNotAllowed;
+                        throw new InvalidRequestException(msg.text("SVN Connector does not support Same Name Sibling"));
+                    } else if (request.conflictBehavior().equals(NodeConflictBehavior.DO_NOT_REPLACE)) {
+                        skipWrite = true;
+                    }
                 }
+            } catch (SVNException e1) {
+                throw new RepositorySourceException(getSourceName(), e1.getMessage());
             }
+
             // Don't try to write if the node conflict behavior is DO_NOT_REPLACE
             if (!skipWrite) {
                 // create a new, empty file
@@ -430,7 +433,7 @@
                         } else {
                             rootPath = getPathAsString(request.under().getPath());
                         }
-                        newFile(rootPath, newName, "".getBytes(), null, request.inWorkspace(), this.defaultWorkspace);
+                        newFile(rootPath, newName, "".getBytes(), null, request.inWorkspace(), workspaceRoot);
                     } catch (SVNException e) {
                         I18n msg = SVNRepositoryConnectorI18n.couldNotCreateFile;
                         request.setError(new RepositorySourceException(getSourceName(),
@@ -480,7 +483,7 @@
             if (parent != SVNNodeKind.NONE || parent != SVNNodeKind.UNKNOWN) {
                 if (request.conflictBehavior().equals(NodeConflictBehavior.APPEND)) {
                     I18n msg = SVNRepositoryConnectorI18n.sameNameSiblingsAreNotAllowed;
-                    throw new InvalidRequestException(msg.text(this.getSourceName(), newName));
+                    throw new InvalidRequestException(msg.text("SVN Connector does not support Same Name Sibling"));
                 } else if (request.conflictBehavior().equals(NodeConflictBehavior.DO_NOT_REPLACE)) {
                     // TODO check if the file already has content
                     skipWrite = true;
@@ -521,13 +524,7 @@
                             rootPath = "";
                         }
 
-                        modifyFile(rootPath,
-                                   fileName,
-                                   oldData,
-                                   binary.getBytes(),
-                                   null,
-                                   request.inWorkspace(),
-                                   this.defaultWorkspace);
+                        modifyFile(rootPath, fileName, oldData, binary.getBytes(), null, request.inWorkspace(), workspaceRoot);
                     }
                 } catch (SVNException e) {
                     I18n msg = SVNRepositoryConnectorI18n.couldNotReadData;
@@ -600,7 +597,7 @@
         for (Path.Segment segment : path) {
             if (segment.getIndex() > 1) {
                 I18n msg = SVNRepositoryConnectorI18n.sameNameSiblingsAreNotAllowed;
-                throw new RepositorySourceException(getSourceName(), msg.text(getSourceName(), request));
+                throw new RepositorySourceException(getSourceName(), msg.text("SVN Connector does not support Same Name Sibling"));
             }
         }
 
@@ -625,13 +622,12 @@
         return kind;
     }
 
-    private void sameNameSiblingIsNotSupported( Path path,
-                                                CreateNodeRequest request ) {
+    protected void sameNameSiblingIsNotSupported( Path path ) {
         for (Path.Segment segment : path) {
             // Verify the segment is valid ...
             if (segment.getIndex() > 1) {
                 I18n msg = SVNRepositoryConnectorI18n.sameNameSiblingsAreNotAllowed;
-                throw new RepositorySourceException(getSourceName(), msg.text(getSourceName(), request));
+                throw new RepositorySourceException(getSourceName(), msg.text("SVN Connector does not support Same Name Sibling"));
             }
         }
     }
@@ -674,7 +670,67 @@
      */
     @Override
     public void process( DeleteBranchRequest request ) {
-        updatesAllowed(request);
+        logger.trace(request.toString());
+        if (!updatesAllowed(request)) return;
+
+        SVNRepository workspaceRoot = getWorkspaceDirectory(request.inWorkspace());
+        assert workspaceRoot != null;
+        
+        NamespaceRegistry registry = getExecutionContext().getNamespaceRegistry();
+
+        Path requestedPath = request.at().getPath();
+        // svn connector does not support same name sibling
+        sameNameSiblingIsNotSupported(requestedPath);
+
+        if (!requestedPath.isRoot() && JcrLexicon.CONTENT.equals(requestedPath.getLastSegment().getName())) {
+            Path p = requestedPath.getAncestor(1);
+            if(p != null) {
+                String itemPath = getPathAsString(p);
+                if (itemPath.equals("") || itemPath.equals("/")) {
+                    return;
+                }
+                String filePath = null;
+                if (!accessData.getRepositoryRootUrl().equals(request.inWorkspace())) {
+                    filePath = itemPath.substring(1);
+                }
+                try {
+                    //check if the file exist
+                    if (!SVNRepositoryUtil.exists(workspaceRoot, filePath)) return;
+                    
+                    //update the file
+                    SVNProperties fileProperties = new SVNProperties();
+                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                    workspaceRoot.getFile(filePath, -1, fileProperties, baos);
+                    
+                    String rootPath = getPathAsString(p.getAncestor(1));
+                    String fileName = p.getLastSegment().getString(registry);
+                    modifyFile(rootPath, fileName, baos.toByteArray(), "".getBytes(), null, request.inWorkspace(), workspaceRoot);
+
+                } catch (SVNException e) {
+                    throw new RepositorySourceException(getSourceName(),
+                                                        SVNRepositoryConnectorI18n.deleteFailed.text(itemPath, getSourceName()));
+
+                }
+            }
+
+
+        } else {
+
+            String nodePath = getPathAsString(requestedPath);
+
+            if (!accessData.getRepositoryRootUrl().equals(request.inWorkspace())) {
+                nodePath = nodePath.substring(1);
+            }
+
+            try {
+                if (!SVNRepositoryUtil.exists(workspaceRoot, nodePath)) return;
+                eraseEntry(nodePath, null, request.inWorkspace(), workspaceRoot);
+            } catch (SVNException e) {
+                throw new RepositorySourceException(getSourceName(),
+                                                    SVNRepositoryConnectorI18n.deleteFailed.text(nodePath, getSourceName()));
+
+            }
+        }
     }
 
     /**
@@ -822,102 +878,6 @@
     }
 
     /**
-     * Verify if change is allowed on a specific source.
-     * 
-     * @throws RepositorySourceException if change on that repository source is not allowed.
-     */
-    protected void verifyUpdatesAllowed() {
-        if (!updatesAllowed) {
-            throw new InvalidRequestException(SVNRepositoryConnectorI18n.sourceIsReadOnly.text(getSourceName()));
-        }
-    }
-
-    protected boolean updatesAllowed( Request request ) {
-        if (!updatesAllowed) {
-            request.setError(new InvalidRequestException(SVNRepositoryConnectorI18n.sourceIsReadOnly.text(getSourceName())));
-        }
-        return !request.hasError();
-    }
-
-    /**
-     * Factory for sample name.
-     * 
-     * @return the name factory
-     */
-    protected NameFactory nameFactory() {
-        return getExecutionContext().getValueFactories().getNameFactory();
-    }
-
-    /**
-     * Factory for path creation.
-     * 
-     * @return a path factory.
-     */
-    protected PathFactory pathFactory() {
-        return getExecutionContext().getValueFactories().getPathFactory();
-    }
-
-    /**
-     * Factory for property creation.
-     * 
-     * @return the property factory.
-     */
-    protected PropertyFactory propertyFactory() {
-        return getExecutionContext().getPropertyFactory();
-    }
-
-    /**
-     * Factory for date creation.
-     * 
-     * @return the date factory.
-     */
-    protected DateTimeFactory dateFactory() {
-        return getExecutionContext().getValueFactories().getDateFactory();
-    }
-
-    /**
-     * Factory for binary creation.
-     * 
-     * @return the binary factory..
-     */
-    protected ValueFactory<Binary> binaryFactory() {
-        return getExecutionContext().getValueFactories().getBinaryFactory();
-    }
-
-    /**
-     * Get the path for a locarion and check if the path is null or not.
-     * 
-     * @param location - the location.
-     * @param request - the requested path.
-     * @return the path.
-     * @throws RepositorySourceException if the path of a location is null.
-     */
-    protected Path getPathFor( Location location,
-                               Request request ) {
-        Path path = location.getPath();
-        if (path == null) {
-            I18n msg = SVNRepositoryConnectorI18n.locationInRequestMustHavePath;
-            throw new RepositorySourceException(getSourceName(), msg.text(getSourceName(), request));
-        }
-        return path;
-    }
-
-    /**
-     * Get the content of a file.
-     * 
-     * @param path - the path to that file.
-     * @param properties - the properties of the file.
-     * @param os - the output stream where to store the content.
-     * @throws SVNException - throws if such path is not at that revision or in case of a connection problem.
-     */
-    protected void getData( String path,
-                            SVNProperties properties,
-                            OutputStream os ) throws SVNException {
-        getDefaultWorkspace().getFile(path, -1, properties, os);
-
-    }
-
-    /**
      * Get the repository driver.
      * 
      * @return repository
@@ -927,72 +887,6 @@
     }
 
     /**
-     * Validate the kind of node and throws an exception if necessary.
-     * 
-     * @param repos
-     * @param requestedPath
-     * @return the kind.
-     */
-    protected SVNNodeKind validateNodeKind( SVNRepository repos,
-                                            Path requestedPath ) {
-        SVNNodeKind kind;
-        String myPath;
-        if (getPathAsString(requestedPath).trim().equals("/")) {
-            myPath = getPathAsString(requestedPath);
-        } else if (requestedPath.endsWith(JcrLexicon.CONTENT)) {
-            myPath = getPathAsString(requestedPath.getParent());
-        } else {
-            // directory and file
-            myPath = getPathAsString(requestedPath);
-        }
-
-        try {
-
-            kind = repos.checkPath(myPath, -1);
-            if (kind == SVNNodeKind.NONE) {
-                // node does not exist or requested node is not correct.
-                throw new PathNotFoundException(Location.create(requestedPath), null,
-                                                SVNRepositoryConnectorI18n.nodeDoesNotExist.text(myPath));
-            } else if (kind == SVNNodeKind.UNKNOWN) {
-                // node is unknown
-                throw new PathNotFoundException(Location.create(requestedPath), null,
-                                                SVNRepositoryConnectorI18n.nodeIsActuallyUnknow.text(myPath));
-            }
-        } catch (SVNException e) {
-            throw new RepositorySourceException(
-                                                getSourceName(),
-                                                SVNRepositoryConnectorI18n.connectingFailureOrUserAuthenticationProblem.text(getSourceName()));
-        }
-
-        return kind;
-    }
-
-    private String getPathAsString( Path path ) {
-        return path.getString(getExecutionContext().getNamespaceRegistry());
-    }
-
-    /**
-     * Get some important informations of a path
-     * 
-     * @param repos
-     * @param path - the path
-     * @return - the {@link SVNDirEntry}, or null if there is no such entry
-     */
-    protected SVNDirEntry getEntryInfo( SVNRepository repos,
-                                        String path ) {
-        assert path != null;
-        SVNDirEntry entry = null;
-        try {
-            entry = repos.info(path, -1);
-        } catch (SVNException e) {
-            throw new RepositorySourceException(
-                                                getSourceName(),
-                                                SVNRepositoryConnectorI18n.connectingFailureOrUserAuthenticationProblem.text(getSourceName()));
-        }
-        return entry;
-    }
-
-    /**
      * Get the last revision.
      * 
      * @param repos
@@ -1068,7 +962,7 @@
      * @param currentRepository
      * @throws SVNException
      */
-    public void newFile( String rootDirPath,
+    private void newFile( String rootDirPath,
                          String childFilePath,
                          byte[] content,
                          String comment,
@@ -1153,7 +1047,7 @@
                 throw new SVNException(err);
             }
 
-            ScmAction modifyFileAction = mergeFile(rootPath, fileName, oldData, newData);
+            ScmAction modifyFileAction = updateFile(rootPath, fileName, oldData, newData);
             SVNActionExecutor executor = new SVNActionExecutor(currentRepository);
             comment = comment == null ? "modify the " + fileName : comment;
             executor.execute(modifyFileAction, comment);
@@ -1166,6 +1060,39 @@
     }
 
     /**
+     * Delete entry from the repository
+     * 
+     * @param path
+     * @param comment
+     * @param inWorkspace
+     * @param currentRepository
+     * @throws SVNException
+     */
+    private void eraseEntry( String path,
+                             String comment,
+                             String inWorkspace,
+                             SVNRepository currentRepository ) throws SVNException {
+        assert path != null;
+        assert inWorkspace != null;
+        if (path.equals("/") || path.equals("")) {
+            SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.BAD_URL, "The root directory cannot be deleted");
+            throw new SVNException(err);
+        }
+
+        try {
+            ScmAction deleteEntryAction = deleteEntry(path);
+            SVNActionExecutor executor = new SVNActionExecutor(currentRepository);
+            comment = comment == null ? "Delete the " + path : comment;
+            executor.execute(deleteEntryAction, comment);
+        } catch (SVNException e) {
+            SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
+                                                         "unknow error during delete action: {0)",
+                                                         e.getMessage());
+            throw new SVNException(err);
+        }
+    }
+
+    /**
      * {@inheritDoc}
      * 
      * @see org.jboss.dna.connector.scm.ScmActionFactory#addDirectory(java.lang.String, java.lang.String)
@@ -1189,73 +1116,31 @@
     /**
      * {@inheritDoc}
      * 
-     * @see org.jboss.dna.connector.scm.ScmActionFactory#mergeFile(java.lang.String, java.lang.String, byte[], byte[])
+     * @see org.jboss.dna.connector.scm.ScmActionFactory#updateFile(java.lang.String, java.lang.String, byte[], byte[])
      */
-    public ScmAction mergeFile( String rootPath,
-                                String fileName,
-                                byte[] oldData,
-                                byte[] newData ) {
-        return new MergeFile(rootPath, fileName, oldData, newData);
+    public ScmAction updateFile( String rootPath,
+                                 String fileName,
+                                 byte[] oldData,
+                                 byte[] newData ) {
+        return new UpdateFile(rootPath, fileName, oldData, newData);
     }
 
     /**
      * {@inheritDoc}
      * 
-     * @see org.jboss.dna.connector.scm.ScmActionFactory#copyDirectory(java.lang.String, java.lang.String, long)
+     * @see org.jboss.dna.connector.scm.ScmActionFactory#deleteEntry(java.lang.String)
      */
-    public ScmAction copyDirectory( String path,
-                                    String newPath,
-                                    long revision ) {
-        return null;
+    public ScmAction deleteEntry( String path ) {
+        return new DeleteEntry(path);
     }
 
-    /**
-     * {@inheritDoc}
-     * 
-     * @see org.jboss.dna.connector.scm.ScmActionFactory#deleteDirectory(java.lang.String)
-     */
-    public ScmAction deleteDirectory( String path ) {
-        return null;
-    }
-
-    /**
-     * {@inheritDoc}
-     * 
-     * @see org.jboss.dna.connector.scm.ScmActionFactory#deleteFile(java.lang.String, java.lang.String)
-     */
-    public ScmAction deleteFile( String path,
-                                 String file ) {
-        return null;
-    }
-
-    @SuppressWarnings( "unused" )
-    private byte[] getContent( Object[] objs ) {
-        byte[] content = null;
-        for (Object object : objs) {
-            if (object != null && object instanceof Binary) {
-                Binary buf = (Binary)object;
-                content = buf.getBytes();
-            }
-        }
-        return content;
-    }
-
-    @SuppressWarnings( "unused" )
-    private Object[] values( Collection<Property> childNodeProperties ) {
-        Set<Object> result = new HashSet<Object>();
-        for (Property property : childNodeProperties) {
-            result.add(property.getFirstValue());
-        }
-        return result.toArray();
-    }
-
-    private void checkThePath( Path path,
-                               Request request ) {
+    protected void checkThePath( Path path,
+                                 Request request ) {
         for (Path.Segment segment : path) {
             // Verify the segment is valid ...
             if (segment.getIndex() > 1) {
                 I18n msg = SVNRepositoryConnectorI18n.sameNameSiblingsAreNotAllowed;
-                throw new RepositorySourceException(getSourceName(), msg.text(getSourceName(), request));
+                throw new RepositorySourceException(getSourceName(), msg.text("SVN Connector does not support Same Name Sibling"));
             }
         }
     }
@@ -1329,4 +1214,166 @@
                                                 SVNRepositoryConnectorI18n.invalidPropertyNames.text(invalidNames.toString()));
         }
     }
+    
+    /**
+     * Validate the kind of node and throws an exception if necessary.
+     * 
+     * @param repos
+     * @param requestedPath
+     * @return the kind.
+     */
+    protected SVNNodeKind validateNodeKind( SVNRepository repos,
+                                            Path requestedPath ) {
+        SVNNodeKind kind;
+        String myPath;
+        if (getPathAsString(requestedPath).trim().equals("/")) {
+            myPath = getPathAsString(requestedPath);
+        } else if (requestedPath.endsWith(JcrLexicon.CONTENT)) {
+            myPath = getPathAsString(requestedPath.getParent());
+        } else {
+            // directory and file
+            myPath = getPathAsString(requestedPath);
+        }
+
+        try {
+
+            kind = repos.checkPath(myPath, -1);
+            if (kind == SVNNodeKind.NONE) {
+                // node does not exist or requested node is not correct.
+                throw new PathNotFoundException(Location.create(requestedPath), null,
+                                                SVNRepositoryConnectorI18n.nodeDoesNotExist.text(myPath));
+            } else if (kind == SVNNodeKind.UNKNOWN) {
+                // node is unknown
+                throw new PathNotFoundException(Location.create(requestedPath), null,
+                                                SVNRepositoryConnectorI18n.nodeIsActuallyUnknow.text(myPath));
+            }
+        } catch (SVNException e) {
+            throw new RepositorySourceException(
+                                                getSourceName(),
+                                                SVNRepositoryConnectorI18n.connectingFailureOrUserAuthenticationProblem.text(getSourceName()));
+        }
+
+        return kind;
+    }
+    
+    /**
+     * Verify if change is allowed on a specific source.
+     * 
+     * @throws RepositorySourceException if change on that repository source is not allowed.
+     */
+    protected void verifyUpdatesAllowed() {
+        if (!updatesAllowed) {
+            throw new InvalidRequestException(SVNRepositoryConnectorI18n.sourceIsReadOnly.text(getSourceName()));
+        }
+    }
+
+    protected boolean updatesAllowed( Request request ) {
+        if (!updatesAllowed) {
+            request.setError(new InvalidRequestException(SVNRepositoryConnectorI18n.sourceIsReadOnly.text(getSourceName())));
+        }
+        return !request.hasError();
+    }
+
+    /**
+     * Factory for sample name.
+     * 
+     * @return the name factory
+     */
+    protected NameFactory nameFactory() {
+        return getExecutionContext().getValueFactories().getNameFactory();
+    }
+
+    /**
+     * Factory for path creation.
+     * 
+     * @return a path factory.
+     */
+    protected PathFactory pathFactory() {
+        return getExecutionContext().getValueFactories().getPathFactory();
+    }
+
+    /**
+     * Factory for property creation.
+     * 
+     * @return the property factory.
+     */
+    protected PropertyFactory propertyFactory() {
+        return getExecutionContext().getPropertyFactory();
+    }
+
+    /**
+     * Factory for date creation.
+     * 
+     * @return the date factory.
+     */
+    protected DateTimeFactory dateFactory() {
+        return getExecutionContext().getValueFactories().getDateFactory();
+    }
+
+    /**
+     * Factory for binary creation.
+     * 
+     * @return the binary factory..
+     */
+    protected ValueFactory<Binary> binaryFactory() {
+        return getExecutionContext().getValueFactories().getBinaryFactory();
+    }
+
+    /**
+     * Get the path for a locarion and check if the path is null or not.
+     * 
+     * @param location - the location.
+     * @param request - the requested path.
+     * @return the path.
+     * @throws RepositorySourceException if the path of a location is null.
+     */
+    protected Path getPathFor( Location location,
+                               Request request ) {
+        Path path = location.getPath();
+        if (path == null) {
+            I18n msg = SVNRepositoryConnectorI18n.locationInRequestMustHavePath;
+            throw new RepositorySourceException(getSourceName(), msg.text(getSourceName(), request));
+        }
+        return path;
+    }
+
+    /**
+     * Get the content of a file.
+     * 
+     * @param path - the path to that file.
+     * @param properties - the properties of the file.
+     * @param os - the output stream where to store the content.
+     * @throws SVNException - throws if such path is not at that revision or in case of a connection problem.
+     */
+    protected void getData( String path,
+                            SVNProperties properties,
+                            OutputStream os ) throws SVNException {
+        getDefaultWorkspace().getFile(path, -1, properties, os);
+
+    }
+    
+    protected String getPathAsString( Path path ) {
+        return path.getString(getExecutionContext().getNamespaceRegistry());
+    }
+
+    /**
+     * Get some important informations of a path
+     * 
+     * @param repos
+     * @param path - the path
+     * @return - the {@link SVNDirEntry}, or null if there is no such entry
+     */
+    protected SVNDirEntry getEntryInfo( SVNRepository repos,
+                                        String path ) {
+        assert path != null;
+        SVNDirEntry entry = null;
+        try {
+            entry = repos.info(path, -1);
+        } catch (SVNException e) {
+            throw new RepositorySourceException(
+                                                getSourceName(),
+                                                SVNRepositoryConnectorI18n.connectingFailureOrUserAuthenticationProblem.text(getSourceName()));
+        }
+        return entry;
+    }
 }

Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryUtil.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryUtil.java	2009-12-31 13:45:57 UTC (rev 1500)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryUtil.java	2009-12-31 13:46:43 UTC (rev 1501)
@@ -28,6 +28,8 @@
 import org.jboss.dna.graph.connector.RepositorySourceException;
 import org.jboss.dna.graph.request.InvalidWorkspaceException;
 import org.tmatesoft.svn.core.SVNDirEntry;
+import org.tmatesoft.svn.core.SVNErrorCode;
+import org.tmatesoft.svn.core.SVNErrorMessage;
 import org.tmatesoft.svn.core.SVNException;
 import org.tmatesoft.svn.core.SVNNodeKind;
 import org.tmatesoft.svn.core.SVNURL;
@@ -215,7 +217,7 @@
     }
 
     public static boolean exists( SVNRepository repository,
-                                  String path ) {
+                                  String path ) throws SVNException{
         try {
             if (repository.checkPath(path, -1) == SVNNodeKind.NONE) {
                 return false;
@@ -223,7 +225,10 @@
                 return false;
             }
         } catch (SVNException e) {
-            return false;
+            SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
+                                                         "unknow error during delete action: {0)",
+                                                         e.getMessage());
+            throw new SVNException(err);
         }
         return true;
     }

Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/AddDirectory.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/AddDirectory.java	2009-12-31 13:45:57 UTC (rev 1500)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/AddDirectory.java	2009-12-31 13:46:43 UTC (rev 1501)
@@ -29,6 +29,7 @@
 
 /**
  * root should be the last, previously created, parent folder. Each directory in the path will be created.
+ * @author serge pagop
  */
 public class AddDirectory implements ScmAction {
     private String rootDirPath;

Added: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/DeleteEntry.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/DeleteEntry.java	                        (rev 0)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/DeleteEntry.java	2009-12-31 13:46:43 UTC (rev 1501)
@@ -0,0 +1,51 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of 
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.connector.svn.mgnt;
+
+import org.jboss.dna.connector.scm.ScmAction;
+import org.tmatesoft.svn.core.io.ISVNEditor;
+
+/**
+ * @author serge pagop
+ */
+public class DeleteEntry implements ScmAction {
+
+    private String path;
+
+    public DeleteEntry( String path ) {
+        this.path = path;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.connector.scm.ScmAction#applyAction(java.lang.Object)
+     */
+    public void applyAction( Object context ) throws Exception {
+
+        ISVNEditor editor = (ISVNEditor)context;
+        editor.deleteEntry(this.path, -1);
+    }
+
+}


Property changes on: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/DeleteEntry.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Deleted: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/MergeFile.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/MergeFile.java	2009-12-31 13:45:57 UTC (rev 1500)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/MergeFile.java	2009-12-31 13:46:43 UTC (rev 1501)
@@ -1,64 +0,0 @@
-/*
- * JBoss DNA (http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership.  Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of 
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- * 
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.connector.svn.mgnt;
-
-import java.io.ByteArrayInputStream;
-import org.jboss.dna.connector.scm.ScmAction;
-import org.tmatesoft.svn.core.io.ISVNEditor;
-import org.tmatesoft.svn.core.io.diff.SVNDeltaGenerator;
-
-public class MergeFile implements ScmAction {
-    private String path;
-    private String file;
-    private byte[] oldData;
-    private byte[] newData;
-
-    public MergeFile( String path,
-                      String file,
-                      byte[] oldData,
-                      byte[] newData ) {
-        this.path = path;
-        this.file = file;
-        this.oldData = oldData;
-        this.newData = newData;
-    }
-
-    public void applyAction( Object context ) throws Exception {
-        ISVNEditor editor = (ISVNEditor)context;
-        ISVNEditorUtil.openDirectories(editor, this.path);
-        
-        editor.openFile(this.path + "/" + this.file, -1);        
-        editor.applyTextDelta(this.path + "/" + this.file, null);
-        SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();
-        String checksum = deltaGenerator.sendDelta(this.path + "/" + this.file,
-                                                   new ByteArrayInputStream(this.oldData),
-                                                   0,
-                                                   new ByteArrayInputStream(this.newData),
-                                                   editor,
-                                                   true);
-        editor.closeFile(this.path + "/" + this.file, checksum);
-        ISVNEditorUtil.closeDirectories(editor, path);
-    }
-
-}
\ No newline at end of file

Copied: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/UpdateFile.java (from rev 1494, trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/MergeFile.java)
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/UpdateFile.java	                        (rev 0)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/UpdateFile.java	2009-12-31 13:46:43 UTC (rev 1501)
@@ -0,0 +1,64 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of 
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.connector.svn.mgnt;
+
+import java.io.ByteArrayInputStream;
+import org.jboss.dna.connector.scm.ScmAction;
+import org.tmatesoft.svn.core.io.ISVNEditor;
+import org.tmatesoft.svn.core.io.diff.SVNDeltaGenerator;
+
+public class UpdateFile implements ScmAction {
+    private String path;
+    private String file;
+    private byte[] oldData;
+    private byte[] newData;
+
+    public UpdateFile( String path,
+                      String file,
+                      byte[] oldData,
+                      byte[] newData ) {
+        this.path = path;
+        this.file = file;
+        this.oldData = oldData;
+        this.newData = newData;
+    }
+
+    public void applyAction( Object context ) throws Exception {
+        ISVNEditor editor = (ISVNEditor)context;
+        ISVNEditorUtil.openDirectories(editor, this.path);
+        
+        editor.openFile(this.path + "/" + this.file, -1);        
+        editor.applyTextDelta(this.path + "/" + this.file, null);
+        SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();
+        String checksum = deltaGenerator.sendDelta(this.path + "/" + this.file,
+                                                   new ByteArrayInputStream(this.oldData),
+                                                   0,
+                                                   new ByteArrayInputStream(this.newData),
+                                                   editor,
+                                                   true);
+        editor.closeFile(this.path + "/" + this.file, checksum);
+        ISVNEditorUtil.closeDirectories(editor, path);
+    }
+
+}
\ No newline at end of file



More information about the dna-commits mailing list