Esempio n. 1
0
 /**
  * Connects a request. and sets the requests as the browsers latest request
  *
  * @param request
  * @throws IOException
  */
 public void connect(final Request request) throws IOException {
   // sets request BEVOR connection. this enhables to find the request in
   // the protocol handlers
   this.request = request;
   try {
     Browser.waitForPageAccess(this, request);
   } catch (final InterruptedException e) {
     throw new IOException("requestIntervalTime Exception");
   }
   try {
     request.connect();
   } finally {
     if (this.isDebug()) {
       final Logger llogger = this.getLogger();
       if (llogger != null) {
         try {
           llogger.finest("\r\n" + request.printHeaders());
         } catch (final Throwable e) {
           e.printStackTrace();
           // LogSource.exception(llogger, e);
         }
       }
     }
   }
 }
Esempio n. 2
0
 public void setCookie(final String url, final String key, final String value) {
   final String host = Browser.getHost(url);
   Cookies cookies;
   if (!this.getCookies().containsKey(host) || (cookies = this.getCookies().get(host)) == null) {
     cookies = new Cookies();
     this.getCookies().put(host, cookies);
   }
   cookies.add(new Cookie(host, key, value));
 }
Esempio n. 3
0
  public void createXmlMessages() throws Exception {
    Browser.createXmlMessages();
    MMS.createXmlMessages();
    JavaApp.createXmlMessages();

    // IM should be last to generate id_name for all other applications!!!
    // set flag to avoid duplicationNAP names before calling createXmlMessages()
    // The method setNAPFlagForIMAndValidate() should be changed for new  applications
    Validator.setNAPFlagForIMAndValidate();
    IM.createXmlMessages();
  }
Esempio n. 4
0
 public void updateCookies(final Request request) {
   if (request == null) {
     return;
   }
   final String host = Browser.getHost(request.getUrl());
   Cookies cookies = this.getCookies().get(host);
   if (cookies == null) {
     cookies = new Cookies();
     this.getCookies().put(host, cookies);
   }
   cookies.add(request.getCookies());
 }
Esempio n. 5
0
 /**
  * Clears all cookies for the given url. URL has to be a valid url if url==null,all cookies were
  * cleared
  *
  * @param url
  */
 public void clearCookies(final String url) {
   if (url == null) {
     this.cookies.clear();
   }
   final String host = Browser.getHost(url);
   final Iterator<String> it = this.getCookies().keySet().iterator();
   String check = null;
   while (it.hasNext()) {
     check = it.next();
     if (check.contains(host)) {
       this.cookies.get(check).clear();
       break;
     }
   }
 }
Esempio n. 6
0
  private static synchronized void waitForPageAccess(final Browser browser, final Request request)
      throws InterruptedException {
    final String host = Browser.getHost(request.getUrl());
    try {
      Integer localLimit = null;
      Integer globalLimit = null;
      Long localLastRequest = null;
      Long globalLastRequest = null;

      if (localLimit == null && globalLimit == null) {
        return;
      }
      if (localLastRequest == null && globalLastRequest == null) {
        return;
      }
      if (localLimit != null && localLastRequest == null) {
        return;
      }
      if (globalLimit != null && globalLastRequest == null) {
        return;
      }

      if (globalLimit == null) {
        globalLimit = 0;
      }
      if (localLimit == null) {
        localLimit = 0;
      }
      if (localLastRequest == null) {
        localLastRequest = System.currentTimeMillis();
      }
      if (globalLastRequest == null) {
        globalLastRequest = System.currentTimeMillis();
      }
      final long dif =
          Math.max(
              localLimit - (System.currentTimeMillis() - localLastRequest),
              globalLimit - (System.currentTimeMillis() - globalLastRequest));

      if (dif > 0) {
        // System.out.println("Sleep " + dif + " before connect to " +
        // request.getUrl().getHost());
        Thread.sleep(dif);
        // waitForPageAccess(request);
      }
    } finally {
    }
  }
Esempio n. 7
0
  public void forwardCookies(final Request request) {
    if (request == null) {
      return;
    }
    final String host = Browser.getHost(request.getUrl());
    final Cookies cookies = this.getCookies().get(host);
    if (cookies == null) {
      return;
    }

    for (final Cookie cookie : cookies.getCookies()) {
      // Pfade sollten verarbeitet werden...TODO
      if (cookie.isExpired()) {
        continue;
      }
      request.getCookies().add(cookie);
    }
  }
