Skip to content
Browse files

support zipped repository files

  • Loading branch information...
1 parent 97aba9e commit c0edff9a578ce6d59e92f49abaec9e7204ba084b BooVeMan committed Jul 20, 2011
View
27 guvnor-webapp/src/main/java/org/drools/guvnor/server/files/RepositoryBackupServlet.java
@@ -20,6 +20,7 @@
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import javax.jcr.PathNotFoundException;
@@ -28,6 +29,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.drools.RuntimeDroolsException;
import org.drools.guvnor.server.util.FormData;
import org.drools.guvnor.server.util.LoggingHelper;
@@ -65,18 +67,25 @@ public void execute() throws Exception {
String packageImport = request.getParameter( "packageImport" );
+ InputStream inputFileStream = null;
+ if(uploadItem.getFile()!= null && uploadItem.getFile().getContentType().indexOf("zip")>=0) {
+ ZipInputStream zipInputStream = new ZipInputStream(uploadItem.getFile().getInputStream());
+ ZipEntry zipEntry = zipInputStream.getNextEntry();
+ if(zipEntry != null){
+ inputFileStream = zipInputStream;
+ } else {
+ new RuntimeDroolsException("Invalid compressed reporitory");
+ }
+ } else {
+ inputFileStream = uploadItem.getFile().getInputStream();
+ }
if ( "true".equals( packageImport ) ) {
- boolean importAsNew = "true".equals( request
- .getParameter( "importAsNew" ) );
-
- response.getWriter().write(
- processImportPackage( uploadItem.getFile().getInputStream(),
- importAsNew ) );
+ boolean importAsNew = "true".equals( request.getParameter( "importAsNew" ) );
+ response.getWriter().write( processImportPackage( inputFileStream, importAsNew ) );
} else {
- response.getWriter().write(
- processImportRepository( uploadItem.getFile()
- .getInputStream() ) );
+ response.getWriter().write( processImportRepository( inputFileStream ) );
}
+ inputFileStream.close();
}
}
} );

0 comments on commit c0edff9

Please sign in to comment.
Something went wrong with that request. Please try again.