Ejemplo n.º 1
0
 // map GPX-Attribute-Id to baseName
 public static String getBaseName(final int id) {
   // get String out of array
   if (CACHE_ATTRIBUTES.length <= id) {
     return null;
   }
   final int stringId = CACHE_ATTRIBUTES[id];
   if (stringId == -1) {
     return null; // id not found
   }
   // get text for string
   String stringName;
   try {
     stringName = cgeoapplication.getInstance().getResources().getResourceName(stringId);
   } catch (NullPointerException e) {
     return null;
   }
   if (stringName == null) {
     return null;
   }
   // cut out baseName
   final MatcherWrapper m = new MatcherWrapper(BASENAME_PATTERN, stringName);
   if (!m.matches()) {
     return null;
   }
   return m.group(1);
 }
Ejemplo n.º 2
0
 static Date parseDate(String inputUntrimmed) throws ParseException {
   String input = inputUntrimmed.trim();
   // remove milliseconds to reduce number of needed patterns
   final MatcherWrapper matcher = new MatcherWrapper(PATTERN_MILLISECONDS, input);
   input = matcher.replaceFirst("");
   if (input.contains("Z")) {
     return formatSimpleZ.parse(input);
   }
   if (StringUtils.countMatches(input, ":") == 3) {
     final String removeColon =
         input.substring(0, input.length() - 3) + input.substring(input.length() - 2);
     return formatTimezone.parse(removeColon);
   }
   return formatSimple.parse(input);
 }
Ejemplo n.º 3
0
 private void findGeoCode(final String input) {
   if (input == null || StringUtils.isNotBlank(cache.getGeocode())) {
     return;
   }
   final String trimmed = input.trim();
   final MatcherWrapper matcherGeocode = new MatcherWrapper(patternGeocode, trimmed);
   if (matcherGeocode.find()) {
     final String geocode = matcherGeocode.group(1);
     // a geocode should not be part of a word
     if (geocode.length() == trimmed.length()
         || Character.isWhitespace(trimmed.charAt(geocode.length()))) {
       if (ConnectorFactory.canHandle(geocode)) {
         cache.setGeocode(geocode);
       }
     }
   }
 }
  private void requestToken() {

    final Parameters params = new Parameters();
    params.put("oauth_callback", callback);
    final String method = "GET";
    OAuth.signOAuth(
        host, pathRequest, method, https, params, null, null, consumerKey, consumerSecret);
    final HttpResponse response = Network.getRequest(getUrlPrefix() + host + pathRequest, params);

    if (Network.isSuccess(response)) {
      final String line = Network.getResponseData(response);

      int status = STATUS_ERROR;
      if (StringUtils.isNotBlank(line)) {
        assert line != null;
        final MatcherWrapper paramsMatcher1 = new MatcherWrapper(paramsPattern1, line);
        if (paramsMatcher1.find()) {
          OAtoken = paramsMatcher1.group(1);
        }
        final MatcherWrapper paramsMatcher2 = new MatcherWrapper(paramsPattern2, line);
        if (paramsMatcher2.find()) {
          OAtokenSecret = paramsMatcher2.group(1);
        }

        if (StringUtils.isNotBlank(OAtoken) && StringUtils.isNotBlank(OAtokenSecret)) {
          setTempTokens(OAtoken, OAtokenSecret);
          try {
            final Parameters paramsBrowser = new Parameters();
            paramsBrowser.put("oauth_token", OAtoken);
            final String encodedParams =
                EntityUtils.toString(new UrlEncodedFormEntity(paramsBrowser));
            startActivity(
                new Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse(getUrlPrefix() + host + pathAuthorize + "?" + encodedParams)));
            status = STATUS_SUCCESS;
          } catch (ParseException e) {
            Log.e("OAuthAuthorizationActivity.requestToken", e);
          } catch (IOException e) {
            Log.e("OAuthAuthorizationActivity.requestToken", e);
          }
        }
      }

      requestTokenHandler.sendEmptyMessage(status);
    } else {
      final String extErrMsg = getExtendedErrorMsg(response);
      if (StringUtils.isNotBlank(extErrMsg)) {
        final Message msg = requestTokenHandler.obtainMessage(STATUS_ERROR_EXT_MSG, extErrMsg);
        requestTokenHandler.sendMessage(msg);
      } else {
        requestTokenHandler.sendEmptyMessage(STATUS_ERROR);
      }
    }
  }
  private void changeToken(final String verifier) {

    int status = NOT_AUTHENTICATED;

    try {
      final Parameters params = new Parameters("oauth_verifier", verifier);

      final String method = "POST";
      OAuth.signOAuth(
          host,
          pathAccess,
          method,
          https,
          params,
          OAtoken,
          OAtokenSecret,
          consumerKey,
          consumerSecret);
      final String line =
          StringUtils.defaultString(
              Network.getResponseData(
                  Network.postRequest(getUrlPrefix() + host + pathAccess, params)));

      OAtoken = "";
      OAtokenSecret = "";

      final MatcherWrapper paramsMatcher1 = new MatcherWrapper(paramsPattern1, line);
      if (paramsMatcher1.find()) {
        OAtoken = paramsMatcher1.group(1);
      }
      final MatcherWrapper paramsMatcher2 = new MatcherWrapper(paramsPattern2, line);
      if (paramsMatcher2.find() && paramsMatcher2.groupCount() > 0) {
        OAtokenSecret = paramsMatcher2.group(1);
      }

      if (StringUtils.isBlank(OAtoken) && StringUtils.isBlank(OAtokenSecret)) {
        OAtoken = "";
        OAtokenSecret = "";
        setTokens(null, null, false);
      } else {
        setTokens(OAtoken, OAtokenSecret, true);
        status = AUTHENTICATED;
      }
    } catch (Exception e) {
      Log.e("OAuthAuthorizationActivity.changeToken", e);
    }

    changeTokensHandler.sendEmptyMessage(status);
  }
Ejemplo n.º 6
0
  /**
   * read all viewstates from page
   *
   * @return String[] with all view states
   */
  public static String[] getViewstates(String page) {
    // Get the number of viewstates.
    // If there is only one viewstate, __VIEWSTATEFIELDCOUNT is not present

    if (page == null) { // no network access
      return null;
    }

    int count = 1;
    final MatcherWrapper matcherViewstateCount =
        new MatcherWrapper(GCConstants.PATTERN_VIEWSTATEFIELDCOUNT, page);
    if (matcherViewstateCount.find()) {
      try {
        count = Integer.parseInt(matcherViewstateCount.group(1));
      } catch (NumberFormatException e) {
        Log.e("getViewStates", e);
      }
    }

    String[] viewstates = new String[count];

    // Get the viewstates
    final MatcherWrapper matcherViewstates =
        new MatcherWrapper(GCConstants.PATTERN_VIEWSTATES, page);
    while (matcherViewstates.find()) {
      String sno = matcherViewstates.group(1); // number of viewstate
      int no;
      if (StringUtils.isEmpty(sno)) {
        no = 0;
      } else {
        try {
          no = Integer.parseInt(sno);
        } catch (NumberFormatException e) {
          Log.e("getViewStates", e);
          no = 0;
        }
      }
      viewstates[no] = matcherViewstates.group(2);
    }

    if (viewstates.length != 1 || viewstates[0] != null) {
      return viewstates;
    }
    // no viewstates were present
    return null;
  }