Revision 7513

View differences:

branches/v10/frameworks/_fwAndami/src/com/iver/andami/Launcher.java
64 64
import java.net.MalformedURLException;
65 65
import java.net.URL;
66 66
import java.net.URLConnection;
67
import java.security.AllPermission;
68
import java.security.CodeSource;
69
import java.security.PermissionCollection;
70
import java.security.Permissions;
71
import java.security.Policy;
67 72
import java.util.ArrayList;
68 73
import java.util.Comparator;
69 74
import java.util.Date;
......
211 216
		// de plugin services para quien lo quiera usar (por ejemplo, para
212 217
		// cargar un proyecto por l?nea de comandos)
213 218
		PluginServices.setArguments(args);
214
		
219

  
215 220
		configureLocales(args);
216
		
221

  
217 222
		//Se pone el lookAndFeel
218 223
		try {
219 224
			String lookAndFeel = getAndamiConfig().getLookAndFeel();
......
224 229
			logger.warn(Messages.getString("Launcher.look_and_feel"), e);
225 230
		}
226 231

  
232

  
233
		// Solucionamos el problema de permisos que se produc?a con Java Web Start con este c?digo.
234
		// System.setSecurityManager(null);
235
	     Policy.setPolicy(new Policy() {
236
	     public PermissionCollection getPermissions(CodeSource codesource) {
237
	              Permissions perms = new Permissions();
238
	              perms.add(new AllPermission());
239
	              return (perms);
240
	     }
241
	     public void
242
		 	refresh() {}
243
	     });
244

  
245

  
227 246
		// Mostrar la ventana de inicio
228 247
		splashWindow = new SplashWindow(null);
229 248

  
......
1449 1468

  
1450 1469
					if (lastMiliSeconds.longValue() == miliSecondsInWeb.longValue()) {
1451 1470
						System.out.println("No hay nueva actualizaci?n");
1471
                        logger.debug("No hay nueva actualizaci?n -> Return");
1472
                        logger.debug("timeStampWeb= " + miliSecondsInWeb);
1473
                        logger.debug("timeStampLocal= " + lastMiliSeconds);
1452 1474

  
1453 1475
						return;
1454 1476
					}
......
1460 1482
						timeFile.getAbsolutePath());
1461 1483
				}
1462 1484

  
1463
				InputStream stream = connection.getInputStream();
1464
				File temp = File.createTempFile("gvsig", ".zip");
1465
				temp.deleteOnExit();
1485
				InputStream stream = url.openStream();
1486
                File temp = File.createTempFile("gvsig", ".zip");
1466 1487

  
1467
				FileOutputStream file = new FileOutputStream(temp);
1468
				BufferedInputStream in = new BufferedInputStream(stream);
1469
				BufferedOutputStream out = new BufferedOutputStream(file);
1488
                logger.debug(temp.getAbsolutePath());
1470 1489

  
1471
				int i;
1472
				int pct;
1473
				int desde;
1474
				int hasta;
1490
                temp.deleteOnExit();
1491
                FileOutputStream file = new FileOutputStream(temp);
1475 1492

  
1476
				hasta = connection.getContentLength() / 1024;
1477
				desde = 0;
1493
                byte[] lt_read = new byte[1];
1478 1494

  
1479
				while ((i = in.read()) != -1) {
1480
					pct = ((desde / 1024) * 100) / hasta;
1495
                while (stream.read(lt_read) > 0)
1496
                  file.write(lt_read);
1481 1497

  
1482
					if (((desde % 10240) == 0) && (pct > 10) &&
1483
							((pct % 10) == 0)) {
1484
						SplashWindow.process(pct,
1485
							(desde / 1024) + "Kb de " + hasta +
1486
							"Kb descargados...");
1487
					}
1498
                stream.close();
1499
                stream = null;
1500
                file.close();
1501
                file = null;
1488 1502

  
1489
					out.write(i);
1490
					desde++;
1491
				}
1503
                System.gc();
1492 1504

  
1493
				out.flush();
1494
				out.close();
1495
				in.close();
1496

  
1505
                logger.debug("Ha creado el fichero ZIP");
1497 1506
				//Se extrae el zip
1498 1507
				SplashWindow.process(5, "Extensiones descargadas.");
1499 1508

  
......
1906 1915
	 * provided language code (which may be an ISO 839-2/T
1907 1916
	 * three-characters-long code or an ISO 839-1 two-characters-long
1908 1917
	 * code).
1909
	 * 
1918
	 *
1910 1919
	 * If the provided parameter is already two characters long, it
1911 1920
	 * returns the parameter without any modification.
1912
	 * 
1921
	 *
1913 1922
	 * @param langCode A language code representing either
1914 1923
	 *  an ISO 839-2/T language code or an ISO 839-1 code.
1915 1924
	 * @return A two-characters-long code specifying
......
1948 1957
		}
1949 1958
		return "es";
1950 1959
	}
1951
	
