Package freemarker.template

Examples of freemarker.template.TemplateException$PrintWriterStackTraceWriter


    public void testEvaluateWriterException() throws TemplateException, IOException {
        TemplateDirectiveBody body = createMock(TemplateDirectiveBody.class);
        Writer writer = createMock(Writer.class);

        body.render(writer);
        expectLastCall().andThrow(new TemplateException(null));

        replay(body, writer);
        try {
            FreemarkerModelBody modelBody = new FreemarkerModelBody(null, body);
            modelBody.evaluate(writer);
View Full Code Here


    if (result != null) {
      try {
        env.getOut().write(result);
      } catch (IOException ex) {
        throw new TemplateException("Error writing [" + result + "] to Freemarker.", ex, env);
      }
    } else {
      renderBody(env, body);
    }
  }
View Full Code Here

    if (result != null) {
      try {
        env.getOut().write(result);
      } catch (IOException ex) {
        throw new TemplateException("Error writing [" + result + "] to Freemarker.", ex, env);
      }
    } else {
      renderBody(env, body);
    }
  }
View Full Code Here

    // Print out the principal value if not null
    if (result != null) {
      try {
        env.getOut().write(result);
      } catch (IOException ex) {
        throw new TemplateException("Error writing [" + result + "] to Freemarker.", ex, env);
      }
    }
  }
View Full Code Here

     void visitAttemptRecover(TemplateElement attemptBlock, RecoveryBlock recoveryBlock)
     throws TemplateException, IOException {
         Writer prevOut = this.out;
         StringWriter sw = new StringWriter();
         this.out = sw;
         TemplateException thrownException = null;
         boolean lastFIRE = setFastInvalidReferenceExceptions(false);
         boolean lastInAttemptBlock = inAttemptBlock;
         try {
             inAttemptBlock = true;
             visitByHiddingParent(attemptBlock);
View Full Code Here

            Date date, int dateType, Environment env)
    throws TemplateException;
   
    static TemplateException newNonDateException(Environment env, TemplateModel model, Expression target)
            throws InvalidReferenceException {
        TemplateException e;
        if(model == null) {
            e = InvalidReferenceException.getInstance(target, env);
        } else {
            e = new NonDateException(target, model, "date", env);
        }
View Full Code Here

      TemplateDirectiveBody body) throws TemplateException, IOException {

    // 数据名称
    String name = getAttribute(params, "name");
    if (name == null) {
      throw new TemplateException(
          "Can not find attribute 'name' in data tag", env);
    }
    String text = getAttribute(params, "text");
    String tablename = getAttribute(params, "tablename");
    // 变量名称
View Full Code Here

    throws TemplateException, IOException
    {
        // Determine the path
        final TemplateModel path = params.get("path");
        if(path == null) {
            throw new TemplateException("Missing required parameter 'path'", env);
        }
        if(!(path instanceof TemplateScalarModel)) {
            throw new TemplateException("Expected a scalar model. 'path' is instead " +
                    path.getClass().getName(), env);
        }
        final String strPath = ((TemplateScalarModel)path).getAsString();
        if(strPath == null) {
            throw new TemplateException("String value of 'path' parameter is null", env);
        }
       
        // See whether we need to use a custom response (if we're inside a TTM
        // or TDM or macro nested body, we'll need to as then the current
        // FM environment writer is not identical to HTTP servlet response
        // writer.
        final Writer envOut = env.getOut();
        final HttpServletResponse wrappedResponse;
        if(envOut == response.getWriter()) {
            // Don't bother wrapping if environment's writer is same as
            // response writer
            wrappedResponse = response;
        }
        else {
            final PrintWriter printWriter = (envOut instanceof PrintWriter) ?
                (PrintWriter)envOut :
                new PrintWriter(envOut);
            // Otherwise, create a response wrapper that will pass the
            // env writer, potentially first wrapping it in a print
            // writer when it ain't one already.
            wrappedResponse = new HttpServletResponseWrapper(response) {
                @Override
                public PrintWriter getWriter() {
                    return printWriter;
                }
            };
        }

        // Determine inherit_params value
        final boolean inheritParams;
        final TemplateModel inheritParamsModel = params.get("inherit_params");
        if(inheritParamsModel == null) {
            // defaults to true when not specified
            inheritParams = true;
        }
        else {
            if(!(inheritParamsModel instanceof TemplateBooleanModel)) {
                throw new TemplateException("'inherit_params' should be a boolean but it is " +
                        inheritParamsModel.getClass().getName() + " instead", env);
            }
            inheritParams = ((TemplateBooleanModel)inheritParamsModel).getAsBoolean();
        }
       
        // Get explicit params, if any
        final TemplateModel paramsModel = params.get("params");
       
        // Determine whether we need to wrap the request
        final HttpServletRequest wrappedRequest;
        if(paramsModel == null && inheritParams) {
            // Inherit original request params & no params explicitly
            // specified, so use the original request
            wrappedRequest = request;
        }
        else {
            // In any other case, use a custom request wrapper
            final Map paramsMap;
            if(paramsModel != null) {
                // Convert params to a Map
                final Object unwrapped = DeepUnwrap.unwrap(paramsModel);
                if(!(unwrapped instanceof Map)) {
                    throw new TemplateException("Expected 'params' to unwrap " +
                            "into a java.util.Map. It unwrapped into " +
                            unwrapped.getClass().getName() + " instead.", env);
                }
                paramsMap = (Map)unwrapped;
            }
            else {
                paramsMap = Collections.EMPTY_MAP;
            }
            wrappedRequest = new CustomParamsRequest(request, paramsMap,
                    inheritParams);
        }
       
        // Finally, do the include
        try {
            request.getRequestDispatcher(strPath).include(wrappedRequest,
                    wrappedResponse);
        }
        catch (ServletException e) {
            throw new TemplateException(e, env);
        }
    }
View Full Code Here

            importedTemplate = env.getTemplateForImporting(templateNameString);
        }
        catch (ParseException pe) {
            String msg = "Error parsing imported template "
                        + templateNameString;
            throw new TemplateException(msg, pe, env);
        }
        catch (IOException ioe) {
            String msg = "Error reading imported file "
                        + templateNameString;
            throw new TemplateException(msg, ioe, env);
        }
        env.importLib(importedTemplate, namespace, false);
    }
View Full Code Here

                        }
                        assert value != null;
                        curriedParams.addParam(name, new ModelLiteral(value, env));
                    }
                } else {
                    throw new TemplateException(
                            "Can't use positional arguments to curry an instance of "
                            + base.getClass().getName() +
                            " as it has no @Parameters annotation", env);
                }
            } else {
View Full Code Here

TOP

Related Classes of freemarker.template.TemplateException$PrintWriterStackTraceWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.