Ejemplo n.º 1
0
  /**
   * Builds the full URI path to this resource method.
   *
   * @return the full URI path to this resource method.
   */
  public String getFullpath() {
    List<String> subpaths = new ArrayList<String>();
    if (getSubpath() != null) {
      subpaths.add(0, getSubpath());
    }

    Resource parent = getParent();
    while (parent != null) {
      subpaths.add(0, parent.getPath());
      parent = parent.getParent();
    }

    StringBuilder builder = new StringBuilder();
    for (String subpath : subpaths) {
      subpath = subpath.trim();
      if (!subpath.startsWith("/")) {
        subpath = '/' + subpath;
      }
      while (subpath.endsWith("/")) {
        subpath = subpath.substring(0, subpath.length() - 1);
      }
      subpath = scrubParamNames(subpath);

      builder.append(subpath);
    }

    return builder.toString();
  }
Ejemplo n.º 2
0
 /**
  * The servlet pattern that can be applied to access this resource method.
  *
  * @return The servlet pattern that can be applied to access this resource method.
  */
 public String getServletPattern() {
   StringBuilder builder = new StringBuilder();
   String fullPath = getFullpath();
   Matcher pathParamMatcher = CONTEXT_PARAM_PATTERN.matcher(fullPath);
   if (pathParamMatcher.find()) {
     builder.append(fullPath, 0, pathParamMatcher.start()).append("*");
   } else {
     builder.append(fullPath);
   }
   return builder.toString();
 }
Ejemplo n.º 3
0
  /**
   * Scrubs the path parameters names from the specified subpath.
   *
   * @param subpath The subpath.
   * @return The scrubbed path.
   */
  protected static String scrubParamNames(String subpath) {
    StringBuilder builder = new StringBuilder(subpath.length());
    int charIndex = 0;
    int inBrace = 0;
    boolean definingRegexp = false;
    while (charIndex < subpath.length()) {
      char ch = subpath.charAt(charIndex++);
      if (ch == '{') {
        inBrace++;
      } else if (ch == '}') {
        inBrace--;
        if (inBrace == 0) {
          definingRegexp = false;
        }
      } else if (inBrace == 1 && ch == ':') {
        definingRegexp = true;
      }

      if (!definingRegexp) {
        builder.append(ch);
      }
    }
    return builder.toString();
  }