ソースを参照

移除 velocity 模板引擎

James 3 年 前
コミット
b6b8098575

+ 0 - 14
pom.xml

@@ -162,20 +162,6 @@
 			<scope>provided</scope>
 		</dependency>
 		
-		<!-- velocity 模板引擎 -->
-		<dependency>
-			<groupId>org.apache.velocity</groupId>
-			<artifactId>velocity</artifactId>
-			<version>1.7</version>
-			<scope>provided</scope>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.velocity</groupId>
-			<artifactId>velocity-tools</artifactId>
-			<version>2.0</version>
-			<scope>provided</scope>
-		</dependency>
-		
 		<!-- redis 客户端 -->
 		<dependency>
 			<groupId>redis.clients</groupId>

+ 0 - 7
src/main/java/com/jfinal/core/Controller.java

@@ -1103,13 +1103,6 @@ public abstract class Controller {
 	}
 	
 	/**
-	 * Render with velocity view
-	 */
-	public void renderVelocity(String view) {
-		render = renderManager.getRenderFactory().getVelocityRender(view);
-	}
-	
-	/**
 	 * Render with json
 	 * <p>
 	 * Example:<br>

+ 0 - 5
src/main/java/com/jfinal/plugin/ehcache/RenderInfo.java

@@ -24,7 +24,6 @@ import com.jfinal.render.JsonRender;
 import com.jfinal.render.JspRender;
 import com.jfinal.render.Render;
 import com.jfinal.render.TemplateRender;
-import com.jfinal.render.VelocityRender;
 import com.jfinal.render.XmlRender;
 
 /**
@@ -50,8 +49,6 @@ public class RenderInfo implements Serializable {
 			renderType = RenderType.FREE_MARKER_RENDER;
 		} else if (render instanceof JspRender) {
 			renderType = RenderType.JSP_RENDER;
-		} else if (render instanceof VelocityRender) {
-			renderType = RenderType.VELOCITY_RENDER;
 		} else if (render instanceof XmlRender) {
 			renderType = RenderType.XML_RENDER;
 		} else if(render instanceof JsonRender) {
@@ -74,8 +71,6 @@ public class RenderInfo implements Serializable {
 			return new FreeMarkerRender(view);
 		case RenderType.JSP_RENDER:
 			return new JspRender(view);
-		case RenderType.VELOCITY_RENDER:
-			return new VelocityRender(view);
 		case RenderType.XML_RENDER:
 			return new XmlRender(view);
 		case RenderType.JSON_RENDER:

+ 2 - 3
src/main/java/com/jfinal/plugin/ehcache/RenderType.java

@@ -23,9 +23,8 @@ public class RenderType {
 	public static final int TEMPLATE_RENDER = 0;
 	public static final int FREE_MARKER_RENDER = 1;
 	public static final int JSP_RENDER = 2;
-	public static final int VELOCITY_RENDER = 3;
-	public static final int XML_RENDER = 4;
-	public static final int JSON_RENDER = 5;
+	public static final int XML_RENDER = 3;
+	public static final int JSON_RENDER = 4;
 }
 
 

+ 0 - 2
src/main/java/com/jfinal/render/IRenderFactory.java

@@ -39,8 +39,6 @@ public interface IRenderFactory {
 	
 	public Render getJspRender(String view);
 	
-	public Render getVelocityRender(String view);
-	
 	public Render getJsonRender();
 	
 	public Render getJsonRender(String key, Object value);

+ 0 - 13
src/main/java/com/jfinal/render/RenderFactory.java

@@ -54,9 +54,6 @@ public class RenderFactory implements IRenderFactory {
 		case JSP:
 			mainRenderFactory = new JspRenderFactory();
 			break ;
-		case VELOCITY:
-			mainRenderFactory = new VelocityRenderFactory();
-			break ;
 		}
 	}
 	
@@ -79,10 +76,6 @@ public class RenderFactory implements IRenderFactory {
 		return new JspRender(view);
 	}
 	
-	public Render getVelocityRender(String view) {
-		return new VelocityRender(view);
-	}
-	
 	public Render getJsonRender() {
 		return new JsonRender();
 	}
@@ -205,12 +198,6 @@ public class RenderFactory implements IRenderFactory {
 			return new JspRender(view);
 		}
 	}
-	
-	private static class VelocityRenderFactory extends MainRenderFactory {
-		public Render getRender(String view) {
-			return new VelocityRender(view);
-		}
-	}
 }
 
 

+ 0 - 12
src/main/java/com/jfinal/render/RenderManager.java

@@ -61,7 +61,6 @@ public class RenderManager {
 		Render.init(constants.getEncoding(), constants.getDevMode());
 		initTemplateRender();
 		initFreeMarkerRender(servletContext);
-		initVelocityRender(servletContext);
 		initJspRender(servletContext);
 		initFileRender(servletContext);
 		
@@ -86,17 +85,6 @@ public class RenderManager {
 		}
 	}
 	
-	private void initVelocityRender(ServletContext servletContext) {
-		try {
-			Class.forName("org.apache.velocity.VelocityContext");
-			VelocityRender.init(servletContext);
-		}
-		catch (ClassNotFoundException e) {
-			// System.out.println("Velocity can not be supported!");
-			LogKit.logNothing(e);
-		}
-	}
-	
 	private void initJspRender(ServletContext servletContext) {
 		try {
 			Class.forName("javax.el.ELResolver");

+ 0 - 149
src/main/java/com/jfinal/render/VelocityRender.java

@@ -1,149 +0,0 @@
-/**
- * Copyright (c) 2011-2021, James Zhan 詹波 (jfinal@126.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jfinal.render;
-
-import java.io.PrintWriter;
-import java.util.Enumeration;
-import java.util.Map.Entry;
-import java.util.Iterator;
-import java.util.Properties;
-import java.util.Set;
-import javax.servlet.ServletContext;
-import org.apache.velocity.Template;
-import org.apache.velocity.VelocityContext;
-import org.apache.velocity.app.Velocity;
-import org.apache.velocity.exception.ParseErrorException;
-import org.apache.velocity.exception.ResourceNotFoundException;
-
-/**
- * VelocityRender.
- */
-public class VelocityRender extends Render {
-	
-	private static final String contentType = "text/html; charset=" + getEncoding();
-	private static final Properties properties = new Properties();
-	
-	private static boolean notInit = true;
-	
-	public VelocityRender(String view) {
-		this.view = view;
-	}
-	
-	/*
-	static {
-		String webPath = RenderManager.me().getServletContext().getRealPath("/");
-		
-		Properties properties = new Properties();
-		properties.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, webPath);
-		properties.setProperty(Velocity.ENCODING_DEFAULT, encoding); 
-		properties.setProperty(Velocity.INPUT_ENCODING, encoding); 
-		properties.setProperty(Velocity.OUTPUT_ENCODING, encoding); 
-		
-		Velocity.init(properties);	// Velocity.init("velocity.properties");	// setup
-	}*/
-	
-	static void init(ServletContext servletContext) {
-		String webPath = servletContext.getRealPath("/");
-		if (webPath == null) {
-			try {
-				// 支持 weblogic: https://jfinal.com/feedback/1994
-				webPath = servletContext.getResource("/").getPath();
-			} catch (java.net.MalformedURLException e) {
-				com.jfinal.kit.LogKit.error(e.getMessage(), e);
-			}
-		}
-		properties.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, webPath);
-		properties.setProperty(Velocity.ENCODING_DEFAULT, getEncoding()); 
-		properties.setProperty(Velocity.INPUT_ENCODING, getEncoding()); 
-		properties.setProperty(Velocity.OUTPUT_ENCODING, getEncoding());
-	}
-	
-	public static void setProperties(Properties properties) {
-		Set<Entry<Object, Object>> set = properties.entrySet();
-		for (Iterator<Entry<Object, Object>> it=set.iterator(); it.hasNext();) {
-			Entry<Object, Object> e = it.next();
-			VelocityRender.properties.put(e.getKey(), e.getValue());
-		}
-	}
-	
-	/**
-	 * 继承类可通过覆盖此方法改变 contentType,从而重用 velocity 模板功能
-	 * 例如利用 velocity 实现  VelocityXmlRender
-	 */
-	public String getContentType() {
-		return contentType;
-	}
-	
-	public void render() {
-		 if (notInit) {
-			 Velocity.init(properties);	// Velocity.init("velocity.properties");	// setup
-			 notInit = false;
-		 }
-		
-		PrintWriter writer = null;
-        try {
-            /*
-             *  Make a context object and populate with the data.  This
-             *  is where the Velocity engine gets the data to resolve the
-             *  references (ex. $list) in the template
-             */
-            VelocityContext context = new VelocityContext();
-            
-    		// Map root = new HashMap();
-    		for (Enumeration<String> attrs=request.getAttributeNames(); attrs.hasMoreElements();) {
-    			String attrName = attrs.nextElement();
-    			context.put(attrName, request.getAttribute(attrName));
-    		}
-    		
-            /*
-             *  get the Template object.  This is the parsed version of your
-             *  template input file.  Note that getTemplate() can throw
-             *   ResourceNotFoundException : if it doesn't find the template
-             *   ParseErrorException : if there is something wrong with the VTL
-             *   Exception : if something else goes wrong (this is generally
-             *        indicative of as serious problem...)
-             */
-            Template template = Velocity.getTemplate(view);
-            
-            /*
-             *  Now have the template engine process your template using the
-             *  data placed into the context.  Think of it as a  'merge'
-             *  of the template and the data to produce the output stream.
-             */
-           response.setContentType(getContentType());
-           writer = response.getWriter();	// BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
-            
-           template.merge(context, writer);
-           writer.flush();	// flush and cleanup
-        }
-        catch(ResourceNotFoundException e) {
-        	throw new RenderException("Example : error : cannot find template " + view, e);
-        }
-        catch( ParseErrorException e) {
-            throw new RenderException("Example : Syntax error in template " + view + ":" + e, e);
-        }
-        catch(Exception e ) {
-            throw new RenderException(e);
-        }
-	}
-}
-
-
-
-
-
-

+ 1 - 2
src/main/java/com/jfinal/render/ViewType.java

@@ -22,6 +22,5 @@ package com.jfinal.render;
 public enum ViewType {
 	JFINAL_TEMPLATE,
 	JSP,
-	FREE_MARKER,
-	VELOCITY;
+	FREE_MARKER;
 }