mirror of
https://gitee.com/dromara/MaxKey.git
synced 2026-05-15 04:52:09 +08:00
freemark
This commit is contained in:
@@ -2,11 +2,13 @@ package org.maxkey.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.apache.mybatis.jpa.persistence.JpaBaseDomain;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
|
||||
|
||||
@Table(name = "GROUPS")
|
||||
public class Groups extends JpaBaseDomain implements Serializable{
|
||||
/**
|
||||
*
|
||||
@@ -18,7 +20,12 @@ public class Groups extends JpaBaseDomain implements Serializable{
|
||||
@Length(max=60)
|
||||
private String name;
|
||||
private int isdefault;
|
||||
|
||||
String description;
|
||||
String createdBy;
|
||||
String createdDate;
|
||||
String modifiedBy;
|
||||
String modifiedDate;
|
||||
String status;
|
||||
|
||||
public Groups() {}
|
||||
|
||||
@@ -58,6 +65,54 @@ public class Groups extends JpaBaseDomain implements Serializable{
|
||||
this.isdefault = isdefault;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getCreatedBy() {
|
||||
return createdBy;
|
||||
}
|
||||
|
||||
public void setCreatedBy(String createdBy) {
|
||||
this.createdBy = createdBy;
|
||||
}
|
||||
|
||||
public String getCreatedDate() {
|
||||
return createdDate;
|
||||
}
|
||||
|
||||
public void setCreatedDate(String createdDate) {
|
||||
this.createdDate = createdDate;
|
||||
}
|
||||
|
||||
public String getModifiedBy() {
|
||||
return modifiedBy;
|
||||
}
|
||||
|
||||
public void setModifiedBy(String modifiedBy) {
|
||||
this.modifiedBy = modifiedBy;
|
||||
}
|
||||
|
||||
public String getModifiedDate() {
|
||||
return modifiedDate;
|
||||
}
|
||||
|
||||
public void setModifiedDate(String modifiedDate) {
|
||||
this.modifiedDate = modifiedDate;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
|
||||
@@ -21,6 +21,8 @@ import org.maxkey.util.PathUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
@@ -28,8 +30,11 @@ import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
* @author Crystal.Sea
|
||||
*
|
||||
*/
|
||||
public class InitWebContext extends HttpServlet {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(InitWebContext.class);
|
||||
public class InitApplicationContext extends HttpServlet {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(InitApplicationContext.class);
|
||||
|
||||
ApplicationContext applicationContext;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -62,8 +67,12 @@ public class InitWebContext extends HttpServlet {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public InitWebContext() {
|
||||
|
||||
public InitApplicationContext() {
|
||||
this.applicationContext=WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
|
||||
}
|
||||
|
||||
public InitApplicationContext(ConfigurableApplicationContext applicationContext) {
|
||||
this.applicationContext=applicationContext;
|
||||
}
|
||||
|
||||
public void loadCaches(){
|
||||
@@ -71,8 +80,8 @@ public class InitWebContext extends HttpServlet {
|
||||
_logger.info("Load Caches ");
|
||||
|
||||
try {
|
||||
if(WebApplicationContextUtils.getWebApplicationContext(this.getServletContext()).containsBean("cacheFactory")){
|
||||
CacheFactory cacheFactory=WebApplicationContextUtils.getWebApplicationContext(this.getServletContext()).getBean("cacheFactory", CacheFactory.class);
|
||||
if(applicationContext.containsBean("cacheFactory")){
|
||||
CacheFactory cacheFactory=applicationContext.getBean("cacheFactory", CacheFactory.class);
|
||||
cacheFactory.start();
|
||||
}
|
||||
} catch (BeansException e) {
|
||||
@@ -82,11 +91,11 @@ public class InitWebContext extends HttpServlet {
|
||||
|
||||
}
|
||||
public void listDataBaseVariables(){
|
||||
if(WebApplicationContextUtils.getWebApplicationContext(this.getServletContext()).containsBean("dataSource")){
|
||||
if(applicationContext.containsBean("dataSource")){
|
||||
try {
|
||||
_logger.info("----------------------------------------------------------------------------------------------------");
|
||||
_logger.info("List DatabaseMetaData Variables ");
|
||||
Connection connection = ((javax.sql.DataSource)WebApplicationContextUtils.getWebApplicationContext(this.getServletContext()).getBean("dataSource")).getConnection();
|
||||
Connection connection = ((javax.sql.DataSource)applicationContext.getBean("dataSource")).getConnection();
|
||||
|
||||
java.sql.DatabaseMetaData databaseMetaData = connection.getMetaData();
|
||||
_logger.info("DatabaseProductName : " + databaseMetaData.getDatabaseProductName());
|
||||
@@ -113,10 +122,10 @@ public class InitWebContext extends HttpServlet {
|
||||
|
||||
//propertySourcesPlaceholderConfigurer
|
||||
public void listProperties(){
|
||||
if(WebApplicationContextUtils.getWebApplicationContext(this.getServletContext()).containsBean("propertySourcesPlaceholderConfigurer")){
|
||||
if(applicationContext.containsBean("propertySourcesPlaceholderConfigurer")){
|
||||
_logger.info("----------------------------------------------------------------------------------------------------");
|
||||
_logger.info("List Properties Variables ");
|
||||
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = ((PropertySourcesPlaceholderConfigurer)WebApplicationContextUtils.getWebApplicationContext(this.getServletContext()).getBean("propertySourcesPlaceholderConfigurer"));
|
||||
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = ((PropertySourcesPlaceholderConfigurer)applicationContext.getBean("propertySourcesPlaceholderConfigurer"));
|
||||
Properties properties=(Properties)propertySourcesPlaceholderConfigurer.getAppliedPropertySources().get(PropertySourcesPlaceholderConfigurer.LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME).getSource();
|
||||
Set<Object> keyValue = properties.keySet();
|
||||
SortedSet<String> keyValueSet=new TreeSet<String>();
|
||||
@@ -158,8 +167,7 @@ public class InitWebContext extends HttpServlet {
|
||||
_logger.info("+ MaxKey Version 1.0 GA");
|
||||
_logger.info("");
|
||||
_logger.info("+ Copyright (c) 2018-2019 Maxkey .");
|
||||
_logger.info("+ We're focus on Identity and Access Management ");
|
||||
_logger.info("+ https://github.com/shimingxy/MaxKey");
|
||||
_logger.info("+ https://github.com/shimingxy/MaxKey");
|
||||
_logger.info("----------------------------------------------------------------------------------------------------");
|
||||
}
|
||||
|
||||
|
||||
15
maxkey-core/src/main/java/org/maxkey/web/tag/St.java
Normal file
15
maxkey-core/src/main/java/org/maxkey/web/tag/St.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package org.maxkey.web.tag;
|
||||
|
||||
public class St {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
String cv="com.ddm.core.utils.TestClass@InnerClass1@InnerClass2@p2";
|
||||
|
||||
String[] c = cv.trim().split("@");
|
||||
for(String cs : c) {
|
||||
System.out.println(cs);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package org.maxkey.web.tag;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
import freemarker.core.Environment;
|
||||
import freemarker.template.TemplateDirectiveBody;
|
||||
import freemarker.template.TemplateDirectiveModel;
|
||||
import freemarker.template.TemplateException;
|
||||
import freemarker.template.TemplateModel;
|
||||
/**
|
||||
* 静态变量读取
|
||||
* <@static/>
|
||||
* @author Crystal.Sea
|
||||
*
|
||||
*/
|
||||
|
||||
@FreemarkerTag("static")
|
||||
public class StaticTagDirective implements TemplateDirectiveModel {
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
||||
throws TemplateException, IOException {
|
||||
|
||||
// 获取字符串变量
|
||||
String[] c = params.get("name").toString().trim().split("@");
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
try {
|
||||
if(null == c || c.length < 2) {
|
||||
throw new TemplateException("至少应该包含一个@符。", env);
|
||||
}
|
||||
|
||||
Class<?> clazz = null;
|
||||
for(int i=0;i<c.length;i++) {
|
||||
sb.append(c[i]).append("@");
|
||||
if(i == 0) {
|
||||
clazz = Class.forName(c[i]);
|
||||
} else if(i != c.length - 1) {
|
||||
Class<?>[] clazzs = clazz.getDeclaredClasses();
|
||||
boolean flag = false;
|
||||
for(Class<?> clz : clazzs) {
|
||||
if(clz.getSimpleName().equals(c[i])) {
|
||||
clazz = clz;
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!flag) {
|
||||
throw new TemplateException("内部类 " + sb.substring(0, sb.length() - 1) + " 未找到。", env);
|
||||
}
|
||||
} else {
|
||||
Field sp = clazz.getDeclaredField(c[i]);
|
||||
env.getOut().write(sp.get(clazz).toString());
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new TemplateException("类 " + sb.substring(0, sb.length() - 1) + " 未找到。", e.getCause(), env);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new TemplateException("属性 " + sb.substring(0, sb.length() - 1) + " 未找到。", e.getCause(), env);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new TemplateException("没权限访问 " + sb.substring(0, sb.length() - 1) + " 属性。", e.getCause(), env);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user