Archive for Diciembre, 2007

Abrir una URL (PDF, o lo que sea) con Java

Lunes, Diciembre 17th, 2007

Miguel Álvarez Úbeda ha enviado este código a la lista de desarrolladores de gvSIG:

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;

public class ApplicationLauncher {

public static void main(String args[]){
if( args.length!=1) {
System.out.println(”Numero de parametros erroneo forma de uso: java -cp . ApplicationLauncher fichero|URL”);
return;
}
if(args[0].indexOf(”http”)!=-1) launchURL(args[0]);
else launchDefaultViewer(args[0]);
}

private static String linuxDesktop = null;

private static String getEnv(String envvar){
try{
Process p = Runtime.getRuntime().exec(”/bin/sh echo $”+envvar);
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String value = br.readLine();
if(value==null) return “”;
else return value.trim ();
}
catch(Exception error){
return “”;
}
}

private static String getLinuxDesktop(){
//solo se averigua el entorno de escritorio una vez, despues se almacena en la variable estatica
if(linuxDesktop!=null) return linuxDesktop;
if(!getEnv(”KDE_FULL_SESSION”).equals(”") || !getEnv(”KDE_MULTIHEAD”).equals(”")){
linuxDesktop=”kde”;
}
else if(!getEnv(”GNOME_DESKTOP_SESSION_ID”).equals(”") || !getEnv(”GNOME_KEYRING_SOCKET”).equals(”")){
linuxDesktop=”gnome”;
}
else linuxDesktop=”";

return linuxDesktop;
}

public static Process launchURL(String url){
try{
if (System.getProperty(”os.name “).toUpperCase().indexOf(”95″) != -1)
return Runtime.getRuntime().exec( new String[]{”command.com“, “/C”, “start”, url} );
if (System.getProperty(”os.name“).toUpperCase().indexOf(”WINDOWS”) != -1)
return Runtime.getRuntime().exec( new String[]{”cmd.exe”, “/C”, “start”, url} );
if (System.getProperty(”os.name“).toUpperCase().indexOf(”MAC”) != -1)
return Runtime.getRuntime().exec( new String[]{”open”, url} );
if (System.getProperty(”os.name“).toUpperCase().indexOf(”LINUX”) != -1 ) {
if(getLinuxDesktop().equals(”kde”))
return Runtime.getRuntime().exec( new String[]{”kfmclient”, “exec”, url} );
else
return Runtime.getRuntime().exec( new String[]{”gnome-open”, url} );
}
}
catch(IOException ioex){System.out.println(ioex);}

return null;
}

public static Process launchDefaultViewer(String filepath){
return launchURL( new File(filepath).getAbsolutePath());
}

}

Con este código puedes lanzar ficheros pasandole una URL y te lo abre con la aplicacion asociada, funciona con Windows, Linux y Mac.

Una tontería con Open Office…

Martes, Diciembre 4th, 2007

… que me ha llevado lo menos una hora.

Resulta que no es fácil quitar un hiperenlace una vez puesto. Buscando por internet, he encontrado la solución:


Right Click sobre el texto al que quieres quitar el hipervínculo

-> Character…
-> Hyperlink Tab

y desde ahí, quitas la URL.

La solución la he encontrado en este post:

http://www.oooforum.org/forum/viewtopic.phtml?t=18962

Vuelta a casa

Lunes, Diciembre 3rd, 2007

Otra vez por Valencia, y con prisas (para variar). Tengo que empujar el manual de desarrolladores de gvSIG, y terminar de pulir Aficom Mobile.

Y a ver si de una vez puedo hacer las tareas administrativas, hablar con la gente, etc…. Al final le voy a pedir a los Reyes Magos un clon.

Hoy he estado mirando un poquito algo para gestionar las horas que empleo en los diferentes trabajos. Lo de Google, está muy bien, pero tampoco tengo tiempo para terminar el “extractor de horas”. El proyecto airTODO me ha gustado, a ver si un día de estos lo pruebo.

Por cierto, “off topic”. El último disco de Fito está genial. No tiene desperdicio.