/**
   * @param str
   * @param startIndex
   * @param parameters
   * @return
   */
  private String doReplacement(String str, int startIndex, LinkedList<Object> parameters) {
    if (parameters == null || parameters.isEmpty()) {
      return str;
    }

    final int length = str.length();
    for (int index = startIndex; index < length; index++) {
      int persentIndex = 0;
      if (str.charAt(index) == PERSENT) {
        persentIndex = index;
      } else continue;

      if (persentIndex != -1 && persentIndex != length - 1) {
        char nextChar = str.charAt(persentIndex + 1);
        if (supports.contains(nextChar)) {
          Object firstObject = parameters.getFirst();
          String firstParameter = (firstObject != null) ? firstObject.toString() : NULL;
          String formattedString =
              StringUtils.replaceOnce(
                  str, str.substring(persentIndex, persentIndex + 2), firstParameter);
          parameters.removeFirst();
          int newStartIndex = persentIndex + firstParameter.length();
          return doReplacement(formattedString, newStartIndex, parameters);
        }
      }
    }
    return str;
  }
Ejemplo n.º 2
0
  /** The method to replace http:// URLs to https:// */
  protected void sendRedirect(
      HttpServletRequest request,
      HttpServletResponse response,
      String targetUrl,
      boolean http10Compatible)
      throws IOException {

    if (secure && targetUrl.startsWith("http://")) {
      targetUrl = StringUtils.replaceOnce(targetUrl, "http://", "https://");
    }

    if (!targetUrl.startsWith("http")) {
      // Get the secure URL and build complete URL
      StringBuffer sb = new StringBuffer();

      if (!ignoreContext) {
        sb.append(request.getServletPath());
      }
      sb.append("/");
      sb.append(targetUrl);
      targetUrl = sb.toString();
    }

    if (logger.isDebugEnabled()) {
      logger.debug("Redirecting to URL : [" + targetUrl + "]");
    }

    super.sendRedirect(request, response, targetUrl, http10Compatible);
  }
Ejemplo n.º 3
0
 public static List<String> removePrefixFromPathList(
     Collection<? extends Object> pathList, String prefix) {
   List<String> outPathList = new LinkedList<String>();
   for (Object path : pathList) {
     outPathList.add(StringUtils.replaceOnce(path.toString(), prefix, ""));
   }
   return outPathList;
 }
  /** @see java.beans.PropertyEditorSupport#setAsText(String) */
  @Override
  public void setAsText(String text) {
    String value = text;
    if (StringUtils.contains(value, "-")) {
      value = StringUtils.replaceOnce(value, "-", "");
    }

    this.setValue(value);
  }
