- Timestamp:
- 2013-04-29T17:25:45+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java
r5890 r5915 24 24 import org.openstreetmap.josm.data.osm.TagCollection; 25 25 import org.openstreetmap.josm.gui.conflict.tags.PasteTagsConflictResolverDialog; 26 import org.openstreetmap.josm.gui.help.HelpUtil;27 26 import org.openstreetmap.josm.tools.Shortcut; 28 27 import org.openstreetmap.josm.tools.TextTagParser; … … 40 39 41 40 private static final String help = ht("/Action/PasteTags"); 42 private static final String helpUrl = HelpUtil.getHelpTopicUrl(HelpUtil.buildAbsoluteHelpTopic(help));43 41 44 42 public PasteTagsAction() { … … 267 265 List<Command> commands = new ArrayList<Command>(); 268 266 if (tags==null || tags.isEmpty()) { 269 TextTagParser.showBadBufferMessage(help Url);267 TextTagParser.showBadBufferMessage(help); 270 268 return false; 271 269 } -
trunk/src/org/openstreetmap/josm/gui/help/HelpBrowser.java
r5886 r5915 50 50 import org.openstreetmap.josm.gui.widgets.JosmEditorPane; 51 51 import org.openstreetmap.josm.tools.ImageProvider; 52 import org.openstreetmap.josm.tools.LanguageInfo.LocaleType; 52 53 import org.openstreetmap.josm.tools.OpenBrowser; 53 54 import org.openstreetmap.josm.tools.Utils; … … 261 262 relativeHelpTopic, 262 263 Locale.getDefault().getDisplayName(), 263 getHelpTopicEditUrl(buildAbsoluteHelpTopic(relativeHelpTopic )),264 getHelpTopicEditUrl(buildAbsoluteHelpTopic(relativeHelpTopic, Locale .ENGLISH))264 getHelpTopicEditUrl(buildAbsoluteHelpTopic(relativeHelpTopic, LocaleType.DEFAULT)), 265 getHelpTopicEditUrl(buildAbsoluteHelpTopic(relativeHelpTopic, LocaleType.ENGLISH)) 265 266 ); 266 267 loadTopic(message); … … 294 295 */ 295 296 protected void loadRelativeHelpTopic(String relativeHelpTopic) { 296 String url = HelpUtil.getHelpTopicUrl(HelpUtil.buildAbsoluteHelpTopic(relativeHelpTopic ));297 String url = HelpUtil.getHelpTopicUrl(HelpUtil.buildAbsoluteHelpTopic(relativeHelpTopic, LocaleType.DEFAULTNOTENGLISH)); 297 298 String content = null; 298 299 try { 299 300 content = reader.fetchHelpTopicContent(url, true); 300 301 } catch(MissingHelpContentException e) { 301 url = HelpUtil.getHelpTopicUrl(HelpUtil.buildAbsoluteHelpTopic(relativeHelpTopic, Locale .ENGLISH));302 url = HelpUtil.getHelpTopicUrl(HelpUtil.buildAbsoluteHelpTopic(relativeHelpTopic, LocaleType.BASELANGUAGE)); 302 303 try { 303 304 content = reader.fetchHelpTopicContent(url, true); 304 305 } catch(MissingHelpContentException e1) { 305 this.url = url; 306 handleMissingHelpContent(relativeHelpTopic); 307 return; 306 url = HelpUtil.getHelpTopicUrl(HelpUtil.buildAbsoluteHelpTopic(relativeHelpTopic, LocaleType.ENGLISH)); 307 try { 308 content = reader.fetchHelpTopicContent(url, true); 309 } catch(MissingHelpContentException e2) { 310 this.url = url; 311 handleMissingHelpContent(relativeHelpTopic); 312 return; 313 } catch(HelpContentReaderException e2) { 314 e2.printStackTrace(); 315 handleHelpContentReaderException(relativeHelpTopic, e2); 316 return; 317 } 308 318 } catch(HelpContentReaderException e1) { 309 319 e1.printStackTrace(); 310 handleHelpContentReaderException(relativeHelpTopic, e1);320 handleHelpContentReaderException(relativeHelpTopic, e1); 311 321 return; 312 322 } -
trunk/src/org/openstreetmap/josm/gui/help/HelpContentReader.java
r5874 r5915 42 42 */ 43 43 public String fetchHelpTopicContent(String helpTopicUrl, boolean dotest) throws HelpContentReaderException { 44 if(helpTopicUrl == null) 45 throw new MissingHelpContentException(); 44 46 HttpURLConnection con = null; 45 47 BufferedReader in = null; -
trunk/src/org/openstreetmap/josm/gui/help/HelpUtil.java
r5899 r5915 14 14 import org.openstreetmap.josm.actions.HelpAction; 15 15 import org.openstreetmap.josm.tools.LanguageInfo; 16 import org.openstreetmap.josm.tools.LanguageInfo.LocaleType; 16 17 17 18 public class HelpUtil { … … 40 41 * @param absoluteHelpTopic the absolute help topic 41 42 * @return the url 42 * @see #buildAbsoluteHelpTopic(String) 43 * @see #buildAbsoluteHelpTopic(String, Locale) 43 * @see #buildAbsoluteHelpTopic 44 44 */ 45 45 static public String getHelpTopicUrl(String absoluteHelpTopic) { 46 if(absoluteHelpTopic == null) 47 return null; 46 48 String ret = getWikiBaseHelpUrl(); 47 49 ret = ret.replaceAll("\\/+$", ""); 48 absoluteHelpTopic =absoluteHelpTopic.replace(" ", "%20");50 absoluteHelpTopic = absoluteHelpTopic.replace(" ", "%20"); 49 51 absoluteHelpTopic = absoluteHelpTopic.replaceAll("^\\/+", "/"); 50 52 return ret + absoluteHelpTopic; … … 72 74 static public String extractRelativeHelpTopic(String url) { 73 75 String topic = extractAbsoluteHelpTopic(url); 74 if (topic == null) return null; 75 String pattern = "/[A-Z][a-z]:" + getHelpTopicPrefix(Locale.ENGLISH).replaceAll("^\\/+", ""); 76 if (url.matches(pattern)) 76 if (topic == null) 77 return null; 78 String pattern = "/[A-Z][a-z]{1,2}(_[A-Z]{2})?:" + getHelpTopicPrefix(LocaleType.ENGLISH).replaceAll("^\\/+", ""); 79 if (url.matches(pattern)) { 77 80 return topic.substring(pattern.length()); 81 } 78 82 return null; 79 83 } … … 89 93 if (!url.startsWith(getWikiBaseHelpUrl())) return null; 90 94 url = url.substring(getWikiBaseHelpUrl().length()); 91 String prefix = getHelpTopicPrefix(Locale .ENGLISH);95 String prefix = getHelpTopicPrefix(LocaleType.ENGLISH); 92 96 if (url.startsWith(prefix)) 93 97 return url; 94 98 95 String pattern = "/[A-Z][a-z] :" + prefix.replaceAll("^\\/+", "");99 String pattern = "/[A-Z][a-z]{1,2}(_[A-Z]{2})?:" + prefix.replaceAll("^\\/+", ""); 96 100 if (url.matches(pattern)) 97 101 return url; 98 102 99 103 return null; 100 }101 102 /**103 * Replies the help topic prefix for the current locale. Examples:104 * <ul>105 * <li>/Help if the current locale is a locale with language "en"</li>106 * <li>/De:Help if the current locale is a locale with language "de"</li>107 * </ul>108 *109 * @return the help topic prefix110 * @see #getHelpTopicPrefix(Locale)111 */112 static public String getHelpTopicPrefix() {113 return getHelpTopicPrefix(Locale.getDefault());114 104 } 115 105 … … 121 111 * </ul> 122 112 * 123 * @param locale the locale. {@link Locale#ENGLISH} assumed, if null.113 * @param type the type of the locale to use 124 114 * @return the help topic prefix 125 * @see #getHelpTopicPrefix(Locale) 126 */ 127 static public String getHelpTopicPrefix(Locale locale) { 128 if (locale == null) { 129 locale = Locale.ENGLISH; 130 } 131 String ret = Main.pref.get("help.pathhelp", "/Help"); 132 ret = ret.replaceAll("^\\/+", ""); // remove leading / 133 ret = "/" + LanguageInfo.getWikiLanguagePrefix(locale) + ret; 134 return ret; 115 */ 116 static private String getHelpTopicPrefix(LocaleType type) { 117 String ret = LanguageInfo.getWikiLanguagePrefix(type); 118 if(ret == null) 119 return ret; 120 ret = "/" + ret + Main.pref.get("help.pathhelp", "/Help").replaceAll("^\\/+", ""); // remove leading /; 121 return ret.replaceAll("\\/+", "\\/"); // collapse sequences of // 135 122 } 136 123 … … 142 129 * 143 130 * @param topic the relative help topic. Home help topic assumed, if null. 144 * @param locale the locale. {@link Locale#ENGLISH} assumed, if null.131 * @param type the locale. {@link Locale#ENGLISH} assumed, if null. 145 132 * @return the absolute, localized help topic 146 133 */ 147 static public String buildAbsoluteHelpTopic(String topic, Locale locale) { 148 if (locale == null) { 149 locale = Locale.ENGLISH; 150 } 151 if (topic == null || topic.trim().length() == 0 || topic.trim().equals("/")) 152 return getHelpTopicPrefix(locale); 153 String ret = getHelpTopicPrefix(locale); 154 if (topic.startsWith("/")) { 155 ret += topic; 156 } else { 157 ret += "/" + topic; 158 } 159 ret = ret.replaceAll("\\/+", "\\/"); // just in case, collapse sequences of // 160 return ret; 161 } 162 163 /** 164 * Replies the absolute, localized help topic for the given topic and the 165 * current locale. 166 * 167 * @param topic the relative help topic. Home help topic assumed, if null. 168 * @return the absolute, localized help topic 169 * @see Locale#getDefault() 170 * @see #buildAbsoluteHelpTopic(String, Locale) 171 */ 172 static public String buildAbsoluteHelpTopic(String topic) { 173 return buildAbsoluteHelpTopic(topic, Locale.getDefault()); 134 static public String buildAbsoluteHelpTopic(String topic, LocaleType type) { 135 String prefix = getHelpTopicPrefix(type); 136 if (prefix == null || topic == null || topic.trim().length() == 0 || topic.trim().equals("/")) 137 return prefix; 138 prefix += "/" + topic; 139 return prefix.replaceAll("\\/+", "\\/"); // collapse sequences of // 174 140 } 175 141 -
trunk/src/org/openstreetmap/josm/tools/LanguageInfo.java
r5275 r5915 2 2 package org.openstreetmap.josm.tools; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 4 import static org.openstreetmap.josm.tools.I18n.marktr; 5 6 import org.openstreetmap.josm.Main; 5 7 6 8 import java.util.Locale; 7 9 8 10 public class LanguageInfo { 11 /** Type of the locale to use */ 12 public enum LocaleType { 13 /** The current default language */ 14 DEFAULT, 15 /** The current default language, but not english */ 16 DEFAULTNOTENGLISH, 17 /** The base language (i.e. pt for pt_BR) */ 18 BASELANGUAGE, 19 /** The standard english texts */ 20 ENGLISH 21 }; 9 22 10 23 /** 11 24 * Replies the wiki language prefix for the given locale. The wiki language 12 25 * prefix has the form 'Xy:' where 'Xy' is a ISO 639 language code in title 13 * case .26 * case (or Xy_AB: for sub languages). 14 27 * 15 * @param locale the locale 16 * @return the wiki language prefix 28 * @param type the type 29 * @return the wiki language prefix or {@code null} for {@link LocaleType#BASELANGUAGE}, when 30 * base language is identical to default or english 31 * @since 8636 17 32 */ 18 static public String getWikiLanguagePrefix(Locale locale) { 19 String code = getJOSMLocaleCode(locale); 20 if (code.length() == 2) { 21 if (code.equals("en")) return ""; 22 } else if (code.equals("zh_TW") || code.equals("zh_CN")) { 23 /* do nothing */ 24 } else if (code.matches("[^_]+_[^_]+")) { 25 code = code.substring(0,2); 26 if (code.equals("en")) return ""; 27 } else { 28 System.err.println(tr("Warning: failed to derive wiki language prefix from JOSM locale code ''{0}''. Using default code ''en''.", code)); 29 return ""; 30 } 33 static public String getWikiLanguagePrefix(LocaleType type) { 34 if(type == LocaleType.ENGLISH) 35 return ""; 36 37 String code = getJOSMLocaleCode(); 38 if(type == LocaleType.BASELANGUAGE) { 39 if(code.matches("[^_]+_[^_]+")) { 40 code = code.substring(0,2); 41 if(code == "en") 42 return null; 43 } else { 44 return null; 45 } 46 } else if(type == LocaleType.DEFAULTNOTENGLISH && code == "en") 47 return null; 31 48 return code.substring(0,1).toUpperCase() + code.substring(1) + ":"; 32 49 } … … 37 54 * @return the wiki language prefix 38 55 * @see Locale#getDefault() 39 * @see #getWikiLanguagePrefix(Locale )56 * @see #getWikiLanguagePrefix(LocaleType) 40 57 */ 41 58 static public String getWikiLanguagePrefix() { 42 return getWikiLanguagePrefix(Locale .getDefault());59 return getWikiLanguagePrefix(LocaleType.DEFAULT); 43 60 } 44 61 -
trunk/src/org/openstreetmap/josm/tools/TextTagParser.java
r5813 r5915 11 11 import javax.swing.JPanel; 12 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.gui.help.HelpUtil; 13 14 import org.openstreetmap.josm.gui.ExtendedDialog; 14 15 import org.openstreetmap.josm.io.XmlWriter; 16 import org.openstreetmap.josm.tools.LanguageInfo.LocaleType; 15 17 16 18 import static org.openstreetmap.josm.tools.I18n.tr; … … 279 281 /** 280 282 * Shows message that the buffer can not be pasted, allowing user to clean the buffer 281 * @param helpUrl 283 * @param helpTopic the help topic of the parent action 284 * TODO: Replace by proper HelpAwareOptionPane instead of self-made help link 282 285 */ 283 public static void showBadBufferMessage(String help Url) {286 public static void showBadBufferMessage(String helpTopic) { 284 287 String msg = tr("<html><p> Sorry, it is impossible to paste tags from buffer. It does not contain any JOSM object" 285 288 + " or suitable text. </p></html>"); 286 289 JPanel p = new JPanel(new GridBagLayout()); 287 290 p.add(new JLabel(msg),GBC.eop()); 291 String helpUrl = HelpUtil.getHelpTopicUrl(HelpUtil.buildAbsoluteHelpTopic(helpTopic, LocaleType.DEFAULT)); 288 292 if (helpUrl != null) { 289 293 p.add(new UrlLabel(helpUrl), GBC.eop()); -
trunk/src/org/openstreetmap/josm/tools/WikiReader.java
r5874 r5915 7 7 8 8 import org.openstreetmap.josm.Main; 9 import org.openstreetmap.josm.tools.LanguageInfo.LocaleType; 9 10 10 11 /** … … 45 46 46 47 public String readLang(String text) throws IOException { 47 String languageCode = LanguageInfo.getWikiLanguagePrefix(); 48 String res = readLang(new URL(baseurl + "/wiki/" + languageCode + text)); 49 if (res.isEmpty() && !languageCode.isEmpty()) { 50 res = readLang(new URL(baseurl + "/wiki/" + text)); 48 String languageCode; 49 String res = ""; 50 51 languageCode = LanguageInfo.getWikiLanguagePrefix(LocaleType.DEFAULTNOTENGLISH); 52 if(languageCode != null) { 53 res = readLang(new URL(baseurl + "/wiki/" + languageCode + text)); 51 54 } 52 if (res.isEmpty()) { 55 56 if(res.isEmpty()) { 57 languageCode = LanguageInfo.getWikiLanguagePrefix(LocaleType.BASELANGUAGE); 58 if(languageCode != null) { 59 res = readLang(new URL(baseurl + "/wiki/" + languageCode + text)); 60 } 61 } 62 63 if(res.isEmpty()) { 64 languageCode = LanguageInfo.getWikiLanguagePrefix(LocaleType.ENGLISH); 65 if(languageCode != null) { 66 res = readLang(new URL(baseurl + "/wiki/" + languageCode + text)); 67 } 68 } 69 70 if(res.isEmpty()) { 53 71 throw new IOException(text + " does not exist"); 54 72 } else { … … 101 119 // will render a thick border around images inside an <a> element 102 120 // 103 b += line.replaceAll("<img src=\"/", "<img border=\"0\" src=\"" + baseurl + "/").replaceAll("href=\"/", 104 "href=\"" + baseurl + "/").replaceAll(" />", ">") 105 + "\n"; 121 b += line.replaceAll("<img ", "<img border=\"0\" ").replaceAll(" />", ">") + "\n"; 106 122 } else if (transl && line.contains("</div>")) { 107 123 transl = false; … … 114 130 || b.indexOf(" does not exist. You can create it here.</p>") >= 0) 115 131 return ""; 116 return "<html> " + b + "</html>";132 return "<html><base href=\""+baseurl+"\"> " + b + "</html>"; 117 133 } 118 134 }
Note:
See TracChangeset
for help on using the changeset viewer.