All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.docshare.mvc.except.FreeMarkerHandler Maven / Gradle / Ivy

Go to download

An efficient, fast, convenient, easy to learn, easy to use MVC framework and ORM framework. It is seamless compatible with JSTL and supports FreeMarker. It can run independently, and it can also be applied to traditional Java Web projects. It is an efficient, fast, convenient, easy to learn and easy to use MVC framework and ORM framework. It is seamless compatible with JSTL and supports FreeMarker. It can be run on its own, or it can be applied to traditional Java Web projects

There is a newer version: 2023.06.19
Show newest version
package org.docshare.mvc.except;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;

import org.docshare.log.Log;

import freemarker.core.Environment;
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;

public class FreeMarkerHandler implements TemplateExceptionHandler  {

	@Override
	public void handleTemplateException(TemplateException e,
			Environment env, Writer out) throws TemplateException {
		ByteArrayOutputStream ba  = new ByteArrayOutputStream();
		try {
			out.write("Freemarker Error: "+ e.getMessage());
		} catch (IOException e1) {
			e1.printStackTrace();
		}
//		try {
//			
//			e.printStackTrace(new PrintWriter(ba));
////			String msg = e.getMessage().replace("\n", "
\n"); //// String msg2 = msg.replace("The following has evaluated to null or missing" , "发生错误时因为下面的变量是空的。你可以通过加默认值的方法来避免这个错误,如${haha!\"我是默认值\"}"); //// msg2 = msg2.replaceAll("in template \"(.+?)\" at line (\\d+?), column (\\d+?)", " 模板$1 $2 行 $3 列"); //// out.write("[错误]"+msg2); //// out.write("
~~~~~~~~~~~~~~~~~~~~~~~~
你觉得错误提示天生就是中文的吗?太天真了。下面是原文
"); //// out.write(msg); //// out.write(ba.toString()); // out.write(""); // } catch (UnsupportedEncodingException e1) { // Log.e(e1); // } catch (IOException e2) { // Log.e(e2); // } // } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy