@Override
  public String toString() {
    StringBuilder result = new StringBuilder();
    for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) {
      if (result.length() > 0) result.append("&");

      result.append(entry.getKey());
      result.append("=");
      result.append(entry.getValue());
    }

    for (ConcurrentHashMap.Entry<String, FileWrapper> entry : fileParams.entrySet()) {
      if (result.length() > 0) result.append("&");

      result.append(entry.getKey());
      result.append("=");
      result.append("FILE");
    }

    for (ConcurrentHashMap.Entry<String, ArrayList<String>> entry : urlParamsWithArray.entrySet()) {
      if (result.length() > 0) result.append("&");

      ArrayList<String> values = entry.getValue();
      for (String value : values) {
        if (values.indexOf(value) != 0) result.append("&");
        result.append(entry.getKey());
        result.append("=");
        result.append(value);
      }
    }

    return result.toString();
  }
  /** Returns an HttpEntity containing all request parameters */
  public HttpEntity getEntity() {
    HttpEntity entity = null;

    if (!fileParams.isEmpty()) {
      SimpleMultipartEntity multipartEntity = new SimpleMultipartEntity();

      // Add string params
      for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) {
        multipartEntity.addPart(entry.getKey(), entry.getValue());
      }

      // Add dupe params
      for (ConcurrentHashMap.Entry<String, ArrayList<String>> entry :
          urlParamsWithArray.entrySet()) {
        ArrayList<String> values = entry.getValue();
        for (String value : values) {
          multipartEntity.addPart(entry.getKey(), value);
        }
      }

      // Add file params
      int currentIndex = 0;
      int lastIndex = fileParams.entrySet().size() - 1;
      for (ConcurrentHashMap.Entry<String, FileWrapper> entry : fileParams.entrySet()) {
        FileWrapper file = entry.getValue();
        if (file.inputStream != null) {
          boolean isLast = currentIndex == lastIndex;
          if (file.contentType != null) {
            multipartEntity.addPart(
                entry.getKey(), file.getFileName(), file.inputStream, file.contentType, isLast);
          } else {
            multipartEntity.addPart(entry.getKey(), file.getFileName(), file.inputStream, isLast);
          }
        }
        currentIndex++;
      }

      entity = multipartEntity;
    } else {
      try {
        entity = new UrlEncodedFormEntity(getParamsList(), ENCODING);
      } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
      }
    }

    return entity;
  }
  @Override
  public boolean clearExpired(Date date) {
    boolean clearedAny = false;
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();

    for (ConcurrentHashMap.Entry<String, Cookie> entry : cookies.entrySet()) {
      String name = entry.getKey();
      Cookie cookie = entry.getValue();
      if (cookie.isExpired(date)) {
        // Clear cookies from local store
        cookies.remove(name);

        // Clear cookies from persistent store
        prefsWriter.remove(COOKIE_NAME_PREFIX + name);

        // We've cleared at least one
        clearedAny = true;
      }
    }

    // Update names in persistent store
    if (clearedAny) {
      prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    }
    prefsWriter.commit();

    return clearedAny;
  }
  /** Returns an HttpEntity containing all request parameters */
  public HttpEntity getEntity() {

    if (bodyEntity != null) {
      return bodyEntity;
    }

    HttpEntity result = null;

    if (fileParams != null && !fileParams.isEmpty()) {

      MultipartEntity multipartEntity =
          new MultipartEntity(HttpMultipartMode.STRICT, boundary, Charset.forName(charset));

      if (bodyParams != null && !bodyParams.isEmpty()) {
        for (NameValuePair param : bodyParams) {
          try {
            multipartEntity.addPart(param.getName(), new StringBody(param.getValue()));
          } catch (UnsupportedEncodingException e) {
            LogUtils.e(e.getMessage(), e);
          }
        }
      }

      for (ConcurrentHashMap.Entry<String, ContentBody> entry : fileParams.entrySet()) {
        multipartEntity.addPart(entry.getKey(), entry.getValue());
      }

      result = multipartEntity;
    } else if (bodyParams != null && !bodyParams.isEmpty()) {
      result = new BodyParamsEntity(bodyParams, charset);
    }

    return result;
  }
  /**
   * Returns an appropriate commandStrategy after determining it using the CommandContext of the
   * request. If no such Strategy is found then a default strategy is returned back.
   *
   * @param commandContext
   * @return CommandStrategy
   * @see org.mifosplatform.batch.command.internal.UnknownCommandStrategy
   */
  public CommandStrategy getCommandStrategy(final CommandContext commandContext) {

    if (this.commandStrategies.containsKey(commandContext)) {
      return (CommandStrategy)
          this.applicationContext.getBean(this.commandStrategies.get(commandContext));
    }

    for (ConcurrentHashMap.Entry<CommandContext, String> entry :
        this.commandStrategies.entrySet()) {
      if (commandContext.matcher(entry.getKey())) {
        return (CommandStrategy)
            this.applicationContext.getBean(this.commandStrategies.get(entry.getKey()));
      }
    }

    return new UnknownCommandStrategy();
  }
Exemple #6
0
  protected List<BasicNameValuePair> getParamsList() {
    List<BasicNameValuePair> lparams = new LinkedList<BasicNameValuePair>();

    for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) {
      lparams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
    }

    return lparams;
  }
Exemple #7
0
  @Override
  public String toString() {
    StringBuilder result = new StringBuilder();
    for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) {
      if (result.length() > 0) result.append("&");

      result.append(entry.getKey());
      result.append("=");
      result.append(entry.getValue());
    }

    for (ConcurrentHashMap.Entry<String, FileWrapper> entry : fileParams.entrySet()) {
      if (result.length() > 0) result.append("&");

      result.append(entry.getKey());
      result.append("=");
      result.append("FILE");
    }

    return result.toString();
  }
  protected List<BasicNameValuePair> getParamsList() {
    List<BasicNameValuePair> lparams = new LinkedList<BasicNameValuePair>();

    for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) {
      lparams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
    }

    for (ConcurrentHashMap.Entry<String, ArrayList<String>> entry : urlParamsWithArray.entrySet()) {
      ArrayList<String> values = entry.getValue();
      for (String value : values) {
        lparams.add(new BasicNameValuePair(entry.getKey(), value));
      }
    }

    return lparams;
  }