Révision 2907
| tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/OpenLocalizedWebPage.java (revision 2907) | ||
|---|---|---|
| 52 | 52 |
* @author mdecorde. |
| 53 | 53 |
*/ |
| 54 | 54 |
public class OpenLocalizedWebPage extends AbstractHandler {
|
| 55 |
|
|
| 55 |
|
|
| 56 | 56 |
/** The Constant ID. */ |
| 57 | 57 |
public final static String ID = "org.txm.rcp.commands.OpenLocalizedWebPage"; //$NON-NLS-1$ |
| 58 |
|
|
| 59 |
public static final String GITPAGES = "https://pages.textometrie.org/"; |
|
| 60 |
public static final String URL_TEXTOMETRIE = GITPAGES+"textometrie/"; |
|
| 61 |
public static final String URL_TXMMANUAL = GITPAGES+"txm-manual/"; |
|
| 62 |
public static final String URL_TXMDEPOT = GITPAGES+"txm-software/"; |
|
| 58 |
|
|
| 59 |
public static final String GITPAGES = "https://txm.gitpages.huma-num.fr/"; |
|
| 60 |
|
|
| 61 |
public static final String URL_TEXTOMETRIE = GITPAGES + "textometrie/"; |
|
| 62 |
|
|
| 63 |
public static final String URL_TXMMANUAL = GITPAGES + "txm-manual/"; |
|
| 64 |
|
|
| 65 |
public static final String URL_TXMDEPOT = GITPAGES + "txm-software/"; |
|
| 66 |
|
|
| 63 | 67 |
public static final String HTMLPAGES = URL_TEXTOMETRIE + "html/"; |
| 68 |
|
|
| 64 | 69 |
public static final String FILESPAGES = URL_TEXTOMETRIE + "files/"; |
| 65 |
|
|
| 70 |
|
|
| 66 | 71 |
public static final String TEXTOMETRIE = "textometrie"; //$NON-NLS-1$ |
| 72 |
|
|
| 67 | 73 |
public static final String TEXTOMETRIE_DOCS = "textometrie_docs"; //$NON-NLS-1$ |
| 74 |
|
|
| 68 | 75 |
public static final String SF = "sf"; //$NON-NLS-1$ |
| 76 |
|
|
| 69 | 77 |
public static final String SF_DOCS = "sf_docs"; //$NON-NLS-1$ |
| 78 |
|
|
| 70 | 79 |
public static final String TREETAGGER = "treetagger"; //$NON-NLS-1$ |
| 80 |
|
|
| 71 | 81 |
public static final String REFMAN = "refman"; //$NON-NLS-1$ |
| 82 |
|
|
| 72 | 83 |
public static final String PDFREFMAN = "pdfrefman"; //$NON-NLS-1$ |
| 84 |
|
|
| 73 | 85 |
public static final String BUG = "bug"; //$NON-NLS-1$ |
| 86 |
|
|
| 74 | 87 |
public static final String FEATURE = "feature"; //$NON-NLS-1$ |
| 88 |
|
|
| 75 | 89 |
public static final String MAILINGLIST = "mailinglist"; //$NON-NLS-1$ |
| 90 |
|
|
| 76 | 91 |
public static final String FAQ = "faq"; //$NON-NLS-1$ |
| 92 |
|
|
| 77 | 93 |
public static final String CONTRIB = "contrib"; //$NON-NLS-1$ |
| 94 |
|
|
| 78 | 95 |
public static final String TXMUSERS = "txm-users wiki"; //$NON-NLS-1$ |
| 96 |
|
|
| 79 | 97 |
public static final String MACROS = "macros"; //$NON-NLS-1$ |
| 98 |
|
|
| 80 | 99 |
public static final String CORPORA = "corpora"; //$NON-NLS-1$ |
| 81 |
|
|
| 82 |
/* (non-Javadoc) |
|
| 100 |
|
|
| 101 |
/* |
|
| 102 |
* (non-Javadoc) |
|
| 83 | 103 |
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
| 84 | 104 |
*/ |
| 85 | 105 |
@Override |
| ... | ... | |
| 90 | 110 |
openfile(key); |
| 91 | 111 |
return null; |
| 92 | 112 |
} |
| 93 |
|
|
| 113 |
|
|
| 94 | 114 |
return null; |
| 95 | 115 |
} |
| 96 |
|
|
| 116 |
|
|
| 97 | 117 |
/** |
| 98 | 118 |
* try connecting to an URL if it fails, the alternative url is returned |
| 99 |
*
|
|
| 119 |
* |
|
| 100 | 120 |
* @param urltoTest |
| 101 | 121 |
* @param alternativeUrl |
| 102 | 122 |
* @return |
| ... | ... | |
| 105 | 125 |
try {
|
| 106 | 126 |
URL url = new URL(urltoTest); |
| 107 | 127 |
if (url.getProtocol().equals("https")) {
|
| 108 |
|
|
| 109 |
//ts.setCertificateEntry(UUID.randomUUID(), cert); |
|
| 128 |
|
|
| 129 |
// ts.setCertificateEntry(UUID.randomUUID(), cert);
|
|
| 110 | 130 |
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); |
| 111 | 131 |
if (SSLContext.getDefault() != null) {
|
| 112 |
|
|
| 132 |
|
|
| 113 | 133 |
// Create a trust manager that does not validate certificate chains |
| 114 |
TrustManager[] trustAllCerts = new TrustManager[] {
|
|
| 115 |
new X509TrustManager() {
|
|
| 116 |
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
|
| 134 |
TrustManager[] trustAllCerts = new TrustManager[] {
|
|
| 135 |
new X509TrustManager() {
|
|
| 136 |
|
|
| 137 |
@Override |
|
| 138 |
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
|
| 117 | 139 |
return new java.security.cert.X509Certificate[0]; |
| 118 |
} |
|
| 119 |
public void checkClientTrusted( |
|
| 120 |
java.security.cert.X509Certificate[] certs, String authType) {
|
|
| 121 |
} |
|
| 122 |
public void checkServerTrusted( |
|
| 123 |
java.security.cert.X509Certificate[] certs, String authType) {
|
|
| 124 | 140 |
} |
| 125 |
} |
|
| 141 |
|
|
| 142 |
@Override |
|
| 143 |
public void checkClientTrusted( |
|
| 144 |
java.security.cert.X509Certificate[] certs, String authType) {}
|
|
| 145 |
|
|
| 146 |
@Override |
|
| 147 |
public void checkServerTrusted( |
|
| 148 |
java.security.cert.X509Certificate[] certs, String authType) {}
|
|
| 149 |
} |
|
| 126 | 150 |
}; |
| 127 |
|
|
| 151 |
|
|
| 128 | 152 |
// Install the all-trusting trust manager for this connection ONLY |
| 129 | 153 |
try {
|
| 130 | 154 |
SSLContext sc = SSLContext.getInstance("SSL");
|
| 131 |
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
|
| 155 |
sc.init(null, trustAllCerts, new java.security.SecureRandom()); |
|
| 132 | 156 |
connection.setSSLSocketFactory(sc.getSocketFactory()); |
| 133 |
} catch (GeneralSecurityException e) {
|
|
| 157 |
} |
|
| 158 |
catch (GeneralSecurityException e) {
|
|
| 134 | 159 |
Log.printStackTrace(e); |
| 135 |
}
|
|
| 160 |
} |
|
| 136 | 161 |
} |
| 137 |
|
|
| 162 |
|
|
| 138 | 163 |
if (connection.getResponseCode() != HttpsURLConnection.HTTP_OK) {
|
| 139 | 164 |
Log.fine(NLS.bind("HTTP Error while testing the \"{0}\" web page: {1}", urltoTest, connection.getResponseCode()));
|
| 140 | 165 |
connection.disconnect(); |
| 141 | 166 |
return alternativeUrl; |
| 142 | 167 |
} |
| 143 | 168 |
connection.disconnect(); |
| 144 |
} else {
|
|
| 169 |
} |
|
| 170 |
else {
|
|
| 145 | 171 |
url.openStream().close(); |
| 146 | 172 |
} |
| 147 |
|
|
| 148 |
} catch (Exception e) {
|
|
| 173 |
|
|
| 174 |
} |
|
| 175 |
catch (Exception e) {
|
|
| 149 | 176 |
Log.fine(NLS.bind("Error while testing the \"{0}\" web page: {1}", urltoTest, e.getMessage()));
|
| 150 | 177 |
return alternativeUrl; |
| 151 | 178 |
} |
| 152 | 179 |
return urltoTest; |
| 153 | 180 |
} |
| 154 |
|
|
| 181 |
|
|
| 155 | 182 |
/** |
| 156 | 183 |
* Openfile. |
| 157 | 184 |
* |
| ... | ... | |
| 159 | 186 |
* @return the txm browser |
| 160 | 187 |
*/ |
| 161 | 188 |
static public Object openfile(String key) {
|
| 162 |
|
|
| 189 |
|
|
| 163 | 190 |
String version = Platform.getBundle(Activator.PLUGIN_ID).getVersion().toString(); |
| 164 | 191 |
int idx = version.lastIndexOf("."); //$NON-NLS-1$
|
| 165 | 192 |
if (idx > 0) version = version.substring(0, idx); // remove the "qualifier" part |
| 166 |
|
|
| 193 |
|
|
| 167 | 194 |
String locale = Locale.getDefault().getLanguage(); |
| 168 |
|
|
| 195 |
|
|
| 169 | 196 |
if (TEXTOMETRIE.equals(key)) {
|
| 170 | 197 |
if ("fr".equals(locale)) { //$NON-NLS-1$
|
| 171 |
return OpenBrowser.openfile(URL_TEXTOMETRIE); |
|
| 172 |
} else {
|
|
| 173 |
return OpenBrowser.openfile(getValidURL(URL_TEXTOMETRIE+locale, URL_TEXTOMETRIE+"en")); //$NON-NLS-1$ |
|
| 198 |
return OpenBrowser.openfile(URL_TEXTOMETRIE); |
|
| 174 | 199 |
} |
| 175 |
} else if (FAQ.equals(key)) {
|
|
| 200 |
else {
|
|
| 201 |
return OpenBrowser.openfile(getValidURL(URL_TEXTOMETRIE + locale, URL_TEXTOMETRIE + "en")); //$NON-NLS-1$ |
|
| 202 |
} |
|
| 203 |
} |
|
| 204 |
else if (FAQ.equals(key)) {
|
|
| 176 | 205 |
return OpenBrowser.openfile("https://groupes.renater.fr/wiki/txm-users/public/faq"); //$NON-NLS-1$
|
| 177 |
} else if (CONTRIB.equals(key)) {
|
|
| 206 |
} |
|
| 207 |
else if (CONTRIB.equals(key)) {
|
|
| 178 | 208 |
return OpenBrowser.openfile("https://groupes.renater.fr/wiki/txm-users/public/contribuer"); //$NON-NLS-1$
|
| 179 |
} else if (SF_DOCS.equals(key)) {
|
|
| 209 |
} |
|
| 210 |
else if (SF_DOCS.equals(key)) {
|
|
| 180 | 211 |
if ("fr".equals(locale)) { //$NON-NLS-1$
|
| 181 |
return OpenBrowser.openfile(URL_TEXTOMETRIE+"/Documentation/#txm-manual"); |
|
| 182 |
} else {
|
|
| 183 |
return OpenBrowser.openfile(getValidURL(URL_TEXTOMETRIE+locale+"/Documentation/#txm-manual", URL_TEXTOMETRIE+"en/Documentation/#txm-manual")); //$NON-NLS-1$ |
|
| 212 |
return OpenBrowser.openfile(URL_TEXTOMETRIE + "Documentation/#txm-manual"); |
|
| 184 | 213 |
} |
| 185 |
} else if (SF.equals(key)) {
|
|
| 214 |
else {
|
|
| 215 |
return OpenBrowser.openfile(getValidURL(URL_TEXTOMETRIE + locale + "Documentation/#txm-manual", URL_TEXTOMETRIE + "en/Documentation/#txm-manual")); //$NON-NLS-1$ |
|
| 216 |
} |
|
| 217 |
} |
|
| 218 |
else if (SF.equals(key)) {
|
|
| 186 | 219 |
if ("fr".equals(locale)) { //$NON-NLS-1$
|
| 187 |
return OpenBrowser.openfile(FILESPAGES); |
|
| 188 |
} else {
|
|
| 189 |
return OpenBrowser.openfile(getValidURL(FILESPAGES+locale, URL_TEXTOMETRIE+"en")); //$NON-NLS-1$ |
|
| 220 |
return OpenBrowser.openfile(FILESPAGES); |
|
| 190 | 221 |
} |
| 191 |
} else if (TEXTOMETRIE_DOCS.equals(key)) {
|
|
| 222 |
else {
|
|
| 223 |
return OpenBrowser.openfile(getValidURL(FILESPAGES + locale, URL_TEXTOMETRIE + "en")); //$NON-NLS-1$ |
|
| 224 |
} |
|
| 225 |
} |
|
| 226 |
else if (TEXTOMETRIE_DOCS.equals(key)) {
|
|
| 192 | 227 |
if ("fr".equals(locale)) { //$NON-NLS-1$
|
| 193 |
return OpenBrowser.openfile(URL_TEXTOMETRIE+"/Documentation"); |
|
| 194 |
} else {
|
|
| 195 |
return OpenBrowser.openfile(getValidURL(URL_TEXTOMETRIE+locale+"/Documentation", URL_TEXTOMETRIE+"en/Documentation")); //$NON-NLS-1$ |
|
| 228 |
return OpenBrowser.openfile(URL_TEXTOMETRIE + "Documentation"); |
|
| 196 | 229 |
} |
| 197 |
} else if (TREETAGGER.equals(key)) {
|
|
| 230 |
else {
|
|
| 231 |
return OpenBrowser.openfile(getValidURL(URL_TEXTOMETRIE + locale + "/Documentation", URL_TEXTOMETRIE + "en/Documentation")); //$NON-NLS-1$ |
|
| 232 |
} |
|
| 233 |
} |
|
| 234 |
else if (TREETAGGER.equals(key)) {
|
|
| 198 | 235 |
if ("fr".equals(locale)) { //$NON-NLS-1$
|
| 199 |
return OpenBrowser.openfile(URL_TEXTOMETRIE+"InstallTreeTagger"); |
|
| 200 |
} else {
|
|
| 201 |
return OpenBrowser.openfile(getValidURL(URL_TEXTOMETRIE+locale+"/InstallTreeTagger/", URL_TEXTOMETRIE+"en/InstallTreeTagger")); //$NON-NLS-1$ //$NON-NLS-2$ |
|
| 236 |
return OpenBrowser.openfile(URL_TEXTOMETRIE + "InstallTreeTagger"); |
|
| 202 | 237 |
} |
| 203 |
} else if (REFMAN.equals(key)) {
|
|
| 238 |
else {
|
|
| 239 |
return OpenBrowser.openfile(getValidURL(URL_TEXTOMETRIE + locale + "/InstallTreeTagger/", URL_TEXTOMETRIE + "en/InstallTreeTagger")); //$NON-NLS-1$ //$NON-NLS-2$ |
|
| 240 |
} |
|
| 241 |
} |
|
| 242 |
else if (REFMAN.equals(key)) {
|
|
| 204 | 243 |
if ("fr".equals(locale)) { //$NON-NLS-1$
|
| 205 |
return OpenBrowser.openfile(URL_TXMMANUAL); |
|
| 206 |
} else {
|
|
| 207 |
return OpenBrowser.openfile(getValidURL(URL_TXMMANUAL+locale, URL_TXMMANUAL)); //$NON-NLS-1$ |
|
| 244 |
return OpenBrowser.openfile(URL_TXMMANUAL); |
|
| 208 | 245 |
} |
| 209 |
} else if (CORPORA.equals(key)) {
|
|
| 246 |
else {
|
|
| 247 |
return OpenBrowser.openfile(getValidURL(URL_TXMMANUAL + locale, URL_TXMMANUAL)); |
|
| 248 |
} |
|
| 249 |
} |
|
| 250 |
else if (CORPORA.equals(key)) {
|
|
| 210 | 251 |
if ("fr".equals(locale)) { //$NON-NLS-1$
|
| 211 |
return OpenBrowser.openfile(FILESPAGES+"corpora"); |
|
| 212 |
} else {
|
|
| 213 |
return OpenBrowser.openfile(getValidURL(FILESPAGES+"corpora/"+locale, URL_TXMMANUAL+"corpora/en")); //$NON-NLS-1$ |
|
| 252 |
return OpenBrowser.openfile(FILESPAGES + "corpora"); |
|
| 214 | 253 |
} |
| 215 |
}else if (PDFREFMAN.equals(key)) {
|
|
| 216 |
return OpenBrowser.openfile(FILESPAGES+"documentation/Manuel%20de%20TXM%200.8%20FR.pdf"); //$NON-NLS-1$ |
|
| 217 |
} else if (BUG.equals(key)) {
|
|
| 254 |
else {
|
|
| 255 |
return OpenBrowser.openfile(getValidURL(FILESPAGES + "corpora/" + locale, URL_TXMMANUAL + "corpora/en")); //$NON-NLS-1$ |
|
| 256 |
} |
|
| 257 |
} |
|
| 258 |
else if (PDFREFMAN.equals(key)) {
|
|
| 259 |
return OpenBrowser.openfile(FILESPAGES + "documentation/Manuel%20de%20TXM%200.8%20FR.pdf"); //$NON-NLS-1$ |
|
| 260 |
} |
|
| 261 |
else if (BUG.equals(key)) {
|
|
| 218 | 262 |
if ("fr".equals(locale)) { //$NON-NLS-1$
|
| 219 | 263 |
return OpenBrowser.openfile("https://groupes.renater.fr/wiki/txm-users/public/retours_de_bugs_logiciel"); //$NON-NLS-1$
|
| 220 |
} else {
|
|
| 264 |
} |
|
| 265 |
else {
|
|
| 221 | 266 |
return OpenBrowser.openfile("https://sourceforge.net/p/txm/feature-requests/?source=navbar"); //$NON-NLS-1$
|
| 222 | 267 |
} |
| 223 |
} else if (FEATURE.equals(key)) {
|
|
| 268 |
} |
|
| 269 |
else if (FEATURE.equals(key)) {
|
|
| 224 | 270 |
if ("fr".equals(locale)) { //$NON-NLS-1$
|
| 225 | 271 |
return OpenBrowser.openfile("https://groupes.renater.fr/wiki/txm-users/public/demande_de_fonctionnalites"); //$NON-NLS-1$
|
| 226 |
} else {
|
|
| 272 |
} |
|
| 273 |
else {
|
|
| 227 | 274 |
return OpenBrowser.openfile("http://sourceforge.net/tracker/?group_id=247041&atid=1190851"); //$NON-NLS-1$
|
| 228 | 275 |
} |
| 229 |
} else if (MAILINGLIST.equals(key)) {
|
|
| 276 |
} |
|
| 277 |
else if (MAILINGLIST.equals(key)) {
|
|
| 230 | 278 |
return OpenBrowser.openfile("https://groupes.renater.fr/sympa/subscribe/txm-users"); //$NON-NLS-1$
|
| 231 |
} else if (MACROS.equals(key)) {
|
|
| 279 |
} |
|
| 280 |
else if (MACROS.equals(key)) {
|
|
| 232 | 281 |
return OpenBrowser.openfile("https://groupes.renater.fr/wiki/txm-users/public/macros"); //$NON-NLS-1$
|
| 233 |
} else if (TXMUSERS.equals(key)) {
|
|
| 282 |
} |
|
| 283 |
else if (TXMUSERS.equals(key)) {
|
|
| 234 | 284 |
return OpenBrowser.openfile("https://groupes.renater.fr/wiki/txm-users"); //$NON-NLS-1$
|
| 235 |
} else { // no key associated, key is an URL
|
|
| 236 |
return OpenBrowser.openfile(key); //$NON-NLS-1$ |
|
| 237 | 285 |
} |
| 286 |
else { // no key associated, key is an URL
|
|
| 287 |
return OpenBrowser.openfile(key); |
|
| 288 |
} |
|
| 238 | 289 |
} |
| 239 |
|
|
| 290 |
|
|
| 240 | 291 |
public static void main(String args[]) {
|
| 241 | 292 |
String s = getValidURL("https://txm.gitpages.huma-num.fr/textometrie/files/software/TXM/0.8.1beta/", "https://txm.gitpages.huma-num.fr/textometrie/files/software/TXM/0.8.1beta");
|
| 242 | 293 |
System.out.println(s); |
Formats disponibles : Unified diff