Logo Search packages:      
Sourcecode: josm-plugins version File versions  Download package

void org::openstreetmap::josm::plugins::ywms::ImageLoader::load (  )  throws ImageLoaderException [inline, private]

Does the hard work.

It spawns a Firefox process with an HTML page that loads Yahoo imagery using Yahoo's AJAX API. Firefox must be configured to allow the "dump" method for this to work.

The image is cropped and reescaled to meet requested dimensions.

Exceptions:
ImageLoaderException When error loading the page

Definition at line 122 of file ImageLoader.java.

References cleanImages(), final_height, final_width, firefoxFiles, GECKO_DEBUG_LINE, org::openstreetmap::josm::plugins::ywms::PPM::getImage(), image, resizeImage(), and yahooUrl.

Referenced by ImageLoader().

      {
            Process browser = null;
            try 
            {
                  browser = GeckoSupport.browse(yahooUrl.toString(), true);
                  // TODO: set focus in main window
                  File imageFilePpm = null;

                  // Parse output
                  BufferedReader in = new BufferedReader( new InputStreamReader( browser.getInputStream() ) );
                  String line = in.readLine();
              while( line != null ) 
              {
                  System.out.println("YWMS::" + line);
                if( line.startsWith("new_width=") )
                {
                    final_width = (int)Math.round( Double.parseDouble( line.substring(10)) );
                }
                else if( line.startsWith("new_height=") )
                {
                    final_height = (int)Math.round( Double.parseDouble( line.substring(11)) );
                }
                  else if( line.startsWith(GECKO_DEBUG_LINE))
                  {
                        // Find out the screenshot file
                        StringTokenizer st = new StringTokenizer(line);
                        // Skip header
                        for( int i = 0; i < 5; i++) st.nextToken();
                        String url = st.nextToken();
                        String file = st.nextToken();
                        firefoxFiles.add(file);
                        
                        try 
                        {
                              URI browserUri = new URI(url);      
                              if( yahooUrl.getPath().equals(browserUri.getPath()))
                              {
                                    String status = st.nextToken();
                                    if( !"(OK)".equals(status) )
                                          throw new ImageLoaderException("Firefox couldn't load image");
                                    
                                    imageFilePpm = new File(file);
                                    break;
                              }
                              } catch (URISyntaxException e) {
                                    // Probably a mozilla "chrome://" URL. Do nothing
                              }
                  }
                  else if( line.startsWith("WYMS ERROR:") )
                  {
                        throw new ImageLoaderException("Error in JavaScript page:" + line);
                  }
                  line = in.readLine();
              }

              if( final_width == -1 && imageFilePpm == null && !firefoxFiles.isEmpty() )
              {
                  throw new ImageLoaderException("Is there any other firefox window open with same profile?");
              }
              if( final_width == -1)
              {
                  throw new ImageLoaderException("Couldn't find new dimension. Is browser.dom.window.dump.enabled set in Firefox config?");
              }
              if( imageFilePpm == null )
              {
                  throw new ImageLoaderException("Couldn't find dumped image. Is it a modern Gecko browser (i.e., firefox 1.5)?");
              }
              
            PPM ppmImage = new PPM(imageFilePpm.getAbsolutePath());
            image = ppmImage.getImage();
            cleanImages();

              resizeImage();
            } catch (IOException e) 
            {
                  throw new ImageLoaderException(e);
            }
            finally
            {
                  if( browser != null )
                      browser.destroy();
            }
      }


Generated by  Doxygen 1.6.0   Back to index