Exemplo n.º 1
0
    private void renderQueryString(Route route, URIWriter writer) throws IOException {
      if (route.parent != null) {
        renderQueryString(route.parent, writer);
      }

      //
      for (RequestParam requestParamDef : route.requestParamArray) {
        String s = matches.get(requestParamDef.name);
        switch (requestParamDef.valueMapping) {
          case CANONICAL:
            break;
          case NEVER_EMPTY:
            if (s != null && s.length() == 0) {
              s = null;
            }
            break;
          case NEVER_NULL:
            if (s == null) {
              s = "";
            }
            break;
        }
        if (s != null) {
          writer.appendQueryParameter(requestParamDef.matchName, s);
        }
      }
    }
Exemplo n.º 2
0
    private boolean renderPath(Route route, URIWriter writer, boolean hasChildren)
        throws IOException {
      boolean endWithSlash;
      if (route.parent != null) {
        endWithSlash = renderPath(route.parent, writer, true);
      } else {
        endWithSlash = false;
      }

      //
      if (route instanceof SegmentRoute) {
        SegmentRoute sr = (SegmentRoute) route;
        if (!endWithSlash) {
          writer.append('/');
          endWithSlash = true;
        }
        String name = sr.encodedName;
        writer.append(name);
        if (name.length() > 0) {
          endWithSlash = false;
        }
      } else if (route instanceof PatternRoute) {
        PatternRoute pr = (PatternRoute) route;
        if (!endWithSlash) {
          writer.append('/');
          endWithSlash = true;
        }
        int i = 0;
        int count = 0;
        while (i < pr.params.length) {
          writer.append(pr.encodedChunks[i]);
          count += pr.chunks[i].length();

          //
          PathParam def = pr.params[i];
          String value = matches.get(def.name);
          count += value.length();

          // Write value
          for (int len = value.length(), j = 0; j < len; j++) {
            char c = value.charAt(j);
            if (c == route.router.separatorEscape) {
              if (def.encodingMode == EncodingMode.PRESERVE_PATH) {
                writer.append('_');
              } else {
                writer.append('%');
                writer.append(route.router.separatorEscapeNible1);
                writer.append(route.router.separatorEscapeNible2);
              }
            } else if (c == '/') {
              writer.append(
                  def.encodingMode == EncodingMode.PRESERVE_PATH
                      ? '/'
                      : route.router.separatorEscape);
            } else {
              writer.appendSegment(c);
            }
          }

          //
          i++;
        }
        writer.append(pr.encodedChunks[i]);
        count += pr.chunks[i].length();
        if (count > 0) {
          endWithSlash = false;
        }
      } else {
        if (!hasChildren) {
          writer.append('/');
          endWithSlash = true;
        }
      }

      //
      return endWithSlash;
    }