Package net.matuschek.http

Examples of net.matuschek.http.ExtendedURL


   * (e.g. from a DOM parser or HTML Tidy)
   *
   * @return a form filled with values or null, if no form handler was found
   */
  public ExtendedURL fillForm(URL baseURL, Element form) {
    ExtendedURL eurl = new ExtendedURL();
    String formURL = form.getAttribute("action");
    String type = form.getAttribute("method");
    FormHandler handler;
    URL absoluteFormURL = null;

    try {
      absoluteFormURL = new URL(baseURL, formURL);
    } catch( MalformedURLException e) {
      log.info("MalformedURLException in fillForm(): "+e.getMessage());
    }

    if (! form.getNodeName().equals("form")) {
      log.error("not a form !");
      return null;
    }

    handler = getFormHandler(absoluteFormURL.toString());
    if (handler == null) {
      log.debug("found no form handler for URL "+formURL);
      return null;
    }

    if (type.equalsIgnoreCase("get")) {
      eurl.setRequestMethod(HttpConstants.GET);
    } else if (type.equalsIgnoreCase("post")) {
      eurl.setRequestMethod(HttpConstants.POST);
    } else if (type.equals("")) {
      // workaround for sites that have no "action" attribute
      // in their forms, like Google :-(
      eurl.setRequestMethod(HttpConstants.GET);
    } else {
      log.debug("method "+type+" unknown");
      return null;
    }

    try {
      eurl.setURL(absoluteFormURL);
    } catch (Exception e) {
      log.debug("error calculating URL: "+e.getMessage());
    }

    // clear the old data in this form handler
    handler.clearValues();

    // okay, now fill the form fields ...
    collectInputFields(form, handler);
    eurl.setParams(handler.getParamString());
   
    return eurl;
  }
View Full Code Here


         
          if (hasFormHandlers) {
            // add forms
            Vector forms = htmlDoc.getElements("form");
            for (int i = 0; i < forms.size(); i++) {
              ExtendedURL eurl = formFiller.fillForm(u, (Element) forms.elementAt(i));
              if (eurl != null) {
                RobotTask newTask = createRobotTask(eurl.getURL(), depth - 1, u.toString());
                newTask.setParamString(eurl.getParams());
                newTask.setMethod(eurl.getRequestMethod());
                addTask(newTask);
              }
            }
          }
 
View Full Code Here

TOP

Related Classes of net.matuschek.http.ExtendedURL

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.