提交 dd7d68d1 编写于 作者: C Calvin

#21 将sprignside-core 部分类移动到springside-extension项目

上级 281a21b8
...@@ -14,8 +14,9 @@ import org.hibernate.dialect.Oracle10gDialect; ...@@ -14,8 +14,9 @@ import org.hibernate.dialect.Oracle10gDialect;
public class Hibernates { public class Hibernates {
/** /**
* Initialize the lazy property value, eg. * Initialize the lazy property value.
* *
* eg.
* Hibernates.initLazyProperty(user.getGroups()); * Hibernates.initLazyProperty(user.getGroups());
*/ */
public static void initLazyProperty(Object proxyedPropertyValue) { public static void initLazyProperty(Object proxyedPropertyValue) {
......
...@@ -38,10 +38,10 @@ public class Exceptions { ...@@ -38,10 +38,10 @@ public class Exceptions {
/** /**
* 判断异常是否由某些底层的异常引起. * 判断异常是否由某些底层的异常引起.
*/ */
public static boolean isCausedBy(Exception ex, Class... causeExceptionClasses) { public static boolean isCausedBy(Exception ex, Class<? extends Exception>... causeExceptionClasses) {
Throwable cause = ex.getCause(); Throwable cause = ex.getCause();
while (cause != null) { while (cause != null) {
for (Class causeClass : causeExceptionClasses) { for (Class<? extends Exception> causeClass : causeExceptionClasses) {
if (causeClass.isInstance(cause)) { if (causeClass.isInstance(cause)) {
return true; return true;
} }
......
...@@ -20,10 +20,7 @@ import org.springframework.core.io.Resource; ...@@ -20,10 +20,7 @@ import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
/** /**
* Properties文件载入工具类. 可载入多个properties文件, 相同的属性在最后载入的文件中的值将会覆盖之前的值. * Properties文件载入工具类. 可载入多个properties文件, 相同的属性在最后载入的文件中的值将会覆盖之前的值,但以System的Property优先.
*
* 本类有两种使用方法:
* 1.
* *
* @author calvin * @author calvin
*/ */
...@@ -44,7 +41,7 @@ public class PropertiesLoader { ...@@ -44,7 +41,7 @@ public class PropertiesLoader {
} }
/** /**
* 取出Property,但以System的Property优先. * 取出Property
*/ */
private String getValue(String key) { private String getValue(String key) {
String systemProperty = System.getProperty(key); String systemProperty = System.getProperty(key);
...@@ -55,7 +52,7 @@ public class PropertiesLoader { ...@@ -55,7 +52,7 @@ public class PropertiesLoader {
} }
/** /**
* 取出String类型的Property,但以System的Property优先,如果都為Null则抛出异常. * 取出String类型的Property,如果都為Null则抛出异常.
*/ */
public String getProperty(String key) { public String getProperty(String key) {
String value = getValue(key); String value = getValue(key);
...@@ -66,7 +63,7 @@ public class PropertiesLoader { ...@@ -66,7 +63,7 @@ public class PropertiesLoader {
} }
/** /**
* 取出String类型的Property,但以System的Property优先.如果都為Null則返回Default值. * 取出String类型的Property.如果都為Null則返回Default值.
*/ */
public String getProperty(String key, String defaultValue) { public String getProperty(String key, String defaultValue) {
String value = getValue(key); String value = getValue(key);
...@@ -74,7 +71,7 @@ public class PropertiesLoader { ...@@ -74,7 +71,7 @@ public class PropertiesLoader {
} }
/** /**
* 取出Integer类型的Property,但以System的Property优先.如果都為Null或内容错误则抛出异常. * 取出Integer类型的Property.如果都為Null或内容错误则抛出异常.
*/ */
public Integer getInteger(String key) { public Integer getInteger(String key) {
String value = getValue(key); String value = getValue(key);
...@@ -85,7 +82,7 @@ public class PropertiesLoader { ...@@ -85,7 +82,7 @@ public class PropertiesLoader {
} }
/** /**
* 取出Integer类型的Property,但以System的Property优先.如果都為Null則返回Default值,如果内容错误则抛出异常 * 取出Integer类型的Property.如果都為Null則返回Default值,如果内容错误则抛出异常
*/ */
public Integer getInteger(String key, Integer defaultValue) { public Integer getInteger(String key, Integer defaultValue) {
String value = getValue(key); String value = getValue(key);
...@@ -93,7 +90,7 @@ public class PropertiesLoader { ...@@ -93,7 +90,7 @@ public class PropertiesLoader {
} }
/** /**
* 取出Double类型的Property,但以System的Property优先.如果都為Null或内容错误则抛出异常. * 取出Double类型的Property.如果都為Null或内容错误则抛出异常.
*/ */
public Double getDouble(String key) { public Double getDouble(String key) {
String value = getValue(key); String value = getValue(key);
...@@ -104,7 +101,7 @@ public class PropertiesLoader { ...@@ -104,7 +101,7 @@ public class PropertiesLoader {
} }
/** /**
* 取出Double类型的Property,但以System的Property优先.如果都為Null則返回Default值,如果内容错误则抛出异常 * 取出Double类型的Property.如果都為Null則返回Default值,如果内容错误则抛出异常
*/ */
public Double getDouble(String key, Integer defaultValue) { public Double getDouble(String key, Integer defaultValue) {
String value = getValue(key); String value = getValue(key);
...@@ -112,7 +109,7 @@ public class PropertiesLoader { ...@@ -112,7 +109,7 @@ public class PropertiesLoader {
} }
/** /**
* 取出Boolean类型的Property,但以System的Property优先.如果都為Null抛出异常,如果内容不是true/false则返回false. * 取出Boolean类型的Property.如果都為Null抛出异常,如果内容不是true/false则返回false.
*/ */
public Boolean getBoolean(String key) { public Boolean getBoolean(String key) {
String value = getValue(key); String value = getValue(key);
...@@ -123,7 +120,7 @@ public class PropertiesLoader { ...@@ -123,7 +120,7 @@ public class PropertiesLoader {
} }
/** /**
* 取出Boolean类型的Property,但以System的Property优先.如果都為Null則返回Default值,如果内容不为true/false则返回false. * 取出Boolean类型的Propert.如果都為Null則返回Default值,如果内容不为true/false则返回false.
*/ */
public Boolean getBoolean(String key, boolean defaultValue) { public Boolean getBoolean(String key, boolean defaultValue) {
String value = getValue(key); String value = getValue(key);
......
...@@ -99,5 +99,4 @@ public class Log4jManager { ...@@ -99,5 +99,4 @@ public class Log4jManager {
public void setProjectLoggerName(String projectLoggerName) { public void setProjectLoggerName(String projectLoggerName) {
this.projectLoggerName = projectLoggerName; this.projectLoggerName = projectLoggerName;
} }
} }
\ No newline at end of file
package org.springside.modules.utils; package org.springside.modules.tools;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
...@@ -7,12 +7,16 @@ import java.util.Map; ...@@ -7,12 +7,16 @@ import java.util.Map;
import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springside.modules.utils.Exceptions;
import freemarker.template.Configuration; import freemarker.template.Configuration;
import freemarker.template.Template; import freemarker.template.Template;
public class FreeMarkers { public class FreeMarkers {
/**
* 渲染模板字符串。
*/
public static String rendereString(String templateString, Map<String, ?> model) { public static String rendereString(String templateString, Map<String, ?> model) {
try { try {
StringWriter result = new StringWriter(); StringWriter result = new StringWriter();
...@@ -24,6 +28,9 @@ public class FreeMarkers { ...@@ -24,6 +28,9 @@ public class FreeMarkers {
} }
} }
/**
* 渲染Template文件.
*/
public static String renderTemplate(Template template, Object model) { public static String renderTemplate(Template template, Object model) {
try { try {
StringWriter result = new StringWriter(); StringWriter result = new StringWriter();
...@@ -34,6 +41,9 @@ public class FreeMarkers { ...@@ -34,6 +41,9 @@ public class FreeMarkers {
} }
} }
/**
* 创建默认配置,设定模板目录.
*/
public static Configuration buildConfiguration(String directory) throws IOException { public static Configuration buildConfiguration(String directory) throws IOException {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
Resource path = new DefaultResourceLoader().getResource(directory); Resource path = new DefaultResourceLoader().getResource(directory);
......
package org.springside.modules.utils; package org.springside.modules.tools;
import static org.junit.Assert.*; import static org.junit.Assert.*;
...@@ -6,6 +6,7 @@ import java.io.IOException; ...@@ -6,6 +6,7 @@ import java.io.IOException;
import java.util.Map; import java.util.Map;
import org.junit.Test; import org.junit.Test;
import org.springside.modules.tools.FreeMarkers;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册