Changeset 5868 in josm for trunk/src/org
- Timestamp:
- 2013-04-15T19:12:01+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Version.java
r5850 r5868 6 6 import java.io.BufferedReader; 7 7 import java.io.IOException; 8 import java.io.InputStreamReader;9 8 import java.net.URL; 10 9 import java.util.HashMap; … … 15 14 import org.openstreetmap.josm.Main; 16 15 import org.openstreetmap.josm.tools.LanguageInfo; 16 import org.openstreetmap.josm.tools.Utils; 17 17 18 18 /** … … 35 35 static public String loadResourceFile(URL resource) { 36 36 if (resource == null) return null; 37 BufferedReader in;38 37 String s = null; 39 38 try { 40 in = new BufferedReader(new InputStreamReader(resource.openStream(), "UTF-8"));39 BufferedReader in = Utils.openURLReader(resource); 41 40 StringBuffer sb = new StringBuffer(); 42 41 try { … … 227 226 return "JOSM/1.5 ("+ s+" "+LanguageInfo.getJOSMLocaleCode()+") " + Main.platform.getOSDescription(); 228 227 } 228 229 /** 230 * Returns the full User-Agent string 231 * @return The User-Agent 232 * @since 5866 233 */ 234 public String getFullAgentString() { 235 return getAgentString() + " Java/"+System.getProperty("java.version"); 236 } 229 237 } -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r5831 r5868 51 51 import org.openstreetmap.josm.tools.I18n; 52 52 import org.openstreetmap.josm.tools.ImageProvider; 53 import org.openstreetmap.josm.tools.Utils; 53 54 54 55 /** … … 292 293 System.out.println("Reading preferences from " + i); 293 294 try { 294 URL url = new URL(i); 295 config.openAndReadXML(url.openStream()); 295 config.openAndReadXML(Utils.openURL(new URL(i))); 296 296 } catch (Exception ex) { 297 297 throw new RuntimeException(ex); -
trunk/src/org/openstreetmap/josm/gui/help/HelpContentReader.java
r5587 r5868 21 21 * It also has to be <strong>transformed</strong> because the internal help browser required slightly 22 22 * different HTML than what is provided by the Wiki. 23 *24 * @see WikiReader25 23 */ 26 public class HelpContentReader { 27 28 /** the base url */ 29 private String baseUrl; 24 public class HelpContentReader extends WikiReader { 30 25 31 26 /** … … 35 30 */ 36 31 public HelpContentReader(String baseUrl) { 37 this.baseUrl = baseUrl;32 super(baseUrl); 38 33 } 39 34 … … 90 85 */ 91 86 protected String prepareHelpContent(BufferedReader in, boolean dotest) throws HelpContentReaderException { 92 boolean isInContent = false; 93 boolean isInTranslationsSideBar = false; 94 boolean isExistingHelpPage = false; 95 StringBuffer sball = new StringBuffer(); 96 StringBuffer sb = new StringBuffer(); 87 String s = ""; 97 88 try { 98 for (String line = in.readLine(); line != null; line = in.readLine()) { 99 sball.append(line); 100 sball.append("\n"); 101 if (line.contains("<div id=\"searchable\">")) { 102 isInContent = true; 103 } else if (line.contains("<div class=\"wiki-toc trac-nav\"")) { 104 isInTranslationsSideBar = true; 105 } else if (line.contains("<div class=\"wikipage searchable\">")) { 106 isInContent = true; 107 } else if (line.contains("<div class=\"buttons\">")) { 108 isInContent = false; 109 } else if (line.contains("<h3>Attachments</h3>")) { 110 isInContent = false; 111 } else if (line.contains("<div id=\"attachments\">")) { 112 isInContent = false; 113 } else if (line.contains("<div class=\"trac-modifiedby\">")) { 114 continue; 115 } else if (line.contains("<input type=\"submit\" name=\"attachfilebutton\"")) { 116 // heuristic: if we find a button for uploading images we are in an 117 // existing pages. Otherwise this is probably the stub page for a not yet 118 // existing help page 119 isExistingHelpPage = true; 120 } 121 if (isInContent && !isInTranslationsSideBar) { 122 // add a border="0" attribute to images, otherwise the internal help browser 123 // will render a thick border around images inside an <a> element 124 // 125 // Also make sure image URLs are absolute 126 // 127 line = line.replaceAll("<img ([^>]*)src=\"/", "<img border=\"0\" \\1src=\"" + baseUrl + "/").replaceAll("href=\"/", 128 "href=\"" + baseUrl + "/").replaceAll(" />", ">"); 129 sb.append(line); 130 sb.append("\n"); 131 } else if (isInTranslationsSideBar && line.contains("</div>")) { 132 isInTranslationsSideBar = false; 133 } 134 } 89 s = readFromTrac(in); 135 90 } catch(IOException e) { 136 91 throw new HelpContentReaderException(e); 137 92 } 138 if(!dotest && sb.length() == 0) 139 sb = sball; 140 else if (dotest && !isExistingHelpPage) 93 if(dotest && s.isEmpty()) 141 94 throw new MissingHelpContentException(); 142 sb.insert(0, "<html>"); 143 sb.append("<html>"); 144 return sb.toString(); 95 return s; 145 96 } 146 97 } -
trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java
r5839 r5868 77 77 import org.openstreetmap.josm.io.OsmTransferException; 78 78 import org.openstreetmap.josm.io.UTFInputStreamReader; 79 import org.openstreetmap.josm.tools.Utils; 79 80 import org.xml.sax.InputSource; 80 81 import org.xml.sax.SAXException; … … 321 322 protected byte[] updateData() throws IOException { 322 323 URL u = getAttributionUrl(); 323 UTFInputStreamReader in = UTFInputStreamReader.create( u.openStream(), "utf-8");324 UTFInputStreamReader in = UTFInputStreamReader.create(Utils.openURL(u), "utf-8"); 324 325 String r = new Scanner(in).useDelimiter("\\A").next(); 325 326 in.close(); -
trunk/src/org/openstreetmap/josm/io/MirroredInputStream.java
r5587 r5868 71 71 } else { 72 72 if (Main.applet) { 73 URLConnection conn = url.openConnection(); 74 conn.setConnectTimeout(Main.pref.getInteger("socket.timeout.connect",15)*1000); 75 conn.setReadTimeout(Main.pref.getInteger("socket.timeout.read",30)*1000); 76 fs = new BufferedInputStream(conn.getInputStream()); 73 fs = new BufferedInputStream(Utils.openURL(url)); 77 74 file = new File(url.getFile()); 78 75 } else { -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r5819 r5868 10 10 import java.awt.datatransfer.Transferable; 11 11 import java.awt.datatransfer.UnsupportedFlavorException; 12 import java.io.BufferedReader; 12 13 import java.io.File; 13 14 import java.io.IOException; 14 15 import java.io.InputStream; 16 import java.io.InputStreamReader; 15 17 import java.io.OutputStream; 16 18 import java.io.Reader; … … 18 20 import java.net.HttpURLConnection; 19 21 import java.net.URL; 22 import java.net.URLConnection; 20 23 import java.security.MessageDigest; 21 24 import java.security.NoSuchAlgorithmException; … … 28 31 import java.util.List; 29 32 33 import org.openstreetmap.josm.Main; 30 34 import org.openstreetmap.josm.data.Version; 31 35 … … 554 558 } 555 559 HttpURLConnection connection = (HttpURLConnection) httpURL.openConnection(); 560 connection.setRequestProperty("User-Agent", Version.getInstance().getFullAgentString()); 556 561 return connection; 557 562 } 558 563 564 /** 565 * Opens a connection to the given URL and sets the User-Agent property to JOSM's one. 566 * @param url The url to open 567 * @return An stream for the given URL 568 * @throws IOException if an I/O exception occurs. 569 * @since 5867 570 */ 571 public static InputStream openURL(URL url) throws IOException { 572 URLConnection connection = url.openConnection(); 573 connection.setRequestProperty("User-Agent", Version.getInstance().getFullAgentString()); 574 connection.setConnectTimeout(Main.pref.getInteger("socket.timeout.connect",15)*1000); 575 connection.setReadTimeout(Main.pref.getInteger("socket.timeout.read",30)*1000); 576 return connection.getInputStream(); 577 } 578 579 /** 580 * Opens a connection to the given URL and sets the User-Agent property to JOSM's one. 581 * @param url The url to open 582 * @return An buffered stream reader for the given URL (using UTF-8) 583 * @throws IOException if an I/O exception occurs. 584 * @since 5867 585 */ 586 public static BufferedReader openURLReader(URL url) throws IOException { 587 return new BufferedReader(new InputStreamReader(openURL(url), "utf-8")); 588 } 589 559 590 /** 560 591 * Opens a HTTP connection to the given URL, sets the User-Agent property to JOSM's one and optionnaly disables Keep-Alive. -
trunk/src/org/openstreetmap/josm/tools/WikiReader.java
r5834 r5868 5 5 import java.io.IOException; 6 6 import java.io.InputStream; 7 import java.io.InputStreamReader;8 7 import java.net.URL; 9 8 … … 36 35 */ 37 36 public String read(String url) throws IOException { 38 BufferedReader in = new BufferedReader(new InputStreamReader(new URL(url).openStream(), "utf-8"));37 BufferedReader in = Utils.openURLReader(new URL(url)); 39 38 try { 40 39 if (url.startsWith(baseurl) && !url.endsWith("?format=txt")) … … 60 59 61 60 private String readLang(URL url) throws IOException { 62 InputStream in = url.openStream();61 BufferedReader in = Utils.openURLReader(url); 63 62 try { 64 return readFromTrac( new BufferedReader(new InputStreamReader(in, "utf-8")));63 return readFromTrac(in); 65 64 } finally { 66 65 in.close(); … … 78 77 } 79 78 80 pr ivateString readFromTrac(BufferedReader in) throws IOException {79 protected String readFromTrac(BufferedReader in) throws IOException { 81 80 boolean inside = false; 82 81 boolean transl = false;
Note:
See TracChangeset
for help on using the changeset viewer.