Beispiel #1
0
  public void internalRenderTemplate(Map<String, Object> args, boolean startingNewRendering)
      throws GTTemplateNotFoundWithSourceInfo, GTRuntimeException {

    if (startingNewRendering) {
      // start with fresh tag-stack
      GTTagContext.singleton.init();
    }

    try {

      // must store a copy of args, so we can pass the same (unchnaged) args to an extending
      // template.
      this.orgArgs = new HashMap<String, Object>(args);
      this.binding =
          new Binding(
              new HashMap<String, Object>(
                  args)); // Must create a new map to prevent script-generated variables to leak out
      this.binding.setProperty("java_class", this);
      // must init our groovy script

      // groovyScript = InvokerHelper.createScript(groovyClass, binding);
      groovyScript = groovyClass.newInstance();
      groovyScript.setBinding(binding);

      // create a property in groovy so that groovy can find us (this)

      // call _renderTemplate directly
      _renderTemplate();

      // check if "we" have extended another template..
      if (extendsTemplateLocation != null) {
        // yes, we've extended another template
        // Get the template we are extending
        extendedTemplate = templateRepo.getTemplateInstance(extendsTemplateLocation);

        // tell it that "we" extended it..
        extendedTemplate.extendingTemplate = this;

        // ok, render it with original args..
        extendedTemplate.internalRenderTemplate(orgArgs, false);
      }

    } catch (GTCompilationException e) {
      // just throw it
      throw e;
    } catch (Throwable e) {
      // wrap it in a GTRuntimeException
      throw templateRepo.fixException(e);
    }
  }