private void initPathWriterList()

in common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/URLPathBuilder.java [56:93]


  private void initPathWriterList(String rawPath, Map<String, RestParam> paramMap) {
    // 去掉末尾'/'
    if (rawPath.endsWith(SLASH)) {
      rawPath = rawPath.substring(0, rawPath.length() - 1);
    }
    // 首部加上'/'
    if (!rawPath.startsWith(SLASH)) {
      rawPath = SLASH + rawPath;
    }

    StringBuilder tmpPath = new StringBuilder();
    for (int idx = 0; idx < rawPath.length(); idx++) {
      char currentChar = rawPath.charAt(idx);
      if (currentChar == '{') {
        if (tmpPath.length() != 0) {
          this.pathParamWriterList.add(new StaticUrlParamWriter(tmpPath.toString()));
          tmpPath.setLength(0);
        }
      } else if (currentChar == '}') {
        if (tmpPath.length() == 0) {
          continue;
        }
        String tmpPathStr = tmpPath.toString();
        String pathParamName = tmpPathStr;
        if (tmpPathStr.contains(":")) {
          pathParamName = tmpPathStr.split(":", 2)[0].trim();
        }
        RestParam param = paramMap.get(pathParamName);
        this.pathParamWriterList.add(new PathVarParamWriter(param));
        tmpPath.setLength(0);
      } else {
        tmpPath.append(currentChar);
      }
    }
    if (tmpPath.length() != 0) {
      this.pathParamWriterList.add(new StaticUrlParamWriter(tmpPath.toString()));
    }
  }