From 4ff87727d7e18545bed5872a81b8ff0da6f59cb3 Mon Sep 17 00:00:00 2001 From: zhaoxuyang03 Date: Fri, 5 Mar 2021 21:22:02 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E3=80=90Sprint3.3.3=E3=80=91=E3=80=90Bee?= =?UTF-8?q?tl=E3=80=91=E5=B0=86=20lab=20=E4=BB=8E=20core=20=E7=A7=BB?= =?UTF-8?q?=E5=88=B0=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/{main => test}/java/org/beetl/core/lab/BaseEntity.java | 0 src/{main => test}/java/org/beetl/core/lab/ColTag.java | 0 src/{main => test}/java/org/beetl/core/lab/MyTestObject.java | 0 src/{main => test}/java/org/beetl/core/lab/TableTag.java | 0 src/{main => test}/java/org/beetl/core/lab/TailBean.java | 0 src/{main => test}/java/org/beetl/core/lab/Test.java | 1 - src/{main => test}/java/org/beetl/core/lab/TestUser.java | 0 src/{main => test}/resources/lab/hello.txt | 0 src/{main => test}/resources/lab/index.btl | 0 src/{main => test}/resources/lab/layout.btl | 0 src/{main => test}/resources/lab/searchbar.btl | 0 11 files changed, 1 deletion(-) rename src/{main => test}/java/org/beetl/core/lab/BaseEntity.java (100%) rename src/{main => test}/java/org/beetl/core/lab/ColTag.java (100%) rename src/{main => test}/java/org/beetl/core/lab/MyTestObject.java (100%) rename src/{main => test}/java/org/beetl/core/lab/TableTag.java (100%) rename src/{main => test}/java/org/beetl/core/lab/TailBean.java (100%) rename src/{main => test}/java/org/beetl/core/lab/Test.java (97%) rename src/{main => test}/java/org/beetl/core/lab/TestUser.java (100%) rename src/{main => test}/resources/lab/hello.txt (100%) rename src/{main => test}/resources/lab/index.btl (100%) rename src/{main => test}/resources/lab/layout.btl (100%) rename src/{main => test}/resources/lab/searchbar.btl (100%) diff --git a/src/main/java/org/beetl/core/lab/BaseEntity.java b/src/test/java/org/beetl/core/lab/BaseEntity.java similarity index 100% rename from src/main/java/org/beetl/core/lab/BaseEntity.java rename to src/test/java/org/beetl/core/lab/BaseEntity.java diff --git a/src/main/java/org/beetl/core/lab/ColTag.java b/src/test/java/org/beetl/core/lab/ColTag.java similarity index 100% rename from src/main/java/org/beetl/core/lab/ColTag.java rename to src/test/java/org/beetl/core/lab/ColTag.java diff --git a/src/main/java/org/beetl/core/lab/MyTestObject.java b/src/test/java/org/beetl/core/lab/MyTestObject.java similarity index 100% rename from src/main/java/org/beetl/core/lab/MyTestObject.java rename to src/test/java/org/beetl/core/lab/MyTestObject.java diff --git a/src/main/java/org/beetl/core/lab/TableTag.java b/src/test/java/org/beetl/core/lab/TableTag.java similarity index 100% rename from src/main/java/org/beetl/core/lab/TableTag.java rename to src/test/java/org/beetl/core/lab/TableTag.java diff --git a/src/main/java/org/beetl/core/lab/TailBean.java b/src/test/java/org/beetl/core/lab/TailBean.java similarity index 100% rename from src/main/java/org/beetl/core/lab/TailBean.java rename to src/test/java/org/beetl/core/lab/TailBean.java diff --git a/src/main/java/org/beetl/core/lab/Test.java b/src/test/java/org/beetl/core/lab/Test.java similarity index 97% rename from src/main/java/org/beetl/core/lab/Test.java rename to src/test/java/org/beetl/core/lab/Test.java index ef5a73f..cdbe0a2 100644 --- a/src/main/java/org/beetl/core/lab/Test.java +++ b/src/test/java/org/beetl/core/lab/Test.java @@ -4,7 +4,6 @@ import org.beetl.core.Configuration; import org.beetl.core.GroupTemplate; import org.beetl.core.Template; import org.beetl.core.config.BeetlConfig; -import org.beetl.android.util.Log; import org.beetl.core.resource.ClasspathResourceLoader; /** diff --git a/src/main/java/org/beetl/core/lab/TestUser.java b/src/test/java/org/beetl/core/lab/TestUser.java similarity index 100% rename from src/main/java/org/beetl/core/lab/TestUser.java rename to src/test/java/org/beetl/core/lab/TestUser.java diff --git a/src/main/resources/lab/hello.txt b/src/test/resources/lab/hello.txt similarity index 100% rename from src/main/resources/lab/hello.txt rename to src/test/resources/lab/hello.txt diff --git a/src/main/resources/lab/index.btl b/src/test/resources/lab/index.btl similarity index 100% rename from src/main/resources/lab/index.btl rename to src/test/resources/lab/index.btl diff --git a/src/main/resources/lab/layout.btl b/src/test/resources/lab/layout.btl similarity index 100% rename from src/main/resources/lab/layout.btl rename to src/test/resources/lab/layout.btl diff --git a/src/main/resources/lab/searchbar.btl b/src/test/resources/lab/searchbar.btl similarity index 100% rename from src/main/resources/lab/searchbar.btl rename to src/test/resources/lab/searchbar.btl -- Gitee From 4fa509747569888fdfdeb555562d7f7e1a418b3a Mon Sep 17 00:00:00 2001 From: zhaoxuyang03 Date: Sun, 14 Mar 2021 19:40:38 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E3=80=90Sprint3.3.3=E3=80=91=E3=80=90Bee?= =?UTF-8?q?tl=E3=80=91IO=20=E5=B7=A5=E5=85=B7=E7=B1=BB=E5=89=8D=E7=BC=80?= =?UTF-8?q?=E6=94=B9=E4=B8=BABeetl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{ByteWriter.java => BeetlWriter.java} | 12 +++++----- src/main/java/org/beetl/core/BodyContent.java | 2 +- src/main/java/org/beetl/core/Context.java | 2 +- src/main/java/org/beetl/core/Script.java | 10 ++++----- src/main/java/org/beetl/core/Template.java | 22 +++++++++---------- .../java/org/beetl/core/TemplateProxy.java | 14 +++--------- .../core/engine/OnlineTemplateEngine.java | 6 ++--- .../beetl/core/fun/FileFunctionWrapper.java | 2 +- .../core/impl/DefaultBeetlConfigManager.java | 2 +- ...eWriter_Byte.java => BeetlByteWriter.java} | 16 +++++++------- ...eWriter_Char.java => BeetlCharWriter.java} | 16 +++++++------- .../org/beetl/core/io/ByteBodyContent.java | 4 ++-- .../org/beetl/core/io/FloatingIOWriter.java | 4 ++-- .../java/org/beetl/core/io/IntIOWriter.java | 10 ++++----- .../org/beetl/core/io/StringBodyContent.java | 4 ++-- .../java/org/beetl/core/misc/BeetlUtil.java | 22 +++++++++---------- .../core/statement/ContentBodyExpression.java | 10 ++++----- .../beetl/core/statement/PlaceholderST.java | 14 ++++++------ .../core/statement/StaticTextASTNode.java | 2 +- .../core/statement/StaticTextByteASTNode.java | 2 +- .../beetl/core/tag/HTMLTagSupportWrapper.java | 2 +- src/main/java/org/beetl/core/tag/Tag.java | 14 ++++++------ src/main/java/org/beetl/ext/fn/Flush.java | 2 +- src/main/java/org/beetl/ext/fn/Print.java | 2 +- src/main/java/org/beetl/ext/fn/PrintFile.java | 4 +--- src/main/java/org/beetl/ext/fn/Printf.java | 2 +- src/main/java/org/beetl/ext/fn/Println.java | 4 ++-- .../java/org/beetl/ext/jsp/IncludeJSPTag.java | 2 +- .../org/beetl/ext/tag/IncludeFragmentTag.java | 4 ++-- .../java/org/beetl/ext/tag/IncludeTag.java | 4 ++-- .../java/org/beetl/ext/tag/IncludeUrlTag.java | 2 +- .../java/org/beetl/ext/tag/LayoutTag.java | 2 +- .../org/beetl/ext/tag/html/IfHtmlTag.java | 7 ------ .../html/IncludeResourceFragmentHtmlTag.java | 4 ++-- .../ext/tag/html/IncludeResourceHtmlTag.java | 4 ++-- .../ext/tag/html/LayoutResourceHtmlTag.java | 2 +- .../core/function/SampleFunctionPackage.java | 2 +- .../org/beetl/core/tag/SimpleHtmlTag.java | 2 +- 38 files changed, 111 insertions(+), 130 deletions(-) rename src/main/java/org/beetl/core/{ByteWriter.java => BeetlWriter.java} (92%) rename src/main/java/org/beetl/core/io/{ByteWriter_Byte.java => BeetlByteWriter.java} (88%) rename src/main/java/org/beetl/core/io/{ByteWriter_Char.java => BeetlCharWriter.java} (87%) diff --git a/src/main/java/org/beetl/core/ByteWriter.java b/src/main/java/org/beetl/core/BeetlWriter.java similarity index 92% rename from src/main/java/org/beetl/core/ByteWriter.java rename to src/main/java/org/beetl/core/BeetlWriter.java index e261438..ddf3a0a 100644 --- a/src/main/java/org/beetl/core/ByteWriter.java +++ b/src/main/java/org/beetl/core/BeetlWriter.java @@ -38,13 +38,13 @@ import org.beetl.core.io.IntIOWriter; * * @author xiandafu */ -public abstract class ByteWriter { +public abstract class BeetlWriter { protected ContextBuffer localBuffer = null; protected Context ctx = null; - protected ByteWriter parent; + protected BeetlWriter parent; - public ByteWriter(Context ctx) { + public BeetlWriter(Context ctx) { this.ctx = ctx; this.localBuffer = ctx.localBuffer; } @@ -66,14 +66,14 @@ public abstract class ByteWriter { // public abstract void write(BodyContent bc) throws IOException; - public abstract ByteWriter getTempWriter(ByteWriter parent); + public abstract BeetlWriter getTempWriter(BeetlWriter parent); public abstract BodyContent getTempContent(); /** * 将内容填充到bw里 */ - public abstract void fill(ByteWriter bw) throws IOException; + public abstract void fill(BeetlWriter bw) throws IOException; public abstract void flush() throws IOException; @@ -114,7 +114,7 @@ public abstract class ByteWriter { return localBuffer; } - public ByteWriter getParent() { + public BeetlWriter getParent() { return parent; } diff --git a/src/main/java/org/beetl/core/BodyContent.java b/src/main/java/org/beetl/core/BodyContent.java index b8c6d7e..1cb56f1 100644 --- a/src/main/java/org/beetl/core/BodyContent.java +++ b/src/main/java/org/beetl/core/BodyContent.java @@ -46,6 +46,6 @@ public interface BodyContent { /** * 通过 {@param out} 写出暂存的内容 */ - void fill(ByteWriter out) throws IOException; + void fill(BeetlWriter out) throws IOException; } diff --git a/src/main/java/org/beetl/core/Context.java b/src/main/java/org/beetl/core/Context.java index a53c3ea..ccc0642 100644 --- a/src/main/java/org/beetl/core/Context.java +++ b/src/main/java/org/beetl/core/Context.java @@ -60,7 +60,7 @@ public class Context { /** * 采用的输出流 */ - public ByteWriter byteWriter; + public BeetlWriter beetlWriter; /** * 当前模板 diff --git a/src/main/java/org/beetl/core/Script.java b/src/main/java/org/beetl/core/Script.java index f6ab6c1..711a6e5 100644 --- a/src/main/java/org/beetl/core/Script.java +++ b/src/main/java/org/beetl/core/Script.java @@ -35,7 +35,7 @@ import java.util.Map.Entry; import org.beetl.core.exception.BeetlException; import org.beetl.core.exception.ErrorInfo; -import org.beetl.core.io.ByteWriter_Char; +import org.beetl.core.io.BeetlCharWriter; import org.beetl.core.misc.BeetlUtil; import org.beetl.core.statement.ErrorGrammarProgram; import org.beetl.core.statement.Program; @@ -133,15 +133,15 @@ public class Script extends Template{ * 获取模板输出的文本,输出到Writer里 */ public void renderTo(Writer writer) throws BeetlException { - ByteWriter_Char byteWriter = new ByteWriter_Char(writer, cf.charset, ctx); + BeetlCharWriter byteWriter = new BeetlCharWriter(writer, cf.charset, ctx); this.renderTo(byteWriter); } - public void renderTo(ByteWriter byteWriter) { + public void renderTo(BeetlWriter beetlWriter) { try { - ctx.byteWriter = byteWriter; + ctx.beetlWriter = beetlWriter; ctx.byteOutputMode = cf.directByteOutput; ctx.gt = this.gt; @@ -153,7 +153,7 @@ public class Script extends Template{ if (!(program instanceof ErrorGrammarProgram)) { e.pushResource(this.program.res); } - Writer w = BeetlUtil.getWriterByByteWriter(ctx.byteWriter); + Writer w = BeetlUtil.getWriterByByteWriter(ctx.beetlWriter); e.gt = this.program.gt; e.cr = this.program.metaData.lineSeparator; diff --git a/src/main/java/org/beetl/core/Template.java b/src/main/java/org/beetl/core/Template.java index 4c3bef6..b0d1da0 100644 --- a/src/main/java/org/beetl/core/Template.java +++ b/src/main/java/org/beetl/core/Template.java @@ -35,8 +35,8 @@ import java.util.Map.Entry; import org.beetl.core.cache.ContextBuffer; import org.beetl.core.exception.BeetlException; -import org.beetl.core.io.ByteWriter_Byte; -import org.beetl.core.io.ByteWriter_Char; +import org.beetl.core.io.BeetlByteWriter; +import org.beetl.core.io.BeetlCharWriter; import org.beetl.core.io.NoLockStringWriter; import org.beetl.core.misc.BeetlUtil; import org.beetl.core.statement.*; @@ -87,7 +87,7 @@ public class Template { * 获取模板输出的文本,输出到Writer里.可以使用{@code CachedStringWriter}来提高极限性能 */ public void renderTo(Writer writer) throws BeetlException { - ByteWriter_Char byteWriter = new ByteWriter_Char(writer, cf.charset, ctx); + BeetlCharWriter byteWriter = new BeetlCharWriter(writer, cf.charset, ctx); this.renderTo(byteWriter); } @@ -96,14 +96,14 @@ public class Template { * 获取模板输出的文本,输出到OutputStream里,tempalte必须在二进制输出模式下才能使用 */ public void renderTo(OutputStream os) throws BeetlException { - ByteWriter_Byte byteWriter = new ByteWriter_Byte(os, cf.charset, ctx); + BeetlByteWriter byteWriter = new BeetlByteWriter(os, cf.charset, ctx); this.renderTo(byteWriter); } - public void renderTo(ByteWriter byteWriter) { + public void renderTo(BeetlWriter beetlWriter) { try { - ctx.byteWriter = byteWriter; + ctx.beetlWriter = beetlWriter; ctx.byteOutputMode = cf.directByteOutput; ctx.gt = this.gt; ctx.template = this; @@ -141,7 +141,7 @@ public class Template { } if (isRoot) { - byteWriter.flush(); + beetlWriter.flush(); } } catch (BeetlException e) { if (!(program instanceof ErrorGrammarProgram)) { @@ -155,7 +155,7 @@ public class Template { return; } - Writer w = BeetlUtil.getWriterByByteWriter(ctx.byteWriter); + Writer w = BeetlUtil.getWriterByByteWriter(ctx.beetlWriter); e.gt = this.program.gt; e.cr = this.program.metaData.lineSeparator; @@ -166,7 +166,7 @@ public class Template { } errorHandler.processExcption(e, w); try { - ctx.byteWriter.flush(); + ctx.beetlWriter.flush(); } catch (IOException e1) { // 输出到客户端 } @@ -182,10 +182,10 @@ public class Template { if (errorHandler == null) { throw be; } - Writer w = BeetlUtil.getWriterByByteWriter(ctx.byteWriter); + Writer w = BeetlUtil.getWriterByByteWriter(ctx.beetlWriter); errorHandler.processExcption(be, w); try { - ctx.byteWriter.flush(); + ctx.beetlWriter.flush(); } catch (IOException e1) { // 输出到客户端 } diff --git a/src/main/java/org/beetl/core/TemplateProxy.java b/src/main/java/org/beetl/core/TemplateProxy.java index c782a76..ba451ad 100644 --- a/src/main/java/org/beetl/core/TemplateProxy.java +++ b/src/main/java/org/beetl/core/TemplateProxy.java @@ -1,15 +1,7 @@ package org.beetl.core; import org.beetl.core.exception.BeetlException; -import org.beetl.core.io.ByteWriter_Byte; -import org.beetl.core.io.ByteWriter_Char; -import org.beetl.core.io.NoLockStringWriter; -import org.beetl.core.misc.BeetlUtil; -import org.beetl.core.statement.*; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.Writer; + import java.util.Map; /** @@ -29,8 +21,8 @@ public class TemplateProxy extends Template { } - public void renderTo(ByteWriter byteWriter) { - current().renderTo(byteWriter); + public void renderTo(BeetlWriter beetlWriter) { + current().renderTo(beetlWriter); clear(); } diff --git a/src/main/java/org/beetl/core/engine/OnlineTemplateEngine.java b/src/main/java/org/beetl/core/engine/OnlineTemplateEngine.java index 90c08e6..9e5926c 100644 --- a/src/main/java/org/beetl/core/engine/OnlineTemplateEngine.java +++ b/src/main/java/org/beetl/core/engine/OnlineTemplateEngine.java @@ -124,8 +124,8 @@ public class OnlineTemplateEngine extends DefaultTemplateEngine { if (i >= sMaxNumLoop) { try { - ctx.byteWriter.writeString(sMaxNumLoopError); - ctx.byteWriter.flush(); + ctx.beetlWriter.writeString(sMaxNumLoopError); + ctx.beetlWriter.flush(); } catch (IOException ignored) { } } @@ -158,7 +158,7 @@ public class OnlineTemplateEngine extends DefaultTemplateEngine { if (i >= sMaxNumLoop) { try { - ctx.byteWriter.writeString(sMaxNumLoopError); + ctx.beetlWriter.writeString(sMaxNumLoopError); } catch (IOException ignored) { } } diff --git a/src/main/java/org/beetl/core/fun/FileFunctionWrapper.java b/src/main/java/org/beetl/core/fun/FileFunctionWrapper.java index e983780..b98c842 100644 --- a/src/main/java/org/beetl/core/fun/FileFunctionWrapper.java +++ b/src/main/java/org/beetl/core/fun/FileFunctionWrapper.java @@ -61,7 +61,7 @@ public class FileFunctionWrapper implements Function { template.binding("para".concat(String.valueOf(i)), paras[i]); } - template.renderTo(ctx.byteWriter); + template.renderTo(ctx.beetlWriter); Object[] vars = template.getCtx().vars; Object o = vars[vars.length - 1]; return o != Context.NOT_EXIST_OBJECT ? o : null; diff --git a/src/main/java/org/beetl/core/impl/DefaultBeetlConfigManager.java b/src/main/java/org/beetl/core/impl/DefaultBeetlConfigManager.java index c0fca74..3d06de0 100644 --- a/src/main/java/org/beetl/core/impl/DefaultBeetlConfigManager.java +++ b/src/main/java/org/beetl/core/impl/DefaultBeetlConfigManager.java @@ -39,6 +39,6 @@ public class DefaultBeetlConfigManager implements IBeetlConfigManager { @Override public String getBeetlVersion() { - return "3.3.2"; + return "3.3.3"; } } diff --git a/src/main/java/org/beetl/core/io/ByteWriter_Byte.java b/src/main/java/org/beetl/core/io/BeetlByteWriter.java similarity index 88% rename from src/main/java/org/beetl/core/io/ByteWriter_Byte.java rename to src/main/java/org/beetl/core/io/BeetlByteWriter.java index 011b4f0..c8c43aa 100644 --- a/src/main/java/org/beetl/core/io/ByteWriter_Byte.java +++ b/src/main/java/org/beetl/core/io/BeetlByteWriter.java @@ -31,10 +31,10 @@ import java.io.IOException; import java.io.OutputStream; import org.beetl.core.BodyContent; -import org.beetl.core.ByteWriter; +import org.beetl.core.BeetlWriter; import org.beetl.core.Context; -public class ByteWriter_Byte extends ByteWriter { +public class BeetlByteWriter extends BeetlWriter { protected OutputStream os; protected String cs; @@ -46,14 +46,14 @@ public class ByteWriter_Byte extends ByteWriter { * @param cs * @param ctx */ - public ByteWriter_Byte(OutputStream os, String cs, Context ctx) { + public BeetlByteWriter(OutputStream os, String cs, Context ctx) { super(ctx); this.os = os; this.cs = cs; encode = new DefaultEncoder(cs, this.localBuffer); } - public ByteWriter_Byte(OutputStream os, String cs, Context ctx, ByteWriter parent) { + public BeetlByteWriter(OutputStream os, String cs, Context ctx, BeetlWriter parent) { this(os, cs, ctx); this.parent = parent; } @@ -86,8 +86,8 @@ public class ByteWriter_Byte extends ByteWriter { } @Override - public ByteWriter getTempWriter(ByteWriter parent) { - return new ByteWriter_Byte(new NoLockByteArrayOutputStream(), cs, this.ctx, parent); + public BeetlWriter getTempWriter(BeetlWriter parent) { + return new BeetlByteWriter(new NoLockByteArrayOutputStream(), cs, this.ctx, parent); } @Override @@ -99,8 +99,8 @@ public class ByteWriter_Byte extends ByteWriter { } @Override - public void fill(ByteWriter bw) throws IOException { - ByteWriter_Byte bwb = (ByteWriter_Byte) bw; + public void fill(BeetlWriter bw) throws IOException { + BeetlByteWriter bwb = (BeetlByteWriter) bw; NoLockByteArrayOutputStream byteArray = (NoLockByteArrayOutputStream) bwb.os; this.write(byteArray.buf, byteArray.pos); } diff --git a/src/main/java/org/beetl/core/io/ByteWriter_Char.java b/src/main/java/org/beetl/core/io/BeetlCharWriter.java similarity index 87% rename from src/main/java/org/beetl/core/io/ByteWriter_Char.java rename to src/main/java/org/beetl/core/io/BeetlCharWriter.java index ca316bf..f55f3a5 100644 --- a/src/main/java/org/beetl/core/io/ByteWriter_Char.java +++ b/src/main/java/org/beetl/core/io/BeetlCharWriter.java @@ -22,21 +22,21 @@ import java.io.IOException; import java.io.Writer; import org.beetl.core.BodyContent; -import org.beetl.core.ByteWriter; +import org.beetl.core.BeetlWriter; import org.beetl.core.Context; -public final class ByteWriter_Char extends ByteWriter { +public final class BeetlCharWriter extends BeetlWriter { Writer w; String cs; - public ByteWriter_Char(Writer w, String cs, Context ctx) { + public BeetlCharWriter(Writer w, String cs, Context ctx) { super(ctx); this.w = w; this.cs = cs; } - public ByteWriter_Char(Writer w, String cs, Context ctx, ByteWriter parent) { + public BeetlCharWriter(Writer w, String cs, Context ctx, BeetlWriter parent) { this(w, cs, ctx); this.parent = parent; } @@ -76,8 +76,8 @@ public final class ByteWriter_Char extends ByteWriter { } @Override - public ByteWriter getTempWriter(ByteWriter parent) { - return new ByteWriter_Char(new NoLockStringWriter(), cs, ctx, parent); + public BeetlWriter getTempWriter(BeetlWriter parent) { + return new BeetlCharWriter(new NoLockStringWriter(), cs, ctx, parent); } @Override @@ -95,8 +95,8 @@ public final class ByteWriter_Char extends ByteWriter { } @Override - public void fill(ByteWriter bw) throws IOException { - NoLockStringWriter blw = ((NoLockStringWriter) ((ByteWriter_Char) bw).w); + public void fill(BeetlWriter bw) throws IOException { + NoLockStringWriter blw = ((NoLockStringWriter) ((BeetlCharWriter) bw).w); char[] buf = blw.buf; this.write(buf, blw.pos); } diff --git a/src/main/java/org/beetl/core/io/ByteBodyContent.java b/src/main/java/org/beetl/core/io/ByteBodyContent.java index f251473..f215170 100644 --- a/src/main/java/org/beetl/core/io/ByteBodyContent.java +++ b/src/main/java/org/beetl/core/io/ByteBodyContent.java @@ -31,7 +31,7 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import org.beetl.core.BodyContent; -import org.beetl.core.ByteWriter; +import org.beetl.core.BeetlWriter; /** * 模板变量对应的类型,其内容是字节 @@ -64,7 +64,7 @@ public class ByteBodyContent implements BodyContent { } @Override - public void fill(ByteWriter bw) throws IOException { + public void fill(BeetlWriter bw) throws IOException { bw.write(bs, count); } } diff --git a/src/main/java/org/beetl/core/io/FloatingIOWriter.java b/src/main/java/org/beetl/core/io/FloatingIOWriter.java index ddec66f..c1e0152 100644 --- a/src/main/java/org/beetl/core/io/FloatingIOWriter.java +++ b/src/main/java/org/beetl/core/io/FloatingIOWriter.java @@ -3,7 +3,7 @@ package org.beetl.core.io; import java.io.IOException; import java.util.regex.Pattern; -import org.beetl.core.ByteWriter; +import org.beetl.core.BeetlWriter; public class FloatingIOWriter { boolean isExceptional; @@ -861,7 +861,7 @@ public class FloatingIOWriter { return new String(result); } - public void write(ByteWriter bw, char[] buffer) throws IOException { + public void write(BeetlWriter bw, char[] buffer) throws IOException { int i = getChars(buffer); bw.writeNumberChars(buffer, i); diff --git a/src/main/java/org/beetl/core/io/IntIOWriter.java b/src/main/java/org/beetl/core/io/IntIOWriter.java index bfee406..6566851 100644 --- a/src/main/java/org/beetl/core/io/IntIOWriter.java +++ b/src/main/java/org/beetl/core/io/IntIOWriter.java @@ -1,7 +1,7 @@ package org.beetl.core.io; -import org.beetl.core.ByteWriter; +import org.beetl.core.BeetlWriter; import org.jetbrains.annotations.Range; import java.io.IOException; @@ -77,9 +77,9 @@ public class IntIOWriter { * * @param out 混合了字节和字符的Writer * @param value 即将写入到 {@param bw} 中的 Integer 类型 - * @throws IOException {@link ByteWriter#writeNumberChars} 或 {@link ByteWriter#writeString} + * @throws IOException {@link BeetlWriter#writeNumberChars} 或 {@link BeetlWriter#writeString} */ - public static void writeInt(ByteWriter out, int value) throws IOException { + public static void writeInt(BeetlWriter out, int value) throws IOException { // 命中预置的缓存 if (0 <= value && value < DEFAULT_INT_CHAR_ARRAY_CACHE_CAPACITY) { char[] buf = (char[]) INT_CHAR_ARRAY_CACHE[value]; @@ -105,9 +105,9 @@ public class IntIOWriter { * * @param out 混合了字节和字符的Writer * @param value 即将写入到 {@param bw} 中的 Long 类型 - * @throws IOException {@link ByteWriter#writeNumberChars} 或 {@link ByteWriter#writeString} + * @throws IOException {@link BeetlWriter#writeNumberChars} 或 {@link BeetlWriter#writeString} */ - public static void writeLong(ByteWriter out, long value) throws IOException { + public static void writeLong(BeetlWriter out, long value) throws IOException { // TODO: 类似 {@link #writeInteger} 加入缓存机制 if (value == Long.MIN_VALUE) { diff --git a/src/main/java/org/beetl/core/io/StringBodyContent.java b/src/main/java/org/beetl/core/io/StringBodyContent.java index 544cf37..f475d20 100644 --- a/src/main/java/org/beetl/core/io/StringBodyContent.java +++ b/src/main/java/org/beetl/core/io/StringBodyContent.java @@ -30,7 +30,7 @@ package org.beetl.core.io; import java.io.IOException; import org.beetl.core.BodyContent; -import org.beetl.core.ByteWriter; +import org.beetl.core.BeetlWriter; /** * 模板变量对应的类型,其内容是字符 @@ -66,7 +66,7 @@ public class StringBodyContent implements BodyContent { } @Override - public void fill(ByteWriter bw) throws IOException { + public void fill(BeetlWriter bw) throws IOException { bw.write(this.buf, count); } } diff --git a/src/main/java/org/beetl/core/misc/BeetlUtil.java b/src/main/java/org/beetl/core/misc/BeetlUtil.java index 362b52b..dadc18a 100644 --- a/src/main/java/org/beetl/core/misc/BeetlUtil.java +++ b/src/main/java/org/beetl/core/misc/BeetlUtil.java @@ -32,16 +32,14 @@ import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; import java.net.URISyntaxException; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; -import org.beetl.core.ByteWriter; +import org.beetl.core.BeetlWriter; import org.beetl.core.GroupTemplate; import org.beetl.core.fun.FileFunctionWrapper; -import org.beetl.core.io.ByteWriter_Byte; -import org.beetl.core.io.ByteWriter_Char; +import org.beetl.core.io.BeetlByteWriter; +import org.beetl.core.io.BeetlCharWriter; /** * Beetl使用方法 @@ -176,19 +174,19 @@ public class BeetlUtil { } - public static Writer getWriterByByteWriter(ByteWriter byteWriter) { + public static Writer getWriterByByteWriter(BeetlWriter beetlWriter) { - ByteWriter temp = null; - while ((temp = byteWriter.getParent()) != null) { - byteWriter = temp; + BeetlWriter temp = null; + while ((temp = beetlWriter.getParent()) != null) { + beetlWriter = temp; } Writer w = null; - if (byteWriter instanceof ByteWriter_Char) { - ByteWriter_Char bw = (ByteWriter_Char) byteWriter; + if (beetlWriter instanceof BeetlCharWriter) { + BeetlCharWriter bw = (BeetlCharWriter) beetlWriter; w = bw.getW(); } else { - ByteWriter_Byte bw = (ByteWriter_Byte) byteWriter; + BeetlByteWriter bw = (BeetlByteWriter) beetlWriter; try { w = new OutputStreamWriter(bw.getOs(), bw.getCs()); } catch (Exception ex) { diff --git a/src/main/java/org/beetl/core/statement/ContentBodyExpression.java b/src/main/java/org/beetl/core/statement/ContentBodyExpression.java index f47f5ec..1ade82f 100644 --- a/src/main/java/org/beetl/core/statement/ContentBodyExpression.java +++ b/src/main/java/org/beetl/core/statement/ContentBodyExpression.java @@ -27,7 +27,7 @@ */ package org.beetl.core.statement; -import org.beetl.core.ByteWriter; +import org.beetl.core.BeetlWriter; import org.beetl.core.Context; /** @@ -45,11 +45,11 @@ public class ContentBodyExpression extends Expression { } public Object evaluate(Context ctx) { - ByteWriter real = ctx.byteWriter; - ByteWriter temp = real.getTempWriter(real); - ctx.byteWriter = temp; + BeetlWriter real = ctx.beetlWriter; + BeetlWriter temp = real.getTempWriter(real); + ctx.beetlWriter = temp; block.execute(ctx); - ctx.byteWriter = real; + ctx.beetlWriter = real; return temp.getTempContent(); } diff --git a/src/main/java/org/beetl/core/statement/PlaceholderST.java b/src/main/java/org/beetl/core/statement/PlaceholderST.java index 3eada8b..19c2245 100644 --- a/src/main/java/org/beetl/core/statement/PlaceholderST.java +++ b/src/main/java/org/beetl/core/statement/PlaceholderST.java @@ -38,31 +38,31 @@ public class PlaceholderST extends Statement { } if (value != null) { if (value instanceof String) { - ctx.byteWriter.writeString((String) value); + ctx.beetlWriter.writeString((String) value); return; } else { if (value instanceof Number) { Class c = value.getClass(); if (c == Integer.class) { - ctx.byteWriter.writeInteger((Integer) value); + ctx.beetlWriter.writeInteger((Integer) value); return; } else if (c == Long.class) { - ctx.byteWriter.writeLong((Long) value); + ctx.beetlWriter.writeLong((Long) value); return; } else if (c == Double.class) { - ctx.byteWriter.writeDouble((Double) value); + ctx.beetlWriter.writeDouble((Double) value); return; } else if (c == Float.class) { - ctx.byteWriter.writeFloat((Float) value); + ctx.beetlWriter.writeFloat((Float) value); return; } else if (c == Short.class) { - ctx.byteWriter.writeShort((Short) value); + ctx.beetlWriter.writeShort((Short) value); return; } } } - ctx.byteWriter.writeString(value.toString()); + ctx.beetlWriter.writeString(value.toString()); } // ctx.byteWriter.writeObject(value); } catch (IOException e) { diff --git a/src/main/java/org/beetl/core/statement/StaticTextASTNode.java b/src/main/java/org/beetl/core/statement/StaticTextASTNode.java index b9a3dd4..2c4bef6 100644 --- a/src/main/java/org/beetl/core/statement/StaticTextASTNode.java +++ b/src/main/java/org/beetl/core/statement/StaticTextASTNode.java @@ -49,7 +49,7 @@ public final class StaticTextASTNode extends Statement { @Override public void execute(Context ctx) { try { - ctx.byteWriter.write((char[]) ctx.staticTextArray[textIndex]); + ctx.beetlWriter.write((char[]) ctx.staticTextArray[textIndex]); } catch (IOException ex) { BeetlException be = new BeetlException(BeetlException.CLIENT_IO_ERROR_ERROR, "Client IO Error", ex); diff --git a/src/main/java/org/beetl/core/statement/StaticTextByteASTNode.java b/src/main/java/org/beetl/core/statement/StaticTextByteASTNode.java index 75146b0..0a4ba27 100644 --- a/src/main/java/org/beetl/core/statement/StaticTextByteASTNode.java +++ b/src/main/java/org/beetl/core/statement/StaticTextByteASTNode.java @@ -49,7 +49,7 @@ public final class StaticTextByteASTNode extends Statement { @Override public void execute(Context ctx) { try { - ctx.byteWriter.write((byte[]) ctx.staticTextArray[textIndex]); + ctx.beetlWriter.write((byte[]) ctx.staticTextArray[textIndex]); } catch (IOException ex) { BeetlException be = new BeetlException(BeetlException.CLIENT_IO_ERROR_ERROR, "Client IO Error", ex); be.pushToken(this.token); diff --git a/src/main/java/org/beetl/core/tag/HTMLTagSupportWrapper.java b/src/main/java/org/beetl/core/tag/HTMLTagSupportWrapper.java index be10cf6..523874e 100644 --- a/src/main/java/org/beetl/core/tag/HTMLTagSupportWrapper.java +++ b/src/main/java/org/beetl/core/tag/HTMLTagSupportWrapper.java @@ -99,6 +99,6 @@ public class HTMLTagSupportWrapper extends Tag { } }); - t.renderTo(ctx.byteWriter); + t.renderTo(ctx.beetlWriter); } } diff --git a/src/main/java/org/beetl/core/tag/Tag.java b/src/main/java/org/beetl/core/tag/Tag.java index 5729660..f7f7e71 100644 --- a/src/main/java/org/beetl/core/tag/Tag.java +++ b/src/main/java/org/beetl/core/tag/Tag.java @@ -28,7 +28,7 @@ package org.beetl.core.tag; import org.beetl.core.BodyContent; -import org.beetl.core.ByteWriter; +import org.beetl.core.BeetlWriter; import org.beetl.core.Context; import org.beetl.core.GroupTemplate; import org.beetl.core.statement.Statement; @@ -58,7 +58,7 @@ public abstract class Tag { protected Object[] args = null; protected GroupTemplate gt; protected Context ctx; - protected ByteWriter bw; + protected BeetlWriter bw; //标签体 protected Statement bs; //父标签 @@ -77,11 +77,11 @@ public abstract class Tag { * 得到内容暂时保存在BodyContent。如果不需要保存直接输出,可以调用doBodyRender */ protected BodyContent getBodyContent() { - ByteWriter writer = ctx.byteWriter; - ByteWriter tempWriter = ctx.byteWriter.getTempWriter(writer); - ctx.byteWriter = tempWriter; + BeetlWriter writer = ctx.beetlWriter; + BeetlWriter tempWriter = ctx.beetlWriter.getTempWriter(writer); + ctx.beetlWriter = tempWriter; doBodyRender(); - ctx.byteWriter = writer; + ctx.beetlWriter = writer; return tempWriter.getTempContent(); } @@ -99,7 +99,7 @@ public abstract class Tag { protected void inintBase(Context ctx, Object[] args, Statement st) { this.ctx = ctx; - this.bw = ctx.byteWriter; + this.bw = ctx.beetlWriter; this.gt = ctx.gt; this.args = args; this.bs = st; diff --git a/src/main/java/org/beetl/ext/fn/Flush.java b/src/main/java/org/beetl/ext/fn/Flush.java index c79997d..62f6a5d 100644 --- a/src/main/java/org/beetl/ext/fn/Flush.java +++ b/src/main/java/org/beetl/ext/fn/Flush.java @@ -11,7 +11,7 @@ public class Flush implements Function { @Override public Object call(Object[] paras, Context ctx) { try { - ctx.byteWriter.flush(); + ctx.beetlWriter.flush(); return null; } catch (IOException e) { throw new BeetlException(BeetlException.CLIENT_IO_ERROR_ERROR, e.getMessage(), e); diff --git a/src/main/java/org/beetl/ext/fn/Print.java b/src/main/java/org/beetl/ext/fn/Print.java index 161f68b..f6a4288 100644 --- a/src/main/java/org/beetl/ext/fn/Print.java +++ b/src/main/java/org/beetl/ext/fn/Print.java @@ -44,7 +44,7 @@ public class Print implements Function { Object o = paras[0]; if (o != null) { try { - ctx.byteWriter.writeString(o.toString()); + ctx.beetlWriter.writeString(o.toString()); } catch (IOException e) { throw new BeetlException(BeetlException.CLIENT_IO_ERROR_ERROR); } diff --git a/src/main/java/org/beetl/ext/fn/PrintFile.java b/src/main/java/org/beetl/ext/fn/PrintFile.java index e69b70e..fdb771d 100644 --- a/src/main/java/org/beetl/ext/fn/PrintFile.java +++ b/src/main/java/org/beetl/ext/fn/PrintFile.java @@ -28,13 +28,11 @@ package org.beetl.ext.fn; import java.io.IOException; -import java.io.InputStream; import java.io.Reader; import org.beetl.core.Context; import org.beetl.core.Function; import org.beetl.core.Resource; -import org.beetl.core.exception.BeetlException; /** * ${includeStatic(file)} @@ -52,7 +50,7 @@ public class PrintFile implements Function { int rc = 0; try { while ((rc = reader.read(buff)) != -1) { - ctx.byteWriter.write(buff, rc); + ctx.beetlWriter.write(buff, rc); } } catch (IOException e) { throw new RuntimeException(e); diff --git a/src/main/java/org/beetl/ext/fn/Printf.java b/src/main/java/org/beetl/ext/fn/Printf.java index 56ef2a7..851c558 100644 --- a/src/main/java/org/beetl/ext/fn/Printf.java +++ b/src/main/java/org/beetl/ext/fn/Printf.java @@ -48,7 +48,7 @@ public class Printf implements Function { f.format(template, args); try { - ctx.byteWriter.writeString(sb.toString()); + ctx.beetlWriter.writeString(sb.toString()); } catch (IOException e) { throw new BeetlException(BeetlException.CLIENT_IO_ERROR_ERROR); } diff --git a/src/main/java/org/beetl/ext/fn/Println.java b/src/main/java/org/beetl/ext/fn/Println.java index 2ea0843..06a586c 100644 --- a/src/main/java/org/beetl/ext/fn/Println.java +++ b/src/main/java/org/beetl/ext/fn/Println.java @@ -29,7 +29,7 @@ package org.beetl.ext.fn; import java.io.IOException; -import org.beetl.core.ByteWriter; +import org.beetl.core.BeetlWriter; import org.beetl.core.Context; import org.beetl.core.Function; import org.beetl.core.exception.BeetlException; @@ -43,7 +43,7 @@ public class Println implements Function { public String call(Object[] paras, Context ctx) { try { - ByteWriter w = ctx.byteWriter; + BeetlWriter w = ctx.beetlWriter; if (paras.length == 0) { w.writeString(ctx.template.program.metaData.lineSeparator); return ""; diff --git a/src/main/java/org/beetl/ext/jsp/IncludeJSPTag.java b/src/main/java/org/beetl/ext/jsp/IncludeJSPTag.java index 7fe3309..06578f3 100644 --- a/src/main/java/org/beetl/ext/jsp/IncludeJSPTag.java +++ b/src/main/java/org/beetl/ext/jsp/IncludeJSPTag.java @@ -57,7 +57,7 @@ public class IncludeJSPTag extends Tag { String realJspPath = getJSPPath(prefix, child); request.getRequestDispatcher(realJspPath).include(request, rspWrapper); - ctx.byteWriter.writeString(rspWrapper.getRealWriter().toString()); + ctx.beetlWriter.writeString(rspWrapper.getRealWriter().toString()); } catch (IOException e) { e.printStackTrace(); diff --git a/src/main/java/org/beetl/ext/tag/IncludeFragmentTag.java b/src/main/java/org/beetl/ext/tag/IncludeFragmentTag.java index b36b413..976300f 100644 --- a/src/main/java/org/beetl/ext/tag/IncludeFragmentTag.java +++ b/src/main/java/org/beetl/ext/tag/IncludeFragmentTag.java @@ -27,7 +27,7 @@ */ package org.beetl.ext.tag; -import org.beetl.core.ByteWriter; +import org.beetl.core.BeetlWriter; import org.beetl.core.Resource; import org.beetl.core.Template; import org.beetl.core.tag.Tag; @@ -76,7 +76,7 @@ public class IncludeFragmentTag extends Tag { } } - ByteWriter bw = ctx.byteWriter; + BeetlWriter bw = ctx.beetlWriter; t.renderTo(bw); } diff --git a/src/main/java/org/beetl/ext/tag/IncludeTag.java b/src/main/java/org/beetl/ext/tag/IncludeTag.java index cd31b22..c7200d1 100644 --- a/src/main/java/org/beetl/ext/tag/IncludeTag.java +++ b/src/main/java/org/beetl/ext/tag/IncludeTag.java @@ -30,7 +30,7 @@ package org.beetl.ext.tag; import java.util.Map; import java.util.Map.Entry; -import org.beetl.core.ByteWriter; +import org.beetl.core.BeetlWriter; import org.beetl.core.Resource; import org.beetl.core.Template; import org.beetl.core.tag.Tag; @@ -53,7 +53,7 @@ public class IncludeTag extends Tag { } } - ByteWriter bw = ctx.byteWriter; + BeetlWriter bw = ctx.beetlWriter; t.renderTo(bw); } diff --git a/src/main/java/org/beetl/ext/tag/IncludeUrlTag.java b/src/main/java/org/beetl/ext/tag/IncludeUrlTag.java index 3f25514..792d5bb 100644 --- a/src/main/java/org/beetl/ext/tag/IncludeUrlTag.java +++ b/src/main/java/org/beetl/ext/tag/IncludeUrlTag.java @@ -51,7 +51,7 @@ public class IncludeUrlTag extends Tag { } BeetlServletResponseWrapper rspWrapper = new BeetlServletResponseWrapper(response); request.getRequestDispatcher(child).include(request, rspWrapper); - ctx.byteWriter.writeString(rspWrapper.getRealWriter().toString()); + ctx.beetlWriter.writeString(rspWrapper.getRealWriter().toString()); } catch (IOException e) { e.printStackTrace(); diff --git a/src/main/java/org/beetl/ext/tag/LayoutTag.java b/src/main/java/org/beetl/ext/tag/LayoutTag.java index 5426729..ac48a78 100644 --- a/src/main/java/org/beetl/ext/tag/LayoutTag.java +++ b/src/main/java/org/beetl/ext/tag/LayoutTag.java @@ -102,7 +102,7 @@ public class LayoutTag extends Tag { } else { t.binding(defaultLayoutName, content); } - t.renderTo(ctx.byteWriter); + t.renderTo(ctx.beetlWriter); } diff --git a/src/main/java/org/beetl/ext/tag/html/IfHtmlTag.java b/src/main/java/org/beetl/ext/tag/html/IfHtmlTag.java index 5fb1bc1..29d558e 100644 --- a/src/main/java/org/beetl/ext/tag/html/IfHtmlTag.java +++ b/src/main/java/org/beetl/ext/tag/html/IfHtmlTag.java @@ -27,15 +27,8 @@ */ package org.beetl.ext.tag.html; -import org.beetl.core.ByteWriter; -import org.beetl.core.Resource; -import org.beetl.core.Template; -import org.beetl.core.exception.BeetlException; import org.beetl.core.tag.Tag; -import java.util.Map; -import java.util.Map.Entry; - /** * 一个html标签方式的tag,同includeTag *
diff --git a/src/main/java/org/beetl/ext/tag/html/IncludeResourceFragmentHtmlTag.java b/src/main/java/org/beetl/ext/tag/html/IncludeResourceFragmentHtmlTag.java
index d771b2a..16b92a2 100644
--- a/src/main/java/org/beetl/ext/tag/html/IncludeResourceFragmentHtmlTag.java
+++ b/src/main/java/org/beetl/ext/tag/html/IncludeResourceFragmentHtmlTag.java
@@ -27,7 +27,7 @@
  */
 package org.beetl.ext.tag.html;
 
-import org.beetl.core.ByteWriter;
+import org.beetl.core.BeetlWriter;
 import org.beetl.core.Resource;
 import org.beetl.core.Template;
 import org.beetl.core.exception.BeetlException;
@@ -64,7 +64,7 @@ public class IncludeResourceFragmentHtmlTag extends Tag {
 
         }
 
-        ByteWriter bw = ctx.byteWriter;
+        BeetlWriter bw = ctx.beetlWriter;
         t.renderTo(bw);
 
     }
diff --git a/src/main/java/org/beetl/ext/tag/html/IncludeResourceHtmlTag.java b/src/main/java/org/beetl/ext/tag/html/IncludeResourceHtmlTag.java
index 2aef5c5..413d4b7 100644
--- a/src/main/java/org/beetl/ext/tag/html/IncludeResourceHtmlTag.java
+++ b/src/main/java/org/beetl/ext/tag/html/IncludeResourceHtmlTag.java
@@ -30,7 +30,7 @@ package org.beetl.ext.tag.html;
 import java.util.Map;
 import java.util.Map.Entry;
 
-import org.beetl.core.ByteWriter;
+import org.beetl.core.BeetlWriter;
 import org.beetl.core.Resource;
 import org.beetl.core.Template;
 import org.beetl.core.exception.BeetlException;
@@ -66,7 +66,7 @@ public class IncludeResourceHtmlTag extends Tag {
 
         }
 
-        ByteWriter bw = ctx.byteWriter;
+        BeetlWriter bw = ctx.beetlWriter;
         t.renderTo(bw);
 
     }
diff --git a/src/main/java/org/beetl/ext/tag/html/LayoutResourceHtmlTag.java b/src/main/java/org/beetl/ext/tag/html/LayoutResourceHtmlTag.java
index 9477d64..dd55e57 100644
--- a/src/main/java/org/beetl/ext/tag/html/LayoutResourceHtmlTag.java
+++ b/src/main/java/org/beetl/ext/tag/html/LayoutResourceHtmlTag.java
@@ -68,7 +68,7 @@ public class LayoutResourceHtmlTag extends Tag {
 
         BodyContent content = this.getBodyContent();
         t.binding(layoutName, content);
-        t.renderTo(ctx.byteWriter);
+        t.renderTo(ctx.beetlWriter);
 
     }
 
diff --git a/src/test/java/org/beetl/core/function/SampleFunctionPackage.java b/src/test/java/org/beetl/core/function/SampleFunctionPackage.java
index 8a7a154..de3e75a 100644
--- a/src/test/java/org/beetl/core/function/SampleFunctionPackage.java
+++ b/src/test/java/org/beetl/core/function/SampleFunctionPackage.java
@@ -6,7 +6,7 @@ public class SampleFunctionPackage
 {
 	public void test1(Context ctx) throws Exception
 	{
-		ctx.byteWriter.writeString("hi");
+		ctx.beetlWriter.writeString("hi");
 		//ctx.byteWriter.write(ctx.template.program.metaData.lineSeparator);
 
 	}
diff --git a/src/test/java/org/beetl/core/tag/SimpleHtmlTag.java b/src/test/java/org/beetl/core/tag/SimpleHtmlTag.java
index 1af9a4f..a7afadd 100644
--- a/src/test/java/org/beetl/core/tag/SimpleHtmlTag.java
+++ b/src/test/java/org/beetl/core/tag/SimpleHtmlTag.java
@@ -14,7 +14,7 @@ public class SimpleHtmlTag extends Tag
 		String value = (String) map.get("attr");
 		try
 		{
-			this.ctx.byteWriter.writeString(value);
+			this.ctx.beetlWriter.writeString(value);
 		}
 		catch (IOException e)
 		{
-- 
Gitee


From 59e057276320cf9586f7c63d1e86774394ed6c0f Mon Sep 17 00:00:00 2001
From: zhaoxuyang03 
Date: Sun, 14 Mar 2021 19:54:32 +0800
Subject: [PATCH 03/10] =?UTF-8?q?=E3=80=90Sprint3.3.3=E3=80=91=E3=80=90Bee?=
 =?UTF-8?q?tl=E3=80=91=E6=9C=AC=E5=9C=B0=E8=B0=83=E7=94=A8=E5=AE=89?=
 =?UTF-8?q?=E5=85=A8=E7=AE=A1=E7=90=86=E5=99=A8-=E9=87=8D=E6=9E=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 beetl.md                                      | 39 +++++++++----------
 .../java/org/beetl/core/Configuration.java    |  2 +-
 .../java/org/beetl/core/GroupTemplate.java    |  9 +++--
 .../DefaultNativeSecurityManager.java         |  8 ++--
 .../INativeSecurityManager.java}              |  4 +-
 .../core/statement/NativeCallExpression.java  |  4 +-
 .../org/beetl/core/beetl-default.properties   |  2 +-
 7 files changed, 35 insertions(+), 33 deletions(-)
 rename src/main/java/org/beetl/core/{ => impl/security}/DefaultNativeSecurityManager.java (91%)
 rename src/main/java/org/beetl/core/{NativeSecurityManager.java => runtime/INativeSecurityManager.java} (96%)

diff --git a/beetl.md b/beetl.md
index e58817d..a9c45e0 100644
--- a/beetl.md
+++ b/beetl.md
@@ -109,40 +109,39 @@ DELIMITER_PLACEHOLDER_START=${
 DELIMITER_PLACEHOLDER_END=}
 DELIMITER_STATEMENT_START=<%
 DELIMITER_STATEMENT_END=%>
-DIRECT_BYTE_OUTPUT = FALSE
-HTML_TAG_SUPPORT = true
-HTML_TAG_FLAG = #
-HTML_TAG_BINDING_ATTRIBUTE = var
-NATIVE_CALL = TRUE
-TEMPLATE_CHARSET = UTF-8
-ERROR_HANDLER = org.beetl.core.ConsoleErrorHandler
-NATIVE_SECUARTY_MANAGER= org.beetl.core.DefaultNativeSecurityManager
-MVC_STRICT = FALSE
-
+DIRECT_BYTE_OUTPUT=FALSE
+HTML_TAG_SUPPORT=true
+HTML_TAG_FLAG=#
+HTML_TAG_BINDING_ATTRIBUTE=var
+NATIVE_CALL=TRUE
+TEMPLATE_CHARSET=UTF-8
+ERROR_HANDLER=org.beetl.core.ConsoleErrorHandler
+NATIVE_SECUARTY_MANAGER=org.beetl.core.impl.security.DefaultNativeSecurityManager
+MVC_STRICT=FALSE
 #资源配置,resource后的属性只限于特定ResourceLoader
 RESOURCE_LOADER=org.beetl.core.resource.ClasspathResourceLoader
 #classpath 根路径
-RESOURCE.root= /
+RESOURCE.root=/
 #是否检测文件变化
-RESOURCE.autoCheck= true
+RESOURCE.autoCheck=true
 #自定义脚本方法文件的Root目录和后缀
-RESOURCE.functionRoot = functions
-RESOURCE.functionSuffix = html
+RESOURCE.functionRoot=functions
+RESOURCE.functionSuffix=html
 #自定义标签文件Root目录和后缀
-RESOURCE.tagRoot = htmltag
-RESOURCE.tagSuffix = tag
+RESOURCE.tagRoot=htmltag
+RESOURCE.tagSuffix=tag
 #####  扩展 ##############
 ## 内置的方法
-FN.date = org.beetl.ext.fn.DateFunction
+FN.date=org.beetl.ext.fn.DateFunction
 ......
 ##内置的功能包
-FNP.strutil = org.beetl.ext.fn.StringUtil
+FNP.strutil=org.beetl.ext.fn.StringUtil
 ......
 ##内置的默认格式化函数
-FTC.java.util.Date = org.beetl.ext.format.DateFormat
+FTC.java.util.Date=org.beetl.ext.format.DateFormat
 .....
 ## 标签类
-TAG.include= org.beetl.ext.tag.IncludeTag
+TAG.include=org.beetl.ext.tag.IncludeTag
 ```
 
 第2行配置引擎实现类,默认即可.
diff --git a/src/main/java/org/beetl/core/Configuration.java b/src/main/java/org/beetl/core/Configuration.java
index b75a645..f9bd1ac 100644
--- a/src/main/java/org/beetl/core/Configuration.java
+++ b/src/main/java/org/beetl/core/Configuration.java
@@ -117,7 +117,7 @@ public class Configuration {
 
     /** {@code String engine = "org.beetl.core.DefaultTemplateEngine";} */
     String engine = "org.beetl.core.FastRuntimeEngine";
-    String nativeSecurity = "org.beetl.core.DefaultNativeSecurityManager";
+    String nativeSecurity = "org.beetl.core.impl.security.DefaultNativeSecurityManager";
     String resourceLoader = "org.beetl.core.resource.ClasspathResourceLoader";
 
     // 扩展资源
diff --git a/src/main/java/org/beetl/core/GroupTemplate.java b/src/main/java/org/beetl/core/GroupTemplate.java
index c9dec15..1db5403 100644
--- a/src/main/java/org/beetl/core/GroupTemplate.java
+++ b/src/main/java/org/beetl/core/GroupTemplate.java
@@ -55,6 +55,7 @@ import org.beetl.core.misc.ClassSearch;
 import org.beetl.core.misc.PrimitiveArrayUtil;
 import org.beetl.core.om.AABuilder;
 import org.beetl.core.resource.ClasspathResourceLoader;
+import org.beetl.core.runtime.INativeSecurityManager;
 import org.beetl.core.statement.ErrorGrammarProgram;
 import org.beetl.core.statement.Program;
 import org.beetl.core.tag.TagFactory;
@@ -97,7 +98,7 @@ public class GroupTemplate {
     /** 用于查找类的工具 */
     ClassSearch classSearch = null;
     /** 本地调用(这里就是Java)安全管理器 */
-    NativeSecurityManager nativeSecurity = null;
+    INativeSecurityManager nativeSecurity = null;
     /** 错误处理类 */
     ErrorHandler errorHandler = null;
     /** 共享变量 */
@@ -183,7 +184,7 @@ public class GroupTemplate {
         this.initBuffers();
 
         classSearch = new ClassSearch(conf.getPkgList(), this);
-        nativeSecurity = (NativeSecurityManager) ObjectUtil.instance(conf.getNativeSecurity(), this.classLoader);
+        nativeSecurity = (INativeSecurityManager) ObjectUtil.instance(conf.getNativeSecurity(), this.classLoader);
         if (conf.errorHandlerClass == null) {
             errorHandler = null;
         } else {
@@ -714,11 +715,11 @@ public class GroupTemplate {
         return this.classSearch.getClassByName(simpleName);
     }
 
-    public NativeSecurityManager getNativeSecurity() {
+    public INativeSecurityManager getNativeSecurity() {
         return nativeSecurity;
     }
 
-    public void setNativeSecurity(NativeSecurityManager nativeSecurity){
+    public void setNativeSecurity(INativeSecurityManager nativeSecurity){
     	this.nativeSecurity = nativeSecurity;
 	}
 
diff --git a/src/main/java/org/beetl/core/DefaultNativeSecurityManager.java b/src/main/java/org/beetl/core/impl/security/DefaultNativeSecurityManager.java
similarity index 91%
rename from src/main/java/org/beetl/core/DefaultNativeSecurityManager.java
rename to src/main/java/org/beetl/core/impl/security/DefaultNativeSecurityManager.java
index 99cfce8..cf8ab9f 100644
--- a/src/main/java/org/beetl/core/DefaultNativeSecurityManager.java
+++ b/src/main/java/org/beetl/core/impl/security/DefaultNativeSecurityManager.java
@@ -25,19 +25,21 @@
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-package org.beetl.core;
+package org.beetl.core.impl.security;
+
+import org.beetl.core.runtime.INativeSecurityManager;
 
 /**
  * 默认的本地调用安全管理器,黑名单方式,不允许调用java.lang.Runtime和Process
  *
  * @author xiandafu
  */
-public class DefaultNativeSecurityManager implements NativeSecurityManager {
+public class DefaultNativeSecurityManager implements INativeSecurityManager {
 
     /*
      * (non-Javadoc)
      *
-     * @see org.beetl.core.NativeSecurityManager#permit(java.lang.String,
+     * @see org.beetl.core.runtime.NativeSecurityManager#permit(java.lang.String,
      * java.lang.Class, java.lang.Object, java.lang.String)
      */
     @Override
diff --git a/src/main/java/org/beetl/core/NativeSecurityManager.java b/src/main/java/org/beetl/core/runtime/INativeSecurityManager.java
similarity index 96%
rename from src/main/java/org/beetl/core/NativeSecurityManager.java
rename to src/main/java/org/beetl/core/runtime/INativeSecurityManager.java
index 5f31551..ceca94f 100644
--- a/src/main/java/org/beetl/core/NativeSecurityManager.java
+++ b/src/main/java/org/beetl/core/runtime/INativeSecurityManager.java
@@ -25,14 +25,14 @@
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-package org.beetl.core;
+package org.beetl.core.runtime;
 
 /**
  * 判断是否允许调用本地方法
  *
  * @author xiandafu
  */
-public interface NativeSecurityManager {
+public interface INativeSecurityManager {
     /**
      * 判断是否允许调用本地方法
      *
diff --git a/src/main/java/org/beetl/core/statement/NativeCallExpression.java b/src/main/java/org/beetl/core/statement/NativeCallExpression.java
index 7088783..6e8f829 100644
--- a/src/main/java/org/beetl/core/statement/NativeCallExpression.java
+++ b/src/main/java/org/beetl/core/statement/NativeCallExpression.java
@@ -5,7 +5,7 @@ import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Modifier;
 
 import org.beetl.core.Context;
-import org.beetl.core.NativeSecurityManager;
+import org.beetl.core.runtime.INativeSecurityManager;
 import org.beetl.core.exception.BeetlException;
 import org.beetl.core.exception.BeetlParserException;
 import org.beetl.core.misc.BeetlUtil;
@@ -164,7 +164,7 @@ public class NativeCallExpression extends Expression {
         if (targetCls == null) {
             return;
         }
-        NativeSecurityManager securityManager = ctx.gt.getNativeSecurity();
+        INativeSecurityManager securityManager = ctx.gt.getNativeSecurity();
         if (securityManager == null) {
             return;
         }
diff --git a/src/main/resources/org/beetl/core/beetl-default.properties b/src/main/resources/org/beetl/core/beetl-default.properties
index f38eb71..7551251 100644
--- a/src/main/resources/org/beetl/core/beetl-default.properties
+++ b/src/main/resources/org/beetl/core/beetl-default.properties
@@ -12,7 +12,7 @@ HTML_TAG_ATTR_CONVERT=org.beetl.core.text.DefaultAttributeNameConvert
 NATIVE_CALL = true
 TEMPLATE_CHARSET = UTF-8
 ERROR_HANDLER = org.beetl.core.ConsoleErrorHandler
-NATIVE_SECUARTY_MANAGER= org.beetl.core.DefaultNativeSecurityManager
+NATIVE_SECUARTY_MANAGER= org.beetl.core.impl.security.DefaultNativeSecurityManager
 RESOURCE_LOADER=org.beetl.core.resource.ClasspathResourceLoader
 MVC_STRICT = false
 SAFE_OUTPUT=false
-- 
Gitee


From 5426b25d358bf3efbc1bd82f5e9f3b4d5a0215b6 Mon Sep 17 00:00:00 2001
From: zhaoxuyang03 
Date: Sun, 14 Mar 2021 20:10:04 +0800
Subject: [PATCH 04/10] =?UTF-8?q?=E3=80=90Sprint3.3.3=E3=80=91=E3=80=90Bee?=
 =?UTF-8?q?tl=E3=80=91=E8=B5=84=E6=BA=90=E5=8A=A0=E8=BD=BD=E5=99=A8-?=
 =?UTF-8?q?=E9=87=8D=E6=9E=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 beetl.md                                      |  8 ++---
 src/main/java/org/beetl/core/BeetlKit.java    |  2 +-
 .../java/org/beetl/core/Configuration.java    |  2 +-
 .../org/beetl/core/ConsoleErrorHandler.java   |  4 +--
 .../java/org/beetl/core/GroupTemplate.java    | 33 ++++++++++---------
 src/main/java/org/beetl/core/Resource.java    | 10 +++---
 .../matcher}/AllowAllMatcher.java             |  6 ++--
 .../matcher}/StartsWithMatcher.java           |  5 +--
 .../resource/ClasspathResource.java           | 14 +++++---
 .../resource/ClasspathResourceLoader.java     | 12 +++----
 .../resource/CompositeResourceLoader.java     | 31 ++++++++---------
 .../{ => impl}/resource/FileResource.java     |  6 ++--
 .../resource/FileResourceLoader.java          |  7 ++--
 .../resource/MapResourceLoader.java           | 18 ++++++----
 .../resource/StringTemplateResource.java      |  8 ++---
 .../StringTemplateResourceLoader.java         |  6 ++--
 .../resource/WebAppResourceLoader.java        |  2 +-
 .../Matcher.java => runtime/IMatcher.java}    |  4 +--
 .../IResourceLoader.java}                     | 31 +++++++++--------
 .../org/beetl/ext/jodd/BeetlActionResult.java |  2 +-
 .../java/org/beetl/ext/jsp/IncludeJSPTag.java |  6 ++--
 .../org/beetl/ext/nutz/BeetlViewMaker.java    |  4 +--
 .../ext/servlet/ServletGroupTemplate.java     |  2 +-
 .../org/beetl/ext/simulate/BaseSimulate.java  |  5 ++-
 .../spring/BeetlGroupUtilConfiguration.java   |  9 +++--
 .../ext/struts2/Struts2BeetlActionResult.java |  2 +-
 .../org/beetl/ext/web/WebErrorHandler.java    |  4 +--
 .../org/beetl/core/beetl-default.properties   |  2 +-
 .../java/org/beetl/core/BasicTestCase.java    |  2 +-
 .../beetl/core/function/FileFunctionTest.java |  2 +-
 src/test/java/org/beetl/core/lab/Test.java    |  2 +-
 .../org/beetl/core/nativecall/NativeTest.java |  2 +-
 .../CompositeResourceLoaderTest.java          |  8 ++---
 .../resourceloader/MapResourceLoader.java     |  6 ++--
 .../resourceloader/ResourceLoaderTest.java    |  4 +--
 .../java/org/beetl/core/tag/HtmlTagTest.java  |  2 +-
 .../java/org/beetl/core/text/PairDLTest.java  |  2 +-
 .../org/beetl/core/text/SingleDLTest.java     |  2 +-
 .../beetl/core/va/VirtualAttributeTest.java   |  2 +-
 .../beetl/ext/nutz/BeetlViewMakerTest.java    |  2 +-
 40 files changed, 147 insertions(+), 134 deletions(-)
 rename src/main/java/org/beetl/core/{resource => impl/matcher}/AllowAllMatcher.java (93%)
 rename src/main/java/org/beetl/core/{resource => impl/matcher}/StartsWithMatcher.java (96%)
 rename src/main/java/org/beetl/core/{ => impl}/resource/ClasspathResource.java (92%)
 rename src/main/java/org/beetl/core/{ => impl}/resource/ClasspathResourceLoader.java (95%)
 rename src/main/java/org/beetl/core/{ => impl}/resource/CompositeResourceLoader.java (84%)
 rename src/main/java/org/beetl/core/{ => impl}/resource/FileResource.java (89%)
 rename src/main/java/org/beetl/core/{ => impl}/resource/FileResourceLoader.java (95%)
 rename src/main/java/org/beetl/core/{ => impl}/resource/MapResourceLoader.java (84%)
 rename src/main/java/org/beetl/core/{ => impl}/resource/StringTemplateResource.java (91%)
 rename src/main/java/org/beetl/core/{ => impl}/resource/StringTemplateResourceLoader.java (93%)
 rename src/main/java/org/beetl/core/{ => impl}/resource/WebAppResourceLoader.java (98%)
 rename src/main/java/org/beetl/core/{resource/Matcher.java => runtime/IMatcher.java} (96%)
 rename src/main/java/org/beetl/core/{ResourceLoader.java => runtime/IResourceLoader.java} (76%)

diff --git a/beetl.md b/beetl.md
index a9c45e0..6966d55 100644
--- a/beetl.md
+++ b/beetl.md
@@ -119,7 +119,7 @@ ERROR_HANDLER=org.beetl.core.ConsoleErrorHandler
 NATIVE_SECUARTY_MANAGER=org.beetl.core.impl.security.DefaultNativeSecurityManager
 MVC_STRICT=FALSE
 #资源配置,resource后的属性只限于特定ResourceLoader
-RESOURCE_LOADER=org.beetl.core.resource.ClasspathResourceLoader
+RESOURCE_LOADER=org.beetl.core.impl.resource.ClasspathResourceLoader
 #classpath 根路径
 RESOURCE.root=/
 #是否检测文件变化
@@ -1247,12 +1247,12 @@ Beetl建议通过配置文件配置配置GroupTemplate,主要考虑到未来
 配置文件分为三部分,第一部分是基本配置,在第一节讲到过。第二部分是资源类配置,可以在指定资源加载类,以及资源加载器的属性,如下
 
 ```properties
-RESOURCE_LOADER=org.beetl.core.resource.ClasspathResourceLoader
+RESOURCE_LOADER=org.beetl.core.impl.resource.ClasspathResourceLoader
 #资源配置,resource后的属性只限于特定ResourceLoader
 #classpath 根路径
-RESOURCE.root= /
+RESOURCE.root=/
 #是否检测文件变化
-RESOURCE.autouCheck= true
+RESOURCE.autouCheck=true
 ```
 
 第1行指定了类加载器
diff --git a/src/main/java/org/beetl/core/BeetlKit.java b/src/main/java/org/beetl/core/BeetlKit.java
index 5932b1e..342a954 100644
--- a/src/main/java/org/beetl/core/BeetlKit.java
+++ b/src/main/java/org/beetl/core/BeetlKit.java
@@ -9,7 +9,7 @@ import org.beetl.core.config.BeetlConfig;
 import org.beetl.core.exception.BeetlException;
 import org.beetl.core.exception.ErrorInfo;
 import org.beetl.android.util.Log;
-import org.beetl.core.resource.StringTemplateResourceLoader;
+import org.beetl.core.impl.resource.StringTemplateResourceLoader;
 
 /**
  * 一个综合展示Beetl功能代码
diff --git a/src/main/java/org/beetl/core/Configuration.java b/src/main/java/org/beetl/core/Configuration.java
index f9bd1ac..213467d 100644
--- a/src/main/java/org/beetl/core/Configuration.java
+++ b/src/main/java/org/beetl/core/Configuration.java
@@ -118,7 +118,7 @@ public class Configuration {
     /** {@code String engine = "org.beetl.core.DefaultTemplateEngine";} */
     String engine = "org.beetl.core.FastRuntimeEngine";
     String nativeSecurity = "org.beetl.core.impl.security.DefaultNativeSecurityManager";
-    String resourceLoader = "org.beetl.core.resource.ClasspathResourceLoader";
+    String resourceLoader = "org.beetl.core.impl.resource.ClasspathResourceLoader";
 
     // 扩展资源
     Map fnMap = new HashMap<>();
diff --git a/src/main/java/org/beetl/core/ConsoleErrorHandler.java b/src/main/java/org/beetl/core/ConsoleErrorHandler.java
index 1d0f71e..aa3c447 100644
--- a/src/main/java/org/beetl/core/ConsoleErrorHandler.java
+++ b/src/main/java/org/beetl/core/ConsoleErrorHandler.java
@@ -32,9 +32,9 @@ import java.io.Writer;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
-import org.beetl.core.config.BeetlConfig;
 import org.beetl.core.exception.BeetlException;
 import org.beetl.core.exception.ErrorInfo;
+import org.beetl.core.runtime.IResourceLoader;
 
 /**
  * 向控制台输出错误,并不抛出异常
@@ -80,7 +80,7 @@ public class ConsoleErrorHandler implements ErrorHandler {
             println(writer, ex.getMessage());
         }
 
-        ResourceLoader resLoader = ex.gt.getResourceLoader();
+        IResourceLoader resLoader = ex.gt.getResourceLoader();
         //潜在问题,此时可能得到是一个新的模板(开发模式下),不过可能性很小,忽略!
 
         String content = null;
diff --git a/src/main/java/org/beetl/core/GroupTemplate.java b/src/main/java/org/beetl/core/GroupTemplate.java
index 1db5403..a5cc327 100644
--- a/src/main/java/org/beetl/core/GroupTemplate.java
+++ b/src/main/java/org/beetl/core/GroupTemplate.java
@@ -54,8 +54,9 @@ import org.beetl.core.misc.BeetlUtil;
 import org.beetl.core.misc.ClassSearch;
 import org.beetl.core.misc.PrimitiveArrayUtil;
 import org.beetl.core.om.AABuilder;
-import org.beetl.core.resource.ClasspathResourceLoader;
+import org.beetl.core.impl.resource.ClasspathResourceLoader;
 import org.beetl.core.runtime.INativeSecurityManager;
+import org.beetl.core.runtime.IResourceLoader;
 import org.beetl.core.statement.ErrorGrammarProgram;
 import org.beetl.core.statement.Program;
 import org.beetl.core.tag.TagFactory;
@@ -75,7 +76,7 @@ public class GroupTemplate {
             : GroupTemplate.class.getClassLoader();
 
     AABuilder attributeAccessFactory = new AABuilder();
-    ResourceLoader resourceLoader = null;
+    IResourceLoader resourceLoader = null;
     Configuration conf = null;
     TemplateEngine engine = null;
     IBeetlCache programCache = BeetlRuntime.getCache();
@@ -144,7 +145,7 @@ public class GroupTemplate {
      * @param conf   模板引擎配置
      */
 
-    public GroupTemplate(ResourceLoader loader, Configuration conf) {
+    public GroupTemplate(IResourceLoader loader, Configuration conf) {
         this(loader, conf, null);
     }
 
@@ -154,7 +155,7 @@ public class GroupTemplate {
 	 * @param conf
 	 * @param classLoader  默认是 Thread.currentThread().getContextClassLoader() 或者GroupTemplate的加载类
 	 */
-    public GroupTemplate(ResourceLoader loader, Configuration conf, ClassLoader classLoader) {
+    public GroupTemplate(IResourceLoader loader, Configuration conf, ClassLoader classLoader) {
         try {
             this.resourceLoader = loader;
             this.classLoader = classLoader == null ? this.classLoader : classLoader;
@@ -169,7 +170,7 @@ public class GroupTemplate {
 
     protected void initResourceLoader() {
         if (this.resourceLoader == null) {
-            this.resourceLoader = (ResourceLoader) ObjectUtil.instance(conf.resourceLoader, classLoader);
+            this.resourceLoader = (IResourceLoader) ObjectUtil.instance(conf.resourceLoader, classLoader);
         }
         resourceLoader.init(this);
     }
@@ -297,7 +298,7 @@ public class GroupTemplate {
     /**
      * 获得脚本
      */
-    public Script getScript(Object key, ResourceLoader loader) {
+    public Script getScript(Object key, IResourceLoader loader) {
         return loadScriptTemplate(key, loader);
     }
 
@@ -325,7 +326,7 @@ public class GroupTemplate {
     /**
      * 执行某个脚本,参数是paras,返回的是顶级变量
      */
-    public Map runScript(Object key, Map paras, Writer w, ResourceLoader loader)
+    public Map runScript(Object key, Map paras, Writer w, IResourceLoader loader)
             throws BeetlException {
         Script t = loadScriptTemplate(key, loader);
         t.fastBinding(paras);
@@ -341,7 +342,7 @@ public class GroupTemplate {
     }
 
 
-    public BeetlException validateTemplate(Object key, ResourceLoader loader) {
+    public BeetlException validateTemplate(Object key, IResourceLoader loader) {
         Template t = getTemplate(key, loader);
         return t.validate();
     }
@@ -354,7 +355,7 @@ public class GroupTemplate {
     }
 
 
-    public BeetlException validateScript(Object key, ResourceLoader loader) {
+    public BeetlException validateScript(Object key, IResourceLoader loader) {
         return loadScriptTemplate(key, loader).validate();
     }
 
@@ -386,7 +387,7 @@ public class GroupTemplate {
         return result;
     }
 
-    private Script loadScriptTemplate(Object key, ResourceLoader loader) {
+    private Script loadScriptTemplate(Object key, IResourceLoader loader) {
         Program program = (Program) this.programCache.get(key, k -> this.loadScript(loader.getResource(key)));
 
         if (resourceLoader.isModified(program.res)) {
@@ -400,7 +401,7 @@ public class GroupTemplate {
     /**
      * 使用额外的资源加载器加载模板
      */
-    public Template getTemplate(Object key, ResourceLoader loader) {
+    public Template getTemplate(Object key, IResourceLoader loader) {
         return this.getTemplateByLoader(key, loader, null);
     }
 
@@ -408,7 +409,7 @@ public class GroupTemplate {
     /**
      * 获取模板key的标有ajaxId的模板片段。
      */
-    public Template getAjaxTemplate(Object key, String ajaxId, ResourceLoader loader) {
+    public Template getAjaxTemplate(Object key, String ajaxId, IResourceLoader loader) {
         Template template = this.getTemplateByLoader(key, loader, null);
         template.ajaxId = ajaxId;
         return template;
@@ -418,7 +419,7 @@ public class GroupTemplate {
     /**
      * 得到模板,并指明父模板
      */
-    public Template getTemplate(Object key, String parent, ResourceLoader loader) {
+    public Template getTemplate(Object key, String parent, IResourceLoader loader) {
         Template template = this.getTemplate(key, loader);
         template.isRoot = false;
         return template;
@@ -460,7 +461,7 @@ public class GroupTemplate {
         return new TemplateProxy(t);
     }
 
-    private Template getTemplateByLoader(Object key, ResourceLoader loader, ContextBuffer buffers) {
+    private Template getTemplateByLoader(Object key, IResourceLoader loader, ContextBuffer buffers) {
         Program program = (Program) this.programCache.get(key, k -> this.loadTemplate(loader.getResource(key)));
 
         if (resourceLoader.isModified(program.res)) {
@@ -546,11 +547,11 @@ public class GroupTemplate {
 
     }
 
-    public ResourceLoader getResourceLoader() {
+    public IResourceLoader getResourceLoader() {
         return resourceLoader;
     }
 
-    public void setResourceLoader(ResourceLoader resourceLoader) {
+    public void setResourceLoader(IResourceLoader resourceLoader) {
         this.resourceLoader = resourceLoader;
     }
 
diff --git a/src/main/java/org/beetl/core/Resource.java b/src/main/java/org/beetl/core/Resource.java
index fef8a09..f30a5c1 100644
--- a/src/main/java/org/beetl/core/Resource.java
+++ b/src/main/java/org/beetl/core/Resource.java
@@ -27,6 +27,8 @@
  */
 package org.beetl.core;
 
+import org.beetl.core.runtime.IResourceLoader;
+
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.Reader;
@@ -38,10 +40,10 @@ import java.io.Reader;
  */
 public abstract class Resource {
 
-    protected ResourceLoader resourceLoader = null;
+    protected IResourceLoader resourceLoader = null;
     protected T id = null;
 
-    public Resource(T id, ResourceLoader loader) {
+    public Resource(T id, IResourceLoader loader) {
         this.id = id;
         this.resourceLoader = loader;
     }
@@ -59,11 +61,11 @@ public abstract class Resource {
     /**
      * 得到Resource对应的ResourceLoader
      */
-    public ResourceLoader getResourceLoader() {
+    public IResourceLoader getResourceLoader() {
         return this.resourceLoader;
     }
 
-    public void setResourceLoader(ResourceLoader resourceLoader) {
+    public void setResourceLoader(IResourceLoader resourceLoader) {
         this.resourceLoader = resourceLoader;
     }
 
diff --git a/src/main/java/org/beetl/core/resource/AllowAllMatcher.java b/src/main/java/org/beetl/core/impl/matcher/AllowAllMatcher.java
similarity index 93%
rename from src/main/java/org/beetl/core/resource/AllowAllMatcher.java
rename to src/main/java/org/beetl/core/impl/matcher/AllowAllMatcher.java
index 93dbba9..85e9dd5 100644
--- a/src/main/java/org/beetl/core/resource/AllowAllMatcher.java
+++ b/src/main/java/org/beetl/core/impl/matcher/AllowAllMatcher.java
@@ -25,14 +25,16 @@
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-package org.beetl.core.resource;
+package org.beetl.core.impl.matcher;
+
+import org.beetl.core.runtime.IMatcher;
 
 /**
  * 匹配一切的匹配器,始终返回true  ,通常用于默认的匹配,放在最后
  *
  * @author 李飞 (lifei@wellbole.com)
  */
-public class AllowAllMatcher implements Matcher {
+public class AllowAllMatcher implements IMatcher {
     @Override
     public String match(String key) {
         return key;
diff --git a/src/main/java/org/beetl/core/resource/StartsWithMatcher.java b/src/main/java/org/beetl/core/impl/matcher/StartsWithMatcher.java
similarity index 96%
rename from src/main/java/org/beetl/core/resource/StartsWithMatcher.java
rename to src/main/java/org/beetl/core/impl/matcher/StartsWithMatcher.java
index 51e1b02..e7388db 100644
--- a/src/main/java/org/beetl/core/resource/StartsWithMatcher.java
+++ b/src/main/java/org/beetl/core/impl/matcher/StartsWithMatcher.java
@@ -25,16 +25,17 @@
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-package org.beetl.core.resource;
+package org.beetl.core.impl.matcher;
 
 import org.beetl.android.util.Log;
+import org.beetl.core.runtime.IMatcher;
 
 /**
  * 检查key以给定的字符串开头的匹配器
  *
  * @author 李飞 (lifei@wellbole.com)
  */
-public class StartsWithMatcher implements Matcher {
+public class StartsWithMatcher implements IMatcher {
 
     /** Log TAG */
     private static final String TAG = "org.beetl.core.lab.StartsWithMatcher";
diff --git a/src/main/java/org/beetl/core/resource/ClasspathResource.java b/src/main/java/org/beetl/core/impl/resource/ClasspathResource.java
similarity index 92%
rename from src/main/java/org/beetl/core/resource/ClasspathResource.java
rename to src/main/java/org/beetl/core/impl/resource/ClasspathResource.java
index f243b1e..c790566 100644
--- a/src/main/java/org/beetl/core/resource/ClasspathResource.java
+++ b/src/main/java/org/beetl/core/impl/resource/ClasspathResource.java
@@ -25,7 +25,7 @@
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-package org.beetl.core.resource;
+package org.beetl.core.impl.resource;
 
 import java.io.BufferedReader;
 import java.io.File;
@@ -37,19 +37,25 @@ import java.io.UnsupportedEncodingException;
 import java.net.URL;
 
 import org.beetl.core.Resource;
-import org.beetl.core.ResourceLoader;
+import org.beetl.core.runtime.IResourceLoader;
 import org.beetl.core.exception.BeetlException;
 
 /**
  * @author xiandafu
  */
 public class ClasspathResource extends Resource {
-    String path = null;
 
+    String path = null;
     File file = null;
     long lastModified = 0;
 
-    public ClasspathResource(String key, String path, ResourceLoader resourceLoader) {
+    /**
+     * 构造方法
+     * @param key
+     * @param path
+     * @param resourceLoader
+     */
+    public ClasspathResource(String key, String path, IResourceLoader resourceLoader) {
         super(key, resourceLoader);
         this.path = path;
     }
diff --git a/src/main/java/org/beetl/core/resource/ClasspathResourceLoader.java b/src/main/java/org/beetl/core/impl/resource/ClasspathResourceLoader.java
similarity index 95%
rename from src/main/java/org/beetl/core/resource/ClasspathResourceLoader.java
rename to src/main/java/org/beetl/core/impl/resource/ClasspathResourceLoader.java
index 6abec3a..464cd0f 100644
--- a/src/main/java/org/beetl/core/resource/ClasspathResourceLoader.java
+++ b/src/main/java/org/beetl/core/impl/resource/ClasspathResourceLoader.java
@@ -25,16 +25,14 @@
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-package org.beetl.core.resource;
+package org.beetl.core.impl.resource;
 
-import java.io.File;
 import java.net.URL;
 import java.util.Map;
 
 import org.beetl.core.GroupTemplate;
 import org.beetl.core.Resource;
-import org.beetl.core.ResourceLoader;
-import org.beetl.core.fun.FileFunctionWrapper;
+import org.beetl.core.runtime.IResourceLoader;
 import org.beetl.core.misc.BeetlUtil;
 
 /**
@@ -45,7 +43,7 @@ import org.beetl.core.misc.BeetlUtil;
  *
  * @author xiandafu
  */
-public class ClasspathResourceLoader implements ResourceLoader {
+public class ClasspathResourceLoader implements IResourceLoader {
     private String root = null;
     boolean autoCheck = false;
     protected String charset = "UTF-8";
@@ -114,7 +112,7 @@ public class ClasspathResourceLoader implements ResourceLoader {
     /*
      * (non-Javadoc)
      *
-     * @see org.beetl.core.ResourceLoader#getResource(java.lang.String)
+     * @see org.beetl.core.runtime.ResourceLoader#getResource(java.lang.String)
      */
     @Override
     public Resource getResource(String key) {
@@ -124,7 +122,7 @@ public class ClasspathResourceLoader implements ResourceLoader {
     /*
      * (non-Javadoc)
      *
-     * @see org.beetl.core.ResourceLoader#close()
+     * @see org.beetl.core.runtime.ResourceLoader#close()
      */
     @Override
     public void close() {
diff --git a/src/main/java/org/beetl/core/resource/CompositeResourceLoader.java b/src/main/java/org/beetl/core/impl/resource/CompositeResourceLoader.java
similarity index 84%
rename from src/main/java/org/beetl/core/resource/CompositeResourceLoader.java
rename to src/main/java/org/beetl/core/impl/resource/CompositeResourceLoader.java
index 8ac94e0..b368dc5 100644
--- a/src/main/java/org/beetl/core/resource/CompositeResourceLoader.java
+++ b/src/main/java/org/beetl/core/impl/resource/CompositeResourceLoader.java
@@ -25,7 +25,7 @@
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-package org.beetl.core.resource;
+package org.beetl.core.impl.resource;
 
 import java.io.Reader;
 import java.util.ArrayList;
@@ -36,25 +36,26 @@ import java.util.Map;
 
 import org.beetl.core.GroupTemplate;
 import org.beetl.core.Resource;
-import org.beetl.core.ResourceLoader;
+import org.beetl.core.runtime.IResourceLoader;
 import org.beetl.core.exception.BeetlException;
+import org.beetl.core.runtime.IMatcher;
 
 /**
  * 复合加载器,依据对应的匹配器调用响应的加载器
  *
  * @author 李飞 (lifei@wellbole.com
  **/
-public class CompositeResourceLoader implements ResourceLoader {
+public class CompositeResourceLoader implements IResourceLoader {
 
     /**
      * 匹配器列表
      */
-    private List matchers = new ArrayList();
+    private List matchers = new ArrayList();
 
     /**
      * 匹配器-加载器映射表
      */
-    private Map matcherResourceLoaderMap = new HashMap();
+    private Map matcherResourceLoaderMap = new HashMap();
 
     /**
      * 是否自动检查文件是否变动
@@ -67,7 +68,7 @@ public class CompositeResourceLoader implements ResourceLoader {
      * @param matcher        匹配器
      * @param resourceLoader 匹配时对应的资源加载器
      */
-    public void addResourceLoader(Matcher matcher, ResourceLoader resourceLoader) {
+    public void addResourceLoader(IMatcher matcher, IResourceLoader resourceLoader) {
         //检查是否存在该匹配器
         if (this.matcherResourceLoaderMap.containsKey(matcher)) {
             //已经添加了。
@@ -80,14 +81,14 @@ public class CompositeResourceLoader implements ResourceLoader {
     /**
      * 一次性设置资源加载器,方便配置使用
      */
-    public void setResourceLoaderMap(Map map) {
+    public void setResourceLoaderMap(Map map) {
         this.matcherResourceLoaderMap = map;
     }
 
     @Override
     public void close() {
-        Iterator it = matcherResourceLoaderMap.values().iterator();
-        ResourceLoader rl = null;
+        Iterator it = matcherResourceLoaderMap.values().iterator();
+        IResourceLoader rl = null;
         while (it.hasNext()) {
             rl = it.next();
             rl.close();
@@ -115,7 +116,7 @@ public class CompositeResourceLoader implements ResourceLoader {
     @Override
     public void init(GroupTemplate gt) {
         //逐个初始化
-        for (ResourceLoader rl : this.matcherResourceLoaderMap.values()) {
+        for (IResourceLoader rl : this.matcherResourceLoaderMap.values()) {
             rl.init(gt);
         }
         Map resourceMap = gt.getConf().getResourceMap();
@@ -131,7 +132,7 @@ public class CompositeResourceLoader implements ResourceLoader {
      * @return 匹配到了返回一个加载器新key实体。否则报异常(说明代码写的有问题)
      */
     private ResourceLoaderKeyEntry match(String key) {
-        for (Matcher matcher : this.matchers) {
+        for (IMatcher matcher : this.matchers) {
             //匹配了
             String newKey = matcher.match(key);
             if (newKey != null) {
@@ -147,9 +148,9 @@ public class CompositeResourceLoader implements ResourceLoader {
      */
     private final static class ResourceLoaderKeyEntry {
         private final String newKey;
-        private final ResourceLoader resourceLoader;
+        private final IResourceLoader resourceLoader;
 
-        public ResourceLoaderKeyEntry(String newKey, ResourceLoader resourceLoader) {
+        public ResourceLoaderKeyEntry(String newKey, IResourceLoader resourceLoader) {
             this.newKey = newKey;
             this.resourceLoader = resourceLoader;
         }
@@ -158,14 +159,14 @@ public class CompositeResourceLoader implements ResourceLoader {
             return newKey;
         }
 
-        public final ResourceLoader getResourceLoader() {
+        public final IResourceLoader getResourceLoader() {
             return resourceLoader;
         }
     }
 
     private final static class UnReachableResource extends Resource {
 
-        UnReachableResource(String key, ResourceLoader loader) {
+        UnReachableResource(String key, IResourceLoader loader) {
             super(key, loader);
         }
 
diff --git a/src/main/java/org/beetl/core/resource/FileResource.java b/src/main/java/org/beetl/core/impl/resource/FileResource.java
similarity index 89%
rename from src/main/java/org/beetl/core/resource/FileResource.java
rename to src/main/java/org/beetl/core/impl/resource/FileResource.java
index 8929d94..ea6f997 100644
--- a/src/main/java/org/beetl/core/resource/FileResource.java
+++ b/src/main/java/org/beetl/core/impl/resource/FileResource.java
@@ -1,4 +1,4 @@
-package org.beetl.core.resource;
+package org.beetl.core.impl.resource;
 
 import java.io.BufferedReader;
 import java.io.File;
@@ -9,7 +9,7 @@ import java.io.Reader;
 import java.io.UnsupportedEncodingException;
 
 import org.beetl.core.Resource;
-import org.beetl.core.ResourceLoader;
+import org.beetl.core.runtime.IResourceLoader;
 import org.beetl.core.exception.BeetlException;
 
 public class FileResource extends Resource {
@@ -17,7 +17,7 @@ public class FileResource extends Resource {
     File file = null;
     long lastModified = 0;
 
-    public FileResource(File file, String id, ResourceLoader loader) {
+    public FileResource(File file, String id, IResourceLoader loader) {
         super(id, loader);
         this.file = file;
         lastModified = file.lastModified();
diff --git a/src/main/java/org/beetl/core/resource/FileResourceLoader.java b/src/main/java/org/beetl/core/impl/resource/FileResourceLoader.java
similarity index 95%
rename from src/main/java/org/beetl/core/resource/FileResourceLoader.java
rename to src/main/java/org/beetl/core/impl/resource/FileResourceLoader.java
index 32723a5..adbe749 100644
--- a/src/main/java/org/beetl/core/resource/FileResourceLoader.java
+++ b/src/main/java/org/beetl/core/impl/resource/FileResourceLoader.java
@@ -25,15 +25,14 @@
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-package org.beetl.core.resource;
+package org.beetl.core.impl.resource;
 
 import java.io.File;
 import java.util.Map;
 
 import org.beetl.core.GroupTemplate;
 import org.beetl.core.Resource;
-import org.beetl.core.ResourceLoader;
-import org.beetl.core.fun.FileFunctionWrapper;
+import org.beetl.core.runtime.IResourceLoader;
 import org.beetl.core.misc.BeetlUtil;
 
 /**
@@ -41,7 +40,7 @@ import org.beetl.core.misc.BeetlUtil;
  *
  * @author xiandafu
  */
-public class FileResourceLoader implements ResourceLoader {
+public class FileResourceLoader implements IResourceLoader {
 
     String root = null;
     String charset = "UTF-8";
diff --git a/src/main/java/org/beetl/core/resource/MapResourceLoader.java b/src/main/java/org/beetl/core/impl/resource/MapResourceLoader.java
similarity index 84%
rename from src/main/java/org/beetl/core/resource/MapResourceLoader.java
rename to src/main/java/org/beetl/core/impl/resource/MapResourceLoader.java
index d62a067..fb13bcf 100644
--- a/src/main/java/org/beetl/core/resource/MapResourceLoader.java
+++ b/src/main/java/org/beetl/core/impl/resource/MapResourceLoader.java
@@ -1,4 +1,4 @@
-package org.beetl.core.resource;
+package org.beetl.core.impl.resource;
 
 import java.io.Reader;
 import java.io.StringReader;
@@ -6,7 +6,7 @@ import java.util.HashMap;
 
 import org.beetl.core.GroupTemplate;
 import org.beetl.core.Resource;
-import org.beetl.core.ResourceLoader;
+import org.beetl.core.runtime.IResourceLoader;
 import org.beetl.core.exception.BeetlException;
 
 /**
@@ -14,25 +14,30 @@ import org.beetl.core.exception.BeetlException;
  *
  * @author wendal(wendal1985 @ gmail.com)
  */
-public class MapResourceLoader extends HashMap implements ResourceLoader {
+public class MapResourceLoader extends HashMap implements IResourceLoader {
 
     private static final long serialVersionUID = 5361058943317379270L;
 
     protected boolean autoCheck;
 
+    @Override
     public boolean isModified(Resource key) {
         return !autoCheck;
     }
 
+    @Override
     public void init(GroupTemplate gt) {
     }
 
+    @Override
     public String getResourceId(Resource resource, String key) {
         return key;
     }
 
+    @Override
     public Resource getResource(final String key) {
         return new Resource(key, this) {
+            @Override
             public Reader openReader() {
                 String val = get(key);
                 if (val == null) {
@@ -41,23 +46,22 @@ public class MapResourceLoader extends HashMap implements Resour
                 return new StringReader(val);
             }
 
+            @Override
             public boolean isModified() {
                 return !autoCheck;
             }
         };
     }
 
+    @Override
     public boolean exist(String key) {
         return containsKey(key);
     }
 
+    @Override
     public void close() {
     }
 
-    public void setAutoCheck(boolean autoCheck) {
-        this.autoCheck = autoCheck;
-    }
-
     @Override
     public String getInfo() {
         return "MapResourceLoader ";
diff --git a/src/main/java/org/beetl/core/resource/StringTemplateResource.java b/src/main/java/org/beetl/core/impl/resource/StringTemplateResource.java
similarity index 91%
rename from src/main/java/org/beetl/core/resource/StringTemplateResource.java
rename to src/main/java/org/beetl/core/impl/resource/StringTemplateResource.java
index ed9d570..6c18b0d 100644
--- a/src/main/java/org/beetl/core/resource/StringTemplateResource.java
+++ b/src/main/java/org/beetl/core/impl/resource/StringTemplateResource.java
@@ -25,27 +25,25 @@
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-package org.beetl.core.resource;
+package org.beetl.core.impl.resource;
 
 import java.io.Reader;
 import java.io.StringReader;
 
 import org.beetl.core.Resource;
-import org.beetl.core.ResourceLoader;
+import org.beetl.core.runtime.IResourceLoader;
 
 /**
  * 字符模板资源
  */
 public class StringTemplateResource extends Resource {
 
-    public StringTemplateResource(String template, ResourceLoader resourceLoader) {
+    public StringTemplateResource(String template, IResourceLoader resourceLoader) {
         super(template, resourceLoader);
-
     }
 
     @Override
     public Reader openReader() {
-
         return new StringReader(this.id);
     }
 
diff --git a/src/main/java/org/beetl/core/resource/StringTemplateResourceLoader.java b/src/main/java/org/beetl/core/impl/resource/StringTemplateResourceLoader.java
similarity index 93%
rename from src/main/java/org/beetl/core/resource/StringTemplateResourceLoader.java
rename to src/main/java/org/beetl/core/impl/resource/StringTemplateResourceLoader.java
index e850533..187bba5 100644
--- a/src/main/java/org/beetl/core/resource/StringTemplateResourceLoader.java
+++ b/src/main/java/org/beetl/core/impl/resource/StringTemplateResourceLoader.java
@@ -25,18 +25,18 @@
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-package org.beetl.core.resource;
+package org.beetl.core.impl.resource;
 
 import org.beetl.core.GroupTemplate;
 import org.beetl.core.Resource;
-import org.beetl.core.ResourceLoader;
+import org.beetl.core.runtime.IResourceLoader;
 
 /**
  * 字符串模板加载器
  *
  * @author xiandafu
  */
-public class StringTemplateResourceLoader implements ResourceLoader {
+public class StringTemplateResourceLoader implements IResourceLoader {
 
     public StringTemplateResourceLoader() {
 
diff --git a/src/main/java/org/beetl/core/resource/WebAppResourceLoader.java b/src/main/java/org/beetl/core/impl/resource/WebAppResourceLoader.java
similarity index 98%
rename from src/main/java/org/beetl/core/resource/WebAppResourceLoader.java
rename to src/main/java/org/beetl/core/impl/resource/WebAppResourceLoader.java
index 4af5355..28ae68a 100644
--- a/src/main/java/org/beetl/core/resource/WebAppResourceLoader.java
+++ b/src/main/java/org/beetl/core/impl/resource/WebAppResourceLoader.java
@@ -25,7 +25,7 @@
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-package org.beetl.core.resource;
+package org.beetl.core.impl.resource;
 
 import java.io.File;
 
diff --git a/src/main/java/org/beetl/core/resource/Matcher.java b/src/main/java/org/beetl/core/runtime/IMatcher.java
similarity index 96%
rename from src/main/java/org/beetl/core/resource/Matcher.java
rename to src/main/java/org/beetl/core/runtime/IMatcher.java
index 49be405..2802d10 100644
--- a/src/main/java/org/beetl/core/resource/Matcher.java
+++ b/src/main/java/org/beetl/core/runtime/IMatcher.java
@@ -25,14 +25,14 @@
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-package org.beetl.core.resource;
+package org.beetl.core.runtime;
 
 /**
  * 匹配器接口,实现类必须实现equals和hashCode接口
  *
  * @author 李飞 (lifei@wellbole.com)
  */
-public interface Matcher {
+public interface IMatcher {
     /**
      * 检查key是否匹配(满足)某种规则
      *
diff --git a/src/main/java/org/beetl/core/ResourceLoader.java b/src/main/java/org/beetl/core/runtime/IResourceLoader.java
similarity index 76%
rename from src/main/java/org/beetl/core/ResourceLoader.java
rename to src/main/java/org/beetl/core/runtime/IResourceLoader.java
index f707682..80bf225 100644
--- a/src/main/java/org/beetl/core/ResourceLoader.java
+++ b/src/main/java/org/beetl/core/runtime/IResourceLoader.java
@@ -25,7 +25,10 @@
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-package org.beetl.core;
+package org.beetl.core.runtime;
+
+import org.beetl.core.GroupTemplate;
+import org.beetl.core.Resource;
 
 import java.io.Closeable;
 
@@ -35,24 +38,24 @@ import java.io.Closeable;
  *
  * @author xiandafu
  *
- * @see org.beetl.core.resource.ClasspathResource
- * @see org.beetl.core.resource.ClasspathResourceLoader 类路径资源加载器
+ * @see org.beetl.core.impl.resource.ClasspathResource
+ * @see org.beetl.core.impl.resource.ClasspathResourceLoader 类路径资源加载器
  *
- * @see org.beetl.core.resource.StringTemplateResource
- * @see org.beetl.core.resource.StringTemplateResourceLoader 字符串模板资源加载器
+ * @see org.beetl.core.impl.resource.StringTemplateResource
+ * @see org.beetl.core.impl.resource.StringTemplateResourceLoader 字符串模板资源加载器
  *
- * @see org.beetl.core.resource.FileResource
- * @see org.beetl.core.resource.FileResourceLoader 文件资源加载器
- * @see org.beetl.core.resource.WebAppResourceLoader web应用资源加载器
+ * @see org.beetl.core.impl.resource.FileResource
+ * @see org.beetl.core.impl.resource.FileResourceLoader 文件资源加载器
+ * @see org.beetl.core.impl.resource.WebAppResourceLoader web应用资源加载器
  *
- * @see org.beetl.core.resource.Matcher
- * @see org.beetl.core.resource.AllowAllMatcher
- * @see org.beetl.core.resource.StartsWithMatcher
- * @see org.beetl.core.resource.CompositeResourceLoader 混合形式的资源加载器
+ * @see org.beetl.core.runtime.IMatcher
+ * @see org.beetl.core.impl.matcher.AllowAllMatcher
+ * @see org.beetl.core.impl.matcher.StartsWithMatcher
+ * @see org.beetl.core.impl.resource.CompositeResourceLoader 混合形式的资源加载器
  *
- * @see org.beetl.core.resource.MapResourceLoader 映射形式的资源加载器
+ * @see org.beetl.core.impl.resource.MapResourceLoader 映射形式的资源加载器
  */
-public interface ResourceLoader extends Closeable {
+public interface IResourceLoader extends Closeable {
 
     /**
      * 根据key获取Resource
diff --git a/src/main/java/org/beetl/ext/jodd/BeetlActionResult.java b/src/main/java/org/beetl/ext/jodd/BeetlActionResult.java
index 60c4c5b..3b572a7 100644
--- a/src/main/java/org/beetl/ext/jodd/BeetlActionResult.java
+++ b/src/main/java/org/beetl/ext/jodd/BeetlActionResult.java
@@ -7,7 +7,7 @@ import jodd.madvoc.result.ActionResult;
 
 import org.beetl.core.Configuration;
 import org.beetl.core.GroupTemplate;
-import org.beetl.core.resource.WebAppResourceLoader;
+import org.beetl.core.impl.resource.WebAppResourceLoader;
 import org.beetl.ext.web.WebRender;
 
 public class BeetlActionResult implements ActionResult {
diff --git a/src/main/java/org/beetl/ext/jsp/IncludeJSPTag.java b/src/main/java/org/beetl/ext/jsp/IncludeJSPTag.java
index 06578f3..d8e7da8 100644
--- a/src/main/java/org/beetl/ext/jsp/IncludeJSPTag.java
+++ b/src/main/java/org/beetl/ext/jsp/IncludeJSPTag.java
@@ -9,9 +9,9 @@ import java.util.Map.Entry;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.beetl.core.ResourceLoader;
+import org.beetl.core.runtime.IResourceLoader;
 import org.beetl.core.misc.BeetlUtil;
-import org.beetl.core.resource.FileResourceLoader;
+import org.beetl.core.impl.resource.FileResourceLoader;
 import org.beetl.core.tag.Tag;
 import org.beetl.ext.web.WebVariable;
 
@@ -77,7 +77,7 @@ public class IncludeJSPTag extends Tag {
     }
 
     protected String getPrefix(File root) {
-        ResourceLoader rs = ctx.gt.getResourceLoader();
+        IResourceLoader rs = ctx.gt.getResourceLoader();
         if(!(rs instanceof FileResourceLoader)) {
             return "";
         }
diff --git a/src/main/java/org/beetl/ext/nutz/BeetlViewMaker.java b/src/main/java/org/beetl/ext/nutz/BeetlViewMaker.java
index bf64d55..94eaafb 100644
--- a/src/main/java/org/beetl/ext/nutz/BeetlViewMaker.java
+++ b/src/main/java/org/beetl/ext/nutz/BeetlViewMaker.java
@@ -7,7 +7,7 @@ import java.util.Properties;
 import org.beetl.core.Configuration;
 import org.beetl.core.GroupTemplate;
 import org.beetl.core.misc.BeetlUtil;
-import org.beetl.core.resource.WebAppResourceLoader;
+import org.beetl.core.impl.resource.WebAppResourceLoader;
 import org.beetl.ext.web.WebRender;
 import org.nutz.ioc.Ioc;
 import org.nutz.lang.Streams;
@@ -28,7 +28,7 @@ import org.nutz.mvc.ViewMaker;
  * 

* 本实现的默认配置

* - * RESOURCE_LOADER=org.beetl.core.resource.WebAppResourceLoader

+ * RESOURCE_LOADER=org.beetl.core.impl.resource.WebAppResourceLoader

* DIRECT_BYTE_OUTPUT=true

* ERROR_HANDLER=org.beetl.ext.nutz.LogErrorHandler

*

diff --git a/src/main/java/org/beetl/ext/servlet/ServletGroupTemplate.java b/src/main/java/org/beetl/ext/servlet/ServletGroupTemplate.java index 85970f4..c82b9db 100644 --- a/src/main/java/org/beetl/ext/servlet/ServletGroupTemplate.java +++ b/src/main/java/org/beetl/ext/servlet/ServletGroupTemplate.java @@ -5,7 +5,7 @@ import javax.servlet.http.HttpServletResponse; import org.beetl.core.Configuration; import org.beetl.core.GroupTemplate; -import org.beetl.core.resource.WebAppResourceLoader; +import org.beetl.core.impl.resource.WebAppResourceLoader; import org.beetl.ext.web.WebRender; /** diff --git a/src/main/java/org/beetl/ext/simulate/BaseSimulate.java b/src/main/java/org/beetl/ext/simulate/BaseSimulate.java index 80416af..c7f551e 100644 --- a/src/main/java/org/beetl/ext/simulate/BaseSimulate.java +++ b/src/main/java/org/beetl/ext/simulate/BaseSimulate.java @@ -5,7 +5,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -16,7 +15,7 @@ import javax.servlet.http.HttpSession; import org.beetl.core.Context; import org.beetl.core.Function; import org.beetl.core.GroupTemplate; -import org.beetl.core.ResourceLoader; +import org.beetl.core.runtime.IResourceLoader; import org.beetl.core.misc.ClassSearch; import org.beetl.ext.web.ParameterWrapper; import org.beetl.ext.web.SessionWrapper; @@ -107,7 +106,7 @@ public class BaseSimulate { return getRealPath(gt.getResourceLoader(), path, method); } - private RestPath getRealPath(ResourceLoader loader, String path, String method) { + private RestPath getRealPath(IResourceLoader loader, String path, String method) { method = method.toLowerCase(); path = this.base + "/" + path; RestPath restPath = new RestPath(); diff --git a/src/main/java/org/beetl/ext/spring/BeetlGroupUtilConfiguration.java b/src/main/java/org/beetl/ext/spring/BeetlGroupUtilConfiguration.java index 8552e67..a4065f7 100644 --- a/src/main/java/org/beetl/ext/spring/BeetlGroupUtilConfiguration.java +++ b/src/main/java/org/beetl/ext/spring/BeetlGroupUtilConfiguration.java @@ -29,7 +29,6 @@ package org.beetl.ext.spring; import java.io.IOException; import java.io.InputStream; -import java.util.Enumeration; import java.util.Map; import java.util.Map.Entry; import java.util.Properties; @@ -39,8 +38,8 @@ import javax.servlet.ServletContext; import org.beetl.core.Configuration; import org.beetl.core.ErrorHandler; import org.beetl.core.GroupTemplate; -import org.beetl.core.ResourceLoader; -import org.beetl.core.resource.WebAppResourceLoader; +import org.beetl.core.runtime.IResourceLoader; +import org.beetl.core.impl.resource.WebAppResourceLoader; import org.springframework.core.io.Resource; import org.springframework.web.context.ServletContextAware; @@ -74,7 +73,7 @@ public class BeetlGroupUtilConfiguration extends AbstractGroupTemplateConfig imp /** * Beetl资源加载器,如果未指定,会自动依据ApplicationContext和配置文件识别 */ - protected ResourceLoader resourceLoader = null; + protected IResourceLoader resourceLoader = null; /** * 异常处理器 */ @@ -114,7 +113,7 @@ public class BeetlGroupUtilConfiguration extends AbstractGroupTemplateConfig imp /** * Beetl资源加载器,如果未指定,会自动依据ApplicationContext和配置文件识别 */ - public void setResourceLoader(ResourceLoader resourceLoader) { + public void setResourceLoader(IResourceLoader resourceLoader) { this.resourceLoader = resourceLoader; } diff --git a/src/main/java/org/beetl/ext/struts2/Struts2BeetlActionResult.java b/src/main/java/org/beetl/ext/struts2/Struts2BeetlActionResult.java index e32ad17..55b76f2 100644 --- a/src/main/java/org/beetl/ext/struts2/Struts2BeetlActionResult.java +++ b/src/main/java/org/beetl/ext/struts2/Struts2BeetlActionResult.java @@ -39,7 +39,7 @@ import org.apache.struts2.views.util.ResourceUtil; import org.beetl.core.Configuration; import org.beetl.core.GroupTemplate; import org.beetl.core.Template; -import org.beetl.core.resource.WebAppResourceLoader; +import org.beetl.core.impl.resource.WebAppResourceLoader; import org.beetl.ext.web.WebRender; import com.opensymphony.xwork2.ActionContext; diff --git a/src/main/java/org/beetl/ext/web/WebErrorHandler.java b/src/main/java/org/beetl/ext/web/WebErrorHandler.java index 31b3480..33991d3 100644 --- a/src/main/java/org/beetl/ext/web/WebErrorHandler.java +++ b/src/main/java/org/beetl/ext/web/WebErrorHandler.java @@ -32,7 +32,7 @@ import java.io.Writer; import org.beetl.core.ConsoleErrorHandler; import org.beetl.core.Resource; -import org.beetl.core.ResourceLoader; +import org.beetl.core.runtime.IResourceLoader; import org.beetl.core.exception.BeetlException; import org.beetl.core.exception.ErrorInfo; @@ -86,7 +86,7 @@ public class WebErrorHandler extends ConsoleErrorHandler { msg.append(e.getMessage()).append("\n"); } - ResourceLoader resLoader = e.gt.getResourceLoader(); + IResourceLoader resLoader = e.gt.getResourceLoader(); //潜在问题,此时可能得到是一个新的模板,不过可能性很小,忽略! String content = null; Resource res = e.resource; diff --git a/src/main/resources/org/beetl/core/beetl-default.properties b/src/main/resources/org/beetl/core/beetl-default.properties index 7551251..c525388 100644 --- a/src/main/resources/org/beetl/core/beetl-default.properties +++ b/src/main/resources/org/beetl/core/beetl-default.properties @@ -13,7 +13,7 @@ NATIVE_CALL = true TEMPLATE_CHARSET = UTF-8 ERROR_HANDLER = org.beetl.core.ConsoleErrorHandler NATIVE_SECUARTY_MANAGER= org.beetl.core.impl.security.DefaultNativeSecurityManager -RESOURCE_LOADER=org.beetl.core.resource.ClasspathResourceLoader +RESOURCE_LOADER=org.beetl.core.impl.resource.ClasspathResourceLoader MVC_STRICT = false SAFE_OUTPUT=false diff --git a/src/test/java/org/beetl/core/BasicTestCase.java b/src/test/java/org/beetl/core/BasicTestCase.java index 024f703..5978b37 100644 --- a/src/test/java/org/beetl/core/BasicTestCase.java +++ b/src/test/java/org/beetl/core/BasicTestCase.java @@ -3,7 +3,7 @@ package org.beetl.core; import java.io.IOException; import java.io.Reader; -import org.beetl.core.resource.ClasspathResourceLoader; +import org.beetl.core.impl.resource.ClasspathResourceLoader; import junit.framework.TestCase; diff --git a/src/test/java/org/beetl/core/function/FileFunctionTest.java b/src/test/java/org/beetl/core/function/FileFunctionTest.java index aca48a0..17a6e99 100644 --- a/src/test/java/org/beetl/core/function/FileFunctionTest.java +++ b/src/test/java/org/beetl/core/function/FileFunctionTest.java @@ -7,7 +7,7 @@ import org.beetl.core.BasicTestCase; import org.beetl.core.Configuration; import org.beetl.core.GroupTemplate; import org.beetl.core.Template; -import org.beetl.core.resource.ClasspathResourceLoader; +import org.beetl.core.impl.resource.ClasspathResourceLoader; import org.testng.AssertJUnit; import org.testng.annotations.Test; diff --git a/src/test/java/org/beetl/core/lab/Test.java b/src/test/java/org/beetl/core/lab/Test.java index cdbe0a2..9d90d7e 100644 --- a/src/test/java/org/beetl/core/lab/Test.java +++ b/src/test/java/org/beetl/core/lab/Test.java @@ -4,7 +4,7 @@ import org.beetl.core.Configuration; import org.beetl.core.GroupTemplate; import org.beetl.core.Template; import org.beetl.core.config.BeetlConfig; -import org.beetl.core.resource.ClasspathResourceLoader; +import org.beetl.core.impl.resource.ClasspathResourceLoader; /** * @author xiandafu diff --git a/src/test/java/org/beetl/core/nativecall/NativeTest.java b/src/test/java/org/beetl/core/nativecall/NativeTest.java index 335a67f..6344b89 100644 --- a/src/test/java/org/beetl/core/nativecall/NativeTest.java +++ b/src/test/java/org/beetl/core/nativecall/NativeTest.java @@ -8,7 +8,7 @@ import org.beetl.core.GroupTemplate; import org.beetl.core.Template; import org.beetl.core.User; import org.beetl.core.nativecall.obj.Request; -import org.beetl.core.resource.StringTemplateResourceLoader; +import org.beetl.core.impl.resource.StringTemplateResourceLoader; import org.testng.AssertJUnit; import org.testng.annotations.Test; diff --git a/src/test/java/org/beetl/core/resourceloader/CompositeResourceLoaderTest.java b/src/test/java/org/beetl/core/resourceloader/CompositeResourceLoaderTest.java index f04ad24..6b8a224 100644 --- a/src/test/java/org/beetl/core/resourceloader/CompositeResourceLoaderTest.java +++ b/src/test/java/org/beetl/core/resourceloader/CompositeResourceLoaderTest.java @@ -7,10 +7,10 @@ import org.beetl.core.BasicTestCase; import org.beetl.core.Configuration; import org.beetl.core.GroupTemplate; import org.beetl.core.Template; -import org.beetl.core.resource.AllowAllMatcher; -import org.beetl.core.resource.CompositeResourceLoader; -import org.beetl.core.resource.FileResourceLoader; -import org.beetl.core.resource.StartsWithMatcher; +import org.beetl.core.impl.matcher.AllowAllMatcher; +import org.beetl.core.impl.resource.CompositeResourceLoader; +import org.beetl.core.impl.resource.FileResourceLoader; +import org.beetl.core.impl.matcher.StartsWithMatcher; import org.testng.AssertJUnit; import org.testng.annotations.Test; diff --git a/src/test/java/org/beetl/core/resourceloader/MapResourceLoader.java b/src/test/java/org/beetl/core/resourceloader/MapResourceLoader.java index ae41001..123100c 100644 --- a/src/test/java/org/beetl/core/resourceloader/MapResourceLoader.java +++ b/src/test/java/org/beetl/core/resourceloader/MapResourceLoader.java @@ -4,10 +4,10 @@ import java.util.Map; import org.beetl.core.GroupTemplate; import org.beetl.core.Resource; -import org.beetl.core.ResourceLoader; -import org.beetl.core.resource.StringTemplateResource; +import org.beetl.core.runtime.IResourceLoader; +import org.beetl.core.impl.resource.StringTemplateResource; -public class MapResourceLoader implements ResourceLoader +public class MapResourceLoader implements IResourceLoader { Map data; diff --git a/src/test/java/org/beetl/core/resourceloader/ResourceLoaderTest.java b/src/test/java/org/beetl/core/resourceloader/ResourceLoaderTest.java index b7723a5..22e93a9 100644 --- a/src/test/java/org/beetl/core/resourceloader/ResourceLoaderTest.java +++ b/src/test/java/org/beetl/core/resourceloader/ResourceLoaderTest.java @@ -5,8 +5,8 @@ import java.util.Map; import org.beetl.core.BasicTestCase; import org.beetl.core.Template; -import org.beetl.core.resource.ClasspathResourceLoader; -import org.beetl.core.resource.FileResourceLoader; +import org.beetl.core.impl.resource.ClasspathResourceLoader; +import org.beetl.core.impl.resource.FileResourceLoader; import org.testng.AssertJUnit; import org.testng.annotations.Test; diff --git a/src/test/java/org/beetl/core/tag/HtmlTagTest.java b/src/test/java/org/beetl/core/tag/HtmlTagTest.java index 8afb31f..e05fb61 100644 --- a/src/test/java/org/beetl/core/tag/HtmlTagTest.java +++ b/src/test/java/org/beetl/core/tag/HtmlTagTest.java @@ -8,7 +8,7 @@ import org.beetl.core.Configuration; import org.beetl.core.GroupTemplate; import org.beetl.core.Template; import org.beetl.core.User; -import org.beetl.core.resource.ClasspathResourceLoader; +import org.beetl.core.impl.resource.ClasspathResourceLoader; import org.testng.AssertJUnit; import org.testng.annotations.Test; diff --git a/src/test/java/org/beetl/core/text/PairDLTest.java b/src/test/java/org/beetl/core/text/PairDLTest.java index 3798b22..0a49bb9 100644 --- a/src/test/java/org/beetl/core/text/PairDLTest.java +++ b/src/test/java/org/beetl/core/text/PairDLTest.java @@ -6,7 +6,7 @@ import org.beetl.core.BasicTestCase; import org.beetl.core.Configuration; import org.beetl.core.GroupTemplate; import org.beetl.core.Template; -import org.beetl.core.resource.ClasspathResourceLoader; +import org.beetl.core.impl.resource.ClasspathResourceLoader; import org.testng.AssertJUnit; import org.testng.annotations.Test; diff --git a/src/test/java/org/beetl/core/text/SingleDLTest.java b/src/test/java/org/beetl/core/text/SingleDLTest.java index 9022b93..109e824 100644 --- a/src/test/java/org/beetl/core/text/SingleDLTest.java +++ b/src/test/java/org/beetl/core/text/SingleDLTest.java @@ -6,7 +6,7 @@ import org.beetl.core.BasicTestCase; import org.beetl.core.Configuration; import org.beetl.core.GroupTemplate; import org.beetl.core.Template; -import org.beetl.core.resource.ClasspathResourceLoader; +import org.beetl.core.impl.resource.ClasspathResourceLoader; import org.testng.AssertJUnit; import org.testng.annotations.Test; diff --git a/src/test/java/org/beetl/core/va/VirtualAttributeTest.java b/src/test/java/org/beetl/core/va/VirtualAttributeTest.java index faf9ac9..5bbae66 100644 --- a/src/test/java/org/beetl/core/va/VirtualAttributeTest.java +++ b/src/test/java/org/beetl/core/va/VirtualAttributeTest.java @@ -8,7 +8,7 @@ import org.beetl.core.Template; import org.beetl.core.User; import org.beetl.core.VirtualAttributeEval; import org.beetl.core.VirtualClassAttribute; -import org.beetl.core.resource.StringTemplateResourceLoader; +import org.beetl.core.impl.resource.StringTemplateResourceLoader; import org.testng.AssertJUnit; import org.testng.annotations.Test; diff --git a/src/test/java/org/beetl/ext/nutz/BeetlViewMakerTest.java b/src/test/java/org/beetl/ext/nutz/BeetlViewMakerTest.java index 4552c99..24d9620 100644 --- a/src/test/java/org/beetl/ext/nutz/BeetlViewMakerTest.java +++ b/src/test/java/org/beetl/ext/nutz/BeetlViewMakerTest.java @@ -16,7 +16,7 @@ import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.beetl.core.resource.MapResourceLoader; +import org.beetl.core.impl.resource.MapResourceLoader; import org.nutz.lang.util.NutMap; import org.nutz.mvc.View; -- Gitee From 22ab9d4110d0f209ce446ddeb97ff9b6c21305b2 Mon Sep 17 00:00:00 2001 From: zhaoxuyang03 Date: Sun, 14 Mar 2021 20:24:56 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E3=80=90Sprint3.3.3=E3=80=91=E3=80=90Bee?= =?UTF-8?q?tl=E3=80=91=E9=94=99=E8=AF=AF=E7=A0=81-=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/beetl/core/AntlrProgramBuilder.java | 29 ++- src/main/java/org/beetl/core/BeetlKit.java | 4 +- .../org/beetl/core/ConsoleErrorHandler.java | 11 +- .../org/beetl/core/DefaultTagFactory.java | 5 +- .../java/org/beetl/core/GroupTemplate.java | 3 +- .../java/org/beetl/core/IBeetlConstants.java | 8 + src/main/java/org/beetl/core/Script.java | 8 +- src/main/java/org/beetl/core/Template.java | 7 +- .../org/beetl/core/engine/GrammarCreator.java | 3 +- .../core/engine/OnlineTemplateEngine.java | 3 +- .../beetl/core/exception/BeetlErrorCode.java | 239 ++++++++++++++++++ .../{ErrorInfo.java => BeetlErrorInfo.java} | 98 +++---- .../beetl/core/exception/BeetlException.java | 115 +-------- .../exception/HTMLTagParserException.java | 2 +- .../core/exception/MVCStrictException.java | 2 +- .../exception/NativeNotAllowedException.java | 2 +- .../core/exception/TextParserException.java | 2 +- .../beetl/core/fun/FileFunctionWrapper.java | 3 +- .../core/fun/GeneralGetMethodInvoker.java | 7 +- .../core/fun/MutipleFunctionWrapper.java | 9 +- .../java/org/beetl/core/fun/ObjectUtil.java | 12 +- .../org/beetl/core/fun/PojoMethodInvoker.java | 13 +- .../beetl/core/fun/SingleFunctionWrapper.java | 5 +- .../core/impl/resource/ClasspathResource.java | 7 +- .../resource/CompositeResourceLoader.java | 3 +- .../core/impl/resource/FileResource.java | 3 +- .../core/impl/resource/MapResourceLoader.java | 3 +- src/main/java/org/beetl/core/misc/ALU.java | 19 +- src/main/java/org/beetl/core/om/ArrayAA.java | 3 +- .../org/beetl/core/om/AttributeAccess.java | 9 +- src/main/java/org/beetl/core/om/ListAA.java | 4 +- .../java/org/beetl/core/om/ReflectBeanAA.java | 3 +- .../beetl/core/om/asm/BeanEnhanceUtils.java | 3 +- .../core/parser/BeetlAntlrErrorStrategy.java | 32 +-- .../core/parser/SyntaxErrorListener.java | 3 +- .../beetl/core/statement/ForStatement.java | 5 +- .../core/statement/FormatExpression.java | 5 +- .../core/statement/FunctionExpression.java | 9 +- .../core/statement/GeneralForStatement.java | 3 +- .../core/statement/NativeCallExpression.java | 30 +-- .../beetl/core/statement/PlaceholderST.java | 3 +- .../beetl/core/statement/ProgramMetaData.java | 3 +- .../beetl/core/statement/SelectStatement.java | 5 +- .../core/statement/StaticTextASTNode.java | 3 +- .../core/statement/StaticTextByteASTNode.java | 3 +- .../beetl/core/statement/SwitchStatement.java | 3 +- .../beetl/core/statement/TagStatement.java | 5 +- .../statement/TagVarBindingStatement.java | 5 +- .../core/statement/TernaryExpression.java | 5 +- .../core/statement/TryCatchStatement.java | 5 +- .../java/org/beetl/core/statement/VarRef.java | 17 +- .../core/statement/VarRefAssignExpress.java | 5 +- .../core/statement/VarRefAssignStatement.java | 5 +- .../core/statement/VarVirtualAttribute.java | 3 +- .../beetl/core/statement/WhileStatement.java | 5 +- .../core/statement/optimal/VarRefOptimal.java | 11 +- .../beetl/core/text/HtmlTagStartFragment.java | 3 +- src/main/java/org/beetl/ext/fn/Flush.java | 3 +- src/main/java/org/beetl/ext/fn/Print.java | 3 +- src/main/java/org/beetl/ext/fn/Printf.java | 3 +- src/main/java/org/beetl/ext/fn/Println.java | 3 +- .../org/beetl/ext/nutz/NutJsonFunction.java | 3 +- .../org/beetl/ext/tag/cache/CacheTag.java | 3 +- .../html/IncludeResourceFragmentHtmlTag.java | 3 +- .../ext/tag/html/IncludeResourceHtmlTag.java | 3 +- .../ext/tag/html/LayoutResourceHtmlTag.java | 3 +- .../org/beetl/ext/web/WebErrorHandler.java | 9 +- .../beetl/core/om/asm/AsmBeanFactoryTest.java | 3 +- 68 files changed, 524 insertions(+), 338 deletions(-) create mode 100644 src/main/java/org/beetl/core/IBeetlConstants.java create mode 100644 src/main/java/org/beetl/core/exception/BeetlErrorCode.java rename src/main/java/org/beetl/core/exception/{ErrorInfo.java => BeetlErrorInfo.java} (44%) diff --git a/src/main/java/org/beetl/core/AntlrProgramBuilder.java b/src/main/java/org/beetl/core/AntlrProgramBuilder.java index b461dc2..b61b00e 100644 --- a/src/main/java/org/beetl/core/AntlrProgramBuilder.java +++ b/src/main/java/org/beetl/core/AntlrProgramBuilder.java @@ -43,6 +43,7 @@ import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.tree.ParseTree; import org.antlr.v4.runtime.tree.TerminalNode; import org.beetl.core.engine.GrammarCreator; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.exception.MVCStrictException; import org.beetl.core.exception.NativeNotAllowedException; @@ -394,7 +395,7 @@ public class AntlrProgramBuilder { token = this.getBTToken(nodes.get(1).getSymbol()); flag = nodes.get(0).getSymbol().getText(); if (!(flag.equals("render") || flag.equals("norender"))) { - BeetlException be = new BeetlException(BeetlException.AJAX_PROPERTY_ERROR, + BeetlException be = new BeetlException(BeetlErrorCode.Ajax.AJAX_PROPERTY_ERROR, "expect render or norender ,but " + flag); be.pushToken(token); throw be; @@ -413,7 +414,7 @@ public class AntlrProgramBuilder { String anchor = ajaxStat.token.text; if (this.data.ajaxs.containsKey(anchor)) { GrammarToken lastToken = this.data.ajaxs.get(anchor).token; - BeetlException ex = new BeetlException(BeetlException.AJAX_ALREADY_DEFINED, + BeetlException ex = new BeetlException(BeetlErrorCode.Ajax.AJAX_ALREADY_DEFINED, "已经在第" + lastToken.line + "行定义"); ex.pushToken(token); throw ex; @@ -486,7 +487,7 @@ public class AntlrProgramBuilder { registerVar(vas); return vas; } else { - throw new BeetlException(BeetlException.VAR_NOT_DEFINED).pushToken(this.getBTToken(token)); + throw new BeetlException(BeetlErrorCode.Var.VAR_NOT_DEFINED).pushToken(this.getBTToken(token)); } } @@ -524,7 +525,7 @@ public class AntlrProgramBuilder { registerVar(vas); return vas; } else { - throw new BeetlException(BeetlException.VAR_NOT_DEFINED).pushToken(this.getBTToken(token)); + throw new BeetlException(BeetlErrorCode.Var.VAR_NOT_DEFINED).pushToken(this.getBTToken(token)); } } @@ -536,7 +537,7 @@ public class AntlrProgramBuilder { protected void registerNewVar(ASTNode vas) { if (pbCtx.hasDefined(vas.token.text) != null) { GrammarToken token = pbCtx.hasDefined(vas.token.text); - throw new BeetlException(BeetlException.VAR_ALREADY_DEFINED, "已经在第" + token.line + "行定义") + throw new BeetlException(BeetlErrorCode.Var.VAR_ALREADY_DEFINED, "已经在第" + token.line + "行定义") .pushToken(vas.token); } pbCtx.addVar(vas.token.text); @@ -666,7 +667,7 @@ public class AntlrProgramBuilder { ASTNode astNode = varDescrption.where.get(0); if (!(astNode instanceof VarDefineNode)) { //不可能发生,先保留 - BeetlException ex = new BeetlException(BeetlException.PARSER_HTML_TAG_ERROR, + BeetlException ex = new BeetlException(BeetlErrorCode.Parser.PARSER_HTML_TAG_ERROR, "标签定义了一个全局变量 " + varName + " 但是此变量名在 " + astNode.token.line + " 使用了"); ex.pushToken(this.getBTToken(id, fc.functionNs().getStart().getLine())); } @@ -704,7 +705,7 @@ public class AntlrProgramBuilder { TagFactory tf = this.gt.getTagFactory(id); if (tf == null) { - throw new BeetlException(BeetlException.TAG_NOT_FOUND) + throw new BeetlException(BeetlErrorCode.Tag.TAG_NOT_FOUND) .pushToken(this.getBTToken(id, fc.functionNs().getStart().getLine())); } return gc.createVarTag(id, expList, block, varDefine, this.getBTToken(id, line)); @@ -713,7 +714,7 @@ public class AntlrProgramBuilder { Statement block = parseBlock(blockCtx.statement(), blockCtx); TagFactory tf = this.gt.getTagFactory(id); if (tf == null) { - throw new BeetlException(BeetlException.TAG_NOT_FOUND) + throw new BeetlException(BeetlErrorCode.Tag.TAG_NOT_FOUND) .pushToken(this.getBTToken(id, fc.functionNs().getStart().getLine())); } @@ -811,7 +812,7 @@ public class AntlrProgramBuilder { if (one instanceof VarRef) { VarRef ref = (VarRef) one; if (ref.attributes.length != 0) { - BeetlException ex = new BeetlException(BeetlException.HAS_CALL_ILLEGAL, + BeetlException ex = new BeetlException(BeetlErrorCode.Function.HAS_CALL_ILLEGAL, "has函数用于判断全局变量是否存在,不能判断其属性是否有值,可以使用安全输出符号或者isEmpty函数"); ex.pushToken(ref.token); throw ex; @@ -821,7 +822,7 @@ public class AntlrProgramBuilder { // 将变量名引用转化为字符串 exps[i] = newExp; } else { - BeetlException ex = new BeetlException(BeetlException.HAS_CALL_ILLEGAL, + BeetlException ex = new BeetlException(BeetlErrorCode.Function.HAS_CALL_ILLEGAL, "has函数用于判断全局变量是否存在,请传入一个全局变量名"); ex.pushToken(exps[i].token); throw ex; @@ -936,7 +937,7 @@ public class AntlrProgramBuilder { if (pbCtx.hasDefined(forVar.token.text) != null) { GrammarToken token = pbCtx.hasDefined(forVar.token.text); - BeetlException ex = new BeetlException(BeetlException.VAR_ALREADY_DEFINED, "已经在第" + token.line + "行定义"); + BeetlException ex = new BeetlException(BeetlErrorCode.Var.VAR_ALREADY_DEFINED, "已经在第" + token.line + "行定义"); ex.pushToken(forVar.token); throw ex; } @@ -946,7 +947,7 @@ public class AntlrProgramBuilder { if (pbCtx.hasDefined(loopStatusVar.token.text) != null) { GrammarToken token = pbCtx.hasDefined(loopStatusVar.token.text); - BeetlException ex = new BeetlException(BeetlException.VAR_ALREADY_DEFINED, + BeetlException ex = new BeetlException(BeetlErrorCode.Var.VAR_ALREADY_DEFINED, "For循环隐含变量,已经在第" + token.line + "行定义"); ex.pushToken(loopStatusVar.token); throw ex; @@ -1323,7 +1324,7 @@ public class AntlrProgramBuilder { } else { msg = "()()"; } - BeetlException ex = new BeetlException(BeetlException.PARSER_NATIVE_ERROR, msg); + BeetlException ex = new BeetlException(BeetlErrorCode.Parser.PARSER_NATIVE_ERROR, msg); ex.pushToken(this.getBTToken(methodCtx.getStart())); throw ex; } @@ -1543,7 +1544,7 @@ public class AntlrProgramBuilder { Expression safeExp = null; Safe_outputContext soctx = varRef.safe_output(); if (soctx != null) { - throw new BeetlException(BeetlException.ERROR, "语法错,赋值表达式不能使用安全输出"); + throw new BeetlException(BeetlErrorCode.Default.ERROR, "语法错,赋值表达式不能使用安全输出"); } List list = varRef.varAttribute(); diff --git a/src/main/java/org/beetl/core/BeetlKit.java b/src/main/java/org/beetl/core/BeetlKit.java index 342a954..be70819 100644 --- a/src/main/java/org/beetl/core/BeetlKit.java +++ b/src/main/java/org/beetl/core/BeetlKit.java @@ -7,7 +7,7 @@ import java.util.Map; import org.beetl.core.config.BeetlConfig; import org.beetl.core.exception.BeetlException; -import org.beetl.core.exception.ErrorInfo; +import org.beetl.core.exception.BeetlErrorInfo; import org.beetl.android.util.Log; import org.beetl.core.impl.resource.StringTemplateResourceLoader; @@ -99,7 +99,7 @@ public class BeetlKit { BeetlKit.execute(json); } catch (BeetlException e) { if (DEBUG) { - ErrorInfo info = new ErrorInfo(e); + BeetlErrorInfo info = new BeetlErrorInfo(e); Log.e(TAG, "error=" + info.toString()); } } diff --git a/src/main/java/org/beetl/core/ConsoleErrorHandler.java b/src/main/java/org/beetl/core/ConsoleErrorHandler.java index aa3c447..390e476 100644 --- a/src/main/java/org/beetl/core/ConsoleErrorHandler.java +++ b/src/main/java/org/beetl/core/ConsoleErrorHandler.java @@ -32,8 +32,9 @@ import java.io.Writer; import java.text.SimpleDateFormat; import java.util.Date; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; -import org.beetl.core.exception.ErrorInfo; +import org.beetl.core.exception.BeetlErrorInfo; import org.beetl.core.runtime.IResourceLoader; /** @@ -46,9 +47,9 @@ public class ConsoleErrorHandler implements ErrorHandler { @Override public void processExcption(BeetlException ex, Writer writer) { - ErrorInfo error = new ErrorInfo(ex); + BeetlErrorInfo error = new BeetlErrorInfo(ex); - if (error.errorCode.equals(BeetlException.CLIENT_IO_ERROR_ERROR)) { + if (error.errorCode.equals(BeetlErrorCode.IO.CLIENT_IO_ERROR_ERROR)) { //不输出详细提示信息 if (!ex.gt.conf.isIgnoreClientIOError) { println(writer, "客户端IO异常:" + getResourceName(ex.resource.id) + ":" + error.msg); @@ -67,7 +68,7 @@ public class ConsoleErrorHandler implements ErrorHandler { .append(":").append(error.errorTokenText).append(" 位于").append(line != 0 ? line + "行" : "").append(" 资源:") .append(getResourceName(ex.resource.id)); - if (error.errorCode.equals(BeetlException.TEMPLATE_LOAD_ERROR)) { + if (error.errorCode.equals(BeetlErrorCode.Template.TEMPLATE_LOAD_ERROR)) { if (error.msg != null) sb.append(error.msg); println(writer, sb.toString()); @@ -124,7 +125,7 @@ public class ConsoleErrorHandler implements ErrorHandler { } - protected void printCause(ErrorInfo error, Writer writer) { + protected void printCause(BeetlErrorInfo error, Writer writer) { Throwable t = error.cause; if (t != null) { printThrowable(writer, t); diff --git a/src/main/java/org/beetl/core/DefaultTagFactory.java b/src/main/java/org/beetl/core/DefaultTagFactory.java index e20f76b..e15197b 100644 --- a/src/main/java/org/beetl/core/DefaultTagFactory.java +++ b/src/main/java/org/beetl/core/DefaultTagFactory.java @@ -27,6 +27,7 @@ */ package org.beetl.core; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.tag.Tag; import org.beetl.core.tag.TagFactory; @@ -48,9 +49,9 @@ public class DefaultTagFactory implements TagFactory { try { return (Tag) tagCls.newInstance(); } catch (InstantiationException e) { - throw new BeetlException(BeetlException.TAG_INSTANCE_ERROR, "实例化 " + tagCls + " 出错"); + throw new BeetlException(BeetlErrorCode.Tag.TAG_INSTANCE_ERROR, "实例化 " + tagCls + " 出错"); } catch (IllegalAccessException e) { - throw new BeetlException(BeetlException.TAG_INSTANCE_ERROR, "不能实例化 " + tagCls); + throw new BeetlException(BeetlErrorCode.Tag.TAG_INSTANCE_ERROR, "不能实例化 " + tagCls); } } } diff --git a/src/main/java/org/beetl/core/GroupTemplate.java b/src/main/java/org/beetl/core/GroupTemplate.java index a5cc327..d715347 100644 --- a/src/main/java/org/beetl/core/GroupTemplate.java +++ b/src/main/java/org/beetl/core/GroupTemplate.java @@ -40,6 +40,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.runtime.BeetlRuntime; import org.beetl.core.runtime.IBeetlCache; import org.beetl.core.cache.ContextBuffer; @@ -513,7 +514,7 @@ public class GroupTemplate { return ep; } catch (IOException e) { ErrorGrammarProgram ep = new ErrorGrammarProgram(res, this, String.valueOf(text.cr1)); - ep.setException(new BeetlException(BeetlException.TEMPLATE_LOAD_ERROR).pushResource(res)); + ep.setException(new BeetlException(BeetlErrorCode.Template.TEMPLATE_LOAD_ERROR).pushResource(res)); return ep; } catch (BeetlException ex) { ErrorGrammarProgram ep = new ErrorGrammarProgram(res, this, text.systemCrStr); diff --git a/src/main/java/org/beetl/core/IBeetlConstants.java b/src/main/java/org/beetl/core/IBeetlConstants.java new file mode 100644 index 0000000..7af19e1 --- /dev/null +++ b/src/main/java/org/beetl/core/IBeetlConstants.java @@ -0,0 +1,8 @@ +package org.beetl.core; + +/** + * Beetl 常量 + */ +public class IBeetlConstants { + +} diff --git a/src/main/java/org/beetl/core/Script.java b/src/main/java/org/beetl/core/Script.java index 711a6e5..36e8c05 100644 --- a/src/main/java/org/beetl/core/Script.java +++ b/src/main/java/org/beetl/core/Script.java @@ -34,7 +34,7 @@ import java.util.Map; import java.util.Map.Entry; import org.beetl.core.exception.BeetlException; -import org.beetl.core.exception.ErrorInfo; +import org.beetl.core.exception.BeetlErrorInfo; import org.beetl.core.io.BeetlCharWriter; import org.beetl.core.misc.BeetlUtil; import org.beetl.core.statement.ErrorGrammarProgram; @@ -49,7 +49,7 @@ public class Script extends Template{ protected boolean success = false; protected Map result = null; - protected ErrorInfo errorInfo = null; + protected BeetlErrorInfo errorInfo = null; protected BeetlException ex = null; private boolean done = false; @@ -72,7 +72,7 @@ public class Script extends Template{ } catch (BeetlException ex) { success = false; this.ex = ex; - this.errorInfo = new ErrorInfo(ex); + this.errorInfo = new BeetlErrorInfo(ex); } done = true; @@ -101,7 +101,7 @@ public class Script extends Template{ return (T) ret.get("return"); } - public ErrorInfo getErrorInfo() { + public BeetlErrorInfo getErrorInfo() { if (isSuccess()) { throw new IllegalStateException("脚本运行成功"); } diff --git a/src/main/java/org/beetl/core/Template.java b/src/main/java/org/beetl/core/Template.java index b0d1da0..3705b24 100644 --- a/src/main/java/org/beetl/core/Template.java +++ b/src/main/java/org/beetl/core/Template.java @@ -34,6 +34,7 @@ import java.util.Map; import java.util.Map.Entry; import org.beetl.core.cache.ContextBuffer; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.io.BeetlByteWriter; import org.beetl.core.io.BeetlCharWriter; @@ -117,7 +118,7 @@ public class Template { if (!(program instanceof ErrorGrammarProgram)) { AjaxStatement ajax = program.metaData.getAjax(ajaxId); if (ajax == null) { - BeetlException be = new BeetlException(BeetlException.AJAX_NOT_FOUND); + BeetlException be = new BeetlException(BeetlErrorCode.Ajax.AJAX_NOT_FOUND); be.pushToken(new GrammarToken(ajaxId, 0, 0)); throw be; } @@ -151,7 +152,7 @@ public class Template { // 是否打印异常,只有根模板才能打印异常 if (!isRoot) throw e; - if (e.detailCode == BeetlException.CLIENT_IO_ERROR_ERROR && ctx.gt.conf.isIgnoreClientIOError) { + if (e.detailCode == BeetlErrorCode.IO.CLIENT_IO_ERROR_ERROR && ctx.gt.conf.isIgnoreClientIOError) { return; } @@ -174,7 +175,7 @@ public class Template { } catch (IOException e) { if (!ctx.gt.conf.isIgnoreClientIOError) { - BeetlException be = new BeetlException(BeetlException.CLIENT_IO_ERROR_ERROR, e.getMessage(), e); + BeetlException be = new BeetlException(BeetlErrorCode.IO.CLIENT_IO_ERROR_ERROR, e.getMessage(), e); be.pushResource(this.program.res); be.pushToken(new GrammarToken(this.program.res.id.toString(), 0, 0)); ErrorHandler errorHandler = this.gt.getErrorHandler(); diff --git a/src/main/java/org/beetl/core/engine/GrammarCreator.java b/src/main/java/org/beetl/core/engine/GrammarCreator.java index 936a04e..e065be9 100644 --- a/src/main/java/org/beetl/core/engine/GrammarCreator.java +++ b/src/main/java/org/beetl/core/engine/GrammarCreator.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.statement.AjaxStatement; import org.beetl.core.statement.AndExpression; @@ -290,7 +291,7 @@ public class GrammarCreator implements IGrammarConstants { protected void disableSyntaxCheck(String ast) { // 禁用的语法列表 if (this.disableGrammarSet.contains(ast)) { - throw new BeetlException(BeetlException.GRAMMAR_NOT_ALLOWED, "语法 " + ast + "不允许"); + throw new BeetlException(BeetlErrorCode.Grammar.GRAMMAR_NOT_ALLOWED, "语法 " + ast + "不允许"); } } diff --git a/src/main/java/org/beetl/core/engine/OnlineTemplateEngine.java b/src/main/java/org/beetl/core/engine/OnlineTemplateEngine.java index 9e5926c..fcf4388 100644 --- a/src/main/java/org/beetl/core/engine/OnlineTemplateEngine.java +++ b/src/main/java/org/beetl/core/engine/OnlineTemplateEngine.java @@ -7,6 +7,7 @@ import java.util.Map; import org.beetl.core.Context; import org.beetl.core.GroupTemplate; import org.beetl.core.Resource; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.statement.Expression; import org.beetl.core.statement.GeneralForStatement; @@ -151,7 +152,7 @@ public class OnlineTemplateEngine extends DefaultTemplateEngine { break; } } else { - throw new BeetlException(BeetlException.BOOLEAN_EXPECTED_ERROR).setToken(exp.token); + throw new BeetlException(BeetlErrorCode.Type.BOOLEAN_EXPECTED_ERROR).setToken(exp.token); } i++; } diff --git a/src/main/java/org/beetl/core/exception/BeetlErrorCode.java b/src/main/java/org/beetl/core/exception/BeetlErrorCode.java new file mode 100644 index 0000000..b917fc3 --- /dev/null +++ b/src/main/java/org/beetl/core/exception/BeetlErrorCode.java @@ -0,0 +1,239 @@ +package org.beetl.core.exception; + +import org.intellij.lang.annotations.MagicConstant; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * Beetl 错误码 + */ +@MagicConstant(stringValues = { + BeetlErrorCode.Grammar.DO_NOT_SUPPORT, + BeetlErrorCode.Var.VAR_ALREADY_DEFINED, + BeetlErrorCode.Ajax.AJAX_ALREADY_DEFINED, + BeetlErrorCode.Ajax.AJAX_NOT_FOUND, + BeetlErrorCode.Ajax.AJAX_PROPERTY_ERROR, + BeetlErrorCode.Var.VAR_READONLY, + BeetlErrorCode.Var.VAR_NOT_DEFINED, + BeetlErrorCode.Function.FUNCTION_NOT_FOUND, + BeetlErrorCode.Function.FUNCTION_INVALID, + BeetlErrorCode.Tag.TAG_NOT_FOUND, + BeetlErrorCode.Attribute.VIRTUAL_NOT_FOUND, + BeetlErrorCode.Tag.TAG_INSTANCE_ERROR, + BeetlErrorCode.NativeCall.NATIVE_CALL_INVALID, + BeetlErrorCode.NativeCall.NATIVE_CALL_EXCEPTION, + BeetlErrorCode.NativeCall.NATIVE_SECURITY_EXCEPTION, + BeetlErrorCode.Format.FORMAT_NOT_FOUND, + BeetlErrorCode.Format.DEFAULT_FORMAT_NOT_FOUND, + BeetlErrorCode.Attribute.ATTRIBUTE_INVALID, + BeetlErrorCode.Attribute.ATTRIBUTE_NOT_FOUND, + BeetlErrorCode.Attribute.ATTRIBUTE_NOT_FOUND_PRIVATE, + BeetlErrorCode.Type.CAST_LIST_OR_MAP_ERROR, + BeetlErrorCode.Default.NULL, + BeetlErrorCode.Default.DIV_ZERO_ERROR, + BeetlErrorCode.Array.ARRAY_INDEX_ERROR, + BeetlErrorCode.Array.ARRAY_TYPE_ERROR, + BeetlErrorCode.Type.BOOLEAN_EXPECTED_ERROR, + BeetlErrorCode.Type.COLLECTION_EXPECTED_ERROR, + BeetlErrorCode.Type.NUMBER_EXPECTED_ERROR, + BeetlErrorCode.Grammar.STRICT_MVC, + BeetlErrorCode.NativeCall.NATIVE_NOT_ALLOWED, + BeetlErrorCode.Attribute.GET_CALL_ERROR, + BeetlErrorCode.Function.HAS_CALL_ILLEGAL, + BeetlErrorCode.Default.ERROR, + BeetlErrorCode.Grammar.TOKEN_ERROR, + BeetlErrorCode.Parser.PARSER_UNKNOW_ERROR, + BeetlErrorCode.Parser.PARSER_VIABLE_ERROR, + BeetlErrorCode.Parser.PARSER_MISS_ERROR, + BeetlErrorCode.Parser.PARSER_PREDICATE_ERROR, + BeetlErrorCode.Parser.PARSER_HTML_TAG_ERROR, + BeetlErrorCode.Type.TYPE_SEARCH_ERROR, + BeetlErrorCode.Parser.PARSER_NATIVE_ERROR, + BeetlErrorCode.Template.TEMPLATE_LOAD_ERROR, + BeetlErrorCode.IO.CLIENT_IO_ERROR_ERROR, + BeetlErrorCode.Type.EXPRESSION_NOT_COMPATIBLE, + BeetlErrorCode.Grammar.GRAMMAR_NOT_ALLOWED +}) +@Retention(RetentionPolicy.SOURCE) +public @interface BeetlErrorCode { + + /** + * 变量相关错误 + */ + interface Var { + /** 变量已经定义过了 */ + String VAR_ALREADY_DEFINED = "VAR_ALREADY_DEFINED"; + /** 变量只读: 通过template.set()的变量,即用于渲染模板的变量都是只读的,不能在模板中被改写 */ + String VAR_READONLY = "VAR_READONLY"; + /** 模板引用未定义的变量 */ + String VAR_NOT_DEFINED = "VAR_NOT_DEFINED"; + } + + /** + * AJAX 相关错误 + */ + interface Ajax { + /** AJAX 已经定义过了 */ + String AJAX_ALREADY_DEFINED = "AJAX_ALREADY_DEFINED"; + /** AJAX 未找到 */ + String AJAX_NOT_FOUND = "AJAX_NOT_FOUND"; + /** AJAX 属性定义错误 */ + String AJAX_PROPERTY_ERROR = "AJAX_PROPERTY_ERROR"; + } + + interface Function { + /** 函数未定义 */ + String FUNCTION_NOT_FOUND = "FUNCTION_NOT_FOUND"; + /** 函数定义无效 */ + String FUNCTION_INVALID = "FUNCTION_INVALID"; + /** has函数调用错误 */ + String HAS_CALL_ILLEGAL = "HAS_CALL_ILLEGAL"; + } + + /** + * 语法相关错误 + */ + interface Grammar { + + /** 不支持 */ + String DO_NOT_SUPPORT = "DO_NOT_SUPPORT"; + /** Token 错误 */ + String TOKEN_ERROR = "TOKEN_ERROR"; + /** 不允许的语法 */ + String GRAMMAR_NOT_ALLOWED = "GRAMMAR_NOT_ALLOWED"; + /** 严格MVC错误,模板使用严格MVC,但模板内容含有不允许的语法 */ + String STRICT_MVC = "STRICT_MVC"; + } + + /** + * 本地调用相关错误 + */ + interface NativeCall { + /** 本地(Java)调用错误,如 classnotfound, methodnotfound 等 */ + String NATIVE_CALL_INVALID = "NATIVE_CALL_INVALID"; + /** 被调用的 class 抛出了异常 */ + String NATIVE_CALL_EXCEPTION = "NATIVE_CALL_EXCEPTION"; + /** 不允许本地调用 */ + String NATIVE_SECURITY_EXCEPTION = "NATIVE_SECURITY_EXCEPTION"; + /** 不允许调用本地方法 */ + String NATIVE_NOT_ALLOWED = "NATIVE_NOT_ALLOWED"; + } + + /** + * 标签相关错误 + */ + interface Tag { + /** 标签未找到 */ + String TAG_NOT_FOUND = "TAG_NOT_FOUND"; + /** 标签实例化错误 */ + String TAG_INSTANCE_ERROR = "TAG_INSTANCE_ERROR"; + } + + /** + * 属性相关错误 + */ + interface Attribute { + + /** 引用属性失效 */ + String ATTRIBUTE_INVALID = "ATTRIBUTE_INVALID"; + /** 属性未找到 */ + String ATTRIBUTE_NOT_FOUND = "ATTRIBUTE_NOT_FOUND"; + /** 属性不存在,但可能是私有 */ + String ATTRIBUTE_NOT_FOUND_PRIVATE = "ATTRIBUTE_NOT_FOUND_PRIVATE"; + /** 虚拟属性未找到 {@code list.~size} */ + String VIRTUAL_NOT_FOUND = "VIRTUAL_NOT_FOUND"; + /** 对象的属性get方法出错 */ + String GET_CALL_ERROR = "GET_CALL_ERROR"; + } + + /** + * 类型或类型转换相关错误 + */ + interface Type { + /** 模板里使用了[]指示应该是 Map 或者 List,但实际上不是此类型 */ + String CAST_LIST_OR_MAP_ERROR = "CAST_LIST_OR_MAP_ERROR"; + /** 期望表达式返回 bool 值,但却是其他类型 */ + String BOOLEAN_EXPECTED_ERROR = "BOOLEAN_EXPECTED_ERROR"; + /** 期望是个集合,数组,Iterator,Iterable类型,但却是其他类型 */ + String COLLECTION_EXPECTED_ERROR = "COLLECTION_EXPECTED_ERROR"; + /** 期望是数字类型,但却是其他类型 */ + String NUMBER_EXPECTED_ERROR = "NUMBER_EXPECTED_ERROR"; + /** 类型识别错误 */ + String TYPE_SEARCH_ERROR = "TYPE_SEARCH_ERROR"; + /** 表达式类型不一致,无法运算,如俩个字符串相乘 */ + String EXPRESSION_NOT_COMPATIBLE = "EXPRESSION_NOT_COMPATIBLE"; + } + + /** + * 格式化相关错误 + */ + interface Format { + /** 格式化函数未找到 */ + String FORMAT_NOT_FOUND = "FORMAT_NOT_FOUND"; + /** 默认的格式化函数未找到 */ + String DEFAULT_FORMAT_NOT_FOUND = "DEFAULT_FORMAT_NOT_FOUND"; + } + + /** + * 数组相关错误 + */ + interface Array { + + /** 数组 index 错 */ + String ARRAY_INDEX_ERROR = "ARRAY_INDEX_ERROR"; + /** 必须是数组 */ + String ARRAY_TYPE_ERROR = "ARRAY_TYPE_ERROR"; + } + + /** + * 默认错误 / 未归类错误 + */ + interface Default { + + /** NULL 标识 */ + String NULL = "NULL"; + /** 除 0 错误 */ + String DIV_ZERO_ERROR = "DIV_ZERO_ERROR"; + /** 语法错误 */ + String ERROR = "ERROR"; + } + + /** + * 解析时错误 + */ + interface Parser { + /** 错误码的前缀 */ + String PREFIX = "PARSER"; + + /** 解析时产生的未知错误 */ + String PARSER_UNKNOW_ERROR = "PARSER_UNKNOW_ERROR"; + /** 解析时产生语法错误 */ + String PARSER_VIABLE_ERROR = "PARSER_VIABLE_ERROR"; + /** 解析时缺少符号 */ + String PARSER_MISS_ERROR = "PARSER_MISS_ERROR"; + /** 解析时产生的谓语错误 */ + String PARSER_PREDICATE_ERROR = "PARSER_PREDICATE_ERROR"; + /** HTML TAG 解析出错 */ + String PARSER_HTML_TAG_ERROR = "PARSER_HTML_TAG_ERROR"; + /** 本地调用格式错误,如a[0](1,2) */ + String PARSER_NATIVE_ERROR = "PARSER_NATIVE_ERROR"; + } + + /** + * 模板错误 + */ + interface Template { + /** 错误码的前缀 */ + String PREFIX = "TEMPLATE"; + + /** 模板加载失败 */ + String TEMPLATE_LOAD_ERROR = "TEMPLATE_LOAD_ERROR"; + } + + interface IO { + /** Client IO */ + String CLIENT_IO_ERROR_ERROR = "CLIENT_IO_ERROR_ERROR"; + } + +} diff --git a/src/main/java/org/beetl/core/exception/ErrorInfo.java b/src/main/java/org/beetl/core/exception/BeetlErrorInfo.java similarity index 44% rename from src/main/java/org/beetl/core/exception/ErrorInfo.java rename to src/main/java/org/beetl/core/exception/BeetlErrorInfo.java index 04572ce..cf80e00 100644 --- a/src/main/java/org/beetl/core/exception/ErrorInfo.java +++ b/src/main/java/org/beetl/core/exception/BeetlErrorInfo.java @@ -40,7 +40,7 @@ import org.beetl.core.statement.GrammarToken; * * @author xiandafu */ -public class ErrorInfo { +public class BeetlErrorInfo { /** {@link GrammarToken#text} */ public String errorTokenText = ""; @@ -56,7 +56,7 @@ public class ErrorInfo { public List tokenCallStack = null; /** 错误码 */ - @BeetlException.BeetlErrorCode + @BeetlErrorCode public String errorCode = null; /** 错误类型 */ public String type = ""; @@ -65,49 +65,49 @@ public class ErrorInfo { public static Map errorLocalMap = new HashMap<>(); static { - errorLocalMap.put(BeetlException.ERROR, "错误"); - errorLocalMap.put(BeetlException.DO_NOT_SUPPORT, "不支持的语法"); - errorLocalMap.put(BeetlException.VAR_ALREADY_DEFINED, concat("变量已经定义", BeetlException.VAR_ALREADY_DEFINED)); - errorLocalMap.put(BeetlException.VAR_READONLY, concat("全局变量为只读变量", BeetlException.VAR_READONLY)); - errorLocalMap.put(BeetlException.VAR_NOT_DEFINED, concat("变量未定义", BeetlException.VAR_NOT_DEFINED)); - errorLocalMap.put(BeetlException.FUNCTION_NOT_FOUND, concat("该方法未注册", BeetlException.FUNCTION_NOT_FOUND)); - errorLocalMap.put(BeetlException.FUNCTION_INVALID, concat("方法未实现Function接口", BeetlException.FUNCTION_INVALID)); - errorLocalMap.put(BeetlException.TAG_NOT_FOUND, concat("该标签未注册", BeetlException.TAG_NOT_FOUND)); - errorLocalMap.put(BeetlException.VIRTUAL_NOT_FOUND, concat("未找到虚拟属性", BeetlException.VIRTUAL_NOT_FOUND)); - errorLocalMap.put(BeetlException.TAG_INSTANCE_ERROR, concat("创建Tag错", BeetlException.TAG_INSTANCE_ERROR)); - errorLocalMap.put(BeetlException.NATIVE_CALL_INVALID, concat("本地调用不合法,找不到类或者方法", BeetlException.NATIVE_CALL_INVALID)); - errorLocalMap.put(BeetlException.NATIVE_CALL_EXCEPTION, concat("调用方法抛出了异常", BeetlException.NATIVE_CALL_EXCEPTION)); - errorLocalMap.put(BeetlException.NATIVE_SECUARITY_EXCEPTION, concat("安全管理器不允许的本地调用", BeetlException.NATIVE_SECUARITY_EXCEPTION)); - errorLocalMap.put(BeetlException.FORMAT_NOT_FOUND, concat("未注册的格式化函数", BeetlException.FORMAT_NOT_FOUND)); - errorLocalMap.put(BeetlException.DEFAULT_FORMAT_NOT_FOUND, concat("类型未有对应的默认的格式化函数", BeetlException.DEFAULT_FORMAT_NOT_FOUND)); - errorLocalMap.put(BeetlException.ATTRIBUTE_INVALID, concat("属性获取异常", BeetlException.ATTRIBUTE_INVALID)); - errorLocalMap.put(BeetlException.ATTRIBUTE_NOT_FOUND, concat("未找到属性", BeetlException.ATTRIBUTE_NOT_FOUND)); - errorLocalMap.put(BeetlException.CAST_LIST_OR_MAP_ERROR, concat("模板里使用了[]指示应该是Map或者List,但实际上不是此类型", BeetlException.CAST_LIST_OR_MAP_ERROR)); - errorLocalMap.put(BeetlException.ATTRIBUTE_NOT_FOUND_PRIVATE, concat("未找到属性,可能是私有属性", BeetlException.ATTRIBUTE_NOT_FOUND)); - errorLocalMap.put(BeetlException.NULL, concat("表达式值为空", BeetlException.NULL)); - errorLocalMap.put(BeetlException.DIV_ZERO_ERROR, concat("除0错误", BeetlException.DIV_ZERO_ERROR)); - errorLocalMap.put(BeetlException.ARRAY_INDEX_ERROR, concat("数组index错", BeetlException.ARRAY_INDEX_ERROR)); - errorLocalMap.put(BeetlException.ARRAY_TYPE_ERROR, concat("本地调用[] 期望类型是数组", BeetlException.ARRAY_TYPE_ERROR)); - errorLocalMap.put(BeetlException.BOOLEAN_EXPECTED_ERROR, concat("期望为Boolean类型", BeetlException.BOOLEAN_EXPECTED_ERROR)); - errorLocalMap.put(BeetlException.COLLECTION_EXPECTED_ERROR, concat("期望遍历目标是是集合,数组,Iterator,Iterable", BeetlException.COLLECTION_EXPECTED_ERROR)); - errorLocalMap.put(BeetlException.NUMBER_EXPECTED_ERROR, concat("期望是数字类型", BeetlException.NUMBER_EXPECTED_ERROR)); - errorLocalMap.put(BeetlException.STRICK_MVC, concat("严格MVC,不允许的语法", BeetlException.STRICK_MVC)); - errorLocalMap.put(BeetlException.NATIVE_NOT_ALLOWED, concat("本地调用不允许", BeetlException.NATIVE_NOT_ALLOWED)); - errorLocalMap.put(BeetlException.GET_CALL_ERROR, concat("属性获取错误", BeetlException.GET_CALL_ERROR)); - errorLocalMap.put(BeetlException.TOKEN_ERROR, concat("词法错误", BeetlException.TOKEN_ERROR)); - errorLocalMap.put(BeetlException.PARSER_HTML_TAG_ERROR, concat("解析HTML标签出错", BeetlException.PARSER_HTML_TAG_ERROR)); - errorLocalMap.put(BeetlException.PARSER_UNKNOW_ERROR, concat("语法错误", BeetlException.PARSER_UNKNOW_ERROR)); - errorLocalMap.put(BeetlException.PARSER_VIABLE_ERROR, concat("语法错误,无法继续解析模板", BeetlException.PARSER_VIABLE_ERROR)); - errorLocalMap.put(BeetlException.PARSER_MISS_ERROR, concat("缺少符号", BeetlException.PARSER_MISS_ERROR)); - errorLocalMap.put(BeetlException.PARSER_PREDICATE_ERROR, concat("语法错误", BeetlException.PARSER_PREDICATE_ERROR)); - errorLocalMap.put(BeetlException.TYPE_SEARCH_ERROR, concat("未找到指定类型,请配置类搜索路径或者增加类包名", BeetlException.TYPE_SEARCH_ERROR)); - errorLocalMap.put(BeetlException.PARSER_NATIVE_ERROR, concat("本地调用格式出错,不允许此格式", BeetlException.PARSER_NATIVE_ERROR)); - errorLocalMap.put(BeetlException.TEMPLATE_LOAD_ERROR, concat("找不到指定模板或者加载模板错", BeetlException.TEMPLATE_LOAD_ERROR)); - errorLocalMap.put(BeetlException.CLIENT_IO_ERROR_ERROR, concat("客户端IO出错", BeetlException.CLIENT_IO_ERROR_ERROR)); - errorLocalMap.put(BeetlException.EXPRESSION_NOT_COMPATIBLE, concat("表达式类型不一致,无法运算", BeetlException.EXPRESSION_NOT_COMPATIBLE)); - errorLocalMap.put(BeetlException.AJAX_ALREADY_DEFINED, concat("Ajax 锚点已经定义", BeetlException.AJAX_ALREADY_DEFINED)); - errorLocalMap.put(BeetlException.AJAX_NOT_FOUND, concat("Ajax 锚点未定义", BeetlException.AJAX_NOT_FOUND)); - errorLocalMap.put(BeetlException.AJAX_PROPERTY_ERROR, concat("Ajax 属性设置错误", BeetlException.AJAX_PROPERTY_ERROR)); + errorLocalMap.put(BeetlErrorCode.Default.ERROR, "错误"); + errorLocalMap.put(BeetlErrorCode.Grammar.DO_NOT_SUPPORT, "不支持的语法"); + errorLocalMap.put(BeetlErrorCode.Var.VAR_ALREADY_DEFINED, concat("变量已经定义", BeetlErrorCode.Var.VAR_ALREADY_DEFINED)); + errorLocalMap.put(BeetlErrorCode.Var.VAR_READONLY, concat("全局变量为只读变量", BeetlErrorCode.Var.VAR_READONLY)); + errorLocalMap.put(BeetlErrorCode.Var.VAR_NOT_DEFINED, concat("变量未定义", BeetlErrorCode.Var.VAR_NOT_DEFINED)); + errorLocalMap.put(BeetlErrorCode.Function.FUNCTION_NOT_FOUND, concat("该方法未注册", BeetlErrorCode.Function.FUNCTION_NOT_FOUND)); + errorLocalMap.put(BeetlErrorCode.Function.FUNCTION_INVALID, concat("方法未实现Function接口", BeetlErrorCode.Function.FUNCTION_INVALID)); + errorLocalMap.put(BeetlErrorCode.Tag.TAG_NOT_FOUND, concat("该标签未注册", BeetlErrorCode.Tag.TAG_NOT_FOUND)); + errorLocalMap.put(BeetlErrorCode.Attribute.VIRTUAL_NOT_FOUND, concat("未找到虚拟属性", BeetlErrorCode.Attribute.VIRTUAL_NOT_FOUND)); + errorLocalMap.put(BeetlErrorCode.Tag.TAG_INSTANCE_ERROR, concat("创建Tag错", BeetlErrorCode.Tag.TAG_INSTANCE_ERROR)); + errorLocalMap.put(BeetlErrorCode.NativeCall.NATIVE_CALL_INVALID, concat("本地调用不合法,找不到类或者方法", BeetlErrorCode.NativeCall.NATIVE_CALL_INVALID)); + errorLocalMap.put(BeetlErrorCode.NativeCall.NATIVE_CALL_EXCEPTION, concat("调用方法抛出了异常", BeetlErrorCode.NativeCall.NATIVE_CALL_EXCEPTION)); + errorLocalMap.put(BeetlErrorCode.NativeCall.NATIVE_SECURITY_EXCEPTION, concat("安全管理器不允许的本地调用", BeetlErrorCode.NativeCall.NATIVE_SECURITY_EXCEPTION)); + errorLocalMap.put(BeetlErrorCode.Format.FORMAT_NOT_FOUND, concat("未注册的格式化函数", BeetlErrorCode.Format.FORMAT_NOT_FOUND)); + errorLocalMap.put(BeetlErrorCode.Format.DEFAULT_FORMAT_NOT_FOUND, concat("类型未有对应的默认的格式化函数", BeetlErrorCode.Format.DEFAULT_FORMAT_NOT_FOUND)); + errorLocalMap.put(BeetlErrorCode.Attribute.ATTRIBUTE_INVALID, concat("属性获取异常", BeetlErrorCode.Attribute.ATTRIBUTE_INVALID)); + errorLocalMap.put(BeetlErrorCode.Attribute.ATTRIBUTE_NOT_FOUND, concat("未找到属性", BeetlErrorCode.Attribute.ATTRIBUTE_NOT_FOUND)); + errorLocalMap.put(BeetlErrorCode.Type.CAST_LIST_OR_MAP_ERROR, concat("模板里使用了[]指示应该是Map或者List,但实际上不是此类型", BeetlErrorCode.Type.CAST_LIST_OR_MAP_ERROR)); + errorLocalMap.put(BeetlErrorCode.Attribute.ATTRIBUTE_NOT_FOUND_PRIVATE, concat("未找到属性,可能是私有属性", BeetlErrorCode.Attribute.ATTRIBUTE_NOT_FOUND)); + errorLocalMap.put(BeetlErrorCode.Default.NULL, concat("表达式值为空", BeetlErrorCode.Default.NULL)); + errorLocalMap.put(BeetlErrorCode.Default.DIV_ZERO_ERROR, concat("除0错误", BeetlErrorCode.Default.DIV_ZERO_ERROR)); + errorLocalMap.put(BeetlErrorCode.Array.ARRAY_INDEX_ERROR, concat("数组index错", BeetlErrorCode.Array.ARRAY_INDEX_ERROR)); + errorLocalMap.put(BeetlErrorCode.Array.ARRAY_TYPE_ERROR, concat("本地调用[] 期望类型是数组", BeetlErrorCode.Array.ARRAY_TYPE_ERROR)); + errorLocalMap.put(BeetlErrorCode.Type.BOOLEAN_EXPECTED_ERROR, concat("期望为Boolean类型", BeetlErrorCode.Type.BOOLEAN_EXPECTED_ERROR)); + errorLocalMap.put(BeetlErrorCode.Type.COLLECTION_EXPECTED_ERROR, concat("期望遍历目标是是集合,数组,Iterator,Iterable", BeetlErrorCode.Type.COLLECTION_EXPECTED_ERROR)); + errorLocalMap.put(BeetlErrorCode.Type.NUMBER_EXPECTED_ERROR, concat("期望是数字类型", BeetlErrorCode.Type.NUMBER_EXPECTED_ERROR)); + errorLocalMap.put(BeetlErrorCode.Grammar.STRICT_MVC, concat("严格MVC,不允许的语法", BeetlErrorCode.Grammar.STRICT_MVC)); + errorLocalMap.put(BeetlErrorCode.NativeCall.NATIVE_NOT_ALLOWED, concat("本地调用不允许", BeetlErrorCode.NativeCall.NATIVE_NOT_ALLOWED)); + errorLocalMap.put(BeetlErrorCode.Attribute.GET_CALL_ERROR, concat("属性获取错误", BeetlErrorCode.Attribute.GET_CALL_ERROR)); + errorLocalMap.put(BeetlErrorCode.Grammar.TOKEN_ERROR, concat("词法错误", BeetlErrorCode.Grammar.TOKEN_ERROR)); + errorLocalMap.put(BeetlErrorCode.Parser.PARSER_HTML_TAG_ERROR, concat("解析HTML标签出错", BeetlErrorCode.Parser.PARSER_HTML_TAG_ERROR)); + errorLocalMap.put(BeetlErrorCode.Parser.PARSER_UNKNOW_ERROR, concat("语法错误", BeetlErrorCode.Parser.PARSER_UNKNOW_ERROR)); + errorLocalMap.put(BeetlErrorCode.Parser.PARSER_VIABLE_ERROR, concat("语法错误,无法继续解析模板", BeetlErrorCode.Parser.PARSER_VIABLE_ERROR)); + errorLocalMap.put(BeetlErrorCode.Parser.PARSER_MISS_ERROR, concat("缺少符号", BeetlErrorCode.Parser.PARSER_MISS_ERROR)); + errorLocalMap.put(BeetlErrorCode.Parser.PARSER_PREDICATE_ERROR, concat("语法错误", BeetlErrorCode.Parser.PARSER_PREDICATE_ERROR)); + errorLocalMap.put(BeetlErrorCode.Type.TYPE_SEARCH_ERROR, concat("未找到指定类型,请配置类搜索路径或者增加类包名", BeetlErrorCode.Type.TYPE_SEARCH_ERROR)); + errorLocalMap.put(BeetlErrorCode.Parser.PARSER_NATIVE_ERROR, concat("本地调用格式出错,不允许此格式", BeetlErrorCode.Parser.PARSER_NATIVE_ERROR)); + errorLocalMap.put(BeetlErrorCode.Template.TEMPLATE_LOAD_ERROR, concat("找不到指定模板或者加载模板错", BeetlErrorCode.Template.TEMPLATE_LOAD_ERROR)); + errorLocalMap.put(BeetlErrorCode.IO.CLIENT_IO_ERROR_ERROR, concat("客户端IO出错", BeetlErrorCode.IO.CLIENT_IO_ERROR_ERROR)); + errorLocalMap.put(BeetlErrorCode.Type.EXPRESSION_NOT_COMPATIBLE, concat("表达式类型不一致,无法运算", BeetlErrorCode.Type.EXPRESSION_NOT_COMPATIBLE)); + errorLocalMap.put(BeetlErrorCode.Ajax.AJAX_ALREADY_DEFINED, concat("Ajax 锚点已经定义", BeetlErrorCode.Ajax.AJAX_ALREADY_DEFINED)); + errorLocalMap.put(BeetlErrorCode.Ajax.AJAX_NOT_FOUND, concat("Ajax 锚点未定义", BeetlErrorCode.Ajax.AJAX_NOT_FOUND)); + errorLocalMap.put(BeetlErrorCode.Ajax.AJAX_PROPERTY_ERROR, concat("Ajax 属性设置错误", BeetlErrorCode.Ajax.AJAX_PROPERTY_ERROR)); } /** @@ -117,7 +117,7 @@ public class ErrorInfo { * @param code 错误码 * @return {@link #type} */ - private static String concat(String info, @BeetlException.BeetlErrorCode String code) { + private static String concat(String info, @BeetlErrorCode String code) { return info + "(" + code + ")"; } @@ -126,14 +126,14 @@ public class ErrorInfo { * * @param ex Beetl异常 */ - public ErrorInfo(BeetlException ex) { + public BeetlErrorInfo(BeetlException ex) { cause = ex.getCause(); errorCode = ex.detailCode; - if (errorCode.startsWith("TEMPLATE")) { + if (errorCode.startsWith(BeetlErrorCode.Template.PREFIX)) { this.msg = ex.getMessage(); this.type = errorLocalMap.get(errorCode); return; - } else if (errorCode.startsWith("PARSER")) { + } else if (errorCode.startsWith(BeetlErrorCode.Parser.PREFIX)) { if (ex.token != null) { this.errorTokenText = ex.token.text; } else { diff --git a/src/main/java/org/beetl/core/exception/BeetlException.java b/src/main/java/org/beetl/core/exception/BeetlException.java index 1c72ff3..47a5a2d 100644 --- a/src/main/java/org/beetl/core/exception/BeetlException.java +++ b/src/main/java/org/beetl/core/exception/BeetlException.java @@ -27,15 +27,12 @@ */ package org.beetl.core.exception; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.List; import org.beetl.core.GroupTemplate; import org.beetl.core.Resource; import org.beetl.core.statement.GrammarToken; -import org.intellij.lang.annotations.MagicConstant; /** * Beetl异常基类,此异常包含了错误码,错误符号,所属的模板文件,以及错误详情,错误栈 @@ -44,114 +41,6 @@ import org.intellij.lang.annotations.MagicConstant; */ public class BeetlException extends RuntimeException { - @MagicConstant(stringValues = { - DO_NOT_SUPPORT, VAR_ALREADY_DEFINED, AJAX_ALREADY_DEFINED, AJAX_NOT_FOUND, AJAX_PROPERTY_ERROR, - VAR_READONLY, VAR_NOT_DEFINED, FUNCTION_NOT_FOUND, FUNCTION_INVALID, TAG_NOT_FOUND, - VIRTUAL_NOT_FOUND, TAG_INSTANCE_ERROR, NATIVE_CALL_INVALID, NATIVE_CALL_EXCEPTION, - NATIVE_SECUARITY_EXCEPTION, FORMAT_NOT_FOUND, DEFAULT_FORMAT_NOT_FOUND, - ATTRIBUTE_INVALID, ATTRIBUTE_NOT_FOUND, ATTRIBUTE_NOT_FOUND_PRIVATE, - CAST_LIST_OR_MAP_ERROR, NULL, DIV_ZERO_ERROR, ARRAY_INDEX_ERROR, ARRAY_TYPE_ERROR, - BOOLEAN_EXPECTED_ERROR, COLLECTION_EXPECTED_ERROR, NUMBER_EXPECTED_ERROR, - STRICK_MVC, NATIVE_NOT_ALLOWED, GET_CALL_ERROR, HAS_CALL_ILLEGAL, ERROR, TOKEN_ERROR, - PARSER_UNKNOW_ERROR, PARSER_VIABLE_ERROR, PARSER_MISS_ERROR, PARSER_PREDICATE_ERROR, - PARSER_HTML_TAG_ERROR, TYPE_SEARCH_ERROR, PARSER_NATIVE_ERROR, TEMPLATE_LOAD_ERROR, - CLIENT_IO_ERROR_ERROR, EXPRESSION_NOT_COMPATIBLE, GRAMMAR_NOT_ALLOWED - }) - @Retention(RetentionPolicy.SOURCE) - public @interface BeetlErrorCode { - } - - /** 不支持 */ - public static final String DO_NOT_SUPPORT = "DO_NOT_SUPPORT"; - /** 变量已经定义过了 */ - public static final String VAR_ALREADY_DEFINED = "VAR_ALREADY_DEFINED"; - /** AJAX 已经定义过了 */ - public static final String AJAX_ALREADY_DEFINED = "AJAX_ALREADY_DEFINED"; - /** AJAX 未找到 */ - public static final String AJAX_NOT_FOUND = "AJAX_NOT_FOUND"; - /** AJAX 属性定义错误 */ - public static final String AJAX_PROPERTY_ERROR = "AJAX_PROPERTY_ERROR"; - /** 变量只读: 通过template.set()的变量,即用于渲染模板的变量都是只读的,不能在模板中被改写 */ - public static final String VAR_READONLY = "VAR_READONLY"; - /** 模板引用未定义的变量 */ - public static final String VAR_NOT_DEFINED = "VAR_NOT_DEFINED"; - /** 函数未定义 */ - public static final String FUNCTION_NOT_FOUND = "FUNCTION_NOT_FOUND"; - /** 函数定义无效 */ - public static final String FUNCTION_INVALID = "FUNCTION_INVALID"; - /** 标签未找到 */ - public static final String TAG_NOT_FOUND = "TAG_NOT_FOUND"; - /** 虚拟属性未找到 */ - public static final String VIRTUAL_NOT_FOUND = "VIRTUAL_NOT_FOUND"; - /** 标签实例化错误 */ - public static final String TAG_INSTANCE_ERROR = "TAG_INSTANCE_ERROR"; - /** 本地(Java)调用错误,如 classnotfound, methodnotfound 等 */ - public static final String NATIVE_CALL_INVALID = "NATIVE_CALL_INVALID"; - /** 被调用的 class 抛出了异常 */ - public static final String NATIVE_CALL_EXCEPTION = "NATIVE_CALL_EXCEPTION"; - /** 不允许本地调用 */ - public static final String NATIVE_SECUARITY_EXCEPTION = "NATIVE_SECUARITY_EXCEPTION"; - /** 格式化函数未找到 */ - public static final String FORMAT_NOT_FOUND = "FORMAT_NOT_FOUND"; - /** 默认的格式化函数未找到 */ - public static final String DEFAULT_FORMAT_NOT_FOUND = "DEFAULT_FORMAT_NOT_FOUND"; - /** 引用属性失效 */ - public static final String ATTRIBUTE_INVALID = "ATTRIBUTE_INVALID"; - /** 属性未找到 */ - public static final String ATTRIBUTE_NOT_FOUND = "ATTRIBUTE_NOT_FOUND"; - /** 属性不存在,但可能是私有 */ - public static final String ATTRIBUTE_NOT_FOUND_PRIVATE = "ATTRIBUTE_NOT_FOUND_PRIVATE"; - /** 模板里使用了[]指示应该是 Map 或者 List,但实际上不是此类型 */ - public static final String CAST_LIST_OR_MAP_ERROR = "CAST_LIST_OR_MAP_ERROR"; - /** NULL 标识 */ - public static final String NULL = "NULL"; - /** 除 0 错误 */ - public static final String DIV_ZERO_ERROR = "DIV_ZERO_ERROR"; - /** 数组 index 错 */ - public static final String ARRAY_INDEX_ERROR = "ARRAY_INDEX_ERROR"; - /** 必须是数组 */ - public static final String ARRAY_TYPE_ERROR = "ARRAY_TYPE_ERROR"; - /** 期望表达式返回 bool 值,但却是其他类型 */ - public static final String BOOLEAN_EXPECTED_ERROR = "BOOLEAN_EXPECTED_ERROR"; - /** 期望是个集合,数组,Iterator,Iterable类型,但却是其他类型 */ - public static final String COLLECTION_EXPECTED_ERROR = "COLLECTION_EXPECTED_ERROR"; - /** 期望是数字类型,但却是其他类型 */ - public static final String NUMBER_EXPECTED_ERROR = "NUMBER_EXPECTED_ERROR"; - /** 严格MVC错误,模板使用严格MVC,但模板内容含有不允许的语法 */ - public static final String STRICK_MVC = "STRICK_MVC"; - /** 不允许调用本地方法 */ - public static final String NATIVE_NOT_ALLOWED = "NATIVE_NOT_ALLOWED"; - /** 对象的属性get方法出错 */ - public static final String GET_CALL_ERROR = "GET_CALL_ERROR"; - /** has函数调用错误 */ - public static final String HAS_CALL_ILLEGAL = "HAS_CALL_ILLEGAL"; - /** 语法错误 */ - public static final String ERROR = "ERROR"; - /** Token 错误 */ - public static final String TOKEN_ERROR = "TOKEN_ERROR"; - /** 解析时产生的未知错误 */ - public static final String PARSER_UNKNOW_ERROR = "PARSER_UNKNOW_ERROR"; - /** 解析时产生语法错误 */ - public static final String PARSER_VIABLE_ERROR = "PARSER_VIABLE_ERROR"; - /** 解析时缺少符号 */ - public static final String PARSER_MISS_ERROR = "PARSER_MISS_ERROR"; - /** 解析时产生的谓语错误 */ - public static final String PARSER_PREDICATE_ERROR = "PARSER_PREDICATE_ERROR"; - /** HTML TAG 解析出错 */ - public static final String PARSER_HTML_TAG_ERROR = "PARSER_HTML_TAG_ERROR"; - /** 类型识别错误 */ - public static final String TYPE_SEARCH_ERROR = "TYPE_SEARCH_ERROR"; - /** 本地调用格式错误,如a[0](1,2) */ - public static final String PARSER_NATIVE_ERROR = "PARSER_NATIVE_ERROR"; - /** 模板加载失败 */ - public static final String TEMPLATE_LOAD_ERROR = "TEMPLATE_LOAD_ERROR"; - /** Client IO */ - public static final String CLIENT_IO_ERROR_ERROR = "CLIENT_IO_ERROR_ERROR"; - /** 表达式类型不一致,无法运算,如俩个字符串相乘 */ - public static final String EXPRESSION_NOT_COMPATIBLE = "EXPRESSION_NOT_COMPATIBLE"; - /** 不允许的语法 */ - public static final String GRAMMAR_NOT_ALLOWED = "GRAMMAR_NOT_ALLOWED"; - /** 错误栈的初始容量 */ private static final int DEFAULT_INITIAL_CAPACITY = 3; @@ -279,8 +168,8 @@ public class BeetlException extends RuntimeException { /** * 返回一个错误描述信息 */ - public ErrorInfo toErrorInfo() { - return new ErrorInfo(this); + public BeetlErrorInfo toErrorInfo() { + return new BeetlErrorInfo(this); } } diff --git a/src/main/java/org/beetl/core/exception/HTMLTagParserException.java b/src/main/java/org/beetl/core/exception/HTMLTagParserException.java index da51268..e5c6f43 100644 --- a/src/main/java/org/beetl/core/exception/HTMLTagParserException.java +++ b/src/main/java/org/beetl/core/exception/HTMLTagParserException.java @@ -43,7 +43,7 @@ public class HTMLTagParserException extends BeetlException { * @param message 错误信息 */ public HTMLTagParserException(String message) { - super(BeetlException.PARSER_HTML_TAG_ERROR, message); + super(BeetlErrorCode.Parser.PARSER_HTML_TAG_ERROR, message); } /** diff --git a/src/main/java/org/beetl/core/exception/MVCStrictException.java b/src/main/java/org/beetl/core/exception/MVCStrictException.java index a243088..bb08134 100644 --- a/src/main/java/org/beetl/core/exception/MVCStrictException.java +++ b/src/main/java/org/beetl/core/exception/MVCStrictException.java @@ -42,7 +42,7 @@ public class MVCStrictException extends BeetlException { * @param token 语法单词 */ public MVCStrictException(GrammarToken token) { - super(BeetlException.STRICK_MVC); + super(BeetlErrorCode.Grammar.STRICT_MVC); this.token = token; } diff --git a/src/main/java/org/beetl/core/exception/NativeNotAllowedException.java b/src/main/java/org/beetl/core/exception/NativeNotAllowedException.java index 6968dda..c2ed86b 100644 --- a/src/main/java/org/beetl/core/exception/NativeNotAllowedException.java +++ b/src/main/java/org/beetl/core/exception/NativeNotAllowedException.java @@ -42,7 +42,7 @@ public class NativeNotAllowedException extends BeetlException { * @param token 语法单词 */ public NativeNotAllowedException(GrammarToken token) { - super(BeetlException.NATIVE_NOT_ALLOWED); + super(BeetlErrorCode.NativeCall.NATIVE_NOT_ALLOWED); this.token = token; } diff --git a/src/main/java/org/beetl/core/exception/TextParserException.java b/src/main/java/org/beetl/core/exception/TextParserException.java index 7663f58..7a4a30b 100644 --- a/src/main/java/org/beetl/core/exception/TextParserException.java +++ b/src/main/java/org/beetl/core/exception/TextParserException.java @@ -43,7 +43,7 @@ public class TextParserException extends BeetlException { * @param message 错误信息 */ public TextParserException(String message) { - super(BeetlException.ERROR, message); + super(BeetlErrorCode.Default.ERROR, message); } } diff --git a/src/main/java/org/beetl/core/fun/FileFunctionWrapper.java b/src/main/java/org/beetl/core/fun/FileFunctionWrapper.java index b98c842..b09569a 100644 --- a/src/main/java/org/beetl/core/fun/FileFunctionWrapper.java +++ b/src/main/java/org/beetl/core/fun/FileFunctionWrapper.java @@ -30,6 +30,7 @@ package org.beetl.core.fun; import org.beetl.core.Context; import org.beetl.core.Function; import org.beetl.core.Template; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; /** @@ -68,7 +69,7 @@ public class FileFunctionWrapper implements Function { } catch (BeetlException ex) { throw ex; } catch (Exception ex) { - throw new BeetlException(BeetlException.NATIVE_CALL_EXCEPTION, "调用方法出错 " + this.resourceId, ex); + throw new BeetlException(BeetlErrorCode.NativeCall.NATIVE_CALL_EXCEPTION, "调用方法出错 " + this.resourceId, ex); } } diff --git a/src/main/java/org/beetl/core/fun/GeneralGetMethodInvoker.java b/src/main/java/org/beetl/core/fun/GeneralGetMethodInvoker.java index 39d8ce3..374145a 100644 --- a/src/main/java/org/beetl/core/fun/GeneralGetMethodInvoker.java +++ b/src/main/java/org/beetl/core/fun/GeneralGetMethodInvoker.java @@ -3,6 +3,7 @@ package org.beetl.core.fun; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; public class GeneralGetMethodInvoker implements MethodInvoker { @@ -20,15 +21,15 @@ public class GeneralGetMethodInvoker implements MethodInvoker { try { return method.invoke(o, name); } catch (IllegalArgumentException e) { - throw new BeetlException(BeetlException.ATTRIBUTE_INVALID, "错误参数", e); + throw new BeetlException(BeetlErrorCode.Attribute.ATTRIBUTE_INVALID, "错误参数", e); } catch (IllegalAccessException e) { - throw new BeetlException(BeetlException.ATTRIBUTE_INVALID, "无法访问", e); + throw new BeetlException(BeetlErrorCode.Attribute.ATTRIBUTE_INVALID, "无法访问", e); } catch (InvocationTargetException e) { Throwable target = e.getTargetException(); if (target instanceof BeetlException) { throw (BeetlException) target; } - throw new BeetlException(BeetlException.ATTRIBUTE_INVALID, "属性访问异常", e.getTargetException()); + throw new BeetlException(BeetlErrorCode.Attribute.ATTRIBUTE_INVALID, "属性访问异常", e.getTargetException()); } } diff --git a/src/main/java/org/beetl/core/fun/MutipleFunctionWrapper.java b/src/main/java/org/beetl/core/fun/MutipleFunctionWrapper.java index 2b58307..bf4908e 100644 --- a/src/main/java/org/beetl/core/fun/MutipleFunctionWrapper.java +++ b/src/main/java/org/beetl/core/fun/MutipleFunctionWrapper.java @@ -33,6 +33,7 @@ import java.util.ArrayList; import java.util.List; import org.beetl.core.Context; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.misc.BeetlUtil; import org.beetl.core.om.ObjectMethodMatchConf; @@ -132,18 +133,18 @@ public class MutipleFunctionWrapper extends FunctionWrapper { } } catch (IllegalArgumentException e) { - throw new BeetlException(BeetlException.NATIVE_CALL_EXCEPTION, "参数不匹配 " + this.functionName, e); + throw new BeetlException(BeetlErrorCode.NativeCall.NATIVE_CALL_EXCEPTION, "参数不匹配 " + this.functionName, e); } catch (IllegalAccessException e) { - throw new BeetlException(BeetlException.NATIVE_CALL_EXCEPTION, "非法访问方法 " + this.functionName, e); + throw new BeetlException(BeetlErrorCode.NativeCall.NATIVE_CALL_EXCEPTION, "非法访问方法 " + this.functionName, e); } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (t instanceof BeetlException) { throw (BeetlException) t; } else { - throw new BeetlException(BeetlException.NATIVE_CALL_EXCEPTION, "调用方法出错 " + this.functionName, t); + throw new BeetlException(BeetlErrorCode.NativeCall.NATIVE_CALL_EXCEPTION, "调用方法出错 " + this.functionName, t); } } - throw new BeetlException(BeetlException.NATIVE_CALL_INVALID, + throw new BeetlException(BeetlErrorCode.NativeCall.NATIVE_CALL_INVALID, "找不到方法 " + this.functionName + BeetlUtil.getParameterDescription(parameterType)); } diff --git a/src/main/java/org/beetl/core/fun/ObjectUtil.java b/src/main/java/org/beetl/core/fun/ObjectUtil.java index a0c3bcc..d14d735 100644 --- a/src/main/java/org/beetl/core/fun/ObjectUtil.java +++ b/src/main/java/org/beetl/core/fun/ObjectUtil.java @@ -41,11 +41,6 @@ import static org.beetl.core.om.ObjectMethodMatchConf.VARIABLE_ARRAY; import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; import java.beans.BeanInfo; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -55,6 +50,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.exception.BeetlParserException; import org.beetl.core.misc.BeetlUtil; @@ -120,7 +116,7 @@ public class ObjectUtil { pd = propertyDescriptors(c); property = find(pd, name); } catch (IntrospectionException e) { - throw new BeetlException(BeetlException.ERROR, "获取类属性错", e); + throw new BeetlException(BeetlErrorCode.Default.ERROR, "获取类属性错", e); } if (property != null) { @@ -349,7 +345,7 @@ public class ObjectUtil { } ObjectMethodMatchConf mf = findMethod(target, methodName, parameterType); if (mf == null) { - throw new BeetlParserException(BeetlParserException.NATIVE_CALL_INVALID, "根据参数未找到匹配的方法" + methodName + BeetlUtil.getParameterDescription(parameterType)); + throw new BeetlParserException(BeetlErrorCode.NativeCall.NATIVE_CALL_INVALID, "根据参数未找到匹配的方法" + methodName + BeetlUtil.getParameterDescription(parameterType)); } return invoke(o, mf, paras); } @@ -378,7 +374,7 @@ public class ObjectUtil { if (o == null) { //check static if (!Modifier.isStatic(conf.method.getModifiers())) { - throw new BeetlException(BeetlException.NULL, "该方法是非静态方法,不能静态形式调用"); + throw new BeetlException(BeetlErrorCode.Default.NULL, "该方法是非静态方法,不能静态形式调用"); } } conf.method.setAccessible(true); diff --git a/src/main/java/org/beetl/core/fun/PojoMethodInvoker.java b/src/main/java/org/beetl/core/fun/PojoMethodInvoker.java index 277a294..07d55cc 100644 --- a/src/main/java/org/beetl/core/fun/PojoMethodInvoker.java +++ b/src/main/java/org/beetl/core/fun/PojoMethodInvoker.java @@ -4,6 +4,7 @@ import java.beans.PropertyDescriptor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; /** @@ -32,17 +33,17 @@ public class PojoMethodInvoker implements MethodInvoker { return readMethod.invoke(obj, null); } catch (IllegalArgumentException e) { - throw new BeetlException(BeetlException.ATTRIBUTE_INVALID, "错误参数", e); + throw new BeetlException(BeetlErrorCode.Attribute.ATTRIBUTE_INVALID, "错误参数", e); } catch (IllegalAccessException e) { - throw new BeetlException(BeetlException.ATTRIBUTE_INVALID, "无法访问", e); + throw new BeetlException(BeetlErrorCode.Attribute.ATTRIBUTE_INVALID, "无法访问", e); } catch (InvocationTargetException e) { Throwable target = e.getTargetException(); if (target instanceof BeetlException) { throw (BeetlException) target; } - throw new BeetlException(BeetlException.ATTRIBUTE_INVALID, "属性访问异常", e.getTargetException()); + throw new BeetlException(BeetlErrorCode.Attribute.ATTRIBUTE_INVALID, "属性访问异常", e.getTargetException()); } } @@ -62,15 +63,15 @@ public class PojoMethodInvoker implements MethodInvoker { try { pd.getWriteMethod().invoke(ins, value); } catch (IllegalAccessException e) { - throw new BeetlException(BeetlException.ATTRIBUTE_INVALID, "无法访问 " + pd, e); + throw new BeetlException(BeetlErrorCode.Attribute.ATTRIBUTE_INVALID, "无法访问 " + pd, e); } catch (IllegalArgumentException e) { - throw new BeetlException(BeetlException.ATTRIBUTE_INVALID, "错误参数 " + pd, e); + throw new BeetlException(BeetlErrorCode.Attribute.ATTRIBUTE_INVALID, "错误参数 " + pd, e); } catch (InvocationTargetException e) { Throwable target = e.getTargetException(); if (target instanceof BeetlException) { throw (BeetlException) target; } - throw new BeetlException(BeetlException.ATTRIBUTE_INVALID, "属性访问异常 " + pd, e.getTargetException()); + throw new BeetlException(BeetlErrorCode.Attribute.ATTRIBUTE_INVALID, "属性访问异常 " + pd, e.getTargetException()); } } diff --git a/src/main/java/org/beetl/core/fun/SingleFunctionWrapper.java b/src/main/java/org/beetl/core/fun/SingleFunctionWrapper.java index e77c97f..7a885a9 100644 --- a/src/main/java/org/beetl/core/fun/SingleFunctionWrapper.java +++ b/src/main/java/org/beetl/core/fun/SingleFunctionWrapper.java @@ -31,6 +31,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import org.beetl.core.Context; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; /** @@ -78,12 +79,12 @@ public class SingleFunctionWrapper extends FunctionWrapper { if (t instanceof BeetlException) { throw (BeetlException) t; } else { - throw new BeetlException(BeetlException.NATIVE_CALL_EXCEPTION, "调用方法出错 " + this.functionName, t); + throw new BeetlException(BeetlErrorCode.NativeCall.NATIVE_CALL_EXCEPTION, "调用方法出错 " + this.functionName, t); } } catch (BeetlException ex) { throw ex; } catch (Exception ex) { - throw new BeetlException(BeetlException.NATIVE_CALL_EXCEPTION, "调用方法出错 " + this.functionName, ex); + throw new BeetlException(BeetlErrorCode.NativeCall.NATIVE_CALL_EXCEPTION, "调用方法出错 " + this.functionName, ex); } } diff --git a/src/main/java/org/beetl/core/impl/resource/ClasspathResource.java b/src/main/java/org/beetl/core/impl/resource/ClasspathResource.java index c790566..b76d7ea 100644 --- a/src/main/java/org/beetl/core/impl/resource/ClasspathResource.java +++ b/src/main/java/org/beetl/core/impl/resource/ClasspathResource.java @@ -37,6 +37,7 @@ import java.io.UnsupportedEncodingException; import java.net.URL; import org.beetl.core.Resource; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.runtime.IResourceLoader; import org.beetl.core.exception.BeetlException; @@ -71,17 +72,17 @@ public class ClasspathResource extends Resource { } if (url == null) { - throw new BeetlException(BeetlException.TEMPLATE_LOAD_ERROR).pushResource(this); + throw new BeetlException(BeetlErrorCode.Template.TEMPLATE_LOAD_ERROR).pushResource(this); } InputStream is; try { is = url.openStream(); } catch (IOException e1) { - throw new BeetlException(BeetlException.TEMPLATE_LOAD_ERROR).pushResource(this); + throw new BeetlException(BeetlErrorCode.Template.TEMPLATE_LOAD_ERROR).pushResource(this); } if (is == null) { - throw new BeetlException(BeetlException.TEMPLATE_LOAD_ERROR).pushResource(this); + throw new BeetlException(BeetlErrorCode.Template.TEMPLATE_LOAD_ERROR).pushResource(this); } if (url.getProtocol().equals("file")) { diff --git a/src/main/java/org/beetl/core/impl/resource/CompositeResourceLoader.java b/src/main/java/org/beetl/core/impl/resource/CompositeResourceLoader.java index b368dc5..22fee4a 100644 --- a/src/main/java/org/beetl/core/impl/resource/CompositeResourceLoader.java +++ b/src/main/java/org/beetl/core/impl/resource/CompositeResourceLoader.java @@ -36,6 +36,7 @@ import java.util.Map; import org.beetl.core.GroupTemplate; import org.beetl.core.Resource; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.runtime.IResourceLoader; import org.beetl.core.exception.BeetlException; import org.beetl.core.runtime.IMatcher; @@ -172,7 +173,7 @@ public class CompositeResourceLoader implements IResourceLoader { @Override public Reader openReader() { - throw new BeetlException(BeetlException.TEMPLATE_LOAD_ERROR, "复合资源加载器未匹配路径:" + this.id) + throw new BeetlException(BeetlErrorCode.Template.TEMPLATE_LOAD_ERROR, "复合资源加载器未匹配路径:" + this.id) .pushResource(this); } diff --git a/src/main/java/org/beetl/core/impl/resource/FileResource.java b/src/main/java/org/beetl/core/impl/resource/FileResource.java index ea6f997..18a3029 100644 --- a/src/main/java/org/beetl/core/impl/resource/FileResource.java +++ b/src/main/java/org/beetl/core/impl/resource/FileResource.java @@ -9,6 +9,7 @@ import java.io.Reader; import java.io.UnsupportedEncodingException; import org.beetl.core.Resource; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.runtime.IResourceLoader; import org.beetl.core.exception.BeetlException; @@ -34,7 +35,7 @@ public class FileResource extends Resource { return null; } catch (FileNotFoundException e) { FileResourceLoader loader = (FileResourceLoader) this.resourceLoader; - BeetlException be = new BeetlException(BeetlException.TEMPLATE_LOAD_ERROR, " 模板根目录为 " + loader.getRoot()); + BeetlException be = new BeetlException(BeetlErrorCode.Template.TEMPLATE_LOAD_ERROR, " 模板根目录为 " + loader.getRoot()); be.pushResource(this); throw be; diff --git a/src/main/java/org/beetl/core/impl/resource/MapResourceLoader.java b/src/main/java/org/beetl/core/impl/resource/MapResourceLoader.java index fb13bcf..2967d51 100644 --- a/src/main/java/org/beetl/core/impl/resource/MapResourceLoader.java +++ b/src/main/java/org/beetl/core/impl/resource/MapResourceLoader.java @@ -6,6 +6,7 @@ import java.util.HashMap; import org.beetl.core.GroupTemplate; import org.beetl.core.Resource; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.runtime.IResourceLoader; import org.beetl.core.exception.BeetlException; @@ -41,7 +42,7 @@ public class MapResourceLoader extends HashMap implements IResou public Reader openReader() { String val = get(key); if (val == null) { - throw new BeetlException(BeetlException.TEMPLATE_LOAD_ERROR).pushResource(this); + throw new BeetlException(BeetlErrorCode.Template.TEMPLATE_LOAD_ERROR).pushResource(this); } return new StringReader(val); } diff --git a/src/main/java/org/beetl/core/misc/ALU.java b/src/main/java/org/beetl/core/misc/ALU.java index b42a14c..fffb76e 100644 --- a/src/main/java/org/beetl/core/misc/ALU.java +++ b/src/main/java/org/beetl/core/misc/ALU.java @@ -31,6 +31,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.math.BigDecimal; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.statement.ASTNode; import org.beetl.core.statement.GrammarToken; @@ -459,7 +460,7 @@ public class ALU { case SHORT: double c = ((Number) o2).doubleValue(); if (c == 0) { - throw new BeetlException(BeetlException.DIV_ZERO_ERROR).pushToken(node2.token); + throw new BeetlException(BeetlErrorCode.Default.DIV_ZERO_ERROR).pushToken(node2.token); } double a = ((Number) o1).doubleValue() / ((Number) o2).doubleValue(); return trim(a, (Number) o1, (Number) o2); @@ -741,7 +742,7 @@ public class ALU { } return result; } catch (RuntimeException e) { - throw new BeetlException(BeetlException.EXPRESSION_NOT_COMPATIBLE, e) + throw new BeetlException(BeetlErrorCode.Type.EXPRESSION_NOT_COMPATIBLE, e) .pushToken(GrammarToken.createToken(node1.token.text + " " + node2.token.text, node1.token.line)); } @@ -753,23 +754,23 @@ public class ALU { private static RuntimeException UnsupportedTypeException(final Object o1, final Object o2, final ASTNode node1, final ASTNode node2, String type) { String tagName = node1.token.text + type + node2.token.text; - throw new BeetlException(BeetlException.EXPRESSION_NOT_COMPATIBLE, o1.getClass() + type + o2.getClass()) + throw new BeetlException(BeetlErrorCode.Type.EXPRESSION_NOT_COMPATIBLE, o1.getClass() + type + o2.getClass()) .pushToken(GrammarToken.createToken(tagName, node1.token.line)); } private static RuntimeException numberExpectedException(final Object o1, ASTNode node1) { - throw new BeetlException(BeetlException.NUMBER_EXPECTED_ERROR).pushToken(node1.token); + throw new BeetlException(BeetlErrorCode.Type.NUMBER_EXPECTED_ERROR).pushToken(node1.token); } private static RuntimeException valueIsNullException(final Object o1, ASTNode node1) { - throw new BeetlException(BeetlException.NULL).pushToken(node1.token); + throw new BeetlException(BeetlErrorCode.Default.NULL).pushToken(node1.token); } private static BeetlException valueIsNullException(final Object o1, final Object o2, final ASTNode node1, final ASTNode node2) { throw o1 == null - ? new BeetlException(BeetlException.NULL).pushToken(node1.token) - : new BeetlException(BeetlException.NULL).pushToken(node2.token); + ? new BeetlException(BeetlErrorCode.Default.NULL).pushToken(node1.token) + : new BeetlException(BeetlErrorCode.Default.NULL).pushToken(node2.token); } private static BigDecimal getBigDecimal(Object o) { @@ -781,7 +782,7 @@ public class ALU { */ public static Boolean isTrue(final Object o, ASTNode node) { if (o == null) { - throw new BeetlException(BeetlException.NULL).pushToken(node.token); + throw new BeetlException(BeetlErrorCode.Default.NULL).pushToken(node.token); } if (Boolean.TRUE == o) { @@ -791,7 +792,7 @@ public class ALU { } else if (o instanceof Boolean) { return ((Boolean) o); } else { - throw new BeetlException(BeetlException.BOOLEAN_EXPECTED_ERROR, o.getClass().toString()) + throw new BeetlException(BeetlErrorCode.Type.BOOLEAN_EXPECTED_ERROR, o.getClass().toString()) .pushToken(node.token); } } diff --git a/src/main/java/org/beetl/core/om/ArrayAA.java b/src/main/java/org/beetl/core/om/ArrayAA.java index 36ccac0..b36f2df 100644 --- a/src/main/java/org/beetl/core/om/ArrayAA.java +++ b/src/main/java/org/beetl/core/om/ArrayAA.java @@ -28,6 +28,7 @@ package org.beetl.core.om; import org.beetl.android.util.Pair; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.misc.PrimitiveArrayUtil; @@ -46,7 +47,7 @@ public class ArrayAA extends AttributeAccess { ? PrimitiveArrayUtil.getObject(o, indexCheckResult.second) : ((Object[]) o)[indexCheckResult.second]; } - throw new BeetlException(BeetlException.ARRAY_INDEX_ERROR, + throw new BeetlException(BeetlErrorCode.Array.ARRAY_INDEX_ERROR, "该对象是数组,期望是整型或者BigDecimal类型, 如果对象是动态的,需要directive dynamic "); } diff --git a/src/main/java/org/beetl/core/om/AttributeAccess.java b/src/main/java/org/beetl/core/om/AttributeAccess.java index 1a72710..256d68c 100644 --- a/src/main/java/org/beetl/core/om/AttributeAccess.java +++ b/src/main/java/org/beetl/core/om/AttributeAccess.java @@ -28,6 +28,7 @@ package org.beetl.core.om; import org.beetl.android.util.Pair; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.fun.MethodInvoker; import org.beetl.core.fun.ObjectUtil; @@ -67,7 +68,7 @@ public abstract class AttributeAccess implements java.io.Serializable { try { ((List) o).set(((Number) k).intValue(), v); } catch (IndexOutOfBoundsException ex) { - throw new BeetlException(BeetlException.ATTRIBUTE_INVALID, ex); + throw new BeetlException(BeetlErrorCode.Attribute.ATTRIBUTE_INVALID, ex); } catch (ClassCastException ex) { throw new ClassCastException("目标无法强转成 java.util.List,无法设置属性:" + k); } @@ -89,8 +90,8 @@ public abstract class AttributeAccess implements java.io.Serializable { invoker.set(o, v); } else { throw new BeetlException(ObjectUtil.hasPrivateAttribute(objType, keyStr) - ? BeetlException.ATTRIBUTE_NOT_FOUND_PRIVATE - : BeetlException.ATTRIBUTE_NOT_FOUND, keyStr); + ? BeetlErrorCode.Attribute.ATTRIBUTE_NOT_FOUND_PRIVATE + : BeetlErrorCode.Attribute.ATTRIBUTE_NOT_FOUND, keyStr); } } } @@ -111,7 +112,7 @@ public abstract class AttributeAccess implements java.io.Serializable { || attr instanceof BigDecimal) { int index = ((Number) attr).intValue(); if (index < 0) { - throw new BeetlException(BeetlException.ARRAY_INDEX_ERROR, "索引必须大于或者等于"); + throw new BeetlException(BeetlErrorCode.Array.ARRAY_INDEX_ERROR, "索引必须大于或者等于"); } return new Pair<>(true, index); } diff --git a/src/main/java/org/beetl/core/om/ListAA.java b/src/main/java/org/beetl/core/om/ListAA.java index c0268b8..9f5d047 100644 --- a/src/main/java/org/beetl/core/om/ListAA.java +++ b/src/main/java/org/beetl/core/om/ListAA.java @@ -27,10 +27,10 @@ */ package org.beetl.core.om; -import java.math.BigDecimal; import java.util.List; import org.beetl.android.util.Pair; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; /** @@ -46,7 +46,7 @@ public class ListAA extends AttributeAccess { if (indexCheckResult.first) { return ((List) o).get(indexCheckResult.second); } - throw new BeetlException(BeetlException.ARRAY_INDEX_ERROR, "期望是整型或者是BigDecimal类型"); + throw new BeetlException(BeetlErrorCode.Array.ARRAY_INDEX_ERROR, "期望是整型或者是BigDecimal类型"); } } diff --git a/src/main/java/org/beetl/core/om/ReflectBeanAA.java b/src/main/java/org/beetl/core/om/ReflectBeanAA.java index c6e6e20..26ae7c2 100644 --- a/src/main/java/org/beetl/core/om/ReflectBeanAA.java +++ b/src/main/java/org/beetl/core/om/ReflectBeanAA.java @@ -1,5 +1,6 @@ package org.beetl.core.om; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.fun.MethodInvoker; import org.beetl.core.fun.ObjectUtil; @@ -25,7 +26,7 @@ public class ReflectBeanAA extends AttributeAccess { MethodInvoker mi = ObjectUtil.getInvokder(c, key); if (mi == null) { throw new BeetlException(ObjectUtil.hasPrivateAttribute(c, key) - ? BeetlException.ATTRIBUTE_NOT_FOUND_PRIVATE : BeetlException.ATTRIBUTE_NOT_FOUND, key); + ? BeetlErrorCode.Attribute.ATTRIBUTE_NOT_FOUND_PRIVATE : BeetlErrorCode.Attribute.ATTRIBUTE_NOT_FOUND, key); } return mi.get(o); } diff --git a/src/main/java/org/beetl/core/om/asm/BeanEnhanceUtils.java b/src/main/java/org/beetl/core/om/asm/BeanEnhanceUtils.java index 714dbec..6c80181 100644 --- a/src/main/java/org/beetl/core/om/asm/BeanEnhanceUtils.java +++ b/src/main/java/org/beetl/core/om/asm/BeanEnhanceUtils.java @@ -15,6 +15,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.ow2.asm.ClassReader; import org.beetl.ow2.asm.Type; @@ -62,7 +63,7 @@ final class BeanEnhanceUtils implements Constants { classDesc.generalGetMethodDesc = getGeneralGetMethodDescription(beanClass); classDesc.hasField = !classDesc.fieldDescMap.isEmpty(); } catch (IOException | IntrospectionException e) { - throw new BeetlException(BeetlException.ERROR, "ASM增强功能,生成类:" + beanClass.getName() + "时发生错误", e); + throw new BeetlException(BeetlErrorCode.Default.ERROR, "ASM增强功能,生成类:" + beanClass.getName() + "时发生错误", e); } finally { try { if (in != null) { diff --git a/src/main/java/org/beetl/core/parser/BeetlAntlrErrorStrategy.java b/src/main/java/org/beetl/core/parser/BeetlAntlrErrorStrategy.java index 09134da..1c3ae1a 100644 --- a/src/main/java/org/beetl/core/parser/BeetlAntlrErrorStrategy.java +++ b/src/main/java/org/beetl/core/parser/BeetlAntlrErrorStrategy.java @@ -35,11 +35,11 @@ import org.antlr.v4.runtime.DefaultErrorStrategy; import org.antlr.v4.runtime.FailedPredicateException; import org.antlr.v4.runtime.InputMismatchException; import org.antlr.v4.runtime.NoViableAltException; -import org.antlr.v4.runtime.Parser; import org.antlr.v4.runtime.RecognitionException; import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.TokenStream; import org.antlr.v4.runtime.misc.IntervalSet; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.exception.BeetlParserException; import org.beetl.core.statement.GrammarToken; @@ -81,13 +81,13 @@ public class BeetlAntlrErrorStrategy extends DefaultErrorStrategy { } @Override - public void recover(Parser recognizer, RecognitionException e) { + public void recover(org.antlr.v4.runtime.Parser recognizer, RecognitionException e) { //不会执行到此处,因为在report部分就抛出异常了 super.recover(recognizer, e); } @Override - public void reportError(Parser recognizer, RecognitionException e) { + public void reportError(org.antlr.v4.runtime.Parser recognizer, RecognitionException e) { // if we've already reported an error and have not matched a token // yet successfully, don't report any errors. if (inErrorRecoveryMode(recognizer)) { @@ -102,13 +102,13 @@ public class BeetlAntlrErrorStrategy extends DefaultErrorStrategy { } else if (e instanceof FailedPredicateException) { reportFailedPredicate(recognizer, (FailedPredicateException) e); } else { - throw new BeetlException(BeetlException.PARSER_UNKNOW_ERROR, e.getClass().getName(), e) + throw new BeetlException(BeetlErrorCode.Parser.PARSER_UNKNOW_ERROR, e.getClass().getName(), e) .pushToken(this.getGrammarToken(e.getOffendingToken())); } } - protected void reportNoViableAlternative(Parser recognizer, NoViableAltException e) { + protected void reportNoViableAlternative(org.antlr.v4.runtime.Parser recognizer, NoViableAltException e) { TokenStream tokens = recognizer.getInputStream(); String input = tokens == null ? "<未知输入>" : e.getStartToken().getType() == Token.EOF ? "<文件尾>" @@ -116,28 +116,28 @@ public class BeetlAntlrErrorStrategy extends DefaultErrorStrategy { String msg = keys.contains(e.getOffendingToken().getText()) ? "不允许" + e.getOffendingToken().getText() + "关键出现在这里" + ":" + escapeWSAndQuote(input) : escapeWSAndQuote(input); - throw new BeetlParserException(BeetlException.PARSER_VIABLE_ERROR, msg, e) + throw new BeetlParserException(BeetlErrorCode.Parser.PARSER_VIABLE_ERROR, msg, e) .pushToken(this.getGrammarToken(e.getOffendingToken())); } - protected void reportInputMismatch(Parser recognizer, InputMismatchException e) { + protected void reportInputMismatch(org.antlr.v4.runtime.Parser recognizer, InputMismatchException e) { Token t1 = recognizer.getInputStream().LT(-1); String msg = "缺少输入在 " + getTokenErrorDisplay(t1) + " 后面, 期望 " + e.getExpectedTokens().toString(recognizer.getVocabulary()); - throw new BeetlParserException(BeetlException.PARSER_MISS_ERROR, msg, e) + throw new BeetlParserException(BeetlErrorCode.Parser.PARSER_MISS_ERROR, msg, e) .pushToken(this.getGrammarToken(t1)); } - protected void reportFailedPredicate(Parser recognizer, FailedPredicateException e) { + protected void reportFailedPredicate(org.antlr.v4.runtime.Parser recognizer, FailedPredicateException e) { String ruleName = recognizer.getRuleNames()[recognizer.getContext().getRuleIndex()]; - throw new BeetlParserException(BeetlException.PARSER_PREDICATE_ERROR, ruleName, e) + throw new BeetlParserException(BeetlErrorCode.Parser.PARSER_PREDICATE_ERROR, ruleName, e) .pushToken(this.getGrammarToken(e.getOffendingToken())); } /** Make sure we don't attempt to recover from problems in subrules. */ @Override - public void sync(Parser recognizer) { + public void sync(org.antlr.v4.runtime.Parser recognizer) { } /** @@ -145,7 +145,7 @@ public class BeetlAntlrErrorStrategy extends DefaultErrorStrategy { * successfully recovers, it won't throw an exception. */ @Override - public Token recoverInline(Parser recognizer) throws RecognitionException { + public Token recoverInline(org.antlr.v4.runtime.Parser recognizer) throws RecognitionException { // SINGLE TOKEN DELETION Token matchedSymbol = singleTokenDeletion(recognizer); if (matchedSymbol != null) { @@ -166,7 +166,7 @@ public class BeetlAntlrErrorStrategy extends DefaultErrorStrategy { throw new InputMismatchException(recognizer); } - protected void reportMissingToken(Parser recognizer) { + protected void reportMissingToken(org.antlr.v4.runtime.Parser recognizer) { if (inErrorRecoveryMode(recognizer)) { return; } @@ -191,10 +191,10 @@ public class BeetlAntlrErrorStrategy extends DefaultErrorStrategy { //常规情况 msg = "缺少输入 " + expect + " 在 " + tokenStr + " 后面"; } - throw new BeetlParserException(BeetlException.PARSER_MISS_ERROR, msg).pushToken(this.getGrammarToken(t)); + throw new BeetlParserException(BeetlErrorCode.Parser.PARSER_MISS_ERROR, msg).pushToken(this.getGrammarToken(t)); } - protected void reportUnwantedToken(Parser recognizer) { + protected void reportUnwantedToken(org.antlr.v4.runtime.Parser recognizer) { if (inErrorRecoveryMode(recognizer)) { return; } @@ -206,7 +206,7 @@ public class BeetlAntlrErrorStrategy extends DefaultErrorStrategy { IntervalSet expecting = getExpectedTokens(recognizer); String key = getErrorKey(expecting.toString(recognizer.getVocabulary())); String msg = "多余输入 " + tokenName + " 期望 " + key; - throw new BeetlParserException(BeetlException.PARSER_MISS_ERROR, msg).pushToken(this.getGrammarToken(t)); + throw new BeetlParserException(BeetlErrorCode.Parser.PARSER_MISS_ERROR, msg).pushToken(this.getGrammarToken(t)); } protected String getErrorKey(String key) { diff --git a/src/main/java/org/beetl/core/parser/SyntaxErrorListener.java b/src/main/java/org/beetl/core/parser/SyntaxErrorListener.java index 00a2ddb..4e2be6b 100644 --- a/src/main/java/org/beetl/core/parser/SyntaxErrorListener.java +++ b/src/main/java/org/beetl/core/parser/SyntaxErrorListener.java @@ -3,6 +3,7 @@ package org.beetl.core.parser; import org.antlr.v4.runtime.BaseErrorListener; import org.antlr.v4.runtime.RecognitionException; import org.antlr.v4.runtime.Recognizer; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.misc.BeetlUtil; import org.beetl.core.statement.GrammarToken; @@ -10,7 +11,7 @@ import org.beetl.core.statement.GrammarToken; public class SyntaxErrorListener extends BaseErrorListener { public void syntaxError(Recognizer recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { - throw new BeetlException(BeetlException.TOKEN_ERROR) + throw new BeetlException(BeetlErrorCode.Grammar.TOKEN_ERROR) .setToken(new GrammarToken(BeetlUtil.reportChineseTokenError(msg), line, charPositionInLine)); } } diff --git a/src/main/java/org/beetl/core/statement/ForStatement.java b/src/main/java/org/beetl/core/statement/ForStatement.java index dc81940..e68231b 100644 --- a/src/main/java/org/beetl/core/statement/ForStatement.java +++ b/src/main/java/org/beetl/core/statement/ForStatement.java @@ -32,6 +32,7 @@ import java.util.Collections; import org.beetl.core.Context; import org.beetl.core.GeneralLoopStatus; import org.beetl.core.ILoopStatus; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.exception.BeetlParserException; @@ -70,7 +71,7 @@ public final class ForStatement extends Statement implements IGoto { ILoopStatus it = null; if (collection == null) { if (!(this.hasSafe || ctx.safeOutput)) { - throw new BeetlException(BeetlException.NULL).pushToken(exp.token); + throw new BeetlException(BeetlErrorCode.Default.NULL).pushToken(exp.token); } else { it = new GeneralLoopStatus(Collections.EMPTY_LIST); } @@ -78,7 +79,7 @@ public final class ForStatement extends Statement implements IGoto { } else { it = GeneralLoopStatus.getIteratorStatus(collection); if (it == null) { - throw new BeetlParserException(BeetlParserException.COLLECTION_EXPECTED_ERROR, + throw new BeetlParserException(BeetlErrorCode.Type.COLLECTION_EXPECTED_ERROR, "实际类型是:" + collection.getClass()) .pushToken(exp.token); } diff --git a/src/main/java/org/beetl/core/statement/FormatExpression.java b/src/main/java/org/beetl/core/statement/FormatExpression.java index 48405fa..855f534 100644 --- a/src/main/java/org/beetl/core/statement/FormatExpression.java +++ b/src/main/java/org/beetl/core/statement/FormatExpression.java @@ -30,6 +30,7 @@ package org.beetl.core.statement; import org.beetl.core.Context; import org.beetl.core.ContextFormat; import org.beetl.core.Format; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; /** @@ -66,14 +67,14 @@ public class FormatExpression extends Expression { } if (format == null) { - throw new BeetlException(BeetlException.FORMAT_NOT_FOUND).pushToken(token); + throw new BeetlException(BeetlErrorCode.Format.FORMAT_NOT_FOUND).pushToken(token); } try { return format instanceof ContextFormat ? ((ContextFormat) format).format(o, pattern, ctx) : format.format(o, pattern); } catch (Exception e) { - throw new BeetlException(BeetlException.NATIVE_CALL_EXCEPTION, "调用格式化函数抛出异常", e) + throw new BeetlException(BeetlErrorCode.NativeCall.NATIVE_CALL_EXCEPTION, "调用格式化函数抛出异常", e) .pushToken(token); } } diff --git a/src/main/java/org/beetl/core/statement/FunctionExpression.java b/src/main/java/org/beetl/core/statement/FunctionExpression.java index 866ed94..0517c6c 100644 --- a/src/main/java/org/beetl/core/statement/FunctionExpression.java +++ b/src/main/java/org/beetl/core/statement/FunctionExpression.java @@ -33,6 +33,7 @@ import org.beetl.core.Context; import org.beetl.core.Function; import org.beetl.core.GroupTemplate; import org.beetl.core.Resource; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.fun.FileFunctionWrapper; @@ -67,7 +68,7 @@ public class FunctionExpression extends Expression { if (resource != null && resource.getResourceLoader().exist(resource.getId())) { fn = new FileFunctionWrapper(resource.getId().toString()); } else { - throw new BeetlException(BeetlException.FUNCTION_NOT_FOUND).pushToken(token); + throw new BeetlException(BeetlErrorCode.Function.FUNCTION_NOT_FOUND).pushToken(token); } } @@ -81,7 +82,7 @@ public class FunctionExpression extends Expression { } catch (BeetlException ex) { throw ex.pushToken(token); } catch (RuntimeException ex) { - throw new BeetlException(BeetlException.NATIVE_CALL_EXCEPTION, "调用方法出错 " + name, ex) + throw new BeetlException(BeetlErrorCode.NativeCall.NATIVE_CALL_EXCEPTION, "调用方法出错 " + name, ex) .pushToken(this.token); } @@ -93,14 +94,14 @@ public class FunctionExpression extends Expression { } catch (BeetlException ex) { throw ex.pushToken(attr.token); } catch (RuntimeException ex) { - throw new BeetlException(BeetlException.ATTRIBUTE_INVALID, "属性访问出错", ex).pushToken(attr.token); + throw new BeetlException(BeetlErrorCode.Attribute.ATTRIBUTE_INVALID, "属性访问出错", ex).pushToken(attr.token); } if (value == null) { if (hasSafe) { return safeExp == null ? null : safeExp.evaluate(ctx); } else { - throw new BeetlException(BeetlException.ERROR, "空指针 ").pushToken(attr.token); + throw new BeetlException(BeetlErrorCode.Default.ERROR, "空指针 ").pushToken(attr.token); } } diff --git a/src/main/java/org/beetl/core/statement/GeneralForStatement.java b/src/main/java/org/beetl/core/statement/GeneralForStatement.java index 2965065..e415213 100644 --- a/src/main/java/org/beetl/core/statement/GeneralForStatement.java +++ b/src/main/java/org/beetl/core/statement/GeneralForStatement.java @@ -28,6 +28,7 @@ package org.beetl.core.statement; import org.beetl.core.Context; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; /** @@ -87,7 +88,7 @@ public class GeneralForStatement extends Statement implements IGoto { if (val instanceof Boolean) { bool = ((Boolean) val).booleanValue(); } else { - BeetlException be = new BeetlException(BeetlException.BOOLEAN_EXPECTED_ERROR); + BeetlException be = new BeetlException(BeetlErrorCode.Type.BOOLEAN_EXPECTED_ERROR); be.pushToken(condition.token); throw be; } diff --git a/src/main/java/org/beetl/core/statement/NativeCallExpression.java b/src/main/java/org/beetl/core/statement/NativeCallExpression.java index 6e8f829..50b0610 100644 --- a/src/main/java/org/beetl/core/statement/NativeCallExpression.java +++ b/src/main/java/org/beetl/core/statement/NativeCallExpression.java @@ -5,9 +5,9 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Modifier; import org.beetl.core.Context; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.runtime.INativeSecurityManager; import org.beetl.core.exception.BeetlException; -import org.beetl.core.exception.BeetlParserException; import org.beetl.core.misc.BeetlUtil; import org.beetl.core.om.ObjectMethodMatchConf; import org.beetl.core.fun.ObjectUtil; @@ -56,7 +56,7 @@ public class NativeCallExpression extends Expression { } else { targetCls = ctx.gt.loadClassBySimpleName(this.clsNode.clazz); if (targetCls == null) { - throw new BeetlException(BeetlException.NATIVE_CALL_EXCEPTION, "该类不存在") + throw new BeetlException(BeetlErrorCode.NativeCall.NATIVE_CALL_EXCEPTION, "该类不存在") .pushToken(GrammarToken.createToken(clsNode.clazz, token.line)); } lastNode = clsNode; @@ -76,13 +76,13 @@ public class NativeCallExpression extends Expression { targetObj = f.get(targetObj); targetCls = f.getType(); } catch (SecurityException e) { - throw new BeetlException(BeetlException.NATIVE_CALL_EXCEPTION, "不能调用属性", e) + throw new BeetlException(BeetlErrorCode.NativeCall.NATIVE_CALL_EXCEPTION, "不能调用属性", e) .pushToken(GrammarToken.createToken(attr, token.line)); } catch (NoSuchFieldException e) { - throw new BeetlException(BeetlException.NATIVE_CALL_EXCEPTION, "无此属性", e) + throw new BeetlException(BeetlErrorCode.NativeCall.NATIVE_CALL_EXCEPTION, "无此属性", e) .pushToken(GrammarToken.createToken(attr, token.line)); } catch (IllegalArgumentException | IllegalAccessException e) { - throw new BeetlException(BeetlException.NATIVE_CALL_EXCEPTION, "访问属性出错", e) + throw new BeetlException(BeetlErrorCode.NativeCall.NATIVE_CALL_EXCEPTION, "访问属性出错", e) .pushToken(GrammarToken.createToken(attr, token.line)); } @@ -90,7 +90,7 @@ public class NativeCallExpression extends Expression { checkNull(targetCls, lastNode); if (!targetCls.isArray()) { // 最好是把上一个字符显示出来 - throw new BeetlException(BeetlException.ARRAY_TYPE_ERROR) + throw new BeetlException(BeetlErrorCode.Array.ARRAY_TYPE_ERROR) .pushToken(GrammarToken.createToken("[]", token.line)); } Expression exp = ((NativeArrayNode) node).exp; @@ -100,7 +100,7 @@ public class NativeCallExpression extends Expression { targetObj = ((Object[]) targetObj)[index]; targetCls = targetObj == null ? null : targetObj.getClass(); // todo or component of array } else { - throw new BeetlException(BeetlException.ARRAY_INDEX_ERROR, "数组指针必须是Number类型") + throw new BeetlException(BeetlErrorCode.Array.ARRAY_INDEX_ERROR, "数组指针必须是Number类型") .pushToken(GrammarToken.createToken("[]", token.line)); } } else if (node instanceof NativeMethodNode) { @@ -118,13 +118,13 @@ public class NativeCallExpression extends Expression { this.checkNull(targetCls, lastNode); ObjectMethodMatchConf mf = ObjectUtil.findMethod(targetCls, method, parameterType); if (mf == null) { - throw new BeetlException(BeetlParserException.NATIVE_CALL_INVALID, + throw new BeetlException(BeetlErrorCode.NativeCall.NATIVE_CALL_INVALID, "根据参数未找到匹配的方法" + method + BeetlUtil.getParameterDescription(parameterType)) .pushToken(GrammarToken.createToken(token.text, token.line)); } if (targetObj == null && !Modifier.isStatic(mf.method.getModifiers())) { - throw new BeetlException(BeetlException.NULL) + throw new BeetlException(BeetlErrorCode.Default.NULL) .pushToken(GrammarToken.createToken(token.text, token.line)); } @@ -132,16 +132,16 @@ public class NativeCallExpression extends Expression { targetObj = ObjectUtil.invoke(targetObj, mf, args); targetCls = targetObj == null ? null : targetObj.getClass(); } catch (SecurityException e) { - throw new BeetlException(BeetlException.NATIVE_CALL_EXCEPTION, "不能调用方法", e) + throw new BeetlException(BeetlErrorCode.NativeCall.NATIVE_CALL_EXCEPTION, "不能调用方法", e) .pushToken(GrammarToken.createToken(method, token.line)); } catch (IllegalArgumentException e) { - throw new BeetlException(BeetlException.NATIVE_CALL_EXCEPTION, "错误的参数", e) + throw new BeetlException(BeetlErrorCode.NativeCall.NATIVE_CALL_EXCEPTION, "错误的参数", e) .pushToken(GrammarToken.createToken(method, token.line)); } catch (IllegalAccessException e) { - throw new BeetlException(BeetlException.NATIVE_CALL_EXCEPTION, "无法访问方法", e) + throw new BeetlException(BeetlErrorCode.NativeCall.NATIVE_CALL_EXCEPTION, "无法访问方法", e) .pushToken(GrammarToken.createToken(method, token.line)); } catch (InvocationTargetException e) { - throw new BeetlException(BeetlException.NATIVE_CALL_EXCEPTION, "内部调用报错", e.getTargetException()) + throw new BeetlException(BeetlErrorCode.NativeCall.NATIVE_CALL_EXCEPTION, "内部调用报错", e.getTargetException()) .pushToken(GrammarToken.createToken(method, token.line)); } @@ -155,7 +155,7 @@ public class NativeCallExpression extends Expression { private void checkNull(Object o, NativeNode node) { if (o == null) { - throw new BeetlException(BeetlException.NULL) + throw new BeetlException(BeetlErrorCode.Default.NULL) .pushToken(GrammarToken.createToken(node.getName(), token.line)); } } @@ -169,7 +169,7 @@ public class NativeCallExpression extends Expression { return; } if (!securityManager.permit(ctx.template.program.res.getId(), targetCls, targetObj, method)) { - throw new BeetlException(BeetlException.NATIVE_SECUARITY_EXCEPTION) + throw new BeetlException(BeetlErrorCode.NativeCall.NATIVE_SECURITY_EXCEPTION) .pushToken(GrammarToken.createToken(method, token.line)); } } diff --git a/src/main/java/org/beetl/core/statement/PlaceholderST.java b/src/main/java/org/beetl/core/statement/PlaceholderST.java index 19c2245..ae2e258 100644 --- a/src/main/java/org/beetl/core/statement/PlaceholderST.java +++ b/src/main/java/org/beetl/core/statement/PlaceholderST.java @@ -3,6 +3,7 @@ package org.beetl.core.statement; import java.io.IOException; import org.beetl.core.Context; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; /** @@ -66,7 +67,7 @@ public class PlaceholderST extends Statement { } // ctx.byteWriter.writeObject(value); } catch (IOException e) { - BeetlException be = new BeetlException(BeetlException.CLIENT_IO_ERROR_ERROR, e.getMessage(), e); + BeetlException be = new BeetlException(BeetlErrorCode.IO.CLIENT_IO_ERROR_ERROR, e.getMessage(), e); be.pushToken(this.token); throw be; } diff --git a/src/main/java/org/beetl/core/statement/ProgramMetaData.java b/src/main/java/org/beetl/core/statement/ProgramMetaData.java index 376dd05..185d8e7 100644 --- a/src/main/java/org/beetl/core/statement/ProgramMetaData.java +++ b/src/main/java/org/beetl/core/statement/ProgramMetaData.java @@ -32,6 +32,7 @@ import java.util.Map; import java.util.Map.Entry; import org.beetl.core.Context; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; /** @@ -148,7 +149,7 @@ public class ProgramMetaData implements java.io.Serializable { public AjaxStatement getAjax(String anchor) { if (ajaxs == null) { - BeetlException be = new BeetlException(BeetlException.AJAX_NOT_FOUND, "该模板文件没有发现任何ajax锚点"); + BeetlException be = new BeetlException(BeetlErrorCode.Ajax.AJAX_NOT_FOUND, "该模板文件没有发现任何ajax锚点"); be.pushToken(new GrammarToken(anchor, 0, 0)); throw be; } diff --git a/src/main/java/org/beetl/core/statement/SelectStatement.java b/src/main/java/org/beetl/core/statement/SelectStatement.java index c91b0ff..e3dc89a 100644 --- a/src/main/java/org/beetl/core/statement/SelectStatement.java +++ b/src/main/java/org/beetl/core/statement/SelectStatement.java @@ -28,6 +28,7 @@ package org.beetl.core.statement; import org.beetl.core.Context; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.misc.ALU; @@ -58,7 +59,7 @@ public class SelectStatement extends Statement { if (value != null) { base = value.evaluate(ctx); if (base == null) { - BeetlException ex = new BeetlException(BeetlException.NULL); + BeetlException ex = new BeetlException(BeetlErrorCode.Default.NULL); ex.pushToken(value.token); throw ex; } @@ -74,7 +75,7 @@ public class SelectStatement extends Statement { if (condValue instanceof Boolean) { isMatch = (Boolean) condValue; } else { - BeetlException be = new BeetlException(BeetlException.BOOLEAN_EXPECTED_ERROR); + BeetlException be = new BeetlException(BeetlErrorCode.Type.BOOLEAN_EXPECTED_ERROR); be.pushToken(exp.token); throw be; } diff --git a/src/main/java/org/beetl/core/statement/StaticTextASTNode.java b/src/main/java/org/beetl/core/statement/StaticTextASTNode.java index 2c4bef6..3706f92 100644 --- a/src/main/java/org/beetl/core/statement/StaticTextASTNode.java +++ b/src/main/java/org/beetl/core/statement/StaticTextASTNode.java @@ -30,6 +30,7 @@ package org.beetl.core.statement; import java.io.IOException; import org.beetl.core.Context; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; /** @@ -52,7 +53,7 @@ public final class StaticTextASTNode extends Statement { ctx.beetlWriter.write((char[]) ctx.staticTextArray[textIndex]); } catch (IOException ex) { - BeetlException be = new BeetlException(BeetlException.CLIENT_IO_ERROR_ERROR, "Client IO Error", ex); + BeetlException be = new BeetlException(BeetlErrorCode.IO.CLIENT_IO_ERROR_ERROR, "Client IO Error", ex); be.pushToken(this.token); throw be; } diff --git a/src/main/java/org/beetl/core/statement/StaticTextByteASTNode.java b/src/main/java/org/beetl/core/statement/StaticTextByteASTNode.java index 0a4ba27..a23181a 100644 --- a/src/main/java/org/beetl/core/statement/StaticTextByteASTNode.java +++ b/src/main/java/org/beetl/core/statement/StaticTextByteASTNode.java @@ -30,6 +30,7 @@ package org.beetl.core.statement; import java.io.IOException; import org.beetl.core.Context; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; /** @@ -51,7 +52,7 @@ public final class StaticTextByteASTNode extends Statement { try { ctx.beetlWriter.write((byte[]) ctx.staticTextArray[textIndex]); } catch (IOException ex) { - BeetlException be = new BeetlException(BeetlException.CLIENT_IO_ERROR_ERROR, "Client IO Error", ex); + BeetlException be = new BeetlException(BeetlErrorCode.IO.CLIENT_IO_ERROR_ERROR, "Client IO Error", ex); be.pushToken(this.token); throw be; } diff --git a/src/main/java/org/beetl/core/statement/SwitchStatement.java b/src/main/java/org/beetl/core/statement/SwitchStatement.java index 1e954bb..acfa79c 100644 --- a/src/main/java/org/beetl/core/statement/SwitchStatement.java +++ b/src/main/java/org/beetl/core/statement/SwitchStatement.java @@ -30,6 +30,7 @@ package org.beetl.core.statement; import java.util.LinkedHashMap; import org.beetl.core.Context; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.misc.ALU; @@ -61,7 +62,7 @@ public class SwitchStatement extends Statement { public void execute(Context ctx) { Object o = value.evaluate(ctx); if (o == null) { - BeetlException ex = new BeetlException(BeetlException.NULL); + BeetlException ex = new BeetlException(BeetlErrorCode.Default.NULL); ex.pushToken(value.token); throw ex; } diff --git a/src/main/java/org/beetl/core/statement/TagStatement.java b/src/main/java/org/beetl/core/statement/TagStatement.java index fba811a..895391b 100644 --- a/src/main/java/org/beetl/core/statement/TagStatement.java +++ b/src/main/java/org/beetl/core/statement/TagStatement.java @@ -28,6 +28,7 @@ package org.beetl.core.statement; import org.beetl.core.Context; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.fun.ObjectUtil; import org.beetl.core.tag.Tag; @@ -82,7 +83,7 @@ public class TagStatement extends Statement { } throw ex; } catch (RuntimeException ex) { - BeetlException bex = new BeetlException(BeetlException.TAG_INSTANCE_ERROR, ex.getMessage(), ex); + BeetlException bex = new BeetlException(BeetlErrorCode.Tag.TAG_INSTANCE_ERROR, ex.getMessage(), ex); bex.pushToken(token); throw bex; } @@ -98,7 +99,7 @@ public class TagStatement extends Statement { // BeetlException异常时不要设置token,因为抛出的地方已经设置了 throw ex; } catch (RuntimeException ex) { - BeetlException be = new BeetlException(BeetlException.ERROR, "tag执行抛错", ex); + BeetlException be = new BeetlException(BeetlErrorCode.Default.ERROR, "tag执行抛错", ex); be.pushToken(token); throw be; } diff --git a/src/main/java/org/beetl/core/statement/TagVarBindingStatement.java b/src/main/java/org/beetl/core/statement/TagVarBindingStatement.java index 9c74d42..c49d281 100644 --- a/src/main/java/org/beetl/core/statement/TagVarBindingStatement.java +++ b/src/main/java/org/beetl/core/statement/TagVarBindingStatement.java @@ -3,6 +3,7 @@ package org.beetl.core.statement; import java.util.LinkedHashMap; import org.beetl.core.Context; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.tag.HTMLTagVarBindingWrapper; import org.beetl.core.tag.Tag; @@ -22,7 +23,7 @@ public class TagVarBindingStatement extends TagStatement { try { if (!(tag instanceof HTMLTagVarBindingWrapper)) { - BeetlException be = new BeetlException(BeetlException.ERROR, "tag必须是HTMLTagVarBindingWrapper"); + BeetlException be = new BeetlException(BeetlErrorCode.Default.ERROR, "tag必须是HTMLTagVarBindingWrapper"); be.pushToken(this.token); throw be; } @@ -40,7 +41,7 @@ public class TagVarBindingStatement extends TagStatement { // BeetlException异常时不要设置token,因为抛出的地方已经设置了 throw ex; } catch (RuntimeException ex) { - BeetlException be = new BeetlException(BeetlException.ERROR, "tag执行抛错", ex); + BeetlException be = new BeetlException(BeetlErrorCode.Default.ERROR, "tag执行抛错", ex); be.pushToken(token); throw be; } diff --git a/src/main/java/org/beetl/core/statement/TernaryExpression.java b/src/main/java/org/beetl/core/statement/TernaryExpression.java index 751da5a..bb3f193 100644 --- a/src/main/java/org/beetl/core/statement/TernaryExpression.java +++ b/src/main/java/org/beetl/core/statement/TernaryExpression.java @@ -28,6 +28,7 @@ package org.beetl.core.statement; import org.beetl.core.Context; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; /** @@ -55,11 +56,11 @@ public class TernaryExpression extends Expression { Object value = condtion.evaluate(ctx); if (value == null) { - BeetlException be = new BeetlException(BeetlException.NULL); + BeetlException be = new BeetlException(BeetlErrorCode.Default.NULL); be.pushToken(condtion.token); throw be; } else if (!(value instanceof Boolean)) { - BeetlException be = new BeetlException(BeetlException.BOOLEAN_EXPECTED_ERROR); + BeetlException be = new BeetlException(BeetlErrorCode.Type.BOOLEAN_EXPECTED_ERROR); be.pushToken(condtion.token); throw be; } diff --git a/src/main/java/org/beetl/core/statement/TryCatchStatement.java b/src/main/java/org/beetl/core/statement/TryCatchStatement.java index 19db5fc..cf05934 100644 --- a/src/main/java/org/beetl/core/statement/TryCatchStatement.java +++ b/src/main/java/org/beetl/core/statement/TryCatchStatement.java @@ -28,6 +28,7 @@ package org.beetl.core.statement; import org.beetl.core.Context; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; /** @@ -62,7 +63,7 @@ public class TryCatchStatement extends Statement { if (ex instanceof BeetlException) { ctx.vars[error.varIndex] = ex; } else { - ctx.vars[error.varIndex] = new BeetlException(BeetlException.ERROR, ex.getMessage(), ex); + ctx.vars[error.varIndex] = new BeetlException(BeetlErrorCode.Default.ERROR, ex.getMessage(), ex); } } @@ -73,7 +74,7 @@ public class TryCatchStatement extends Statement { if (ex instanceof BeetlException) { throw (BeetlException) ex; } else { - throw new BeetlException(BeetlException.ERROR, ex.getMessage(), ex).pushToken(tryPart.token); + throw new BeetlException(BeetlErrorCode.Default.ERROR, ex.getMessage(), ex).pushToken(tryPart.token); } } } diff --git a/src/main/java/org/beetl/core/statement/VarRef.java b/src/main/java/org/beetl/core/statement/VarRef.java index a8efd70..6b46230 100644 --- a/src/main/java/org/beetl/core/statement/VarRef.java +++ b/src/main/java/org/beetl/core/statement/VarRef.java @@ -28,6 +28,7 @@ package org.beetl.core.statement; import org.beetl.core.Context; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.om.AttributeAccess; import org.beetl.core.om.AABuilder; @@ -82,7 +83,7 @@ public class VarRef extends Expression implements IVarIndex { if (hasSafe || ctx.safeOutput) { return safe == null ? null : safe.evaluate(ctx); } else { - throw new BeetlException(BeetlException.NULL, "空指针") + throw new BeetlException(BeetlErrorCode.Default.NULL, "空指针") .pushToken(i == 0 ? this.firstToken : attributes[i - 1].token); } } @@ -92,7 +93,7 @@ public class VarRef extends Expression implements IVarIndex { } catch (BeetlException ex) { throw ex.pushToken(attr.token); } catch (RuntimeException ex) { - throw new BeetlException(BeetlException.ATTRIBUTE_INVALID, "属性访问出错", ex).pushToken(attr.token); + throw new BeetlException(BeetlErrorCode.Attribute.ATTRIBUTE_INVALID, "属性访问出错", ex).pushToken(attr.token); } } @@ -133,7 +134,7 @@ public class VarRef extends Expression implements IVarIndex { if (hasSafe || ctx.safeOutput) { return new Result(safe == null ? null : safe.evaluate(ctx), true); } else { - throw new BeetlException(BeetlException.NULL, "_root为空指针,无" + this.firstToken.text + "值") + throw new BeetlException(BeetlErrorCode.Default.NULL, "_root为空指针,无" + this.firstToken.text + "值") .pushToken(this.firstToken); } @@ -143,7 +144,7 @@ public class VarRef extends Expression implements IVarIndex { try { value = aa.value(root, attr); } catch (RuntimeException e) { - throw new BeetlException(BeetlException.ATTRIBUTE_INVALID, + throw new BeetlException(BeetlErrorCode.Attribute.ATTRIBUTE_INVALID, "访问 _root " + root.getClass() + "." + attr + " 属性访问错误") .pushToken(this.firstToken); } @@ -153,7 +154,7 @@ public class VarRef extends Expression implements IVarIndex { } else if (hasSafe || ctx.safeOutput) { return new Result(safe == null ? null : safe.evaluate(ctx), true); } else { - BeetlException ex = new BeetlException(BeetlException.VAR_NOT_DEFINED); + BeetlException ex = new BeetlException(BeetlErrorCode.Var.VAR_NOT_DEFINED); ex.pushToken(this.firstToken); throw ex; } @@ -195,13 +196,13 @@ public class VarRef extends Expression implements IVarIndex { Result ret = this.getValue(ctx); Object value = ret.value; if (value == null) { - throw new BeetlException(BeetlException.NULL).pushToken(this.firstToken); + throw new BeetlException(BeetlErrorCode.Default.NULL).pushToken(this.firstToken); } for (int i = 0; i < attributes.length - 1; i++) { VarAttribute attr = attributes[i]; if (value == null) { - throw new BeetlException(BeetlException.NULL, "空指针") + throw new BeetlException(BeetlErrorCode.Default.NULL, "空指针") .pushToken(i == 0 ? this.firstToken : attributes[i - 1].token); } try { @@ -209,7 +210,7 @@ public class VarRef extends Expression implements IVarIndex { } catch (BeetlException ex) { throw ex.pushToken(attr.token); } catch (RuntimeException ex) { - throw new BeetlException(BeetlException.ATTRIBUTE_INVALID, "属性访问出错", ex).pushToken(attr.token); + throw new BeetlException(BeetlErrorCode.Attribute.ATTRIBUTE_INVALID, "属性访问出错", ex).pushToken(attr.token); } } diff --git a/src/main/java/org/beetl/core/statement/VarRefAssignExpress.java b/src/main/java/org/beetl/core/statement/VarRefAssignExpress.java index abdce2c..85839de 100644 --- a/src/main/java/org/beetl/core/statement/VarRefAssignExpress.java +++ b/src/main/java/org/beetl/core/statement/VarRefAssignExpress.java @@ -28,6 +28,7 @@ package org.beetl.core.statement; import org.beetl.core.Context; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.om.AABuilder; @@ -73,7 +74,7 @@ public class VarRefAssignExpress extends Expression implements IVarIndex { } if (obj == null) { - throw new BeetlException(BeetlException.NULL).pushToken(varRef.token); + throw new BeetlException(BeetlErrorCode.Default.NULL).pushToken(varRef.token); } try { @@ -81,7 +82,7 @@ public class VarRefAssignExpress extends Expression implements IVarIndex { aa.setValue(obj, key, value); return value; } catch (ClassCastException ex) { - throw new BeetlException(BeetlException.ATTRIBUTE_INVALID, ex).pushToken(lastVarAttribute.token); + throw new BeetlException(BeetlErrorCode.Attribute.ATTRIBUTE_INVALID, ex).pushToken(lastVarAttribute.token); } catch (BeetlException be) { throw be.pushToken(lastVarAttribute.token); } diff --git a/src/main/java/org/beetl/core/statement/VarRefAssignStatement.java b/src/main/java/org/beetl/core/statement/VarRefAssignStatement.java index 86f60b0..2e5fa6f 100644 --- a/src/main/java/org/beetl/core/statement/VarRefAssignStatement.java +++ b/src/main/java/org/beetl/core/statement/VarRefAssignStatement.java @@ -28,6 +28,7 @@ package org.beetl.core.statement; import org.beetl.core.Context; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.om.AttributeAccess; import org.beetl.core.om.AABuilder; @@ -63,7 +64,7 @@ public class VarRefAssignStatement extends VarAssignStatement { } if (obj == null) { - BeetlException bx = new BeetlException(BeetlException.NULL); + BeetlException bx = new BeetlException(BeetlErrorCode.Default.NULL); bx.pushToken(varRef.token); throw bx; } @@ -72,7 +73,7 @@ public class VarRefAssignStatement extends VarAssignStatement { aa.setValue(obj, key, value); } catch (ClassCastException ex) { - BeetlException bx = new BeetlException(BeetlException.ATTRIBUTE_INVALID, ex); + BeetlException bx = new BeetlException(BeetlErrorCode.Attribute.ATTRIBUTE_INVALID, ex); bx.pushToken(lastVarAttribute.token); throw bx; } catch (BeetlException be) { diff --git a/src/main/java/org/beetl/core/statement/VarVirtualAttribute.java b/src/main/java/org/beetl/core/statement/VarVirtualAttribute.java index 0a99a28..9331742 100644 --- a/src/main/java/org/beetl/core/statement/VarVirtualAttribute.java +++ b/src/main/java/org/beetl/core/statement/VarVirtualAttribute.java @@ -2,6 +2,7 @@ package org.beetl.core.statement; import org.beetl.core.Context; import org.beetl.core.VirtualClassAttribute; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; /** @@ -22,7 +23,7 @@ public class VarVirtualAttribute extends VarAttribute { VirtualClassAttribute vae = ctx.gt.getVirtualAttributeEval(o.getClass(), name); if (vae == null) { - BeetlException be = new BeetlException(BeetlException.VIRTUAL_NOT_FOUND); + BeetlException be = new BeetlException(BeetlErrorCode.Attribute.VIRTUAL_NOT_FOUND); be.pushToken(token); throw be; } diff --git a/src/main/java/org/beetl/core/statement/WhileStatement.java b/src/main/java/org/beetl/core/statement/WhileStatement.java index d4eb29e..8f28c41 100644 --- a/src/main/java/org/beetl/core/statement/WhileStatement.java +++ b/src/main/java/org/beetl/core/statement/WhileStatement.java @@ -28,6 +28,7 @@ package org.beetl.core.statement; import org.beetl.core.Context; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; /** @@ -75,7 +76,7 @@ public class WhileStatement extends Statement implements IGoto { } } else { - BeetlException be = new BeetlException(BeetlException.BOOLEAN_EXPECTED_ERROR); + BeetlException be = new BeetlException(BeetlErrorCode.Type.BOOLEAN_EXPECTED_ERROR); be.pushToken(exp.token); throw be; } @@ -94,7 +95,7 @@ public class WhileStatement extends Statement implements IGoto { } } else { - BeetlException be = new BeetlException(BeetlException.BOOLEAN_EXPECTED_ERROR); + BeetlException be = new BeetlException(BeetlErrorCode.Type.BOOLEAN_EXPECTED_ERROR); be.pushToken(exp.token); throw be; } diff --git a/src/main/java/org/beetl/core/statement/optimal/VarRefOptimal.java b/src/main/java/org/beetl/core/statement/optimal/VarRefOptimal.java index bd95977..bea3559 100644 --- a/src/main/java/org/beetl/core/statement/optimal/VarRefOptimal.java +++ b/src/main/java/org/beetl/core/statement/optimal/VarRefOptimal.java @@ -28,6 +28,7 @@ package org.beetl.core.statement.optimal; import org.beetl.core.Context; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.fun.ObjectUtil; import org.beetl.core.om.AABuilder; @@ -57,23 +58,23 @@ public class VarRefOptimal extends VarRef { if (this.hasSafe || ctx.safeOutput) { return null; } - throw new BeetlException(BeetlException.NULL, "空指针").pushToken(this.token); + throw new BeetlException(BeetlErrorCode.Default.NULL, "空指针").pushToken(this.token); } try { value = attribute.evaluate(ctx, value); } catch (BeetlException ex) { ex.pushToken(attribute.token); - if (ex.detailCode == BeetlException.ATTRIBUTE_NOT_FOUND) { + if (ex.detailCode == BeetlErrorCode.Attribute.ATTRIBUTE_NOT_FOUND) { //进一步可出可能友好的提示 if (ObjectUtil.hasPrivateAttribute(value.getClass(), attribute.token.text)) { - ex.detailCode = BeetlException.ATTRIBUTE_NOT_FOUND_PRIVATE; + ex.detailCode = BeetlErrorCode.Attribute.ATTRIBUTE_NOT_FOUND_PRIVATE; } } throw ex; } catch (RuntimeException ex) { - throw new BeetlException(BeetlException.ATTRIBUTE_INVALID, "属性访问出错", ex).pushToken(attribute.token); + throw new BeetlException(BeetlErrorCode.Attribute.ATTRIBUTE_INVALID, "属性访问出错", ex).pushToken(attribute.token); } return value; @@ -101,7 +102,7 @@ public class VarRefOptimal extends VarRef { try { value = aa.value(root, attr); } catch (RuntimeException e) { - throw new BeetlException(BeetlException.ATTRIBUTE_INVALID, "_root " + root.getClass() + " 属性访问错误") + throw new BeetlException(BeetlErrorCode.Attribute.ATTRIBUTE_INVALID, "_root " + root.getClass() + " 属性访问错误") .pushToken(this.firstToken); } diff --git a/src/main/java/org/beetl/core/text/HtmlTagStartFragment.java b/src/main/java/org/beetl/core/text/HtmlTagStartFragment.java index ea5bad0..359789a 100644 --- a/src/main/java/org/beetl/core/text/HtmlTagStartFragment.java +++ b/src/main/java/org/beetl/core/text/HtmlTagStartFragment.java @@ -4,6 +4,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Stack; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.exception.HTMLTagParserException; import org.beetl.core.statement.GrammarToken; @@ -123,7 +124,7 @@ public class HtmlTagStartFragment extends ScriptFragment { html.parser(); } catch (RuntimeException ex) { String tagName = html.tagName == null ? "<>" : "<" + html.tagName + ">"; - throw new BeetlException(BeetlException.PARSER_HTML_TAG_ERROR, ex.getMessage(), ex) + throw new BeetlException(BeetlErrorCode.Parser.PARSER_HTML_TAG_ERROR, ex.getMessage(), ex) .pushToken(GrammarToken.createToken(tagName, source.curLine + 1)); } diff --git a/src/main/java/org/beetl/ext/fn/Flush.java b/src/main/java/org/beetl/ext/fn/Flush.java index 62f6a5d..dc76e60 100644 --- a/src/main/java/org/beetl/ext/fn/Flush.java +++ b/src/main/java/org/beetl/ext/fn/Flush.java @@ -4,6 +4,7 @@ import java.io.IOException; import org.beetl.core.Context; import org.beetl.core.Function; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; public class Flush implements Function { @@ -14,7 +15,7 @@ public class Flush implements Function { ctx.beetlWriter.flush(); return null; } catch (IOException e) { - throw new BeetlException(BeetlException.CLIENT_IO_ERROR_ERROR, e.getMessage(), e); + throw new BeetlException(BeetlErrorCode.IO.CLIENT_IO_ERROR_ERROR, e.getMessage(), e); } } diff --git a/src/main/java/org/beetl/ext/fn/Print.java b/src/main/java/org/beetl/ext/fn/Print.java index f6a4288..8d2ec5b 100644 --- a/src/main/java/org/beetl/ext/fn/Print.java +++ b/src/main/java/org/beetl/ext/fn/Print.java @@ -31,6 +31,7 @@ import java.io.IOException; import org.beetl.core.Context; import org.beetl.core.Function; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; /** @@ -46,7 +47,7 @@ public class Print implements Function { try { ctx.beetlWriter.writeString(o.toString()); } catch (IOException e) { - throw new BeetlException(BeetlException.CLIENT_IO_ERROR_ERROR); + throw new BeetlException(BeetlErrorCode.IO.CLIENT_IO_ERROR_ERROR); } } return ""; diff --git a/src/main/java/org/beetl/ext/fn/Printf.java b/src/main/java/org/beetl/ext/fn/Printf.java index 851c558..39981b3 100644 --- a/src/main/java/org/beetl/ext/fn/Printf.java +++ b/src/main/java/org/beetl/ext/fn/Printf.java @@ -32,6 +32,7 @@ import java.util.Formatter; import org.beetl.core.Context; import org.beetl.core.Function; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; /** @@ -50,7 +51,7 @@ public class Printf implements Function { try { ctx.beetlWriter.writeString(sb.toString()); } catch (IOException e) { - throw new BeetlException(BeetlException.CLIENT_IO_ERROR_ERROR); + throw new BeetlException(BeetlErrorCode.IO.CLIENT_IO_ERROR_ERROR); } return ""; diff --git a/src/main/java/org/beetl/ext/fn/Println.java b/src/main/java/org/beetl/ext/fn/Println.java index 06a586c..afd3888 100644 --- a/src/main/java/org/beetl/ext/fn/Println.java +++ b/src/main/java/org/beetl/ext/fn/Println.java @@ -32,6 +32,7 @@ import java.io.IOException; import org.beetl.core.BeetlWriter; import org.beetl.core.Context; import org.beetl.core.Function; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; /** @@ -57,7 +58,7 @@ public class Println implements Function { } } catch (IOException e) { - throw new BeetlException(BeetlException.CLIENT_IO_ERROR_ERROR); + throw new BeetlException(BeetlErrorCode.IO.CLIENT_IO_ERROR_ERROR); } return ""; diff --git a/src/main/java/org/beetl/ext/nutz/NutJsonFunction.java b/src/main/java/org/beetl/ext/nutz/NutJsonFunction.java index 70eea87..a408fff 100644 --- a/src/main/java/org/beetl/ext/nutz/NutJsonFunction.java +++ b/src/main/java/org/beetl/ext/nutz/NutJsonFunction.java @@ -2,6 +2,7 @@ package org.beetl.ext.nutz; import org.beetl.core.Context; import org.beetl.core.Function; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.nutz.json.Json; import org.nutz.json.JsonFormat; @@ -37,7 +38,7 @@ public class NutJsonFunction implements Function { } } } - throw new BeetlException(BeetlException.FUNCTION_INVALID); + throw new BeetlException(BeetlErrorCode.Function.FUNCTION_INVALID); } } diff --git a/src/main/java/org/beetl/ext/tag/cache/CacheTag.java b/src/main/java/org/beetl/ext/tag/cache/CacheTag.java index 95dd8a7..d15b3e1 100644 --- a/src/main/java/org/beetl/ext/tag/cache/CacheTag.java +++ b/src/main/java/org/beetl/ext/tag/cache/CacheTag.java @@ -30,6 +30,7 @@ package org.beetl.ext.tag.cache; import java.io.IOException; import org.beetl.core.BodyContent; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.tag.Tag; @@ -94,7 +95,7 @@ public class CacheTag extends Tag { } } catch (IOException ex) { if (!ctx.gt.getConf().isIgnoreClientIOError()) { - throw new BeetlException(BeetlException.CLIENT_IO_ERROR_ERROR, "IO Error", ex); + throw new BeetlException(BeetlErrorCode.IO.CLIENT_IO_ERROR_ERROR, "IO Error", ex); } } diff --git a/src/main/java/org/beetl/ext/tag/html/IncludeResourceFragmentHtmlTag.java b/src/main/java/org/beetl/ext/tag/html/IncludeResourceFragmentHtmlTag.java index 16b92a2..1031cb4 100644 --- a/src/main/java/org/beetl/ext/tag/html/IncludeResourceFragmentHtmlTag.java +++ b/src/main/java/org/beetl/ext/tag/html/IncludeResourceFragmentHtmlTag.java @@ -30,6 +30,7 @@ package org.beetl.ext.tag.html; import org.beetl.core.BeetlWriter; import org.beetl.core.Resource; import org.beetl.core.Template; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.tag.Tag; @@ -78,7 +79,7 @@ public class IncludeResourceFragmentHtmlTag extends Tag { @SuppressWarnings("unchecked") String targetResourceId = (String) ((Map) this.args[1]).get("file"); if (targetResourceId == null || targetResourceId.trim().length() == 0) { - throw new BeetlException(BeetlException.ERROR, "缺少 file属性 "); + throw new BeetlException(BeetlErrorCode.Default.ERROR, "缺少 file属性 "); } return targetResourceId; } diff --git a/src/main/java/org/beetl/ext/tag/html/IncludeResourceHtmlTag.java b/src/main/java/org/beetl/ext/tag/html/IncludeResourceHtmlTag.java index 413d4b7..ee5b2f8 100644 --- a/src/main/java/org/beetl/ext/tag/html/IncludeResourceHtmlTag.java +++ b/src/main/java/org/beetl/ext/tag/html/IncludeResourceHtmlTag.java @@ -33,6 +33,7 @@ import java.util.Map.Entry; import org.beetl.core.BeetlWriter; import org.beetl.core.Resource; import org.beetl.core.Template; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.tag.Tag; @@ -80,7 +81,7 @@ public class IncludeResourceHtmlTag extends Tag { @SuppressWarnings("unchecked") String targetResourceId = (String) ((Map) this.args[1]).get("file"); if (targetResourceId == null || targetResourceId.trim().length() == 0) { - throw new BeetlException(BeetlException.ERROR, "缺少 file属性 "); + throw new BeetlException(BeetlErrorCode.Default.ERROR, "缺少 file属性 "); } return targetResourceId; } diff --git a/src/main/java/org/beetl/ext/tag/html/LayoutResourceHtmlTag.java b/src/main/java/org/beetl/ext/tag/html/LayoutResourceHtmlTag.java index dd55e57..2cd7ead 100644 --- a/src/main/java/org/beetl/ext/tag/html/LayoutResourceHtmlTag.java +++ b/src/main/java/org/beetl/ext/tag/html/LayoutResourceHtmlTag.java @@ -33,6 +33,7 @@ import java.util.Map.Entry; import org.beetl.core.BodyContent; import org.beetl.core.Resource; import org.beetl.core.Template; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.tag.Tag; @@ -81,7 +82,7 @@ public class LayoutResourceHtmlTag extends Tag { @SuppressWarnings("unchecked") String targetResourceId = (String) ((Map) this.args[1]).get("parent"); if (targetResourceId == null || targetResourceId.trim().length() == 0) { - throw new BeetlException(BeetlException.ERROR, "缺少 parent 属性 "); + throw new BeetlException(BeetlErrorCode.Default.ERROR, "缺少 parent 属性 "); } return targetResourceId; } diff --git a/src/main/java/org/beetl/ext/web/WebErrorHandler.java b/src/main/java/org/beetl/ext/web/WebErrorHandler.java index 33991d3..568de20 100644 --- a/src/main/java/org/beetl/ext/web/WebErrorHandler.java +++ b/src/main/java/org/beetl/ext/web/WebErrorHandler.java @@ -32,9 +32,10 @@ import java.io.Writer; import org.beetl.core.ConsoleErrorHandler; import org.beetl.core.Resource; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.runtime.IResourceLoader; import org.beetl.core.exception.BeetlException; -import org.beetl.core.exception.ErrorInfo; +import org.beetl.core.exception.BeetlErrorInfo; /** * 把错误信息渲染到视图 异常处理器 @@ -56,11 +57,11 @@ public class WebErrorHandler extends ConsoleErrorHandler { if (!Boolean.parseBoolean(e.gt.getConf().getProperty("RESOURCE.autoCheck"))) { super.processExcption(e, writer); } - ErrorInfo error = new ErrorInfo(e); + BeetlErrorInfo error = new BeetlErrorInfo(e); StringBuilder title = new StringBuilder(); StringBuilder msg = new StringBuilder(); - if (error.errorCode.equals(BeetlException.CLIENT_IO_ERROR_ERROR)) { + if (error.errorCode.equals(BeetlErrorCode.IO.CLIENT_IO_ERROR_ERROR)) { //不输出详细提示信息 title = new StringBuilder(">>").append("客户端IO异常:").append(e.resource.getId()); if (e.getCause() != null) { @@ -75,7 +76,7 @@ public class WebErrorHandler extends ConsoleErrorHandler { title = new StringBuilder(">>").append(error.type).append(":").append(error.errorTokenText) .append(" 位于").append(line).append("行").append(" 资源:").append(e.resource.getId()); - if (error.errorCode.equals(BeetlException.TEMPLATE_LOAD_ERROR)) { + if (error.errorCode.equals(BeetlErrorCode.Template.TEMPLATE_LOAD_ERROR)) { if (error.msg != null) msg.append(error.msg); render(writer, title.toString(), msg.toString()); diff --git a/src/test/java/org/beetl/core/om/asm/AsmBeanFactoryTest.java b/src/test/java/org/beetl/core/om/asm/AsmBeanFactoryTest.java index 7b65d1f..02b707e 100644 --- a/src/test/java/org/beetl/core/om/asm/AsmBeanFactoryTest.java +++ b/src/test/java/org/beetl/core/om/asm/AsmBeanFactoryTest.java @@ -3,6 +3,7 @@ package org.beetl.core.om.asm; import java.util.List; import org.beetl.core.BasicTestCase; +import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.fun.ObjectUtil; import org.testng.AssertJUnit; @@ -89,7 +90,7 @@ public class AsmBeanFactoryTest extends BasicTestCase { asmBeanFactory.value(empty, "ss"); AssertJUnit.fail(); } catch (BeetlException e) { - AssertJUnit.assertEquals(BeetlException.ATTRIBUTE_NOT_FOUND, e.detailCode); + AssertJUnit.assertEquals(BeetlErrorCode.Attribute.ATTRIBUTE_NOT_FOUND, e.detailCode); AssertJUnit.assertTrue(e.getMessage().contains("ss")); } AssertJUnit.assertEquals(name, asmBeanFactory.value(empty, "name")); -- Gitee From 3893a54cf4bea0ebcfadf208af5d1c57df11353c Mon Sep 17 00:00:00 2001 From: zhaoxuyang03 Date: Sun, 14 Mar 2021 21:12:51 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E3=80=90Sprint3.3.3=E3=80=91=E3=80=90Bee?= =?UTF-8?q?tl=E3=80=91=E6=A0=87=E7=AD=BE=E6=A8=A1=E5=9D=97=E7=9A=84?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E5=B8=B8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/beetl/core/AntlrProgramBuilder.java | 6 ++-- .../java/org/beetl/core/GroupTemplate.java | 11 ++++--- .../{ => impl/tag}/DefaultTagFactory.java | 6 ++-- .../ITagFactory.java} | 6 ++-- .../beetl/core/statement/TagStatement.java | 4 +-- .../beetl/core/tag/GeneralVarTagBinding.java | 2 +- .../beetl/core/tag/HTMLTagSupportWrapper.java | 15 +++++---- .../core/tag/HTMLTagVarBindingWrapper.java | 11 ++++--- .../org/beetl/core/tag/ITagConstants.java | 17 ++++++++++ src/main/java/org/beetl/core/tag/Tag.java | 33 ++++++++----------- .../spring/AbstractGroupTemplateConfig.java | 8 ++--- .../ext/spring/SpringBeanTagFactory.java | 4 +-- 12 files changed, 69 insertions(+), 54 deletions(-) rename src/main/java/org/beetl/core/{ => impl/tag}/DefaultTagFactory.java (94%) rename src/main/java/org/beetl/core/{tag/TagFactory.java => runtime/ITagFactory.java} (66%) create mode 100644 src/main/java/org/beetl/core/tag/ITagConstants.java diff --git a/src/main/java/org/beetl/core/AntlrProgramBuilder.java b/src/main/java/org/beetl/core/AntlrProgramBuilder.java index b61b00e..b7523cf 100644 --- a/src/main/java/org/beetl/core/AntlrProgramBuilder.java +++ b/src/main/java/org/beetl/core/AntlrProgramBuilder.java @@ -182,7 +182,7 @@ import org.beetl.core.statement.nat.NativeArrayNode; import org.beetl.core.statement.nat.NativeAttributeNode; import org.beetl.core.statement.nat.NativeMethodNode; import org.beetl.core.statement.nat.NativeNode; -import org.beetl.core.tag.TagFactory; +import org.beetl.core.runtime.ITagFactory; /** * 通过antlr来生成Program @@ -703,7 +703,7 @@ public class AntlrProgramBuilder { } } - TagFactory tf = this.gt.getTagFactory(id); + ITagFactory tf = this.gt.getTagFactory(id); if (tf == null) { throw new BeetlException(BeetlErrorCode.Tag.TAG_NOT_FOUND) .pushToken(this.getBTToken(id, fc.functionNs().getStart().getLine())); @@ -712,7 +712,7 @@ public class AntlrProgramBuilder { } else { BlockContext blockCtx = fc.block(); Statement block = parseBlock(blockCtx.statement(), blockCtx); - TagFactory tf = this.gt.getTagFactory(id); + ITagFactory tf = this.gt.getTagFactory(id); if (tf == null) { throw new BeetlException(BeetlErrorCode.Tag.TAG_NOT_FOUND) .pushToken(this.getBTToken(id, fc.functionNs().getStart().getLine())); diff --git a/src/main/java/org/beetl/core/GroupTemplate.java b/src/main/java/org/beetl/core/GroupTemplate.java index d715347..cc171b2 100644 --- a/src/main/java/org/beetl/core/GroupTemplate.java +++ b/src/main/java/org/beetl/core/GroupTemplate.java @@ -41,6 +41,7 @@ import java.util.Map; import java.util.Map.Entry; import org.beetl.core.exception.BeetlErrorCode; +import org.beetl.core.impl.tag.DefaultTagFactory; import org.beetl.core.runtime.BeetlRuntime; import org.beetl.core.runtime.IBeetlCache; import org.beetl.core.cache.ContextBuffer; @@ -60,7 +61,7 @@ import org.beetl.core.runtime.INativeSecurityManager; import org.beetl.core.runtime.IResourceLoader; import org.beetl.core.statement.ErrorGrammarProgram; import org.beetl.core.statement.Program; -import org.beetl.core.tag.TagFactory; +import org.beetl.core.runtime.ITagFactory; import org.beetl.core.text.AttributeNameConvert; import org.beetl.core.text.TextParser; @@ -96,7 +97,7 @@ public class GroupTemplate { /** 虚类与虚类属性的映射 */ Map virtualClass = new HashMap<>(); /** 标签函数 */ - Map tagFactoryMap = new HashMap<>(); + Map tagFactoryMap = new HashMap<>(); /** 用于查找类的工具 */ ClassSearch classSearch = null; /** 本地调用(这里就是Java)安全管理器 */ @@ -258,7 +259,7 @@ public class GroupTemplate { for (Entry entry : tagFactoryMap.entrySet()) { String name = entry.getKey(); String clsName = entry.getValue(); - this.registerTagFactory(name, (TagFactory) ObjectUtil.instance(clsName, classLoader)); + this.registerTagFactory(name, (ITagFactory) ObjectUtil.instance(clsName, classLoader)); } } @@ -657,7 +658,7 @@ public class GroupTemplate { this.tagFactoryMap.put(name, new DefaultTagFactory(tagCls)); } - public void registerTagFactory(String name, TagFactory tagFactory) { + public void registerTagFactory(String name, ITagFactory tagFactory) { checkTagName(name); this.tagFactoryMap.put(name, tagFactory); } @@ -674,7 +675,7 @@ public class GroupTemplate { } } - public TagFactory getTagFactory(String name) { + public ITagFactory getTagFactory(String name) { return this.tagFactoryMap.get(name); } diff --git a/src/main/java/org/beetl/core/DefaultTagFactory.java b/src/main/java/org/beetl/core/impl/tag/DefaultTagFactory.java similarity index 94% rename from src/main/java/org/beetl/core/DefaultTagFactory.java rename to src/main/java/org/beetl/core/impl/tag/DefaultTagFactory.java index e15197b..c1a4320 100644 --- a/src/main/java/org/beetl/core/DefaultTagFactory.java +++ b/src/main/java/org/beetl/core/impl/tag/DefaultTagFactory.java @@ -25,19 +25,19 @@ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.beetl.core; +package org.beetl.core.impl.tag; import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.tag.Tag; -import org.beetl.core.tag.TagFactory; +import org.beetl.core.runtime.ITagFactory; /** * Tag工场类 * * @author xiandafu */ -public class DefaultTagFactory implements TagFactory { +public class DefaultTagFactory implements ITagFactory { Class tagCls; public DefaultTagFactory(Class tagCls) { diff --git a/src/main/java/org/beetl/core/tag/TagFactory.java b/src/main/java/org/beetl/core/runtime/ITagFactory.java similarity index 66% rename from src/main/java/org/beetl/core/tag/TagFactory.java rename to src/main/java/org/beetl/core/runtime/ITagFactory.java index 3d69be3..e6ead6e 100644 --- a/src/main/java/org/beetl/core/tag/TagFactory.java +++ b/src/main/java/org/beetl/core/runtime/ITagFactory.java @@ -1,11 +1,13 @@ -package org.beetl.core.tag; +package org.beetl.core.runtime; + +import org.beetl.core.tag.Tag; /** * 标签函数工厂类 * * @author xiandafu */ -public interface TagFactory { +public interface ITagFactory { /** * 创建一个标签 * diff --git a/src/main/java/org/beetl/core/statement/TagStatement.java b/src/main/java/org/beetl/core/statement/TagStatement.java index 895391b..8857f97 100644 --- a/src/main/java/org/beetl/core/statement/TagStatement.java +++ b/src/main/java/org/beetl/core/statement/TagStatement.java @@ -32,7 +32,7 @@ import org.beetl.core.exception.BeetlErrorCode; import org.beetl.core.exception.BeetlException; import org.beetl.core.fun.ObjectUtil; import org.beetl.core.tag.Tag; -import org.beetl.core.tag.TagFactory; +import org.beetl.core.runtime.ITagFactory; /** * 标签,如: @@ -62,7 +62,7 @@ public class TagStatement extends Statement { public void execute(Context ctx) { Tag tag = null; try { - TagFactory tagFactory = ctx.gt.getTagFactory(this.tagName); + ITagFactory tagFactory = ctx.gt.getTagFactory(this.tagName); tag = tagFactory.createTag(); Object[] args = null; if (paras.length == 0) { diff --git a/src/main/java/org/beetl/core/tag/GeneralVarTagBinding.java b/src/main/java/org/beetl/core/tag/GeneralVarTagBinding.java index de50e7b..73cc581 100644 --- a/src/main/java/org/beetl/core/tag/GeneralVarTagBinding.java +++ b/src/main/java/org/beetl/core/tag/GeneralVarTagBinding.java @@ -75,7 +75,7 @@ public abstract class GeneralVarTagBinding extends Tag { */ protected void binds(Object... array) { if (name2Index == null) { - throw new RuntimeException("html标签没有定义绑定变量,但标签实现中试图绑定" + Arrays.asList(array)); + throw new IllegalStateException(ERROR_MSG_NOT_DEFINED + Arrays.asList(array)); } Iterator it = name2Index.values().iterator(); diff --git a/src/main/java/org/beetl/core/tag/HTMLTagSupportWrapper.java b/src/main/java/org/beetl/core/tag/HTMLTagSupportWrapper.java index 523874e..5e931af 100644 --- a/src/main/java/org/beetl/core/tag/HTMLTagSupportWrapper.java +++ b/src/main/java/org/beetl/core/tag/HTMLTagSupportWrapper.java @@ -7,6 +7,7 @@ import java.util.Map.Entry; import org.beetl.core.Context; import org.beetl.core.Template; import org.beetl.core.exception.BeetlException; +import org.beetl.core.runtime.ITagFactory; import org.beetl.core.statement.Statement; /** @@ -22,20 +23,20 @@ public class HTMLTagSupportWrapper extends Tag { @Override public void init(Context ctx, Object[] args, Statement st) { super.inintBase(ctx, args, st); - //Parent tag 不在这里设置,而在正真的Tag里设置 - tagRoot = ctx.gt.getConf().getResourceMap().get("tagRoot"); - tagSuffix = ctx.gt.getConf().getResourceMap().get("tagSuffix"); + // Parent tag 不在这里设置,而在真正的Tag里设置 + tagRoot = ctx.gt.getConf().getResourceMap().get(KEY_TAG_ROOT); + tagSuffix = ctx.gt.getConf().getResourceMap().get(KEY_TAG_SUFFIX); } @Override public void render() { if (args.length == 0 || args.length > 2) { - throw new RuntimeException("参数错误,期望child,Map ....."); + throw new IllegalArgumentException(ERROR_MSG_ILLEGAL_ARGUMENT); } //标签名称 String child = (String) args[0]; // 首先查找 已经注册的Tag - TagFactory tagFactory = null; + ITagFactory tagFactory = null; String functionTagName = child.replace(':', '.'); tagFactory = this.gt.getTagFactory(functionTagName); if (tagFactory == null) { @@ -55,7 +56,7 @@ public class HTMLTagSupportWrapper extends Tag { return "/" + this.tagRoot + "/" + path + "." + this.tagSuffix; } - protected void callTag(TagFactory tagFactory) { + protected void callTag(ITagFactory tagFactory) { Tag tag = tagFactory.createTag(); tag.init(ctx, args, bs); @@ -86,7 +87,7 @@ public class HTMLTagSupportWrapper extends Tag { * 模板需要调用方法 与默认实现不同,并没有先渲染body体,而是延迟处理, 等待调用的时候在获取tag体内容 * */ - t.binding("tagBody", new Object() { + t.binding(KEY_TAG_BODY, new Object() { @Override public String toString() { try { diff --git a/src/main/java/org/beetl/core/tag/HTMLTagVarBindingWrapper.java b/src/main/java/org/beetl/core/tag/HTMLTagVarBindingWrapper.java index 43a2785..af222d1 100644 --- a/src/main/java/org/beetl/core/tag/HTMLTagVarBindingWrapper.java +++ b/src/main/java/org/beetl/core/tag/HTMLTagVarBindingWrapper.java @@ -30,6 +30,7 @@ package org.beetl.core.tag; import java.util.LinkedHashMap; import org.beetl.core.Context; +import org.beetl.core.runtime.ITagFactory; import org.beetl.core.statement.Statement; /** @@ -55,22 +56,22 @@ public class HTMLTagVarBindingWrapper extends Tag { public void init(Context ctx, Object[] args, Statement st) { super.init(ctx, args, st); if (args.length == 0 || args.length > 3) { - throw new RuntimeException("参数错误,期望child,Map ....."); + throw new IllegalArgumentException(ERROR_MSG_ILLEGAL_ARGUMENT); } String child = (String) args[0]; // 已经注册的Tag - TagFactory tagFactory = null; + ITagFactory tagFactory = null; String functionTagName = child.replace(':', '.'); tagFactory = this.gt.getTagFactory(functionTagName); if (tagFactory == null) { - throw new RuntimeException("标签初始化错误,未找到指定的标签实现类" + functionTagName); + throw new IllegalStateException(ERROR_MSG_NOT_TAG_IMPL_CLASS + functionTagName); } Tag temp = tagFactory.createTag(); if (temp == null) { - throw new RuntimeException("找不到注册的Tag"); + throw new IllegalStateException(ERROR_MSG_NOT_TAG_REGISTER); } else if (!(temp instanceof GeneralVarTagBinding)) { - throw new RuntimeException(tag.getClass() + " 必须是TagVarBinding的实现类"); + throw new RuntimeException(tag.getClass() + ERROR_MSG_MUST_BE_TAG_VAR_BINDING_IMPL_CLASS); } this.tag = ((GeneralVarTagBinding) temp); diff --git a/src/main/java/org/beetl/core/tag/ITagConstants.java b/src/main/java/org/beetl/core/tag/ITagConstants.java new file mode 100644 index 0000000..eb5d9bc --- /dev/null +++ b/src/main/java/org/beetl/core/tag/ITagConstants.java @@ -0,0 +1,17 @@ +package org.beetl.core.tag; + +/** + * 标签模块的相关常量 + */ +interface ITagConstants { + String ERROR_MSG_NOT_HTML_TAG = "非html标签"; + String ERROR_MSG_ILLEGAL_ARGUMENT = "参数错误,期望child,Map ....."; + String ERROR_MSG_NOT_TAG_IMPL_CLASS = "标签初始化错误,未找到指定的标签实现类"; + String ERROR_MSG_NOT_TAG_REGISTER = "找不到注册的Tag"; + String ERROR_MSG_MUST_BE_TAG_VAR_BINDING_IMPL_CLASS = " 必须是TagVarBinding的实现类"; + String ERROR_MSG_NOT_DEFINED = "html标签没有定义绑定变量,但标签实现中试图绑定"; + + String KEY_TAG_ROOT = "tagRoot"; + String KEY_TAG_SUFFIX = "tagSuffix"; + String KEY_TAG_BODY = "tagBody"; +} diff --git a/src/main/java/org/beetl/core/tag/Tag.java b/src/main/java/org/beetl/core/tag/Tag.java index f7f7e71..e4f08b6 100644 --- a/src/main/java/org/beetl/core/tag/Tag.java +++ b/src/main/java/org/beetl/core/tag/Tag.java @@ -38,39 +38,33 @@ import java.util.Map; /** * 标签函数,用于处理一段模板快 * - *

; - * <% cache(key){ %> - *

- * ip=10.1.1.1 - *

- * port=9090 - *

- * <%}> - * - *

+ *
+ *     <% cache(key) { %>
+ *         ip=10.1.1.1
+ *         port=9090
+ *     <% } %>
+ * 
* * Beetl的标签函数可以转化HTML标签风格,参考{@link HTMLTagSupportWrapper} * - * @author joeli + * @author xiandafu */ -public abstract class Tag { - //标签函数参数,同Function,如果是HTML标签,则参数0是html标签内容,参数1是Map,所有的html属性 +public abstract class Tag implements ITagConstants { + /** 标签函数参数,同Function,如果是HTML标签,则参数0是html标签内容,参数1是Map,所有的html属性 */ protected Object[] args = null; protected GroupTemplate gt; protected Context ctx; protected BeetlWriter bw; - //标签体 + /** 标签体 */ protected Statement bs; - //父标签 + /** 父标签 */ protected Tag parent; /** * 主要方法:渲染标签体 */ protected void doBodyRender() { - bs.execute(ctx); - } /** @@ -94,7 +88,6 @@ public abstract class Tag { public void init(Context ctx, Object[] args, Statement st) { inintBase(ctx, args, st); setTagParent(); - } protected void inintBase(Context ctx, Object[] args, Statement st) { @@ -126,7 +119,7 @@ public abstract class Tag { Object obj = (Object) args[1]; if (!(obj instanceof Map)) { - throw new IllegalStateException("非html标签"); + throw new IllegalStateException(ERROR_MSG_NOT_HTML_TAG); } return ((Map) obj).get(attrName); @@ -135,7 +128,7 @@ public abstract class Tag { public boolean containHtmlAttribute(String attrName) { Object obj = (Object) args[1]; if (!(obj instanceof Map)) { - throw new IllegalStateException("非html标签"); + throw new IllegalStateException(ERROR_MSG_NOT_HTML_TAG); } return ((Map) obj).containsKey(attrName); diff --git a/src/main/java/org/beetl/ext/spring/AbstractGroupTemplateConfig.java b/src/main/java/org/beetl/ext/spring/AbstractGroupTemplateConfig.java index 086ab37..a2d58bc 100644 --- a/src/main/java/org/beetl/ext/spring/AbstractGroupTemplateConfig.java +++ b/src/main/java/org/beetl/ext/spring/AbstractGroupTemplateConfig.java @@ -37,7 +37,7 @@ import org.beetl.core.Function; import org.beetl.core.GroupTemplate; import org.beetl.core.VirtualAttributeEval; import org.beetl.core.VirtualClassAttribute; -import org.beetl.core.tag.TagFactory; +import org.beetl.core.runtime.ITagFactory; /** * GroupTemplate对象配置类的抽象基类 @@ -61,7 +61,7 @@ public abstract class AbstractGroupTemplateConfig { /** * 自定义标签 */ - private Map tagFactorys = Collections.emptyMap(); + private Map tagFactorys = Collections.emptyMap(); /** * 自定义函数包 */ @@ -99,7 +99,7 @@ public abstract class AbstractGroupTemplateConfig { /** * 自定义标签 */ - public void setTagFactorys(Map tagFactorys) { + public void setTagFactorys(Map tagFactorys) { this.tagFactorys = tagFactorys; } @@ -145,7 +145,7 @@ public abstract class AbstractGroupTemplateConfig { } // 注册自定义标签 - for (Entry entry : tagFactorys.entrySet()) { + for (Entry entry : tagFactorys.entrySet()) { groupTemplate.registerTagFactory(entry.getKey(), entry.getValue()); } diff --git a/src/main/java/org/beetl/ext/spring/SpringBeanTagFactory.java b/src/main/java/org/beetl/ext/spring/SpringBeanTagFactory.java index 77aad4c..528a430 100644 --- a/src/main/java/org/beetl/ext/spring/SpringBeanTagFactory.java +++ b/src/main/java/org/beetl/ext/spring/SpringBeanTagFactory.java @@ -1,7 +1,7 @@ package org.beetl.ext.spring; import org.beetl.core.tag.Tag; -import org.beetl.core.tag.TagFactory; +import org.beetl.core.runtime.ITagFactory; import org.springframework.beans.factory.annotation.Required; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; @@ -11,7 +11,7 @@ import org.springframework.context.ApplicationContextAware; * * @author Chen Rui */ -public class SpringBeanTagFactory implements TagFactory, ApplicationContextAware { +public class SpringBeanTagFactory implements ITagFactory, ApplicationContextAware { /* ----- ----- ----- ----- 属性 ----- ----- ----- ----- */ /** * 目标Bean名 -- Gitee From b275f0cfbc8222740c84faea9c0bc9b0d5eba5cd Mon Sep 17 00:00:00 2001 From: zhaoxuyang03 Date: Sun, 14 Mar 2021 21:15:13 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E3=80=90Sprint3.3.3=E3=80=91=E3=80=90Bee?= =?UTF-8?q?tl=E3=80=91=E5=B0=86BeetlKit=E7=A7=BB=E5=8A=A8=E5=88=B0test?= =?UTF-8?q?=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/{main => test}/java/org/beetl/core/BeetlKit.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{main => test}/java/org/beetl/core/BeetlKit.java (100%) diff --git a/src/main/java/org/beetl/core/BeetlKit.java b/src/test/java/org/beetl/core/BeetlKit.java similarity index 100% rename from src/main/java/org/beetl/core/BeetlKit.java rename to src/test/java/org/beetl/core/BeetlKit.java -- Gitee From 856b6dd0a9648eb078e4c8ebd56d8e0decaf93ad Mon Sep 17 00:00:00 2001 From: zhaoxuyang03 Date: Sun, 14 Mar 2021 21:20:23 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E3=80=90Sprint3.3.3=E3=80=91=E3=80=90Bee?= =?UTF-8?q?tl=E3=80=91ALU=20type=20=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/beetl/core/misc/ALU.java | 305 +++++++++++---------- 1 file changed, 157 insertions(+), 148 deletions(-) diff --git a/src/main/java/org/beetl/core/misc/ALU.java b/src/main/java/org/beetl/core/misc/ALU.java index fffb76e..07fb24d 100644 --- a/src/main/java/org/beetl/core/misc/ALU.java +++ b/src/main/java/org/beetl/core/misc/ALU.java @@ -38,29 +38,12 @@ import org.beetl.core.statement.GrammarToken; import org.intellij.lang.annotations.MagicConstant; /** - * 用于算数表达式,对于加法,允许null值,但其他则不允许,将抛出异常 - * 参考了webit + * 用于算数表达式,对于加法,允许null值,但其他则不允许,将抛出异常 参考了webit * * @author xiandafu */ public class ALU { - public static final int NULL = 0; - public static final int OBJECT = 1; - public static final int STRING = 2; - public static final int DOUBLE = 3; - public static final int FLOAT = 4; - public static final int LONG = 5; - public static final int INTEGER = 6; - public static final int SHORT = 7; - public static final int CHAR = 8; - public static final int BIG_DECIMAL = 9; - - @MagicConstant(intValues = {NULL, OBJECT, STRING, DOUBLE, FLOAT, LONG, INTEGER, SHORT, CHAR, BIG_DECIMAL}) - @Retention(RetentionPolicy.SOURCE) - public @interface AluType { - } - public static int scale = 12; public static int round = BigDecimal.ROUND_HALF_DOWN; @@ -74,30 +57,30 @@ public class ALU { @AluType public static int getAluType(final Object left, final Object right) { if (left == null || right == null) { - return NULL; + return AluType.NULL; } final Class cls1 = left.getClass(); final Class cls2 = right.getClass(); if (cls1 == Character.class && cls2 == Character.class) { - return CHAR; + return AluType.CHAR; } else if (left instanceof Number && right instanceof Number) { if (cls1 == BigDecimal.class || cls2 == BigDecimal.class) { - return BIG_DECIMAL; + return AluType.BIG_DECIMAL; } else if (cls1 == Double.class || cls2 == Double.class) { - return DOUBLE; + return AluType.DOUBLE; } else if (cls1 == Float.class || cls2 == Float.class) { - return FLOAT; + return AluType.FLOAT; } else if (cls1 == Long.class || cls2 == Long.class) { - return LONG; + return AluType.LONG; } else if (cls1 == Integer.class || cls2 == Integer.class) { - return INTEGER; + return AluType.INTEGER; } else if (cls1 == Short.class || cls2 == Short.class) { - return SHORT; + return AluType.SHORT; } } - return STRING; + return AluType.STRING; } /** @@ -110,27 +93,27 @@ public class ALU { @AluType public static int getAluType(Class cls1, Class cls2) { if (cls1 == String.class || cls2 == String.class) { - return STRING; + return AluType.STRING; } if (cls1 == Character.class && cls2 == Character.class) { - return CHAR; + return AluType.CHAR; } if (Number.class.isAssignableFrom(cls1) && Number.class.isAssignableFrom(cls2)) { if (cls1 == BigDecimal.class || cls2 == BigDecimal.class) { - return BIG_DECIMAL; + return AluType.BIG_DECIMAL; } else if (cls1 == Double.class || cls2 == Double.class) { - return DOUBLE; + return AluType.DOUBLE; } else if (cls1 == Float.class || cls2 == Float.class) { - return FLOAT; + return AluType.FLOAT; } else if (cls1 == Long.class || cls2 == Long.class) { - return LONG; + return AluType.LONG; } else if (cls1 == Integer.class || cls2 == Integer.class) { - return INTEGER; + return AluType.INTEGER; } else if (cls1 == Short.class || cls2 == Short.class) { - return SHORT; + return AluType.SHORT; } } - return OBJECT; + return AluType.OBJECT; } /** @@ -144,19 +127,19 @@ public class ALU { public static Class getBaseTypeClass(Class cls1, Class cls2) { int type = getAluType(cls1, cls2); switch (type) { - case INTEGER: + case AluType.INTEGER: return Integer.class; - case STRING: + case AluType.STRING: return String.class; - case LONG: + case AluType.LONG: return Long.class; - case DOUBLE: + case AluType.DOUBLE: return Double.class; - case FLOAT: + case AluType.FLOAT: return Float.class; - case SHORT: + case AluType.SHORT: return Short.class; - case BIG_DECIMAL: + case AluType.BIG_DECIMAL: return BigDecimal.class; default: return Object.class; @@ -171,23 +154,23 @@ public class ALU { */ public static int getNumberType(final Number num) { if (num == null) { - return NULL; + return AluType.NULL; } final Class cls = num.getClass(); if (cls == Integer.class) { - return INTEGER; + return AluType.INTEGER; } else if (cls == Long.class) { - return LONG; + return AluType.LONG; } else if (cls == Short.class) { - return SHORT; + return AluType.SHORT; } else if (cls == Float.class) { - return FLOAT; + return AluType.FLOAT; } else if (cls == Double.class) { - return DOUBLE; + return AluType.DOUBLE; } else if (cls == BigDecimal.class) { - return BIG_DECIMAL; + return AluType.BIG_DECIMAL; } - return NULL; + return AluType.NULL; } /** @@ -198,27 +181,27 @@ public class ALU { */ public static int getAluType(final Object obj) { if (obj == null) { - return NULL; + return AluType.NULL; } final Class cls = obj.getClass(); if (cls == String.class) { - return STRING; + return AluType.STRING; } else if (cls == Integer.class) { - return INTEGER; + return AluType.INTEGER; } else if (cls == Long.class) { - return LONG; + return AluType.LONG; } else if (cls == Short.class) { - return SHORT; + return AluType.SHORT; } else if (cls == Float.class) { - return FLOAT; + return AluType.FLOAT; } else if (cls == Double.class) { - return DOUBLE; + return AluType.DOUBLE; } else if (cls == Character.class) { - return CHAR; + return AluType.CHAR; } else if (cls == BigDecimal.class) { - return BIG_DECIMAL; + return AluType.BIG_DECIMAL; } - return OBJECT; + return AluType.OBJECT; } /** @@ -233,17 +216,17 @@ public class ALU { if (obj instanceof Number) { final Number num = (Number) obj; switch (getNumberType(num)) { - case INTEGER: + case AluType.INTEGER: return Integer.valueOf(num.intValue() + 1); - case LONG: + case AluType.LONG: return Long.valueOf(num.longValue() + 1L); - case DOUBLE: + case AluType.DOUBLE: return Double.valueOf(num.doubleValue() + 1D); - case FLOAT: + case AluType.FLOAT: return Float.valueOf(num.floatValue() + 1F); - case SHORT: + case AluType.SHORT: return Short.valueOf((short) (num.intValue() + 1)); - case BIG_DECIMAL: + case AluType.BIG_DECIMAL: BigDecimal bd = (BigDecimal) obj; return bd.add(BigDecimal.ONE); } @@ -266,17 +249,17 @@ public class ALU { if (obj instanceof Number) { final Number num = (Number) obj; switch (getNumberType(num)) { - case INTEGER: + case AluType.INTEGER: return Integer.valueOf(num.intValue() - 1); - case LONG: + case AluType.LONG: return Long.valueOf(num.longValue() - 1l); - case DOUBLE: + case AluType.DOUBLE: return Double.valueOf(num.doubleValue() - 1d); - case FLOAT: + case AluType.FLOAT: return Float.valueOf(num.floatValue() - 1f); - case SHORT: + case AluType.SHORT: return Short.valueOf((short) (num.intValue() - 1)); - case BIG_DECIMAL: + case AluType.BIG_DECIMAL: BigDecimal bd = (BigDecimal) obj; return bd.min(BigDecimal.ONE); } @@ -299,21 +282,21 @@ public class ALU { public static Object plus(final Object o1, final Object o2, final ASTNode node1, final ASTNode node2) { if (o1 != null && o2 != null) { switch (getAluType(o1, o2)) { - case STRING: + case AluType.STRING: return String.valueOf(o1).concat(String.valueOf(o2)); - case INTEGER: + case AluType.INTEGER: return Integer.valueOf(((Number) o1).intValue() + ((Number) o2).intValue()); - case LONG: + case AluType.LONG: return Long.valueOf(((Number) o1).longValue() + ((Number) o2).longValue()); - case DOUBLE: + case AluType.DOUBLE: return Double.valueOf(((Number) o1).doubleValue() + ((Number) o2).doubleValue()); - case FLOAT: + case AluType.FLOAT: return Float.valueOf(((Number) o1).floatValue() + ((Number) o2).floatValue()); - case SHORT: + case AluType.SHORT: return Short.valueOf((short) (((Number) o1).intValue() + ((Number) o2).intValue())); - case CHAR: + case AluType.CHAR: return Character.valueOf((char) (((Number) o1).intValue() + ((Number) o2).intValue())); - case BIG_DECIMAL: + case AluType.BIG_DECIMAL: BigDecimal b1 = getBigDecimal(o1); BigDecimal b2 = getBigDecimal(o2); return b1.add(b2); @@ -321,12 +304,12 @@ public class ALU { throw UnsupportedTypeException(o1, o2, node1, node2, "+"); } } else if (o1 != null) { - if (getAluType(o1) == STRING) { + if (getAluType(o1) == AluType.STRING) { return o1; } throw valueIsNullException(o1, o2, node1, node2); } else if (o2 != null) { - if (getAluType(o2) == STRING) { + if (getAluType(o2) == AluType.STRING) { return o2; } throw valueIsNullException(o1, o2, node1, node2); @@ -349,19 +332,19 @@ public class ALU { switch (getAluType(o1, o2)) { // case STRING: // return String.valueOf(o1) + String.valueOf(o2); - case INTEGER: + case AluType.INTEGER: return Integer.valueOf(((Number) o1).intValue() - ((Number) o2).intValue()); - case LONG: + case AluType.LONG: return Long.valueOf(((Number) o1).longValue() - ((Number) o2).longValue()); - case DOUBLE: + case AluType.DOUBLE: return Double.valueOf(((Number) o1).doubleValue() - ((Number) o2).doubleValue()); - case FLOAT: + case AluType.FLOAT: return Float.valueOf(((Number) o1).floatValue() - ((Number) o2).floatValue()); - case SHORT: + case AluType.SHORT: return Short.valueOf((short) (((Number) o1).intValue() - ((Number) o2).intValue())); - case CHAR: + case AluType.CHAR: return Character.valueOf((char) (((Number) o1).intValue() - ((Number) o2).intValue())); - case BIG_DECIMAL: + case AluType.BIG_DECIMAL: BigDecimal b1 = getBigDecimal(o1); BigDecimal b2 = getBigDecimal(o2); return b1.subtract(b2); @@ -385,17 +368,17 @@ public class ALU { switch (getAluType(o1)) { // case STRING: // return String.valueOf(o1) + String.valueOf(o2); - case INTEGER: + case AluType.INTEGER: return -((Number) o1).intValue(); - case LONG: + case AluType.LONG: return -((Number) o1).longValue(); - case DOUBLE: + case AluType.DOUBLE: return -((Number) o1).doubleValue(); - case FLOAT: + case AluType.FLOAT: return -((Number) o1).floatValue(); - case SHORT: + case AluType.SHORT: return -((Number) o1).shortValue(); - case BIG_DECIMAL: + case AluType.BIG_DECIMAL: return ((BigDecimal) o1).negate(); default: throw new RuntimeException("value not a number"); @@ -419,17 +402,17 @@ public class ALU { switch (getAluType(o1, o2)) { // case STRING: // return String.valueOf(o1) + String.valueOf(o2); - case INTEGER: + case AluType.INTEGER: return Integer.valueOf(((Number) o1).intValue() * ((Number) o2).intValue()); - case LONG: + case AluType.LONG: return Long.valueOf(((Number) o1).longValue() * ((Number) o2).longValue()); - case DOUBLE: + case AluType.DOUBLE: return Double.valueOf(((Number) o1).doubleValue() * ((Number) o2).doubleValue()); - case FLOAT: + case AluType.FLOAT: return Float.valueOf(((Number) o1).floatValue() * ((Number) o2).floatValue()); - case SHORT: + case AluType.SHORT: return Short.valueOf((short) (((Number) o1).intValue() * ((Number) o2).intValue())); - case BIG_DECIMAL: + case AluType.BIG_DECIMAL: BigDecimal b1 = getBigDecimal(o1); BigDecimal b2 = getBigDecimal(o2); return b1.multiply(b2); @@ -453,18 +436,18 @@ public class ALU { public static Object div(final Object o1, final Object o2, final ASTNode node1, final ASTNode node2) { if (o1 != null && o2 != null) { switch (getAluType(o1, o2)) { - case INTEGER: - case LONG: - case DOUBLE: - case FLOAT: - case SHORT: + case AluType.INTEGER: + case AluType.LONG: + case AluType.DOUBLE: + case AluType.FLOAT: + case AluType.SHORT: double c = ((Number) o2).doubleValue(); if (c == 0) { throw new BeetlException(BeetlErrorCode.Default.DIV_ZERO_ERROR).pushToken(node2.token); } double a = ((Number) o1).doubleValue() / ((Number) o2).doubleValue(); return trim(a, (Number) o1, (Number) o2); - case BIG_DECIMAL: + case AluType.BIG_DECIMAL: BigDecimal b1 = getBigDecimal(o1), b2 = getBigDecimal(o2); BigDecimal b = b1.divide(b2, scale, round); @@ -518,17 +501,17 @@ public class ALU { switch (getAluType(o1, o2)) { // case STRING: // return String.valueOf(o1) + String.valueOf(o2); - case INTEGER: + case AluType.INTEGER: return Integer.valueOf(((Number) o1).intValue() % ((Number) o2).intValue()); - case LONG: + case AluType.LONG: return Long.valueOf(((Number) o1).longValue() % ((Number) o2).longValue()); - case DOUBLE: + case AluType.DOUBLE: return Double.valueOf(((Number) o1).doubleValue() % ((Number) o2).doubleValue()); - case FLOAT: + case AluType.FLOAT: return Float.valueOf(((Number) o1).floatValue() % ((Number) o2).floatValue()); - case SHORT: + case AluType.SHORT: return Short.valueOf((short) (((Number) o1).intValue() % ((Number) o2).intValue())); - case BIG_DECIMAL: + case AluType.BIG_DECIMAL: BigDecimal b1 = getBigDecimal(o1), b2 = getBigDecimal(o2); return b1.divide(b2); @@ -555,17 +538,17 @@ public class ALU { // case STRING: // case CHAR: - case SHORT: - case INTEGER: + case AluType.SHORT: + case AluType.INTEGER: return ((Number) o1).intValue() == ((Number) o2).intValue(); - case LONG: + case AluType.LONG: return ((Number) o1).longValue() == ((Number) o2).longValue(); - case DOUBLE: + case AluType.DOUBLE: return ((Number) o1).doubleValue() == ((Number) o2).doubleValue(); - case FLOAT: + case AluType.FLOAT: return ((Number) o1).floatValue() == ((Number) o2).floatValue(); - case BIG_DECIMAL: + case AluType.BIG_DECIMAL: BigDecimal b1 = getBigDecimal(o1), b2 = getBigDecimal(o2); return b1.compareTo(b2) == 0; @@ -590,20 +573,20 @@ public class ALU { if (o1 != null && o2 != null) { switch (getAluType(o1, o2)) { // case STRING: - case CHAR: + case AluType.CHAR: return (o1 instanceof Number ? ((Number) o1).intValue() : (int) ((Character) o1).charValue()) > (o2 instanceof Number ? ((Number) o2) .intValue() : (int) ((Character) o2).charValue()); - case SHORT: - case INTEGER: + case AluType.SHORT: + case AluType.INTEGER: return ((Number) o1).intValue() > ((Number) o2).intValue(); - case LONG: + case AluType.LONG: return ((Number) o1).longValue() > ((Number) o2).longValue(); - case DOUBLE: + case AluType.DOUBLE: return ((Number) o1).doubleValue() > ((Number) o2).doubleValue(); - case FLOAT: + case AluType.FLOAT: return ((Number) o1).floatValue() > ((Number) o2).floatValue(); - case BIG_DECIMAL: + case AluType.BIG_DECIMAL: BigDecimal b1 = getBigDecimal(o1), b2 = getBigDecimal(o2); return b1.compareTo(b2) > 0; @@ -626,20 +609,20 @@ public class ALU { if (o1 != null && o2 != null) { switch (getAluType(o1, o2)) { // case STRING: - case CHAR: + case AluType.CHAR: return (o1 instanceof Number ? ((Number) o1).intValue() : (int) ((Character) o1).charValue()) >= (o2 instanceof Number ? ((Number) o2) .intValue() : (int) ((Character) o2).charValue()); - case SHORT: - case INTEGER: + case AluType.SHORT: + case AluType.INTEGER: return ((Number) o1).intValue() >= ((Number) o2).intValue(); - case LONG: + case AluType.LONG: return ((Number) o1).longValue() >= ((Number) o2).longValue(); - case DOUBLE: + case AluType.DOUBLE: return ((Number) o1).doubleValue() >= ((Number) o2).doubleValue(); - case FLOAT: + case AluType.FLOAT: return ((Number) o1).floatValue() >= ((Number) o2).floatValue(); - case BIG_DECIMAL: + case AluType.BIG_DECIMAL: BigDecimal b1 = getBigDecimal(o1), b2 = getBigDecimal(o2); return b1.compareTo(b2) >= 0; @@ -662,20 +645,20 @@ public class ALU { if (o1 != null && o2 != null) { switch (getAluType(o1, o2)) { // case STRING: - case CHAR: + case AluType.CHAR: return (o1 instanceof Number ? ((Number) o1).intValue() : (int) ((Character) o1).charValue()) < (o2 instanceof Number ? ((Number) o2) .intValue() : (int) ((Character) o2).charValue()); - case SHORT: - case INTEGER: + case AluType.SHORT: + case AluType.INTEGER: return ((Number) o1).intValue() < ((Number) o2).intValue(); - case LONG: + case AluType.LONG: return ((Number) o1).longValue() < ((Number) o2).longValue(); - case DOUBLE: + case AluType.DOUBLE: return ((Number) o1).doubleValue() < ((Number) o2).doubleValue(); - case FLOAT: + case AluType.FLOAT: return ((Number) o1).floatValue() < ((Number) o2).floatValue(); - case BIG_DECIMAL: + case AluType.BIG_DECIMAL: BigDecimal b1 = getBigDecimal(o1), b2 = getBigDecimal(o2); return b1.compareTo(b2) < 0; @@ -698,20 +681,20 @@ public class ALU { if (o1 != null && o2 != null) { switch (getAluType(o1, o2)) { // case STRING: - case CHAR: + case AluType.CHAR: return (o1 instanceof Number ? ((Number) o1).intValue() : (int) ((Character) o1).charValue()) <= (o2 instanceof Number ? ((Number) o2) .intValue() : (int) ((Character) o2).charValue()); - case SHORT: - case INTEGER: + case AluType.SHORT: + case AluType.INTEGER: return ((Number) o1).intValue() <= ((Number) o2).intValue(); - case LONG: + case AluType.LONG: return ((Number) o1).longValue() <= ((Number) o2).longValue(); - case DOUBLE: + case AluType.DOUBLE: return ((Number) o1).doubleValue() <= ((Number) o2).doubleValue(); - case FLOAT: + case AluType.FLOAT: return ((Number) o1).floatValue() <= ((Number) o2).floatValue(); - case BIG_DECIMAL: + case AluType.BIG_DECIMAL: BigDecimal b1 = getBigDecimal(o1), b2 = getBigDecimal(o2); return b1.compareTo(b2) <= 0; @@ -796,4 +779,30 @@ public class ALU { .pushToken(node.token); } } + + @MagicConstant(intValues = { + AluType.NULL, + AluType.OBJECT, + AluType.STRING, + AluType.DOUBLE, + AluType.FLOAT, + AluType.LONG, + AluType.INTEGER, + AluType.SHORT, + AluType.CHAR, + AluType.BIG_DECIMAL + }) + @Retention(RetentionPolicy.SOURCE) + @interface AluType { + int NULL = 0; + int OBJECT = 1; + int STRING = 2; + int DOUBLE = 3; + int FLOAT = 4; + int LONG = 5; + int INTEGER = 6; + int SHORT = 7; + int CHAR = 8; + int BIG_DECIMAL = 9; + } } -- Gitee From 3bc4d4d62ecc82558a3d8258f0c7c4c0d4fb3486 Mon Sep 17 00:00:00 2001 From: zhaoxuyang03 Date: Sun, 14 Mar 2021 21:28:42 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E3=80=90Sprint3.3.3=E3=80=91=E3=80=90Bee?= =?UTF-8?q?tl=E3=80=91JsonTool-=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/impl/json/BeetlJsonFactory.java | 52 +++++++++++++++++++ .../{misc => impl/json}/FastJsonTool.java | 6 +-- .../core/{misc => impl/json}/JacksonTool.java | 5 +- .../java/org/beetl/core/misc/JsonFactory.java | 35 ------------- .../JsonTool.java => runtime/IJsonTool.java} | 4 +- .../beetl/ext/fn/AllGlobaAsJsonlFunction.java | 4 +- src/main/java/org/beetl/ext/fn/Json.java | 7 +-- 7 files changed, 64 insertions(+), 49 deletions(-) create mode 100644 src/main/java/org/beetl/core/impl/json/BeetlJsonFactory.java rename src/main/java/org/beetl/core/{misc => impl/json}/FastJsonTool.java (72%) rename src/main/java/org/beetl/core/{misc => impl/json}/JacksonTool.java (80%) delete mode 100644 src/main/java/org/beetl/core/misc/JsonFactory.java rename src/main/java/org/beetl/core/{misc/JsonTool.java => runtime/IJsonTool.java} (77%) diff --git a/src/main/java/org/beetl/core/impl/json/BeetlJsonFactory.java b/src/main/java/org/beetl/core/impl/json/BeetlJsonFactory.java new file mode 100644 index 0000000..6695327 --- /dev/null +++ b/src/main/java/org/beetl/core/impl/json/BeetlJsonFactory.java @@ -0,0 +1,52 @@ +package org.beetl.core.impl.json; + +import org.beetl.android.util.Log; +import org.beetl.core.runtime.BeetlRuntime; +import org.beetl.core.runtime.IJsonTool; + +/** + * 用于加载 JSON 序列化工具的工厂类 预置 {@link JacksonTool} 和 {@link FastJsonTool} + */ +public class BeetlJsonFactory { + + /** Debug flag */ + private static final boolean DEBUG = BeetlRuntime.getConfigManager().isDebug(); + /** Log TAG */ + private static final String TAG = "BeetlJsonFactory"; + + /** JSON 序列化工具的实例 */ + static IJsonTool sTool = null; + + static { + try { + sTool = new JacksonTool(); + } catch (Throwable ex) { // 类不加载 + if (DEBUG) { + Log.d(TAG, "JacksonTool 实例化异常\n" + ex); + } + } + if (sTool == null) { + try { + sTool = new FastJsonTool(); + } catch (Throwable ex) { // 类不加载 + if (DEBUG) { + Log.d(TAG, "FastJsonTool 实例化异常\n" + ex); + } + } + } + + if (sTool == null) { + throw new IllegalStateException("沒有对应的jackson或者fastjson库"); + } + + } + + /** + * 调用该方法后会对 BeetlJsonFactory 进行初始化 + * + * @return IJsonTool 的实例 + */ + public static IJsonTool get() { + return sTool; + } +} diff --git a/src/main/java/org/beetl/core/misc/FastJsonTool.java b/src/main/java/org/beetl/core/impl/json/FastJsonTool.java similarity index 72% rename from src/main/java/org/beetl/core/misc/FastJsonTool.java rename to src/main/java/org/beetl/core/impl/json/FastJsonTool.java index 6c023b9..e137b54 100644 --- a/src/main/java/org/beetl/core/misc/FastJsonTool.java +++ b/src/main/java/org/beetl/core/impl/json/FastJsonTool.java @@ -1,12 +1,12 @@ -package org.beetl.core.misc; +package org.beetl.core.impl.json; import com.alibaba.fastjson.JSON; - +import org.beetl.core.runtime.IJsonTool; /** * 封装了 Fastjson 的 JSON 序列化操作 */ -public class FastJsonTool implements JsonTool { +public class FastJsonTool implements IJsonTool { public FastJsonTool() { // just test FastJSON in classpath diff --git a/src/main/java/org/beetl/core/misc/JacksonTool.java b/src/main/java/org/beetl/core/impl/json/JacksonTool.java similarity index 80% rename from src/main/java/org/beetl/core/misc/JacksonTool.java rename to src/main/java/org/beetl/core/impl/json/JacksonTool.java index 334d66f..430d249 100644 --- a/src/main/java/org/beetl/core/misc/JacksonTool.java +++ b/src/main/java/org/beetl/core/impl/json/JacksonTool.java @@ -1,12 +1,13 @@ -package org.beetl.core.misc; +package org.beetl.core.impl.json; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import org.beetl.core.runtime.IJsonTool; /** * 封装了 Jackson 的 JSON 序列化操作 */ -public class JacksonTool implements JsonTool { +public class JacksonTool implements IJsonTool { /** Jackson 对 JSON 序列化时所需的实例 */ static ObjectMapper mapper = new ObjectMapper(); diff --git a/src/main/java/org/beetl/core/misc/JsonFactory.java b/src/main/java/org/beetl/core/misc/JsonFactory.java deleted file mode 100644 index 06d0348..0000000 --- a/src/main/java/org/beetl/core/misc/JsonFactory.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.beetl.core.misc; - -/** - * 用于加载 JSON 序列化工具的工厂类 - * 预置 {@link JacksonTool} 和 {@link FastJsonTool} - */ -public class JsonFactory { - - /** JSON 序列化工具的实例 */ - static JsonTool tool = null; - - static { - try { - tool = new JacksonTool(); - } catch (Throwable ex) { - // 类不加载 - } - if (tool == null) { - try { - tool = new FastJsonTool(); - } catch (Throwable ex) { - //类不加载 - } - } - - if (tool == null) { - throw new IllegalStateException("沒有对应的jackson或者fastjson库"); - } - - } - - public static JsonTool get() { - return tool; - } -} diff --git a/src/main/java/org/beetl/core/misc/JsonTool.java b/src/main/java/org/beetl/core/runtime/IJsonTool.java similarity index 77% rename from src/main/java/org/beetl/core/misc/JsonTool.java rename to src/main/java/org/beetl/core/runtime/IJsonTool.java index 45d4022..480c43e 100644 --- a/src/main/java/org/beetl/core/misc/JsonTool.java +++ b/src/main/java/org/beetl/core/runtime/IJsonTool.java @@ -1,9 +1,9 @@ -package org.beetl.core.misc; +package org.beetl.core.runtime; /** * JSON 序列化的抽象 */ -public interface JsonTool { +public interface IJsonTool { /** * 将 {@param object} 渲染成JSON字符串 * diff --git a/src/main/java/org/beetl/ext/fn/AllGlobaAsJsonlFunction.java b/src/main/java/org/beetl/ext/fn/AllGlobaAsJsonlFunction.java index ef83a64..88fa65f 100644 --- a/src/main/java/org/beetl/ext/fn/AllGlobaAsJsonlFunction.java +++ b/src/main/java/org/beetl/ext/fn/AllGlobaAsJsonlFunction.java @@ -2,11 +2,11 @@ package org.beetl.ext.fn; import org.beetl.core.Context; import org.beetl.core.Function; -import org.beetl.core.misc.JsonFactory; +import org.beetl.core.impl.json.BeetlJsonFactory; public class AllGlobaAsJsonlFunction implements Function { @Override public Object call(Object[] paras, Context ctx) { - return JsonFactory.get().render(ctx.globalVar); + return BeetlJsonFactory.get().render(ctx.globalVar); } } diff --git a/src/main/java/org/beetl/ext/fn/Json.java b/src/main/java/org/beetl/ext/fn/Json.java index a7aa2a1..13bc1b7 100644 --- a/src/main/java/org/beetl/ext/fn/Json.java +++ b/src/main/java/org/beetl/ext/fn/Json.java @@ -1,11 +1,8 @@ package org.beetl.ext.fn; -import java.lang.reflect.Method; - import org.beetl.core.Context; import org.beetl.core.Function; -import org.beetl.core.exception.BeetlException; -import org.beetl.core.misc.JsonFactory; +import org.beetl.core.impl.json.BeetlJsonFactory; /** * 使用jackson或者fastjson 序列化对对象 @@ -15,7 +12,7 @@ public class Json implements Function { @Override public String call(Object[] paras, Context ctx) { Object object = paras[0]; - return object == null ? "" : JsonFactory.get().render(object); + return object == null ? "" : BeetlJsonFactory.get().render(object); } } -- Gitee From e0b8447c849d5386a30b54ed8a0ddae48bf12a32 Mon Sep 17 00:00:00 2001 From: zhaoxuyang03 Date: Sun, 14 Mar 2021 21:34:42 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E3=80=90Sprint3.3.3=E3=80=91=E3=80=90Bee?= =?UTF-8?q?tl=E3=80=91AttributeNameConvert-=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/beetl/core/Configuration.java | 5 +++-- src/main/java/org/beetl/core/GroupTemplate.java | 8 ++++---- .../core/{ => impl}/text/DefaultAttributeNameConvert.java | 6 ++++-- .../IAttributeNameConvert.java} | 4 ++-- .../java/org/beetl/core/text/HTMLTagContentParser.java | 6 ++++-- src/main/java/org/beetl/core/text/TextParser.java | 4 +++- .../resources/org/beetl/core/beetl-default.properties | 2 +- 7 files changed, 21 insertions(+), 14 deletions(-) rename src/main/java/org/beetl/core/{ => impl}/text/DefaultAttributeNameConvert.java (82%) rename src/main/java/org/beetl/core/{text/AttributeNameConvert.java => runtime/IAttributeNameConvert.java} (34%) diff --git a/src/main/java/org/beetl/core/Configuration.java b/src/main/java/org/beetl/core/Configuration.java index 213467d..4e407c6 100644 --- a/src/main/java/org/beetl/core/Configuration.java +++ b/src/main/java/org/beetl/core/Configuration.java @@ -41,6 +41,7 @@ import java.util.Properties; import java.util.Set; import org.beetl.android.text.TextUtils; +import org.beetl.core.impl.text.DefaultAttributeNameConvert; import org.beetl.core.text.HtmlTagConfig; import org.beetl.core.text.PlaceHolderDelimeter; import org.beetl.core.text.ScriptDelimeter; @@ -99,8 +100,8 @@ public class Configuration { /** html 绑定的属性,如<aa var="customer"> */ String htmlTagBindingAttribute = "var"; - /** {@link org.beetl.core.text.DefaultAttributeNameConvert} */ - String htmlTagAttributeConvert = "org.beetl.core.text.DefaultAttributeNameConvert"; + /** {@link DefaultAttributeNameConvert} */ + String htmlTagAttributeConvert = "org.beetl.core.impl.text.DefaultAttributeNameConvert"; /** 类搜索的包名列表 */ Set pkgList = new HashSet<>(); diff --git a/src/main/java/org/beetl/core/GroupTemplate.java b/src/main/java/org/beetl/core/GroupTemplate.java index cc171b2..00ab932 100644 --- a/src/main/java/org/beetl/core/GroupTemplate.java +++ b/src/main/java/org/beetl/core/GroupTemplate.java @@ -62,7 +62,7 @@ import org.beetl.core.runtime.IResourceLoader; import org.beetl.core.statement.ErrorGrammarProgram; import org.beetl.core.statement.Program; import org.beetl.core.runtime.ITagFactory; -import org.beetl.core.text.AttributeNameConvert; +import org.beetl.core.runtime.IAttributeNameConvert; import org.beetl.core.text.TextParser; /** @@ -109,7 +109,7 @@ public class GroupTemplate { /** 缓冲区 */ ContextLocalBuffers buffers = null; /** 用于解析html tag得属性,转化为符合js变量名字 */ - AttributeNameConvert htmlTagAttrNameConvert = null; + IAttributeNameConvert htmlTagAttrNameConvert = null; /** * 使用默认的配置和默认的模板资源加载器{@link ClasspathResourceLoader}, @@ -194,7 +194,7 @@ public class GroupTemplate { errorHandler = (ErrorHandler) ObjectUtil.instance(conf.errorHandlerClass, classLoader); } - htmlTagAttrNameConvert = (AttributeNameConvert) ObjectUtil.instance(conf.htmlTagAttributeConvert, classLoader); + htmlTagAttrNameConvert = (IAttributeNameConvert) ObjectUtil.instance(conf.htmlTagAttributeConvert, classLoader); } protected void initFunction() { @@ -810,7 +810,7 @@ public class GroupTemplate { } } - public AttributeNameConvert getHtmlTagAttrNameConvert() { + public IAttributeNameConvert getHtmlTagAttrNameConvert() { return htmlTagAttrNameConvert; } } diff --git a/src/main/java/org/beetl/core/text/DefaultAttributeNameConvert.java b/src/main/java/org/beetl/core/impl/text/DefaultAttributeNameConvert.java similarity index 82% rename from src/main/java/org/beetl/core/text/DefaultAttributeNameConvert.java rename to src/main/java/org/beetl/core/impl/text/DefaultAttributeNameConvert.java index c37f797..99ed5d6 100644 --- a/src/main/java/org/beetl/core/text/DefaultAttributeNameConvert.java +++ b/src/main/java/org/beetl/core/impl/text/DefaultAttributeNameConvert.java @@ -1,11 +1,13 @@ -package org.beetl.core.text; +package org.beetl.core.impl.text; + +import org.beetl.core.runtime.IAttributeNameConvert; /** * html标签的属性名转为为变量名字 ,user-provider 转化userProvider * * @author xiandafu */ -public class DefaultAttributeNameConvert implements AttributeNameConvert { +public class DefaultAttributeNameConvert implements IAttributeNameConvert { @Override public String convert(String orginal) { diff --git a/src/main/java/org/beetl/core/text/AttributeNameConvert.java b/src/main/java/org/beetl/core/runtime/IAttributeNameConvert.java similarity index 34% rename from src/main/java/org/beetl/core/text/AttributeNameConvert.java rename to src/main/java/org/beetl/core/runtime/IAttributeNameConvert.java index e2dceac..5afd8ce 100644 --- a/src/main/java/org/beetl/core/text/AttributeNameConvert.java +++ b/src/main/java/org/beetl/core/runtime/IAttributeNameConvert.java @@ -1,5 +1,5 @@ -package org.beetl.core.text; +package org.beetl.core.runtime; -public interface AttributeNameConvert { +public interface IAttributeNameConvert { String convert(String orginal); } diff --git a/src/main/java/org/beetl/core/text/HTMLTagContentParser.java b/src/main/java/org/beetl/core/text/HTMLTagContentParser.java index 83203dd..0da1c29 100644 --- a/src/main/java/org/beetl/core/text/HTMLTagContentParser.java +++ b/src/main/java/org/beetl/core/text/HTMLTagContentParser.java @@ -28,6 +28,8 @@ package org.beetl.core.text; import org.beetl.android.util.Log; +import org.beetl.core.impl.text.DefaultAttributeNameConvert; +import org.beetl.core.runtime.IAttributeNameConvert; import java.util.*; @@ -69,9 +71,9 @@ class HTMLTagContentParser { static char[] ENT_TAGS = new char[] {'/', '>'}; - AttributeNameConvert attributeNameConvert = null; + IAttributeNameConvert attributeNameConvert = null; - public HTMLTagContentParser(AttributeNameConvert attributeNameConvert, char[] cs, int index, String bindingAttr, boolean isStart) { + public HTMLTagContentParser(IAttributeNameConvert attributeNameConvert, char[] cs, int index, String bindingAttr, boolean isStart) { this.attributeNameConvert = attributeNameConvert; this.cs = cs; parseBindingAttr(bindingAttr); diff --git a/src/main/java/org/beetl/core/text/TextParser.java b/src/main/java/org/beetl/core/text/TextParser.java index 1ecf971..f59f18c 100644 --- a/src/main/java/org/beetl/core/text/TextParser.java +++ b/src/main/java/org/beetl/core/text/TextParser.java @@ -4,6 +4,8 @@ import org.beetl.core.Configuration; import org.beetl.core.GroupTemplate; import org.beetl.core.config.BeetlConfig; import org.beetl.android.util.Log; +import org.beetl.core.impl.text.DefaultAttributeNameConvert; +import org.beetl.core.runtime.IAttributeNameConvert; import java.io.BufferedReader; import java.io.IOException; @@ -40,7 +42,7 @@ public class TextParser { //文本里的回车 String textCr = null; - AttributeNameConvert attributeNameConvert; + IAttributeNameConvert attributeNameConvert; public TextParser(GroupTemplate groupTemplate, Configuration.DelimeterHolder pdConfig, diff --git a/src/main/resources/org/beetl/core/beetl-default.properties b/src/main/resources/org/beetl/core/beetl-default.properties index c525388..8c84539 100644 --- a/src/main/resources/org/beetl/core/beetl-default.properties +++ b/src/main/resources/org/beetl/core/beetl-default.properties @@ -8,7 +8,7 @@ DIRECT_BYTE_OUTPUT = false HTML_TAG_SUPPORT = true HTML_TAG_FLAG = # HTML_TAG_BINDING_ATTRIBUTE = var,export -HTML_TAG_ATTR_CONVERT=org.beetl.core.text.DefaultAttributeNameConvert +HTML_TAG_ATTR_CONVERT=org.beetl.core.impl.text.DefaultAttributeNameConvert NATIVE_CALL = true TEMPLATE_CHARSET = UTF-8 ERROR_HANDLER = org.beetl.core.ConsoleErrorHandler -- Gitee