String getViewURIInternal(
      String controllerName, String viewName, FastStringWriter buf, boolean includeSuffix) {
    if (viewName != null && viewName.startsWith(SLASH_STR)) {
      String tmp = viewName.substring(1, viewName.length());
      if (tmp.indexOf(SLASH) > -1) {
        buf.append(SLASH);
        buf.append(tmp.substring(0, tmp.lastIndexOf(SLASH)));
        buf.append(SLASH);
        buf.append(tmp.substring(tmp.lastIndexOf(SLASH) + 1, tmp.length()));
      } else {
        buf.append(SLASH);
        buf.append(viewName.substring(1, viewName.length()));
      }
    } else {
      buf.append(SLASH).append(controllerName);
      if (viewName != null) {

        buf.append(SLASH).append(viewName);
      }
    }

    if (includeSuffix) {
      return buf.append(GroovyPage.SUFFIX).toString();
    }

    return buf.toString();
  }
  /**
   * Obtains the URI to a template using the controller name and template name
   *
   * @param controllerName The controller name
   * @param templateName The template name
   * @return The template URI
   */
  String getTemplateURI(String controllerName, String templateName) {
    FastStringWriter buf = new FastStringWriter();

    if (templateName.startsWith(SLASH_STR)) {
      String tmp = templateName.substring(1, templateName.length());
      if (tmp.indexOf(SLASH) > -1) {
        buf.append(SLASH);
        int i = tmp.lastIndexOf(SLASH);
        buf.append(tmp.substring(0, i));
        buf.append(SLASH_UNDR);
        buf.append(tmp.substring(i + 1, tmp.length()));
      } else {
        buf.append(SLASH_UNDR);
        buf.append(templateName.substring(1, templateName.length()));
      }
    } else {
      String pathToTemplate = BLANK;

      int lastSlash = templateName.lastIndexOf(SLASH);
      if (lastSlash > -1) {
        pathToTemplate = templateName.substring(0, lastSlash + 1);
        templateName = templateName.substring(lastSlash + 1);
      }
      buf.append(SLASH)
          .append(controllerName)
          .append(SLASH)
          .append(pathToTemplate)
          .append(UNDERSCORE)
          .append(templateName);
    }
    return buf.append(GroovyPage.EXTENSION).toString();
  }
Esempio n. 3
0
 /** {@inheritDoc} */
 @Override
 public final CharSequence apply(final Object context) throws IOException {
   FastStringWriter writer = new FastStringWriter();
   apply(context, writer);
   return writer.toString();
 }