Example #1
0
  public Document HTMLGetAuthor(String html, String url, AlchemyAPI_Params params)
      throws IOException, SAXException, ParserConfigurationException, XPathExpressionException {
    CheckHTML(html, url);

    params.setHtml(html);
    params.setUrl(url);

    return POST("HTMLGetAuthor", "html", params);
  }
Example #2
0
  public Document URLGetAuthor(String url, AlchemyAPI_Params params)
      throws IOException, SAXException, ParserConfigurationException, XPathExpressionException {
    CheckURL(url);

    params.setUrl(url);

    return GET("URLGetAuthor", "url", params);
  }
Example #3
0
  public Document TextGetTextSentiment(String text, AlchemyAPI_Params params)
      throws IOException, SAXException, ParserConfigurationException, XPathExpressionException {
    CheckText(text);

    params.setText(text);

    return POST("TextGetTextSentiment", "text", params);
  }
Example #4
0
  private Document GET(String callName, String callPrefix, AlchemyAPI_Params params)
      throws IOException, SAXException, ParserConfigurationException, XPathExpressionException {
    StringBuilder uri = new StringBuilder();
    uri.append(_requestUri)
        .append(callPrefix)
        .append('/')
        .append(callName)
        .append('?')
        .append("apikey=")
        .append(this._apiKey);
    uri.append(params.getParameterString());

    URL url = new URL(uri.toString());
    HttpURLConnection handle = (HttpURLConnection) url.openConnection();
    handle.setDoOutput(true);

    return doRequest(handle, params.getOutputMode());
  }
Example #5
0
  private Document POST(String callName, String callPrefix, AlchemyAPI_Params params)
      throws IOException, SAXException, ParserConfigurationException, XPathExpressionException {
    URL url = new URL(_requestUri + callPrefix + "/" + callName);

    HttpURLConnection handle = (HttpURLConnection) url.openConnection();
    handle.setDoOutput(true);

    StringBuilder data = new StringBuilder();

    data.append("apikey=").append(this._apiKey);
    data.append(params.getParameterString());

    handle.addRequestProperty("Content-Length", Integer.toString(data.length()));

    DataOutputStream ostream = new DataOutputStream(handle.getOutputStream());
    ostream.write(data.toString().getBytes());
    ostream.close();

    return doRequest(handle, params.getOutputMode());
  }