1960

  
1952 1961
	/**
1953 1962
	 * Configures the locales (languages and local resources) to be used
1954 1963
	 * by the application.
1955
	 * 
1964
	 *
1956 1965
	 * First it tries to get the locale from the command line parameters,
1957 1966
	 * then the andami-config file is checked.
1958
	 * 
1967
	 *
1959 1968
	 * The locale name is normalized to get a two characters language code
1960 1969
	 * as defined by ISO-639-1 (although ISO-639-2/T three characters codes
1961 1970
	 * are also accepted from the command line or the configuration file).
1962
	 * 
1971
	 *
1963 1972
	 * Finally, the gvsig-i18n library and the default locales for Java and
1964 1973
	 * Swing are configured.
1965 1974
	 *
branches/v10/frameworks/_fwAndami/src/com/iver/andami/Utilities.java
83 83
    /** DOCUMENT ME! */
84 84
    private static Logger logger = Logger.getLogger(Utilities.class.getName());
85 85
	private static final String tempDirectoryPath = System.getProperty("java.io.tmpdir")+"/tmp-andami";
86
	
87 86

  
87

  
88 88
    /**
89 89
     * Crea un icono a partir del path de una imagen
90 90
     *
......
116 116
    public static void cleanComponent(Component baseComponent) {
117 117
        try {
118 118
            cleanComponent(baseComponent, 0);
119
        } catch (Exception ignore) { // give some exception handling... 
119
        } catch (Exception ignore) { // give some exception handling...
120 120
        }
121 121
    }
122 122

  
123 123
    /*    * The "depth" parameter was being used for text output debugging.    * But isn't essential now.  I'll keep it anyways, as it avoids    * calling the garbage collector every recursion.    */
