();
+ }
+ return setupChainBuilder;
+ }
+
+ public IocSetupBuilder addFirst(final IocSetup e) {
+ if (e == null) {
+ return this;
+ }
+ getIocSetupChainBuilder().addFirst(e);
+ return this;
+ }
+
+ public IocSetupBuilder addLast(final IocSetup e) {
+ if (e == null) {
+ return this;
+ }
+ getIocSetupChainBuilder().addLast(e);
+ return this;
+ }
+
+ public IocSetupBuilder add(final IocSetup e) {
+ return addLast(e);
+ }
+
+ public IocSetupBuilder addAllFirst(final IocSetup... e) {
+ if (e == null) {
+ return this;
+ }
+ getIocSetupChainBuilder().addAllFirst(e);
+ return this;
+ }
+
+ public IocSetupBuilder addAllLast(final IocSetup... e) {
+ if (e == null) {
+ return this;
+ }
+ getIocSetupChainBuilder().addAllLast(e);
+ return this;
+ }
+
+ public IocSetupBuilder addAll(final IocSetup... e) {
+ return addAllLast(e);
+ }
+}
diff --git a/nutz-plugins-iocloader/src/main/java/org/nutz/plugins/ioc/loader/dao/DaoIocLoader.java b/nutz-plugins-iocloader/src/main/java/org/nutz/plugins/ioc/loader/dao/DaoIocLoader.java
index 5f1f198065b529cdbbfeaf00908c3b84f6477256..b0f13185bd9fcac37281b0725d971016b27830fe 100644
--- a/nutz-plugins-iocloader/src/main/java/org/nutz/plugins/ioc/loader/dao/DaoIocLoader.java
+++ b/nutz-plugins-iocloader/src/main/java/org/nutz/plugins/ioc/loader/dao/DaoIocLoader.java
@@ -8,11 +8,12 @@ import org.nutz.dao.Dao;
import org.nutz.dao.entity.Record;
import org.nutz.ioc.IocLoading;
import org.nutz.ioc.ObjectLoadException;
+import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.json.JsonLoader;
import org.nutz.ioc.meta.IocObject;
import org.nutz.json.Json;
import org.nutz.lang.Lang;
-import org.nutz.mvc.Mvcs;
+import org.nutz.plugins.ioc.loader.ThreadIocLoader;
/**
* 从数据库加载ioc配置, 需要4个参数,
@@ -24,16 +25,31 @@ import org.nutz.mvc.Mvcs;
* select val from t_iocbean where nm="mqtt"
*
* @author wendal(wendal1985@gmail.com)
- *
+ * @rewriter 邓华锋 http://dhf.ink
*/
public class DaoIocLoader extends JsonLoader {
-
+ private static final String IOC_DAO_NAME="ioc.dao.name";
+ private static final String IOC_TABLE="ioc.table";
+ private static final String IOC_NAME_FIELD="ioc.name.field";
+ private static final String IOC_VALUE_FIELD="ioc.value.field";
+ private static final String PROPERTIES_NAME = "daoIocLoader.properties";
protected String name = "dao";
protected String table = "t_iocbean";
protected String nameField = "nm";
protected String valueField = "val";
+
protected Dao dao;
- public DaoIocLoader(String ... args) {
+
+ public DaoIocLoader() {
+ super();
+ PropertiesProxy config = new PropertiesProxy(PROPERTIES_NAME);
+ name=config.get(IOC_DAO_NAME, name);
+ table=config.get(IOC_TABLE, table);
+ nameField=config.get(IOC_NAME_FIELD, nameField);
+ valueField=config.get(IOC_VALUE_FIELD, valueField);
+ }
+
+ public DaoIocLoader(String ... args) {
if (args.length > 0) {
name = args[0];
if (args.length > 1) {
@@ -56,10 +72,10 @@ public class DaoIocLoader extends JsonLoader {
throw new ObjectLoadException("Object '" + name + "' without define!");
Map map = Json.fromJsonAsMap(Object.class, re.getString(valueField));
try {
- map.put(name, map);
+ getMap().put(name, map);
return super.load(loading, name);
} catch (Throwable e) {
- map.remove(name);
+ getMap().remove(name);
throw Lang.wrapThrow(e);
}
}
@@ -80,8 +96,8 @@ public class DaoIocLoader extends JsonLoader {
}
protected Dao dao() {
- if (dao == null)
- dao = Mvcs.getIoc().get(Dao.class, name);
+ if (dao == null)//dao = Mvcs.getIoc().get(Dao.class, name);
+ dao = ThreadIocLoader.getIoc().get(Dao.class, name);
return dao;
}
}
diff --git a/nutz-plugins-iocloader/src/test/java/ink/dhf/TestIocBean.java b/nutz-plugins-iocloader/src/test/java/ink/dhf/TestIocBean.java
new file mode 100644
index 0000000000000000000000000000000000000000..9d572cbb4add6bc80b1de8c2c2ce9435fdee67f3
--- /dev/null
+++ b/nutz-plugins-iocloader/src/test/java/ink/dhf/TestIocBean.java
@@ -0,0 +1,8 @@
+package ink.dhf;
+
+import org.nutz.ioc.loader.annotation.IocBean;
+
+@IocBean
+public class TestIocBean {
+
+}
diff --git a/nutz-plugins-iocloader/src/test/java/org/nutz/integration/quartz/NutQuartzCronJobFactory.java b/nutz-plugins-iocloader/src/test/java/org/nutz/integration/quartz/NutQuartzCronJobFactory.java
new file mode 100644
index 0000000000000000000000000000000000000000..bbf918e0743fd9b791d221b60ceef61c93abfee4
--- /dev/null
+++ b/nutz-plugins-iocloader/src/test/java/org/nutz/integration/quartz/NutQuartzCronJobFactory.java
@@ -0,0 +1,8 @@
+package org.nutz.integration.quartz;
+
+import org.nutz.ioc.loader.annotation.IocBean;
+
+@IocBean
+public class NutQuartzCronJobFactory {
+
+}
diff --git a/nutz-plugins-iocloader/src/test/java/org/nutz/plugins/ioc/loader/TestIocBean1.java b/nutz-plugins-iocloader/src/test/java/org/nutz/plugins/ioc/loader/TestIocBean1.java
new file mode 100644
index 0000000000000000000000000000000000000000..ddd644afdfe49379caa4f203a6db49c8af84da06
--- /dev/null
+++ b/nutz-plugins-iocloader/src/test/java/org/nutz/plugins/ioc/loader/TestIocBean1.java
@@ -0,0 +1,8 @@
+package org.nutz.plugins.ioc.loader;
+
+import org.nutz.ioc.loader.annotation.IocBean;
+
+@IocBean
+public class TestIocBean1 {
+
+}
diff --git a/nutz-plugins-iocloader/src/test/java/org/nutz/plugins/ioc/loader/TestThreadIocLoader.java b/nutz-plugins-iocloader/src/test/java/org/nutz/plugins/ioc/loader/TestThreadIocLoader.java
new file mode 100644
index 0000000000000000000000000000000000000000..7bbadd560f4819357d9962ae6dfd9afe021b6024
--- /dev/null
+++ b/nutz-plugins-iocloader/src/test/java/org/nutz/plugins/ioc/loader/TestThreadIocLoader.java
@@ -0,0 +1,12 @@
+package org.nutz.plugins.ioc.loader;
+
+import org.nutz.ioc.impl.PropertiesProxy;
+
+public class TestThreadIocLoader {
+ public static void main(String[] args) {
+ //ThreadIocLoader.getIoc();
+ //IocLoader daoIocLoader=new DaoIocLoader("dao","t_iocbean","nm","val");
+ //ThreadIocLoader.comboIocLoader.addLoader(daoIocLoader);
+ System.out.println(ThreadIocLoader.getIoc().get(PropertiesProxy.class, "config").get("db.url"));
+ }
+}
diff --git a/nutz-plugins-iocloader/src/test/resources/comboIocLoader.properties b/nutz-plugins-iocloader/src/test/resources/comboIocLoader.properties
new file mode 100644
index 0000000000000000000000000000000000000000..5ac787a0062e60b0cf3955a0fc582909d767e873
--- /dev/null
+++ b/nutz-plugins-iocloader/src/test/resources/comboIocLoader.properties
@@ -0,0 +1,8 @@
+ioc.main.module=
+ioc.by=*js, ioc/dao.js, *anno, ink.dhf, org.nutz.integration.quartz,org.nutz.plugins.ioc.loader
+#
+ioc.loader.classes=org.nutz.integration.quartz.NutQuartzCronJobFactory,org.nutz.plugins.ioc.loader.TestIocBean1
+#
+ioc.setup.first=
+ioc.setup.last=
+ioc.combo.loader=org.nutz.plugins.ioc.loader.dao.DaoIocLoader
\ No newline at end of file
diff --git a/nutz-plugins-iocloader/src/test/resources/custom/db.properties b/nutz-plugins-iocloader/src/test/resources/custom/db.properties
new file mode 100644
index 0000000000000000000000000000000000000000..f69bcbcc068ff2d00402a1781666895d862d1007
--- /dev/null
+++ b/nutz-plugins-iocloader/src/test/resources/custom/db.properties
@@ -0,0 +1,24 @@
+db.driverClassName=com.mysql.jdbc.Driver
+db.validationQuery=SELECT 1
+db.defaultAutoCommit=false
+db.maxWait=180000
+db.testWhileIdle=true
+db.maxActive=1000
+db.filters=mergeStat
+db.connectionProperties=druid.stat.slowSqlMillis=180000
+db.timeBetweenEvictionRunsMillis=3000
+db.minEvictableIdleTimeMillis=300000
+db.poolPreparedStatements=true
+db.maxPoolPreparedStatementPerConnectionSize=20
+db.initialSize=1
+db.minIdle=1
+db.testWhileIdle=true;
+db.testOnBorrow=false
+db.testOnReturn=false
+db.removeAbandoned=true
+db.removeAbandonedTimeout=180
+db.logAbandoned=true
+db.url=jdbc:mysql://localhost:3306/jqgrid?autoReconnect=true&autoReconnectForPools=true&maxReconnects=3&serverTimezone=CST&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&noAccessToProcedureBodies=true
+db.username=root
+db.password=root
+
diff --git a/nutz-plugins-iocloader/src/test/resources/daoIocLoader.properties b/nutz-plugins-iocloader/src/test/resources/daoIocLoader.properties
new file mode 100644
index 0000000000000000000000000000000000000000..8e53054e1485d20b54ab27c03f7613fbf6fb83f3
--- /dev/null
+++ b/nutz-plugins-iocloader/src/test/resources/daoIocLoader.properties
@@ -0,0 +1,4 @@
+ioc.dao.name=dao
+ioc.table=t_iocbean
+ioc.name.field=nm
+ioc.value.field=val
\ No newline at end of file
diff --git a/nutz-plugins-iocloader/src/test/resources/ioc/dao.js b/nutz-plugins-iocloader/src/test/resources/ioc/dao.js
new file mode 100644
index 0000000000000000000000000000000000000000..78a401334b53c4ccfe82c141da5780dff3c4829c
--- /dev/null
+++ b/nutz-plugins-iocloader/src/test/resources/ioc/dao.js
@@ -0,0 +1,91 @@
+var ioc = {
+ conf : {
+ type : "org.nutz.ioc.impl.PropertiesProxy",
+ fields : {
+ paths : [ "custom/" ]
+ }
+ },
+ dataSource : {
+ type : "com.alibaba.druid.pool.DruidDataSource",
+ events : {
+ depose : 'close'
+ },
+ fields : {
+ driverClassName : {
+ java : "$conf.get('db.driverClassName')"
+ },
+ url : {
+ java : "$conf.get('db.url')"
+ },
+ maxWait : {
+ java : "$conf.get('db.maxWait')"
+ },
+ defaultAutoCommit : {
+ java : "$conf.get('db.defaultAutoCommit')"
+ },
+ validationQuery : {
+ java : "$conf.get('db.validationQuery')"
+ },
+ testWhileIdle : {
+ java : "$conf.get('db.testWhileIdle')"
+ },
+ maxActive : {
+ java : "$conf.get('db.maxActive')"
+ },
+ filters : {
+ java : "$conf.get('db.filters')"
+ },
+ connectionProperties : {
+ java : "$conf.get('db.connectionProperties')"
+ },
+ username : {
+ java : "$conf.get('db.username')"
+ },
+ password : {
+ java : "$conf.get('db.password')"
+ },
+ timeBetweenEvictionRunsMillis : {
+ java : "$conf.get('db.timeBetweenEvictionRunsMillis')"
+ },
+ minEvictableIdleTimeMillis : {
+ java : "$conf.get('db.minEvictableIdleTimeMillis')"
+ },
+ poolPreparedStatements : {
+ java : "$conf.get('db.poolPreparedStatements')"
+ },
+ maxPoolPreparedStatementPerConnectionSize : {
+ java : "$conf.get('db.maxPoolPreparedStatementPerConnectionSize')"
+ },
+ initialSize : {
+ java : "$conf.get('db.initialSize')"
+ },
+ minIdle : {
+ java : "$conf.get('db.minIdle')"
+ },
+ testWhileIdle : {
+ java : "$conf.get('db.testWhileIdle')"
+ },
+ testOnBorrow : {
+ java : "$conf.get('db.testOnBorrow')"
+ },
+ testOnReturn : {
+ java : "$conf.get('db.testOnReturn')"
+ },
+ removeAbandoned : {
+ java : "$conf.get('db.removeAbandoned')"
+ },
+ removeAbandonedTimeout : {
+ java : "$conf.get('db.removeAbandonedTimeout')"
+ },
+ logAbandoned : {
+ java : "$conf.get('db.logAbandoned')"
+ },
+ }
+ },
+ dao : {
+ type : "org.nutz.dao.impl.NutDao",
+ args : [ {
+ refer : "dataSource"
+ } ]
+ }
+};
\ No newline at end of file
diff --git a/nutz-plugins-ip2region/pom.xml b/nutz-plugins-ip2region/pom.xml
index 1b91dada70b0716e9b403a1801f0b842652a83fe..e1a3b4a44edab564d529950ff0187e8145172a12 100644
--- a/nutz-plugins-ip2region/pom.xml
+++ b/nutz-plugins-ip2region/pom.xml
@@ -3,7 +3,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-ip2region
稍微改造一下原版的java代码,https://github.com/lionsoul2014/ip2region
diff --git a/nutz-plugins-jqgrid/README.md b/nutz-plugins-jqgrid/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..00e1bd508d9697dc31f6c91fc56aa7fe7712fae9
--- /dev/null
+++ b/nutz-plugins-jqgrid/README.md
@@ -0,0 +1,84 @@
+# nutz-plugins-jqgrid JQGrid dao层使用插件
+
+简介(可用性:生产,维护者:邓华锋(http://dhf.ink))
+==================================
+
+前段jqGrid提交到后端通用处理方法:简单、易用
+示例IocBy配置
+----------------------------------------------
+```Java
+@IocBy(type=ComboIocProvider.class, args={"*js", "ioc/","*anno", "ink.dhf","org.nutz.plugins.jqgrid"})
+```
+
+前段jqGrid配置:
+```javascript
+jQuery(grid_selector).jqGrid({
+ url:"${base}/user/bean/list",//${base}/user/tname/list
+ datatype: "json",
+ ......省略
+ editurl: "${basePath}/user/oper",//nothing is saved
+});
+```
+
+```javascript
+$('#btnSeach').on('click', function(e){
+ //此处可以添加对查询数据的合法验证
+ var userId = $("#btnUser").val();
+ $(grid_selector).jqGrid('setGridParam',{
+ datatype:'json',
+ postData:{'userId':userId},
+ page:1
+ }).trigger("reloadGrid");
+});
+```
+module使用示例:
+```Java
+@At("/user")
+@IocBean
+public class UserModule {
+ @Inject
+ JQGridService jQGridService;
+
+ @At("/bean/list")
+ @Fail(">>:/index")
+ @Ok("json")
+ public JQGridResult beanList(Integer userId, @Param("..") JQGridPage jqGridPage) {
+ Cnd cnd = Cnd.where("1", "=", 1);
+ if(userId!=null&&userId>0) {
+ cnd.and("userId", "=", userId);
+ }
+ Dao dao = Mvcs.getIoc().get(Dao.class);
+ return jQGridService.query(jqGridPage, dao, cnd, "id", TestUser.class);
+ }
+
+
+ @At("/tname/list")
+ @Fail(">>:/index")
+ @Ok("json")
+ public JQGridResult tableNamelist(Integer userId, @Param("..") JQGridPage jqGridPage) {
+ Cnd cnd = Cnd.where("1", "=", 1);
+ if(userId!=null&&userId>0) {
+ cnd.and("userId", "=", userId);
+ }
+ Dao dao = Mvcs.getIoc().get(Dao.class);
+ return jQGridService.query(jqGridPage, "test_user", dao, cnd, "id");
+ }
+
+
+ @At
+ @Ok("json")
+ public Object oper(@Param("..") final Map data, @Param("oper") String oper) {
+ if (StringUtils.equals(oper, JQGridOper.add.name())) {
+ //TODO add
+ return true;
+ }else if (StringUtils.equals(oper, JQGridOper.del.name())) {
+ //TODO delete
+ return true;
+ }else if(StringUtils.equals(oper, JQGridOper.edit.name())) {
+ //TODO update
+ return true;
+ }
+ return false;
+ }
+}
+```
diff --git a/nutz-plugins-jqgrid/pom.xml b/nutz-plugins-jqgrid/pom.xml
new file mode 100644
index 0000000000000000000000000000000000000000..d4d184fc1d796e2c64eab33053bb8fc7482e1f8b
--- /dev/null
+++ b/nutz-plugins-jqgrid/pom.xml
@@ -0,0 +1,93 @@
+
+ 4.0.0
+
+ org.nutz
+ nutzmore
+ 1.r.66-SNAPSHOT
+
+ nutz-plugins-jqgrid
+ Nutz More jqgrid
+
+
+ 邓华锋
+ 邓华锋
+ denghuafeng@gmail.com
+ http://dhf.ink
+
+
+
+ UTF-8
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.5
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
+ com.alibaba
+ druid
+ 1.0.29
+ test
+
+
+ mysql
+ mysql-connector-java
+ 5.1.41
+ test
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.1
+
+ 1.6
+ 1.6
+
+ -parameters
+
+ false
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ once
+ -Dfile.encoding=UTF-8
+
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+
+ -Xdoclint:none
+
+
+
+
+
+
+
+ nutzcn-snapshots
+ NutzCN snapshot repository
+ https://jfrog.nutz.cn/artifactory/snapshots
+
+
+
+ sonatype-release-staging
+ Sonatype Nexus release repository
+ https://oss.sonatype.org/service/local/staging/deploy/maven2
+
+
+
diff --git a/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/dict/JQGridGroupOP.java b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/dict/JQGridGroupOP.java
new file mode 100644
index 0000000000000000000000000000000000000000..5d099ca2b94f3edb225f8da579c756ed35fba4fd
--- /dev/null
+++ b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/dict/JQGridGroupOP.java
@@ -0,0 +1,27 @@
+package org.nutz.plugins.jqgrid.dict;
+
+/**
+ * jqgrid分组操作
+ * @author 邓华锋 http://dhf.ink
+ *
+ */
+//@Select(value=Fields.NAME)
+public enum JQGridGroupOP {
+ or("或者",0),and("并且",1);
+ private String text;
+
+ private int value;
+
+ private JQGridGroupOP(String text, int value) {
+ this.text = text;
+ this.value = value;
+ }
+
+ public String text() {
+ return text;
+ }
+
+ public int value() {
+ return value;
+ }
+}
\ No newline at end of file
diff --git a/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/dict/JQGridOper.java b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/dict/JQGridOper.java
new file mode 100644
index 0000000000000000000000000000000000000000..153039c7bf6f01d877fe3fe8adb2e6a2b88faf65
--- /dev/null
+++ b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/dict/JQGridOper.java
@@ -0,0 +1,26 @@
+package org.nutz.plugins.jqgrid.dict;
+/**
+ * jqgrid按钮
+ * @author 邓华锋 http://dhf.ink
+ */
+public enum JQGridOper {
+ edit("编辑",0),del("删除",1),add("增加",2);
+
+ private String text;
+
+ private int value;
+
+ private JQGridOper(String text, int value) {
+ this.text = text;
+ this.value = value;
+ }
+
+ public String text() {
+ return text;
+ }
+
+ public int value() {
+ return value;
+ }
+
+}
diff --git a/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/dict/JQGridOrder.java b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/dict/JQGridOrder.java
new file mode 100644
index 0000000000000000000000000000000000000000..f0ac4617f5712ba6fec47c3a93403bb5e9eefb90
--- /dev/null
+++ b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/dict/JQGridOrder.java
@@ -0,0 +1,26 @@
+package org.nutz.plugins.jqgrid.dict;
+
+/**
+ * jqgrid排序
+ * @author 邓华锋 http://dhf.ink
+ */
+//@Select(value=Fields.NAME)
+public enum JQGridOrder {
+ asc("升序",0),desc("降序",1) ;
+ private String text;
+
+ private int value;
+
+ private JQGridOrder(String text, int value) {
+ this.text = text;
+ this.value = value;
+ }
+
+ public String text() {
+ return text;
+ }
+
+ public int value() {
+ return value;
+ }
+}
\ No newline at end of file
diff --git a/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/dict/JQGridSelectOPT.java b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/dict/JQGridSelectOPT.java
new file mode 100644
index 0000000000000000000000000000000000000000..c7daa60476a2aa04031c1c861d2d70620b3989d1
--- /dev/null
+++ b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/dict/JQGridSelectOPT.java
@@ -0,0 +1,32 @@
+package org.nutz.plugins.jqgrid.dict;
+
+/**
+ * JQGrid查询操作符
+ *
+ * @author 邓华锋 http://dhf.ink
+ *
+ */
+//@Select
+public enum JQGridSelectOPT {
+ eq("等于","="),ne("不等于","<>"),bw("开始于","LIKE ${value}%"),bn("不开始于","NOT LIKE ${value}%"),ew("结束于","LIKE %${value}"),en("不结束于","NOT LIKE %${value}"),
+ cn("包含","LIKE"),nc("不包含","NOT LIKE"),nu("空值于","IS NULL"),nn("非空值","IS NOT NULL"),in("属于","IN"),ni("不属于","NOT IN"),
+ lt("小于","<"),le("小于等于","<="),gt("大于",">"),ge("大于等于",">=");
+
+ private String text;
+
+ private String value;
+
+ private JQGridSelectOPT(String text, String value) {
+ this.text = text;
+ this.value = value;
+ }
+
+ public String text() {
+ return text;
+ }
+
+ public String value() {
+ return value;
+ }
+
+}
\ No newline at end of file
diff --git a/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/entity/JQGridFilter.java b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/entity/JQGridFilter.java
new file mode 100644
index 0000000000000000000000000000000000000000..3c5733d4e360c6dbfe0cd08675a23e18ee037167
--- /dev/null
+++ b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/entity/JQGridFilter.java
@@ -0,0 +1,35 @@
+package org.nutz.plugins.jqgrid.entity;
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * jqGrid过滤器
+ *
+ * @author 邓华锋
+ * @date 2016年6月27日 下午4:22:41
+ *
+ */
+public class JQGridFilter implements Serializable{
+
+ private static final long serialVersionUID = 3777917034270668946L;
+
+ private String groupOp;
+
+ private List rules;
+
+ public String getGroupOp() {
+ return groupOp;
+ }
+
+ public void setGroupOp(String groupOp) {
+ this.groupOp = groupOp;
+ }
+
+ public List getRules() {
+ return rules;
+ }
+
+ public void setRules(List rules) {
+ this.rules = rules;
+ }
+}
\ No newline at end of file
diff --git a/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/entity/JQGridPage.java b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/entity/JQGridPage.java
new file mode 100644
index 0000000000000000000000000000000000000000..517976e6abf7b264ad954db8546fff6b7981ff87
--- /dev/null
+++ b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/entity/JQGridPage.java
@@ -0,0 +1,126 @@
+package org.nutz.plugins.jqgrid.entity;
+import java.io.Serializable;
+
+
+/**
+ * JQGrid分页
+ *
+ * @author 邓华锋
+ * @date 2016年6月27日 下午3:43:11
+ *
+ */
+public class JQGridPage implements Serializable{
+ private static final long serialVersionUID = -6779387545446523955L;
+
+ private boolean _search;
+
+ private JQGridFilter filters;
+
+ private String nd;
+
+ /**
+ * 当前页码
+ */
+ private int page=1;
+
+ /**
+ * 分页行数
+ */
+ private int rows=10;
+
+ private String searchField;
+
+ private String searchOper;
+
+ private String searchString;
+
+ /**
+ * 排序字段
+ */
+ private String sidx;
+
+ /**
+ * 排序方式:1.asc 2.desc
+ */
+ private String sord;
+
+ public boolean is_search() {
+ return _search;
+ }
+
+ public void set_search(boolean _search) {
+ this._search = _search;
+ }
+
+ public JQGridFilter getFilters() {
+ return filters;
+ }
+
+ public void setFilters(JQGridFilter filters) {
+ this.filters = filters;
+ }
+
+ public String getNd() {
+ return nd;
+ }
+
+ public void setNd(String nd) {
+ this.nd = nd;
+ }
+
+ public int getPage() {
+ return page;
+ }
+
+ public void setPage(int page) {
+ this.page = page;
+ }
+
+ public int getRows() {
+ return rows;
+ }
+
+ public void setRows(int rows) {
+ this.rows = rows;
+ }
+
+ public String getSearchField() {
+ return searchField;
+ }
+
+ public void setSearchField(String searchField) {
+ this.searchField = searchField;
+ }
+
+ public String getSearchOper() {
+ return searchOper;
+ }
+
+ public void setSearchOper(String searchOper) {
+ this.searchOper = searchOper;
+ }
+
+ public String getSearchString() {
+ return searchString;
+ }
+
+ public void setSearchString(String searchString) {
+ this.searchString = searchString;
+ }
+
+ public String getSidx() {
+ return sidx;
+ }
+
+ public void setSidx(String sidx) {
+ this.sidx = sidx;
+ }
+
+ public String getSord() {
+ return sord;
+ }
+
+ public void setSord(String sord) {
+ this.sord = sord;
+ }
+}
\ No newline at end of file
diff --git a/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/entity/JQGridResult.java b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/entity/JQGridResult.java
new file mode 100644
index 0000000000000000000000000000000000000000..8c4e0d19a199f72dc20cbdcd0c24f9ffa54207ac
--- /dev/null
+++ b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/entity/JQGridResult.java
@@ -0,0 +1,74 @@
+package org.nutz.plugins.jqgrid.entity;
+import java.io.Serializable;
+import java.util.List;
+
+import org.nutz.dao.pager.Pager;
+/**
+ * jqGrid返回的结果
+ *
+ * @author 邓华锋
+ * @date 2016年6月27日 下午4:22:19
+ *
+ */
+public class JQGridResult implements Serializable{
+ private static final long serialVersionUID = 5939846263450399192L;
+
+ /**
+ * 页码
+ */
+ private int page;
+
+ /**
+ * 总页数
+ */
+ private int total;
+
+ /**
+ * 总行数
+ */
+ private int records;
+
+ /**
+ * 当前页的数据
+ */
+ private List> rows;
+
+ public JQGridResult(Pager page,List> rows) {
+ this.page=page.getPageNumber();
+ this.total=page.getPageCount();
+ this.records=page.getRecordCount();
+ this.rows = rows;
+ }
+
+ public int getPage() {
+ return page;
+ }
+
+ public void setPage(int page) {
+ this.page = page;
+ }
+
+ public int getTotal() {
+ return total;
+ }
+
+ public void setTotal(int total) {
+ this.total = total;
+ }
+
+ public int getRecords() {
+ return records;
+ }
+
+ public void setRecords(int records) {
+ this.records = records;
+ }
+
+ public List> getRows() {
+ return rows;
+ }
+
+ public void setRows(List> rows) {
+ this.rows = rows;
+ }
+}
\ No newline at end of file
diff --git a/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/entity/JQGridRule.java b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/entity/JQGridRule.java
new file mode 100644
index 0000000000000000000000000000000000000000..a52a6cc9ab3f6dd420e635213250a1973f2d4ead
--- /dev/null
+++ b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/entity/JQGridRule.java
@@ -0,0 +1,44 @@
+package org.nutz.plugins.jqgrid.entity;
+import java.io.Serializable;
+
+
+/**
+ * jqGrid规则
+ *
+ * @author 邓华锋
+ * @date 2016年6月27日 下午4:21:21
+ *
+ */
+public class JQGridRule implements Serializable{
+ private static final long serialVersionUID = -2672331350537972005L;
+
+ private String field;
+
+ private String op;
+
+ private String data;
+
+ public String getField() {
+ return field;
+ }
+
+ public void setField(String field) {
+ this.field = field;
+ }
+
+ public String getOp() {
+ return op;
+ }
+
+ public void setOp(String op) {
+ this.op = op;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+}
diff --git a/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/service/JQGridService.java b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/service/JQGridService.java
new file mode 100644
index 0000000000000000000000000000000000000000..c5b901f04b35459b29189b5a3a41597d77079c59
--- /dev/null
+++ b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/service/JQGridService.java
@@ -0,0 +1,35 @@
+package org.nutz.plugins.jqgrid.service;
+
+import org.nutz.dao.Cnd;
+import org.nutz.dao.Dao;
+import org.nutz.plugins.jqgrid.entity.JQGridPage;
+import org.nutz.plugins.jqgrid.entity.JQGridResult;
+
+/**
+ * JQGrid通用查询
+ * @author 邓华锋 http://dhf.ink
+ *
+ */
+public interface JQGridService {
+ /**
+ * JQGrid通用查询 传class 返回class集合
+ * @param jqGridPage
+ * @param dao
+ * @param cnd
+ * @param defaultOrderField
+ * @param clazz
+ * @return
+ */
+ public JQGridResult query(JQGridPage jqGridPage, Dao dao, Cnd cnd, String defaultOrderField, Class> clazz);
+
+ /**
+ * JQGrid通用查询 传表名 返回Record集合
+ * @param jqGridPage
+ * @param tableName
+ * @param dao
+ * @param cnd
+ * @param defaultOrderField
+ * @return
+ */
+ public JQGridResult query(JQGridPage jqGridPage, String tableName,Dao dao, Cnd cnd, String defaultOrderField);
+}
diff --git a/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/service/impl/JQGridServiceImpl.java b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/service/impl/JQGridServiceImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..76d41c780312446dc368ae54fbfb09ccdb4dd0b7
--- /dev/null
+++ b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/service/impl/JQGridServiceImpl.java
@@ -0,0 +1,150 @@
+package org.nutz.plugins.jqgrid.service.impl;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.nutz.dao.Cnd;
+import org.nutz.dao.Dao;
+import org.nutz.dao.pager.Pager;
+import org.nutz.dao.sql.Criteria;
+import org.nutz.ioc.loader.annotation.IocBean;
+import org.nutz.lang.Strings;
+import org.nutz.plugins.jqgrid.dict.JQGridGroupOP;
+import org.nutz.plugins.jqgrid.dict.JQGridOrder;
+import org.nutz.plugins.jqgrid.dict.JQGridSelectOPT;
+import org.nutz.plugins.jqgrid.entity.JQGridPage;
+import org.nutz.plugins.jqgrid.entity.JQGridResult;
+import org.nutz.plugins.jqgrid.entity.JQGridRule;
+import org.nutz.plugins.jqgrid.service.JQGridService;
+import org.nutz.plugins.jqgrid.util.Args;
+
+/**
+ * 操作jqgrid service类
+ * @author 邓华锋 http://dhf.ink
+ *
+ */
+@IocBean(name = "jQGridService")
+public class JQGridServiceImpl implements JQGridService {
+ private static Map selectOPT = new HashMap();
+
+ static {
+ // 遍历JQGrid查询操作符枚举及对应的操作符,放入到静态变量中
+ for (JQGridSelectOPT sopt : JQGridSelectOPT.values()) {
+ selectOPT.put(sopt.name(), sopt.value());
+ }
+ }
+
+ @Override
+ public JQGridResult query(JQGridPage jqGridPage, String tableName, Dao dao, Cnd cnd, String defaultOrderField) {
+ Args.notBlank(tableName, "tableName");
+ return query(jqGridPage, tableName, dao, cnd, defaultOrderField, null);
+ }
+
+ /**
+ * JQGrid通用查询
+ *
+ * @param jqGridPage
+ * @param dao
+ * @param cnd
+ * @param defaultOrderField
+ * @param clazz
+ * @return
+ */
+ public JQGridResult query(JQGridPage jqGridPage, Dao dao, Cnd cnd, String defaultOrderField, Class> clazz) {
+ Args.notNull(clazz, "clazz");
+ return query(jqGridPage, null,dao, cnd, defaultOrderField, clazz);
+ }
+
+ private JQGridResult query(JQGridPage jqGridPage, String tableName, Dao dao, Cnd cnd, String defaultOrderField,
+ Class> clazz) {
+ Args.notNull(jqGridPage, "jqGridPage");
+ Args.notNull(dao, "dao");
+ Args.notNull(cnd, "cnd");
+ if (jqGridPage.getRows() < 1)
+ jqGridPage.setRows(10);
+
+ Pager pager = dao.createPager(jqGridPage.getPage(), jqGridPage.getRows());
+ // 创建一个 Criteria 接口实例
+ Criteria cri = null;
+ if (cnd != null) {
+ cri = cnd.getCri();
+ } else {
+ cri = Cnd.cri();
+ }
+
+ if (jqGridPage.is_search() && jqGridPage.getFilters() != null) {
+ String groupOp = jqGridPage.getFilters().getGroupOp().toLowerCase();
+ List rules = jqGridPage.getFilters().getRules();
+ if (rules != null && rules.size() > 0) {
+ if (Strings.equals(groupOp, JQGridGroupOP.and.name())) {
+ for (JQGridRule rule : rules) {
+ String opt = selectOPT.get(rule.getOp());
+ String data = rule.getData();
+ String field = rule.getField();
+ opt = opt.toLowerCase();
+ if (opt.startsWith("like")) {
+ String vd = opt.replace("like ", "");
+ String vdata = vd.replace("${value}", data);
+ // data="%"+data+"%";
+ // "%A%"
+ cri.where().andLike(field, vdata);
+ } else if (opt.equals("in")) {
+ cri.where().andIn(field, data);
+ } else if (opt.equals("not in")) {
+ cri.where().andNotIn(field, data);
+ } else {
+ cri.where().and(field, opt, data);
+ }
+ }
+ } else if (Strings.equals(groupOp, JQGridGroupOP.or.name())) {
+ for (JQGridRule rule : rules) {
+ String opt = selectOPT.get(rule.getOp());
+ String data = rule.getData();
+ String field = rule.getField();
+ opt = opt.toLowerCase();
+ if (opt.startsWith("like")) {
+ String vd = opt.replace("like ", "");
+ String vdata = vd.replace("${value}", data);
+ // data="%"+data+"%";
+ // "%A%"
+ cri.where().orLike(field, vdata);
+ } else if (opt.equals("in")) {
+ cri.where().orIn(field, data);
+ } else if (opt.equals("not in")) {
+ cri.where().orNotIn(field, data);
+ } else {
+ cri.where().or(field, opt, data);
+ }
+ }
+ }
+ }
+ }
+
+ if (!Strings.isEmpty(jqGridPage.getSidx()) && !Strings.isEmpty(jqGridPage.getSord())) {
+ if (Strings.equals(jqGridPage.getSord(), JQGridOrder.asc.name())) {
+ cri.getOrderBy().asc(jqGridPage.getSidx());
+ } else if (Strings.equals(jqGridPage.getSord(), JQGridOrder.desc.name())) {
+ cri.getOrderBy().desc(jqGridPage.getSidx());
+ }
+ } else {
+ cri.getOrderBy().desc(defaultOrderField);
+ }
+ List> list = null;
+ if (Strings.isBlank(tableName)) {
+ list = dao.query(clazz, cri, pager);
+ } else {
+ list = dao.query(tableName, cri, pager);
+ }
+
+ if (pager != null) {
+ if (Strings.isBlank(tableName)) {
+ pager.setRecordCount(dao.count(clazz, cnd));
+ } else {
+ pager.setRecordCount(dao.count(tableName, cnd));
+ }
+
+ }
+ return new JQGridResult(pager, list);
+ }
+}
diff --git a/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/util/Args.java b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/util/Args.java
new file mode 100644
index 0000000000000000000000000000000000000000..2af4dfc0cd60d1b659edb29609fd67f15b2f4530
--- /dev/null
+++ b/nutz-plugins-jqgrid/src/main/java/org/nutz/plugins/jqgrid/util/Args.java
@@ -0,0 +1,109 @@
+package org.nutz.plugins.jqgrid.util;
+import java.util.Collection;
+
+import org.apache.commons.lang3.StringUtils;
+import org.nutz.lang.Strings;
+
+public class Args {
+
+ public static void check(final boolean expression, final String message) {
+ if (!expression) {
+ throw new IllegalArgumentException(message);
+ }
+ }
+
+ public static void check(final boolean expression, final String message, final Object... args) {
+ if (!expression) {
+ throw new IllegalArgumentException(String.format(message, args));
+ }
+ }
+
+ public static void check(final boolean expression, final String message, final Object arg) {
+ if (!expression) {
+ throw new IllegalArgumentException(String.format(message, arg));
+ }
+ }
+
+ public static T notNull(final T argument, final String name) {
+ if (argument == null) {
+ throw new IllegalArgumentException(name + " may not be null");
+ }
+ return argument;
+ }
+
+ public static T notEmpty(final T argument, final String name) {
+ if (argument == null) {
+ throw new IllegalArgumentException(name + " may not be null");
+ }
+ if (Strings.isEmpty(argument)) {
+ throw new IllegalArgumentException(name + " may not be empty");
+ }
+ return argument;
+ }
+
+ public static T notBlank(final T argument, final String name) {
+ if (argument == null) {
+ throw new IllegalArgumentException(name + " may not be null");
+ }
+ if (Strings.isBlank(argument)) {
+ throw new IllegalArgumentException(name + " may not be blank");
+ }
+ return argument;
+ }
+
+ public static T containsNoBlanks(final T argument, final String name) {
+ if (argument == null) {
+ throw new IllegalArgumentException(name + " may not be null");
+ }
+ //StringUtils.isAnyBlank(arg0)
+ //TextUtils.containsBlanks(argument)
+ if (StringUtils.isAnyBlank(argument)) {
+ throw new IllegalArgumentException(name + " may not contain blanks");
+ }
+ return argument;
+ }
+
+ public static > T notEmpty(final T argument, final String name) {
+ if (argument == null) {
+ throw new IllegalArgumentException(name + " may not be null");
+ }
+ if (argument.isEmpty()) {
+ throw new IllegalArgumentException(name + " may not be empty");
+ }
+ return argument;
+ }
+
+ public static int positive(final int n, final String name) {
+ if (n <= 0) {
+ throw new IllegalArgumentException(name + " may not be negative or zero");
+ }
+ return n;
+ }
+
+ public static long positive(final long n, final String name) {
+ if (n <= 0) {
+ throw new IllegalArgumentException(name + " may not be negative or zero");
+ }
+ return n;
+ }
+
+ public static int notNegative(final int n, final String name) {
+ if (n < 0) {
+ throw new IllegalArgumentException(name + " may not be negative");
+ }
+ return n;
+ }
+
+ public static long notNegative(final long n, final String name) {
+ if (n < 0) {
+ throw new IllegalArgumentException(name + " may not be negative");
+ }
+ return n;
+ }
+
+ /*Args.notNull(header, "Header");
+ Args.notNull(origin, "Cookie origin");
+ Args.notEmpty(cookies, "List of cookies");
+ Args.notNull(cookie, "Cookie");*/
+
+}
\ No newline at end of file
diff --git a/nutz-plugins-jsonrpc/pom.xml b/nutz-plugins-jsonrpc/pom.xml
index 85f2815002b5251d3bdcc54608adeea2bb16819c..785f5b3c9d10f4277c66f167bc6b0811adf19949 100644
--- a/nutz-plugins-jsonrpc/pom.xml
+++ b/nutz-plugins-jsonrpc/pom.xml
@@ -4,7 +4,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-jsonrpc
diff --git a/nutz-plugins-mock/pom.xml b/nutz-plugins-mock/pom.xml
index 59cf8f3feabc95970af529dbbba26b53e0bc32e4..4f7257687df0fe70be315c84db907a493158b88b 100644
--- a/nutz-plugins-mock/pom.xml
+++ b/nutz-plugins-mock/pom.xml
@@ -4,7 +4,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-mock
diff --git a/nutz-plugins-mock/src/main/java/org/nutz/mock/AbstractMvcTest.java b/nutz-plugins-mock/src/main/java/org/nutz/mock/AbstractMvcTest.java
index ac934a13773edc88ba51f1725cc59179e7a066fd..ddf36838443ad4ccbaa54725656313816cfb96b1 100644
--- a/nutz-plugins-mock/src/main/java/org/nutz/mock/AbstractMvcTest.java
+++ b/nutz-plugins-mock/src/main/java/org/nutz/mock/AbstractMvcTest.java
@@ -40,10 +40,10 @@ public abstract class AbstractMvcTest extends NutIocTestBase {
servlet = new NutServlet();
servlet.init(servletConfig);
session = Mock.servlet.session(servletContext);
- newreq();
nc = Mvcs.getNutConfig();
ioc = nc.getIoc();
injectSelfFields();
+ newreq();
_before();
}
diff --git a/nutz-plugins-mongodb/pom.xml b/nutz-plugins-mongodb/pom.xml
index 628022f68d294e7c41ccbded922792425e9a54fa..da82336242d774b60775983230173566e5b6b5ea 100644
--- a/nutz-plugins-mongodb/pom.xml
+++ b/nutz-plugins-mongodb/pom.xml
@@ -125,6 +125,6 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
diff --git a/nutz-plugins-multiview/README.md b/nutz-plugins-multiview/README.md
index d98976f0d6b334547eb77ce745ef76381a882a91..677e1f9ba02807b461bad9f1da0b03ec521f41f4 100644
--- a/nutz-plugins-multiview/README.md
+++ b/nutz-plugins-multiview/README.md
@@ -1,37 +1,35 @@
# nutz-plugins-multiview 多视图插件
-简介(可用性:生产,维护者:邓华锋(http://dhf.ink))
+简介(可用性:生产,维护者:[邓华锋](http://dhf.ink))
==================================
集合N种模板引擎,可配置性强
###### 适应nutz 1.r.55以上,以下版本暂时未测试
-#1.65版本更新日志:
-###### 1.增加默认视图设置
-###### 2.增加配置视图扩展属性
-###### 3.增加全局属性文件的可配置功能
-#1.65之前版本更新日志:
-###### 1.把所有属性配置文件里的变量及值加载到全局里,例如,在配置文件中配置了CDN地址,想在页面中能调用,默认全局变量是cfg变量,通过cfg调用相应的键值。
-###### 2.支持直接调用视图 AbstractTemplateViewResolver atvr=new org.nutz.plugins.view.JspView("abc.bcd");
-###### 3.代码重构,去除了AbstractUrlBasedView.java和ViewResolver
-针对
-https://github.com/nutzam/nutz/issues/603#issuecomment-35709620
-上提出的问题,开发了此插件、
+针对 [nutz 没有可以配置视图前缀功能,即配置模板路径](https://github.com/nutzam/nutz/issues/603#issuecomment-35709620) 此问题,开发了此插件。
目的是用于开发博客社交类等程序,这些可能会经常要更换模板,路径写死在代码不合适。
-使用步骤:
-
- 1.引用nutz-plugins-multiview.jar插件及相关视图的引用包,在pom.xml里有注释引用。
-
- 2.配置MainModule的视图为ResourceBundleViewResolver
+开发此插件有啥优点了,所有配置都可以在配置文件中实现,而不用硬编码:
+-------------------------
+* 配置视图的路径
+* 配置视图扩展名
+* 配置默认视图
+* 配置默认内容类型
+* 配置字符编码
+* 其他扩展属性配置
+* 配置全局的属性文件
+* 可单独配置视图的属性文件
+* 支持session和application级别切换模板路径、后缀及引擎功能
+使用步骤:
+-------------------------
+* 引用nutz-plugins-multiview.jar插件及相关视图的引用包,在pom.xml里有注释引用。
+* 配置MainModule的视图为ResourceBundleViewResolver
```Java
@Views({ResourceBundleViewResolver.class})
```
-
-3.配置json文件,创建view.js文件,内容如下:
-
+* 配置json文件,创建view.js文件,内容如下:
```javascript
var ioc = {
conf : {//默认约定的视图配置文件conf
@@ -105,7 +103,69 @@ https://github.com/nutzam/nutz/issues/603#issuecomment-35709620
```
当然要创建对应配置的目录,上面beetl的configPath是指这个视图的配置文件目录,相对于项目根目录来说的,可配置或不配置,分情况而定。
-4.在module的方法里返回相应的视图,当然要创建相应的视图文件,如下:
+* 在module中使用情况如下
+
+默认视图使用示例
+-------------------------
+```Java
+@At("/user")
+@IocBean
+public class UserModule {
+ @At
+ @Ok("user.index")
+ public void index() {
+
+ }
+
+ @At
+ @Ok("user.info")
+ public void info() {
+
+ }
+}
+```
+默认视图,将会走默认的视图,此例子中走beetl视图,因为上面view.js里配置了defaultView的值为 btl 即此视图的前缀标识。
+默认视图的好处是@Ok里不用再加“视图前缀:”来标识,直接通过配置文件就能改变视图模板引擎。
+
+session和application切换视图示例
+-------------------------
+```Java
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
+
+import org.nutz.ioc.loader.annotation.IocBean;
+import org.nutz.mvc.Mvcs;
+import org.nutz.mvc.annotation.At;
+import org.nutz.mvc.annotation.Ok;
+import org.nutz.plugins.view.MultiView;
+
+@IocBean
+public class IndexModule {
+ @At("/session/change")
+ @Ok("index")
+ public void sessioinChange() {
+ HttpSession session = Mvcs.getHttpSession();
+ session.setAttribute(MultiView.DEFAULT_VIEW, "ftl");
+ session.setAttribute(MultiView.VIEW_PREFIX, "/templates/freemarker");
+ session.setAttribute(MultiView.DEFAULT_SUFFIX, ".html");
+ }
+
+ /**
+ *
+ */
+ @At("/application/change")
+ @Ok("index")
+ public void applicationChange() {
+ ServletContext application = Mvcs.getServletContext();
+ application.setAttribute(MultiView.DEFAULT_VIEW, "jsp");
+ application.setAttribute(MultiView.VIEW_PREFIX, "/templates/jsp");
+ application.setAttribute(MultiView.DEFAULT_SUFFIX, ".jsp");
+ }
+}
+```
+
+其他视图使用
+-------------------------
```Java
@At("/beetl")
@@ -163,29 +223,20 @@ public class JspModule {
访问相应的链接,就会找到相应的视图,
-默认的视图如果已经设置了的话,将会是配置@Ok情况:
-
-```Java
-@At("/user")
-@IocBean
-public class UserModule {
- @At
- @Ok("user.index")
- public void index() {
+插件的核心类
+-------------------------
+* ResourceBundleViewResolver 实现的MultiView接口 MultiView继承ViewMaker2,用于从 IOC 容器配置文件中查找视图。
+* AbstractTemplateViewResolver 抽象出通用的视图请求操作,填充全局变量,资源路径计算
+* MultiViewResover 主要用于注入多视图,设置默认视图,配置文件
+* MultiView MultiView继承ViewMaker2接口,主要在此接口里定义常量
- }
-
- @At
- @Ok("user.info")
- public void info() {
+MultiViewResover灵活性
+-------------------------
+view.js配置文件中,multiViewResover不再是约定的名称,只要定义 org.nutz.plugins.view.MultiViewResover类型,插件都能加载,可灵活定义多个MultiViewResover。
- }
-}
-```
-默认视图,将会走默认的视图,此例子中走beetl视图,因为上面view.js里配置了defaultView的值为 btl 即此视图的前缀标识。
-默认视图的好处是@Ok里不用再加“视图前缀:”来标识,直接通过配置文件就能改变视图模板引擎。
-注意的地方:
+注意
+-------------------------
1.如果beetl.properties里设置了RESOURCE.root=WEB-INF ,则view.js配置的beetl视图的路径则在WEB-INF下面。例如
@@ -225,33 +276,9 @@ $loader.reloadable =false
既这时候的root路径不起作用。
-
-开发此插件有啥优点了,所有配置都可以在配置文件中实现,而不用硬编码:
-
-1.配置视图的路径
-
-2.配置视图扩展名
-
-3.配置默认视图
-
-4.配置默认内容类型
-
-5.配置字符编码
-
-6.其他扩展属性配置
-
-7.配置全局的属性文件
-
-8.可单独配置视图的属性文件
-
-
插件中包含了对beetl、freemarker、JetTemplate和jsp的视图实现,其实把这些代码抽离出来,按需使用可让插件体积更小。
-插件的核心类,包括ResourceBundleViewResolver(接口 ViewMaker2的实现,用于从 IOC 容器配置文件中查找视图。)、
-
-AbstractTemplateViewResolver、MultiViewResover和ViewResolver
-view.js配置文件中,multiViewResover是约定的名称。
如果想添加别的视图,只需继承于AbstractTemplateViewResolver,实现init和render方法即可。
例如以下是在此插件下beetl模板视图的实现:
@@ -313,27 +340,20 @@ public class BeetlView extends AbstractTemplateViewResolver {
```
注意上面的getConfigPath()方法的代码,是为了实现beetl放在公共的lib目录获取不到beetl配置文件的问题而补救的一个解决方案,configPath是父类AbstractTemplateViewResolver 的属性,可在ioc配置文件中配置。
init方法只执行一次,一般用于加载视图的配置相关的代码,且某些对象只需实例化一次,后面就不用实例化。
- render方法的sharedVars是全局的变量,有这些:
-
-path 项目根路径,
-
-完整的项目连接路径basePath,
-
-请求连接的后缀servletExtension,
-
-模板所在目录tplDir,
-
-资源根路径resPath,
-
-模板对应的资源路径tplResPath,
-
-当前系统java边聊props,
-
-国际语言mvcs,
-
-所有配置文件信息cfg,
-
-还有个viewName变量,用于显示使用的模板视图的名称。
+ render方法的sharedVars是全局的变量。
+
+内置变量
+-------------------------
+* path 项目根路径
+* 完整的项目连接路径basePath
+* 请求连接的后缀servletExtension
+* 模板所在目录tplDir
+* 资源根路径resPath
+* 模板对应的资源路径tplResPath
+* 当前系统环境props
+* 国际语言msgs
+* 所有配置文件信息cfg
+* 还有个viewName变量,用于显示使用的模板视图的名称。
这几个变量对于做博客论坛等经常更换模板的程序很有用。
@@ -372,6 +392,8 @@ vr.render(req, resp, evalPath, sv);
}
```
+注意:以上方式已经废弃,不起作用,请使用以下新方式
+
新:
```javascript
multiViewResover : {
@@ -418,9 +440,22 @@ resource.dir 资源根路径 对应页面变量resPath,此路径可以设置为
# 功能改进计划:
-
###### 1.支持全局变量的添加,例如,把一些字典的类加载到全局里,供页面调用。
-
###### 2.支持Ajax视图,此需要特殊处理。例如,前段Ajax请求,需要处理获取的数据、本次请求状态、提示信息等。
-
###### 3.增加对pdf、velocity、thymeleaf、captcha视图支持,增强Freemarker视图可配置性。
+
+# 更新日志:
+# 1.66版本:
+###### 1.增加session和application级别切换模板路径、后缀及引擎功能
+###### 2.增加MultiViewResover获取方式的灵活性
+###### 3.去除约定的获取MultiViewResover和conf的方式
+
+# 1.65版本:
+###### 1.增加默认视图设置
+###### 2.增加配置视图扩展属性
+###### 3.增加全局属性文件的可配置功能
+
+# 1.65之前版本:
+###### 1.把所有属性配置文件里的变量及值加载到全局里,例如,在配置文件中配置了CDN地址,想在页面中能调用,默认全局变量是cfg变量,通过cfg调用相应的键值。
+###### 2.支持直接调用视图 AbstractTemplateViewResolver atvr=new org.nutz.plugins.view.JspView("abc.bcd");
+###### 3.代码重构,去除了AbstractUrlBasedView.java和ViewResolver
diff --git a/nutz-plugins-multiview/pom.xml b/nutz-plugins-multiview/pom.xml
index 38f0180cf1b13704e6b20cbe2ba2db339e0461c9..fa7aafbca6eadd547dbd52803ca03e407916b0bd 100644
--- a/nutz-plugins-multiview/pom.xml
+++ b/nutz-plugins-multiview/pom.xml
@@ -3,7 +3,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-multiview
Nutz More multiView
diff --git a/nutz-plugins-multiview/src/main/java/org/nutz/plugins/view/AbstractTemplateViewResolver.java b/nutz-plugins-multiview/src/main/java/org/nutz/plugins/view/AbstractTemplateViewResolver.java
index eca720dac631fbf64313b0e66292a46b11561e0f..5bbc3acf0f07213435ba0ed42adaa98c5625eddf 100644
--- a/nutz-plugins-multiview/src/main/java/org/nutz/plugins/view/AbstractTemplateViewResolver.java
+++ b/nutz-plugins-multiview/src/main/java/org/nutz/plugins/view/AbstractTemplateViewResolver.java
@@ -6,6 +6,7 @@ import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.lang.Files;
@@ -24,30 +25,6 @@ import org.nutz.mvc.view.AbstractPathView;
*/
public abstract class AbstractTemplateViewResolver extends AbstractPathView {
protected static final Log log = Logs.get();
- private static final String DEFAULT_ENCODING = "UTF-8";
- private static final String DEFAULT_CONTENT_TYPE = "text/html";
- private static final String DEFAULT_PREFIX = "/WEB-INF/template/";
- private static final String DEFAULT_SUFFIX = ".html";
- private static final String OBJ = "obj";
- private static final String REQUEST = "request";
- private static final String RESPONSE = "response";
- private static final String SESSION = "session";
- private static final String APPLICATION = "application";
- private static final String VIEW_NAME = "viewName";
- private static final String PATH = "path";
- private static final String BASE_PATH = "basePath";
- private static final String SERVLET_EXTENSION = "servletExtension";
- private static final String SERVLET_EXTENSION_KEY = "servlet.extension";
- private static final String TPL_DIR = "tplDir";
- private static final String RESOURCE_DIR = "resource.dir";
- private static final String RES_PATH = "resPath";
- private static final String TPL_RES_PATH = "tplResPath";
- private static final String WEB_INF = "WEB-INF/";
- private static final String PROPS = "props";
- private static final String MVCS = "mvcs";
- private static final String CFG = "cfg";
- private static final String EVAL_PATH = "evalPath";
- private static final String DEST = "dest";
private PropertiesProxy config;
private String prefix;
private String suffix;
@@ -74,39 +51,61 @@ public abstract class AbstractTemplateViewResolver extends AbstractPathView {
try {
if (obj != null && obj instanceof Map) {
sourceMap = org.nutz.castor.Castors.me().castTo(obj, Map.class);
- if (!sourceMap.containsKey(EVAL_PATH) || !sourceMap.containsKey(DEST)) {// 验证必要的key值
+ if (!sourceMap.containsKey(MultiView.EVAL_PATH) || !sourceMap.containsKey(MultiView.DEST)) {// 验证必要的key值
sourceMap = null;
}
}
- } catch (Exception e1) {
- // e1.printStackTrace();
+ } catch (Exception e) {
+ throw e;
}
+
Map sv = new HashMap();
Object objOld = sourceMap == null ? obj : sourceMap.get("obj");
- sv.put(OBJ, objOld);
- sv.put(REQUEST, req);
- sv.put(RESPONSE, resp);
- sv.put(SESSION, Mvcs.getHttpSession());
- sv.put(APPLICATION, Mvcs.getServletContext());
- sv.put(VIEW_NAME, this.getClass().getSimpleName());
- sv.put(PROPS, System.getProperties());// .get("java.version")
- Map msgs = Mvcs.getMessages(req);
- sv.put(MVCS, msgs);
- sv.put(CFG, config);
+ sv.put(MultiView.OBJ, objOld);
+ sv.put(MultiView.REQUEST, req);
+ sv.put(MultiView.RESPONSE, resp);
+ HttpSession session = Mvcs.getHttpSession();
+ sv.put(MultiView.SESSION, session);
+ ServletContext application = Mvcs.getServletContext();
+ sv.put(MultiView.APPLICATION, application);
+ sv.put(MultiView.VIEW_NAME, this.getClass().getSimpleName());
+ sv.put(MultiView.PROPS, System.getProperties());// .get("java.version")
+ sv.put(MultiView.MSGS, Mvcs.getMessages(req));// Map
+ sv.put(MultiView.CFG, config);
+
if (resp != null && Strings.isBlank(resp.getContentType()) && !Strings.isBlank(this.getContentType())) {// resp的contentType优先级高
resp.setContentType(this.getContentType() + "; charset=" + this.getCharacterEncoding());// 配置文件设置的contentType
resp.setCharacterEncoding(this.getCharacterEncoding());
}
-
String evalPath = null;
- if (sourceMap != null && sourceMap.get(DEST) != null && Strings.isBlank(evalPath)) {
- sv.put(DEST, sourceMap.get(EVAL_PATH).toString());
- evalPath = sourceMap.get(EVAL_PATH).toString();
+ if (sourceMap != null && sourceMap.get(MultiView.DEST) != null && Strings.isBlank(evalPath)) {
+ sv.put(MultiView.DEST, sourceMap.get(MultiView.EVAL_PATH).toString());
+ evalPath = sourceMap.get(MultiView.EVAL_PATH).toString();
} else {
evalPath = evalPath(req, obj);
}
String tplDir = this.getPrefix();// 模板路径
+ // application级别 动态切换模板路径
+ Object viewPrefix = application.getAttribute(MultiView.VIEW_PREFIX);
+ if (viewPrefix != null) {
+ tplDir = viewPrefix.toString();
+ }
+ // session级别 动态切换模板路径
+ viewPrefix = session.getAttribute(MultiView.VIEW_PREFIX);
+ if (viewPrefix != null) {
+ tplDir = viewPrefix.toString();
+ }
String ext = this.getSuffix();// 模板文件扩展名
+ // application级别 动态切换模板路径
+ Object viewSuffix = application.getAttribute(MultiView.VIEW_SUFFIX);
+ if (viewSuffix != null) {
+ ext = viewSuffix.toString();
+ }
+ // session级别 动态切换模板后缀
+ viewSuffix = session.getAttribute(MultiView.VIEW_SUFFIX);
+ if (viewSuffix != null) {
+ ext = viewSuffix.toString();
+ }
if (Strings.isBlank(tplDir)) {
tplDir = "";
@@ -128,7 +127,7 @@ public abstract class AbstractTemplateViewResolver extends AbstractPathView {
String resDir = "";
if (config != null) {
- resDir = config.get(RESOURCE_DIR);
+ resDir = config.get(MultiView.RESOURCE_DIR);
}
String path = req.getContextPath();
@@ -136,31 +135,31 @@ public abstract class AbstractTemplateViewResolver extends AbstractPathView {
int serverPort = req.getServerPort();
String basePath = req.getScheme() + "://" + req.getServerName() + (serverPort != 80 ? ":" + serverPort : "")
+ path + "/";
- sv.put(BASE_PATH, basePath);
+ sv.put(MultiView.BASE_PATH, basePath);
} catch (Exception e) {// 为了测试,而try的,Mock没有ServerPort Scheme ServerName
if (Strings.equals("Not implement yet!", e.getMessage())) {
}
}
- sv.put(PATH, path);
+ sv.put(MultiView.PATH, path);
String servletExtension = "";
if (config != null) {
- servletExtension = config.get(SERVLET_EXTENSION_KEY);
+ servletExtension = config.get(MultiView.SERVLET_EXTENSION_KEY);
}
- sv.put(SERVLET_EXTENSION, servletExtension);
- sv.put(TPL_DIR, tplDir);
+ sv.put(MultiView.SERVLET_EXTENSION, servletExtension);
+ sv.put(MultiView.TPL_DIR, tplDir);
if (!resDir.startsWith("http")) {// 如果是http开头,说明是CDN静态地址
resDir = path + "/" + resDir;
}
- sv.put(RES_PATH, resDir);// 资源路径
- sv.put(TPL_RES_PATH, resDir + tplDir.replace(WEB_INF, "") + "/");// 模板对应的资源路径
+ sv.put(MultiView.RES_PATH, resDir);// 资源路径
+ sv.put(MultiView.TPL_RES_PATH, resDir + tplDir.replace(MultiView.WEB_INF, "") + "/");// 模板对应的资源路径
this.render(req, resp, evalPath, sv);
}
public String getPrefix() {
if (Strings.isBlank(prefix)) {
- return DEFAULT_PREFIX;
+ return MultiView.DEFAULT_PREFIX;
}
return prefix;
}
@@ -171,7 +170,7 @@ public abstract class AbstractTemplateViewResolver extends AbstractPathView {
public String getSuffix() {
if (Strings.isBlank(suffix)) {
- return DEFAULT_SUFFIX;
+ return MultiView.DEFAULT_SUFFIX;
}
return suffix;
}
@@ -182,7 +181,7 @@ public abstract class AbstractTemplateViewResolver extends AbstractPathView {
public String getContentType() {
if (Strings.isBlank(contentType)) {
- return DEFAULT_CONTENT_TYPE;
+ return MultiView.DEFAULT_CONTENT_TYPE;
}
return contentType;
}
@@ -225,7 +224,7 @@ public abstract class AbstractTemplateViewResolver extends AbstractPathView {
public String getCharacterEncoding() {
if (Strings.isBlank(this.characterEncoding)) {
- return DEFAULT_ENCODING;
+ return MultiView.DEFAULT_ENCODING;
}
return this.characterEncoding;
}
diff --git a/nutz-plugins-multiview/src/main/java/org/nutz/plugins/view/JetTemplateView.java b/nutz-plugins-multiview/src/main/java/org/nutz/plugins/view/JetTemplateView.java
index eed428383d66b3e1eb262531ec374900a76687cf..3832600283b0bc9695a4751449960362a3962794 100644
--- a/nutz-plugins-multiview/src/main/java/org/nutz/plugins/view/JetTemplateView.java
+++ b/nutz-plugins-multiview/src/main/java/org/nutz/plugins/view/JetTemplateView.java
@@ -18,24 +18,23 @@ import org.nutz.lang.Lang;
/**
* JetTemplate视图。
- *
* @author 邓华锋(http://dhf.ink)
*
*/
public class JetTemplateView extends AbstractTemplateViewResolver {
private JetEngine engine;
-
+
public JetTemplateView(String dest) {
super(dest);
}
- public void init(String appRoot, ServletContext sc) {
+ public void init(String appRoot,ServletContext sc) {
engine = JetWebEngine.create(sc);
}
@Override
- public void render(HttpServletRequest req, HttpServletResponse resp, String evalPath,
- Map sharedVars) throws Throwable {
+ public void render(HttpServletRequest req, HttpServletResponse resp,
+ String evalPath, Map sharedVars) throws Throwable {
String charsetEncoding = engine.getConfig().getOutputEncoding().name();
resp.setCharacterEncoding(charsetEncoding);
if (resp.getContentType() == null) {
diff --git a/nutz-plugins-multiview/src/main/java/org/nutz/plugins/view/MultiView.java b/nutz-plugins-multiview/src/main/java/org/nutz/plugins/view/MultiView.java
new file mode 100644
index 0000000000000000000000000000000000000000..5519c012210ff2b0c67e0019b9c6e09974b52370
--- /dev/null
+++ b/nutz-plugins-multiview/src/main/java/org/nutz/plugins/view/MultiView.java
@@ -0,0 +1,40 @@
+package org.nutz.plugins.view;
+
+import org.nutz.mvc.ViewMaker2;
+
+/**
+ * 多视图接口 继承ViewMaker2 常量定义在此
+ *
+ * @author 邓华锋 http://dhf.ink
+ *
+ */
+public interface MultiView extends ViewMaker2 {
+ String VIEW_PREFIX = "viewPrefix";
+ String VIEW_SUFFIX = "viewSuffix";
+ String DEFAULT_ENCODING = "UTF-8";
+ String DEFAULT_CONTENT_TYPE = "text/html";
+ String DEFAULT_PREFIX = "/WEB-INF/template/";
+ String DEFAULT_SUFFIX = ".html";
+ String OBJ = "obj";
+ String REQUEST = "request";
+ String RESPONSE = "response";
+ String SESSION = "session";
+ String APPLICATION = "application";
+ String VIEW_NAME = "viewName";
+ String PATH = "path";
+ String BASE_PATH = "basePath";
+ String SERVLET_EXTENSION = "servletExtension";
+ String SERVLET_EXTENSION_KEY = "servlet.extension";
+ String TPL_DIR = "tplDir";
+ String RESOURCE_DIR = "resource.dir";
+ String RES_PATH = "resPath";
+ String TPL_RES_PATH = "tplResPath";
+ String WEB_INF = "WEB-INF/";
+ String PROPS = "props";
+ String MSGS = "msgs";
+ String CFG = "cfg";
+ String EVAL_PATH = "evalPath";
+ String DEST = "dest";
+ String INNER_VIEW_TYPE = "json|raw|re|void|http|redirect|forward|>>|->";
+ String DEFAULT_VIEW = "defaultView";
+}
diff --git a/nutz-plugins-multiview/src/main/java/org/nutz/plugins/view/MultiViewResover.java b/nutz-plugins-multiview/src/main/java/org/nutz/plugins/view/MultiViewResover.java
index e00d75164701628742ab8aca4239e31cbff9e151..0ebd799885ccbd9fc0f6e302d0c54c96ab28bbef 100644
--- a/nutz-plugins-multiview/src/main/java/org/nutz/plugins/view/MultiViewResover.java
+++ b/nutz-plugins-multiview/src/main/java/org/nutz/plugins/view/MultiViewResover.java
@@ -6,6 +6,7 @@ import org.nutz.ioc.impl.PropertiesProxy;
/**
* 用于注入的多视图
+ *
* @author 邓华锋(http://dhf.ink)
*
*/
@@ -33,5 +34,5 @@ public class MultiViewResover {
public PropertiesProxy getConfig() {
return config;
}
-
+
}
diff --git a/nutz-plugins-multiview/src/main/java/org/nutz/plugins/view/ResourceBundleViewResolver.java b/nutz-plugins-multiview/src/main/java/org/nutz/plugins/view/ResourceBundleViewResolver.java
index 55eba3c762bc46be5c3bfd3837ea07fe07bf3d6f..41a6b78349648a263e161c9f21121ffac011de1f 100644
--- a/nutz-plugins-multiview/src/main/java/org/nutz/plugins/view/ResourceBundleViewResolver.java
+++ b/nutz-plugins-multiview/src/main/java/org/nutz/plugins/view/ResourceBundleViewResolver.java
@@ -4,18 +4,18 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
+import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
import org.nutz.ioc.Ioc;
-import org.nutz.ioc.IocException;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.lang.Strings;
import org.nutz.mvc.ActionInfo;
import org.nutz.mvc.Mvcs;
import org.nutz.mvc.NutConfig;
import org.nutz.mvc.View;
-import org.nutz.mvc.ViewMaker2;
import org.nutz.mvc.view.AbstractPathView;
/**
@@ -24,13 +24,11 @@ import org.nutz.mvc.view.AbstractPathView;
* @author 邓华锋(http://dhf.ink)
*
*/
-public class ResourceBundleViewResolver implements ViewMaker2 {
- private static final String INNER_VIEW_TYPE = "json|raw|re|void|http|redirect|forward|>>|->";
- private static final String CONFIG = "conf";
- private static final String MULTI_VIEW_RESOVER = "multiViewResover";
+public class ResourceBundleViewResolver implements MultiView {
private LinkedHashMap resolvers = new LinkedHashMap();
- private MultiViewResover multiViewResover;
- private PropertiesProxy config;
+ private MultiViewResover[] multiViewResovers;
+ private PropertiesProxy config = new PropertiesProxy();
+ private String defaultView;
private String appRoot;
private boolean inited;
@@ -40,24 +38,33 @@ public class ResourceBundleViewResolver implements ViewMaker2 {
synchronized (resolvers) {
if (!inited) {
if (ioc != null) {
- try {
- config = ioc.get(PropertiesProxy.class, CONFIG);
- } catch (IocException e) {
- throw e;
+ // 查找MultiViewResover类型的定义名称,进行映射配置
+ String[] names = ioc.getNamesByType(MultiViewResover.class);
+ multiViewResovers = new MultiViewResover[names.length];
+ for (int i = 0; i < names.length; i++) {
+ String name = names[i];
+ MultiViewResover multiViewResover = ioc.get(MultiViewResover.class, name);
+ multiViewResovers[i] = multiViewResover;
+ if (multiViewResover != null) {
+ LinkedHashMap rs = multiViewResover
+ .getResolvers();
+ if (rs == null || rs.size() == 0) {
+ continue;
+ }
+ resolvers.putAll(rs);// 叠加配置视图
+ }
+ config.putAll(multiViewResover.getConfig());// 叠加配置文件
+ // 设置默认视图
+ if (Strings.isNotBlank(multiViewResover.getDefaultView())) {
+ defaultView = multiViewResover.getDefaultView();
+ }
}
- multiViewResover = ioc.get(MultiViewResover.class, MULTI_VIEW_RESOVER);
- }
-
- if (multiViewResover != null) {
- resolvers = multiViewResover.getResolvers();
- }
- if (resolvers == null || resolvers.size() == 0) {
- return null;
}
inited = true;
}
}
}
+
String reqPath = value;
boolean containsInnerType = INNER_VIEW_TYPE.indexOf(type) > -1;// 有没有内置的视图参数
boolean containsResolversKey = resolvers.containsKey(type);// 在配置的目标视图里的前缀有没有
@@ -66,8 +73,8 @@ public class ResourceBundleViewResolver implements ViewMaker2 {
if (isNoContains) {
reqPath = type;
// 设置默认视图
- if (Strings.isNotBlank(multiViewResover.getDefaultView())) {
- viewType = multiViewResover.getDefaultView();
+ if (Strings.isNotBlank(defaultView)) {
+ viewType = defaultView;
}
}
final AbstractTemplateViewResolver vr = resolvers.get(viewType);
@@ -76,13 +83,7 @@ public class ResourceBundleViewResolver implements ViewMaker2 {
}
// 设置全局配置文件
if (vr.getConfig() == null) {
- // 优先自定义配置
- if (multiViewResover.getConfig() != null) {
- vr.setConfig(multiViewResover.getConfig());
- } else {// 约定的配置conf
- vr.setConfig(config);
- }
-
+ vr.setConfig(config);
}
if (Strings.isBlank(vr.getPrefix()) || Strings.isBlank(vr.getSuffix())) {
@@ -102,26 +103,17 @@ public class ResourceBundleViewResolver implements ViewMaker2 {
return new AbstractPathView(reqPath) {
@Override
public void render(HttpServletRequest req, HttpServletResponse resp, Object obj) throws Throwable {
- Map sourceMap = new HashMap();
- sourceMap.put("obj", obj);
- sourceMap.put("evalPath", this.evalPath(req, obj));
- sourceMap.put("dest", type);
- vr.render(req, resp, sourceMap);
+ renderView(type, vr, req, resp, obj, this.evalPath(req, obj));
}
};
} else {
return new AbstractPathView(reqPath) {
@Override
public void render(HttpServletRequest req, HttpServletResponse resp, Object obj) throws Throwable {
- Map sourceMap = new HashMap();
- sourceMap.put("obj", obj);
- sourceMap.put("evalPath", this.evalPath(req, obj));
- sourceMap.put("dest", value);
- vr.render(req, resp, sourceMap);
+ renderView(value, vr, req, resp, obj, this.evalPath(req, obj));
}
};
}
-
}
@Override
@@ -129,4 +121,28 @@ public class ResourceBundleViewResolver implements ViewMaker2 {
appRoot = conf.getAppRoot();
return make(conf.getIoc(), type, value);
}
+
+ private void setDefaultView(String defaultView) {
+ this.defaultView = defaultView;
+ }
+
+ private void renderView(final String dest, final AbstractTemplateViewResolver vr, HttpServletRequest req,
+ HttpServletResponse resp, Object obj, String evalPath) throws Throwable {
+ ServletContext application = Mvcs.getServletContext();
+ // application级别 动态切换模板引擎
+ if (application.getAttribute(DEFAULT_VIEW) != null) {
+ setDefaultView(application.getAttribute(DEFAULT_VIEW).toString());
+ }
+ HttpSession session = Mvcs.getHttpSession();
+ // session级别 动态切换模板引擎
+ if (session.getAttribute(DEFAULT_VIEW) != null) {
+ setDefaultView(session.getAttribute(DEFAULT_VIEW).toString());
+ }
+ Map sourceMap = new HashMap();
+ sourceMap.put(OBJ, obj);
+ sourceMap.put(EVAL_PATH, evalPath);
+ sourceMap.put(DEST, dest);
+ vr.render(req, resp, sourceMap);
+ }
+
}
diff --git a/nutz-plugins-ngrok/pom.xml b/nutz-plugins-ngrok/pom.xml
index 88a688731d8644dfadbeded11ade834435643f64..0c26210b0ff4a73293f9bd629adffb97c2c236c3 100644
--- a/nutz-plugins-ngrok/pom.xml
+++ b/nutz-plugins-ngrok/pom.xml
@@ -3,7 +3,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-ngrok
@@ -45,7 +45,7 @@
org.nutz
nutz-integration-jedis
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
io.netty
@@ -55,7 +55,7 @@
org.nutz
nutz-web
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
provided
diff --git a/nutz-plugins-nop/demo/nop-demo/pom.xml b/nutz-plugins-nop/demo/nop-demo/pom.xml
index d6274ec40208737905facf9288827ef185887ed4..618353322fb838413b3060d8354b01ea9a53d58a 100644
--- a/nutz-plugins-nop/demo/nop-demo/pom.xml
+++ b/nutz-plugins-nop/demo/nop-demo/pom.xml
@@ -22,7 +22,7 @@
org.nutz
nutz-plugins-nop
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
log4j
@@ -39,7 +39,7 @@
org.nutz
nutz-plugins-apidoc
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
diff --git a/nutz-plugins-nop/pom.xml b/nutz-plugins-nop/pom.xml
index 2a3ea6fe9ed62ec84ae380404dc8ebd2140892d3..924f600b75364fb411bd1123cae08020caed3add 100644
--- a/nutz-plugins-nop/pom.xml
+++ b/nutz-plugins-nop/pom.xml
@@ -4,7 +4,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-nop
diff --git a/nutz-plugins-oauth2-server/pom.xml b/nutz-plugins-oauth2-server/pom.xml
index 709c8184c4593e7f08e8cdb5b56095507d358cc6..bc4d111fd9501832afddb6d450c9a29d5548eaab 100644
--- a/nutz-plugins-oauth2-server/pom.xml
+++ b/nutz-plugins-oauth2-server/pom.xml
@@ -3,7 +3,7 @@
4.0.0
org.nutz
oauth2-server
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
war
nutz-plugins-oauth2-server
http://maven.apache.org
diff --git a/nutz-plugins-profiler/pom.xml b/nutz-plugins-profiler/pom.xml
index d0b13abf5456ae917684feeedf23c2c39950e335..c55e7133d78ea6d696d4c7f7a889d5c47136e668 100644
--- a/nutz-plugins-profiler/pom.xml
+++ b/nutz-plugins-profiler/pom.xml
@@ -4,7 +4,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-profiler
diff --git a/nutz-plugins-protobuf/pom.xml b/nutz-plugins-protobuf/pom.xml
index e74854af8f451c38c2e93b1de3f323c5f6197ba3..47956867a589adbb95c838b0dc7f7566e7222e95 100644
--- a/nutz-plugins-protobuf/pom.xml
+++ b/nutz-plugins-protobuf/pom.xml
@@ -4,7 +4,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-protobuf
nutz-plugins-protobuf
diff --git a/nutz-plugins-qrcode/pom.xml b/nutz-plugins-qrcode/pom.xml
index 643d34f07798fb7d908dcf8cfafe24d2174c0d8e..90af98b16bac27806a23371d994ce735de950cd3 100644
--- a/nutz-plugins-qrcode/pom.xml
+++ b/nutz-plugins-qrcode/pom.xml
@@ -4,7 +4,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-qrcode
https://nutzam.com
diff --git a/nutz-plugins-secken/pom.xml b/nutz-plugins-secken/pom.xml
index e60ef870323c3377b9d597a91d3100b41bdf9ebc..2e1cb0ffbf93ee7740cb1a3969440fe384a49855 100644
--- a/nutz-plugins-secken/pom.xml
+++ b/nutz-plugins-secken/pom.xml
@@ -4,7 +4,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-secken
diff --git a/nutz-plugins-sfntly/pom.xml b/nutz-plugins-sfntly/pom.xml
index 048e7368d9ca90cd20ebe745bf21aa675395f3df..e085b2f529888a3a6b673da22a26c37189a8aa22 100644
--- a/nutz-plugins-sfntly/pom.xml
+++ b/nutz-plugins-sfntly/pom.xml
@@ -3,7 +3,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-sfntly
diff --git a/nutz-plugins-sigar/pom.xml b/nutz-plugins-sigar/pom.xml
index 83d13d5e7e80c0ffbb5539355a800f9cb1d27178..3e2cc833be2fb6db0bae403f64eb3a248ac18d51 100644
--- a/nutz-plugins-sigar/pom.xml
+++ b/nutz-plugins-sigar/pom.xml
@@ -4,7 +4,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-sigar
Nutz Sigar
diff --git a/nutz-plugins-slog/pom.xml b/nutz-plugins-slog/pom.xml
index 9dbc21b19548cd3818442245f1714aab97a8093d..5d9bd5cc7bb99cfdb21dfc78daa8adc6363ad5d2 100644
--- a/nutz-plugins-slog/pom.xml
+++ b/nutz-plugins-slog/pom.xml
@@ -4,7 +4,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-slog
diff --git a/nutz-plugins-spring-boot-starter/demo/pom.xml b/nutz-plugins-spring-boot-starter/demo/pom.xml
index ca6dab13c45d50269abad7ee0356b178a3116a34..1bfa2f6e1db5c7f6671d2f8d7bff7b799fcb1e68 100644
--- a/nutz-plugins-spring-boot-starter/demo/pom.xml
+++ b/nutz-plugins-spring-boot-starter/demo/pom.xml
@@ -75,7 +75,7 @@
org.nutz
nutz-plugins-spring-boot-starter
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
club.zhcs
diff --git a/nutz-plugins-spring-boot-starter/pom.xml b/nutz-plugins-spring-boot-starter/pom.xml
index 29b1541a563d539d34ec6185c46e7cc6178f3501..25c1c86de0c0b39ff78e71104ec58ffebcf81640 100644
--- a/nutz-plugins-spring-boot-starter/pom.xml
+++ b/nutz-plugins-spring-boot-starter/pom.xml
@@ -4,7 +4,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-spring-boot-starter
diff --git a/nutz-plugins-sqlmanager/pom.xml b/nutz-plugins-sqlmanager/pom.xml
index 322d7ea4af90184c899a4c8a517fcdf19af081f6..57178fb353ac80294bc9c91ffcfd9c9150576719 100644
--- a/nutz-plugins-sqlmanager/pom.xml
+++ b/nutz-plugins-sqlmanager/pom.xml
@@ -4,7 +4,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-sqlmanager
https://nutzam.com
diff --git a/nutz-plugins-sqltpl/pom.xml b/nutz-plugins-sqltpl/pom.xml
index 7fd27cb4c610e4b37193808fd4d5fec88b33eefe..09be2724c041198f5a9db04db8a42df12e51638b 100644
--- a/nutz-plugins-sqltpl/pom.xml
+++ b/nutz-plugins-sqltpl/pom.xml
@@ -4,7 +4,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-sqltpl
diff --git a/nutz-plugins-thrift-netty/demo/thrift-netty-demo/pom.xml b/nutz-plugins-thrift-netty/demo/thrift-netty-demo/pom.xml
index 9710316ccd82c79a6bf2e9ff516fd70e50db81f5..e487cbd1a49f5eb78302706f25bdad5dcd8796a2 100644
--- a/nutz-plugins-thrift-netty/demo/thrift-netty-demo/pom.xml
+++ b/nutz-plugins-thrift-netty/demo/thrift-netty-demo/pom.xml
@@ -97,7 +97,7 @@
org.nutz
nutz-plugins-thrift-netty
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
log4j
diff --git a/nutz-plugins-thrift-netty/pom.xml b/nutz-plugins-thrift-netty/pom.xml
index 7753ba1b07118e868edbd8d431e528453cb1ea23..7a115965a116d8bba50ec06ed43f94b68d96d0d6 100644
--- a/nutz-plugins-thrift-netty/pom.xml
+++ b/nutz-plugins-thrift-netty/pom.xml
@@ -4,7 +4,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-thrift-netty
Nutz Thrift
diff --git a/nutz-plugins-undertow/pom.xml b/nutz-plugins-undertow/pom.xml
index ec9de3ad99f794f519a1ef35680e854bee981b79..62b9850f3c3965fc2f0e2b328a23ed3a826c049b 100644
--- a/nutz-plugins-undertow/pom.xml
+++ b/nutz-plugins-undertow/pom.xml
@@ -4,7 +4,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-undertow
Simple, lightweight embed web server for Nutz
diff --git a/nutz-plugins-validation/pom.xml b/nutz-plugins-validation/pom.xml
index b363823c0c8f590060fca7f3654e9e2b97ecbcea..a4e4cc9b8e36664250fdd8d7a62b87279fd1de00 100644
--- a/nutz-plugins-validation/pom.xml
+++ b/nutz-plugins-validation/pom.xml
@@ -4,7 +4,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-validation
https://nutzam.com
diff --git a/nutz-plugins-views/pom.xml b/nutz-plugins-views/pom.xml
index c41b77fde89b730330276be4e7a4262df28cec9e..d676eefae19c5b07175668907df5f176d00b05d5 100644
--- a/nutz-plugins-views/pom.xml
+++ b/nutz-plugins-views/pom.xml
@@ -3,7 +3,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-views
Nutz More Views
diff --git a/nutz-plugins-webqq/pom.xml b/nutz-plugins-webqq/pom.xml
index 7522400866c896ef3bba6fa738e7684fe000b5d6..777a568df996a1161a632d9a3daca190f1e2928a 100644
--- a/nutz-plugins-webqq/pom.xml
+++ b/nutz-plugins-webqq/pom.xml
@@ -3,7 +3,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-webqq
diff --git a/nutz-plugins-websocket/README.md b/nutz-plugins-websocket/README.md
index e09cf4da88bfdd13f62092e7337f562ef9bd6171..45f3b26a0645e6655bad35d76900772e913a4aad 100644
--- a/nutz-plugins-websocket/README.md
+++ b/nutz-plugins-websocket/README.md
@@ -64,6 +64,8 @@ public class MyWebsocket extends AbstractWsEndpoint {
}
```
+**特别提醒: 已知限制, Endpoint类不能使用@Aop或者aop相关的注解(如@Async/@SLog)**
+
### 页面端js示例
假设是jsp页面, 其中的base是项目的Context Path, home是房间的名称
diff --git a/nutz-plugins-websocket/pom.xml b/nutz-plugins-websocket/pom.xml
index 29e117488df974e344ebe82f9cd1c48fcdadff90..ad56edec655ae0d780e851d48db1be05250d1f24 100644
--- a/nutz-plugins-websocket/pom.xml
+++ b/nutz-plugins-websocket/pom.xml
@@ -3,7 +3,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-websocket
https://nutzam.com
@@ -113,7 +113,7 @@
org.nutz
nutz-integration-jedis
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
provided
diff --git a/nutz-plugins-wkcache/pom.xml b/nutz-plugins-wkcache/pom.xml
index ed22ea68ef66c7ef24809990d58d7432da1d5e73..0f45036cce283f2c3447afd496e41a39d9c6a65c 100644
--- a/nutz-plugins-wkcache/pom.xml
+++ b/nutz-plugins-wkcache/pom.xml
@@ -5,7 +5,7 @@
nutzmore
org.nutz
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
4.0.0
@@ -15,7 +15,7 @@
org.nutz
nutz-integration-jedis
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
redis.clients
diff --git a/nutz-plugins-xmlentitymaker/pom.xml b/nutz-plugins-xmlentitymaker/pom.xml
index 4da67002e6845ebd5c18550c7faac5c1490685c2..34657579acb93a0501ada5dd90de3510d162cc7e 100644
--- a/nutz-plugins-xmlentitymaker/pom.xml
+++ b/nutz-plugins-xmlentitymaker/pom.xml
@@ -4,7 +4,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-xmlentitymaker
https://nutzam.com
diff --git a/nutz-plugins-zcron/pom.xml b/nutz-plugins-zcron/pom.xml
index 3da00d1a5d2f75afd4f698b45d1eb6a2155637e6..23b9ffe935cf294c2ff65af23f0adecdce8177ac 100644
--- a/nutz-plugins-zcron/pom.xml
+++ b/nutz-plugins-zcron/pom.xml
@@ -4,7 +4,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-zcron
diff --git a/nutz-plugins-zdoc/pom.xml b/nutz-plugins-zdoc/pom.xml
index d66c873eb6d9543fb9f841a462404ee0540f205e..eb5ae2f2dc74435da64cad89686edd80b8777d94 100644
--- a/nutz-plugins-zdoc/pom.xml
+++ b/nutz-plugins-zdoc/pom.xml
@@ -4,7 +4,7 @@
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutz-plugins-zdoc
diff --git a/nutz-plugins-zdoc/src/main/java/org/nutz/plugins/zdoc/markdown/MarkdownDocParser.java b/nutz-plugins-zdoc/src/main/java/org/nutz/plugins/zdoc/markdown/MarkdownDocParser.java
index a320dfff8ff2b98ac379943765aa60da7f8c7ecc..1f9767201359e7b65c9d926fd57e0f7bb9851af6 100644
--- a/nutz-plugins-zdoc/src/main/java/org/nutz/plugins/zdoc/markdown/MarkdownDocParser.java
+++ b/nutz-plugins-zdoc/src/main/java/org/nutz/plugins/zdoc/markdown/MarkdownDocParser.java
@@ -32,10 +32,20 @@ public class MarkdownDocParser implements NutDocParser {
// 定义内容输出函数
private void __B_to_html(Tag tag, MdBlock B) {
boolean isFirstLine = true;
+
+ // 处理任务列表
+ if (B.isTask) {
+ Tag jInput = tag.add("input").attr("disabled", "true").attr("type", "checkbox");
+ if (B.isChecked) {
+ jInput.attr("checked", "true");
+ }
+ }
+
+ // 收集一下块内标签
NutMap tagNames = new NutMap();
for (String line : B.content) {
// 忽略空行
- if(Strings.isBlank(line))
+ if (Strings.isBlank(line))
continue;
// 首行
if (isFirstLine) {
@@ -52,6 +62,10 @@ public class MarkdownDocParser implements NutDocParser {
if (tagNames.size() == 1 && tagNames.getBoolean("img")) {
tag.attr("md-img-only", "yes");
}
+ // 标识一下任务列表
+ if (B.isTask) {
+ tag.attrs(".md-task-list-item");
+ }
}
private void __line_to_html(Tag tag, String str, NutMap tagNames) {
@@ -61,7 +75,9 @@ public class MarkdownDocParser implements NutDocParser {
+ "|(~~([^~]+)~~)"
+ "|(`([^`]+)`)"
+ "|(!\\[([^\\]]*)\\]\\(([^\\)]+)\\))"
- + "|(\\[([^\\]]*)\\]\\(([^\\)]*)\\))"
+ + "|(\\[("
+ + "(!\\[([^\\]]*)\\]\\(([^\\)]+)\\))|([^\\]]*)"
+ + ")\\]\\(([^\\)]*)\\))"
+ "|(https?:\\/\\/[^ ]+)";
Pattern REG = Pattern.compile(reg);
Matcher m = REG.matcher(str);
@@ -130,7 +146,10 @@ public class MarkdownDocParser implements NutDocParser {
}
// IMG: 
else if (null != m.group(11)) {
- tag.add("img").attr("title", m.group(12)).attr("src", m.group(13));
+ Tag img = tag.add("img").attr("src", m.group(13));
+ if (!Strings.isBlank(m.group(12))) {
+ img.attr("alt", m.group(12));
+ }
// 记录标签
if (null != tagNames)
tagNames.put("img", true);
@@ -138,28 +157,42 @@ public class MarkdownDocParser implements NutDocParser {
// A: [](xxxx)
else if (null != m.group(14)) {
// 得到超链
- String href = m.group(16);
+ String href = m.group(20);
if (null != href && href.endsWith(".md")) {
href = Files.renameSuffix(href, ".html");
}
- // 得到文字
- String text = Strings.sBlank(m.group(15), Files.getMajorName(href));
- // 锚点
- if (Strings.isBlank(href) && text.matches("^#.+$")) {
- tag.add("a").attr("name", text.substring(1));
+ // 如果内部是一个图片
+ if (!Strings.isBlank(m.group(16))) {
+ String src = m.group(18);
+ Tag img = tag.add("a").attr("href", href).add("img").attr("src", src);
+ if (!Strings.isBlank(m.group(17))) {
+ img.attr("alt", m.group(17));
+ }
+ // 记录标签
+ if (null != tagNames) {
+ tagNames.put("img", true);
+ }
}
- // 链接
+ // 得到文字
else {
- Tag a = tag.add("a").attr("href", href);
- this.__line_to_html(a, text, tagNames);
+ String text = Strings.sBlank(m.group(19), Files.getMajorName(href));
+ // 锚点
+ if (Strings.isBlank(href) && text.matches("^#.+$")) {
+ tag.add("a").attr("name", text.substring(1));
+ }
+ // 链接
+ else {
+ Tag a = tag.add("a").attr("href", href);
+ this.__line_to_html(a, text, tagNames);
+ }
}
// 记录标签
if (null != tagNames)
tagNames.put("a", true);
}
// A: http://xxxx
- else if (null != m.group(17)) {
- tag.add("a").attr("href", m.group(17)).setText(Strings.sBlank(m.group(17)));
+ else if (null != m.group(21)) {
+ tag.add("a").attr("href", m.group(21)).setText(Strings.sBlank(m.group(21)));
// 记录标签
if (null != tagNames)
tagNames.put("a", true);
@@ -188,8 +221,28 @@ public class MarkdownDocParser implements NutDocParser {
this.index--;
}
+ private static final Pattern _P2 = Pattern.compile("^[ \t]*(\\[[xX ]\\])[ ](.+)$");
+
+ // 处理一下第一行,判断支持一下 task list
+ private MdBlock __B_test_task(MdBlock B) {
+ if (null != B.content && B.content.size() > 0) {
+ String line0 = B.content.get(0);
+ Matcher m2 = _P2.matcher(line0);
+ if (m2.find()) {
+ B.isTask = true;
+ B.isChecked = "[ ]".equals(m2.group(1));
+ B.content.set(0, m2.group(2));
+ }
+ }
+ return B;
+ };
+
private void __B_to_list(Tag tag, MdBlock B) {
+ __B_test_task(B);
Tag tList = tag.add(B.type.toLowerCase());
+ if (B.isTask) {
+ tList.attrs(".md-task-list");
+ }
Tag tLi = tList.add("li");
this.__B_to_html(tLi, B);
// 循环查找后续的列表项,或者是嵌套
@@ -198,6 +251,7 @@ public class MarkdownDocParser implements NutDocParser {
// 继续增加
if (B.type == B2.type && B2.level == B.level) {
tLi = tList.add("li");
+ __B_test_task(B2);
this.__B_to_html(tLi, B2);
}
// 嵌套
diff --git a/nutz-plugins-zdoc/src/main/java/org/nutz/plugins/zdoc/markdown/MdBlock.java b/nutz-plugins-zdoc/src/main/java/org/nutz/plugins/zdoc/markdown/MdBlock.java
index ab93ddfaffa85835f677fac16ad8efbf8914a6e3..1023748531b2cec75224e72708e1d827dab534f4 100644
--- a/nutz-plugins-zdoc/src/main/java/org/nutz/plugins/zdoc/markdown/MdBlock.java
+++ b/nutz-plugins-zdoc/src/main/java/org/nutz/plugins/zdoc/markdown/MdBlock.java
@@ -16,6 +16,10 @@ class MdBlock {
List content;
String[] cellAligns;
+
+ boolean isTask;
+
+ boolean isChecked;
MdBlock() {
this.level = 0;
diff --git a/nutz-plugins-zdoc/src/test/java/org/nutz/plugins/zdoc/markdown/MarkdownTest.java b/nutz-plugins-zdoc/src/test/java/org/nutz/plugins/zdoc/markdown/MarkdownTest.java
index 74541ca679887b140f0aeceddaaf89921b51af2e..2940aefcda25a93d7e15c8136fbaec3c84399710 100644
--- a/nutz-plugins-zdoc/src/test/java/org/nutz/plugins/zdoc/markdown/MarkdownTest.java
+++ b/nutz-plugins-zdoc/src/test/java/org/nutz/plugins/zdoc/markdown/MarkdownTest.java
@@ -6,12 +6,55 @@ import org.junit.Test;
import org.nutz.lang.Strings;
public class MarkdownTest {
-
+
+ /**
+ * https://github.com/nutzam/nutzmore/issues/88
+ */
+ @Test
+ public void test_task_list() {
+ assertEquals("",
+ _HTML("- [ ] AA"));
+
+ assertEquals("",
+ _HTML("- [ ] AAAA\n"
+ + "- [ ] BBBB\n"
+ + " - [ ] BB-b0\n"
+ + " - [ ] BB-b1\n"));
+
+ }
+
+ /**
+ * https://github.com/nutzam/nutzmore/issues/87
+ */
+ @Test
+ public void test_img_in_link() {
+ assertEquals("
",
+ _HTML("[](http://nutz.cn)"));
+ assertEquals("
",
+ _HTML("[](http://nutz.cn)"));
+ }
+
@Test
public void test_mix_html() {
assertEquals("A
BX C
", _HTML("A\n\nBX C"));
}
-
+
@Test
public void test_indent_2space() {
assertEquals("", _HTML(" - A\n - B"));
diff --git a/pom.xml b/pom.xml
index 758fc54f47ae864509653593f7a43d61e856ba36..abfe581406b408209dfc5d405e72f62a2e7a003d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
org.nutz
nutzmore
- 1.r.65-SNAPSHOT
+ 1.r.66-SNAPSHOT
nutzmore
Nutz, which is a collections of lightweight frameworks, each of them can be used independently
@@ -122,9 +122,12 @@
nutz-plugins-cache
nutz-plugins-daocache
nutz-plugins-daomapping
+ nutz-plugins-dict
nutz-plugins-event
nutz-plugins-hotplug
+ nutz-plugins-iocloader
nutz-plugins-ip2region
+ nutz-plugins-jqgrid
nutz-plugins-jsonrpc
nutz-plugins-mock
nutz-plugins-multiview