Esempio n. 8
0
 /**
  * TRies to get a fuill url out of string
  *
  * @throws BrowserException
  */
 public String getURL(String string) throws BrowserException {
   if (string == null) {
     string = this.getRedirectLocation();
   }
   if (string == null) {
     throw new BrowserException("Null URL");
   }
   try {
     new URL(string);
   } catch (final Exception e) {
     if (this.request == null || this.request.getHttpConnection() == null) {
       return string;
     }
     final String base = this.getBase(string);
     if (string.startsWith("/") || string.startsWith("\\")) {
       try {
         final URL bUrl = new URL(base);
         String proto = "http://";
         if (base.startsWith("https")) {
           proto = "https://";
         }
         String portUse = "";
         if (bUrl.getDefaultPort() > 0
             && bUrl.getPort() > 0
             && bUrl.getDefaultPort() != bUrl.getPort()) {
           portUse = ":" + bUrl.getPort();
         }
         string = proto + new URL(base).getHost() + portUse + string;
       } catch (final MalformedURLException e1) {
         e1.printStackTrace();
       }
     } else {
       string = base + string;
     }
   }
   return Browser.correctURL(Encoding.urlEncode_light(string));
 }
  void init() {
    if (MozillaVersion.CheckVersion(MozillaVersion.VERSION_XR10)) {
      /*
       * In XULRunner versions > 4, sending WM_GETDLGCODE to a WM_KEYDOWN's MSG hwnd answers 0
       * instead of the expected DLGC_WANTALLKEYS.  This causes the default traversal framework
       * perform traversals outside of the Browser when it should not.  Hook a Traverse listener
       * to work around these problems.
       */
      browser.addListener(
          SWT.Traverse,
          event -> {
            switch (event.detail) {
              case SWT.TRAVERSE_RETURN:
                {
                  /* always veto the traversal */
                  event.doit = false;
                  break;
                }
              case SWT.TRAVERSE_TAB_NEXT:
              case SWT.TRAVERSE_TAB_PREVIOUS:
                {
                  /* veto the traversal whenever an element in the browser has focus */
                  long /*int*/[] result = new long /*int*/[1];
                  int rc = XPCOM.NS_GetServiceManager(result);
                  if (rc != XPCOM.NS_OK) Mozilla.error(rc);
                  if (result[0] == 0) Mozilla.error(XPCOM.NS_NOINTERFACE);
                  nsIServiceManager serviceManager = new nsIServiceManager(result[0]);
                  result[0] = 0;
                  byte[] aContractID =
                      MozillaDelegate.wcsToMbcs(null, XPCOM.NS_FOCUSMANAGER_CONTRACTID, true);
                  rc =
                      serviceManager.GetServiceByContractID(
                          aContractID,
                          IIDStore.GetIID(nsIFocusManager.class, MozillaVersion.VERSION_XR10),
                          result);
                  serviceManager.Release();

                  if (rc == XPCOM.NS_OK && result[0] != 0) {
                    nsIFocusManager focusManager = new nsIFocusManager(result[0]);
                    result[0] = 0;
                    rc = focusManager.GetFocusedElement(result);
                    focusManager.Release();
                    event.doit = result[0] == 0;
                    if (rc == XPCOM.NS_OK && result[0] != 0) {
                      new nsISupports(result[0]).Release();
                    }
                  }
                  break;
                }
            }
          });

      /* children created in getSiteHandle() should be destroyed whenever a page is left */
      browser.addLocationListener(
          new LocationAdapter() {
            @Override
            public void changing(LocationEvent event) {
              Iterator<Composite> it = childWindows.iterator();
              while (it.hasNext()) {
                it.next().dispose();
              }
              childWindows.clear();
            }
          });
    }
  }
Esempio n. 10
0
 public static String getHost(final String url) {
   return Browser.getHost(url, false);
 }
Esempio n. 11
0
 public String getHost() {
   return this.request == null ? null : Browser.getHost(this.request.getUrl(), false);
 }
Esempio n. 12
0
 public void getDownload(final File file, final String urlString) throws IOException {
   final HTTPConnectionImpl con = this.openGetConnection(URLDecoder.decode(urlString, "UTF-8"));
   Browser.download(file, con);
 }