Ejemplo n.º 5
0
  private String getLocationFromClasspath(String resourceLocation) {
    String location =
        StringUtils.replaceOnce(resourceLocation, ReflectionUtils.CLASSPATH_PREFIX, "");

    if (location != null && !location.startsWith("/")) {
      location = "/" + location;
    }

    return location;
  }
 private void callNow() {
   if (StringUtils.isBlank(ConfigXml.getInstance().getTelephoneSystemUrl()) == true) {
     log.error("Telephone system url not configured. Phone calls not supported.");
     return;
   }
   log.info(
       "User initiates direct call from phone with id '"
           + form.getMyCurrentPhoneId()
           + "' to destination numer: "
           + StringHelper.hideStringEnding(form.getPhoneNumber(), 'x', 3));
   result = null;
   final StringBuffer buf = new StringBuffer();
   buf.append(form.getPhoneNumber()).append(SEPARATOR);
   final AddressDO address = form.getAddress();
   if (address != null
       && StringHelper.isIn(
               form.getPhoneNumber(),
               extractPhonenumber(address.getBusinessPhone()),
               extractPhonenumber(address.getMobilePhone()),
               extractPhonenumber(address.getPrivatePhone()),
               extractPhonenumber(address.getPrivateMobilePhone()))
           == true) {
     buf.append(address.getFirstName()).append(" ").append(address.getName());
     if (form.getPhoneNumber().equals(extractPhonenumber(address.getMobilePhone())) == true) {
       buf.append(", ").append(getString("address.phoneType.mobile"));
     } else if (form.getPhoneNumber().equals(extractPhonenumber(address.getPrivatePhone()))
         == true) {
       buf.append(", ").append(getString("address.phoneType.private"));
     }
     buf.append(" #").append(address.getId());
   } else {
     buf.append("???");
   }
   final HttpClient client = new HttpClient();
   String url = ConfigXml.getInstance().getTelephoneSystemUrl();
   url = StringUtils.replaceOnce(url, "#source", form.getMyCurrentPhoneId());
   url = StringUtils.replaceOnce(url, "#target", form.getPhoneNumber());
   final String urlProtected = StringHelper.hideStringEnding(url, 'x', 3);
   final GetMethod method = new GetMethod(url);
   String errorKey = null;
   try {
     form.lastSuccessfulPhoneCall = new Date();
     client.executeMethod(method);
     final String resultStatus = method.getResponseBodyAsString();
     if ("0".equals(resultStatus) == true) {
       result =
           DateTimeFormatter.instance().getFormattedDateTime(new Date())
               + ": "
               + getString("address.phoneCall.result.successful");
       form.getRecentSearchTermsQueue().append(buf.toString());
     } else if ("2".equals(resultStatus) == true) {
       errorKey = "address.phoneCall.result.wrongSourceNumber";
     } else if ("3".equals(resultStatus) == true) {
       errorKey = "address.phoneCall.result.wrongDestinationNumber";
     } else {
       errorKey = "address.phoneCall.result.callingError";
     }
   } catch (final HttpException ex) {
     result = "Call failed. Please contact administrator.";
     log.fatal(result + ": " + urlProtected);
     throw new RuntimeException(ex);
   } catch (final IOException ex) {
     result = "Call failed. Please contact administrator.";
     log.fatal(result + ": " + urlProtected);
     throw new RuntimeException(ex);
   }
   if (errorKey != null) {
     form.addError(errorKey);
   }
 }
Ejemplo n.º 7
0
 private String getModuleEN(String key, IARESProject project) throws ARESModelException {
   if (StringUtils.startsWith(key, "数据库/")) {
     return StringUtils.replaceOnce(key, "数据库/", "database/");
   } else if (StringUtils.startsWith(key, "数据库\\")) {
     return StringUtils.replaceOnce(key, "数据库\\", "database\\");
   } else if (StringUtils.startsWith(key, "业务逻辑/")) {
     if (project.getModuleRoot("business") != null && project.getModuleRoot("business").exists()) {
       return StringUtils.replaceOnce(key, "业务逻辑/", "business/");
     } else if (project.getModuleRoot("service") != null
         && project.getModuleRoot("service").exists()) {
       System.out.println("asdasasasdad");
       return StringUtils.replaceOnce(key, "业务逻辑/", "service/");
     }
   } else if (StringUtils.startsWith(key, "业务逻辑\\")) {
     if (project.getModuleRoot("business") != null && project.getModuleRoot("business").exists()) {
       return StringUtils.replaceOnce(key, "业务逻辑\\", "business\\");
     } else if (project.getModuleRoot("service") != null
         && project.getModuleRoot("service").exists()) {
       return StringUtils.replaceOnce(key, "业务逻辑\\", "service\\");
     }
   } else if (StringUtils.startsWith(key, "原子/")) {
     return StringUtils.replaceOnce(key, "原子/", "atom/");
   } else if (StringUtils.startsWith(key, "原子\\")) {
     return StringUtils.replaceOnce(key, "原子\\", "atom\\");
   } else if (StringUtils.startsWith(key, "过程/")) {
     return StringUtils.replaceOnce(key, "过程/", "procedure/");
   } else if (StringUtils.startsWith(key, "过程\\")) {
     return StringUtils.replaceOnce(key, "过程\\", "procedure\\");
   } else if (StringUtils.startsWith(key, "对象/")) {
     return StringUtils.replaceOnce(key, "对象/", "objects/");
   } else if (StringUtils.startsWith(key, "对象\\")) {
     return StringUtils.replaceOnce(key, "对象\\", "objects\\");
   } else if (StringUtils.startsWith(key, "逻辑/")) {
     return StringUtils.replaceOnce(key, "逻辑/", "logic/");
   } else if (StringUtils.startsWith(key, "逻辑\\")) {
     return StringUtils.replaceOnce(key, "逻辑\\", "logic\\");
   }
   return key;
 }