Example #1
0
 /**
  * Fetches the content of a help topic from the JOSM wiki.
  *
  * @param helpTopicUrl the absolute help topic URL
  * @return the content, filtered and transformed for being displayed in the internal help browser
  * @throws HelpContentReaderException thrown if problem occurs
  * @throws MissingHelpContentException thrown if this helpTopicUrl doesn't point to an existing
  *     Wiki help page
  */
 public String fetchHelpTopicContent(String helpTopicUrl, boolean dotest)
     throws HelpContentReaderException {
   if (helpTopicUrl == null) throw new MissingHelpContentException(helpTopicUrl);
   HttpURLConnection con = null;
   try {
     URL u = new URL(helpTopicUrl);
     con = Utils.openHttpConnection(u);
     con.connect();
     try (BufferedReader in =
         new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) {
       return prepareHelpContent(in, dotest, u);
     }
   } catch (MalformedURLException e) {
     throw new HelpContentReaderException(e);
   } catch (IOException e) {
     HelpContentReaderException ex = new HelpContentReaderException(e);
     if (con != null) {
       try {
         ex.setResponseCode(con.getResponseCode());
       } catch (IOException e1) {
         // ignore
       }
     }
     throw ex;
   }
 }
Example #2
0
 /**
  * Loads a help topic given by a relative help topic name (i.e. "/Action/New")
  *
  * <p>First tries to load the language specific help topic. If it is missing, tries to load the
  * topic in english.
  *
  * @param relativeHelpTopic the relative help topic
  */
 protected void loadRelativeHelpTopic(String relativeHelpTopic) {
   String url = HelpUtil.getHelpTopicUrl(HelpUtil.buildAbsoluteHelpTopic(relativeHelpTopic));
   String content = null;
   try {
     content = reader.fetchHelpTopicContent(url, true);
   } catch (MissingHelpContentException e) {
     url =
         HelpUtil.getHelpTopicUrl(
             HelpUtil.buildAbsoluteHelpTopic(relativeHelpTopic, Locale.ENGLISH));
     try {
       logger.info("fetching url: " + url);
       content = reader.fetchHelpTopicContent(url, true);
     } catch (MissingHelpContentException e1) {
       this.url = url;
       handleMissingHelpContent(relativeHelpTopic);
       return;
     } catch (HelpContentReaderException e1) {
       e1.printStackTrace();
       handleHelpContentReaderException(relativeHelpTopic, e1);
       return;
     }
   } catch (HelpContentReaderException e) {
     e.printStackTrace();
     handleHelpContentReaderException(relativeHelpTopic, e);
     return;
   }
   help.setText(content);
   history.setCurrentUrl(url);
   this.url = url;
   scrollToTop();
 }
Example #3
0
 /**
  * Loads a help topic given by an absolute help topic name, i.e. "/De:Help/Action/New"
  *
  * @param absoluteHelpTopic the absolute help topic name
  */
 protected void loadAbsoluteHelpTopic(String absoluteHelpTopic) {
   String url = HelpUtil.getHelpTopicUrl(absoluteHelpTopic);
   String content = null;
   try {
     content = reader.fetchHelpTopicContent(url, true);
   } catch (MissingHelpContentException e) {
     this.url = url;
     handleMissingHelpContent(absoluteHelpTopic);
     return;
   } catch (HelpContentReaderException e) {
     e.printStackTrace();
     handleHelpContentReaderException(absoluteHelpTopic, e);
     return;
   }
   loadTopic(content);
   history.setCurrentUrl(url);
   this.url = url;
 }
Example #4
0
 /**
  * Displays a error page if a help topic couldn't be loaded because of network or IO error.
  *
  * @param relativeHelpTopic the help topic
  * @param e the exception
  */
 protected void handleHelpContentReaderException(
     String relativeHelpTopic, HelpContentReaderException e) {
   String message =
       tr(
           "<html><p class=\"error-header\">Error when retrieving help information</p>"
               + "<p class=\"error-body\">The content for the help topic <strong>{0}</strong> could "
               + "not be loaded. The error message is (untranslated):<br>"
               + "<tt>{1}</tt>"
               + "</p></html>",
           relativeHelpTopic, e.toString());
   loadTopic(message);
 }
Example #5
0
 /**
  * Loads a help topic given by a relative help topic name (i.e. "/Action/New")
  *
  * <p>First tries to load the language specific help topic. If it is missing, tries to load the
  * topic in English.
  *
  * @param relativeHelpTopic the relative help topic
  */
 protected void loadRelativeHelpTopic(String relativeHelpTopic) {
   String url =
       HelpUtil.getHelpTopicUrl(
           HelpUtil.buildAbsoluteHelpTopic(relativeHelpTopic, LocaleType.DEFAULTNOTENGLISH));
   String content = null;
   try {
     content = reader.fetchHelpTopicContent(url, true);
   } catch (MissingHelpContentException e) {
     url =
         HelpUtil.getHelpTopicUrl(
             HelpUtil.buildAbsoluteHelpTopic(relativeHelpTopic, LocaleType.BASELANGUAGE));
     try {
       content = reader.fetchHelpTopicContent(url, true);
     } catch (MissingHelpContentException e1) {
       url =
           HelpUtil.getHelpTopicUrl(
               HelpUtil.buildAbsoluteHelpTopic(relativeHelpTopic, LocaleType.ENGLISH));
       try {
         content = reader.fetchHelpTopicContent(url, true);
       } catch (MissingHelpContentException e2) {
         this.url = url;
         handleMissingHelpContent(relativeHelpTopic);
         return;
       } catch (HelpContentReaderException e2) {
         e2.printStackTrace();
         handleHelpContentReaderException(relativeHelpTopic, e2);
         return;
       }
     } catch (HelpContentReaderException e1) {
       e1.printStackTrace();
       handleHelpContentReaderException(relativeHelpTopic, e1);
       return;
     }
   } catch (HelpContentReaderException e) {
     e.printStackTrace();
     handleHelpContentReaderException(relativeHelpTopic, e);
     return;
   }
   loadTopic(content);
   history.setCurrentUrl(url);
   this.url = url;
 }