]> source.dussan.org Git - archiva.git/commitdiff
clean up method calling
authorBrett Porter <brett@apache.org>
Thu, 19 Mar 2009 13:48:54 +0000 (13:48 +0000)
committerBrett Porter <brett@apache.org>
Thu, 19 Mar 2009 13:48:54 +0000 (13:48 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@755995 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java

index 96effbba6edbbe4e9a85fbdc2c80d5c6df5dbae5..71e89c4d973e553e668f9aa73dad46c9c096b77d 100644 (file)
@@ -199,8 +199,8 @@ public class ArchivaDavResourceFactory
             else
             {
                 resource =
-                    processRepositoryGroup( locator, request, archivaLocator, repoGroupConfig.getRepositories(),
-                                            activePrincipal, readMethod, resourcesInAbsolutePath );
+                    processRepositoryGroup( request, archivaLocator, repoGroupConfig.getRepositories(),
+                                            activePrincipal, resourcesInAbsolutePath );
             }
         }
         else
@@ -221,12 +221,10 @@ public class ArchivaDavResourceFactory
                 throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
             }
 
-            resource =
-                processRepository( locator, request, archivaLocator, readMethod, activePrincipal,
-                                   archivaLocator.getRepositoryId(), managedRepository );
+            resource = processRepository( request, archivaLocator, activePrincipal, managedRepository );
 
             String logicalResource = RepositoryPathUtil.getLogicalResource( locator.getResourcePath() );
-            resourcesInAbsolutePath.add( managedRepository.getRepoRoot() + logicalResource );
+            resourcesInAbsolutePath.add( new File( managedRepository.getRepoRoot(), logicalResource ).getAbsolutePath() );
         }
 
         String requestedResource = request.getRequestURI();
@@ -329,10 +327,9 @@ public class ArchivaDavResourceFactory
         return resource;
     }
 
-    private DavResource processRepositoryGroup( final DavResourceLocator locator, final DavServletRequest request,
+    private DavResource processRepositoryGroup( final DavServletRequest request,
                                                 ArchivaDavResourceLocator archivaLocator, List<String> repositories,
-                                                String activePrincipal, boolean readMethod,
-                                                List<String> resourcesInAbsolutePath )
+                                                String activePrincipal, List<String> resourcesInAbsolutePath )
         throws DavException
     {
         DavResource resource = null;
@@ -357,16 +354,15 @@ public class ArchivaDavResourceFactory
 
             try
             {
-                DavResource resource1 =
-                    processRepository( locator, request, archivaLocator, readMethod, activePrincipal, repositoryId,
-                                       managedRepository );
+                DavResource updatedResource =
+                    processRepository( request, archivaLocator, activePrincipal, managedRepository );
                 if ( resource == null )
                 {
-                    resource = resource1;
+                    resource = updatedResource;
                 }
 
-                String logicalResource = RepositoryPathUtil.getLogicalResource( locator.getResourcePath() );
-                resourcesInAbsolutePath.add( managedRepository.getRepoRoot() + logicalResource );
+                String logicalResource = RepositoryPathUtil.getLogicalResource( archivaLocator.getResourcePath() );
+                resourcesInAbsolutePath.add( new File( managedRepository.getRepoRoot(), logicalResource ).getAbsolutePath() );
             }
             catch ( DavException e )
             {
@@ -388,17 +384,15 @@ public class ArchivaDavResourceFactory
         return resource;
     }
 
-    private DavResource processRepository( final DavResourceLocator locator, final DavServletRequest request,
-                                           ArchivaDavResourceLocator archivaLocator, boolean readMethod,
-                                           String activePrincipal, String repositoryId,
-                                           ManagedRepositoryContent managedRepository )
+    private DavResource processRepository( final DavServletRequest request, ArchivaDavResourceLocator archivaLocator,
+                                           String activePrincipal, ManagedRepositoryContent managedRepository )
         throws DavException
     {
         DavResource resource = null;
-        if ( isAuthorized( request, repositoryId ) )
+        if ( isAuthorized( request, managedRepository.getId() ) )
         {
             LogicalResource logicalResource =
-                new LogicalResource( RepositoryPathUtil.getLogicalResource( locator.getResourcePath() ) );
+                new LogicalResource( RepositoryPathUtil.getLogicalResource( archivaLocator.getResourcePath() ) );
 
             File resourceFile = new File( managedRepository.getRepoRoot(), logicalResource.getPath() );
             resource =
@@ -407,7 +401,7 @@ public class ArchivaDavResourceFactory
                                         request.getDavSession(), archivaLocator, this, mimeTypes, auditListeners,
                                         consumers );
 
-            if ( readMethod )
+            if ( WebdavMethodUtil.isReadMethod( request.getMethod() ) )
             {
                 if ( archivaLocator.getHref( false ).endsWith( "/" ) && !resourceFile.isDirectory() )
                 {
@@ -438,22 +432,21 @@ public class ArchivaDavResourceFactory
                                                         activePrincipal, request.getDavSession(), archivaLocator, this,
                                                         mimeTypes, auditListeners, consumers );
                         }
-                        catch ( LayoutException e1 )
+                        catch ( LayoutException e )
                         {
                             if ( !resourceFile.exists() )
                             {
-                                throw new DavException( HttpServletResponse.SC_NOT_FOUND, e1 );
+                                throw new DavException( HttpServletResponse.SC_NOT_FOUND, e );
                             }
                         }
 
                         if ( fromProxy )
                         {
-                            String repositoryId1 = archivaLocator.getRepositoryId();
                             String event =
                                 ( previouslyExisted ? AuditEvent.MODIFY_FILE : AuditEvent.CREATE_FILE )
                                     + PROXIED_SUFFIX;
-                            triggerAuditEvent( request.getRemoteAddr(), repositoryId1, logicalResource.getPath(),
-                                               event, activePrincipal );
+                            triggerAuditEvent( request.getRemoteAddr(), archivaLocator.getRepositoryId(),
+                                               logicalResource.getPath(), event, activePrincipal );
                         }
 
                         if ( !resourceFile.exists() )
@@ -522,24 +515,25 @@ public class ArchivaDavResourceFactory
                                              LogicalResource resource )
         throws DavException
     {
-        if ( repositoryRequest.isSupportFile( resource.getPath() ) )
+        String path = resource.getPath();
+        if ( repositoryRequest.isSupportFile( path ) )
         {
-            File proxiedFile = connectors.fetchFromProxies( managedRepository, resource.getPath() );
+            File proxiedFile = connectors.fetchFromProxies( managedRepository, path );
 
             return ( proxiedFile != null );
         }
 
         // Is it a Metadata resource?
-        if ( repositoryRequest.isDefault( resource.getPath() ) && repositoryRequest.isMetadata( resource.getPath() ) )
+        if ( repositoryRequest.isDefault( path ) && repositoryRequest.isMetadata( path ) )
         {
-            return connectors.fetchMetatadaFromProxies( managedRepository, resource.getPath() ) != null;
+            return connectors.fetchMetatadaFromProxies( managedRepository, path ) != null;
         }
 
         // Not any of the above? Then it's gotta be an artifact reference.
         try
         {
             // Get the artifact reference in a layout neutral way.
-            ArtifactReference artifact = repositoryRequest.toArtifactReference( resource.getPath() );
+            ArtifactReference artifact = repositoryRequest.toArtifactReference( path );
 
             if ( artifact != null )
             {