Author: paperwing
Date: 2012-11-26 16:05:49 -0800 (Mon, 26 Nov 2012)
New Revision: 30843

Modified:
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/BundleApp.java
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/WebQuerier.java
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/CheckForUpdatesPanel.java
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/CurrentlyInstalledAppsPanel.java
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/InstallAppsPanel.java
   
core3/impl/trunk/app-impl/src/test/java/org/cytoscape/app/internal/net/WebQuerierTest.java
Log:
refs #1610 WebQuerier in WebQuerier.java now prevents disallowed characters in 
app download filename causing errors in install.

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/BundleApp.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/BundleApp.java
   2012-11-26 23:59:00 UTC (rev 30842)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/BundleApp.java
   2012-11-27 00:05:49 UTC (rev 30843)
@@ -13,8 +13,34 @@
 import org.cytoscape.app.swing.CySwingAppAdapter;
 
 public class BundleApp extends App {
-
+       
+       /*
        @Override
+       public String getReadableStatus() {
+               switch (this.getStatus()) {
+               
+               case DISABLED:
+                       if (this.getAppInstance() != null) {
+                               return "Disable on Restart";
+                       } else {
+                               return "Disabled";
+                       }
+               case UNINSTALLED:
+                       if (this.getAppInstance() != null) {
+                               return "Uninstall on Restart";
+                       } else {
+                               return "Uninstalled";
+                       }
+               case FILE_MOVED:
+                       return "File Moved (Needs restart to uninstall)";
+               default:
+                       return super.getReadableStatus();
+               
+               }
+       }
+       */
+       
+       @Override
        public Object createAppInstance(CySwingAppAdapter appAdapter)
                        throws AppInstanceException {
                return null;

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/WebQuerier.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/WebQuerier.java
      2012-11-26 23:59:00 UTC (rev 30842)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/WebQuerier.java
      2012-11-27 00:05:49 UTC (rev 30843)
@@ -101,6 +101,8 @@
 
        private static final Pattern VERSION_PATTERN = 
Pattern.compile("(\\d+)([.](\\d+)([.](\\d+)([.]([-_a-zA-Z0-9]+))?)?)?");
        
+       public static final Pattern OUTPUT_FILENAME_DISALLOWED_CHARACTERS = 
Pattern.compile("[^a-zA-Z0-9.-]");
+       
        /**
         * A class that represents a tag used for apps, containing information 
about the tag
         * such as its unique name used on the app store website as well as its 
human-readable name.
@@ -508,11 +510,21 @@
                                        InputStream inputStream = 
connection.getInputStream();
                                        long contentLength = 
connection.getContentLength();
                                        ReadableByteChannel readableByteChannel 
= Channels.newChannel(inputStream);
+                                       
                                        File outputFile;
                                        try {
-                                               // Output file has same name as 
app, but spaces are replaced with hyphens
+                                               // Replace spaces with 
underscores
+                                               String outputFileBasename = 
webApp.getName().replaceAll("\\s", "_");
+                                               
+                                               // Strip disallowed characters
+                                               outputFileBasename = 
OUTPUT_FILENAME_DISALLOWED_CHARACTERS.matcher(outputFileBasename).replaceAll("");
+                                               
+                                               // Append extension
+                                               outputFileBasename += ".jar";
+                                               
+                                               // Output file has same name as 
app, but spaces and slashes are replaced with hyphens
                                                outputFile = new 
File(directory.getCanonicalPath() + File.separator 
-                                                               + 
webApp.getName().replaceAll("\\s", "-") + ".jar");
+                                                               + 
outputFileBasename);
                                                
                                                if (outputFile.exists()) {
                                                        outputFile.delete();
@@ -520,6 +532,8 @@
                                                
                                                outputFile.createNewFile();
                                                
+//                                             System.out.println("preparing 
to download");
+                                               
                                            FileOutputStream fileOutputStream = 
new FileOutputStream(outputFile);
                                            try {
                                                    FileChannel fileChannel = 
fileOutputStream.getChannel();
@@ -549,7 +563,7 @@
                                    return outputFile;
                                } catch (IOException e) {
                                        throw new AppDownloadException("Error 
while downloading app " + webApp.getFullName()
-                                                       + ": " + 
e.getMessage());
+                                                       + ", " + 
e.getMessage());
                                }
                        }
                } else {

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/CheckForUpdatesPanel.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/CheckForUpdatesPanel.java
     2012-11-26 23:59:00 UTC (rev 30842)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/CheckForUpdatesPanel.java
     2012-11-27 00:05:49 UTC (rev 30843)
@@ -128,6 +128,8 @@
         descriptionLabel.setText("Update Description:");
 
         descriptionTextArea.setEditable(false);
+        descriptionTextArea.setLineWrap(true);
+        descriptionTextArea.setWrapStyleWord(true);
         descriptionTextArea.setFocusable(false);
         descriptionScrollPane.setViewportView(descriptionTextArea);
 

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/CurrentlyInstalledAppsPanel.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/CurrentlyInstalledAppsPanel.java
      2012-11-26 23:59:00 UTC (rev 30842)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/CurrentlyInstalledAppsPanel.java
      2012-11-27 00:05:49 UTC (rev 30843)
@@ -121,6 +121,7 @@
 
         descriptionTextArea.setEditable(false);
         descriptionTextArea.setLineWrap(true);
+        descriptionTextArea.setWrapStyleWord(true);
         descriptionTextArea.setFocusable(false);
         descriptionScrollPane.setViewportView(descriptionTextArea);
 
@@ -366,8 +367,6 @@
                        "App description not found." : 
selectedApp.getDescription();
                descriptionTextArea.setText(text);
                
-               
-               
                // Enable/disable the appropriate button
                if (selectedApp.getStatus() == AppStatus.INSTALLED) {
                        enableSelectedButton.setEnabled(false);

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/InstallAppsPanel.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/InstallAppsPanel.java
 2012-11-26 23:59:00 UTC (rev 30842)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/InstallAppsPanel.java
 2012-11-27 00:05:49 UTC (rev 30843)
@@ -503,10 +503,29 @@
                                for (int index = 0; index < files.length; 
index++) {
                                AppParser appParser = appManager.getAppParser();
                                
-                               App app = null;
+                               App parsedApp = null;
                                
-                               app = appParser.parseApp(files[index]);
-                                               appManager.installApp(app);
+                               parsedApp = appParser.parseApp(files[index]);
+                                               
+                               {
+                                       String parsedAppName = 
parsedApp.getAppName();
+                                       String parsedAppVersion = 
parsedApp.getVersion();
+                                       
+                                       for (App app : appManager.getApps()) {
+       
+                                               // App with same name found, 
check if need to replace existing
+                                               if 
(parsedAppName.equals(app.getAppName())) {
+                                                       
+                                                       /*
+                                                       if 
(WebQuerier.compareVersions(parsedAppVersion, app.getVersion() == 0)) {
+                                                               // TODO: Check 
== version, <= version.
+                                                       }
+                                                       */
+                                               }
+                                       }
+                               }
+                               
+                               appManager.installApp(parsedApp);
                        }
                                
                        taskMonitor.setProgress(1.0);

