first commit
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="test"/>
|
||||
<classpathentry kind="lib" path="lib/zhiqim.jar" sourcepath="libsrc/zhiqim-src.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1 @@
|
||||
/bin
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>zhiqim_zml</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,13 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. [http://fsf.org/]
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
@@ -0,0 +1,255 @@
|
||||
### 什么是“ZML”?
|
||||
---------------------------------------
|
||||
ZML(Zhiqim Markup Language)即“知启蒙标记语言”,是知启蒙定义的、类似于Java & Javascript语法的语句和表达式,通常和XML/HTML混编在一起形成的一种新的标记语言。ZML力求简单易用,目前支持常用的十二种标记语句和五十种表达式,在知启蒙框架体系中被用来代替JSP。
|
||||
|
||||
<br>
|
||||
|
||||
### 什么是“ZML引擎”?
|
||||
---------------------------------------
|
||||
ZML引擎(ZhiqimZML)即“知启蒙标识语言引擎”,是实现ZML规范的引擎系统。支持两种ZML加载方式(按文件目录和按类路径)、能够在ZML文件改动后立即发现并在触发时重新加载、并提供详细的“表达式合并运算优先级”、“变量多维作用域”和“无障碍访问Java代码”,以及设置上下文作用域的配置模板、对模板进行缓存等特性。
|
||||
|
||||
<br>
|
||||
|
||||
### “ZML引擎”有哪些优点?
|
||||
---------------------------------------
|
||||
1、ZhiqimZML仅依赖JDK1.7+和ZhiqimKernel。15年的坚持,值得信赖。<br>
|
||||
2、ZhiqimZML支持十二种语句和五十种表达式基本覆盖业务操作,是[知启蒙WEB容器](https://gitee.com/zhiqim/zhiqim_httpd)的重要组成部分,在ZhiqimDK家族中占据非常重要的位置。<br>
|
||||
3、对比国外模板引擎Freemarker和Velocity,ZhiqimZML更有优势,结合[知启蒙微内核](https://gitee.com/zhiqim/zhiqim_kernel)的大量工具类(如Strings/Validatest),使得ZhiqimZML可无障碍访问Java代码,称之为Java的标识语言都不为过。<br>
|
||||
4、最后**自荐一下**,比Spring更轻量、更齐全的J2EE框架 **zhiqim** 正式开源啦,不服来试用。
|
||||
|
||||
<br>
|
||||
|
||||
### 最简单的ZML引擎使用方法
|
||||
---------------------------------------
|
||||
<table style="border-collapse:collapse; border:1px solid #333; height:400px; width:100%">
|
||||
<tr>
|
||||
<td bgcolor="#e1ffff">
|
||||
1、准备好一段符合ZML规格的字符串,和一个变量表,即可解析出结果。<br>
|
||||
2、支持全局变量表中@AnAlias注解别名表和预定义Java类名的静态变量和静态方法调用。<br>
|
||||
3、详细见org.zhiqim.zml.Zmls静态类中的方法,如下提供的parse方法。
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td>
|
||||
<img src="https://images.gitee.com/uploads/images/2018/0907/181507_d7a655a3_2103954.png">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
|
||||
### ZML支持的十二种语句 <a href="https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml/tutorial/primitive.htm">前往五十种表达式</a>
|
||||
---------------------------------------
|
||||
一、变量定义语句(_Var)<br>
|
||||
```
|
||||
<#var name = "知启蒙模板引擎"/>
|
||||
|
||||
表示定义变量name的值为“知启蒙模板引擎”。
|
||||
```
|
||||
二、函数定义语句(_Function)
|
||||
```
|
||||
<#function functionName(param1, param2)>
|
||||
<div>param1 = ${param1}</div>
|
||||
<div>param2 = ${param2}</div>
|
||||
</#function>
|
||||
```
|
||||
三、文件包含语句(_Include)
|
||||
```
|
||||
<#include "/zml/inc.zml"/>
|
||||
|
||||
表示包含文件“/zml/inc.zml”的内容到该页面中。
|
||||
```
|
||||
四、判断语句(_If)
|
||||
```
|
||||
<#if (!Validates.isEmpty(name) && name.startWith("知启蒙"))>
|
||||
${name}
|
||||
</#if>
|
||||
```
|
||||
五、遍历语句(_For)
|
||||
```
|
||||
<#for (var item : list)>
|
||||
<#if (Validates.isNotEmpty(item))>
|
||||
${item}
|
||||
</#if>
|
||||
</#for>
|
||||
|
||||
简写:
|
||||
|
||||
<#for item : list>
|
||||
<#if (Validates.isNotEmpty(item))>
|
||||
${item}
|
||||
</#if>
|
||||
</#for>
|
||||
```
|
||||
六、拦截器语句(_Interceptor)
|
||||
```
|
||||
<#interceptor "chkLogin"/>
|
||||
|
||||
拦截器语句用于在执行之前判断是否支持定义的参数的值,如"chkLogin"表示是一个拦截器名称
|
||||
```
|
||||
七、显示结果语句(_Echo)
|
||||
```
|
||||
显示结果语句是通过连接、计算和合并的方式执行多个表达式,得到执行结果,然后把结果显示在页面上,值为(null)不显示结果,如:
|
||||
|
||||
<#var name = "知启蒙"/>
|
||||
|
||||
${name} 表示执行表达式name,得到结果“知启蒙”
|
||||
|
||||
${name + "引擎"} 表示执行表达式name + "引擎",得到结果“知启蒙引擎”
|
||||
|
||||
${functionName(name, "edf")} 表示调用函数并显示结果
|
||||
|
||||
${Strings.trimLeft(name, "知")} 表示类Strings的trimLeft方法,显示结果“启蒙”
|
||||
```
|
||||
八、显示格式化结果语句(_Format)
|
||||
```
|
||||
显示格式化结果语句是通过连接、计算和合并的方式执行多个表达式,得到执行结果,值为(null)不显示结果,<br>
|
||||
并对其他Zmls.format(zml)格式化,对<,>,\",\',${,@{,#{格式化,保证浏览器解释成字符串而不是ZML代码,如:
|
||||
|
||||
<#var name = "知${abc}启蒙"/>
|
||||
#{name} 表示执行表达式name,得到结果是“知${abc}启蒙”,$符号转为$
|
||||
|
||||
#{name + "引\"擎"} 表示执行表达式name + "引\"擎",得到结果“知${abc}启蒙引"擎”,$符号转为$,引号变成"
|
||||
|
||||
#{functionName(name, "edf")} 表示调用函数并显示结果
|
||||
|
||||
#{Strings.trimLeft(name, "知")} 表示类Strings的trimLeft方法,显示结果“${abc}启蒙”
|
||||
```
|
||||
九、调用不显示结果语句(_Call)
|
||||
```
|
||||
调用语句是通过连接、计算和合并的方式执行多个表达式,执行,但不显示结果到页面上,如:
|
||||
|
||||
@{System.out.println("显示信息到控制台,不是显示到页面")} 表示执行System.out.println();
|
||||
```
|
||||
十、返回语句(_Return)
|
||||
```
|
||||
返回语句应用于标识当前页执行结束,直接返回,和函数function中返回值:
|
||||
|
||||
<#if Validates.isEmpty(sessionKey)>
|
||||
<#return/>
|
||||
</#if>
|
||||
|
||||
<#function functionName(param1, param2)>
|
||||
<#var ret = param1+param2/>
|
||||
<#return ret/>
|
||||
</#function>
|
||||
```
|
||||
十一、继续语句(_Continue)
|
||||
```
|
||||
继续语句应用于_For语句中,表示结束当次处理,继续下一次:
|
||||
|
||||
<#for item : list>
|
||||
<#if (Validates.isNotEmpty(item))>
|
||||
<#continue/>
|
||||
</#if>
|
||||
</#for>
|
||||
```
|
||||
十二、中断语句(_Break)
|
||||
```
|
||||
<#for item : list>
|
||||
<#if (Validates.isNotEmpty(item))>
|
||||
<#break/>
|
||||
</#if>
|
||||
</#for>
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### 常用的ZML页面和ZML配置模板
|
||||
---------------------------------------
|
||||

|
||||

|
||||
<br>
|
||||
<br>
|
||||
|
||||
### 强大的ZML引擎解析文件
|
||||
---------------------------------------
|
||||
<table style="border-collapse:collapse; border:1px solid #333; height:400px; width:100%">
|
||||
<tr>
|
||||
<td colspan="3" class="z-bg-cyan">
|
||||
1、支持对文件目录/类路径加载配置定义的变量和函数到上下文变量表中,支持根据path查找ZML文件加载。<br>
|
||||
2、支持多个组件加载器,依次查找组件配置模板中定义的变量和函数到上下文变量表,和根据path查找的ZML文件加载。<br>
|
||||
3、支持自定义设置全局变量。<br>
|
||||
4、支持对ZML文件监视,有变动立即知晓,并在被触发时加载文件,如是配置模板会回调通知。<br>
|
||||
5、支持对ZML文件缓存,并提供缓存参数maxIdleTime/maxKeepTime。
|
||||
</td>
|
||||
</tr>
|
||||
<tr bgcolor="#f5f5f5">
|
||||
<td width="16%">参数</td>
|
||||
<td width="30%">参数类型</td>
|
||||
<td width="*">描述</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>notice</td>
|
||||
<td>ZmlVarNotice</td>
|
||||
<td>设置模板变量变动通知,当/conf/config.zml有变动并触发时回调doUpdate方法</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>encoding</td>
|
||||
<td>String</td>
|
||||
<td>模板加载编码</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>maxIdleTime</td>
|
||||
<td>int</td>
|
||||
<td>模板最大空闲时长,建议1小时</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>maxKeepTime</td>
|
||||
<td>int</td>
|
||||
<td>模板最大保持时长,建议24小时</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>isAscQuery</td>
|
||||
<td>boolean</td>
|
||||
<td>当有组件配置模板时,是否按顺序查找</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>patterns</td>
|
||||
<td>String</td>
|
||||
<td>模板匹配模式,默认*.zml,*.htm</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>loader</td>
|
||||
<td>ClassZmlLoader<br>FileZmlLoader</td>
|
||||
<td>设置根配置模板加载器,类路径/目录</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>cLoaderMap</td>
|
||||
<td>ClassZmlLoader</td>
|
||||
<td>组件配置模板加载器,类路径/目录,支持多个,<br>通过addComponentZmlLoader()添加</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>globalMap</td>
|
||||
<td>HashMap</td>
|
||||
<td>全局变量表,通过addGlobalVariable添加</td>
|
||||
</tr>
|
||||
<tr><td colspan="3">
|
||||
<span class="z-text-prewrap z-code zi-px16">
|
||||
|
||||
```
|
||||
//先创建ZML引擎,可以保存起来
|
||||
ZmlEngine engine = new ZmlEngine();
|
||||
engine.setFileZmlLoader(new File("./resource"));
|
||||
engine.setConfigZml("/conf/config.zml");
|
||||
|
||||
//调用和解析ZML文件
|
||||
Zml zml = engine.getZml("/zml/abc.zml");
|
||||
HashMapSO variableMap = new HashMapSO();
|
||||
variableMap.put("abc", "知启蒙");
|
||||
variableMap.put("def", "标识语言");
|
||||
variableMap.put("isAbc", false);
|
||||
|
||||
String result = Zmls.parese(zml, variableMap);
|
||||
```
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
|
||||
### 知启蒙技术框架与交流
|
||||
---------------------------------------
|
||||
<br><br>
|
||||
QQ群:加入QQ交流群,请点击[【458171582】](https://jq.qq.com/?_wv=1027&k=5DWlB3b) <br><br>
|
||||
教程:欲知更多知启蒙标识语言,[【请戳这里】](https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml/tutorial/index.htm)
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<section name="zhiqim">
|
||||
<section name="ExportJar">
|
||||
<item value="" key="excludeDirs"/>
|
||||
<item value="test" key="excludePackages"/>
|
||||
<item value="false" key="isDivided"/>
|
||||
<item value="true" key="isExportAndZipProject"/>
|
||||
<item value="true" key="isExportJavaSource"/>
|
||||
<item value="false" key="isIncludeJavaFile"/>
|
||||
<item value="zhiqim_zml" key="jarName"/>
|
||||
<item value="D:/_gitcan/ZhiqimDK/zhiqim_zml/document/metainfo" key="metaInfoPath"/>
|
||||
<item value="zhiqim_zml_v1.5.0" key="projectSourceName"/>
|
||||
<item value="D:/_gitee/zhiqim/V1.5.0/ZhiqimDK" key="releasePath"/>
|
||||
</section>
|
||||
</section>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<section name="zhiqim">
|
||||
<section name="ExportJar">
|
||||
<item value="" key="excludeDirs"/>
|
||||
<item value="test" key="excludePackages"/>
|
||||
<item value="false" key="isDivided"/>
|
||||
<item value="true" key="isExportAndZipProject"/>
|
||||
<item value="true" key="isIncludeJavaFile"/>
|
||||
<item value="zhiqim_zml" key="jarName"/>
|
||||
<item value="D:/_gitcan/ZhiqimDK/zhiqim_zml/document/metainfo" key="metaInfoPath"/>
|
||||
<item value="zhiqim_zml_v1.5.1" key="projectSourceName"/>
|
||||
<item value="D:/_gitee/zhiqim/V1.5.1/ZhiqimDK" key="releasePath"/>
|
||||
</section>
|
||||
</section>
|
||||
@@ -0,0 +1,15 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: ZhiqimML
|
||||
Bundle-SymbolicName: zhiqim_ml
|
||||
Bundle-Version: 1.5.0
|
||||
Export-Package: org.zhiqim.zml,
|
||||
org.zhiqim.zml.exception,
|
||||
org.zhiqim.zml.expression,
|
||||
org.zhiqim.zml.expression.operator,
|
||||
org.zhiqim.zml.expression.primitive,
|
||||
org.zhiqim.zml.expression.symbol,
|
||||
org.zhiqim.zml.loader,
|
||||
org.zhiqim.zml.statement
|
||||
Require-Bundle: zhiqim
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
@@ -0,0 +1,70 @@
|
||||
V1.1.0.R2015072901版本:从原V1.0的fadfox_httpd.jar中分离出来
|
||||
V1.1.0.R2015090201版本:根据fadfox整理成统一该版本
|
||||
V1.1.1.R2015091401版本:使用JDK1.7编译
|
||||
V1.1.2.R2015093001版本:要求使用V1.1.2版本的fadfox.jar
|
||||
V1.1.2.R2015102201版本:支持从AnStatic,AnGlobal,AnNew中读取系统变量
|
||||
V1.1.2.R2015102601版本:修改for语句方法
|
||||
V1.1.3.R2015112501版本:整理版本,用于生产系统
|
||||
V1.1.3.R2015122901版本:根据FTimer改动修改的版本
|
||||
V1.1.3.R2016020301版本:春节前整理版本号
|
||||
V1.1.4.R2016041701版本:增加<#include>
|
||||
V1.2.0.R2016072101版本:
|
||||
1)修改<#for>标签为<#for (item : list)>支持括号和<#for (var item : list)>严格模式
|
||||
2)增加new和.class表达式,以支持<#var abc = new Abc()/>和<#var list=Global.get(FTable.class).list(Abc.class)>
|
||||
3)增加<#interceptor>支持在ftm中写拦截器
|
||||
4)增加包和点号的参数的支持,如com.zhiqim.fadfox.Boot可以是包名,fadfox.manager可以是变量名,属性请使用["property"],如fadfox["key"]
|
||||
5)增加TemplateVarNotice,当上下文文件context.ftml有改动时,回调更新
|
||||
V1.2.1.R2016100801版本:
|
||||
1)增加TemplateEngine.hasTemplate方法,用于使用前先判断是否存在
|
||||
2)修改原后缀.ftml,.ftm为三个(.ftml,.ftm,.htm)
|
||||
3)增加<#def>语句,表<#var>类似用于定义变量,但<#def>会优先从include中执行
|
||||
4)修改${}原名_Apply,修改为_Echo,调用并显示结果,意思更清晰
|
||||
V1.2.2.R2017010101版本:
|
||||
1)配合fadfox.jar调整HashMap<String, Object>为FHashMapSO
|
||||
2)增加return,break,continue的支持,其中function支持<#return "result"/>带结果,template结果会强制转为字符串,for支持break,continue
|
||||
3)修改TemplateVariable为支持传入variableMap和contextMap数组(原功能写死只支持requestVariableMap和contextVariableMap)
|
||||
4)增加<#break> <#return>和<#continue>,完善了function,for,和if语句
|
||||
5)增加对类属性的支持,如variable.property时,如果variable是变量会判断是否有属性[property],但优先级低于本身[variable.property]是一个变量
|
||||
6)调整对类全称的支持,如com.zhiqim.fadfox.bootstrap.Global.get(Abc.class),会把(com.zhiqim.fadfox.bootstrap.Global)作为类名,为后续引入<#import>作准备
|
||||
7)增加Java.util和java.lang一些常用类,如String,List等作了全称和别名的配置,以使支持<#var abc = new ArrayList()/>常用类的写法
|
||||
8)删除AnStatic的支持,增加当变量是类时,先暂存变量结构到_Variable中,在碰到_Method,_Property时支持读取静态变量/常量和调用静态方法,
|
||||
1、如${FadfoxConstants.F_NAME}是支持的
|
||||
2、如@{System.out.println("abc")}也支持
|
||||
9)调整和TemplateNotice接口,统一把Map通知,以前是逐个通知,不利于刷新整个变量表
|
||||
10)修改_Interceptor拦截后成异常的BUG
|
||||
11)增加pattern的设置的支持,以前固定为["*.ftml",*.htm,*.ftm]
|
||||
12)修改process(OutputStream out)时不主动out.flush(),由业务自己触发,否则会引起chuncked
|
||||
V1.3.0.R2017022701版本:
|
||||
1)增加Templates.format(ftml)方法,格式化后不显示代码,而显示字符串
|
||||
2)增加_Format语句(#{})支持,对${}的结果进行格式化,相当于${Templates.format(value)}
|
||||
V1.3.1.R2017052801
|
||||
1)修改Asserts.asserts为Asserts.as()方法,使用三目运算断言,防止断言为真时需要初始化无意义的断言失败字符串
|
||||
2)增加双点号支持括号
|
||||
V1.3.2.R2017080501
|
||||
1)修改<#for>的遍历,原为Collection,改为Iterable,扩大遍历范围
|
||||
2)修改<#function>,原在include时有效,修改为当前模板都有效
|
||||
3)修改变量表定义为FLinkedHashMapSV,原来是HashMap,没有顺序
|
||||
4)修改#{},格式化增加对\',\"处理成'"
|
||||
V1.3.3.R2017110601
|
||||
1)解决<#for>里面注释<#---->的BUG
|
||||
V1.4.0.R2018010101
|
||||
1)正式启用ZhiqimML名称,原所有Fadfox改为Zhiqim,原所有fadfox改为zhiqim,原所有FADFOX改为ZHIQIM
|
||||
2)增加支持自定义的TemplateLoader的子类,如数据库的模板方式
|
||||
3)调整模板查找方式为倒序查找
|
||||
4)支持三目运算?:
|
||||
5)解决三个系统(Windows,Linux,Mac)对\r\n的处理上的不同导致的BUG
|
||||
6)增加_Method对前面的_New进行检查,如果是_New,则优先组合成构造函数,比后面的_Dot操作优先级高
|
||||
7)修改模板未找到时响应FileNotFoundException,原来显示不正确
|
||||
8)删除对@AnNew的自动newInstance的支持,改成要求前缀new,如new Selector(),而不能直接使用Selector
|
||||
9)修改Template为ZML,统一使用ZML代替模板
|
||||
10)增加ZmlVarRuntime类,以支持变量运行时实时调用build生成结果
|
||||
11)增加对ZmlVarRuntime在_Method中检查,得到build结果
|
||||
12)增加三目运算对null的判断为false(采用js的判断方式,有利于该字段未定义表示false)
|
||||
V1.4.1.R2018072501
|
||||
1)修改Timer为Every,使用ZhiqimKernelV1.4.1.R2018072501版本
|
||||
2)修改比较大于时double使用了longValue()方法导致的BUG
|
||||
V1.5.0.R2019010101
|
||||
1)替换为zhiqim_zml名称
|
||||
2)替换zhiqim_kernel_v1.5.0_r2019010101的库
|
||||
3)修改Every为Interval,删除Tasker改为实现Task等修改
|
||||
4)执行程序和源码分开打包
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,69 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>${name}</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
${name}
|
||||
${Styles.src("/service/res/fadfox_2016100801.css")}
|
||||
${Scripts.src("/service/res/fadfox_2016100801.min.js")}
|
||||
${Styles.htmlOverflowHidden()}
|
||||
<#var abc="abc"/>
|
||||
@{name}
|
||||
<#-- dd -->
|
||||
<#--
|
||||
dd
|
||||
-->
|
||||
<script>
|
||||
<!--
|
||||
function doRefreshVcode()
|
||||
{
|
||||
F("#vcode").attr("src", "/service/vcode.jpg?time=" + new Date().getTime());
|
||||
}
|
||||
|
||||
function doRememberCode(rememberPass)
|
||||
{
|
||||
if (rememberPass.checked)
|
||||
{
|
||||
F("#check").checked = true;
|
||||
F("[data-id=check]").addClass("f-active");
|
||||
}
|
||||
}
|
||||
//-->
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body onload="theForm.operatorCode.focus()" style="background-color:#dce2f1;">
|
||||
<table class="f-table f-float-center fi-w500" style="margin-top:100px;">
|
||||
<tr>
|
||||
<td>
|
||||
<form name="theForm" method="post" action="${loginUrl}" onsubmit="return validateForm(this);">
|
||||
<input type="password" style="display:none">
|
||||
<table class=" f-table f-bordered f-px14 f-float-center f-pd6" style="background-color:#f1f3f5">
|
||||
<tr>
|
||||
<th colspan="2" height="40" class="f-bold f-text-white fi-px20" style="border:1px solid #4455aa;border-bottom:none;background-color:#4455aa">${name}</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="150" align="right">登录名:</td>
|
||||
<td width="*">
|
||||
<input name="operatorCode" type="text" class="f-input f-large ${styleColor}" value="${operatorCode}" maxlength="32"<#if !hasAutoComplete> autocomplete="off"</#if>>
|
||||
<input data-role="f-checkbox" data-class="f-blue" id="check" type="checkbox" name="rememberCode" <#if Validates.isNotEmpty(operatorCode)>checked</#if>> 记住用户名
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">密 码:</td>
|
||||
<td>
|
||||
<input name="operatorPass" type="password" class="f-input f-large ${styleColor}" value="${operatorPass}" maxlength="32"<#if !hasAutoComplete> autocomplete="off"</#if>>
|
||||
<input data-role="f-checkbox" data-class="f-blue" type="checkbox" name="rememberPass" onclick="doRememberCode(this);" <#if Validates.isNotEmpty(operatorPass)>checked</#if>/> 记住密码
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="f-h50">
|
||||
<td colspan="2" align="center" bgcolor="#ffffff"><button type="submit" class="f-button f-blue f-w200 f-h40"><span class="f-px16">登录</span></button></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
<html>
|
||||
<#for it : list>
|
||||
<#for item : it>
|
||||
双循环开始 ${item} 双循环结束
|
||||
</#for>
|
||||
</#for>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
${Styles.htmlOverflowHidden()}
|
||||
${name}
|
||||
${Styles.htmlOverflowHidden()}
|
||||
<#for item : list1>
|
||||
as ${item} sd
|
||||
</#for>
|
||||
</meta>
|
||||
</head>
|
||||
<#for item : list1>as ${item} sd </#for>最后加数据
|
||||
</body>
|
||||
<#for item : list1>as ${item} sd </#for>
|
||||
</html>
|
||||
@@ -0,0 +1,86 @@
|
||||
<#var list = new FArrayListS()/>
|
||||
@{list.add("11111")}
|
||||
@{list.add("222222")}
|
||||
|
||||
<#function showList(list)>
|
||||
<table border="1">
|
||||
<#for item : list>
|
||||
${showChild(item)}
|
||||
</#for>
|
||||
</table>
|
||||
</#function>
|
||||
|
||||
<#function showChild(item)>
|
||||
<tr>
|
||||
<td>${item}</td>
|
||||
</tr>
|
||||
</#function>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>${name}</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
${name}
|
||||
${Styles.src("/service/res/fadfox_2016100801.css")}
|
||||
${Scripts.src("/service/res/fadfox_2016100801.min.js")}
|
||||
${Styles.htmlOverflowHidden()}
|
||||
<#function abc()>
|
||||
dass
|
||||
dddf
|
||||
</#function>
|
||||
<script>
|
||||
<!--
|
||||
function doRefreshVcode()
|
||||
{
|
||||
F("#vcode").attr("src", "/service/vcode.jpg?time=" + new Date().getTime());
|
||||
}
|
||||
|
||||
function doRememberCode(rememberPass)
|
||||
{
|
||||
if (rememberPass.checked)
|
||||
{
|
||||
F("#check").checked = true;
|
||||
F("[data-id=check]").addClass("f-active");
|
||||
}
|
||||
}
|
||||
//-->
|
||||
</script>
|
||||
${abc()}
|
||||
</head>
|
||||
${abc()}333
|
||||
<body onload="theForm.operatorCode.focus()" style="background-color:#dce2f1;">
|
||||
${showList()}
|
||||
<table class="f-table f-float-center fi-w500" style="margin-top:100px;">
|
||||
<tr>
|
||||
<td>
|
||||
<form name="theForm" method="post" action="${loginUrl}" onsubmit="return validateForm(this);">
|
||||
<input type="password" style="display:none">
|
||||
<table class=" f-table f-bordered f-px14 f-float-center f-pd6" style="background-color:#f1f3f5">
|
||||
<tr>
|
||||
<th colspan="2" height="40" class="f-bold f-text-white fi-px20" style="border:1px solid #4455aa;border-bottom:none;background-color:#4455aa">${name}</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="150" align="right">登录名:</td>
|
||||
<td width="*">
|
||||
<input name="operatorCode" type="text" class="f-input f-large ${styleColor}" value="${operatorCode}" maxlength="32"<#if !hasAutoComplete> autocomplete="off"</#if>>
|
||||
<input data-role="f-checkbox" data-class="f-blue" id="check" type="checkbox" name="rememberCode" <#if Validates.isNotEmpty(operatorCode)>checked</#if>> 记住用户名
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">密 码:</td>
|
||||
<td>
|
||||
<input name="operatorPass" type="password" class="f-input f-large ${styleColor}" value="${operatorPass}" maxlength="32"<#if !hasAutoComplete> autocomplete="off"</#if>>
|
||||
<input data-role="f-checkbox" data-class="f-blue" type="checkbox" name="rememberPass" onclick="doRememberCode(this);" <#if Validates.isNotEmpty(operatorPass)>checked</#if>/> 记住密码
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="f-h50">
|
||||
<td colspan="2" align="center" bgcolor="#ffffff"><button type="submit" class="f-button f-blue f-w200 f-h40"><span class="f-px16">登录</span></button></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,39 @@
|
||||
<html>
|
||||
<#if hasAutoComplete>${hasAutoComplete}</#if>
|
||||
<#if status == 1>${status}<#elseif status == 2>${status}
|
||||
<#else>${status}</#if>
|
||||
<#if type == 1>${type}<#elseif type == 2>${type}<#else>${type}</#if>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
${Styles.htmlOverflowHidden()}
|
||||
${name}
|
||||
${Styles.htmlOverflowHidden()}
|
||||
<#if !hasAutoComplete>
|
||||
${hasAutoComplete}
|
||||
</#if>
|
||||
</meta>
|
||||
<#if hasAutoComplete>
|
||||
${hasAutoComplete}
|
||||
</#if>
|
||||
</title>
|
||||
<#if hasAutoComplete>
|
||||
${hasAutoComplete}
|
||||
<#else>
|
||||
${hasAutoComplete}
|
||||
</#if>
|
||||
</head>
|
||||
<#if status == 1>
|
||||
${status}
|
||||
<#elseif status == 2>
|
||||
${status}
|
||||
<#else>
|
||||
${status}
|
||||
</#if>
|
||||
</body>
|
||||
<#if type == 1>
|
||||
${type}
|
||||
<#elseif type == 2>
|
||||
${type}
|
||||
<#else>
|
||||
${type}
|
||||
</#if>
|
||||
</html>
|
||||
@@ -0,0 +1 @@
|
||||
<#include "/include_include.ftml"/>
|
||||
@@ -0,0 +1,13 @@
|
||||
<#var a="a"/>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>凡狐管理控制台</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
${Styles.bodyNoBackground()}
|
||||
<link rel="stylesheet" type="text/css" href="/service/res/fadfox_v1.3.0_r2017052801.css">
|
||||
<script type="text/javascript" src="/service/res/fadfox_v1.3.0_r2017052801.min.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/ftmpl/manager/green/global_2015120101.css">
|
||||
<script type="text/javascript" src="/ftmpl/manager/green/global_2015120101.js"></script>
|
||||
</head>
|
||||
@@ -0,0 +1 @@
|
||||
${false?"a":true?"b":"c"}
|
||||
@@ -0,0 +1,3 @@
|
||||
<#var ins = new ArrayListS().instance() />
|
||||
<#var var = TestVar />
|
||||
${var}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE ZHIQIM-CONFIG PUBLIC "-//ZHIQIM //DTD Zhiqim-Config Configuration 1.4.1//EN" "http://opensource.zhiqim.com/xmldtds/zhiqim_config_1_4_1.dtd">
|
||||
<zhiqim-config>
|
||||
|
||||
<group id="boot" desc="系统启动配置">
|
||||
<item key="name" value="${name}" type="protected" desc="系统名称" />
|
||||
<item key="version" value="${version}" type="protected" desc="系统版本" />
|
||||
<item key="port" value="${port}" type="private" desc="系统监听端口,用于启动监听和命令关闭工程" />
|
||||
</group>
|
||||
|
||||
</zhiqim-config>
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml;
|
||||
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
import org.zhiqim.zml.expression.Primitive;
|
||||
|
||||
/**
|
||||
* 表达式基类<br><br>
|
||||
*
|
||||
* @see Operator 运算符表达式<br>
|
||||
* @see Primitive 对象原型表达式<br>
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public interface Expression extends ZmlConstants
|
||||
{
|
||||
/**
|
||||
* 强制子类实现toString方法
|
||||
*
|
||||
* @return 表达式原型字符串
|
||||
*/
|
||||
public String toString();
|
||||
|
||||
/**
|
||||
* 强制子类提供表达式类型,方便switch
|
||||
*
|
||||
* @return 表达式int类型
|
||||
*/
|
||||
public int getType();
|
||||
|
||||
/**
|
||||
* 根据变量列表生成结果值
|
||||
*
|
||||
* @param variableMap 变量表
|
||||
* @return 结果值
|
||||
* @throws ExpressionException 可能的表达式异常
|
||||
*/
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml;
|
||||
|
||||
import org.zhiqim.zml.expression.symbol._Ampersand;
|
||||
import org.zhiqim.zml.expression.symbol._Dot;
|
||||
import org.zhiqim.zml.expression.symbol._Equal;
|
||||
import org.zhiqim.zml.expression.symbol._Exclamation;
|
||||
import org.zhiqim.zml.expression.symbol._VerticalBar;
|
||||
|
||||
/**
|
||||
* 定义需要配对标点符号接口,共5个
|
||||
*
|
||||
* @see _Ampersand 连接符&,由&&组成逻辑与_And
|
||||
* @see _VerticalBar 竖杠符|,由||组成逻辑或_Or
|
||||
* @see _Dot 点号符.,由..组成整数数组_IntegerArray
|
||||
* @see _Equal 等号符=,由==组成恒等_EqualEqual
|
||||
* @see _Exclamation 感叹号!,由!=组成不等_EqualNot
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public interface ExpressionPair
|
||||
{
|
||||
/** 是否已配对 */
|
||||
public boolean isPaired();
|
||||
|
||||
/** 设置已配对 */
|
||||
public void setPaired();
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,298 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.zhiqim.kernel.constants.SignConstants;
|
||||
import org.zhiqim.kernel.util.Validates;
|
||||
import org.zhiqim.zml.exception.StatementException;
|
||||
import org.zhiqim.zml.statement._Echo;
|
||||
import org.zhiqim.zml.statement._For;
|
||||
import org.zhiqim.zml.statement._Function;
|
||||
import org.zhiqim.zml.statement._If;
|
||||
import org.zhiqim.zml.statement._Include;
|
||||
import org.zhiqim.zml.statement._Var;
|
||||
|
||||
/**
|
||||
* 定义ZhiqimML语句接口,有两类语句
|
||||
*
|
||||
* 1、嵌套语句
|
||||
* @see _If 判断语句,格式为:<#if a=1>内容1<#elseif a==2>内容2<#elseif a==3>内容3<#else>其他内容<#if>
|
||||
* @see _For 迭代语句,格式为:<#for item : list></#for>
|
||||
* @see _Function 全局函数定义语句,格式为:<#function name(param1, param2)></#function>
|
||||
*
|
||||
* 2、非嵌套语句
|
||||
* @see _Text 纯文本语句
|
||||
* @see _Var 变量定义语句,格式为:<#var i=1/>
|
||||
* @see _Echo 表达式语句,格式为:${obj.getName()}
|
||||
* @see _Include 包含语句,本身不嵌套,调用后转到父ZML进行嵌套处理,格式为<#include "/zview/include.zml"/>
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public abstract class Statement implements ZmlConstants, SignConstants
|
||||
{
|
||||
public static final StatementComparator COMPARATOR = new StatementComparator();
|
||||
|
||||
private Zml zml;
|
||||
private StatementNesting parent;
|
||||
|
||||
private String statement;
|
||||
private int beginLine;
|
||||
private int beginColumn;
|
||||
private int endLine;
|
||||
private int endColumn;
|
||||
|
||||
private int beginIndex;
|
||||
private int endIndex;
|
||||
|
||||
private int innerBeginIndex;
|
||||
private int innerEndIndex;
|
||||
|
||||
/**************************************************************************/
|
||||
//定义抽象方法,子类必须实现
|
||||
/**************************************************************************/
|
||||
|
||||
/**
|
||||
* 是否是嵌套语句
|
||||
*
|
||||
* @return =true表示是,=false表示不是
|
||||
*/
|
||||
public abstract boolean isNesting();
|
||||
|
||||
/**
|
||||
* 由各子类实现解析语句成不同的表达式
|
||||
*
|
||||
* @throws StatementException
|
||||
*/
|
||||
public abstract void parseStatement() throws StatementException;
|
||||
|
||||
/**
|
||||
* 由各子类实现生成HTML代码
|
||||
*
|
||||
* @param variableMap 变量表
|
||||
* @return HTML内容
|
||||
* @throws StatementException
|
||||
*/
|
||||
public abstract String process(ZmlVariable variableMap) throws StatementException;
|
||||
|
||||
/**************************************************************************/
|
||||
//父类定义的通用方法
|
||||
/**************************************************************************/
|
||||
|
||||
/**
|
||||
* 本基类保存语句基本参数,语句由子类解析
|
||||
*
|
||||
* @param zml ZML对象
|
||||
* @param parent 父语句对象
|
||||
* @param statement 语句
|
||||
*/
|
||||
public void setStatement(Zml zml, StatementNesting parent, String statement)
|
||||
{
|
||||
this.zml = zml;
|
||||
this.parent = parent;
|
||||
this.statement = statement;
|
||||
}
|
||||
|
||||
/**
|
||||
* 本基类保存语句基本参数,语句由子类解析
|
||||
*
|
||||
* @param beginIndex 起始索引
|
||||
* @param endIndex 结束索引
|
||||
*/
|
||||
public void setIndexAll(int beginIndex, int endIndex)
|
||||
{
|
||||
this.beginIndex = beginIndex;
|
||||
this.endIndex = endIndex;
|
||||
|
||||
int[] begins = StatementParser.getLineColumnNoByIndex(zml.getIndexList(), beginIndex);
|
||||
int[] ends = StatementParser.getLineColumnNoByIndex(zml.getIndexList(), endIndex);
|
||||
this.beginLine = begins[0];
|
||||
this.beginColumn = begins[1];
|
||||
this.endLine = ends[0];
|
||||
this.endColumn = ends[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* 本基类保存语句基本参数,语句由子类解析
|
||||
*
|
||||
* @param innerBeginIndex 内部起始索引
|
||||
* @param innerEndIndex 内部结束索引
|
||||
*/
|
||||
public void setIndexInner(int innerBeginIndex, int innerEndIndex)
|
||||
{
|
||||
this.innerBeginIndex = innerBeginIndex;
|
||||
this.innerEndIndex = innerEndIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否语句指令独占一行
|
||||
*
|
||||
* @return =true表示是,=false表示不是
|
||||
*/
|
||||
public boolean isExclusiveLine() throws StatementException
|
||||
{
|
||||
//1.先比前面,查看指令前面是否是空白
|
||||
if (beginColumn > 1)
|
||||
{//前面有字符不是空白的,认为不是独占一行
|
||||
String content = parent.getPrevStatement(this);
|
||||
if (content != null)
|
||||
{
|
||||
if (content.length() < beginColumn-1)
|
||||
return false;//嵌套里前面的语句未顶格
|
||||
|
||||
String previous = content.substring(content.length()-(beginColumn-1));
|
||||
if (!Validates.isEmptyBlank(previous))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//2.再比后面,查看指令结束之后是否为空或是换行符
|
||||
if (beginLine == endLine)
|
||||
{//在同一行查看结束是不是回车换行
|
||||
return isEndBreak();
|
||||
}
|
||||
else
|
||||
{//不在同一行直接返回true,由子类解析语句后设置
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否语句结束后被换行
|
||||
*
|
||||
* @return =true表示被换行或结束,=false表示未被换行,后面有数据
|
||||
*/
|
||||
public boolean isEndBreak() throws StatementException
|
||||
{
|
||||
String content = parent.getNextStatement(this);
|
||||
return (content == null || content.startsWith("\r") || content.startsWith("\n"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取嵌套的_For语句,用于break,continue
|
||||
*
|
||||
* @return =null表示
|
||||
*/
|
||||
public _For getNearestNestingFor()
|
||||
{
|
||||
if (this instanceof _For)
|
||||
return (_For)this;
|
||||
|
||||
StatementNesting sp = parent;
|
||||
while (sp != null)
|
||||
{
|
||||
if (sp instanceof _For)
|
||||
return (_For)sp;
|
||||
|
||||
if (sp instanceof Zml)
|
||||
return null;
|
||||
|
||||
sp = ((Statement)sp).parent;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
//父类定义的获取参数方法
|
||||
/**************************************************************************/
|
||||
|
||||
/** 获取ZML */
|
||||
public Zml getZml()
|
||||
{
|
||||
return zml;
|
||||
}
|
||||
|
||||
/** 获取ZML路径 */
|
||||
public String getPath()
|
||||
{
|
||||
return getZml().getPath();
|
||||
}
|
||||
|
||||
/** 获取ZML索引表 */
|
||||
public List<ZmlLineIndex> getIndexList()
|
||||
{
|
||||
return zml.getIndexList();
|
||||
}
|
||||
|
||||
public String getStatement()
|
||||
{
|
||||
return statement;
|
||||
}
|
||||
|
||||
public int getBeginIndex()
|
||||
{
|
||||
return beginIndex;
|
||||
}
|
||||
|
||||
public int getEndIndex()
|
||||
{
|
||||
return endIndex;
|
||||
}
|
||||
|
||||
public int getBeginLine()
|
||||
{
|
||||
return beginLine;
|
||||
}
|
||||
|
||||
public int getBeginColumn()
|
||||
{
|
||||
return beginColumn;
|
||||
}
|
||||
|
||||
public int getEndLine()
|
||||
{
|
||||
return endLine;
|
||||
}
|
||||
|
||||
public int getEndColumn()
|
||||
{
|
||||
return endColumn;
|
||||
}
|
||||
|
||||
public int getInnerBeginIndex()
|
||||
{
|
||||
return innerBeginIndex;
|
||||
}
|
||||
|
||||
public int getInnerEndIndex()
|
||||
{
|
||||
return innerEndIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return statement;
|
||||
}
|
||||
|
||||
/** 语句比较器 */
|
||||
private static class StatementComparator implements Comparator<Statement>
|
||||
{
|
||||
@Override
|
||||
public int compare(Statement o1, Statement o2)
|
||||
{
|
||||
return o1.getBeginIndex() - o2.getBeginIndex();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.zhiqim.kernel.constants.SignConstants;
|
||||
import org.zhiqim.zml.exception.StatementException;
|
||||
import org.zhiqim.zml.statement._For;
|
||||
import org.zhiqim.zml.statement._Function;
|
||||
import org.zhiqim.zml.statement._If;
|
||||
|
||||
/**
|
||||
* ZML和嵌套语句解析接口,在解析时需实现该接口
|
||||
* @see Zml ZML本身支持嵌套,内部有_If,_For或者_Function语句
|
||||
* @see _If 判断语句内部会嵌套_If,_For
|
||||
* @see _For 循环语句内部会嵌套_If,_For
|
||||
* @see _Function 全局函数定义语句内部会嵌套_If,_For和_Function
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public interface StatementNesting extends ZmlConstants, SignConstants
|
||||
{
|
||||
/**
|
||||
* 获取语句中对应的ZML
|
||||
*
|
||||
* @return ZML
|
||||
*/
|
||||
public Zml getZml();
|
||||
|
||||
/**
|
||||
* 获取对应ZML的路径
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getPath();
|
||||
|
||||
/**
|
||||
* 获取ZML中的行列索引表
|
||||
*
|
||||
* @return List<ZmlLineIndex>
|
||||
*/
|
||||
public List<ZmlLineIndex> getIndexList();
|
||||
|
||||
/**
|
||||
* 获取需要处理的ZML或语句内容
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getContent();
|
||||
|
||||
/**
|
||||
* 获取语句/ZML内容对应ZML起始索引号
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public int getContentBeginIndex();
|
||||
|
||||
/**
|
||||
* 获取上一个语句内容
|
||||
*
|
||||
* @param stmt 当前语句
|
||||
*/
|
||||
public String getPrevStatement(Statement stmt) throws StatementException;
|
||||
|
||||
/**
|
||||
* 获取下一个语句内容
|
||||
*
|
||||
* @param stmt 当前语句
|
||||
*/
|
||||
public String getNextStatement(Statement stmt) throws StatementException;
|
||||
}
|
||||
@@ -0,0 +1,653 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.zhiqim.kernel.constants.SignConstants;
|
||||
import org.zhiqim.kernel.util.Classes;
|
||||
import org.zhiqim.kernel.util.Strings;
|
||||
import org.zhiqim.kernel.util.Validates;
|
||||
import org.zhiqim.zml.exception.StatementException;
|
||||
import org.zhiqim.zml.statement._Break;
|
||||
import org.zhiqim.zml.statement._Call;
|
||||
import org.zhiqim.zml.statement._Comment;
|
||||
import org.zhiqim.zml.statement._Continue;
|
||||
import org.zhiqim.zml.statement._Define;
|
||||
import org.zhiqim.zml.statement._Echo;
|
||||
import org.zhiqim.zml.statement._For;
|
||||
import org.zhiqim.zml.statement._Format;
|
||||
import org.zhiqim.zml.statement._Function;
|
||||
import org.zhiqim.zml.statement._If;
|
||||
import org.zhiqim.zml.statement._Include;
|
||||
import org.zhiqim.zml.statement._Interceptor;
|
||||
import org.zhiqim.zml.statement._Return;
|
||||
import org.zhiqim.zml.statement._Text;
|
||||
import org.zhiqim.zml.statement._Var;
|
||||
|
||||
/**
|
||||
* 语句解析静态类
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class StatementParser implements ZmlConstants, SignConstants
|
||||
{
|
||||
/**
|
||||
* 解析全局定义文件,得到函数列表
|
||||
*
|
||||
* @param zml 全局定义文件
|
||||
* @param _functionList 函数列表
|
||||
* @param _varList 变量列表
|
||||
* @param _includeList 包含列表
|
||||
* @throws StatementException 语句异常
|
||||
*/
|
||||
public static void parseContextZml(Zml zml, List<_Function> _functionList, List<_Var> _varList, List<_Include> _includeList) throws StatementException
|
||||
{
|
||||
List<_Function> functionList = getStatementOutLineAndNesting(zml, _Function.class, FUNCTION, FUNCTION_BEGIN, FUNCTION_END);
|
||||
List<_Comment> commentList = getStatementOutLineAndNesting(zml, _Comment.class, COMMENT, COMMENT_BEGIN, COMMENT_END);
|
||||
|
||||
List<_Var> varList = getStatementListInLine(zml, _Var.class, VAR, VAR_BEGIN, VAR_END);
|
||||
List<_Include> includeList = getStatementListInLine(zml, _Include.class, INCLUDE, INCLUDE_BEGIN, INCLUDE_END);
|
||||
|
||||
for (Iterator<_Function> it=functionList.iterator();it.hasNext();)
|
||||
{
|
||||
_Function _function = it.next();
|
||||
if (isInCommentStatement(_function, commentList))
|
||||
{//_function在comment中,则删除该function
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator<_Var> it=varList.iterator();it.hasNext();)
|
||||
{
|
||||
_Var _var = it.next();
|
||||
if (isInFunctionStatement(_var, functionList) || isInCommentStatement(_var, commentList))
|
||||
{//_var在function或comment里,则删除该var
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator<_Include> it=includeList.iterator();it.hasNext();)
|
||||
{
|
||||
_Include _include = it.next();
|
||||
if (isInFunctionStatement(_include, functionList) || isInCommentStatement(_include, commentList))
|
||||
{//_include在function或comment则删除该<#include>
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
_functionList.addAll(functionList);
|
||||
_varList.addAll(varList);
|
||||
_includeList.addAll(includeList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析ZML中的第一层的嵌套,得到嵌套列表,第一层以下的嵌套的在第一层嵌套中递归处理
|
||||
*
|
||||
* @param nesting 嵌套ZML或嵌套语句
|
||||
* @return 得到第一层的嵌套列表
|
||||
* @throws StatementException 语句异常
|
||||
*/
|
||||
public static List<Statement> parseStatementNesting(StatementNesting nesting) throws StatementException
|
||||
{
|
||||
//第一步,得到除_Text外的所有语句
|
||||
List<_Function> functionList = getStatementOutLineAndNesting(nesting, _Function.class, FUNCTION, FUNCTION_BEGIN, FUNCTION_END);
|
||||
List<_For> forList = getStatementOutLineAndNesting(nesting, _For.class, FOR, FOR_BEGIN, FOR_END);
|
||||
List<_If> ifList = getStatementOutLineAndNesting(nesting, _If.class, IF, IF_BEGIN, IF_END);
|
||||
List<_Comment> commentList = getStatementOutLineAndNesting(nesting, _Comment.class, COMMENT, COMMENT_BEGIN, COMMENT_END);
|
||||
|
||||
List<_Include> includeList = getStatementListInLine(nesting, _Include.class, INCLUDE, INCLUDE_BEGIN, INCLUDE_END);
|
||||
List<_Interceptor> interceptorList = getStatementListInLine(nesting, _Interceptor.class, INTERCEPTOR, INTERCEPTOR_BEGIN, INTERCEPTOR_END);
|
||||
List<_Var> varList = getStatementListInLine(nesting, _Var.class, VAR, VAR_BEGIN, VAR_END);
|
||||
List<_Define> defList = getStatementListInLine(nesting, _Define.class, DEF, DEF_BEGIN, DEF_END);
|
||||
List<_Echo> echoList = getStatementListInLine(nesting, _Echo.class, ECHO, ECHO_BEGIN, ECHO_END);
|
||||
List<_Format> formatList = getStatementListInLine(nesting, _Format.class, FORMAT, FORMAT_BEGIN, FORMAT_END);
|
||||
List<_Call> callList = getStatementListInLine(nesting, _Call.class, CALL, CALL_BEGIN, CALL_END);
|
||||
List<_Return> returnList = getStatementListInLine(nesting, _Return.class, RETURN, RETURN_BEGIN, RETURN_END);
|
||||
List<_Break> breakList = getStatementListInLine(nesting, _Break.class, BREAK, BREAK_BEGIN, BREAK_END);
|
||||
List<_Continue> continueList = getStatementListInLine(nesting, _Continue.class, CONTINUE, CONTINUE_BEGIN, CONTINUE_END);
|
||||
|
||||
//第二步,去掉孙语句,得到ZML的第一层子语句
|
||||
for (Iterator<_Return> it=returnList.iterator();it.hasNext();)
|
||||
{
|
||||
_Return _return = it.next();
|
||||
if (isInFunctionStatement(_return, functionList) || isInForStatement(_return, forList) || isInIfStatement(_return, ifList) || isInCommentStatement(_return, commentList))
|
||||
{//_return在function,for,if或comment则删除该<#include>
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator<_Break> it=breakList.iterator();it.hasNext();)
|
||||
{
|
||||
_Break _break = it.next();
|
||||
if (isInFunctionStatement(_break, functionList) || isInForStatement(_break, forList) || isInIfStatement(_break, ifList) || isInCommentStatement(_break, commentList))
|
||||
{//_break在function,for,if或comment则删除该<#include>
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator<_Continue> it=continueList.iterator();it.hasNext();)
|
||||
{
|
||||
_Continue _continue = it.next();
|
||||
if (isInFunctionStatement(_continue, functionList) || isInForStatement(_continue, forList) || isInIfStatement(_continue, ifList) || isInCommentStatement(_continue, commentList))
|
||||
{//_include在function,for,if或comment则删除该<#include>
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator<_Include> it=includeList.iterator();it.hasNext();)
|
||||
{
|
||||
_Include _include = it.next();
|
||||
if (isInFunctionStatement(_include, functionList) || isInForStatement(_include, forList) || isInIfStatement(_include, ifList) || isInCommentStatement(_include, commentList))
|
||||
{//_include在function,for,if或comment则删除该<#include>
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator<_Var> it=varList.iterator();it.hasNext();)
|
||||
{
|
||||
_Var _var = it.next();
|
||||
if (isInFunctionStatement(_var, functionList) || isInForStatement(_var, forList) || isInIfStatement(_var, ifList) || isInCommentStatement(_var, commentList))
|
||||
{//_var在function,for,if或comment里,则删除该var
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator<_Define> it=defList.iterator();it.hasNext();)
|
||||
{
|
||||
_Define _def = it.next();
|
||||
if (isInFunctionStatement(_def, functionList) || isInForStatement(_def, forList) || isInIfStatement(_def, ifList) || isInCommentStatement(_def, commentList))
|
||||
{//_def在function,for,if或comment里,则删除该var
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator<_Echo> it=echoList.iterator();it.hasNext();)
|
||||
{
|
||||
_Echo _echo = it.next();
|
||||
if (isInFunctionStatement(_echo, functionList) || isInForStatement(_echo, forList) || isInIfStatement(_echo, ifList) || isInCommentStatement(_echo, commentList))
|
||||
{//_echo在function,for,if或comment里,则删除该${}
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator<_Format> it=formatList.iterator();it.hasNext();)
|
||||
{
|
||||
_Format _format = it.next();
|
||||
if (isInFunctionStatement(_format, functionList) || isInForStatement(_format, forList) || isInIfStatement(_format, ifList) || isInCommentStatement(_format, commentList))
|
||||
{//_format在function,for,if或comment里,则删除该#{}
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator<_Call> it=callList.iterator();it.hasNext();)
|
||||
{
|
||||
_Call _call = it.next();
|
||||
if (isInFunctionStatement(_call, functionList) || isInForStatement(_call, forList) || isInIfStatement(_call, ifList) || isInCommentStatement(_call, commentList))
|
||||
{//_call在function,for,if或comment里,则删除该@{}
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator<_Function> it=functionList.iterator();it.hasNext();)
|
||||
{
|
||||
_Function _function = it.next();
|
||||
if (isInIfStatement(_function, ifList) || isInForStatement(_function, forList) || isInCommentStatement(_function, commentList))
|
||||
{//_function在if,for或comment中,则删除该function
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator<_If> it=ifList.iterator();it.hasNext();)
|
||||
{
|
||||
_If _if = it.next();
|
||||
if (isInFunctionStatement(_if, functionList) || isInForStatement(_if, forList) || isInCommentStatement(_if, commentList))
|
||||
{//_if在function,for或comment中,则删除该if
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator<_For> it=forList.iterator();it.hasNext();)
|
||||
{
|
||||
_For _for = it.next();
|
||||
if (isInFunctionStatement(_for, functionList) || isInIfStatement(_for, ifList) || isInCommentStatement(_for, commentList))
|
||||
{//_for在function,if或comment中,则删除该for
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
//第三步,把<#for>、<#if>、<#include>、<#var>和${}整理到一个列表中,并把未在列表中的,使用_Text加入填充
|
||||
ArrayList<Statement> statementList = new ArrayList<Statement>();
|
||||
statementList.addAll(functionList);
|
||||
statementList.addAll(forList);
|
||||
statementList.addAll(ifList);
|
||||
statementList.addAll(commentList);
|
||||
statementList.addAll(includeList);
|
||||
statementList.addAll(interceptorList);
|
||||
statementList.addAll(varList);
|
||||
statementList.addAll(defList);
|
||||
statementList.addAll(echoList);
|
||||
statementList.addAll(formatList);
|
||||
statementList.addAll(callList);
|
||||
statementList.addAll(returnList);
|
||||
statementList.addAll(breakList);
|
||||
statementList.addAll(continueList);
|
||||
statementList.trimToSize();
|
||||
Collections.sort(statementList, Statement.COMPARATOR);
|
||||
|
||||
//把未在语句中的HTML转化成_Text补全到语句列表中
|
||||
if (statementList.isEmpty())
|
||||
{//如果没有一条语句,则全是html
|
||||
String content = nesting.getContent();
|
||||
_Text _txt = new _Text();
|
||||
_txt.setStatement(nesting.getZml(), nesting, content);
|
||||
_txt.setIndexInner(0, content.length());
|
||||
_txt.setIndexAll(nesting.getContentBeginIndex(), nesting.getContentBeginIndex() + content.length());
|
||||
|
||||
List<Statement> tsList = new ArrayList<Statement>(1);
|
||||
tsList.add(_txt);
|
||||
return tsList;
|
||||
}
|
||||
else
|
||||
{
|
||||
ArrayList<Statement> tsList = new ArrayList<Statement>(statementList.size()*2);
|
||||
|
||||
//第一个
|
||||
String content = nesting.getContent();
|
||||
Statement lastTs = statementList.get(0);
|
||||
if (lastTs.getBeginIndex() > 0)
|
||||
{
|
||||
String statement = content.substring(0, lastTs.getInnerBeginIndex());
|
||||
if (!Validates.isEmpty(statement))
|
||||
{
|
||||
_Text _txt = new _Text();
|
||||
_txt.setStatement(nesting.getZml(), nesting, statement);
|
||||
_txt.setIndexInner(0, lastTs.getInnerBeginIndex());
|
||||
_txt.setIndexAll(nesting.getContentBeginIndex(), nesting.getContentBeginIndex() + lastTs.getInnerBeginIndex());
|
||||
|
||||
tsList.add(_txt);
|
||||
}
|
||||
}
|
||||
tsList.add(lastTs);
|
||||
|
||||
//中间的
|
||||
for (int i=1;i<statementList.size();i++)
|
||||
{
|
||||
Statement ts = statementList.get(i);
|
||||
if (ts.getBeginIndex() > lastTs.getEndIndex())
|
||||
{
|
||||
String statement = content.substring(lastTs.getInnerEndIndex(), ts.getInnerBeginIndex());
|
||||
if (!Validates.isEmpty(statement))
|
||||
{
|
||||
_Text _txt = new _Text();
|
||||
_txt.setStatement(nesting.getZml(), nesting, statement);
|
||||
_txt.setIndexInner(lastTs.getInnerEndIndex(), ts.getInnerBeginIndex());
|
||||
_txt.setIndexAll(nesting.getContentBeginIndex() + lastTs.getInnerEndIndex(), nesting.getContentBeginIndex() + ts.getInnerBeginIndex());
|
||||
|
||||
tsList.add(_txt);
|
||||
}
|
||||
}
|
||||
|
||||
tsList.add(ts);
|
||||
lastTs = ts;
|
||||
}
|
||||
|
||||
//最后一个
|
||||
if (lastTs.getInnerEndIndex() < content.length())
|
||||
{
|
||||
String statement = content.substring(lastTs.getInnerEndIndex(), content.length());
|
||||
if (!Validates.isEmpty(statement))
|
||||
{
|
||||
_Text _txt = new _Text();
|
||||
_txt.setStatement(nesting.getZml(), nesting, statement);
|
||||
_txt.setIndexInner(lastTs.getInnerEndIndex(), content.length());
|
||||
_txt.setIndexAll(nesting.getContentBeginIndex() + lastTs.getInnerEndIndex(), nesting.getContentBeginIndex() + content.length());
|
||||
|
||||
tsList.add(_txt);
|
||||
}
|
||||
}
|
||||
|
||||
tsList.trimToSize();
|
||||
return tsList;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定语句类型,且语句类型一行不能表达的语句,且可能存在嵌套的语句列表
|
||||
*
|
||||
* @see _If 判断语句,里面可能还有判断,如<#if a = "a"><#if b = "b">bb</#if></#if>
|
||||
* @see _For 循环语句,里面可能还有循环,如<#for item : list><#for sub : item.list()>${sub}</#for></#for>
|
||||
*
|
||||
* @param nesting 嵌套ZML对象或嵌套语句,Zml,_Include,_If,_For,_Function等
|
||||
* @param cls 语句类
|
||||
* @param name 语句名称
|
||||
* @param begin 语句起始标志
|
||||
* @param end 语句结束标志
|
||||
* @return 得到嵌套语句列表,如_If,_For
|
||||
* @throws StatementException 语句异常
|
||||
*/
|
||||
public static <T> List<T> getStatementOutLineAndNesting(StatementNesting nesting, Class<T> cls, String name, String begin, String end) throws StatementException
|
||||
{
|
||||
String content = nesting.getContent();
|
||||
List<ZmlLineIndex> indexList = nesting.getIndexList();
|
||||
|
||||
int indBegin = 0, indEnd = 0;
|
||||
ArrayList<T> statementList = new ArrayList<T>();
|
||||
while(true)
|
||||
{
|
||||
indBegin = content.indexOf(begin, indEnd);
|
||||
if (indBegin == -1)
|
||||
break;
|
||||
|
||||
int indBeginTemp = indBegin;int indNest = indBegin;
|
||||
while(true)
|
||||
{
|
||||
int indEndTemp = content.indexOf(end, indBeginTemp);
|
||||
if (indEndTemp == -1)
|
||||
{
|
||||
int[] begins = getLineColumnNoByIndex(indexList, indBegin + nesting.getContentBeginIndex());
|
||||
throw new StatementException(nesting.getPath(), begins[0], begins[1], "检查"+name+"时未找到"+end+"结尾");
|
||||
}
|
||||
|
||||
//查看下一个开始是否嵌套
|
||||
indNest = content.indexOf(begin, indNest+begin.length());
|
||||
if (indNest == -1 || indNest > indEndTemp)
|
||||
{//未找到下一个开始或下一个对在结束之后,表示没有嵌套
|
||||
indEnd = indEndTemp + end.length();
|
||||
break;
|
||||
}
|
||||
else
|
||||
{//找到了,并且小于结束,则该开始和结束成对,是嵌套,那么设置开始为结束之后继续查找
|
||||
indBeginTemp = indEndTemp + end.length();
|
||||
}
|
||||
}
|
||||
|
||||
String statement = content.substring(indBegin, indEnd);
|
||||
T obj = Classes.newInstance(cls);
|
||||
Statement stmt = (Statement)obj;
|
||||
stmt.setStatement(nesting.getZml(), nesting, statement);
|
||||
stmt.setIndexInner(indBegin, indEnd);
|
||||
stmt.setIndexAll(nesting.getContentBeginIndex() + indBegin, nesting.getContentBeginIndex() + indEnd);
|
||||
stmt.parseStatement();
|
||||
statementList.add(obj);
|
||||
}
|
||||
|
||||
return statementList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定语句类型,且语句类型一行即可表达的语句列表
|
||||
*
|
||||
* @see _Echo 表达式语句,格式如:${obj.getName()}
|
||||
* @see _Var 变量语句,格式如:<#var abc="ddd"/>
|
||||
* @see _Include 包含语句,格式如:<#include "/zview/include.zml"/>
|
||||
*
|
||||
* @param nesting 嵌套ZML对象或嵌套语句,Zml,_Include,_Interceptor,_If,_For,_Function等
|
||||
* @param cls 语句类
|
||||
* @param name 语句名称
|
||||
* @param begin 语句起始标志
|
||||
* @param end 语句结束标志
|
||||
* @return 得到非嵌套语句列表
|
||||
* @throws StatementException 语句异常
|
||||
*/
|
||||
public static <T> List<T> getStatementListInLine(StatementNesting nesting, Class<T> cls, String name, String begin, String end) throws StatementException
|
||||
{
|
||||
String content = nesting.getContent();
|
||||
List<ZmlLineIndex> indexList = nesting.getIndexList();
|
||||
|
||||
int indBegin = 0, indEnd = 0;
|
||||
ArrayList<T> list = new ArrayList<T>();
|
||||
while(true)
|
||||
{
|
||||
indBegin = content.indexOf(begin, indEnd);
|
||||
if (indBegin == -1)
|
||||
break;
|
||||
|
||||
indEnd = content.indexOf(end, indBegin);
|
||||
if (indEnd == -1)
|
||||
{
|
||||
int[] begins = getLineColumnNoByIndex(indexList, indBegin + nesting.getContentBeginIndex());
|
||||
throw new StatementException(nesting.getPath(), begins[0], begins[1], "检查"+name+"时未找到"+end+"结尾");
|
||||
}
|
||||
|
||||
indEnd = indEnd + end.length();
|
||||
int[] begins = getLineColumnNoByIndex(indexList, indBegin + nesting.getContentBeginIndex());
|
||||
int[] ends = getLineColumnNoByIndex(indexList, indEnd + nesting.getContentBeginIndex());
|
||||
if (begins[0] != ends[0])
|
||||
throw new StatementException(nesting.getPath(), begins[0], begins[1], "检查"+name+"时找到"+end+"不在同一行");
|
||||
|
||||
String statement = content.substring(indBegin, indEnd);
|
||||
T obj = Classes.newInstance(cls);
|
||||
Statement stmt = (Statement)obj;
|
||||
stmt.setStatement(nesting.getZml(), nesting, statement);
|
||||
stmt.setIndexInner(indBegin, indEnd);
|
||||
stmt.setIndexAll(nesting.getContentBeginIndex() + indBegin, nesting.getContentBeginIndex() + indEnd);
|
||||
stmt.parseStatement();
|
||||
list.add(obj);
|
||||
}
|
||||
|
||||
list.trimToSize();
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定内容,得到每行的起始和结尾在内容的总索引位置列表
|
||||
*
|
||||
* @param content 需要指定的内容
|
||||
* @return List<ZmlLineIndex> 行索引号列表
|
||||
*/
|
||||
public static List<ZmlLineIndex> getIndexList(String content)
|
||||
{
|
||||
int index = 0, lineNo = 0;
|
||||
ArrayList<ZmlLineIndex> indexList = new ArrayList<ZmlLineIndex>();
|
||||
StringTokenizer tokener = new StringTokenizer(content, _BR_, true);
|
||||
while(tokener.hasMoreTokens())
|
||||
{//注意转化为第一行开始
|
||||
String line = tokener.nextToken();
|
||||
if (_LN_.equals(line) || _LR_.equals(line))
|
||||
{//空行不加入
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
|
||||
lineNo++;
|
||||
ZmlLineIndex lineIndex = new ZmlLineIndex();
|
||||
lineIndex.setLineNo(lineNo);
|
||||
lineIndex.setBeginIndex(index);
|
||||
|
||||
index += line.length();
|
||||
lineIndex.setEndIndex(index);
|
||||
indexList.add(lineIndex);
|
||||
}
|
||||
|
||||
indexList.trimToSize();
|
||||
return indexList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定行索引号列表和索引号,取得该索引号对应的行列号
|
||||
*
|
||||
* @param indexList 行索引列表
|
||||
* @param index 当前行号
|
||||
* @return 得到当前行号对应的行列号
|
||||
*/
|
||||
public static int[] getLineColumnNoByIndex(List<ZmlLineIndex> indexList, int index)
|
||||
{
|
||||
int lineNo = -1,columnNo = -1;
|
||||
for (ZmlLineIndex lineIndex : indexList)
|
||||
{
|
||||
lineNo = lineIndex.getLineNo(index);
|
||||
if (lineNo == -1)
|
||||
continue;
|
||||
|
||||
columnNo = lineIndex.getColumnNo(index);
|
||||
break;
|
||||
}
|
||||
|
||||
return new int[]{lineNo, columnNo};
|
||||
}
|
||||
|
||||
/** 是否其语语句嵌套在<#if>语句中 */
|
||||
public static boolean isInFunctionStatement(Statement ts, List<_Function> functionList)
|
||||
{
|
||||
for (_Function _function : functionList)
|
||||
{
|
||||
if (ts.getBeginIndex() <= _function.getBeginIndex())
|
||||
continue;//<#var>在<#function之前
|
||||
|
||||
if (ts.getEndIndex() >= _function.getEndIndex())
|
||||
continue;//<#var>在</#function>之后
|
||||
|
||||
//<#var>在<#function之间
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 是否其语语句嵌套在<#if>语句中 */
|
||||
public static boolean isInIfStatement(Statement ts, List<_If> ifList)
|
||||
{
|
||||
for (_If _if : ifList)
|
||||
{
|
||||
if (ts.getBeginIndex() <= _if.getBeginIndex())
|
||||
continue;//ts在<#if之前
|
||||
|
||||
if (ts.getEndIndex() >= _if.getEndIndex())
|
||||
continue;//ts在</#if>之后
|
||||
|
||||
//ts在<#if>在</#if>之间
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 是否其语语句嵌套在<#for>语句中 */
|
||||
public static boolean isInForStatement(Statement ts, List<_For> forList)
|
||||
{
|
||||
for (_For _for : forList)
|
||||
{
|
||||
if (ts.getBeginIndex() < _for.getBeginIndex())
|
||||
continue;//ts在<#for之前
|
||||
|
||||
if (ts.getEndIndex() > _for.getEndIndex())
|
||||
continue;//ts在</#for>之后
|
||||
|
||||
//ts在<#for>在</#for>之间
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 是否其语语句嵌套在<#---->语句中 */
|
||||
public static boolean isInCommentStatement(Statement ts, List<_Comment> commentList)
|
||||
{
|
||||
for (_Comment _comment : commentList)
|
||||
{
|
||||
if (ts.getBeginIndex() <= _comment.getBeginIndex())
|
||||
continue;//<#var>在<#--之前
|
||||
|
||||
if (ts.getEndIndex() >= _comment.getEndIndex())
|
||||
continue;//<#var>在-->之后
|
||||
|
||||
//<#var>在<#-->之间
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 判断是否含有定义变量语句 */
|
||||
public static boolean hasVar(List<Statement> stList)
|
||||
{
|
||||
for (Statement st : stList)
|
||||
{
|
||||
if (st instanceof _Var)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void processStatementList(List<Statement> statementList, ZmlVariable variableMap, StringBuilder strb) throws StatementException
|
||||
{
|
||||
Statement last = null;
|
||||
for (Statement stmt : statementList)
|
||||
{
|
||||
if (stmt instanceof _Return)
|
||||
{//处理return,可能是返回值
|
||||
last = stmt;
|
||||
throw new _Return.ReturnException(((_Return)stmt).build(variableMap));
|
||||
}
|
||||
else if (stmt instanceof _Break)
|
||||
{//处理break;
|
||||
last = stmt;
|
||||
_For _for = stmt.getNearestNestingFor();
|
||||
if (_for != null)
|
||||
{//找到嵌套的_For抛异常到_For处理,跳过中间的所有环节
|
||||
throw new _Break.BreakException();
|
||||
}
|
||||
}
|
||||
else if (stmt instanceof _Continue)
|
||||
{//处理continue;
|
||||
last = stmt;
|
||||
_For _for = stmt.getNearestNestingFor();
|
||||
if (_for != null)
|
||||
{//找到嵌套的_For抛异常到_For处理,跳过中间的所有环节
|
||||
throw new _Continue.ContinueException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{//正常语句
|
||||
String text = stmt.process(variableMap);
|
||||
if (Validates.isEmpty(text))
|
||||
{//为null和为空不写入,如_Var,或者结果是空字符串
|
||||
if (stmt.isExclusiveLine())
|
||||
{//如果是独占一行,则删除独占行
|
||||
Strings.removeRightMaybeEmptyBlankLine(strb);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (stmt.isNesting() && stmt.isExclusiveLine())
|
||||
{//删除独占行前的空白,如_For,_If,保留\r\n
|
||||
Strings.removeRightMaybeEmptyBlank(strb);
|
||||
}
|
||||
|
||||
if ((stmt instanceof _Text) && strb.length() == 0 && last != null && last.isExclusiveLine())
|
||||
{//首行文本时,检查前面是否有独占行的语句,有则删除多余的第一个\r\n
|
||||
text = Strings.trimLeftOneBR(text);
|
||||
}
|
||||
|
||||
strb.append(text);
|
||||
}
|
||||
|
||||
last = stmt;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,347 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Writer;
|
||||
import java.util.List;
|
||||
|
||||
import org.zhiqim.kernel.constants.SignConstants;
|
||||
import org.zhiqim.kernel.extend.MapS;
|
||||
import org.zhiqim.kernel.extend.MapSO;
|
||||
import org.zhiqim.zml.exception.StatementException;
|
||||
import org.zhiqim.zml.statement._Define;
|
||||
import org.zhiqim.zml.statement._Function;
|
||||
import org.zhiqim.zml.statement._Include;
|
||||
import org.zhiqim.zml.statement._Return.ReturnException;
|
||||
|
||||
/**
|
||||
* ZhiqimML主类
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class Zml implements StatementNesting, SignConstants
|
||||
{
|
||||
private ZmlEngine engine; //ZML引擎
|
||||
private Zml parent; //父ZML,在<#include>中有用
|
||||
|
||||
// ZML三要素
|
||||
private String path; //ZML相对路径
|
||||
private long lastModified; //ZML最后修改时间
|
||||
private String content; //ZML内容
|
||||
|
||||
private boolean isParsed; //ZML是否已解析,在缓存中则不需要再解析
|
||||
private List<Statement> stmtList; //ZML语句列表
|
||||
private List<ZmlLineIndex> indexList; //ZML行索引
|
||||
|
||||
private long lastAccessed; //最后访问时间
|
||||
|
||||
/**
|
||||
* 由业务创建ZML,加载当前内容生成ZML对象
|
||||
*
|
||||
* @param content ZML内容
|
||||
*/
|
||||
public Zml(String content)
|
||||
{
|
||||
this(null, null, 0, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 由业务创建ZML,需传入内容和ZML引擎
|
||||
*
|
||||
* @param engine ZML引擎
|
||||
* @param content ZML内容
|
||||
*/
|
||||
public Zml(ZmlEngine engine, String content)
|
||||
{
|
||||
this(engine, null, 0, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 由ZmlLoader 加载ZML字符串进行处理
|
||||
*
|
||||
* @param engine ZML引擎
|
||||
* @param path ZML相对路径
|
||||
* @param lastModified ZML最后修改时间
|
||||
* @param content ZML内容
|
||||
*/
|
||||
public Zml(ZmlEngine engine, String path, long lastModified, String content)
|
||||
{
|
||||
this.engine = engine;
|
||||
this.path = path;
|
||||
this.lastModified = lastModified;
|
||||
this.content = content;
|
||||
this.lastAccessed = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/** 获取ZML索引列表 */
|
||||
public List<ZmlLineIndex> getIndexList()
|
||||
{
|
||||
if (indexList != null)
|
||||
return indexList;
|
||||
|
||||
synchronized (this)
|
||||
{
|
||||
if (indexList == null)
|
||||
indexList = StatementParser.getIndexList(content);
|
||||
}
|
||||
|
||||
return indexList;
|
||||
}
|
||||
|
||||
/** 解析ZML得到语句列表 */
|
||||
public void parse() throws StatementException
|
||||
{
|
||||
this.stmtList = StatementParser.parseStatementNesting(this);
|
||||
|
||||
//解析完之后把内容置为NULL,因为这个占用内存比较大
|
||||
this.isParsed = true;
|
||||
this.content = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出到返回结果中
|
||||
*
|
||||
* @param variableMap 指定的变量表,如_Include中调用
|
||||
* @return 输出的内容
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
public void define(ZmlVariable variableMap) throws StatementException
|
||||
{
|
||||
if (!isParsed)
|
||||
{//没有解析,优先作解析,验证表达式和语句级是否有异常
|
||||
parse();
|
||||
}
|
||||
|
||||
//把_Define的执行一遍
|
||||
for (Statement statement : stmtList)
|
||||
{
|
||||
if (statement instanceof _Define)
|
||||
{//执行预定义
|
||||
((_Define)statement).define(variableMap);
|
||||
}
|
||||
else if (statement instanceof _Include)
|
||||
{//递归回调预定义
|
||||
((_Include)statement).define(variableMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出到返回结果中,在_Include中调用
|
||||
*
|
||||
* @param variableMap 指定的变量表
|
||||
* @param parent 指定父ZML
|
||||
* @return 输出的内容
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
public String process(ZmlVariable variableMap, Zml parent) throws StatementException
|
||||
{
|
||||
this.parent = parent;
|
||||
return process(variableMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出到字节流中,不会调用flush()
|
||||
*
|
||||
* @param pageVariableMap 全页变量表
|
||||
* @param contextVariableMap 上下文变量表
|
||||
* @param out 输出流
|
||||
* @param encoding 输出编码
|
||||
* @throws StatementException 可能产生的语句异常
|
||||
* @throws IOException 可能产生的IO异常
|
||||
*/
|
||||
public void process(OutputStream out, String encoding, MapSO pageVariableMap, MapS... contextVariableMap) throws StatementException, IOException
|
||||
{
|
||||
ZmlVariable variableMap = new ZmlVariable();
|
||||
variableMap.setZml(this);
|
||||
variableMap.setVariableMap(pageVariableMap);
|
||||
variableMap.setContextMap(contextVariableMap);
|
||||
|
||||
out.write(process(variableMap).getBytes(encoding));
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出到字符流中,不会调用flush()
|
||||
*
|
||||
* @param pageVariableMap 全页变量表
|
||||
* @param contextVariableMap 上下文变量表
|
||||
* @param writer 字符流
|
||||
* @throws StatementException 可能产生的语句异常
|
||||
* @throws IOException 可能产生的IO异常
|
||||
*/
|
||||
public void process(Writer writer, MapSO pageVariableMap, MapS... contextVariableMap) throws StatementException, IOException
|
||||
{
|
||||
ZmlVariable variableMap = new ZmlVariable();
|
||||
variableMap.setZml(this);
|
||||
variableMap.setVariableMap(pageVariableMap);
|
||||
variableMap.setContextMap(contextVariableMap);
|
||||
|
||||
writer.write(process(variableMap));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 输出到返回结果中
|
||||
*
|
||||
* @param variableMap 指定的变量表,如_Include中调用
|
||||
* @return 输出的内容
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
private String process(ZmlVariable variableMap) throws StatementException
|
||||
{
|
||||
if (!isParsed)
|
||||
{//没有解析,优先作解析,验证表达式和语句级是否有异常
|
||||
parse();
|
||||
}
|
||||
|
||||
//1.优先把_Def的执行一遍
|
||||
define(variableMap);
|
||||
|
||||
//2.循环执行语句
|
||||
StringBuilder strb = new StringBuilder();
|
||||
try
|
||||
{
|
||||
StatementParser.processStatementList(stmtList, variableMap, strb);
|
||||
return strb.toString();
|
||||
}
|
||||
catch(ReturnException e)
|
||||
{
|
||||
return e.hasValue()?String.valueOf(e.getValue()):strb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrevStatement(Statement stmt) throws StatementException
|
||||
{
|
||||
List<Statement> statementList = getStatementList();
|
||||
int ind = statementList.indexOf(stmt);
|
||||
if (ind <= 0)
|
||||
return null;
|
||||
|
||||
return statementList.get(ind-1).getStatement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNextStatement(Statement stmt) throws StatementException
|
||||
{
|
||||
List<Statement> statementList = getStatementList();
|
||||
int ind = statementList.indexOf(stmt);
|
||||
if (ind == -1 || ind >= statementList.size()-1)
|
||||
return null;
|
||||
|
||||
return statementList.get(ind+1).getStatement();
|
||||
}
|
||||
|
||||
public ZmlEngine getEngine()
|
||||
{
|
||||
return engine;
|
||||
}
|
||||
|
||||
public List<Statement> getStatementList() throws StatementException
|
||||
{
|
||||
if (!isParsed)
|
||||
{//没有解析,优先作解析,验证表达式和语句级是否有异常
|
||||
parse();
|
||||
}
|
||||
|
||||
return stmtList;
|
||||
}
|
||||
|
||||
public _Function getFunction(String name) throws StatementException
|
||||
{
|
||||
for (Statement stmt : getStatementList())
|
||||
{
|
||||
if (!(stmt instanceof _Function))
|
||||
continue;
|
||||
|
||||
_Function function = (_Function)stmt;
|
||||
if (!function.getName().equals(name))
|
||||
continue;
|
||||
|
||||
return function;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasParent()
|
||||
{
|
||||
return parent != null;
|
||||
}
|
||||
|
||||
public String getPath()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
public long getLastModified()
|
||||
{
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
public long getLastAccessed()
|
||||
{
|
||||
return lastAccessed;
|
||||
}
|
||||
|
||||
/** 获取ZML内容,当被解析之后内容将清空置为NULL */
|
||||
public String getContent()
|
||||
{
|
||||
return content;
|
||||
}
|
||||
|
||||
/** 允许设置最后修改时间 */
|
||||
public void setLastModified(long lastModified)
|
||||
{
|
||||
this.lastModified = lastModified;
|
||||
}
|
||||
|
||||
/** 允许设置内容 */
|
||||
public void setContent(String content)
|
||||
{
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
/** 重新设置最后访问时间 */
|
||||
public void setLastAccessed()
|
||||
{
|
||||
this.lastAccessed = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**************************************************************/
|
||||
//定义ZML内容从0开始,通过方向获取自身,适配Statement
|
||||
/**************************************************************/
|
||||
|
||||
@Override
|
||||
public Zml getZml()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContentBeginIndex()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.zhiqim.kernel.extend.HashMapSV;
|
||||
import org.zhiqim.kernel.schedule.Interval;
|
||||
import org.zhiqim.kernel.schedule.Task;
|
||||
|
||||
/**
|
||||
* ZML缓存
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2017-11-21 新建与整理
|
||||
*/
|
||||
public class ZmlCache implements Task
|
||||
{
|
||||
private final HashMapSV<Zml> cache = new HashMapSV<>();
|
||||
|
||||
private int maxIdleTime;//最长空闲时长,单位秒
|
||||
private int maxKeepTime;//最长保持时长,单位秒
|
||||
|
||||
public ZmlCache(int maxIdleTime, int maxKeepTime)
|
||||
{
|
||||
this.maxIdleTime = maxIdleTime;
|
||||
this.maxKeepTime = maxKeepTime;
|
||||
|
||||
//每15分钟检查一次
|
||||
Interval.shedule(this, 15 * 60 * 1000);
|
||||
}
|
||||
|
||||
public Zml get(String path)
|
||||
{
|
||||
synchronized (cache)
|
||||
{
|
||||
Zml zml = cache.get(path);
|
||||
if (zml != null)
|
||||
zml.setLastAccessed();
|
||||
|
||||
return zml;
|
||||
}
|
||||
}
|
||||
|
||||
public void put(String path, Zml zml)
|
||||
{
|
||||
synchronized (cache)
|
||||
{
|
||||
if (cache.containsKey(path))
|
||||
cache.remove(path);
|
||||
|
||||
cache.put(path, zml);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(String path)
|
||||
{
|
||||
synchronized (cache)
|
||||
{
|
||||
cache.remove(path);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute()
|
||||
{
|
||||
boolean hasMaxIdleTime = maxIdleTime > 0;
|
||||
boolean hasMaxKeepTime = maxKeepTime > 0;
|
||||
|
||||
if (!hasMaxIdleTime && !hasMaxKeepTime)
|
||||
return;
|
||||
|
||||
long lastKeepTimeMs = System.currentTimeMillis() - maxKeepTime * 1000;
|
||||
long lastIdleTimeMs = System.currentTimeMillis() - maxIdleTime * 1000;
|
||||
|
||||
synchronized (cache)
|
||||
{
|
||||
for (Iterator<Zml> it=cache.values().iterator();it.hasNext();)
|
||||
{
|
||||
Zml zml = it.next();
|
||||
long lastAccessed = zml.getLastAccessed();
|
||||
if ((hasMaxKeepTime && lastAccessed < lastKeepTimeMs)
|
||||
|| (hasMaxIdleTime && lastAccessed < lastIdleTimeMs))
|
||||
{//超时删除
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getMaxIdleTime()
|
||||
{
|
||||
return maxIdleTime;
|
||||
}
|
||||
|
||||
public int getMaxKeepTime()
|
||||
{
|
||||
return maxKeepTime;
|
||||
}
|
||||
|
||||
public void setMaxIdleTime(int maxIdleTime)
|
||||
{
|
||||
this.maxIdleTime = maxIdleTime;
|
||||
}
|
||||
|
||||
public void setMaxKeepTime(int maxKeepTime)
|
||||
{
|
||||
this.maxKeepTime = maxKeepTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml;
|
||||
|
||||
import org.zhiqim.kernel.constants.CodeConstants;
|
||||
|
||||
/**
|
||||
* ZhiqimML常量定义
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public interface ZmlConstants extends CodeConstants
|
||||
{
|
||||
/********************************************************************/
|
||||
//ZML文件缺省支持的模式
|
||||
/********************************************************************/
|
||||
|
||||
public static final String[] ZML_PATTERN_DEFAULT = {"*.zml", "*.htm"};
|
||||
|
||||
/********************************************************************/
|
||||
//ZML语句定义
|
||||
/********************************************************************/
|
||||
|
||||
public static final String TAG_END = ">";
|
||||
|
||||
//ZML语句
|
||||
public static final String ECHO = "${}";
|
||||
public static final String CALL = "@{}";
|
||||
public static final String FORMAT = "#{}";
|
||||
public static final String COMMENT = "<#---->";
|
||||
public static final String INCLUDE = "<#include>";
|
||||
public static final String INTERCEPTOR = "<#interceptor>";
|
||||
public static final String FUNCTION = "<#function>";
|
||||
public static final String VAR = "<#var>";
|
||||
public static final String DEF = "<#def>";
|
||||
public static final String IF = "<#if>";
|
||||
public static final String ELSEIF = "<#elseif>";
|
||||
public static final String FOR = "<#for>";
|
||||
public static final String RETURN = "<#return>";
|
||||
public static final String BREAK = "<#break/>";
|
||||
public static final String CONTINUE = "<#continue/>";
|
||||
|
||||
public static final String ECHO_BEGIN = "${";
|
||||
public static final String ECHO_END = "}";
|
||||
public static final String CALL_BEGIN = "@{";
|
||||
public static final String CALL_END = "}";
|
||||
public static final String FORMAT_BEGIN = "#{";
|
||||
public static final String FORMAT_END = "}";
|
||||
public static final String COMMENT_BEGIN = "<#--";
|
||||
public static final String COMMENT_END = "-->";
|
||||
public static final String INCLUDE_BEGIN = "<#include ";
|
||||
public static final String INCLUDE_END = "/>";
|
||||
public static final String INTERCEPTOR_BEGIN = "<#interceptor ";
|
||||
public static final String INTERCEPTOR_END = "/>";
|
||||
public static final String FUNCTION_BEGIN = "<#function ";
|
||||
public static final String FUNCTION_END = "</#function>";
|
||||
public static final String VAR_BEGIN = "<#var ";
|
||||
public static final String VAR_END = "/>";
|
||||
public static final String DEF_BEGIN = "<#def ";
|
||||
public static final String DEF_END = "/>";
|
||||
public static final String IF_BEGIN = "<#if ";
|
||||
public static final String IF_ELSEIF = "<#elseif ";
|
||||
public static final String IF_ELSE = "<#else>";
|
||||
public static final String IF_END = "</#if>";
|
||||
public static final String FOR_BEGIN = "<#for ";
|
||||
public static final String FOR_SEPARATOR = ":";
|
||||
public static final String FOR_END = "</#for>";
|
||||
public static final String RETURN_BEGIN = "<#return";
|
||||
public static final String RETURN_END = "/>";
|
||||
public static final String BREAK_BEGIN = "<#break";
|
||||
public static final String BREAK_END = "/>";
|
||||
public static final String CONTINUE_BEGIN = "<#continue";
|
||||
public static final String CONTINUE_END = "/>";
|
||||
|
||||
/********************************************************************/
|
||||
//ZML表达式定义
|
||||
/********************************************************************/
|
||||
|
||||
//原型-最基本
|
||||
public static final int NULL = 0;//null
|
||||
public static final int STRING = 1;//字符串
|
||||
public static final int CHAR = 2;//字符
|
||||
public static final int NUMBERIC = 3;//整数(数值型,允许前面是0开头)
|
||||
public static final int VARIABLE = 4;//变量
|
||||
public static final int BOOLEAN = 5;//布尔
|
||||
public static final int CLASS = 6;//类结构
|
||||
|
||||
//原型-扩展
|
||||
public static final int DECIMAL = 7;//小数
|
||||
|
||||
|
||||
//符号,从变量中转化
|
||||
public static final int GT = 11;
|
||||
public static final int GTE = 12;
|
||||
public static final int LT = 13;
|
||||
public static final int LTE = 14;
|
||||
|
||||
//符号,单标点13个
|
||||
public static final int BRACKET_LEFT = '(';//(40
|
||||
public static final int BRACKET_RIGHT = ')';//)41
|
||||
public static final int ASTERISK = '*';//*42
|
||||
|
||||
public static final int BRACKET_SQUARE_LEFT = '[';//[91
|
||||
public static final int BRACKET_SQUARE_RIGHT = ']';//]93
|
||||
|
||||
public static final int COMMA = ',';//,44
|
||||
public static final int DOT = '.';//.46
|
||||
public static final int EQUAL = '=';//=61
|
||||
public static final int EXCLAMATION = '!';//!33
|
||||
public static final int MINUS = '-';//-45
|
||||
public static final int PERCENT = '%';//%37
|
||||
public static final int PLUS = '+';//+43
|
||||
public static final int SLASH = '/';///47
|
||||
public static final int QUESTION = '?';//?63
|
||||
public static final int COLON = ':';//:58
|
||||
|
||||
//符号,双标点2个
|
||||
public static final int CONNECTOR = '&';//&&38
|
||||
public static final int VERTICAL = '|';//||124
|
||||
|
||||
//符号,标点扩展
|
||||
public static final int INEQUAL = 3361;//!=
|
||||
public static final int DOTDOT = 4646;//..
|
||||
public static final int TERNARY = 6358;//?:
|
||||
|
||||
//操作符
|
||||
public static final int BRACKET = 4041;//()括号
|
||||
|
||||
public static final int NEW = 110101119;//new,实例化newInstance
|
||||
public static final int METHOD = 40410;//()0,方法
|
||||
public static final int PROPERTY = 460;//.0,属性
|
||||
public static final int INDEXABLE = 9193;//[],可索引对象(含数组索引、列表索引和MAP取值)
|
||||
|
||||
|
||||
public static final int ADD = 430;//+0加法
|
||||
public static final int NEGATIVE = 451;//-1取负
|
||||
public static final int SUBTRACTION = 452;//-2减法
|
||||
public static final int MULTIPLICATION = 420;//*0乘法
|
||||
public static final int DIVISION = 470;///0除法
|
||||
public static final int MODULUS = 370;//%0取模
|
||||
|
||||
public static final int GTHEN = 110;//大于
|
||||
public static final int GTEQUAL = 120;//大于等于
|
||||
public static final int LTHEN = 130;//小于
|
||||
public static final int LTEQUAL = 140;//小于等于
|
||||
|
||||
public static final int EQUAL_EQUAL = 61610;//恒等
|
||||
public static final int EQUAL_NOT = 33610;//不等
|
||||
|
||||
public static final int AND = 3800;//逻辑与
|
||||
public static final int OR = 1240;//逻辑或
|
||||
public static final int NOT = 3300;//取反
|
||||
|
||||
public static final int INTEGER_ARR = 46460;//整型数组
|
||||
|
||||
//标点操作符
|
||||
public static final String _BRACKET_LEFT = "(";
|
||||
public static final String _BRACKET_RIGHT = ")";
|
||||
public static final String _BRACKET_BOTH = "()";
|
||||
public static final String _ASTERISK = "*";
|
||||
|
||||
public static final String _BRACKET_SQUARE_LEFT = "[";
|
||||
public static final String _BRACKET_SQUARE_RIGHT = "]";
|
||||
|
||||
public static final String _COMMA = ",";
|
||||
public static final String _DOT = ".";
|
||||
public static final String _CONNECTOR = "&&";
|
||||
public static final String _EQUAL = "=";
|
||||
public static final String _EXCLAMATION = "!";
|
||||
public static final String _MINUS = "-";
|
||||
public static final String _PERCENT = "%";
|
||||
public static final String _PLUS = "+";
|
||||
public static final String _SLASH = "/";
|
||||
public static final String _VERTICAL = "|";
|
||||
|
||||
//标点扩展
|
||||
public static final String _DOTDOT = "..";
|
||||
public static final String _INEQUAL = "!=";
|
||||
public static final String _EQUALEQUAL = "==";
|
||||
}
|
||||
@@ -0,0 +1,684 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.zhiqim.kernel.extend.HashMapSO;
|
||||
import org.zhiqim.kernel.extend.LinkedMapSV;
|
||||
import org.zhiqim.kernel.util.Arrays;
|
||||
import org.zhiqim.kernel.util.Asserts;
|
||||
import org.zhiqim.zml.loader.ClassZmlLoader;
|
||||
import org.zhiqim.zml.loader.FileZmlLoader;
|
||||
import org.zhiqim.zml.statement._Function;
|
||||
import org.zhiqim.zml.statement._Include;
|
||||
import org.zhiqim.zml.statement._Var;
|
||||
|
||||
/**
|
||||
* ZhiqimML引擎主程序<br><br>
|
||||
*
|
||||
* 1、设置引擎参数,如加载器、编码等<br>
|
||||
* 2、加载全局函数定义文件。<br>
|
||||
* 3、设置共享变量。<br>
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class ZmlEngine extends ZmlPredefinded implements ZmlConstants
|
||||
{
|
||||
//ZML引擎基本参数
|
||||
private ZmlVarNotice notice;
|
||||
private String encoding;
|
||||
private int maxIdleTime;
|
||||
private int maxKeepTime;
|
||||
private boolean isAscQuery;
|
||||
private String[] patterns;
|
||||
|
||||
//ZML引擎加载器和全局变量
|
||||
private ZmlLoader loader;
|
||||
private final LinkedMapSV<ZmlLoader> cLoaderMap;
|
||||
private final HashMapSO globalMap;
|
||||
|
||||
//ZML引擎配置ZML(最后修改时间、函数表和变量表)
|
||||
private final LinkedHashMap<ConfigKey, Long> fileMap;
|
||||
private final LinkedHashMap<ConfigKey, LinkedMapSV<_Function>> functionMap;
|
||||
private final LinkedHashMap<ConfigKey, LinkedMapSV<_Var>> variableMap;
|
||||
|
||||
/** 默认ZML引擎构造方法,编码格式默认为UTF-8 */
|
||||
public ZmlEngine()
|
||||
{
|
||||
this(_UTF_8_);
|
||||
}
|
||||
|
||||
/**
|
||||
* ZML引擎构造方法,传入编码格式
|
||||
*
|
||||
* @param encoding ZML通用的编码格式
|
||||
*/
|
||||
public ZmlEngine(String encoding)
|
||||
{
|
||||
this.encoding = encoding;
|
||||
this.patterns = ZML_PATTERN_DEFAULT;
|
||||
|
||||
this.cLoaderMap = new LinkedMapSV<>();
|
||||
this.globalMap = new HashMapSO();
|
||||
|
||||
this.fileMap = new LinkedHashMap<>();
|
||||
this.functionMap = new LinkedHashMap<>();
|
||||
this.variableMap = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
//ZML引擎基本参数
|
||||
/**************************************************************************/
|
||||
|
||||
public void setZmlVarNotice(ZmlVarNotice notice)
|
||||
{
|
||||
this.notice = notice;
|
||||
}
|
||||
|
||||
public void setAscQuery(boolean isAscQuery)
|
||||
{
|
||||
this.isAscQuery = isAscQuery;
|
||||
}
|
||||
|
||||
public void setEncoding(String encoding)
|
||||
{
|
||||
this.encoding = encoding;
|
||||
}
|
||||
|
||||
public void setMaxIdleTime(int maxIdleTime)
|
||||
{
|
||||
this.maxIdleTime = maxIdleTime;
|
||||
}
|
||||
|
||||
public void setMaxKeepTime(int maxKeepTime)
|
||||
{
|
||||
this.maxKeepTime = maxKeepTime;
|
||||
}
|
||||
|
||||
public void setPatterns(String[] patterns)
|
||||
{
|
||||
this.patterns = patterns;
|
||||
}
|
||||
|
||||
public void setPatterns(String patterns)
|
||||
{
|
||||
this.patterns = Arrays.toStringArray(patterns);
|
||||
}
|
||||
|
||||
public String getEncoding()
|
||||
{
|
||||
return encoding;
|
||||
}
|
||||
|
||||
public int getMaxIdleTime()
|
||||
{
|
||||
return maxIdleTime;
|
||||
}
|
||||
|
||||
public int getMaxKeepTime()
|
||||
{
|
||||
return maxKeepTime;
|
||||
}
|
||||
|
||||
public String[] getPatterns()
|
||||
{
|
||||
return patterns;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
//ZML引擎加载器和全局变量
|
||||
/**************************************************************************/
|
||||
|
||||
/**
|
||||
* 设置ZML加载器,如果是默认的类加载器和文件加载器,请使用setClassZmlLoader/setFileZmlLoader方法
|
||||
*
|
||||
* @param loader ZML加载器
|
||||
*/
|
||||
public void setZmlLoader(ZmlLoader loader)
|
||||
{
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置类ZML加载器
|
||||
*
|
||||
* @param clazz 给定一个能访问到ZML文件的类,防止跨ClassLoader加载失败
|
||||
* @param pathPrefix ZML文件路径前缀,格式为/org/zhiqim/example
|
||||
*/
|
||||
public void setClassZmlLoader(Class<?> clazz, String pathPrefix)
|
||||
{
|
||||
this.loader = new ClassZmlLoader(this, clazz, pathPrefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置文件夹加载器
|
||||
*
|
||||
* @param dir ZML文件根目录,如new File("./resource");
|
||||
* @throws IOException 检查文件根目录异常
|
||||
*/
|
||||
public void setFileZmlLoader(File dir) throws IOException
|
||||
{
|
||||
this.loader = new FileZmlLoader(this, dir.getCanonicalPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加组件ZML加载器
|
||||
*
|
||||
* @param clazz 给定一个能访问到ZML文件的类,防止跨ClassLoader加载失败
|
||||
* @param pathPrefix ZML文件路径前缀,格式为/org/zhiqim/example
|
||||
*/
|
||||
public void addComponentZmlLoader(Class<?> clazz, String pathPrefix)
|
||||
{
|
||||
this.cLoaderMap.put(pathPrefix, new ClassZmlLoader(this, clazz, pathPrefix));
|
||||
}
|
||||
|
||||
public void addComponentZmlLoader(String componentPath, ZmlLoader loader)
|
||||
{
|
||||
this.cLoaderMap.put(componentPath, loader);
|
||||
}
|
||||
|
||||
public ZmlLoader getLoader(ConfigKey ck)
|
||||
{
|
||||
return getLoader(ck.configPath, ck.componentPath);
|
||||
}
|
||||
|
||||
public ZmlLoader getLoader(String contextPath, String componentPath)
|
||||
{
|
||||
return (componentPath==null)?this.loader:this.cLoaderMap.get(componentPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加全局变量
|
||||
*
|
||||
* @param name 变量名
|
||||
* @param obj 变量值
|
||||
*/
|
||||
public void addGlobalVariable(String name, Object obj)
|
||||
{
|
||||
globalMap.put(name, obj);
|
||||
}
|
||||
|
||||
public Object getGlobalVariable(String key)
|
||||
{
|
||||
return globalMap.get(key);
|
||||
}
|
||||
|
||||
public HashMapSO getGlobalMap()
|
||||
{
|
||||
return globalMap;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
//ZML引擎配置ZML(最后修改时间、函数表和变量表)
|
||||
/**************************************************************************/
|
||||
|
||||
/**
|
||||
* 添加上下文配置ZML
|
||||
*
|
||||
* @param configPath 上下文配置ZML路径
|
||||
*/
|
||||
public void addConfigZml(String configPath)
|
||||
{
|
||||
Asserts.as(this.loader != null?null:"未设置加载器上不支持添加上下文配置ZML");
|
||||
this.loadConfigZml(new ConfigKey(configPath, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加组件上下文配置ZML,带组件路径
|
||||
*
|
||||
* @param configPath 上下文配置ZML路径
|
||||
* @param componentPath 组件路径
|
||||
*/
|
||||
public void addConfigZml(String configPath, String componentPath)
|
||||
{
|
||||
Asserts.as(this.cLoaderMap.containsKey(componentPath)?null:"未设置该组件加载器上不支持添加组件上下文配置ZML");
|
||||
this.loadConfigZml(new ConfigKey(configPath, componentPath));
|
||||
}
|
||||
|
||||
/** 检查当前配置更新 */
|
||||
public void chkCurConfigModified()
|
||||
{
|
||||
for (Entry<ConfigKey, Long> entry : fileMap.entrySet())
|
||||
{
|
||||
if (entry.getKey().componentPath != null)
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
long lastModified = getConfigLastModified(entry.getKey());
|
||||
if (lastModified != entry.getValue())
|
||||
loadConfigZml(entry.getKey());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw Asserts.exception("加载上下文ZML["+entry.getKey().configPath+"]异常", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 检查所有配置更新 */
|
||||
private void chkAllConfigModified()
|
||||
{
|
||||
for (Entry<ConfigKey, Long> entry : fileMap.entrySet())
|
||||
{
|
||||
try
|
||||
{
|
||||
long lastModified = getConfigLastModified(entry.getKey());
|
||||
if (lastModified != entry.getValue())
|
||||
loadConfigZml(entry.getKey());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw Asserts.exception("加载上下文ZML["+entry.getKey().configPath+"]异常", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 获取配置ZML最后修改时间 */
|
||||
private long getConfigLastModified(ConfigKey ck) throws Exception
|
||||
{
|
||||
ZmlLoader loader = getLoader(ck);
|
||||
return loader.getLastModified(ck.configPath);
|
||||
}
|
||||
|
||||
/** 获取配置ZML里的函数表 */
|
||||
public LinkedMapSV<_Function> getFunctionMap(String contextPath, String componentPath)
|
||||
{
|
||||
return functionMap.get(new ConfigKey(contextPath, componentPath));
|
||||
}
|
||||
|
||||
/** 获取配置ZML里的变量表 */
|
||||
public LinkedMapSV<_Var> getVarMap(String contextPath, String componentPath)
|
||||
{
|
||||
return variableMap.get(new ConfigKey(contextPath, componentPath));
|
||||
}
|
||||
|
||||
/** 查找配置ZML中函数语句 */
|
||||
public _Function getFunction(String name) throws Exception
|
||||
{
|
||||
if (loader == null)
|
||||
throw new Exception("未定义加载器,不支持获取函数调用");
|
||||
|
||||
//先检查上下文文件更新标志
|
||||
chkAllConfigModified();
|
||||
|
||||
if (isAscQuery)
|
||||
{//按顺序查找对应的函数
|
||||
for (LinkedMapSV<_Function> fMap : functionMap.values())
|
||||
{
|
||||
_Function _function = fMap.get(name);
|
||||
if (_function != null)
|
||||
return _function;
|
||||
}
|
||||
}
|
||||
else
|
||||
{//按倒序查找对应的函数
|
||||
_Function _function = null;
|
||||
for (LinkedMapSV<_Function> fMap : functionMap.values())
|
||||
{
|
||||
if (fMap.containsKey(name))
|
||||
_function = fMap.get(name);
|
||||
}
|
||||
|
||||
if (_function != null)
|
||||
return _function;
|
||||
}
|
||||
|
||||
//如果没找到抛异常
|
||||
throw new Exception("加载上下文ZML失败,不支持获取函数");
|
||||
}
|
||||
|
||||
/** 查找配置ZML中变量语句 */
|
||||
public _Var getVar(String name)
|
||||
{
|
||||
if (loader == null)
|
||||
return null;
|
||||
|
||||
//先检查上下文文件更新标志
|
||||
chkAllConfigModified();
|
||||
|
||||
if (isAscQuery)
|
||||
{//按顺序查找对应的变量
|
||||
for (LinkedMapSV<_Var> vMap : variableMap.values())
|
||||
{
|
||||
_Var _var = vMap.get(name);
|
||||
if (_var != null)
|
||||
return _var;
|
||||
}
|
||||
}
|
||||
else
|
||||
{//按倒序查找对应的变量
|
||||
_Var _var = null;
|
||||
for (LinkedMapSV<_Var> vMap : variableMap.values())
|
||||
{
|
||||
if (vMap.containsKey(name))
|
||||
_var = vMap.get(name);
|
||||
}
|
||||
|
||||
if (_var != null)
|
||||
return _var;
|
||||
}
|
||||
|
||||
//如果没找到返回null
|
||||
return null;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
//指定路径判断和查找ZML信息 has & get
|
||||
/**************************************************************************/
|
||||
|
||||
/**
|
||||
* 判断是否存在ZML信息
|
||||
*
|
||||
* @param path ZML相对路径
|
||||
* @return =true表示存在,=false表示不存在
|
||||
*/
|
||||
public boolean hasZml(String path)
|
||||
{
|
||||
Asserts.as(this.loader != null?null:"未设置加载器上不支持增通过引擎获取ZML");
|
||||
|
||||
try
|
||||
{
|
||||
//优先本地查找
|
||||
if (loader.hasZml(path))
|
||||
return true;
|
||||
|
||||
//再到组件中查找
|
||||
List<ZmlLoader> list = new ArrayList<>(cLoaderMap.values());
|
||||
for (int i=list.size()-1;i>=0;i--)
|
||||
{
|
||||
ZmlLoader ld = list.get(i);
|
||||
if (ld.hasZml(path))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw Asserts.exception("加载ZML文件["+path+"]异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否存在ZML信息
|
||||
*
|
||||
* @param path ZML相对路径
|
||||
* @return 存在返回加载器,不存在返回false
|
||||
*/
|
||||
public ZmlLoader getZmlLoader(String path)
|
||||
{
|
||||
Asserts.as(this.loader != null?null:"未设置加载器上不支持增通过引擎获取ZML");
|
||||
|
||||
try
|
||||
{
|
||||
//优先本地查找
|
||||
if (loader.hasZml(path))
|
||||
return loader;
|
||||
|
||||
//再到组件中查找
|
||||
List<ZmlLoader> list = new ArrayList<>(cLoaderMap.values());
|
||||
for (int i=list.size()-1;i>=0;i--)
|
||||
{
|
||||
ZmlLoader ld = list.get(i);
|
||||
if (ld.hasZml(path))
|
||||
return ld;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw Asserts.exception("加载ZML文件["+path+"]异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取ZML信息
|
||||
*
|
||||
* @param path ZML相对路径
|
||||
* @return ZML信息
|
||||
* @throws IOException 读取ZML文件时产生的异常
|
||||
*/
|
||||
public Zml getZml(String path) throws FileNotFoundException
|
||||
{
|
||||
Asserts.as(this.loader != null?null:"未设置加载器上不支持增通过引擎获取ZML");
|
||||
|
||||
try
|
||||
{
|
||||
//优先本地查找
|
||||
Zml zml = loader.loadZml(path);
|
||||
if (zml != null)
|
||||
return zml;
|
||||
|
||||
//再到组件中查找
|
||||
List<ZmlLoader> list = new ArrayList<>(cLoaderMap.values());
|
||||
for (int i=list.size()-1;i>=0;i--)
|
||||
{
|
||||
ZmlLoader ld = list.get(i);
|
||||
zml = ld.loadZml(path);
|
||||
if (zml != null)
|
||||
return zml;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw Asserts.exception("加载ZML文件["+path+"]异常", e);
|
||||
}
|
||||
|
||||
throw Asserts.notFound("未找到ZML文件["+path+"]");
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
//加载配置ZML
|
||||
/**************************************************************************/
|
||||
|
||||
/** 加载配置ZML */
|
||||
private void loadConfigZml(ConfigKey mk)
|
||||
{
|
||||
String configPath = mk.configPath;
|
||||
String componentPath = mk.componentPath;
|
||||
|
||||
//1.1 先加载ZML
|
||||
Zml zml = null;
|
||||
try
|
||||
{
|
||||
ZmlLoader theLoader = componentPath==null?this.loader:this.cLoaderMap.get(componentPath);
|
||||
zml = theLoader.loadZml(configPath);
|
||||
if (zml == null)
|
||||
return;//未找到不加载
|
||||
|
||||
//修改ZML文件的最后修改时间
|
||||
fileMap.put(mk, zml.getLastModified());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw Asserts.exception("加载上下文ZML["+configPath+"]异常", e);
|
||||
}
|
||||
|
||||
//1.2 从ZML中找到函数列表,变量列表和包含列表
|
||||
List<_Function> funcList = new ArrayList<>();
|
||||
List<_Var> varList = new ArrayList<>();
|
||||
List<_Include> includeList = new ArrayList<>();
|
||||
|
||||
try
|
||||
{
|
||||
StatementParser.parseContextZml(zml, funcList, varList, includeList);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw Asserts.exception("加载上下文ZML["+configPath+"]异常", e);
|
||||
}
|
||||
|
||||
//2.1 找到上下文对应的全局函数表
|
||||
LinkedMapSV<_Function> funcMap = null;
|
||||
synchronized (functionMap)
|
||||
{
|
||||
LinkedMapSV<_Function> fMap = functionMap.get(mk);
|
||||
if (fMap == null)
|
||||
{
|
||||
fMap = new LinkedMapSV<_Function>();
|
||||
functionMap.put(mk, fMap);
|
||||
}
|
||||
|
||||
funcMap = fMap;
|
||||
}
|
||||
|
||||
//2.2 把ZML中的函数表加入到全局函数表中
|
||||
synchronized (funcMap)
|
||||
{
|
||||
try
|
||||
{
|
||||
funcMap.clear();
|
||||
for (_Function func : funcList)
|
||||
{
|
||||
String name = func.getName();
|
||||
if (funcMap.containsKey(name))//一个上下文文件定义全局函数不允许重复,多文件之间支持,按优先顺序读取
|
||||
throw Asserts.exception("找到上下文ZML文件["+configPath+"]中全局函数["+name+"]有重复");
|
||||
|
||||
funcMap.put(name, func);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw Asserts.exception("加载上下文ZML["+configPath+"]异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
//3.1 找到上下文对应的全局变量表
|
||||
LinkedMapSV<_Var> varMap = null;
|
||||
synchronized (variableMap)
|
||||
{
|
||||
LinkedMapSV<_Var> vMap = variableMap.get(mk);
|
||||
if (vMap == null)
|
||||
{
|
||||
vMap = new LinkedMapSV<_Var>();
|
||||
variableMap.put(mk, vMap);
|
||||
}
|
||||
|
||||
varMap = vMap;
|
||||
}
|
||||
|
||||
//3.2 把ZML中的变量表并加入到全局变量表中
|
||||
synchronized (varMap)
|
||||
{
|
||||
try
|
||||
{
|
||||
varMap.clear();
|
||||
for (_Var var : varList)
|
||||
{
|
||||
String name = var.getVariableName();
|
||||
if (varMap.containsKey(name))//一个上下文文件定义全局变量不允许重复,多文件之间支持,按优先顺序读取
|
||||
throw Asserts.exception("找到上下文ZML文件["+configPath+"]中全局变量["+name+"]有重复");
|
||||
|
||||
varMap.put(name, var);
|
||||
}
|
||||
|
||||
if (notice != null)
|
||||
{//变量更新通知
|
||||
notice.doUpdateVariable(zml, configPath, componentPath, varMap);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw Asserts.exception("加载上下文ZML["+configPath+"]异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
//4 递归加载里面包含表的函数和变量
|
||||
try
|
||||
{
|
||||
ZmlVariable variable = new ZmlVariable();
|
||||
for (_Include include : includeList)
|
||||
{
|
||||
String path = include.getIncludePath(variable);
|
||||
loadConfigZml(new ConfigKey(path, componentPath));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw Asserts.exception("加载上下文ZML["+configPath+"]异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
//ZML引擎配置键(配置路径和组件路径组合成唯一)
|
||||
/**************************************************************************/
|
||||
|
||||
private class ConfigKey
|
||||
{
|
||||
private String configPath;
|
||||
private String componentPath;
|
||||
|
||||
public ConfigKey(String contextPath, String componentPath)
|
||||
{
|
||||
this.configPath = contextPath;
|
||||
this.componentPath = componentPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((componentPath == null) ? 0 : componentPath.hashCode());
|
||||
result = prime * result + ((configPath == null) ? 0 : configPath.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
|
||||
ConfigKey other = (ConfigKey)obj;
|
||||
if (componentPath == null)
|
||||
{
|
||||
if (other.componentPath != null)
|
||||
return false;
|
||||
}
|
||||
else if (!componentPath.equals(other.componentPath))
|
||||
return false;
|
||||
if (configPath == null)
|
||||
{
|
||||
if (other.configPath != null)
|
||||
return false;
|
||||
}
|
||||
else if (!configPath.equals(other.configPath))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml;
|
||||
|
||||
/**
|
||||
* ZhiqimML行索引,定义每行对应的索引
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class ZmlLineIndex
|
||||
{
|
||||
private int lineNo;
|
||||
|
||||
private int beginIndex;
|
||||
private int endIndex;
|
||||
|
||||
/** 指定总索引号,判断是否在该行,如果不在返回-1,否则返在该行号 */
|
||||
public int getLineNo(int ind)
|
||||
{
|
||||
if (ind < beginIndex || ind > endIndex)
|
||||
return -1;
|
||||
else
|
||||
return lineNo + 1;
|
||||
}
|
||||
|
||||
/** 指定总索引号,判断是否在该行,如果不在返回-1,否则返在该行对应的列号 */
|
||||
public int getColumnNo(int ind)
|
||||
{
|
||||
if (ind < beginIndex || ind > endIndex)
|
||||
return -1;
|
||||
|
||||
return ind - beginIndex + 1;
|
||||
}
|
||||
|
||||
public int getBeginIndex()
|
||||
{
|
||||
return beginIndex;
|
||||
}
|
||||
|
||||
public void setBeginIndex(int beginIndex)
|
||||
{
|
||||
this.beginIndex = beginIndex;
|
||||
}
|
||||
|
||||
public int getEndIndex()
|
||||
{
|
||||
return endIndex;
|
||||
}
|
||||
|
||||
public void setEndIndex(int endIndex)
|
||||
{
|
||||
this.endIndex = endIndex;
|
||||
}
|
||||
|
||||
public int getLineNo()
|
||||
{
|
||||
return lineNo;
|
||||
}
|
||||
|
||||
public void setLineNo(int lineNo)
|
||||
{
|
||||
this.lineNo = lineNo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml;
|
||||
|
||||
/**
|
||||
* ZhiqimML加载接口定义
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public interface ZmlLoader extends ZmlConstants
|
||||
{
|
||||
/** 获取上下文环境路径 */
|
||||
public String getContextPath();
|
||||
|
||||
/**
|
||||
* 判断ZML是否存在
|
||||
*
|
||||
* @param path ZML路径
|
||||
* @return 是否存在true/false
|
||||
* @throws 可能的异常
|
||||
*/
|
||||
public boolean hasZml(String path) throws Exception;
|
||||
|
||||
/**
|
||||
* 加载ZML接口
|
||||
*
|
||||
* @param path 相对于根配置的路径,如/zview/include.zml
|
||||
* @return 返回Zml对象
|
||||
* @throws 可能的异常
|
||||
*/
|
||||
public Zml loadZml(String path) throws Exception;
|
||||
|
||||
/**
|
||||
* 获取ZML资源最后更新时间
|
||||
*
|
||||
* @param path 相对于根配置的路径,如/zview/include.zml
|
||||
* @return long 最后修改时间
|
||||
* @throws 可能的异常
|
||||
*/
|
||||
public long getLastModified(String path) throws Exception;
|
||||
|
||||
/**
|
||||
* 设置ZML缓存最长空闲时长
|
||||
*
|
||||
* @param maxIdleTime 最长空闲时长,单位:秒
|
||||
*/
|
||||
public void setMaxIdleTime(int maxIdleTime);
|
||||
|
||||
/**
|
||||
* 设置ZML缓存最长保持时长
|
||||
*
|
||||
* @param maxKeepTime 最长保持时长,单位:秒
|
||||
*/
|
||||
public void setMaxKeepTime(int maxKeepTime);
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Random;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.zhiqim.kernel.extend.HashMapSC;
|
||||
import org.zhiqim.kernel.extend.HashMapSO;
|
||||
|
||||
/**
|
||||
* ZhiqimML预定义:
|
||||
* 1、预定义的JAVA核心类表
|
||||
* 2、预定义的系统变量表
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2016-12-23 新建与整理
|
||||
*/
|
||||
public class ZmlPredefinded
|
||||
{
|
||||
private static final HashMapSC javaMap = new HashMapSC();
|
||||
private static final HashMapSO systemMap = new HashMapSO();
|
||||
|
||||
static
|
||||
{
|
||||
//java.lang.*
|
||||
javaMap.put("Object", Object.class);
|
||||
javaMap.put("Boolean", Boolean.class);
|
||||
javaMap.put("Byte", Byte.class);
|
||||
javaMap.put("Character", Character.class);
|
||||
javaMap.put("Short", Short.class);
|
||||
javaMap.put("Integer", Integer.class);
|
||||
javaMap.put("Long", Long.class);
|
||||
javaMap.put("Float", Float.class);
|
||||
javaMap.put("Double", Double.class);
|
||||
javaMap.put("Class", Class.class);
|
||||
javaMap.put("String", String.class);
|
||||
javaMap.put("StringBuffer", StringBuffer.class);
|
||||
javaMap.put("StringBuilder", StringBuilder.class);
|
||||
javaMap.put("System", System.class);
|
||||
javaMap.put("Thread", Thread.class);
|
||||
javaMap.put("Runtime", Runtime.class);
|
||||
javaMap.put("Process", Process.class);
|
||||
|
||||
//java.util.*
|
||||
javaMap.put("ArrayList", ArrayList.class);
|
||||
javaMap.put("LinkedList", LinkedList.class);
|
||||
javaMap.put("Vector", Vector.class);
|
||||
javaMap.put("HashMap", HashMap.class);
|
||||
javaMap.put("HashSet", HashSet.class);
|
||||
javaMap.put("Hashtable", Hashtable.class);
|
||||
javaMap.put("LinkedHashMap", LinkedHashMap.class);
|
||||
javaMap.put("LinkedHashSet", LinkedHashSet.class);
|
||||
javaMap.put("Calendar", Calendar.class);
|
||||
javaMap.put("Date", Date.class);
|
||||
javaMap.put("Random", Random.class);
|
||||
}
|
||||
|
||||
/** 获取Java预定义简称表 */
|
||||
public static HashMapSC getJavaMap()
|
||||
{
|
||||
return javaMap;
|
||||
}
|
||||
|
||||
/** 获取Java预定义简称表 */
|
||||
public static Class<?> getJavaClass(String className)
|
||||
{
|
||||
return javaMap.get(className);
|
||||
}
|
||||
|
||||
/** 获取系统变量表 */
|
||||
public static HashMapSO getSystemMap()
|
||||
{
|
||||
return systemMap;
|
||||
}
|
||||
|
||||
/** 获取系统变量 */
|
||||
public static Object getSystemVariable(String key)
|
||||
{
|
||||
return ZmlVariable.chkDynamicVar(systemMap.get(key));
|
||||
}
|
||||
|
||||
/** 增加系统变量 */
|
||||
public static void addSystemVariable(String key, Object value)
|
||||
{
|
||||
systemMap.put(key, value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml;
|
||||
|
||||
import org.zhiqim.kernel.extend.LinkedMapSV;
|
||||
import org.zhiqim.zml.statement._Var;
|
||||
|
||||
/**
|
||||
* ZhiqimML变量更新通知
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2016-7-13 新建与整理
|
||||
*/
|
||||
public interface ZmlVarNotice
|
||||
{
|
||||
/**
|
||||
* 回调更新变量的接口定义
|
||||
*
|
||||
* @param zml ZML对象
|
||||
* @param configPath 配置路径
|
||||
* @param componentPath 组件路径
|
||||
* @param varMap 变量表
|
||||
*/
|
||||
public void doUpdateVariable(Zml zml, String configPath, String componentPath, LinkedMapSV<_Var> varMap);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml;
|
||||
|
||||
/**
|
||||
* ZhiqimML变量运行时生成最终结果
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2018-2-26 新建与整理
|
||||
*/
|
||||
public interface ZmlVarRuntime
|
||||
{
|
||||
public Object build();
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.zhiqim.kernel.extend.HashMapSO;
|
||||
import org.zhiqim.kernel.extend.MapS;
|
||||
import org.zhiqim.kernel.extend.HashMapSV;
|
||||
import org.zhiqim.kernel.extend.MapSO;
|
||||
import org.zhiqim.kernel.extend.MapSV;
|
||||
import org.zhiqim.kernel.util.Asserts;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.exception.StatementException;
|
||||
import org.zhiqim.zml.statement._Function;
|
||||
import org.zhiqim.zml.statement._Var;
|
||||
|
||||
/**
|
||||
* ZhiqimML变量表<br><br>
|
||||
*
|
||||
* 1、最高优先级__局部变量表,按排序先进优先级更高<br>
|
||||
* 2、次优化级__页面全局变量表,来自Action属性表和URL参数表,重名时属性覆盖参数<br>
|
||||
* 3、三级优化级__请求级变量表,来自请求、响应、会话和上下文环境变量定义表<br>
|
||||
* 4、四级优化级__上下文定义变量表,由工程配置启动时指定对象<br>
|
||||
* 5、最低优化级__框架中定义的工程全局变量表,由框架中负责更新<br>
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class ZmlVariable
|
||||
{
|
||||
private Zml zml;
|
||||
|
||||
private MapSO variableMap;
|
||||
private MapS[] contextMap;
|
||||
private MapSV<_Function> functionMap;
|
||||
|
||||
//局部变量,用于_If,_For,_Function
|
||||
private List<MapSO> localList;
|
||||
|
||||
/**************************************************************************************************/
|
||||
//设置变量&函数
|
||||
/**************************************************************************************************/
|
||||
|
||||
public void setZml(Zml zml)
|
||||
{
|
||||
this.zml = zml;
|
||||
}
|
||||
|
||||
public void setVariableMap(MapSO variableMap)
|
||||
{
|
||||
this.variableMap = variableMap;
|
||||
}
|
||||
|
||||
public void setContextMap(MapS... contextMap)
|
||||
{
|
||||
this.contextMap = contextMap;
|
||||
}
|
||||
|
||||
public void setFunctionMap(MapSV<_Function> functionMap)
|
||||
{
|
||||
this.functionMap = functionMap;
|
||||
}
|
||||
|
||||
public void addFunction(_Function function) throws StatementException
|
||||
{
|
||||
if (functionMap == null)
|
||||
functionMap = new HashMapSV<>();
|
||||
else if (functionMap.containsKey(function.getName()))
|
||||
throw new StatementException(function, "存在相同的函数名["+function.getName()+"]");
|
||||
|
||||
functionMap.put(function.getName(), function);
|
||||
}
|
||||
|
||||
public void addLocalVariable(MapSO localMap)
|
||||
{
|
||||
if (localList == null)
|
||||
localList = new ArrayList<>(2);
|
||||
|
||||
localList.add(localMap);
|
||||
}
|
||||
|
||||
public void removeLocalVariable(MapSO localMap)
|
||||
{
|
||||
localList.remove(localMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加变量值,
|
||||
* 1)如果没有局部变量表,则增加到页变量表
|
||||
* 2)有局部变量表,且存在变量定义,更新到局部变量
|
||||
* 3)有局部变量表,但不在局变量表中,且在页变量表中,认为是更新页变量表,更新到页变量表
|
||||
* 4)有局部变量表,但不在局变量表和页变量表中,认为是新增局变量,在最内层增加。
|
||||
*
|
||||
* @param name 变量名
|
||||
* @param value 变量值
|
||||
*/
|
||||
public void addVariable(String name, Object value)
|
||||
{
|
||||
//1.如果没有局部作用域,则直接放置到全页面作用域
|
||||
if (localList == null || localList.isEmpty())
|
||||
{
|
||||
if (variableMap == null)
|
||||
variableMap = new HashMapSO();
|
||||
|
||||
variableMap.put(name, value);
|
||||
return;
|
||||
}
|
||||
|
||||
//2.先检查局部作用域,如果存在定义则赋值到局部作用域
|
||||
for (int i=localList.size()-1;i>=0;i--)
|
||||
{
|
||||
MapSO localMap = localList.get(i);
|
||||
if (localMap.containsKey(name))
|
||||
{
|
||||
localMap.put(name, value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//3.再检查全页面作用域,如果在全页面作用域有定义,则赋值到全页面作用域
|
||||
if (variableMap != null && variableMap.containsKey(name))
|
||||
{
|
||||
variableMap.put(name, value);
|
||||
return;
|
||||
}
|
||||
|
||||
//4.如果局部和全页面都没找到定义,则在最内层局部作用域增加变量
|
||||
MapSO localMap = localList.get(localList.size()-1);
|
||||
localMap.put(name, value);
|
||||
}
|
||||
|
||||
/**************************************************************************************************/
|
||||
//获取基本信息
|
||||
/**************************************************************************************************/
|
||||
|
||||
public Zml getZml()
|
||||
{
|
||||
return zml;
|
||||
}
|
||||
|
||||
public ZmlEngine getEngine()
|
||||
{
|
||||
return zml.getEngine();
|
||||
}
|
||||
|
||||
public MapSO getVariableMap()
|
||||
{
|
||||
return variableMap;
|
||||
}
|
||||
|
||||
public MapS[] getContextMap()
|
||||
{
|
||||
return contextMap;
|
||||
}
|
||||
|
||||
public MapSV<_Function> getFunctionMap()
|
||||
{
|
||||
return functionMap;
|
||||
}
|
||||
|
||||
/**************************************************************************************************/
|
||||
//获取变量&函数
|
||||
/**************************************************************************************************/
|
||||
|
||||
public Object get(String key)
|
||||
{
|
||||
//1.在if,for局部作用域中找
|
||||
if (localList != null && !localList.isEmpty())
|
||||
{
|
||||
for (int i=localList.size()-1;i>=0;i--)
|
||||
{
|
||||
MapSO loaclMap = localList.get(i);
|
||||
Object value = loaclMap.get(key);
|
||||
if (value != null)
|
||||
return chkDynamicVar(value);
|
||||
}
|
||||
}
|
||||
|
||||
//2.在全页面作用域中找
|
||||
if (variableMap != null)
|
||||
{
|
||||
Object value = variableMap.get(key);
|
||||
if (value != null)
|
||||
return chkDynamicVar(value);
|
||||
}
|
||||
|
||||
//3.在context作用域中找
|
||||
if (contextMap != null)
|
||||
{
|
||||
for (MapS map : contextMap)
|
||||
{
|
||||
Object value = map.get(key);
|
||||
if (value != null)
|
||||
return chkDynamicVar(value);
|
||||
}
|
||||
}
|
||||
|
||||
//4.在引擎作用域中找
|
||||
ZmlEngine engine = zml.getEngine();
|
||||
if (engine != null)
|
||||
{
|
||||
//5.1 在引擎global作用域中找
|
||||
Object value = engine.getGlobalVariable(key);
|
||||
if (value != null)
|
||||
return chkDynamicVar(value);
|
||||
|
||||
//5.2 在引擎config变量中找
|
||||
_Var var = engine.getVar(key);
|
||||
if (var != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
return var.getExpression().build(this);
|
||||
}
|
||||
catch (ExpressionException e)
|
||||
{
|
||||
throw Asserts.exception("执行全局变量表达式时异常["+var.getVariableName()+"]", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//5.在system作用域中找
|
||||
return ZmlEngine.getSystemVariable(key);
|
||||
}
|
||||
|
||||
public _Function getFunction(String name) throws StatementException
|
||||
{
|
||||
_Function function = (functionMap == null)?null:functionMap.get(name);
|
||||
if (function != null)
|
||||
return function;
|
||||
else
|
||||
return zml.getFunction(name);
|
||||
}
|
||||
|
||||
/**************************************************************************************************/
|
||||
//对动态变量进行处理
|
||||
/**************************************************************************************************/
|
||||
|
||||
public static Object chkDynamicVar(Object value)
|
||||
{
|
||||
return (value instanceof ZmlVarRuntime)?((ZmlVarRuntime)value).build():value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.zhiqim.kernel.annotation.AnAlias;
|
||||
import org.zhiqim.kernel.constants.SignConstants;
|
||||
import org.zhiqim.kernel.extend.MapS;
|
||||
import org.zhiqim.kernel.extend.HashMapSO;
|
||||
import org.zhiqim.kernel.extend.MapSO;
|
||||
|
||||
/**
|
||||
* ZhiqimML工具类
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
@AnAlias("Zmls")
|
||||
public class Zmls implements SignConstants
|
||||
{
|
||||
/******************************************************************/
|
||||
//指定内容,把ZML标签转义为浏览器可读标签
|
||||
/******************************************************************/
|
||||
|
||||
/**
|
||||
* 内容格式化,对<,>,\",\',${,@{,#{格式化,保证浏览器解释成字符串而不是ZML代码
|
||||
*
|
||||
* @param content 要格式化的字符串
|
||||
* @return 格式化后的字符串
|
||||
*/
|
||||
public static String format(String content)
|
||||
{
|
||||
if (content == null)
|
||||
return "";
|
||||
|
||||
StringBuilder strb = new StringBuilder();
|
||||
for (int i=0;i<content.length();i++)
|
||||
{
|
||||
char c = content.charAt(i);
|
||||
switch (c)
|
||||
{
|
||||
//检查HTML/ZML非表达式语句标签,进行转化
|
||||
case '<':strb.append("<");break;
|
||||
case '>':strb.append(">");break;
|
||||
case '\'':strb.append("'");break;
|
||||
case '\"':strb.append(""");break;
|
||||
case '{':
|
||||
{//检查ZML表达式语句标签,进行转化
|
||||
if (i == 0)
|
||||
strb.append(c);
|
||||
else
|
||||
{
|
||||
switch (content.charAt(i-1))
|
||||
{
|
||||
case '$':strb.setLength(strb.length()-1);strb.append("${");break;
|
||||
case '@':strb.setLength(strb.length()-1);strb.append("@{");break;
|
||||
case '#':strb.setLength(strb.length()-1);strb.append("#{");break;
|
||||
default:strb.append(c);break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:strb.append(c);break;
|
||||
}
|
||||
}
|
||||
|
||||
return strb.toString();
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
//指定内容,解释内容生成结果
|
||||
/******************************************************************/
|
||||
|
||||
/**
|
||||
* 解析ZML内容和属性表得到解析之后的内容
|
||||
*
|
||||
* @param content 指定ZML的内容
|
||||
* @param key 变量KEY
|
||||
* @param value 变量VALUE
|
||||
* @return String 解析之后的内容
|
||||
* @throws Exception 可能解析的异常
|
||||
*/
|
||||
public static String parse(String content, String key, Object value) throws Exception
|
||||
{
|
||||
return parse(new Zml(content), key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析ZML内容和属性表得到解析之后的内容
|
||||
*
|
||||
* @param content 指定ZML的内容
|
||||
* @param variableMap 页变量表
|
||||
* @param contextMap 上下文变量表
|
||||
* @return String 解析之后的内容
|
||||
* @throws Exception 可能解析的异常
|
||||
*/
|
||||
public static String parse(String content, MapSO variableMap, MapS... contextMap) throws Exception
|
||||
{
|
||||
return parse(new Zml(content), variableMap, contextMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析ZML内容和属性表得到解析之后的内容
|
||||
*
|
||||
* @param content 指定ZML的内容
|
||||
* @param contextMap 上下文变量表
|
||||
* @return String 解析之后的内容
|
||||
* @throws Exception 可能解析的异常
|
||||
*/
|
||||
public static String parseContext(String content, MapS... contextMap) throws Exception
|
||||
{
|
||||
return parseContext(new Zml(content), contextMap);
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
//指定ZML,解释ZML生成结果
|
||||
/******************************************************************/
|
||||
|
||||
/**
|
||||
* 解析ZML和属性表得到解析之后的内容
|
||||
*
|
||||
* @param zml ZML对象
|
||||
* @param key 变量KEY
|
||||
* @param value 变量VALUE
|
||||
* @return String 解析之后的内容
|
||||
* @throws Exception 可能解析的异常
|
||||
*/
|
||||
public static String parse(Zml zml, String key, Object value) throws Exception
|
||||
{
|
||||
return parse(zml, new HashMapSO(key, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析ZML和属性表得到解析之后的内容
|
||||
*
|
||||
* @param zml ZML对象
|
||||
* @param variableMap 页变量表
|
||||
* @param contextMap 上下文变量表
|
||||
* @return String 解析之后的内容
|
||||
* @throws Exception 可能解析的异常
|
||||
*/
|
||||
public static String parse(Zml zml, MapSO variableMap, MapS... contextMap) throws Exception
|
||||
{
|
||||
StringWriter writer = new StringWriter();
|
||||
zml.process(writer, variableMap, contextMap);
|
||||
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析ZML和属性表得到解析之后的内容
|
||||
*
|
||||
* @param zml ZML对象
|
||||
* @param contextMap 上下文变量表
|
||||
* @return String 解析之后的内容
|
||||
* @throws Exception 可能解析的异常
|
||||
*/
|
||||
public static String parseContext(Zml zml, MapS... contextMap) throws Exception
|
||||
{
|
||||
StringWriter writer = new StringWriter();
|
||||
zml.process(writer, null, contextMap);
|
||||
|
||||
return writer.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.exception;
|
||||
|
||||
/**
|
||||
* 定义表达式解析异常
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class ExpressionException extends Exception
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 断言,传入要断言的判断,为false时抛出非法的参数异常
|
||||
*
|
||||
* @param param 断言为false时抛出非法的参数异常
|
||||
* @param exception 异常信息
|
||||
* @throws ExpressionException 异常
|
||||
*/
|
||||
public static void asserts(boolean param, String exception) throws ExpressionException
|
||||
{
|
||||
if (!param){
|
||||
throw new ExpressionException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 断言对象不为null,如果为null则抛出非法的参数异常
|
||||
*
|
||||
* @param param 参数
|
||||
* @param exception 异常信息
|
||||
* @throws ExpressionException 异常
|
||||
*/
|
||||
public static void assertNotNull(Object param, String exception) throws ExpressionException
|
||||
{
|
||||
if (param == null){
|
||||
throw new ExpressionException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
public ExpressionException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ExpressionException(String message, Throwable cause)
|
||||
{
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.exception;
|
||||
|
||||
/**
|
||||
* 属性未找到异常,区别于返回值
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2016-12-23 新建与整理
|
||||
*/
|
||||
public class PropertNotExistException extends ExpressionException
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public PropertNotExistException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.exception;
|
||||
|
||||
import org.zhiqim.kernel.util.Validates;
|
||||
import org.zhiqim.zml.Statement;
|
||||
|
||||
/**
|
||||
* 定义语句解析异常,可以得到出错的路径、行列号
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class StatementException extends Exception
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String path;
|
||||
private int lineNo;
|
||||
private int columnNo;
|
||||
|
||||
public StatementException(Statement s, String message)
|
||||
{
|
||||
this(s.getPath(), s.getBeginLine(), s.getBeginColumn(), message);
|
||||
}
|
||||
|
||||
public StatementException(Statement s, String message, Throwable exception)
|
||||
{
|
||||
this(s.getPath(), s.getBeginLine(), s.getBeginColumn(), message, exception);
|
||||
}
|
||||
|
||||
public StatementException(String path, int lineNo, int columnNo, String message)
|
||||
{
|
||||
super(new StringBuilder("[").append(Validates.isEmptyBlank(path)?"自定义ZML":path).append("]").append("[第").append(lineNo).append("行],[第").append(columnNo).append("列][").append(message).append("]").toString());
|
||||
|
||||
this.path = path;
|
||||
this.lineNo = lineNo;
|
||||
this.columnNo = columnNo;
|
||||
}
|
||||
|
||||
public StatementException(String path, int lineNo, int columnNo, String message, Throwable exception)
|
||||
{
|
||||
super(new StringBuilder("[").append(Validates.isEmptyBlank(path)?"自定义ZML":path).append("]").append("[第").append(lineNo).append("行],[第").append(columnNo).append("列][").append(message).append("]").toString(), exception);
|
||||
|
||||
this.path = path;
|
||||
this.lineNo = lineNo;
|
||||
this.columnNo = columnNo;
|
||||
}
|
||||
|
||||
/************************************************/
|
||||
//异常时获取文件对应的路径、行号和列号
|
||||
/************************************************/
|
||||
|
||||
public String getPath()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
public int getLineNo()
|
||||
{
|
||||
return lineNo;
|
||||
}
|
||||
|
||||
public int getColumnNo()
|
||||
{
|
||||
return columnNo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression;
|
||||
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.expression.operator._Or;
|
||||
import org.zhiqim.zml.statement._Var;
|
||||
|
||||
/**
|
||||
* ZhiqimML运算符表达式基类<br><br>
|
||||
*
|
||||
* 以下为Java操作符优先级排序<br>
|
||||
* 优先级 操作 结合性]<br>
|
||||
* 1 后缀运算符 [] . () (函数呼叫) 从左到右<br>
|
||||
* 2 单目运算符 ! ~ ++ -- +(单操作数) –(单操作数) 从右到左<br>
|
||||
* 3 创建 new 从左到右<br>
|
||||
* 4 乘除取模 * / % 从左到右<br>
|
||||
* 5 加减 + - 从左到右<br>
|
||||
* 6 移位 << >> >>> 从左到右<br>
|
||||
* 7 关系 < <= > >= instanceof 从左到右<br>
|
||||
* 8 相等 == != 从左到右<br>
|
||||
* 9 按位与 & 从左到右<br>
|
||||
* 10 按位异或 ^ 从左到右<br>
|
||||
* 11 按位或 | 从左到右<br>
|
||||
* 12 逻辑与 && 从左到右<br>
|
||||
* 13 逻辑或 || 从左到右<br>
|
||||
* 14 条件 ? : 从右到左<br>
|
||||
* 15 赋值 = += -= *= /= %= ^= <<= >>= >>>= 从右到左 <br>
|
||||
*
|
||||
* ZhiqimML操作符只实现如下操作符,共22个(其中1个赋值/20个运算表达式):<br>
|
||||
* 1 后缀运算符 [ ] . ( )(方法调用或表达式括号) 从左到右<br>
|
||||
* 2 单目运算符 ! –(数值取负) ..(数值最小最大值) 从右到左<br>
|
||||
* 3 创建 new 从左到右<br>
|
||||
* 4 乘除取模 * / % 从左到右<br>
|
||||
* 5 加减 + - 从左到右<br>
|
||||
* 6 关系 lt lte gt gte 从左到右<br>
|
||||
* 7 相等 == != 从左到右<br>
|
||||
* 8 逻辑与 && 从左到右<br>
|
||||
* 9 逻辑或 || 从左到右<br>
|
||||
* 10 赋值 = 从右到左 <br>
|
||||
*
|
||||
* @see _Var 其中赋值操作符(=)只存在于定义中<br>
|
||||
* @see _Or 其他操作符都可能出现在表达式中,以逻辑或 优化级最低,默认为_Or,依优化级从低到高依次判断<br>
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public abstract class Operator implements Expression
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression;
|
||||
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.expression.primitive._Boolean;
|
||||
import org.zhiqim.zml.expression.primitive._Char;
|
||||
import org.zhiqim.zml.expression.primitive._Decimal;
|
||||
import org.zhiqim.zml.expression.primitive._Integer;
|
||||
import org.zhiqim.zml.expression.primitive._Null;
|
||||
import org.zhiqim.zml.expression.primitive._String;
|
||||
import org.zhiqim.zml.expression.primitive._Variable;
|
||||
|
||||
/**
|
||||
* 原生类型对象表达式基类
|
||||
*
|
||||
* @see _Null 原生的null类型,表示null
|
||||
* @see _String 字符串原型,双引号""之内的内容
|
||||
* @see _Char 字符原型,单引号''之内的一个字符
|
||||
* @see _Boolean 为true/false的两个值
|
||||
* @see _Integer 整数原型,非零开头全数字组成
|
||||
* @see _Decimal 小数原型,零点开头接全数字,或非零开头后接一个点和数字
|
||||
* @see _Variable 变量原型,字母或下划线开头,后面接字母、下划线和数字
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public abstract class Primitive implements Expression
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression;
|
||||
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
|
||||
/**
|
||||
* 标点符号表达式
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public abstract class Symbol implements Expression
|
||||
{
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
throw new ExpressionException("禁止调用标点符号表达式");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import org.zhiqim.kernel.util.Types;
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
|
||||
/**
|
||||
* 加法运算(+)<br><br>
|
||||
*
|
||||
* 1、数值型相加<br>
|
||||
* 2、字符串相连<br>
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Add extends Operator
|
||||
{
|
||||
private final Expression left;
|
||||
private final Expression right;
|
||||
|
||||
public _Add(Expression left, Expression right)
|
||||
{
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return ADD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
Object privous = left.build(variableMap);
|
||||
Object next = right.build(variableMap);
|
||||
if (privous instanceof String || next instanceof String)
|
||||
{//有一个是字符串则认为是字符串相连
|
||||
String str1 = String.valueOf(privous);
|
||||
String str2 = String.valueOf(next);
|
||||
return str1 + str2;
|
||||
}
|
||||
else if ((!Types.isNumber(privous) && !Types.isChar(privous))
|
||||
|| (!Types.isNumber(next) && !Types.isChar(next)))
|
||||
{//不是整数和小数
|
||||
throw new ExpressionException("加法表达式{"+this+"},格式不正确,出现加数不是数值型和字符串");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Types.isInteger(privous))
|
||||
{//整数
|
||||
long add1 = ((Number)privous).longValue();
|
||||
if (Types.isInteger(next))
|
||||
{
|
||||
long add2 = ((Number)next).longValue();
|
||||
return add1 + add2;
|
||||
}
|
||||
else if (Types.isDecimal(next))
|
||||
{
|
||||
double add2 = ((Number)next).doubleValue();
|
||||
return add1 + add2;
|
||||
}
|
||||
else
|
||||
{
|
||||
char add2 = (Character)next;
|
||||
return add1 + add2;
|
||||
}
|
||||
}
|
||||
else if (Types.isDecimal(privous))
|
||||
{//小数
|
||||
double add1 = (Double)privous;
|
||||
if (Types.isInteger(next))
|
||||
{
|
||||
long add2 = ((Number)next).longValue();
|
||||
return add1 + add2;
|
||||
}
|
||||
else if (Types.isDecimal(next))
|
||||
{
|
||||
double add2 = ((Number)next).doubleValue();
|
||||
return add1 + add2;
|
||||
}
|
||||
else
|
||||
{
|
||||
char add2 = (Character)next;
|
||||
return add1 + add2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{//字符
|
||||
char add1 = (Character)privous;
|
||||
if (Types.isInteger(next))
|
||||
{
|
||||
long add2 = ((Number)next).longValue();
|
||||
return add1 + add2;
|
||||
}
|
||||
else if (Types.isDecimal(next))
|
||||
{
|
||||
double add2 = ((Number)next).doubleValue();
|
||||
return add1 + add2;
|
||||
}
|
||||
else
|
||||
{
|
||||
char add2 = (Character)next;
|
||||
return add1 + add2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuilder().append(left).append(" + ").append(right).toString() ;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import org.zhiqim.kernel.util.Types;
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
|
||||
/**
|
||||
* 逻辑与运算(&&)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _And extends Operator
|
||||
{
|
||||
private final Expression left;
|
||||
private final Expression right;
|
||||
|
||||
public _And(Expression left, Expression right)
|
||||
{
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return AND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
Object privous = left.build(variableMap);
|
||||
if (!Types.isBoolean(privous))
|
||||
throw new ExpressionException("逻辑与表达式{"+this+"}格式不正常,要求结果为布尔型时为非");
|
||||
|
||||
if (!(Boolean)privous)
|
||||
return false;//当左值为否时,不处理右值
|
||||
|
||||
Object next = right.build(variableMap);
|
||||
if (!Types.isBoolean(next))
|
||||
throw new ExpressionException("逻辑与表达式{"+this+"}格式不正常,要求结果为布尔型时为非");
|
||||
|
||||
return (Boolean)next;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuilder().append(left).append(" && ").append(right).toString() ;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.ExpressionParser;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
|
||||
/**
|
||||
* 括号运算()
|
||||
*
|
||||
* @see _Method 括号操作符,和方法操作符不同的是内部是表达式,方法操作符括号内为参数
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Bracket extends Operator
|
||||
{
|
||||
private Expression _expression; //编译后的表达式列表
|
||||
|
||||
private transient ArrayList<Expression> eList; //预编译的表达式列表
|
||||
|
||||
public _Bracket()
|
||||
{
|
||||
eList = new ArrayList<Expression>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return BRACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
return _expression.build(variableMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuilder("(").append(_expression).append(")").toString() ;
|
||||
}
|
||||
|
||||
public void addExpression(Expression expression)
|
||||
{
|
||||
eList.add(expression);
|
||||
}
|
||||
|
||||
public ArrayList<Expression> getExpressionList()
|
||||
{
|
||||
return eList;
|
||||
}
|
||||
|
||||
public Expression getExpression()
|
||||
{
|
||||
return _expression;
|
||||
}
|
||||
|
||||
public void parseBracket() throws ExpressionException
|
||||
{
|
||||
//左右括号去除
|
||||
eList.remove(0);
|
||||
eList.remove(eList.size()-1);
|
||||
|
||||
ExpressionParser.parse_Operator(eList);
|
||||
|
||||
if (eList.size() > 1)
|
||||
throw new ExpressionException("括号表达式存在无法处理的表达式");
|
||||
|
||||
_expression = eList.get(0);
|
||||
eList.clear();eList = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import org.zhiqim.kernel.util.Types;
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
|
||||
/**
|
||||
* 除法运算(/)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Division extends Operator
|
||||
{
|
||||
private final Expression left;
|
||||
private final Expression right;
|
||||
|
||||
public _Division(Expression left, Expression right)
|
||||
{
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return DIVISION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
Object privous = left.build(variableMap);
|
||||
Object next = right.build(variableMap);
|
||||
|
||||
if (!Types.isNumber(privous) || !Types.isNumber(next))
|
||||
{//不是整数和小数
|
||||
throw new ExpressionException("除法表达式{"+this+"},格式不正确,除数或被除数不是数值型");
|
||||
}
|
||||
|
||||
Number dividend = (Number)privous;
|
||||
Number divisor = (Number)next;
|
||||
|
||||
if (Types.isInteger(privous))
|
||||
{//整数
|
||||
if (Types.isInteger(next))
|
||||
return dividend.longValue() / divisor.longValue();
|
||||
else
|
||||
return dividend.longValue() / divisor.doubleValue();
|
||||
}
|
||||
else
|
||||
{//小数
|
||||
if (Types.isInteger(next))
|
||||
return dividend.doubleValue() / divisor.longValue();
|
||||
else
|
||||
return dividend.doubleValue() / divisor.doubleValue();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuilder().append(left).append(" / ").append(right).toString() ;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import org.zhiqim.kernel.util.Types;
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
|
||||
/**
|
||||
* 恒等比较(==)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _EqualEqual extends Operator
|
||||
{
|
||||
private final Expression left;
|
||||
private final Expression right;
|
||||
|
||||
public _EqualEqual(Expression left, Expression right)
|
||||
{
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return EQUAL_EQUAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
Object privous = left.build(variableMap);
|
||||
Object next = right.build(variableMap);
|
||||
|
||||
if (privous == null || next == null)
|
||||
{//出现一个为null
|
||||
return (privous == null)?(next == null):(next != null);
|
||||
}
|
||||
|
||||
if (privous instanceof String || next instanceof String)
|
||||
{//出现一个为字符串
|
||||
return String.valueOf(privous).equals(String.valueOf(next));
|
||||
}
|
||||
|
||||
//判断是否数值型
|
||||
if (!Types.isNumber(privous))
|
||||
return privous.equals(next);
|
||||
|
||||
//数值型
|
||||
if (!Types.isNumber(next))
|
||||
return false;
|
||||
|
||||
if (Types.isInteger(privous))
|
||||
{//整数
|
||||
if (!Types.isInteger(next))
|
||||
return false;
|
||||
|
||||
return ((Number)privous).longValue() == ((Number)next).longValue();
|
||||
}
|
||||
else
|
||||
{//小数
|
||||
if (!Types.isDecimal(next))
|
||||
return false;
|
||||
|
||||
return ((Number)privous).doubleValue() == ((Number)next).doubleValue();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuilder().append(left).append(" == ").append(right).toString() ;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import org.zhiqim.kernel.util.Types;
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
|
||||
/**
|
||||
* 不等比较(!=)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _EqualNot extends Operator
|
||||
{
|
||||
private final Expression left;
|
||||
private final Expression right;
|
||||
|
||||
public _EqualNot(Expression left, Expression right)
|
||||
{
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return EQUAL_NOT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
Object privous = left.build(variableMap);
|
||||
Object next = right.build(variableMap);
|
||||
|
||||
if (privous == null || next == null)
|
||||
{//出现一个为null
|
||||
return (privous == null)?(next != null):(next == null);
|
||||
}
|
||||
|
||||
if (privous instanceof String || next instanceof String)
|
||||
{//出现一个为字符串
|
||||
return !String.valueOf(privous).equals(String.valueOf(next));
|
||||
}
|
||||
|
||||
//判断是否数值型,不是数值型,进行对象相等判断
|
||||
if (!Types.isNumber(privous))
|
||||
return !privous.equals(next);
|
||||
|
||||
//是数值型,进行数值比较
|
||||
|
||||
//next不是数值型
|
||||
if (!Types.isNumber(next))
|
||||
return true;
|
||||
|
||||
if (Types.isInteger(privous))
|
||||
{//整数
|
||||
if (!Types.isInteger(next))
|
||||
return true;
|
||||
|
||||
return ((Number)privous).longValue() != ((Number)next).longValue();
|
||||
}
|
||||
else
|
||||
{//小数
|
||||
if (!Types.isDecimal(next))
|
||||
return true;
|
||||
|
||||
return ((Number)privous).doubleValue() != ((Number)next).doubleValue();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuilder().append(left).append(" != ").append(right).toString() ;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.ExpressionParser;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
|
||||
/**
|
||||
* 大于比较(>),对_Gt左右两值进行大于比较操作
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _GreateThen extends Operator
|
||||
{
|
||||
private final Expression left;
|
||||
private final Expression right;
|
||||
|
||||
public _GreateThen(Expression left, Expression right)
|
||||
{
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return GTHEN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
Object privous = left.build(variableMap);
|
||||
Object next = right.build(variableMap);
|
||||
return ExpressionParser.compare(privous, next, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuilder().append(left).append(" gt ").append(right).toString() ;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.ExpressionParser;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
|
||||
/**
|
||||
* 大于等于比较(>=),对_Gte左右两值进行大于等于比较操作
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _GreateThenEqual extends Operator
|
||||
{
|
||||
private final Expression left;
|
||||
private final Expression right;
|
||||
|
||||
public _GreateThenEqual(Expression left, Expression right)
|
||||
{
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return GTEQUAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
Object privous = left.build(variableMap);
|
||||
Object next = right.build(variableMap);
|
||||
return ExpressionParser.compare(privous, next, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuilder().append(left).append(" gte ").append(right).toString() ;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.zhiqim.kernel.util.Arrays;
|
||||
import org.zhiqim.kernel.util.Maps;
|
||||
import org.zhiqim.kernel.util.Types;
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.ExpressionParser;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.exception.PropertNotExistException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
import org.zhiqim.zml.expression.primitive._Variable;
|
||||
|
||||
/**
|
||||
* 可索引表达式,对应方括号[]:
|
||||
* 1、数组下标,如array[0]
|
||||
* 2、列表坐标、如list[0]
|
||||
* 3、MAP取值、如map["key"]
|
||||
* 4、对象属性,如object["name"]
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Indexable extends Operator
|
||||
{
|
||||
private Expression obj;//数组、列表、MAP等
|
||||
private Expression key;//键值
|
||||
|
||||
private transient ArrayList<Expression> eList;
|
||||
|
||||
public _Indexable()
|
||||
{
|
||||
this.eList = new ArrayList<Expression>(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return INDEXABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
Object target = obj.build(variableMap);
|
||||
Object tk = key.build(variableMap);
|
||||
if (target == null && tk == null)
|
||||
throw new ExpressionException("可索引表达式{"+this+"},目标对象和键对象不能都为null");
|
||||
|
||||
if (target == null)
|
||||
{//转到静态属性处理
|
||||
if (obj instanceof _Variable && tk instanceof String)
|
||||
{
|
||||
Class<?> clazz = ((_Variable)obj).buildClass();
|
||||
if (clazz == null)
|
||||
throw new ExpressionException("属性表达式{"+this+"},目标对象不能为null");
|
||||
|
||||
try
|
||||
{
|
||||
return new _Property(clazz, (String)tk).build(variableMap);
|
||||
}
|
||||
catch(PropertNotExistException e)
|
||||
{
|
||||
//属性未找到不返回值
|
||||
}
|
||||
}
|
||||
|
||||
throw new ExpressionException("可索引表达式{"+this+"},目标对象或键对象不正确");
|
||||
}
|
||||
|
||||
if (tk == null)
|
||||
{//转到MAP处理,MAP支持null键
|
||||
if (target instanceof Map)
|
||||
{//MAP类型
|
||||
return Maps.get(target, tk);
|
||||
}
|
||||
|
||||
throw new ExpressionException("可索引表达式{"+this+"},目标对象或键对象不正确");
|
||||
}
|
||||
|
||||
//目标对象和键都不为null
|
||||
return buildIndexable(variableMap, target, tk);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成可索引对象
|
||||
*
|
||||
* @param variableMap 变量表
|
||||
* @param target 目标对象
|
||||
* @param tk 键对象
|
||||
* @return 索引后对象
|
||||
* @throws ExpressionException 异常
|
||||
*/
|
||||
private Object buildIndexable(ZmlVariable variableMap, Object target, Object tk) throws ExpressionException
|
||||
{
|
||||
if (target.getClass().isArray())
|
||||
{//数组类型
|
||||
if (!Types.isInteger(tk) && !Types.isIntArray(tk))
|
||||
throw new ExpressionException("属性表达式{"+this+"},格式不正确,数组要求键值为整型");
|
||||
|
||||
Object[] ts = Arrays.toArray(target);
|
||||
if (Types.isInteger(tk))
|
||||
{
|
||||
int index = ((Number)tk).intValue();
|
||||
return ts[index];
|
||||
}
|
||||
else
|
||||
{
|
||||
int[] indexs = (int[])tk;
|
||||
if (indexs.length < 2)
|
||||
return null;
|
||||
|
||||
Object[] ds = new Object[indexs[indexs.length-1] - indexs[0]];
|
||||
for (int i=indexs[0];i<indexs[indexs.length-1];i++)
|
||||
{
|
||||
ds[indexs[0] - i] = ts[indexs[0]];
|
||||
}
|
||||
return ds;
|
||||
}
|
||||
}
|
||||
else if (target instanceof String)
|
||||
{//字符串
|
||||
if (!Types.isInteger(tk) && !Types.isIntArray(tk))
|
||||
throw new ExpressionException("属性表达式{"+this+"},格式不正确,数组要求键值为整型");
|
||||
|
||||
String str = (String)target;
|
||||
if (Types.isInteger(tk))
|
||||
{
|
||||
int index = ((Number)tk).intValue();
|
||||
return str.charAt(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
int[] indexs = (int[])tk;
|
||||
if (indexs.length < 2)
|
||||
return null;
|
||||
|
||||
return str.substring(indexs[0], indexs[indexs.length-1]);
|
||||
}
|
||||
}
|
||||
else if (target instanceof List)
|
||||
{//列表类型
|
||||
if (!Types.isInteger(tk) && !Types.isIntArray(tk))
|
||||
throw new ExpressionException("属性表达式{"+this+"},格式不正确,数组要求键值为整型");
|
||||
|
||||
List<?> list = (List<?>)target;
|
||||
if (Types.isInteger(tk))
|
||||
{
|
||||
int index = ((Number)tk).intValue();
|
||||
return list.get(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
int[] indexs = (int[])tk;
|
||||
if (indexs.length < 2)
|
||||
return null;
|
||||
|
||||
List<Object> list2 = new ArrayList<Object>(indexs[indexs.length-1] - indexs[0]);
|
||||
for (int i=indexs[0];i<indexs[indexs.length-1];i++)
|
||||
{
|
||||
list2.add(list.get(i));
|
||||
}
|
||||
return list2;
|
||||
}
|
||||
}
|
||||
else if (target instanceof Map)
|
||||
{//MAP类型
|
||||
Map<?, ?> map = (Map<?, ?>)target;
|
||||
return map.get(tk);
|
||||
}
|
||||
else if (tk instanceof String)
|
||||
{//对象取属性
|
||||
try
|
||||
{
|
||||
return new _Property(target, (String)tk).build(variableMap);
|
||||
}
|
||||
catch (PropertNotExistException e)
|
||||
{
|
||||
//属性未找到不返回
|
||||
}
|
||||
}
|
||||
|
||||
throw new ExpressionException("可索引表达式{"+this+"},格式不正确,目标对象不是数组|列表|MAP");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuilder().append(obj).append("[").append(key).append("]").toString() ;
|
||||
}
|
||||
|
||||
public void addExpression(Expression expression)
|
||||
{
|
||||
eList.add(expression);
|
||||
}
|
||||
|
||||
public void setObject(Expression obj)
|
||||
{
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
public boolean hasObject()
|
||||
{
|
||||
return obj != null;
|
||||
}
|
||||
|
||||
public void parseBracketSquare() throws ExpressionException
|
||||
{
|
||||
//左右括号去除
|
||||
eList.remove(0);
|
||||
eList.remove(eList.size()-1);
|
||||
|
||||
ExpressionParser.parse_Operator(eList);
|
||||
|
||||
if (eList.size() > 1)
|
||||
throw new ExpressionException("属性表达式存在无法处理的表达式");
|
||||
|
||||
key = eList.get(0);
|
||||
eList.clear();eList = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import org.zhiqim.kernel.util.Types;
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
|
||||
/**
|
||||
* 整数数组,双点号运算符(..)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _IntegerArray extends Operator
|
||||
{
|
||||
private final Expression left;
|
||||
private final Expression right;
|
||||
|
||||
public _IntegerArray(Expression left, Expression right)
|
||||
{
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return INTEGER_ARR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
Object privous = left.build(variableMap);
|
||||
if (!Types.isInteger(privous))
|
||||
throw new ExpressionException("整数数组表达式{"+this+"}格式不正常,要求结果不是整数");
|
||||
|
||||
Object next = right.build(variableMap);
|
||||
if (!Types.isInteger(next))
|
||||
throw new ExpressionException("整数数组表达式{"+this+"}格式不正常,要求结果不是整数");
|
||||
|
||||
int v1 = ((Number)privous).intValue();
|
||||
int v2 = ((Number)next).intValue();
|
||||
if (v1 > v2)
|
||||
return new int[0];
|
||||
|
||||
int[] ints = new int[v2 - v1 + 1];
|
||||
for (int i=0;i<ints.length;i++)
|
||||
{
|
||||
ints[i] = v1 + i;
|
||||
}
|
||||
return ints;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuilder().append(left).append("..").append(right).toString() ;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.ExpressionParser;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
|
||||
/**
|
||||
* 小于比较(<),对_Lt左右两值进行小于比较操作
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _LessThen extends Operator
|
||||
{
|
||||
private final Expression left;
|
||||
private final Expression right;
|
||||
|
||||
public _LessThen(Expression left, Expression right)
|
||||
{
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return LTHEN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
Object privous = left.build(variableMap);
|
||||
Object next = right.build(variableMap);
|
||||
return ExpressionParser.compare(privous, next, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuilder().append(left).append(" lt ").append(right).toString() ;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.ExpressionParser;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
|
||||
/**
|
||||
* 小于等于比较(<=),对_Lte左右两值进行小于等于比较操作
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _LessThenEqual extends Operator
|
||||
{
|
||||
private final Expression left;
|
||||
private final Expression right;
|
||||
|
||||
public _LessThenEqual(Expression left, Expression right)
|
||||
{
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return LTEQUAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
Object privous = left.build(variableMap);
|
||||
Object next = right.build(variableMap);
|
||||
return ExpressionParser.compare(privous, next, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuilder().append(left).append(" lte ").append(right).toString() ;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,526 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.zhiqim.kernel.Global;
|
||||
import org.zhiqim.kernel.extend.HashMapSO;
|
||||
import org.zhiqim.kernel.extend.MapSO;
|
||||
import org.zhiqim.kernel.util.Classes;
|
||||
import org.zhiqim.kernel.util.Types;
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.ExpressionParser;
|
||||
import org.zhiqim.zml.ZmlEngine;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.exception.StatementException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
import org.zhiqim.zml.expression.primitive._Variable;
|
||||
import org.zhiqim.zml.statement._Function;
|
||||
|
||||
/**
|
||||
* 方法操作符,括号function(param1, param2)或obj.method(param1, param2)
|
||||
*
|
||||
* @see _Bracket 括号操作符,和方法操作符不同的是内部是表达式,方法操作符括号内为参数
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Method extends Operator
|
||||
{
|
||||
private String methodName;
|
||||
|
||||
private Expression obj;
|
||||
private ArrayList<Expression> paramList;
|
||||
|
||||
public _Method(String methodName)
|
||||
{
|
||||
this.methodName = methodName;
|
||||
this.paramList = new ArrayList<Expression>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return METHOD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
if (obj == null)
|
||||
{//如果前置对象不存在,则认为是调用全局函数
|
||||
return ZmlVariable.chkDynamicVar(buildFunction(variableMap));
|
||||
}
|
||||
else if (obj instanceof _New)
|
||||
{//如果前置对象是_New表示调用构造函数
|
||||
return ZmlVariable.chkDynamicVar(buildNewInstance(variableMap));
|
||||
}
|
||||
else
|
||||
{//对象存在则认为是调用对象的方法
|
||||
return ZmlVariable.chkDynamicVar(buildMethod(variableMap));
|
||||
}
|
||||
}
|
||||
|
||||
/** 方法是全局函数 */
|
||||
private Object buildFunction(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
//先查本身是否有函数和是否包含里有函数
|
||||
_Function _function = null;
|
||||
try{_function = variableMap.getFunction(methodName);}catch (StatementException e){throw new ExpressionException("方法表达式{"+this+"}"+e.getMessage(), e);}
|
||||
|
||||
if (_function == null)
|
||||
{//当前ZML中没有查全局
|
||||
ZmlEngine engine = variableMap.getEngine();
|
||||
if (engine != null)
|
||||
{
|
||||
try{_function = engine.getFunction(methodName);}catch(Exception e){throw new ExpressionException("方法表达式{"+this+"}"+e.getMessage(), e);}
|
||||
}
|
||||
}
|
||||
|
||||
if (_function == null)
|
||||
{//全局也没有抛异常
|
||||
throw new ExpressionException("方法表达式{"+this+"}ZML内部和全局函数都未找到该函数的定义");
|
||||
}
|
||||
|
||||
//设置函数变量表,1.原变量表,2.实参变量传入
|
||||
MapSO pageMap = new HashMapSO();
|
||||
pageMap.putAll(variableMap.getVariableMap());
|
||||
|
||||
//采用javascript的方式,按实参顺序对应形参顺序
|
||||
List<String> varList = _function.getVariableNameList();
|
||||
for (int i=0;i<paramList.size();i++)
|
||||
{
|
||||
String key = varList.get(i);
|
||||
Object value = paramList.get(i).build(variableMap);
|
||||
pageMap.put(key, value);
|
||||
}
|
||||
|
||||
try
|
||||
{//转到全局函数处理,新建变量表,重新定义页变量表
|
||||
ZmlVariable variable = new ZmlVariable();
|
||||
variable.setZml(variableMap.getZml());
|
||||
variable.setVariableMap(pageMap);
|
||||
variable.setContextMap(variableMap.getContextMap());
|
||||
variable.setFunctionMap(variableMap.getFunctionMap());
|
||||
|
||||
return _function.build(variable);
|
||||
}
|
||||
catch (StatementException e)
|
||||
{
|
||||
throw new ExpressionException("方法表达式{"+this+"}对应的全局函数处理异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
/** 方法是构造函数 */
|
||||
private Object buildNewInstance(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
Class<?> newClass = ZmlEngine.getJavaClass(methodName);
|
||||
if (newClass == null)
|
||||
newClass = Global.forName(methodName);
|
||||
|
||||
if (newClass == null)
|
||||
throw new ExpressionException("方法表达式{"+this+"}对应的new构造函数类名不正确");
|
||||
|
||||
Object[] paramArray = new Object[paramList.size()];
|
||||
for (int i=0;i<paramList.size();i++)
|
||||
{
|
||||
paramArray[i] = paramList.get(i).build(variableMap);
|
||||
}
|
||||
|
||||
//找到一个构造函数匹配上的
|
||||
Constructor<?> constructor = null;
|
||||
Constructor<?>[] constructors = newClass.getConstructors();
|
||||
for (Constructor<?> c : constructors)
|
||||
{
|
||||
//判断参数个数
|
||||
Class<?>[] paramTypes = c.getParameterTypes();
|
||||
if (paramTypes.length != paramArray.length)
|
||||
continue;
|
||||
|
||||
//判断每个参数类型
|
||||
boolean isSuccess = true;
|
||||
for (int i=0;i<paramTypes.length;i++)
|
||||
{
|
||||
Class<?> clazz = paramTypes[i];
|
||||
Object param = paramArray[i];
|
||||
if (param == null)
|
||||
{//参数为null时,要求不是基本类型
|
||||
if (Types.isPrimitive(clazz))
|
||||
{
|
||||
isSuccess = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (Types.isPrimitive(clazz))
|
||||
{//基本类型,数值型不一定匹配,要适配
|
||||
if ((Types.isInteger(clazz) && !Types.isInteger(param))//long,int,short,byte
|
||||
|| (Types.isDecimal(clazz) && !Types.isDecimal(param))//float,double
|
||||
|| (Types.isBoolean(clazz) && !Types.isBoolean(param))//boolean
|
||||
|| (Types.isChar(clazz) && !Types.isChar(param)))//char
|
||||
{
|
||||
isSuccess = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{//对象类型,判断是否其子类或本类
|
||||
if (clazz != param.getClass() && !clazz.isAssignableFrom(param.getClass()))
|
||||
{
|
||||
isSuccess = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isSuccess)
|
||||
continue;
|
||||
|
||||
constructor = c;
|
||||
break;
|
||||
}
|
||||
|
||||
if (constructor == null)
|
||||
throw new ExpressionException("方法表达式{"+this+"},格式不正确,没有找到对应的构造函数");
|
||||
|
||||
//_Integer,_Double可能格式不同,要匹配
|
||||
Class<?>[] paramTypes = constructor.getParameterTypes();
|
||||
for (int i=0;i<paramTypes.length;i++)
|
||||
{
|
||||
Class<?> clazz = paramTypes[i];
|
||||
if (!Types.isNumber(clazz))
|
||||
continue;
|
||||
|
||||
if (Types.isDecimal(clazz))
|
||||
{//小数
|
||||
Object param = paramArray[i];
|
||||
if (!Types.isDecimal(param))
|
||||
throw new ExpressionException("方法表达式{"+this+"},格式不正确,参数不匹配,要求小数");
|
||||
|
||||
//需要对double/float进行匹配
|
||||
if (Types.isDouble(clazz))
|
||||
paramArray[i] = ((Number)param).doubleValue();
|
||||
else
|
||||
paramArray[i] = ((Double)param).floatValue();
|
||||
}
|
||||
else
|
||||
{//整数
|
||||
Object param = paramArray[i];
|
||||
if (!Types.isInteger(param))
|
||||
throw new ExpressionException("方法表达式{"+this+"},格式不正确,参数不匹配,要求整数");
|
||||
|
||||
//需要对long/byte/short/int进行匹配
|
||||
if (Types.isLong(clazz))
|
||||
paramArray[i] = ((Number)param).longValue();
|
||||
else if (Types.isInt(clazz))
|
||||
paramArray[i] = ((Number)param).intValue();
|
||||
else if (Types.isShort(clazz))
|
||||
paramArray[i] = ((Number)param).shortValue();
|
||||
else
|
||||
paramArray[i] = ((Number)param).byteValue();
|
||||
}
|
||||
}
|
||||
|
||||
//调用方法
|
||||
try
|
||||
{
|
||||
constructor.setAccessible(true);
|
||||
return constructor.newInstance(paramArray);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e instanceof InvocationTargetException)
|
||||
throw new ExpressionException("方法表达式{"+this+"},调用失败{"+((InvocationTargetException)e).getTargetException().getMessage()+"}");
|
||||
else
|
||||
throw new ExpressionException("方法表达式{"+this+"},调用失败{"+e.getMessage()+"}");
|
||||
}
|
||||
}
|
||||
|
||||
/** 对象方法 */
|
||||
private Object buildMethod(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
Object target = obj.build(variableMap);
|
||||
if (target != null)
|
||||
return buildMethod(variableMap, target.getClass(), target);
|
||||
|
||||
if (!(obj instanceof _Variable))
|
||||
return null;
|
||||
|
||||
Class<?> targetClass = ((_Variable)obj).buildClass();
|
||||
if (targetClass == null)
|
||||
return null;
|
||||
|
||||
return buildMethod(variableMap, targetClass, null);
|
||||
}
|
||||
|
||||
/** 对象方法 */
|
||||
private Object buildMethod(ZmlVariable variableMap, Class<?> targetClass, Object target) throws ExpressionException
|
||||
{
|
||||
//1.先漏选方法,把名称不同的和要求静态方法但不是静态方法的去掉
|
||||
List<Method> normalMethodList = new ArrayList<>();
|
||||
List<Method> arrayMethodList = new ArrayList<>();
|
||||
|
||||
Method[] methods = targetClass.getMethods();
|
||||
for (Method m : methods)
|
||||
{
|
||||
if (!m.getName().equals(methodName))
|
||||
continue;
|
||||
|
||||
if (target == null && !Classes.isStaticMethod(m))
|
||||
continue;
|
||||
|
||||
if (Classes.isMethodLastParamArray(m))
|
||||
arrayMethodList.add(m);
|
||||
else
|
||||
normalMethodList.add(m);
|
||||
}
|
||||
|
||||
if (normalMethodList.isEmpty())
|
||||
{//未找到对应的方法
|
||||
throw new ExpressionException("方法表达式{"+this+"},格式不正确,没有找到对应的方法名或要求是静态方法");
|
||||
}
|
||||
|
||||
Object[] paramArray = new Object[paramList.size()];
|
||||
for (int i=0;i<paramList.size();i++)
|
||||
{
|
||||
paramArray[i] = paramList.get(i).build(variableMap);
|
||||
}
|
||||
|
||||
//2.通过参数匹配,找到对应的方法
|
||||
Method method = null;
|
||||
|
||||
//2.1优先找最后一个参数不是数组的方法
|
||||
for (Method m : normalMethodList)
|
||||
{
|
||||
Class<?>[] paramTypes = m.getParameterTypes();
|
||||
if (Classes.isMethodParamMatch(paramTypes, paramArray))
|
||||
{//正常的参数个数匹配成功
|
||||
method = m;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (method == null)
|
||||
{//2.2再找最后一个参数是数组的,转化个数相等再比较
|
||||
for (Method m : arrayMethodList)
|
||||
{
|
||||
//判断参数个数
|
||||
Class<?>[] paramTypes = m.getParameterTypes();
|
||||
int typeLen = paramTypes.length;
|
||||
int arrayLen = paramArray.length;
|
||||
if (typeLen > arrayLen)
|
||||
{//大于的
|
||||
continue;
|
||||
}
|
||||
else if (typeLen == arrayLen)
|
||||
{//相等的
|
||||
if (Classes.isMethodParamMatch(paramTypes, paramArray))
|
||||
{
|
||||
method = m;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{//小于的,则支持参数最后部分转化为多个参数方式String... params的形参,而实参是"abc", "bde"的情况
|
||||
Class<?> paramLastType = paramTypes[typeLen-1].getComponentType();
|
||||
Class<?>[] newParamTypes = new Class<?>[arrayLen];
|
||||
for (int i=0;i<typeLen-1;i++)
|
||||
{
|
||||
newParamTypes[i] = paramTypes[i];
|
||||
}
|
||||
for (int i=typeLen-1;i<arrayLen;i++)
|
||||
{
|
||||
newParamTypes[i] = paramLastType;
|
||||
}
|
||||
|
||||
if (Classes.isMethodParamMatch(newParamTypes, paramArray))
|
||||
{
|
||||
method = m;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (method == null)
|
||||
{//2.3 方法参数没找到
|
||||
throw new ExpressionException("方法表达式{"+this+"},格式不正确,方法名找到,但参数个数未对应");
|
||||
}
|
||||
|
||||
//3._Integer,_Double可能格式不同,要匹配
|
||||
Class<?>[] paramTypes = method.getParameterTypes();
|
||||
for (int i=0;i<paramTypes.length;i++)
|
||||
{
|
||||
Class<?> clazz = paramTypes[i];
|
||||
if (!Types.isNumber(clazz))
|
||||
continue;
|
||||
|
||||
if (Types.isDecimal(clazz))
|
||||
{//小数
|
||||
Object param = paramArray[i];
|
||||
if (!Types.isDecimal(param))
|
||||
throw new ExpressionException("方法表达式{"+this+"},格式不正确,方法名找到且参数个数一致,参数值不匹配,要求小数");
|
||||
|
||||
//需要对double/float进行匹配
|
||||
if (Types.isDouble(clazz))
|
||||
paramArray[i] = ((Number)param).doubleValue();
|
||||
else
|
||||
paramArray[i] = ((Double)param).floatValue();
|
||||
}
|
||||
else
|
||||
{//整数
|
||||
Object param = paramArray[i];
|
||||
if (!Types.isInteger(param))
|
||||
throw new ExpressionException("方法表达式{"+this+"},格式不正确,方法名找到且参数个数一致,参数不匹配,要求整数");
|
||||
|
||||
//需要对long/byte/short/int进行匹配
|
||||
if (Types.isLong(clazz))
|
||||
paramArray[i] = ((Number)param).longValue();
|
||||
else if (Types.isInt(clazz))
|
||||
paramArray[i] = ((Number)param).intValue();
|
||||
else if (Types.isShort(clazz))
|
||||
paramArray[i] = ((Number)param).shortValue();
|
||||
else
|
||||
paramArray[i] = ((Number)param).byteValue();
|
||||
}
|
||||
}
|
||||
|
||||
//4.最后一个形参是数组,而实参不是数组的转变为数组
|
||||
boolean lastParamIsArray = paramTypes.length > 0 && Types.isArray(paramTypes[paramTypes.length-1]);
|
||||
if (lastParamIsArray && !Types.isArray(paramArray[paramTypes.length-1]))
|
||||
{
|
||||
Class<?> paramLastType = paramTypes[paramTypes.length-1].getComponentType();
|
||||
int num = paramArray.length-paramTypes.length+1;
|
||||
Object[] objs = Classes.newInstance(paramLastType, num);
|
||||
for (int i=0;i<num;i++)
|
||||
{
|
||||
objs[i] = paramArray[paramTypes.length-1+i];
|
||||
}
|
||||
|
||||
Object[] newParamArray = new Object[paramTypes.length];
|
||||
for (int i=0;i<newParamArray.length-1;i++)
|
||||
{
|
||||
newParamArray[i] = paramArray[i];
|
||||
}
|
||||
newParamArray[newParamArray.length-1] = objs;
|
||||
paramArray = newParamArray;
|
||||
}
|
||||
|
||||
//5.调用方法
|
||||
try
|
||||
{
|
||||
method.setAccessible(true);
|
||||
if (Classes.isStaticMethod(method))
|
||||
return method.invoke(null, paramArray);
|
||||
else
|
||||
return method.invoke(target, paramArray);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e instanceof InvocationTargetException)
|
||||
throw new ExpressionException("方法表达式{"+this+"},调用失败{"+((InvocationTargetException)e).getTargetException().getMessage()+"}");
|
||||
else
|
||||
throw new ExpressionException("方法表达式{"+this+"},调用失败{"+e.getMessage()+"}");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder strb = new StringBuilder();
|
||||
if (obj != null)
|
||||
{
|
||||
strb.append(obj);
|
||||
if (obj instanceof _New)
|
||||
strb.append(" ");
|
||||
else
|
||||
strb.append(".");
|
||||
}
|
||||
|
||||
strb.append(methodName).append("(");
|
||||
if (!paramList.isEmpty())
|
||||
{
|
||||
strb.append(paramList.get(0));
|
||||
for (int i=1;i<paramList.size();i++)
|
||||
{
|
||||
strb.append(", ").append(paramList.get(i));
|
||||
}
|
||||
}
|
||||
strb.append(")");
|
||||
|
||||
return strb.toString();
|
||||
}
|
||||
|
||||
public String getMethodName()
|
||||
{
|
||||
return methodName;
|
||||
}
|
||||
|
||||
public Expression getObject()
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
|
||||
/** 合并前面的对象表达式 */
|
||||
public void setObject(Expression obj)
|
||||
{
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
/** 设置为New */
|
||||
public void setNew(Expression obj, String className)
|
||||
{
|
||||
this.obj = obj;
|
||||
this.methodName = className;
|
||||
}
|
||||
|
||||
/** 解析括号得到实参列表 */
|
||||
public void parseBracketParamList(_Bracket bracket) throws ExpressionException
|
||||
{
|
||||
ArrayList<Expression> eList = bracket.getExpressionList();
|
||||
eList.trimToSize();
|
||||
|
||||
//左右括号去除
|
||||
eList.remove(0);
|
||||
eList.remove(eList.size()-1);
|
||||
|
||||
//解析所有操作符
|
||||
ExpressionParser.parse_Operator(eList);
|
||||
|
||||
//对结果进行分析,除逗号外都是参数
|
||||
for (Expression expression : eList)
|
||||
{
|
||||
int type = expression.getType();
|
||||
if (type == COMMA)
|
||||
continue;//,除外
|
||||
|
||||
paramList.add(expression);
|
||||
}
|
||||
|
||||
eList = null;
|
||||
paramList.trimToSize();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import org.zhiqim.kernel.util.Types;
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
|
||||
/**
|
||||
* 求模运算(%)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Modulus extends Operator
|
||||
{
|
||||
private final Expression left;
|
||||
private final Expression right;
|
||||
|
||||
public _Modulus(Expression left, Expression right)
|
||||
{
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return MODULUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
Object privous = left.build(variableMap);
|
||||
Object next = right.build(variableMap);
|
||||
|
||||
if (!Types.isInteger(privous) || !Types.isInteger(next))
|
||||
{//不是整数
|
||||
throw new ExpressionException("求模表达式{"+this+"},格式不正确,除数或被除数不是整数");
|
||||
}
|
||||
|
||||
long dividend = ((Number)privous).longValue();
|
||||
long divisor = ((Number)next).longValue();
|
||||
return dividend % divisor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuilder().append(left).append(" % ").append(right).toString() ;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import org.zhiqim.kernel.util.Types;
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
|
||||
/**
|
||||
* 乘法运算符(*)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Multiplication extends Operator
|
||||
{
|
||||
private final Expression left;
|
||||
private final Expression right;
|
||||
|
||||
public _Multiplication(Expression left, Expression right)
|
||||
{
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return MULTIPLICATION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
Object privous = left.build(variableMap);
|
||||
Object next = right.build(variableMap);
|
||||
|
||||
if (!Types.isNumber(privous) || !Types.isNumber(next))
|
||||
{//不是整数和小数
|
||||
throw new ExpressionException("乘法表达式{"+this+"},格式不正确,出现乘数不是数值型");
|
||||
}
|
||||
|
||||
Number p = (Number)privous;
|
||||
Number n = (Number)next;
|
||||
|
||||
if (Types.isInteger(privous))
|
||||
{//整数
|
||||
if (Types.isInteger(next))
|
||||
return p.longValue() * n.longValue();
|
||||
else
|
||||
return p.longValue() * n.doubleValue();
|
||||
}
|
||||
else
|
||||
{//小数
|
||||
if (Types.isInteger(next))
|
||||
return p.doubleValue() * n.longValue();
|
||||
else
|
||||
return p.doubleValue() * n.doubleValue();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuilder().append(left).append(" * ").append(right).toString() ;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
import org.zhiqim.zml.expression.primitive._Decimal;
|
||||
import org.zhiqim.zml.expression.primitive._Integer;
|
||||
|
||||
/**
|
||||
* 取负运算(-)
|
||||
*
|
||||
* @see _Subtraction 和减号 运算符相同,要注意区分
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Negative extends Operator
|
||||
{
|
||||
private final Expression obj;
|
||||
|
||||
public _Negative(Expression obj)
|
||||
{
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return NEGATIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
Object value = obj.build(variableMap);
|
||||
if (value instanceof Long)
|
||||
{
|
||||
long v = (Long)value;
|
||||
return -v;
|
||||
}
|
||||
else if (value instanceof Double)
|
||||
{
|
||||
double v = (Double)value;
|
||||
return -v;
|
||||
}
|
||||
|
||||
throw new ExpressionException("取负表达式{"+this+"}格式不正常,要求结果不是整数或小数");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuilder("-").append(obj).toString() ;
|
||||
}
|
||||
|
||||
public Number getValue() throws ExpressionException
|
||||
{
|
||||
if (obj instanceof _Integer)
|
||||
{
|
||||
_Integer value = (_Integer)obj;
|
||||
return -value.getLong();
|
||||
}
|
||||
else if (obj instanceof _Decimal)
|
||||
{
|
||||
_Decimal value = (_Decimal)obj;
|
||||
return -value.getDouble();
|
||||
}
|
||||
else if (obj instanceof _Bracket)
|
||||
{
|
||||
Expression expression = ((_Bracket)obj).getExpression();
|
||||
if (expression instanceof _Integer)
|
||||
{
|
||||
_Integer value = (_Integer)obj;
|
||||
return -value.getLong();
|
||||
}
|
||||
else if (expression instanceof _Decimal)
|
||||
{
|
||||
_Decimal value = (_Decimal)obj;
|
||||
return -value.getDouble();
|
||||
}
|
||||
}
|
||||
|
||||
throw new ExpressionException("[逻辑取负运算符]解析时异常,对象不是数值型["+obj+"]");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
|
||||
/**
|
||||
* new 运算符,搭配_Method一起完成newInstance
|
||||
* @see _Method
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2016-6-27 新建与整理
|
||||
*/
|
||||
public class _New extends Operator
|
||||
{
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return NEW;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "new";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
|
||||
/**
|
||||
* 取反运算(!)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Not extends Operator
|
||||
{
|
||||
private final Expression obj;
|
||||
|
||||
public _Not(Expression obj)
|
||||
{
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return NOT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
Object value = obj.build(variableMap);
|
||||
if (value instanceof Boolean)
|
||||
{
|
||||
boolean v = (Boolean)value;
|
||||
return !v;
|
||||
}
|
||||
|
||||
throw new ExpressionException("取反表达式{"+this+"}格式不正常,要求结果不是布尔型");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuilder("!").append(obj).toString() ;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import org.zhiqim.kernel.util.Types;
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
|
||||
/**
|
||||
* 或运算符(||)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Or extends Operator
|
||||
{
|
||||
private final Expression left;
|
||||
private final Expression right;
|
||||
|
||||
public _Or(Expression left, Expression right)
|
||||
{
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return OR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
Object privous = left.build(variableMap);
|
||||
if (!Types.isBoolean(privous))
|
||||
throw new ExpressionException("逻辑或表达式{"+this+"}格式不正常,要求结果不是布尔型");
|
||||
|
||||
if ((Boolean)privous)
|
||||
return true;//当左值为真时,不处理右值
|
||||
|
||||
Object next = right.build(variableMap);
|
||||
if (!Types.isBoolean(next))
|
||||
throw new ExpressionException("逻辑或表达式{"+this+"}格式不正常,要求结果不是布尔型");
|
||||
|
||||
return (Boolean)next;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuilder().append(left).append(" || ").append(right).toString() ;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.zhiqim.kernel.Global;
|
||||
import org.zhiqim.kernel.util.Classes;
|
||||
import org.zhiqim.zml.ZmlEngine;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.exception.PropertNotExistException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
|
||||
/**
|
||||
* 属性表达式,来自两种方式
|
||||
* 1.点号表示法:variable.property
|
||||
* 2.索引表示法:variable["property"]
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2016-12-23 新建与整理
|
||||
*/
|
||||
public class _Property extends Operator
|
||||
{
|
||||
private String variable;
|
||||
private Class<?> clazz;
|
||||
private Object target;
|
||||
|
||||
private final String property;
|
||||
|
||||
public _Property(String variable, String property)
|
||||
{
|
||||
this.variable = variable;
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
public _Property(Class<?> clazz, String property)
|
||||
{
|
||||
this.clazz = clazz;
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
public _Property(Object target, String property)
|
||||
{
|
||||
this.target = target;
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return PROPERTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
ExpressionException.asserts(clazz != null || variable != null || target != null, "属性表达式{"+this+"},实例和类不能都为null");
|
||||
ExpressionException.assertNotNull(property, "属性表达式{"+this+"},属性名不能为null");
|
||||
|
||||
if (target != null)
|
||||
{//实例属性
|
||||
Field field = Classes.getFieldDeep(target.getClass(), property);
|
||||
if (field != null)
|
||||
{//找到字段,则表示定义是正确的
|
||||
return Classes.getFieldValue(target, field);
|
||||
}
|
||||
}
|
||||
else if (clazz != null)
|
||||
{//静态属性
|
||||
Field field = Classes.getFieldStaticDeep(clazz, property);
|
||||
if (field != null)
|
||||
{//找到字段,则表示定义是正确的
|
||||
return Classes.getFieldValue(null, field);
|
||||
}
|
||||
}
|
||||
else
|
||||
{//通过名称先判断实例属性还判断静态属性
|
||||
|
||||
//1.先查实例属性
|
||||
Object obj = variableMap.get(variable);
|
||||
if (obj != null)
|
||||
{
|
||||
Field field = Classes.getFieldDeep(obj.getClass(), property);
|
||||
if (field != null)
|
||||
{//找到字段,则表示定义是正确的
|
||||
return Classes.getFieldValue(obj, field);
|
||||
}
|
||||
}
|
||||
|
||||
//2 再查静态属性
|
||||
Class<?> clazz = ZmlEngine.getJavaClass(variable);
|
||||
if (clazz == null)
|
||||
clazz = Global.forName(variable);
|
||||
|
||||
if (clazz != null)
|
||||
{
|
||||
Field field = Classes.getFieldStaticDeep(clazz, property);
|
||||
if (field != null)
|
||||
{//找到字段,则表示定义是正确的
|
||||
return Classes.getFieldValue(null, field);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new PropertNotExistException("未找到对应的属性");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import org.zhiqim.kernel.util.Types;
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
|
||||
/**
|
||||
* 减法运算(-),支持整数、小数和字符相减<br><br>
|
||||
*
|
||||
* 1、整数相减 56-23,46-21.12,102-'A'<br>
|
||||
* 2、小数相减 56.6-23,46.9-21.12,102.2-'A'<br>
|
||||
* 3、字符相减 'A'-23,'a'-21.12,'Z'-'A'<br>
|
||||
* @see _Negative 和逻辑取负 运算符相同,要注意区分
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Subtraction extends Operator
|
||||
{
|
||||
private final Expression left;
|
||||
private final Expression right;
|
||||
|
||||
public _Subtraction(Expression left, Expression right)
|
||||
{
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return SUBTRACTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
Object privous = left.build(variableMap);
|
||||
Object next = right.build(variableMap);
|
||||
|
||||
if ((!Types.isNumber(privous) && !Types.isChar(privous))
|
||||
|| (!Types.isNumber(next) && !Types.isChar(next)))
|
||||
{//不是整数和小数
|
||||
throw new ExpressionException("减法表达式{"+this+"},格式不正确,减数或被减数不是数值型");
|
||||
}
|
||||
|
||||
if (Types.isInteger(privous))
|
||||
{//整数
|
||||
long minuend = ((Number)privous).longValue();
|
||||
if (Types.isInteger(next))
|
||||
{
|
||||
long subtrahend = ((Number)next).longValue();
|
||||
return minuend - subtrahend;
|
||||
}
|
||||
else if (Types.isDecimal(next))
|
||||
{
|
||||
double subtrahend = ((Number)next).doubleValue();
|
||||
return minuend - subtrahend;
|
||||
}
|
||||
else
|
||||
{
|
||||
char subtrahend = (Character)next;
|
||||
return minuend - subtrahend;
|
||||
}
|
||||
}
|
||||
else if (Types.isDecimal(privous))
|
||||
{//小数
|
||||
double minuend = ((Number)privous).doubleValue();
|
||||
if (Types.isInteger(next))
|
||||
{
|
||||
long subtrahend = ((Number)next).longValue();
|
||||
return minuend - subtrahend;
|
||||
}
|
||||
else if (Types.isDecimal(next))
|
||||
{
|
||||
double subtrahend = ((Number)next).doubleValue();
|
||||
return minuend - subtrahend;
|
||||
}
|
||||
else
|
||||
{
|
||||
char subtrahend = (Character)next;
|
||||
return minuend - subtrahend;
|
||||
}
|
||||
}
|
||||
else
|
||||
{//字符
|
||||
char minuend = (Character)privous;
|
||||
if (Types.isInteger(next))
|
||||
{
|
||||
long subtrahend = ((Number)next).longValue();
|
||||
return minuend - subtrahend;
|
||||
}
|
||||
else if (Types.isDecimal(next))
|
||||
{
|
||||
double subtrahend = ((Number)next).doubleValue();
|
||||
return minuend - subtrahend;
|
||||
}
|
||||
else
|
||||
{
|
||||
char subtrahend = (Character)next;
|
||||
return minuend - subtrahend;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuilder().append(left).append(" - ").append(right).toString() ;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.operator;
|
||||
|
||||
import org.zhiqim.zml.Expression;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Operator;
|
||||
|
||||
/**
|
||||
* 三目运算(?a:b)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2018-1-2 新建与整理
|
||||
*/
|
||||
public class _Ternary extends Operator
|
||||
{
|
||||
private Expression obj;
|
||||
private Expression first;
|
||||
private Expression second;
|
||||
|
||||
public _Ternary(Expression condition, Expression first, Expression second)
|
||||
{
|
||||
this.obj = condition;
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return TERNARY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
Object value = obj.build(variableMap);
|
||||
if (value == null)
|
||||
{//为null时,采用js的规则,判断为false
|
||||
return second.build(variableMap);
|
||||
}
|
||||
|
||||
if (value instanceof Boolean)
|
||||
{//值为boolean型
|
||||
return ((Boolean)value)?first.build(variableMap):second.build(variableMap);
|
||||
}
|
||||
|
||||
//非null且非boolean的不支持
|
||||
throw new ExpressionException("三目表达式{"+this+"}格式不正常,条件不是布尔型");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.primitive;
|
||||
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Primitive;
|
||||
|
||||
/**
|
||||
* 布尔原型,true/false
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Boolean extends Primitive
|
||||
{
|
||||
private final boolean value;
|
||||
|
||||
public _Boolean(boolean value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return BOOLEAN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.valueOf(value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.primitive;
|
||||
|
||||
import org.zhiqim.kernel.util.Asserts;
|
||||
import org.zhiqim.kernel.util.Validates;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Primitive;
|
||||
|
||||
/**
|
||||
* 字符原型,格式为用单引号之内的一个字母或符号,如'a','$'
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Char extends Primitive
|
||||
{
|
||||
private final char value;
|
||||
|
||||
public _Char(String value)
|
||||
{
|
||||
Asserts.as(Validates.isLen(value, 3, 4)?null:"字符["+value+"]格式不对");
|
||||
Asserts.as(value.startsWith("'")?null:"字符["+value+"]格式不对");
|
||||
Asserts.as(value.endsWith("'")?null:"字符["+value+"]格式不对");
|
||||
|
||||
value = value.substring(1, value.length()-1);
|
||||
if (value.length() == 1)
|
||||
{
|
||||
this.value = value.charAt(0);
|
||||
return;
|
||||
}
|
||||
|
||||
//长度==2时,第一个字符必须是转义字符
|
||||
Asserts.as(value.length() == 2?null:"字符["+value+"]格式不对");
|
||||
Asserts.as('\\' == value.charAt(0)?null:"字符["+value+"]格式不对");
|
||||
|
||||
char tc = value.charAt(1);
|
||||
switch (tc)
|
||||
{
|
||||
case '\\':this.value = '\\';;break;
|
||||
case '\"':this.value = '\"';break;
|
||||
case '\'':this.value = '\'';break;
|
||||
case 'b':this.value = '\b';break;
|
||||
case 'f':this.value = '\f';break;
|
||||
case 'n':this.value = '\n';break;
|
||||
case 'r':this.value = '\r';break;
|
||||
case 't':this.value = '\t';break;
|
||||
default:throw Asserts.exception("字符["+value+"]格式不对");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return CHAR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
public char getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.primitive;
|
||||
|
||||
import org.zhiqim.kernel.Global;
|
||||
import org.zhiqim.kernel.util.Strings;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Primitive;
|
||||
|
||||
/**
|
||||
* 类原型,如FTable.class
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2016-6-27 新建与整理
|
||||
*/
|
||||
public class _Class extends Primitive
|
||||
{
|
||||
private String value;
|
||||
|
||||
public _Class(String value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return CLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
String className = Strings.trimRight(value, ".class");
|
||||
return Global.forName(className);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "class";
|
||||
}
|
||||
|
||||
public String getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.primitive;
|
||||
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Primitive;
|
||||
import org.zhiqim.zml.expression.operator._Negative;
|
||||
|
||||
/**
|
||||
* 小数原型,float/double,零点开头后面为数字,或非零数字开头数字和一个点号连贯出现"^(0|[1-9]\\d*)(\\.\\d+)?$"
|
||||
*
|
||||
* @see _Negative 逻辑取负,如果前面有-号,则为负小数原型
|
||||
*
|
||||
* @see Float 四个字节
|
||||
* @see Double 八个字节
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Decimal extends Primitive
|
||||
{
|
||||
private final String value;
|
||||
|
||||
public _Decimal(String value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return DECIMAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
return Double.parseDouble(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
public double getDouble()
|
||||
{
|
||||
return Double.parseDouble(value);
|
||||
}
|
||||
|
||||
public float getFloat()
|
||||
{
|
||||
return Float.parseFloat(value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.primitive;
|
||||
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Primitive;
|
||||
|
||||
/**
|
||||
* 整数原型,byte/short/int/long,非零数字开头数字连贯出现"^[1-9]\\d*$"<br><br>
|
||||
* 但是实际中可能出现0123,这种情况,和点号一起组合成_Decimal
|
||||
*
|
||||
* @see Byte 一个字节
|
||||
* @see Short 二个字节
|
||||
* @see Integer 四个字节
|
||||
* @see Long 八个字节
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Integer extends Primitive
|
||||
{
|
||||
private final String value;
|
||||
|
||||
public _Integer(String value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return NUMBERIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
return Long.parseLong(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
public long getLong()
|
||||
{
|
||||
return Long.parseLong(value);
|
||||
}
|
||||
|
||||
public int getInt()
|
||||
{
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
|
||||
public short getShort()
|
||||
{
|
||||
return Short.parseShort(value);
|
||||
}
|
||||
|
||||
public byte getByte()
|
||||
{
|
||||
return Byte.parseByte(value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.primitive;
|
||||
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Primitive;
|
||||
|
||||
/**
|
||||
* null原型
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Null extends Primitive
|
||||
{
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.primitive;
|
||||
|
||||
import org.zhiqim.kernel.json.Jsons;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.expression.Primitive;
|
||||
|
||||
/**
|
||||
* 字符串原型,格式为""或''之间的内容,注意转义字符
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _String extends Primitive
|
||||
{
|
||||
private final String value;
|
||||
|
||||
public _String(String value)
|
||||
{
|
||||
this.value = Jsons.removeStartEndQuotation(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return STRING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuilder().append("\"").append(value).append("\"").toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.primitive;
|
||||
|
||||
import org.zhiqim.kernel.Global;
|
||||
import org.zhiqim.kernel.annotation.AnGlobal;
|
||||
import org.zhiqim.kernel.util.Classes;
|
||||
import org.zhiqim.zml.ZmlEngine;
|
||||
import org.zhiqim.zml.ZmlVariable;
|
||||
import org.zhiqim.zml.exception.ExpressionException;
|
||||
import org.zhiqim.zml.exception.PropertNotExistException;
|
||||
import org.zhiqim.zml.expression.Primitive;
|
||||
import org.zhiqim.zml.expression.operator._Property;
|
||||
|
||||
/**
|
||||
* 变量原型,格式为字母或下划线开头,(字母、下划线和数字)连贯
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
* @version v1.0.1 @author zouzhigang 2015-10-22 增加对AnAlias,AnStatic,AnGlobal,AnNew的支持
|
||||
* @version v1.2.2 @author zhichenggang 2016-12-21 删除AnStatic的支持,修改为增加buildClass当是类结构但不是AnGlobal,AnNew时再检查调用
|
||||
* @version v1.4.0 @author zouzhigang 2018-01-19 删除对AnNew的支持,AnNew定义为必须前缀new的别名对象
|
||||
*/
|
||||
public class _Variable extends Primitive
|
||||
{
|
||||
private String value;
|
||||
private Class<?> cls;
|
||||
|
||||
public _Variable(String value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/** 重新设置值 */
|
||||
public void setValue(String value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return VARIABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(ZmlVariable variableMap) throws ExpressionException
|
||||
{
|
||||
//1.判断是不是变量,如果是返回变量值
|
||||
Object instance = variableMap.get(value);
|
||||
if (instance != null)
|
||||
return instance;
|
||||
|
||||
//2.判断是否是java系统类名String,List等
|
||||
Class<?> cls = ZmlEngine.getJavaClass(value);
|
||||
if (cls != null)
|
||||
{
|
||||
//认为是通过类去调用静态属性或方式,直接返回null,调用者再从buildClass获取clazz去调用
|
||||
this.cls = cls;
|
||||
return null;
|
||||
}
|
||||
|
||||
//3.判断是否是AnAlias别名定义的类名,如Validates,DateTimes
|
||||
cls = Global.getClass(value);
|
||||
if (cls != null)
|
||||
{
|
||||
return returnAliasInstance(cls);
|
||||
}
|
||||
|
||||
//4.判断是否是属性,即variable.property方式
|
||||
int lastIndex = value.lastIndexOf(".");
|
||||
if (lastIndex != -1)
|
||||
{
|
||||
String name = value.substring(0, lastIndex);
|
||||
String prop = value.substring(lastIndex+1);
|
||||
|
||||
try
|
||||
{
|
||||
return new _Property(name, prop).build(variableMap);
|
||||
}
|
||||
catch(PropertNotExistException e)
|
||||
{
|
||||
//属性未找到则不返回
|
||||
}
|
||||
}
|
||||
|
||||
//5.最后认为是类全称,如org.zhiqim.kernel.util.Validates全名,或没有包名的类,如ATest
|
||||
cls = Classes.forName(value);
|
||||
if (cls != null)
|
||||
{//最少可能且最慢放最后
|
||||
return returnAliasInstance(cls);
|
||||
}
|
||||
|
||||
//都不对,就没办法了啦!
|
||||
return null;
|
||||
}
|
||||
|
||||
/** 在_Method中当build为null时再检查是否是调用静态方法 */
|
||||
public Class<?> buildClass()
|
||||
{
|
||||
return this.cls;
|
||||
}
|
||||
|
||||
private Object returnAliasInstance(Class<?> cls)
|
||||
{
|
||||
if (cls.isAnnotationPresent(AnGlobal.class))
|
||||
{//定义了AnGlobal
|
||||
return Global.getWithoutNew(cls);
|
||||
}
|
||||
|
||||
//其他的认为是通过类去调用静态属性或方式,直接返回null,调用者再从buildClass
|
||||
this.cls = cls;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.ExpressionPair;
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 和与号原型(&&)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Ampersand extends Symbol implements ExpressionPair
|
||||
{
|
||||
private boolean paired;
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return CONNECTOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return " && ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPaired()
|
||||
{
|
||||
return paired;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPaired()
|
||||
{
|
||||
this.paired = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 星号原型(*)乘号
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Asterisk extends Symbol
|
||||
{
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return ASTERISK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return " * ";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 右方括号原型(])
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _CloseBracket extends Symbol
|
||||
{
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return BRACKET_SQUARE_RIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 右圆括号原型())
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _CloseParenthesis extends Symbol
|
||||
{
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return BRACKET_RIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return ")";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 分号原型(:),用于三目运算
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2018-1-2 新建与整理
|
||||
*/
|
||||
public class _Colon extends Symbol
|
||||
{
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return COLON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return ":";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 逗号原型(,)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Comma extends Symbol
|
||||
{
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return COMMA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return ", ";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.ExpressionPair;
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
import org.zhiqim.zml.expression.operator._Method;
|
||||
import org.zhiqim.zml.expression.primitive._Decimal;
|
||||
|
||||
/**
|
||||
* 点号原型(.)<br><br>
|
||||
*
|
||||
* @see _Decimal 浮点型,Integer._Integer<br>
|
||||
* @see _Method 方法访问,_Name._Name_BracketLeft<br>
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Dot extends Symbol implements ExpressionPair
|
||||
{
|
||||
private boolean paired;
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return DOT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return ".";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPaired()
|
||||
{
|
||||
return paired;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPaired()
|
||||
{
|
||||
paired = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 双点号原型(..)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _DotDot extends Symbol
|
||||
{
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return DOTDOT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "..";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.ExpressionPair;
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 等号原型(=)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Equal extends Symbol implements ExpressionPair
|
||||
{
|
||||
private boolean paired;
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return EQUAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return " = ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPaired()
|
||||
{
|
||||
return paired;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPaired()
|
||||
{
|
||||
paired = true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.ExpressionPair;
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 感叹号原型(!)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Exclamation extends Symbol implements ExpressionPair
|
||||
{
|
||||
private boolean paired;
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return EXCLAMATION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "!";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPaired()
|
||||
{
|
||||
return paired;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPaired()
|
||||
{
|
||||
paired = true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 大于号原型(gt)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Gt extends Symbol
|
||||
{
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return GT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return " gt ";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 大于号原型(gte)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Gte extends Symbol
|
||||
{
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return GTE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return " gte ";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 不等号原型(!=)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Inequal extends Symbol
|
||||
{
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return INEQUAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return " != ";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 小于号原型(lt)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Lt extends Symbol
|
||||
{
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return LT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return " lt ";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 小于等于号原型(lte)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Lte extends Symbol
|
||||
{
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return LTE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return " lte ";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 减号/取负原型(-)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Minus extends Symbol
|
||||
{
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return MINUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "-";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 左方括号原型([)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _OpenBracket extends Symbol
|
||||
{
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return BRACKET_SQUARE_LEFT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "[";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 左圆括号原型(()
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _OpenParenthesis extends Symbol
|
||||
{
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return BRACKET_LEFT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "(";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 百分号原型(%),取模
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Percent extends Symbol
|
||||
{
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return PERCENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "%";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 加号/连接原型(+)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Plus extends Symbol
|
||||
{
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return PLUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "+";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 问号原型(?),用于三目运算
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2018-1-2 新建与整理
|
||||
*/
|
||||
public class _Question extends Symbol
|
||||
{
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return QUESTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 斜杠原型(/),除法
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _Slash extends Symbol
|
||||
{
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return SLASH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "/";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.expression.symbol;
|
||||
|
||||
import org.zhiqim.zml.ExpressionPair;
|
||||
import org.zhiqim.zml.expression.Symbol;
|
||||
|
||||
/**
|
||||
* 双竖杠符号原型(||)
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class _VerticalBar extends Symbol implements ExpressionPair
|
||||
{
|
||||
private boolean paired;
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return VERTICAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return " || ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPaired()
|
||||
{
|
||||
return paired;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPaired()
|
||||
{
|
||||
this.paired = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.loader;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import org.zhiqim.kernel.util.Resources;
|
||||
import org.zhiqim.kernel.util.Streams;
|
||||
import org.zhiqim.kernel.util.Strings;
|
||||
import org.zhiqim.kernel.util.Validates;
|
||||
import org.zhiqim.zml.Zml;
|
||||
import org.zhiqim.zml.ZmlCache;
|
||||
import org.zhiqim.zml.ZmlEngine;
|
||||
import org.zhiqim.zml.ZmlLoader;
|
||||
|
||||
/**
|
||||
* 类路径ZML加载器,指定类根路径和加载类,传入相对路径即可
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
|
||||
*/
|
||||
public class ClassZmlLoader implements ZmlLoader
|
||||
{
|
||||
private final ZmlEngine engine; //ZML引擎
|
||||
private final ZmlCache cache; //ZML缓存
|
||||
private final ClassZmlWatcher watcher; //类ZML监视
|
||||
|
||||
private final Class<?> loadClass; //加载类
|
||||
private final String contextPath; //根路径
|
||||
|
||||
/**
|
||||
* 类路径ZML加载器构造方法
|
||||
*
|
||||
* @param engine ZML引擎
|
||||
* @param loadClass 指定可访问到ZML文件的加载类
|
||||
* @param contextPath ZML路径前缀
|
||||
*/
|
||||
public ClassZmlLoader(ZmlEngine engine, Class<?> loadClass, String contextPath)
|
||||
{
|
||||
//对pathPrefix检查和处理,要求格式为/org/zhiqim/example/这种格式,最终会增加前缀/和删除后面的/
|
||||
contextPath = Strings.addStartsWith(contextPath, "/");
|
||||
contextPath = Strings.removeEndsWith(contextPath, "/");
|
||||
|
||||
this.engine = engine;
|
||||
this.loadClass = loadClass;
|
||||
this.contextPath = contextPath;
|
||||
this.cache = new ZmlCache(engine.getMaxIdleTime(), engine.getMaxKeepTime());
|
||||
this.watcher = new ClassZmlWatcher(loadClass, contextPath);
|
||||
}
|
||||
|
||||
/** 获取上下文环境路径 */
|
||||
public String getContextPath()
|
||||
{
|
||||
return contextPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasZml(String path) throws Exception
|
||||
{
|
||||
return getLastModified(path) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Zml loadZml(String path) throws Exception
|
||||
{
|
||||
long lastModified = getLastModified(path);
|
||||
if (lastModified == -1)
|
||||
{
|
||||
cache.remove(path);
|
||||
return null;
|
||||
}
|
||||
|
||||
Zml zml = cache.get(path);
|
||||
if (zml != null && lastModified == zml.getLastModified())
|
||||
{//在缓存中找到,并且缓存最修改时间和文件相同返回缓存中的ZML
|
||||
return zml;
|
||||
}
|
||||
|
||||
//未找到或最后修改时间不同,则重找
|
||||
URL url = Resources.getResource(loadClass, contextPath + path);
|
||||
URLConnection conn = url.openConnection();
|
||||
String content = Streams.getString(conn.getInputStream(), engine.getEncoding());
|
||||
zml = new Zml(engine, path, lastModified, content);
|
||||
cache.put(path, zml);
|
||||
return zml;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastModified(String path) throws Exception
|
||||
{
|
||||
if (!Strings.startsWith(path, "/") || !Validates.isMatch(path, engine.getPatterns()))
|
||||
{//要求相对于根目录的绝对路径
|
||||
throw new Exception("ZML["+path+"]配置不正确,必须/开头且符合配置的模式");
|
||||
}
|
||||
|
||||
return watcher.getLastModified(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxIdleTime(int maxIdleTime)
|
||||
{
|
||||
this.cache.setMaxIdleTime(maxIdleTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxKeepTime(int maxKeepTime)
|
||||
{
|
||||
this.cache.setMaxKeepTime(maxKeepTime);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
|
||||
*
|
||||
* 知启蒙标记语言(zhiqim_zml)在LGPL3.0协议下开源:https://www.zhiqim.com/gitcan/zhiqim/zhiqim_zml.htm
|
||||
*
|
||||
* This file is part of [zhiqim_zml].
|
||||
*
|
||||
* [zhiqim_zml] is free software: you can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* [zhiqim_zml] is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with [zhiqim_zml].
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.zhiqim.zml.loader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import org.zhiqim.kernel.extend.HashMapSV;
|
||||
import org.zhiqim.kernel.util.Resources;
|
||||
|
||||
/**
|
||||
* ZML类目录检查,所有包含*.zml文件的包,当前采用11秒内不检查
|
||||
* TODO 在1.4版本后续中进行优化
|
||||
*
|
||||
* @version v1.0.0 @author zouzhigang 2016-7-13 新建与整理
|
||||
*/
|
||||
public class ClassZmlWatcher
|
||||
{
|
||||
private final Class<?> loadClass;
|
||||
private final String pathPrefix;
|
||||
private final HashMapSV<long[]> modifiedMap;
|
||||
|
||||
public ClassZmlWatcher(Class<?> loadClass, String pathPrefix)
|
||||
{
|
||||
this.loadClass = loadClass;
|
||||
this.pathPrefix = pathPrefix;
|
||||
this.modifiedMap = new HashMapSV<>();
|
||||
}
|
||||
|
||||
public long getLastModified(String path)
|
||||
{
|
||||
long[] value = modifiedMap.get(path);
|
||||
if (value != null)
|
||||
{
|
||||
if (System.currentTimeMillis() - value[1] < 11 * 1000)
|
||||
return value[0];//11秒内不再检查更新
|
||||
}
|
||||
|
||||
URL url = Resources.getResource(loadClass, pathPrefix + path);
|
||||
if (url == null)
|
||||
{//未找到,直接返回-1
|
||||
modifiedMap.remove(path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
URLConnection conn = url.openConnection();
|
||||
long lastModified = conn.getLastModified();
|
||||
modifiedMap.put(path, new long[]{lastModified, System.currentTimeMillis()});
|
||||
return lastModified;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
modifiedMap.remove(path);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user