예제 #1
0
  /**
   * Resolves HTTP method name from method name. If method name or first camel-case word of a method
   * equals to a HTTP method, it will be used as that HTTP methods.
   */
  protected String resolveHttpMethodFromMethodName(String methodName) {
    int i = 0;

    while (i < methodName.length()) {
      if (CharUtil.isUppercaseAlpha(methodName.charAt(i))) {
        break;
      }
      i++;
    }

    String name = methodName.substring(0, i).toUpperCase();

    if (name.equals(Action.CONNECT)) {
      return Action.CONNECT;
    }

    if (name.equals(Action.DELETE)) {
      return Action.DELETE;
    }

    if (name.equals(Action.GET)) {
      return Action.GET;
    }

    if (name.equals(Action.HEAD)) {
      return Action.HEAD;
    }

    if (name.equals(Action.OPTIONS)) {
      return Action.OPTIONS;
    }

    if (name.equals(Action.PATCH)) {
      return Action.PATCH;
    }

    if (name.equalsIgnoreCase(Action.POST)) {
      return Action.POST;
    }

    if (name.equals(Action.PUT)) {
      return Action.PUT;
    }

    if (name.equals(Action.TRACE)) {
      return Action.TRACE;
    }

    return null;
  }
예제 #2
0
파일: RawAction.java 프로젝트: lxmhope/jodd
 @Action
 public RawData view() {
   String result = "this is some raw direct result";
   byte[] bytes = CharUtil.toAsciiByteArray(result.toCharArray());
   return new RawData(bytes, MimeTypes.MIME_TEXT_HTML);
 }
예제 #3
0
  /**
   * {@inheritDoc}
   *
   * @see JdtFormatter#parse(String, String)
   */
  public DateTimeStamp parse(String value, String format) {
    char[] valueChars = value.toCharArray();
    char[] formatChars = format.toCharArray();

    int i = 0, j = 0;
    int valueLen = valueChars.length;
    int formatLen = formatChars.length;

    // detect if separators are used
    boolean useSeparators = true;

    if (valueLen == formatLen) {
      useSeparators = false;

      for (char valueChar : valueChars) {
        if (CharUtil.isDigit(valueChar) == false) {
          useSeparators = true;
          break;
        }
      }
    }

    DateTimeStamp time = new DateTimeStamp();
    StringBuilder sb = new StringBuilder();
    while (true) {
      int n = findPattern(formatChars, i);
      if (n != -1) { // pattern founded
        int patternLen = patterns[n].length;
        i += patternLen;
        sb.setLength(0);
        if (useSeparators == false) {
          for (int k = 0; k < patternLen; k++) {
            sb.append(valueChars[j++]);
          }
        } else {
          char next = 0xFFFF;
          if (i < formatLen) {
            next = formatChars[i]; // next = delimiter
          }
          while ((j < valueLen) && (valueChars[j] != next)) {
            char scj = valueChars[j];
            if ((scj != ' ') && (scj != '\t')) { // ignore surrounding whitespaces
              sb.append(valueChars[j]);
            }
            j++;
          }
        }

        parseValue(n, sb.toString(), time);
      } else {
        if (!useSeparators) {
          throw new IllegalArgumentException("Invalid value: " + value);
        }
        if (formatChars[i] == valueChars[j]) {
          j++;
        }
        i++;
      }
      if ((i == formatLen) || (j == valueLen)) {
        break;
      }
    }
    return time;
  }