Author: keith
Date: Fri Apr  4 08:35:19 2008
New Revision: 15578

Log:

Fixing the sharing part for Mashup-644. Need to add a control to the UI now.



Modified:
   
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupArchiveManupulator.java

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupArchiveManupulator.java
==============================================================================
--- 
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupArchiveManupulator.java
      (original)
+++ 
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupArchiveManupulator.java
      Fri Apr  4 08:35:19 2008
@@ -25,6 +25,7 @@
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.deployment.DescriptionBuilder;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.description.WSDL2Constants;
@@ -35,14 +36,19 @@
 import org.wso2.javascript.rhino.JavaScriptEngineConstants;
 import org.wso2.mashup.MashupConstants;
 import org.wso2.mashup.MashupFault;
+import org.wso2.registry.RegistryConstants;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.Tag;
+import org.wso2.registry.jdbc.JDBCRegistry;
 import org.wso2.utils.ArchiveManipulator;
-import org.wso2.wsas.ServerConstants;
 import org.wso2.ws.dataservice.DBConstants;
+import org.wso2.wsas.ServerConstants;
 
 import javax.activation.DataHandler;
 import javax.activation.DataSource;
 import javax.activation.FileDataSource;
 import javax.xml.namespace.QName;
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -130,6 +136,40 @@
             serviceResourceFolder = (File) 
serviceResourceFolderParameter.getValue();
         }
 
+        Parameter myRegistryPath =
+                        
mashupService.getParameter(MashupConstants.REGISTRY_MASHUP_PATH);
+        ByteArrayInputStream byteArrayInputStream = null;
+        if (myRegistryPath != null) {
+            String mashupPath = (String) myRegistryPath.getValue();
+            JDBCRegistry registry =
+                    (JDBCRegistry) 
configCtx.getAxisConfiguration().getParameterValue(
+                            RegistryConstants.REGISTRY);
+            // Check weather there any any tags associated with this mashup.
+            // If so we need to pack them into the zip too. The following is a 
sample tags file
+            // <tags>
+            //      <tag>test</tag>
+            //      <tag>fun</tag>
+            // </tags>
+            try {
+                Tag[] tags = registry.getTags(mashupPath);
+                if (tags != null && tags.length > 0) {
+                    String tagString = "<tags>";
+                    for (int i = 0; i < tags.length; i++) {
+                        Tag tag = tags[i];
+                        tagString = tagString + "<tag>" + tag.getTagName() + 
"</tag>";
+                    }
+                    tagString = tagString + "</tags>";
+                    byteArrayInputStream = new 
ByteArrayInputStream(tagString.getBytes());
+                }
+            } catch (RegistryException e) {
+                throw new MashupFault(
+                        "Error occured while retrieving tags of Mashup " + 
mashupService, e);
+            }
+        }
+
+
+
+
         if (serviceFile != null && serviceResourceFolder != null) {
             try {
                 // Creating a FileDataSource
@@ -137,7 +177,7 @@
                 // write the service js file & the contents of the
                 // service.resources folder to the outstream of the data source
 
-                createMashupArchive(zos, serviceFile, serviceResourceFolder);
+                createMashupArchive(zos, serviceFile, serviceResourceFolder, 
byteArrayInputStream);
                 return;
             } catch (IOException e) {
                 throw new MashupFault(e);
@@ -282,7 +322,7 @@
      * @throws IOException           - Thrown in case the js file cannot be 
read
      * @throws java.io.FileNotFoundException - Thrown in case the js file 
cannot be found
      */
-    private void createMashupArchive(ZipOutputStream zos, File jsFile, File 
resourcesDir)
+    private void createMashupArchive(ZipOutputStream zos, File jsFile, File 
resourcesDir, ByteArrayInputStream byteArrayInputStream)
             throws IOException {
         if (!resourcesDir.isDirectory()) {
             throw new MashupFault(resourcesDir.getPath() + " is not a 
directory");
@@ -303,6 +343,21 @@
         // close the Stream
         fis.close();
 
+        // We are adding in the tags file here
+        if (byteArrayInputStream != null) {
+            String shortFileName = 
DescriptionBuilder.getShortFileName(jsFile.getName());
+            File tagsFile = new File(resourcesDir.getParentFile(), 
shortFileName + MashupConstants.TAGS_File);
+            zos.putNextEntry(new ZipEntry(getZipEntryPath(tagsFile)));
+            // now write the content of the file to the ZipOutputStream
+            readBuffer = new byte[40960];
+            bytesIn = 0;
+            while ((bytesIn = byteArrayInputStream.read(readBuffer)) != -1) {
+                zos.write(readBuffer, 0, bytesIn);
+            }
+            // close the Stream
+            byteArrayInputStream.close();
+        }
+
         zipDir(resourcesDir, zos);
         zos.close();
     }

_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev

Reply via email to