(String urlString, String resourceName)
| 4948 | } |
| 4949 | |
| 4950 | public void showHelpFrame(String urlString, String resourceName) { |
| 4951 | final URL url; |
| 4952 | if(resourceName == null) { |
| 4953 | resourceName = "unknown"; |
| 4954 | } |
| 4955 | if(urlString != null && !urlString.startsWith("http://") |
| 4956 | && !urlString.startsWith("https://") |
| 4957 | && !urlString.startsWith("file://")) { |
| 4958 | urlString = "http://gate.ac.uk/userguide/" + urlString; |
| 4959 | } |
| 4960 | try { |
| 4961 | |
| 4962 | URL baseUrl = new URL(urlString); |
| 4963 | |
| 4964 | if(baseUrl.toString().startsWith("http://gate.ac.uk/userguide/")) { |
| 4965 | StringBuilder actualURL = new StringBuilder(baseUrl.toString()); |
| 4966 | // add gateVersion=... to the end of the URL |
| 4967 | int insertPoint = actualURL.length(); |
| 4968 | if(baseUrl.getRef() != null) { |
| 4969 | // adjust for a #something on the end |
| 4970 | insertPoint -= baseUrl.getRef().length() + 1; |
| 4971 | } |
| 4972 | if(baseUrl.getQuery() == null) { |
| 4973 | actualURL.insert(insertPoint, '?'); |
| 4974 | } else { |
| 4975 | actualURL.insert(insertPoint, "&"); |
| 4976 | } |
| 4977 | actualURL.insert(insertPoint + 1, "gateVersion=" + gate.Main.version); |
| 4978 | |
| 4979 | url = new URL(actualURL.toString()); |
| 4980 | } else { |
| 4981 | url = baseUrl; |
| 4982 | } |
| 4983 | } catch(MalformedURLException e) { |
| 4984 | JOptionPane.showMessageDialog(MainFrame.this, |
| 4985 | (urlString == null) |
| 4986 | ? "There is no help page for this resource !\n\n" |
| 4987 | + "Find the developer of the resource:\n" + resourceName |
| 4988 | + "\n" + "and force him/her to put one." |
| 4989 | : "The URL of the page for " + resourceName + " is invalid.\n" |
| 4990 | + urlString, |
| 4991 | "GATE", JOptionPane.INFORMATION_MESSAGE); |
| 4992 | return; |
| 4993 | } |
| 4994 | Runnable runnable = new Runnable() { |
| 4995 | @Override |
| 4996 | public void run() { |
| 4997 | try { |
| 4998 | |
| 4999 | Desktop.getDesktop().browse(url.toURI()); |
| 5000 | |
| 5001 | } catch(SecurityException se) { |
| 5002 | JOptionPane.showMessageDialog(instance, se.getMessage(), "Help Error", |
| 5003 | JOptionPane.ERROR_MESSAGE); |
| 5004 | log.error("Help browser Error", se); |
| 5005 | } catch(URISyntaxException | IOException ie) { |
| 5006 | JOptionPane.showMessageDialog(instance, ie.getMessage(), "Help Error", |
| 5007 | JOptionPane.ERROR_MESSAGE); |
no test coverage detected