Changeset 3043 in josm for trunk/src/org


Ignore:
Timestamp:
2010-02-25T18:17:49+01:00 (14 years ago)
Author:
stoecker
Message:

fix #4461 - external pages in Help browser wrong

Location:
trunk/src/org/openstreetmap/josm/gui/help
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/help/HelpBrowser.java

    r2918 r3043  
    273273        String content = null;
    274274        try {
    275             content = reader.fetchHelpTopicContent(url);
     275            content = reader.fetchHelpTopicContent(url, true);
    276276        } catch(MissingHelpContentException e) {
    277277            url = HelpUtil.getHelpTopicUrl(HelpUtil.buildAbsoluteHelpTopic(relativeHelpTopic, Locale.ENGLISH));
    278278            try {
    279279                logger.info("fetching url: " + url);
    280                 content = reader.fetchHelpTopicContent(url);
     280                content = reader.fetchHelpTopicContent(url, true);
    281281            } catch(MissingHelpContentException e1) {
    282282                handleMissingHelpContent(relativeHelpTopic);
     
    308308        String content = null;
    309309        try {
    310             content = reader.fetchHelpTopicContent(url);
     310            content = reader.fetchHelpTopicContent(url, true);
    311311        } catch(MissingHelpContentException e) {
    312312            handleMissingHelpContent(absoluteHelpTopic);
     
    342342            try {
    343343                this.url = url;
    344                 help.setPage(url);
    345             } catch(IOException e) {
     344                String content = reader.fetchHelpTopicContent(url, false);
     345                help.setText(content);
     346                history.setCurrentUrl(url);
     347                this.url = url;
     348                scrollToTop();
     349            } catch(Exception e) {
    346350                HelpAwareOptionPane.showOptionDialog(
    347351                        Main.parent,
  • trunk/src/org/openstreetmap/josm/gui/help/HelpBrowserHistory.java

    r2715 r3043  
    5050
    5151    public void setCurrentUrl(String url) {
    52         if (historyPos == history.size() -1) {
     52        boolean add=true;
     53
     54        if (historyPos >= 0 && historyPos < history.size() && history.get(historyPos).toString().equals(url.toString())) {
     55            add = false;
     56        } else if (historyPos == history.size() -1) {
    5357            // do nothing just append
    5458        } else if (historyPos ==0 && history.size() > 0) {
     
    5963            history = new ArrayList<String>();
    6064        }
    61         history.add(url);
    62         historyPos = history.size()-1;
     65        if(add)
     66        {
     67          history.add(url);
     68          historyPos = history.size()-1;
     69        }
    6370        setChanged();
    6471        notifyObservers();
  • trunk/src/org/openstreetmap/josm/gui/help/HelpContentReader.java

    r2900 r3043  
    4545     * @throws MissingHelpContentException thrown if this helpTopicUrl doesn't point to an existing Wiki help page
    4646     */
    47     public String fetchHelpTopicContent(String helpTopicUrl) throws HelpContentReaderException {
     47    public String fetchHelpTopicContent(String helpTopicUrl, boolean dotest) throws HelpContentReaderException {
    4848        URL url = null;
    4949        HttpURLConnection con = null;
     
    5454            con.connect();
    5555            in = new BufferedReader(new InputStreamReader(con.getInputStream(),"utf-8"));
    56             return prepareHelpContent(in);
     56            return prepareHelpContent(in, dotest);
    5757        } catch(MalformedURLException e) {
    5858            throw new HelpContentReaderException(e);
     
    9090     * @throws MissingHelpContentException thrown, if the content read isn't a help page
    9191     */
    92     protected String prepareHelpContent(BufferedReader in) throws HelpContentReaderException {
     92    protected String prepareHelpContent(BufferedReader in, boolean dotest) throws HelpContentReaderException {
    9393        boolean isInContent = false;
    9494        boolean isInTranslationsSideBar = false;
    9595        boolean isExistingHelpPage = false;
     96        StringBuffer sball = new StringBuffer();
    9697        StringBuffer sb = new StringBuffer();
    9798        try {
    9899            for (String line = in.readLine(); line != null; line = in.readLine()) {
     100                sball.append(line);
     101                sball.append("\n");
    99102                if (line.contains("<div id=\"searchable\">")) {
    100103                    isInContent = true;
     
    130133            throw new HelpContentReaderException(e);
    131134        }
     135        if(!dotest && sb.length() == 0)
     136            sb = sball;
     137        else if (dotest && !isExistingHelpPage)
     138            throw new MissingHelpContentException();
    132139        sb.insert(0, "<html>");
    133140        sb.append("<html>");
    134         if (! isExistingHelpPage)
    135             throw new MissingHelpContentException();
    136141        return sb.toString();
    137142    }
Note: See TracChangeset for help on using the changeset viewer.