greenstone.org greenstone wiki greenstone trac planet greenstone

Changeset 17984

Show
Ignore:
Timestamp:
2008-11-29 21:56:11 (1 month ago)
Author:
oranfry
Message:

reverted to the old way of finding the running jar (as the new way did not work for the mac installer) but improved the url decoding function to properly decode UTF-8 encoded characters

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • release-kits/shared/ant-installer/src/org/tp23/antinstaller/selfextract/SelfExtractor.java

    r17897 r17984  
    2525import java.io.IOException; 
    2626import java.net.URL; 
     27import java.net.URLDecoder; 
    2728import java.util.ArrayList; 
    2829import java.util.jar.JarEntry; 
     
    7374                //String fileForm = jarUrl.getFile(); 
    7475 
    75  
    76 /* 
    77                 File file = new File( fileForm ); 
    78                 if ( !file.exists() ) { 
    79                         throw new RuntimeException( "Failed expanding Jar.\n File: '" + file.getAbsolutePath() + "'\nString: '" + stringForm + "'" ); 
    80                 } 
    81                 return file; 
    82 */ 
    83  
    8476                File file = null; 
    8577                int endIdx = stringForm.indexOf("!/"); 
    86                 if( endIdx == -1 ) { 
    87                         throw new RuntimeException("Failed expanding Jar."); 
    88                 } 
    89                 String unescaped = null; 
    90                 String fileNamePart = stringForm.substring("jar:file:".length(), endIdx); 
    91                 file = new File(fileNamePart); 
    92                 file = new File( file.getName() ); 
    93  
    94 /* 
    95                 if ( !file.exists()) { 
    96                         // try to unescape encase the URL Handler has escaped the " " to %20 
    97                         unescaped = unescape(fileNamePart); 
    98                         file = new File(unescaped); 
    99                 } 
    100 */ 
    101                 return file; 
    102  
     78                if(endIdx != -1){ 
     79                        String unescaped = null; 
     80                        String fileNamePart = stringForm.substring("jar:file:".length(), endIdx); 
     81                        file = new File(fileNamePart); 
     82                        if ( ! file.exists()) { 
     83                                // try to unescape encase the URL Handler has escaped the " " to %20 
     84                                unescaped = unescape(fileNamePart); 
     85                                file = new File(unescaped); 
     86                        } 
     87                        return file; 
     88                } 
     89                throw new RuntimeException("Failed expanding Jar."); 
    10390        } 
    10491 
     
    465452         */ 
    466453        private static String unescape(final String s) { 
    467                 StringBuffer sb = new StringBuffer(s.length()); 
    468  
    469                 for (int i = 0; i < s.length(); i++) { 
    470                         char c = s.charAt(i); 
    471                         switch (c) { 
    472                                 case '%': { 
    473                                         try { 
    474                                                 sb.append( (char) Integer.parseInt(s.substring(i + 1, i + 3), 16)); 
    475                                                 i += 2; 
    476                                                 break; 
    477                                         } 
    478                                         catch (NumberFormatException nfe) { 
    479                                                 throw new IllegalArgumentException(); 
    480                                         } 
    481                                         catch (StringIndexOutOfBoundsException siob) { 
    482                                                 String end = s.substring(i); 
    483                                                 sb.append(end); 
    484                                                 if (end.length() == 2) i++; 
    485                                         } 
    486                                         break; 
    487                                 } 
    488                                 default: { 
    489                                         sb.append(c); 
    490                                         break; 
    491                                 } 
    492                         } 
    493                 } 
    494                 return sb.toString(); 
     454 
     455                URLDecoder ud = new URLDecoder(); 
     456 
     457                String decoded = null; 
     458 
     459                try { 
     460                        decoded = ud.decode( s, "UTF-8" ); 
     461                } catch ( java.io.UnsupportedEncodingException uee ) { 
     462                        System.err.println( "unsupported encoding" ); 
     463                        return s; 
     464                } 
     465                return decoded; 
    495466        } 
    496467