Package org.lobobrowser.html

Examples of org.lobobrowser.html.FormInput


        }
        else {
          newUrlBuffer.append("&");
        }
        for(int i = 0; i < formInputs.length; i++) {
          FormInput parameter = formInputs[i];
          String name = parameter.getName();
          String encName = URLEncoder.encode(name, "UTF-8");
          if(parameter.isText()) {
            if(firstParam) {
              firstParam = false;
            }
            else {
              newUrlBuffer.append("&");
            }
            String valueStr = parameter.getTextValue();
            String encValue = URLEncoder.encode(valueStr, "UTF-8");
            newUrlBuffer.append(encName);
            newUrlBuffer.append("=");
            newUrlBuffer.append(encValue);
          }
        } 
        resolvedURL = new java.net.URL(newUrlBuffer.toString());
      }
      else {
        resolvedURL = action;
      }
      URL urlForLoading;
      if(resolvedURL.getProtocol().equals("file")) {
        // Remove query so it works.
        try {
          String ref = action.getRef();
          String refText = ref == null || ref.length() == 0 ? "" : "#" + ref;
          urlForLoading = new URL(resolvedURL.getProtocol(), action.getHost(), action.getPort(), action.getPath() + refText);
        } catch(java.net.MalformedURLException throwable) {
          urlForLoading = action;
        }
      }
      else {
        urlForLoading = resolvedURL;
      }
      // Using potentially different URL for loading.
      boolean isPost = "POST".equals(actualMethod);
      URLConnection connection = urlForLoading.openConnection();
      connection.setRequestProperty("User-Agent", getUserAgentContext().getUserAgent());
      connection.setRequestProperty("Cookie", "");
      HttpURLConnection hc = null;
      if (connection instanceof HttpURLConnection) {
        hc = (HttpURLConnection) connection;
        hc.setRequestMethod(actualMethod);
        // Do not follow redirects
        hc.setInstanceFollowRedirects(false);
      }
      if(isPost) {
        connection.setDoOutput(true);
        ByteArrayOutputStream bufOut = new ByteArrayOutputStream();
        boolean firstParam = true;
        if(formInputs != null) {
          for(int i = 0; i < formInputs.length; i++) {
            FormInput parameter = formInputs[i];
            String name = parameter.getName();
            String encName = URLEncoder.encode(name, "UTF-8");
            if(parameter.isText()) {
              if(firstParam) {
                firstParam = false;
              }
              else {
                bufOut.write((byte) '&');                     
              }
              String valueStr = parameter.getTextValue();
              String encValue = URLEncoder.encode(valueStr, "UTF-8");
              bufOut.write(encName.getBytes("UTF-8"));
              bufOut.write((byte) '=');
              bufOut.write(encValue.getBytes("UTF-8"));
            }
View Full Code Here


  {
    UserAgentContext uacontext = new MozillaUserAgent();
    LocalHtmlRendererContext rcontext = new LocalHtmlRendererContext(uacontext);
    //rcontext.navigate("http://www.google.com/search");
   
    FormInput submitInput1 = new FormInput("hl", "en");
    FormInput submitInput2 = new FormInput("q", "student");
    FormInput submitInput3 = new FormInput("aqi", "g7g-s1g2");
   
    URL url = org.lobobrowser.util.Urls.guessURL("http://www.google.com/search");
   
    rcontext.submitForm("GET", url, "_this", null, new FormInput[] {
        submitInput1, submitInput2, submitInput3
View Full Code Here

     
      conceptName = breakCapitalizedConcepts(conceptName.replace("_", " ")," ");
     
      Logger.getLogger(Processor.class.getName()).info("Google number of results for " + conceptName);
     
      FormInput submitInput1 = new FormInput("hl", "en");
      FormInput submitInput2 = new FormInput("q", conceptName);
      FormInput submitInput3 = new FormInput("aqi", "g7g-s1g2");
     
      URL url = org.lobobrowser.util.Urls.guessURL(SEARCH_STRING);
     
      rcontext.submitForm("GET", url, "_this", null, new FormInput[] {
          submitInput1, submitInput2, submitInput3
View Full Code Here

TOP

Related Classes of org.lobobrowser.html.FormInput

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.