Modified: 
core3/impl/trunk/app-impl/src/test/java/org/cytoscape/app/internal/net/WebQuerierTest.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/test/java/org/cytoscape/app/internal/net/WebQuerierTest.java
  2012-11-26 23:59:00 UTC (rev 30842)
+++ 
core3/impl/trunk/app-impl/src/test/java/org/cytoscape/app/internal/net/WebQuerierTest.java
  2012-11-27 00:05:49 UTC (rev 30843)
@@ -3,6 +3,8 @@
 import static org.junit.Assert.*;
 import static org.mockito.Mockito.*;
 
+import java.util.regex.Pattern;
+
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -38,6 +40,22 @@
        }
        
        @Test
+       public void testFormatOutputFilename() {
+               
+               Pattern regex = 
WebQuerier.OUTPUT_FILENAME_DISALLOWED_CHARACTERS;
+               
+               assertEquals("test", regex.matcher("test").replaceAll(""));
+               assertEquals("Test", regex.matcher("Test").replaceAll(""));
+               
+               assertEquals("Test123", 
regex.matcher("Test123").replaceAll(""));
+               assertEquals("Test123.123", 
regex.matcher("Test123.123").replaceAll(""));
+               assertEquals("Test", regex.matcher("Test/\\").replaceAll(""));
+               assertEquals("Test", regex.matcher("Test@$(*&").replaceAll(""));
+               assertEquals("Test.2", 
regex.matcher("[email protected]@").replaceAll(""));
+               
+       }
+       
+       @Test
        public void testFail() {
                //assertTrue(false);
        }

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to