[Title] common-eplugin: fixed prevent issues
authorJihoon Song <jihoon80.song@samsung.com>
Wed, 4 Sep 2013 08:13:08 +0000 (17:13 +0900)
committerJihoon Song <jihoon80.song@samsung.com>
Fri, 6 Sep 2013 07:02:17 +0000 (16:02 +0900)
[Desc.]
[Issue]

Change-Id: I9ec3385a33abb118734871f4820fafb6ded6a8c6

org.tizen.common.sign/src/org/tizen/common/sign/command/SignCommand.java
org.tizen.common/src/org/tizen/common/core/command/zip/ZipCommand.java
org.tizen.common/src/org/tizen/common/ui/widget/PictureLabel.java
org.tizen.common/src/org/tizen/common/util/CipherUtil.java
org.tizen.common/src/org/tizen/common/util/EFSUtil.java
org.tizen.common/src/org/tizen/common/util/FreeMarkerUtil.java
org.tizen.common/src/org/tizen/common/util/ZipUtil.java

index 39ce1a2..684d647 100755 (executable)
@@ -70,7 +70,10 @@ public class SignCommand extends FileHandlingCommand<Object> {
             final Policy policy = context.getPolicy( Policy.NONEXIST_IN_PROJECT );
             final MessagePolicy messagePolicy = policy.adapt( MessagePolicy.class );
             
-            messagePolicy.print( context.getPrompter(), "{0} doesn't exist", this.path );
+            if ( messagePolicy != null ) {
+                messagePolicy.print( context.getPrompter(), "{0} doesn't exist", this.path );
+            }
+            
             return ;
         }
         