124 124
    protected static void cleanComponent(Component baseComponent, int depth) {
125
        if (baseComponent == null) // recursion terminating clause     
125
        if (baseComponent == null) // recursion terminating clause
126 126
         {
127 127
            return;
128 128
        }
129
        
129

  
130 130
        if (baseComponent instanceof IWindow){
131 131
        	return;
132 132
        }
......
135 135
        Component[] childComponents;
136 136
        int numChildren; // clean up component containers
137 137

  
138
        if (baseComponent instanceof Container) { // now clean up container instance variables 
138
        if (baseComponent instanceof Container) { // now clean up container instance variables
139 139

  
140
            if (baseComponent instanceof RootPaneContainer) { // Swing specialised container         
140
            if (baseComponent instanceof RootPaneContainer) { // Swing specialised container
141 141
                cont = (Container) baseComponent;
142 142
                numChildren = cont.getComponentCount();
143 143
                childComponents = cont.getComponents();
144 144

  
145
                for (int i = 0; i < numChildren; i++) { // remove each component from the current container            
145
                for (int i = 0; i < numChildren; i++) { // remove each component from the current container
146 146

  
147
                    // each child component may be a container itself   
147
                    // each child component may be a container itself
148 148
                    cleanComponent(childComponents[i], depth + 1);
149 149
                    ((RootPaneContainer) cont).getContentPane().remove(childComponents[i]);
150 150
                }
151 151

  
152 152
                ((RootPaneContainer) cont).getContentPane().setLayout(null);
153
            } else { // General Swing, and AWT, Containers  
153
            } else { // General Swing, and AWT, Containers
154 154
                cont = (Container) baseComponent;
155 155
                numChildren = cont.getComponentCount();
156 156
                childComponents = cont.getComponents();
157 157

  
158
                for (int i = 0; i < numChildren; i++) //for(int i = 0;i < numChildren;i++)              
158
                for (int i = 0; i < numChildren; i++) //for(int i = 0;i < numChildren;i++)
159 159
                 {
160
                    // remove each component from the current container                    // each child component may be a container itself                   
160
                    // remove each component from the current container                    // each child component may be a container itself
161 161
                    cleanComponent(childComponents[i], depth + 1);
162 162
                    cont.remove(childComponents[i]);
163 163
                }
......
166 166
            }
167 167
        }
168 168

  
169
        // if component is also a container  
169
        // if component is also a container
170 170
    }
171 171

  
172

  
173

  
172 174
    /**
173 175
     * Extrae un fichero zip en un directorio
174 176
     *
......
179 181
     * @throws IOException Si se produce un error de entrada salida gen?rico
180 182
     */
181 183
    public static void extractTo(File file, File dir, SplashWindow splash)
182
        throws ZipException, IOException {
183
        ZipFile zip = new ZipFile(file);
184
        Enumeration e = zip.entries();
184
			throws ZipException, IOException {
185
		ZipFile zip = new ZipFile(file);
186
		Enumeration e = zip.entries();
185 187

  
186
        while (e.hasMoreElements()) {
187
            ZipEntry entry = (ZipEntry) e.nextElement();
188
            System.out.println("Procesando " + entry.getName() + "...");
189
            splash.process(30, "Procesando " + entry.getName() + "...");
190
            if (entry.isDirectory()) {
191
                new File(dir.getAbsolutePath() + File.separator +
192
                    entry.getName()).mkdir();
193
            } else {
194
                InputStream in = zip.getInputStream(entry);
195
                OutputStream out = new FileOutputStream(dir + File.separator +
196
                        entry.getName());
197
                BufferedInputStream bin = new BufferedInputStream(in);
198
                BufferedOutputStream bout = new BufferedOutputStream(out);
188
		// Pasada para crear las carpetas
189
		while (e.hasMoreElements()) {
190
			ZipEntry entry = (ZipEntry) e.nextElement();
199 191

  
200
                int i;
192
			if (entry.isDirectory()) {
193
				File directorio = new File(dir.getAbsolutePath()
194
						+ File.separator + entry.getName());
201 195

  
202
                while ((i = bin.read()) != -1) {
203
                    bout.write(i);
204
                }
196
				directorio.mkdirs();
197
			}
205 198

  
206
                bout.flush();
207
                bout.close();
208
                bin.close();
209
            }
210
        }
211
    }
212
    
199
		}
200

  
201
		// Pasada para crear los ficheros
202
		e = zip.entries();
203
		while (e.hasMoreElements()) {
204
			ZipEntry entry = (ZipEntry) e.nextElement();
205
			splash.process(30, "Procesando " + entry.getName() + "...");
206
			if (!entry.isDirectory()) {
207
				InputStream in = zip.getInputStream(entry);
208
				OutputStream out = new FileOutputStream(dir + File.separator
209
						+ entry.getName());
210
				BufferedInputStream bin = new BufferedInputStream(in);
211
				BufferedOutputStream bout = new BufferedOutputStream(out);
212

  
213
				int i;
214

  
215
				while ((i = bin.read()) != -1) {
216
					bout.write(i);
217
				}
218

  
219
				bout.flush();
220
				bout.close();
221
				bin.close();
222

  
223
			}
224

  
225
		}
226

  
227
		zip.close();
228
		zip = null;
229
		System.gc();
230

  
231
	}
232

  
213 233
    /**
214 234
     * Returns the content of this URL as a file from the file system.<br>
215 235
     * <p>
216
     * If the URL has been already downloaded in this session and notified 
236
     * If the URL has been already downloaded in this session and notified
217 237
     * to the system using the static <b>Utilities.addDownloadedURL(URL)</b>
218 238
     * method, it can be restored faster from the file system avoiding to
219 239
     * download it again.
......
229 249
        }
230 250
        return f;
231 251
    }
232
    
252

  
233 253
    /**
234 254
     * Adds an URL to the table of downloaded files for further uses. If the URL
235 255
     * already exists in the table its filePath value is updated to the new one and
236 256
     * the old file itself is removed from the file system.
237
     * 
257
     *
238 258
     * @param url
239 259
     * @param filePath
240 260
     */
......
252 272
        }
253 273
        */
254 274
    }
255
       
275

  
256 276
    /**
257
     * Downloads an URL into a temporary file that is removed the next time the 
277
     * Downloads an URL into a temporary file that is removed the next time the
258 278
     * tempFileManager class is called, which means the next time gvSIG is launched.
259
     * 
279
     *
260 280
     * @param url
261 281
     * @param name
262 282
     * @return
......
273 293
	        	File tempDirectory = new File(tempDirectoryPath);
274 294
	        	if (!tempDirectory.exists())
275 295
	        		tempDirectory.mkdir();
276
	        	
296

  
277 297
	        	f = new File(tempDirectoryPath+"/"+name+System.currentTimeMillis());
278
	            
298

  
279 299
	            System.out.println("downloading '"+url.toString()+"' to: "+f.getAbsolutePath());
280
	            
300

  
281 301
	            f.deleteOnExit();
282 302
                DataOutputStream dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(f)));
283 303
                byte[] buffer = new byte[1024*256];
......
293 313
	    } catch (IOException io) {
294 314
	    	io.printStackTrace();
295 315
	    }
296
	    
316

  
297 317
	    return f;
298 318
	}
299 319

  
......
303 323
    public static void cleanUpTempFiles() {
304 324
    	try{
305 325
    		File tempDirectory = new File(tempDirectoryPath);
306
    		
326

  
307 327
    		File[] files = tempDirectory.listFiles();
308 328
    		if (files!=null) {
309 329
    			for (int i = 0; i < files.length; i++) {
......
314 334
    		}
315 335
    		tempDirectory.delete();
316 336
    	} catch (Exception e) {	}
317
    	
337

  
318 338
    }
319 339
    /**
320 340
     * Recursive directory delete.
......
326 346
			if (files[i].isDirectory()) deleteDirectory(files[i]);
327 347
			files[i].delete();
328 348
		}
329
		
349

  
330 350
	}
331
	
351

  
332 352
    /**
333 353
     * Crea un fichero temporal con un nombre concreto y unos datos pasados por
334 354
     * par?metro.
......
342 362
		dos.close();
343 363
    	f.deleteOnExit();
344 364
    }
345
	
365

  
346 366
    /**
347 367
     * Remove an URL from the system cache. The file will remain in the file
348 368
     * system for further eventual uses.

Also available in: Unified diff