continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r453278 - in /maven/continuum/trunk/continuum-webapp/src/main: java/org/apache/maven/continuum/web/action/WorkingCopyAction.java resources/xwork.xml
Date Thu, 05 Oct 2006 16:08:58 GMT
Author: evenisse
Date: Thu Oct  5 09:08:57 2006
New Revision: 453278

URL: http://svn.apache.org/viewvc?view=rev&rev=453278
Log:
[CONTINUUM-953] Allow to download some type of file

Modified:
    maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/WorkingCopyAction.java
    maven/continuum/trunk/continuum-webapp/src/main/resources/xwork.xml

Modified: maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/WorkingCopyAction.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/WorkingCopyAction.java?view=diff&rev=453278&r1=453277&r2=453278
==============================================================================
--- maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/WorkingCopyAction.java
(original)
+++ maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/WorkingCopyAction.java
Thu Oct  5 09:08:57 2006
@@ -22,8 +22,13 @@
 import com.opensymphony.webwork.ServletActionContext;
 import com.opensymphony.webwork.views.util.UrlHelper;
 
+import javax.activation.MimetypesFileTypeMap;
 import java.util.HashMap;
 import java.util.List;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileInputStream;
+import java.io.InputStream;
 
 /**
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
@@ -55,6 +60,12 @@
 
     private String projectName;
 
+    private File downloadFile;
+
+    private String mimeType = "application/octet-stream";
+
+    private static String FILE_SEPARATOR = System.getProperty( "file.separator" );
+
     public String execute()
         throws ContinuumException
     {
@@ -74,6 +85,34 @@
 
         if ( currentFile != null && currentFile != "" )
         {
+            String dir;
+
+            //TODO: maybe create a plexus component for this so that additional mimetypes
can be easily added
+            MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
+            mimeTypesMap.addMimeTypes( "application/java-archive jar war ear");
+            mimeTypesMap.addMimeTypes( "application/java-class class" );
+            mimeTypesMap.addMimeTypes( "image/png png" );
+
+            if ( FILE_SEPARATOR.equals( userDirectory ) )
+            {
+                dir = userDirectory;
+            }
+            else
+            {
+                dir = FILE_SEPARATOR + userDirectory + FILE_SEPARATOR;
+            }
+
+            downloadFile = new File( getContinuum().getWorkingDirectory( projectId ) + dir
+ currentFile );
+            mimeType = mimeTypesMap.getContentType( downloadFile );
+            
+            if ( ( mimeType.contains( "image" ) ) ||
+                 ( mimeType.contains( "java-archive" ) ) ||
+                 ( mimeType.contains( "java-class" ) ) ||
+                 ( downloadFile.length() > 100000 ) )
+            {
+                return "stream";
+            }
+
             currentFileContent = getContinuum().getFileContent( projectId, userDirectory,
currentFile );
         }
         else
@@ -127,5 +166,37 @@
     public String getFileContent()
     {
         return currentFileContent;
+    }
+
+
+    public InputStream getInputStream()
+        throws ContinuumException
+    {
+        FileInputStream fis = null;
+        try
+        {
+            fis = new FileInputStream( downloadFile );
+        }
+        catch ( FileNotFoundException fne )
+        {
+            throw new ContinuumException( "Error accessing file.", fne );
+        }
+
+        return fis;
+    }
+
+    public String getFileLength()
+    {
+        return Long.toString( downloadFile.length() );
+    }
+
+    public String getDownloadFilename()
+    {
+        return downloadFile.getName();
+    }
+
+    public String getMimeType()
+    {
+        return this.mimeType;
     }
 }

Modified: maven/continuum/trunk/continuum-webapp/src/main/resources/xwork.xml
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-webapp/src/main/resources/xwork.xml?view=diff&rev=453278&r1=453277&r2=453278
==============================================================================
--- maven/continuum/trunk/continuum-webapp/src/main/resources/xwork.xml (original)
+++ maven/continuum/trunk/continuum-webapp/src/main/resources/xwork.xml Thu Oct  5 09:08:57
2006
@@ -286,6 +286,11 @@
 
     <action name="workingCopy" class="workingCopy">
       <result name="success">/workingCopy.jsp</result>
+      <result name="stream" type="stream">
+        <param name="contentType">application/octet-stream</param>
+        <param name="contentDisposition">filename="${downloadFilename}"</param>
+        <param name="contentLength">${fileLength}</param>
+      </result>
     </action>
 
     <!--



Mime
View raw message