index 497137b..58f6fbd 100755 (executable)
@@ -125,22 +125,31 @@ extends FileHandlingCommand<Object>
         if ( !handler.is( baseDir, Attribute.EXISTS ) )
         {
             final Policy policy = context.getPolicy( NONEXIST_IN_DIRECTORY );
-
+            if ( policy == null ) {
+                throw new IllegalStateException( "Could not find a policy : " + NONEXIST_IN_DIRECTORY );
+            }
+            
             final MessagePolicy messagePolicy = policy.adapt( MessagePolicy.class );
-
-            messagePolicy.print( context.getPrompter(), "{0} doesn't exist.", baseDir );
+            if ( messagePolicy != null ) {
+                messagePolicy.print( context.getPrompter(), "{0} doesn't exist.", baseDir );
+            }
+            
             return ;
         }
 
         if ( handler.is( path, Attribute.EXISTS ) )
         {
             final Policy policy = context.getPolicy( EXIST_OUT_WGT );
-
+            if ( policy == null ) {
+                throw new IllegalStateException( "Could not find a policy : " + EXIST_OUT_WGT );
+            }
+            
             final MessagePolicy messagePolicy = policy.adapt( MessagePolicy.class );
-            messagePolicy.print( context.getPrompter(), "Widget already exist." );
-
+            if ( messagePolicy != null ) {
+                messagePolicy.print( context.getPrompter(), "Widget already exist." );
+            }
             final FilePolicy filePolicy = policy.adapt( FilePolicy.class );
-
+            
             if ( FilePolicy.OVERWRITE.equals( filePolicy ) )
             {
                 logger.debug( "No operation" );
@@ -149,7 +158,6 @@ extends FileHandlingCommand<Object>
             {  // It is default to stop process
                 return ;
             }
-
         }
 
         final ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
index a5cf09b..241074b 100755 (executable)
@@ -122,12 +122,12 @@ public class PictureLabel extends Canvas {
                int x = 1;\r
                int y = 1;\r
                int clientAreaWidth = getClientArea().width;\r
-               int textWidth = gc.stringExtent(text).x;\r
                int imageWidth = image.getBounds().width;\r
                int imageHeght = image.getBounds().height;\r
                int maxWidth = Math.max(Math.max(imageWidth, imageWidth), clientAreaWidth);\r
 \r
                if ((image != null) & (text != null)) {\r
+                   int textWidth = gc.stringExtent(text).x;\r
                        x = 1 + (maxWidth - imageWidth) / 2;\r
                        gc.drawImage(image, x, y);\r
                        y = y + imageHeght + 5;\r
@@ -137,6 +137,7 @@ public class PictureLabel extends Canvas {
                        x = 1 + (maxWidth - imageWidth) / 2;\r
                        gc.drawImage(image, x, 1);\r
                } else if (text != null) {\r
+                   int textWidth = gc.stringExtent(text).x;\r
                        x = 1 + (maxWidth - textWidth) / 2;\r
                        gc.drawText(text, x, 1);\r
                }\r
index e35a1d1..1a1e6f2 100755 (executable)
@@ -119,6 +119,11 @@ public class CipherUtil {
      */
     public static String getEncryptedString(String s)
     throws InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
-        return new String(Base64.encode(encryptByDES(s)));
+        String encoded = Base64.encode( encryptByDES( s ) );
+        if ( encoded == null ) {
+            return s;
+        }
+        
+        return encoded;
     }
 }
index 47d33ea..2c9b7b7 100755 (executable)
@@ -36,6 +36,7 @@ import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.OperationCanceledException;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils;
 import org.eclipse.ui.internal.ide.dialogs.IFileStoreFilter;
 import org.tizen.common.Surrogate;
@@ -268,8 +269,14 @@ public class EFSUtil {
         Assert.notNull(source);
         Assert.notNull(destination);
         
+        
+        IWorkbenchWindow window = ViewUtil.getWorkbenchWindow();
+        if ( window == null ) {
+            throw new OperationCanceledException( "Could not find a window" );
+        }
+        
         previousChoice = isExistResourceWithDialog(
-                ViewUtil.getWorkbenchWindow().getShell(), Messages.FileExistDialogTitle,
+                window.getShell(), Messages.FileExistDialogTitle,
                 Messages.bind( Messages.FileExistMsg, destination.getName() ),
                 previousChoice, destination);
         
index b43d60f..547729e 100644 (file)
@@ -30,6 +30,7 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
@@ -132,7 +133,13 @@ public class FreeMarkerUtil {
      */
     public static void generateDocument(Map<String, Object> root, Configuration cfg, String templateFile, File destinationFile)
             throws IOException, TemplateException {
-        generateDocument(root, cfg, templateFile, new FileOutputStream( destinationFile ));
+        OutputStream out = null;
+        try {
+            out = new FileOutputStream( destinationFile );
+            generateDocument(root, cfg, templateFile, out );
+        } finally {
+            IOUtil.tryClose( out );
+        }
     }
     
     /**
@@ -147,7 +154,15 @@ public class FreeMarkerUtil {
      */
     public static void generateDocument(Map<String, Object> root, Configuration cfg, String templateFile, OutputStream outputStream)
             throws IOException, TemplateException {
-        generateDocument(root, cfg, templateFile, new BufferedWriter( new OutputStreamWriter( outputStream ) ));
+        
+        Writer writer = null;
+        try {
+            writer = new OutputStreamWriter( outputStream );
+            writer = new BufferedWriter( writer );
+            generateDocument( root, cfg, templateFile, writer );
+        } finally {
+            IOUtil.tryClose( writer );
+        }
     }
     
     /**
@@ -170,11 +185,7 @@ public class FreeMarkerUtil {
         Template template = cfg.getTemplate(templateFile);
         
         // generate document
-        try {
-            template.process(root, writer);
-            IOUtil.tryFlush(writer);
-        } finally {
-            IOUtil.tryClose(writer);
-        }
+        template.process(root, writer);
+        IOUtil.tryFlush(writer);
     }
 }
index 4e0cc7c..43149c6 100644 (file)
@@ -62,12 +62,18 @@ public class ZipUtil {
         }
 
         ZipFile zipfile = new ZipFile( fullpath );
-        ZipEntry entry = zipfile.getEntry( name );
-        if ( entry == null ) {
-            return null;
+        try {
+            ZipEntry entry = zipfile.getEntry( name );
+            if ( entry == null ) {
+                return null;
+            }
+            
+            InputStream in = zipfile.getInputStream( entry );
+            return IOUtil.getString( in, true );
+        } finally {
+            if ( zipfile != null ) {
+                zipfile.close();
+            }
         }
-
-        InputStream in = zipfile.getInputStream( entry );
-        return IOUtil.getString( in, true );
     }
 }