Changeset 1879 in josm for trunk/src/org/openstreetmap/josm/tools/WikiReader.java
- Timestamp:
- 2009-08-02T14:36:40+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/WikiReader.java
r1755 r1879 4 4 import java.io.BufferedReader; 5 5 import java.io.IOException; 6 import java.io.InputStream; 6 7 import java.io.InputStreamReader; 7 8 import java.net.URL; … … 10 11 import org.openstreetmap.josm.tools.LanguageInfo; 11 12 13 import static org.openstreetmap.josm.tools.I18n.tr; 14 12 15 /** 13 16 * Read a trac-wiki page. 14 * 17 * 15 18 * @author imi 16 19 */ … … 29 32 /** 30 33 * Read the page specified by the url and return the content. 31 * 32 * If the url is within the baseurl path, parse it as an trac wikipage and 33 * replace relativepathes etc..34 * 34 * 35 * If the url is within the baseurl path, parse it as an trac wikipage and replace relative 36 * pathes etc.. 37 * 35 38 * @return Either the string of the content of the wiki page. 36 39 * @throws IOException Throws, if the page could not be loaded. … … 45 48 public String readLang(String text) { 46 49 String languageCode = LanguageInfo.getLanguageCodeWiki(); 47 String url = baseurl + "/wiki/" +languageCode+text;50 String url = baseurl + "/wiki/" + languageCode + text; 48 51 String res = ""; 52 InputStream in = null; 49 53 try { 50 res = readFromTrac(new BufferedReader(new InputStreamReader(new URL(url).openStream(), "utf-8"))); 51 } catch (IOException ioe) {} 52 if(res.length() == 0 && languageCode.length() != 0) 53 { 54 url = baseurl + "/wiki/"+text; 54 in = new URL(url).openStream(); 55 res = readFromTrac(new BufferedReader(new InputStreamReader(in, "utf-8"))); 56 } catch (IOException ioe) { 57 System.out.println(tr("Warning: failed to read MOTD from ''{0}''. Exception was: {1}", url, ioe 58 .toString())); 59 } catch(SecurityException e) { 60 System.out.println(tr( 61 "Warning: failed to read MOTD from ''{0}'' for security reasons. Exception was: {1}", url, e 62 .toString())); 63 } finally { 64 if (in != null) { 65 try { 66 in.close(); 67 } catch (IOException e) { 68 } 69 } 70 } 71 if (res.length() == 0 && languageCode.length() != 0) { 72 url = baseurl + "/wiki/" + text; 55 73 try { 56 res = readFromTrac(new BufferedReader(new InputStreamReader(new URL(url).openStream(), "utf-8"))); 57 } catch (IOException ioe) {} 74 in = new URL(url).openStream(); 75 } catch (IOException e) { 76 System.out.println(tr("Warning: failed to read MOTD from ''{0}''. Exception was: {1}", url, e 77 .toString())); 78 return res; 79 } catch (SecurityException e) { 80 System.out.println(tr( 81 "Warning: failed to read MOTD from ''{0}'' for security reasons. Exception was: {1}", url, e 82 .toString())); 83 return res; 84 } 85 try { 86 res = readFromTrac(new BufferedReader(new InputStreamReader(in, "utf-8"))); 87 } catch (IOException ioe) { 88 System.out.println(tr("Warning: failed to read MOTD from ''{0}''. Exception was: {1}", url, ioe 89 .toString())); 90 return res; 91 } finally { 92 if (in != null) { 93 try { 94 in.close(); 95 } catch (IOException e) { 96 } 97 } 98 } 58 99 } 59 100 return res; … … 63 104 String b = ""; 64 105 for (String line = in.readLine(); line != null; line = in.readLine()) { 65 if (!line.contains("[[TranslatedPages]]"))106 if (!line.contains("[[TranslatedPages]]")) { 66 107 b += line.replaceAll(" />", ">") + "\n"; 108 } 67 109 } 68 110 return "<html>" + b + "</html>"; … … 74 116 String b = ""; 75 117 for (String line = in.readLine(); line != null; line = in.readLine()) { 76 if (line.contains("<div id=\"searchable\">")) 118 if (line.contains("<div id=\"searchable\">")) { 77 119 inside = true; 78 else if (line.contains("<div class=\"wiki-toc trac-nav\""))120 } else if (line.contains("<div class=\"wiki-toc trac-nav\"")) { 79 121 transl = true; 80 else if (line.contains("<div class=\"wikipage searchable\">"))122 } else if (line.contains("<div class=\"wikipage searchable\">")) { 81 123 inside = true; 82 else if (line.contains("<div class=\"buttons\">"))124 } else if (line.contains("<div class=\"buttons\">")) { 83 125 inside = false; 126 } 84 127 if (inside && !transl) { 85 b += line.replaceAll("<img src=\"/", "<img src=\""+baseurl+"/") 86 .replaceAll("href=\"/", "href=\""+baseurl+"/") 87 .replaceAll(" />", ">") + "\n"; 128 b += line.replaceAll("<img src=\"/", "<img src=\"" + baseurl + "/").replaceAll("href=\"/", 129 "href=\"" + baseurl + "/").replaceAll(" />", ">") 130 + "\n"; 131 } else if (transl && line.contains("</div>")) { 132 transl = false; 88 133 } 89 else if (transl && line.contains("</div>"))90 transl = false;91 134 } 92 if (b.indexOf(" Describe ") >= 0)135 if (b.indexOf(" Describe ") >= 0) 93 136 return ""; 94 137 return "<html>" + b + "</html>";
Note:
See TracChangeset
for help on using the changeset viewer.