Example usage for org.apache.commons.configuration DataConfiguration getString

List of usage examples for org.apache.commons.configuration DataConfiguration getString

Introduction

In this page you can find the example usage for org.apache.commons.configuration DataConfiguration getString.

Prototype

public String getString(String key) 

Source Link

Usage

From source file:org.freaknet.gtrends.api.GoogleAuthenticator.java

/**
 * Login in Google.//from   w  w w .  java 2  s.c o m
 *
 * @param galx The GALX id
 * @return <code>true</code> if login was successful
 * @throws GoogleAuthenticatorException
 */
private boolean login(String galx) throws GoogleAuthenticatorException {
    _isLoggedIn = false;

    try {
        DataConfiguration config = GoogleConfigurator.getConfiguration();

        HttpPost httpPost = new HttpPost(config.getString("google.auth.loginAuthenticate"));
        GoogleUtils.setupHttpRequestDefaults(httpPost);
        httpPost.setEntity(new UrlEncodedFormEntity(setupFormInputs(config, galx), HTTP.UTF_8));
        HttpResponse response = _httpClient.execute(httpPost);
        GoogleUtils.toString(response.getEntity().getContent());
        httpPost.releaseConnection();
    } catch (UnsupportedEncodingException ex) {
        throw new GoogleAuthenticatorException(ex);
    } catch (ClientProtocolException ex) {
        throw new GoogleAuthenticatorException(ex);
    } catch (IOException ex) {
        throw new GoogleAuthenticatorException(ex);
    } catch (ConfigurationException ex) {
        throw new GoogleAuthenticatorException(ex);
    }

    _isLoggedIn = true;
    return _isLoggedIn;
}

From source file:org.freaknet.gtrends.api.GoogleAuthenticator.java

/**
 *
 * @param config/*w w  w. ja  va2  s  .co m*/
 * @param galx
 * @return
 */
private List<NameValuePair> setupFormInputs(DataConfiguration config, String galx) {
    List<NameValuePair> formInputs = new ArrayList<NameValuePair>();
    formInputs.add(new BasicNameValuePair(config.getString("google.auth.input.email"), _username));
    formInputs.add(new BasicNameValuePair(config.getString("google.auth.input.passwd"), _passwd));

    formInputs.add(new BasicNameValuePair(config.getString("google.auth.input.galx"), galx));

    return formInputs;
}

From source file:org.freaknet.gtrends.api.GoogleTrendsRequest.java

/**
 * Build the <code>HttpRequestBase</code> with the provided parameters.
 *
 * @return the built request//from   www . j  a  v  a  2 s .  c  om
 * @throws org.freaknet.gtrends.api.exceptions.GoogleTrendsRequestException
 */
public HttpRequestBase build() throws GoogleTrendsRequestException {
    HttpRequestBase request = null;
    try {
        DataConfiguration config = GoogleConfigurator.getConfiguration();
        builder = new URIBuilder(config.getString("google.trends.url"));
        setupDefaultsParameters();
        builder.setParameter(OPT_Q, _q);

        if (_geo != null) {
            builder.setParameter(OPT_GEO, _geo);
        }

        /* Google Trends does not support spaces encoded as '+' hence we need to 
         * replace all '+' with '%20'. This implementation can be improved: only
         * '+' in the query parameter should be replaced. However I did not figure
         * out how to make it in a cleaner way, probably URIBuilder should be 
         * replaced with something custom
         */
        String uriString = builder.build().toString(); //.replaceAll("\\+","%20");
        request = new HttpGet(uriString);
        GoogleUtils.setupHttpRequestDefaults(request);
    } catch (URISyntaxException ex) {
        throw new GoogleTrendsRequestException(ex);
    } catch (ConfigurationException ex) {
        throw new GoogleTrendsRequestException(ex);
    }

    return request;
}

From source file:org.freaknet.gtrends.api.GoogleUtils.java

/**
 * Setup the <code>HttpRequestBase</code> r with default headers and HTTP
 * parameters.//  www . j a  va 2 s .  c o m
 *
 * @param r <code>HttpRequestBase</code> to setup
 * @throws org.apache.commons.configuration.ConfigurationException
 */
public static void setupHttpRequestDefaults(HttpRequestBase r) throws ConfigurationException {
    DataConfiguration config = GoogleConfigurator.getConfiguration();

    //r.addHeader("Content-type", config.getString("request.default.content-type"));
    r.addHeader("User-Agent", config.getString("request.default.user-agent"));
    r.addHeader("Accept", config.getString("request.default.accept"));
    r.addHeader("Accept-Language", config.getString("request.default.accept-language"));
    r.addHeader("Accept-Encoding", config.getString("request.default.accept-encoding"));
    r.addHeader("Connection", config.getString("request.default.connection"));

}

From source file:pl.otros.vfs.browser.favorit.FavoritesUtils.java

public static List<Favorite> loadFromProperties(DataConfiguration conf) {
    ArrayList<Favorite> list = new ArrayList<Favorite>();
    int count = conf.getInt("favorites.count", 0);
    LOGGER.info("Loading favorites {}", count);
    for (int i = 0; i < count; i++) {
        String name = conf.getString(String.format("favorite.item_%d.name", i));
        String url = conf.getString(String.format("favorite.item_%d.url", i));
        Favorite favorite = new Favorite(name, url, Type.USER);
        list.add(favorite);/*from  w w  w. java2 s .  co  m*/
    }
    return list;
}