Ticket #8571: tinyurl.patch
File tinyurl.patch, 2.5 KB (added by , 12 years ago) |
---|
-
core/src/org/openstreetmap/josm/tools/OpenBrowser.java
4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 6 import java.awt.Desktop; 7 import java.io.BufferedReader; 7 8 import java.io.IOException; 9 import java.io.InputStream; 10 import java.net.HttpURLConnection; 8 11 import java.net.MalformedURLException; 9 12 import java.net.URI; 13 import java.net.URISyntaxException; 14 import java.net.URL; 10 15 11 16 import javax.swing.JApplet; 12 17 13 18 import org.openstreetmap.josm.Main; 19 import org.openstreetmap.josm.io.UTFInputStreamReader; 14 20 15 21 /** 16 22 * Helper to open platform web browser on different platforms … … 28 34 } 29 35 30 36 /** 37 * @param uri The URI to display 31 38 * @return <code>null</code> for success or a string in case of an error. 32 39 * @throws IllegalStateException thrown if no platform is set to which opening the URL can be dispatched, 33 40 * {@link Main#platform} … … 42 49 return mue.getMessage(); 43 50 } 44 51 } 52 53 // Windows cannot open URLs longer than 2047 or 2083 characters. Make a tiny url for large URLs (such as bug reports) 54 // See http://josm.openstreetmap.de/ticket/8571#comment:3 55 if (Main.platform instanceof PlatformHookWindows && uri.toString().length() > 2047) { 56 String tinyUrlRequest = "http://tinyurl.com/api-create.php?url="+uri.toString(); 57 try { 58 HttpURLConnection connection = Utils.openHttpConnection(new URL(tinyUrlRequest)); 59 InputStream inputStream = connection.getInputStream(); 60 BufferedReader br = new BufferedReader(UTFInputStreamReader.create(inputStream, "UTF-8")); 61 String tinyUrlAnswer = br.readLine(); 62 try { 63 uri = new URI(tinyUrlAnswer); 64 } catch (URISyntaxException e) { 65 System.err.println("Cannot create URL "+tinyUrlAnswer); 66 } 67 br.close(); 68 connection.disconnect(); 69 } catch (MalformedURLException e) { 70 System.err.println("Cannot create URL "+tinyUrlRequest); 71 } catch (IOException e) { 72 e.printStackTrace(); 73 } 74 } 45 75 46 76 if (Desktop.isDesktopSupported()) { 47 77 try {