Browse Source

MemoryStringSource 更名为 StringSource

James 8 years ago
parent
commit
1d48c6a100

+ 5 - 4
src/main/java/com/jfinal/template/Engine.java

@@ -24,6 +24,7 @@ import com.jfinal.kit.StrKit;
 import com.jfinal.template.expr.ast.MethodKit;
 import com.jfinal.template.source.FileSource;
 import com.jfinal.template.source.ISource;
+import com.jfinal.template.source.StringSource;
 import com.jfinal.template.stat.Parser;
 import com.jfinal.template.stat.ast.Stat;
 
@@ -159,7 +160,7 @@ public class Engine {
 	/**
 	 * Get template by string content and do not cache the template
 	 * 
-	 * 重要:MemoryStringSource 中的 key = HashKit.md5(content),也即 key
+	 * 重要:StringSource 中的 key = HashKit.md5(content),也即 key
 	 *     与 content 有紧密的对应关系,当 content 发生变化时 key 值也相应变化
 	 *     因此,原先 key 所对应的 Template 缓存对象已无法被获取,当 getTemplateByString(String)
 	 *     的 String 参数的数量不确定时会引发内存泄漏
@@ -178,17 +179,17 @@ public class Engine {
 	 */
 	public Template getTemplateByString(String content, boolean cache) {
 		if (!cache) {
-			return buildTemplateBySource(new MemoryStringSource(content, cache));
+			return buildTemplateBySource(new StringSource(content, cache));
 		}
 		
 		String key = HashKit.md5(content);
 		Template template = templateCache.get(key);
 		if (template == null) {
-			template = buildTemplateBySource(new MemoryStringSource(content, cache));
+			template = buildTemplateBySource(new StringSource(content, cache));
 			templateCache.put(key, template);
 		} else if (devMode) {
 			if (template.isModified()) {
-				template = buildTemplateBySource(new MemoryStringSource(content, cache));
+				template = buildTemplateBySource(new StringSource(content, cache));
 				templateCache.put(key, template);
 			}
 		}

+ 4 - 3
src/main/java/com/jfinal/template/EngineConfig.java

@@ -29,6 +29,7 @@ import com.jfinal.template.ext.directive.*;
 import com.jfinal.template.ext.sharedmethod.Json;
 import com.jfinal.template.source.FileSource;
 import com.jfinal.template.source.ISource;
+import com.jfinal.template.source.StringSource;
 import com.jfinal.template.stat.Location;
 import com.jfinal.template.stat.Parser;
 import com.jfinal.template.stat.ast.Define;
@@ -100,10 +101,10 @@ public class EngineConfig {
 	 * Add shared function by string content
 	 */
 	public void addSharedFunctionByString(String content) {
-		// content 中的内容被解析后会存放在 Env 之中,而 MemoryStringSource 所对应的
+		// content 中的内容被解析后会存放在 Env 之中,而 StringSource 所对应的
 		// Template 对象 isModified() 始终返回 false,所以没有必要对其缓存
-		MemoryStringSource memoryStringSource = new MemoryStringSource(content, false);
-		doAddSharedFunction(memoryStringSource, null);
+		StringSource stringSource = new StringSource(content, false);
+		doAddSharedFunction(stringSource, null);
 	}
 	
 	/**

+ 7 - 7
src/main/java/com/jfinal/template/MemoryStringSource.java

@@ -14,26 +14,26 @@
  * limitations under the License.
  */
 
-package com.jfinal.template;
+package com.jfinal.template.source;
 
 import com.jfinal.kit.HashKit;
 import com.jfinal.kit.StrKit;
-import com.jfinal.template.source.ISource;
+import com.jfinal.template.EngineConfig;
 
 /**
- * MemoryStringSource
+ * StringSource
  */
-public class MemoryStringSource implements ISource {
+public class StringSource implements ISource {
 	
 	private String key;
 	private StringBuilder content;
 	
 	/**
-	 * 构造 MemoryStringSource
+	 * 构造 StringSource
 	 * @param content 模板内容
 	 * @param cache true 则缓存 Template,否则不缓存
 	 */
-	public MemoryStringSource(String content, boolean cache) {
+	public StringSource(String content, boolean cache) {
 		if (StrKit.isBlank(content)) {
 			throw new IllegalArgumentException("content can not be blank");
 		}
@@ -41,7 +41,7 @@ public class MemoryStringSource implements ISource {
 		this.key = cache ? HashKit.md5(content) : null;	// 不缓存只要将 key 值赋为 null 即可
 	}
 	
-	public MemoryStringSource(StringBuilder content, boolean cache) {
+	public StringSource(StringBuilder content, boolean cache) {
 		if (content == null || content.length() == 0) {
 			throw new IllegalArgumentException("content can not be blank");
 		}