Esempio n. 13
0
 /**
  * Returns the host for url. input: http://srv2.bluehost.to/dsdsf ->out bluehost.to
  *
  * @param url
  * @return
  * @throws MalformedURLException
  */
 public static String getHost(final URL url) {
   return Browser.getHost(url.getHost());
 }
  @Override
  public void start(Stage stage) {

    // create temporary file outside of application

    // create the scene

    stage.setTitle("CSV visualization");
    Browser b = new Browser();
    BorderPane sp = new BorderPane();
    VBox bottomStack = new VBox();

    FileChooser csvfinder = new FileChooser();
    ExtensionFilter filter = new ExtensionFilter("csv only", "*.csv");
    csvfinder.getExtensionFilters().add(filter);
    csvfinder.setTitle("Find CSV File");

    // initializing bounds and panes
    VBox topStack = new VBox(); // Creates a container to hold all Menu Objects.
    MenuBar mainMenu = new MenuBar(); // Creates our main menu to hold our Sub-Menus.
    ToolBar toolBar = new ToolBar(); // Creates our tool-bar to hold the buttons.
    topStack.getChildren().add(mainMenu);
    topStack.getChildren().add(toolBar);

    Menu file = new Menu("File");
    MenuItem openFile = new MenuItem("Open CSV File");
    MenuItem exitApp = new MenuItem("Exit");
    file.getItems().addAll(openFile, exitApp);

    // Create and add the "Edit" sub-menu options.
    Menu edit = new Menu("Edit");
    MenuItem properties = new MenuItem("Save Frame Image");
    edit.getItems().add(properties);

    // Create and add the "Help" sub-menu options.
    Menu help = new Menu("Help");
    MenuItem visitWebsite = new MenuItem("About");
    help.getItems().add(visitWebsite);
    mainMenu.getMenus().addAll(file, edit, help);

    Options rightStack = new Options(b);
    Label file_notif = new Label();
    file_notif.setText("No file");
    file_notif.setFont(Font.font("Tahoma", FontWeight.NORMAL, 15));
    topStack.setAlignment(Pos.CENTER_LEFT);
    bottomStack.getChildren().add(file_notif);

    // aligning boxes
    b.refresh();
    sp.setCenter(b);

    sp.setTop(topStack);
    sp.setRight(rightStack);
    sp.setBottom(bottomStack);
    properties.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent event) {
            WritableImage image = b.snapshot(new SnapshotParameters(), null);
            FileChooser chooser = new FileChooser();
            // TODO: probably use a file chooser here
            File file = chooser.showSaveDialog(stage);

            try {
              ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);
            } catch (IOException e) {
              // TODO: handle exception here
            }
          }
        });

    visitWebsite.setOnAction(
        new EventHandler<ActionEvent>() {
          public void handle(ActionEvent event) {
            Stage stage = new Stage();
            // Fill stage with content
            StackPane sp = new StackPane();
            Label ta = new Label();
            ta.minHeight(400);
            ta.minWidth(400);

            ta.setText(
                "This is a tool that was developed by PowerAmerica to help "
                    + "visualize multidimensional CSV files on a 2D graph. It's "
                    + "initial use was visualization of the relationships between "
                    + "the specifications of different electrical components as shown"
                    + " by the sample data. Use the file menu option to upload any CSV file and use"
                    + " the option bars on the right pane to control the dimensions "
                    + "that you want to put on the graph.");
            ta.setWrapText(true);
            ta.setPadding(new Insets(10, 10, 10, 10));
            sp.setAlignment(Pos.TOP_LEFT);
            sp.getChildren().add(ta);

            Scene s = new Scene(sp, 400, 400);
            stage.setScene(s);

            stage.show();
          }
        });

    exitApp.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent event) {
            System.exit(0);
          }
        });

    // button event handlers
    openFile.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent event) {
            File file = csvfinder.showOpenDialog(stage);
            System.out.println(file.getName());

            file_notif.setText(file.getName());
            // write name to file for javascript to use

            FTPClient client = new FTPClient();
            FileInputStream fis = null;

            try {
              client.connect("ftp.enloecompsci.com");
              client.login("southpawac", "**********");
              client.changeWorkingDirectory("/public_html/PowerAmerica/CSV_FILES");
              System.out.print(client.getReplyString());
              fis = new FileInputStream(file.getPath());
              client.storeFile(file.getName(), fis);
              b.fileName = file.getName();
              client.logout();
            } catch (IOException e) {
              e.printStackTrace();
            } finally {
              try {
                if (fis != null) {
                  fis.close();
                }
                client.disconnect();
              } catch (IOException e) {
                e.printStackTrace();
              }
            }

            BufferedReader br;
            try {
              br = new BufferedReader(new FileReader(new File(file.getPath())));
              String options;
              if ((options = br.readLine()) != null) {
                rightStack.resetOptions(options.split(","));
                rightStack.setSizes();
              }

            } catch (FileNotFoundException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }
        });

    scene = new Scene(sp, 1000, 850, Color.web("#666970"));
    stage.setScene(scene);
    stage.show();
  }