mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -265,7 +265,7 @@ public class ServletUtil {
|
||||
public static MultipartFormData getMultipart(ServletRequest request, UploadSetting uploadSetting) throws IORuntimeException {
|
||||
final MultipartFormData formData = new MultipartFormData(uploadSetting);
|
||||
try {
|
||||
formData.parseRequestStream(request.getInputStream(), request.getCharacterEncoding());
|
||||
formData.parseRequestStream(request.getInputStream(), CharsetUtil.charset(request.getCharacterEncoding()));
|
||||
} catch (IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
|
@@ -19,7 +19,6 @@ public class SpringUtil implements ApplicationContextAware {
|
||||
|
||||
private static ApplicationContext applicationContext;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) {
|
||||
SpringUtil.applicationContext = applicationContext;
|
||||
@@ -43,8 +42,8 @@ public class SpringUtil implements ApplicationContextAware {
|
||||
* @param name Bean名称
|
||||
* @return Bean
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getBean(String name) {
|
||||
//noinspection unchecked
|
||||
return (T) applicationContext.getBean(name);
|
||||
}
|
||||
|
||||
|
@@ -1,10 +1,8 @@
|
||||
package cn.hutool.extra.template.engine.beetl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Map;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import org.beetl.core.Configuration;
|
||||
import org.beetl.core.GroupTemplate;
|
||||
import org.beetl.core.ResourceLoader;
|
||||
@@ -16,9 +14,10 @@ import org.beetl.core.resource.Matcher;
|
||||
import org.beetl.core.resource.StringTemplateResourceLoader;
|
||||
import org.beetl.core.resource.WebAppResourceLoader;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Beetl模板引擎工具类<br>
|
||||
@@ -26,7 +25,9 @@ import cn.hutool.core.util.CharsetUtil;
|
||||
* 文档:http://ibeetl.com/guide/beetl.html
|
||||
*
|
||||
* @author Looly
|
||||
* @deprecated 使用TemplateUtil替代
|
||||
*/
|
||||
@Deprecated
|
||||
public final class BeetlUtil {
|
||||
|
||||
/**
|
||||
|
@@ -8,7 +8,6 @@ import cn.hutool.extra.template.TemplateConfig;
|
||||
import cn.hutool.extra.template.TemplateConfig.ResourceMode;
|
||||
import cn.hutool.extra.template.TemplateEngine;
|
||||
import com.jfinal.template.source.FileSourceFactory;
|
||||
import org.beetl.core.GroupTemplate;
|
||||
|
||||
/**
|
||||
* Enjoy库的引擎包装
|
||||
@@ -80,7 +79,7 @@ public class EnjoyEngine implements TemplateEngine {
|
||||
* 创建引擎
|
||||
*
|
||||
* @param config 模板配置
|
||||
* @return {@link GroupTemplate}
|
||||
* @return {@link com.jfinal.template.Engine}
|
||||
*/
|
||||
private static com.jfinal.template.Engine createEngine(TemplateConfig config) {
|
||||
final com.jfinal.template.Engine engine = com.jfinal.template.Engine.create("Hutool-Enjoy-Engine-" + IdUtil.fastSimpleUUID());
|
||||
|
@@ -1,11 +1,10 @@
|
||||
package cn.hutool.extra.template.engine.freemarker;
|
||||
|
||||
import java.io.IOException;
|
||||
import freemarker.cache.TemplateLoader;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
|
||||
import freemarker.cache.TemplateLoader;
|
||||
|
||||
/**
|
||||
* {@link TemplateLoader} 字符串实现形式<br>
|
||||
* 用于直接获取字符串模板
|
||||
@@ -16,7 +15,7 @@ import freemarker.cache.TemplateLoader;
|
||||
public class SimpleStringTemplateLoader implements TemplateLoader {
|
||||
|
||||
@Override
|
||||
public Object findTemplateSource(String name) throws IOException {
|
||||
public Object findTemplateSource(String name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -26,12 +25,12 @@ public class SimpleStringTemplateLoader implements TemplateLoader {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reader getReader(Object templateSource, String encoding) throws IOException {
|
||||
public Reader getReader(Object templateSource, String encoding) {
|
||||
return new StringReader((String) templateSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeTemplateSource(Object templateSource) throws IOException {
|
||||
public void closeTemplateSource(Object templateSource) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
|
@@ -1,15 +1,14 @@
|
||||
package cn.hutool.extra.template.engine.rythm;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.TypeReference;
|
||||
import cn.hutool.extra.template.AbstractTemplate;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.io.Writer;
|
||||
import java.util.Map;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.TypeReference;
|
||||
import cn.hutool.extra.template.AbstractTemplate;
|
||||
import cn.hutool.extra.template.engine.beetl.BeetlTemplate;
|
||||
|
||||
/**
|
||||
* Rythm模板包装
|
||||
*
|
||||
@@ -25,7 +24,7 @@ public class RythmTemplate extends AbstractTemplate implements Serializable {
|
||||
* 包装Rythm模板
|
||||
*
|
||||
* @param template Rythm的模板对象 {@link org.rythmengine.template.ITemplate}
|
||||
* @return {@link BeetlTemplate}
|
||||
* @return {@link RythmTemplate}
|
||||
*/
|
||||
public static RythmTemplate wrap(org.rythmengine.template.ITemplate template) {
|
||||
return (null == template) ? null : new RythmTemplate(template);
|
||||
|
@@ -1,5 +1,16 @@
|
||||
package cn.hutool.extra.template.engine.velocity;
|
||||
|
||||
import cn.hutool.core.exceptions.NotInitedException;
|
||||
import cn.hutool.core.exceptions.UtilException;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
import org.apache.velocity.app.VelocityEngine;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
@@ -9,37 +20,30 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
import org.apache.velocity.app.VelocityEngine;
|
||||
|
||||
import cn.hutool.core.exceptions.NotInitedException;
|
||||
import cn.hutool.core.exceptions.UtilException;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
|
||||
/**
|
||||
* Velocity模板引擎工具类<br>
|
||||
* 使用前必须初始化工具类
|
||||
*
|
||||
*
|
||||
* @author xiaoleilu
|
||||
*
|
||||
* @deprecated 使用TemplateUtil替代
|
||||
*/
|
||||
@Deprecated
|
||||
public class VelocityUtil {
|
||||
|
||||
/** 是否初始化了默认引擎 */
|
||||
/**
|
||||
* 是否初始化了默认引擎
|
||||
*/
|
||||
private static boolean isInited;
|
||||
/** 全局上下文,当设定值时,对于每个模板都有效 */
|
||||
/**
|
||||
* 全局上下文,当设定值时,对于每个模板都有效
|
||||
*/
|
||||
private static Map<String, Object> globalContext = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 设置Velocity全局上下文<br>
|
||||
* 当设定值时,对于每个模板都有效
|
||||
*
|
||||
* @param name 名
|
||||
*
|
||||
* @param name 名
|
||||
* @param value 值
|
||||
*/
|
||||
public void putGlobalContext(String name, Object value) {
|
||||
@@ -48,9 +52,9 @@ public class VelocityUtil {
|
||||
|
||||
/**
|
||||
* 初始化Velocity全局属性
|
||||
*
|
||||
*
|
||||
* @param templateDir 模板所在目录,绝对路径
|
||||
* @param charset 编码
|
||||
* @param charset 编码
|
||||
*/
|
||||
synchronized public static void init(String templateDir, String charset) {
|
||||
Velocity.init(_newInitedProp(templateDir, charset));
|
||||
@@ -61,9 +65,9 @@ public class VelocityUtil {
|
||||
|
||||
/**
|
||||
* 初始化全局属性
|
||||
*
|
||||
* @param templateDir 模板目录
|
||||
* @param charset 字符集编码
|
||||
*
|
||||
* @param templateDir 模板目录
|
||||
* @param charset 字符集编码
|
||||
* @param initedGlobalContext 初始的全局上下文
|
||||
*/
|
||||
public static void init(String templateDir, String charset, Map<String, Object> initedGlobalContext) {
|
||||
@@ -73,9 +77,9 @@ public class VelocityUtil {
|
||||
|
||||
/**
|
||||
* 新建Velocity模板引擎
|
||||
*
|
||||
*
|
||||
* @param templateDir 模板所在目录,绝对路径
|
||||
* @param charset 编码
|
||||
* @param charset 编码
|
||||
* @return VelocityEngine
|
||||
*/
|
||||
public static VelocityEngine newEngine(String templateDir, String charset) {
|
||||
@@ -89,11 +93,11 @@ public class VelocityUtil {
|
||||
|
||||
/**
|
||||
* 获得指定模板填充后的内容
|
||||
*
|
||||
* @param templateDir 模板所在目录,绝对路径
|
||||
*
|
||||
* @param templateDir 模板所在目录,绝对路径
|
||||
* @param templateFileName 模板名称
|
||||
* @param context 上下文(变量值的容器)
|
||||
* @param charset 字符集
|
||||
* @param context 上下文(变量值的容器)
|
||||
* @param charset 字符集
|
||||
* @return 模板和内容匹配后的内容
|
||||
*/
|
||||
public static String getContent(String templateDir, String templateFileName, VelocityContext context, String charset) {
|
||||
@@ -105,10 +109,10 @@ public class VelocityUtil {
|
||||
|
||||
/**
|
||||
* 获得指定模板填充后的内容
|
||||
*
|
||||
* @param ve 模板引擎
|
||||
*
|
||||
* @param ve 模板引擎
|
||||
* @param templateFileName 模板名称
|
||||
* @param context 上下文(变量值的容器)
|
||||
* @param context 上下文(变量值的容器)
|
||||
* @return 模板和内容匹配后的内容
|
||||
*/
|
||||
public static String getContent(VelocityEngine ve, String templateFileName, VelocityContext context) {
|
||||
@@ -119,9 +123,9 @@ public class VelocityUtil {
|
||||
|
||||
/**
|
||||
* 获得指定模板填充后的内容,使用默认引擎
|
||||
*
|
||||
*
|
||||
* @param templateFileName 模板文件
|
||||
* @param context 上下文(变量值的容器)
|
||||
* @param context 上下文(变量值的容器)
|
||||
* @return 模板和内容匹配后的内容
|
||||
*/
|
||||
public static String getContent(String templateFileName, VelocityContext context) {
|
||||
@@ -132,11 +136,11 @@ public class VelocityUtil {
|
||||
|
||||
/**
|
||||
* 生成文件
|
||||
*
|
||||
* @param ve 模板引擎
|
||||
*
|
||||
* @param ve 模板引擎
|
||||
* @param templateFileName 模板文件名
|
||||
* @param context 上下文
|
||||
* @param destPath 目标路径(绝对)
|
||||
* @param context 上下文
|
||||
* @param destPath 目标路径(绝对)
|
||||
*/
|
||||
public static void toFile(VelocityEngine ve, String templateFileName, VelocityContext context, String destPath) {
|
||||
toFile(ve.getTemplate(templateFileName), context, destPath);
|
||||
@@ -144,10 +148,10 @@ public class VelocityUtil {
|
||||
|
||||
/**
|
||||
* 生成文件,使用默认引擎
|
||||
*
|
||||
*
|
||||
* @param templateFileName 模板文件名
|
||||
* @param context 模板上下文
|
||||
* @param destPath 目标路径(绝对)
|
||||
* @param context 模板上下文
|
||||
* @param destPath 目标路径(绝对)
|
||||
*/
|
||||
public static void toFile(String templateFileName, VelocityContext context, String destPath) {
|
||||
assertInit();
|
||||
@@ -157,9 +161,9 @@ public class VelocityUtil {
|
||||
|
||||
/**
|
||||
* 生成文件
|
||||
*
|
||||
*
|
||||
* @param template 模板
|
||||
* @param context 模板上下文
|
||||
* @param context 模板上下文
|
||||
* @param destPath 目标路径(绝对)
|
||||
*/
|
||||
public static void toFile(Template template, VelocityContext context, String destPath) {
|
||||
@@ -177,11 +181,11 @@ public class VelocityUtil {
|
||||
/**
|
||||
* 生成内容写入流<br>
|
||||
* 会自动关闭Writer
|
||||
*
|
||||
* @param ve 引擎
|
||||
*
|
||||
* @param ve 引擎
|
||||
* @param templateFileName 模板文件名
|
||||
* @param context 上下文
|
||||
* @param writer 流
|
||||
* @param context 上下文
|
||||
* @param writer 流
|
||||
*/
|
||||
public static void toWriter(VelocityEngine ve, String templateFileName, VelocityContext context, Writer writer) {
|
||||
final Template template = ve.getTemplate(templateFileName);
|
||||
@@ -191,10 +195,10 @@ public class VelocityUtil {
|
||||
/**
|
||||
* 生成内容写入流<br>
|
||||
* 会自动关闭Writer
|
||||
*
|
||||
*
|
||||
* @param templateFileName 模板文件名
|
||||
* @param context 上下文
|
||||
* @param writer 流
|
||||
* @param context 上下文
|
||||
* @param writer 流
|
||||
*/
|
||||
public static void toWriter(String templateFileName, VelocityContext context, Writer writer) {
|
||||
assertInit();
|
||||
@@ -206,10 +210,10 @@ public class VelocityUtil {
|
||||
/**
|
||||
* 生成内容写到响应内容中<br>
|
||||
* 模板的变量来自于Request的Attribute对象
|
||||
*
|
||||
*
|
||||
* @param templateFileName 模板文件
|
||||
* @param request 请求对象,用于获取模板中的变量值
|
||||
* @param response 响应对象
|
||||
* @param request 请求对象,用于获取模板中的变量值
|
||||
* @param response 响应对象
|
||||
*/
|
||||
public static void toWriter(String templateFileName, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) {
|
||||
final VelocityContext context = new VelocityContext();
|
||||
@@ -229,9 +233,9 @@ public class VelocityUtil {
|
||||
|
||||
/**
|
||||
* 融合模板和内容
|
||||
*
|
||||
*
|
||||
* @param templateContent 模板的内容字符串
|
||||
* @param context 上下文
|
||||
* @param context 上下文
|
||||
* @return 模板和内容匹配后的内容
|
||||
*/
|
||||
public static String merge(String templateContent, VelocityContext context) {
|
||||
@@ -246,10 +250,10 @@ public class VelocityUtil {
|
||||
|
||||
/**
|
||||
* 融合模板和内容并写入到Writer
|
||||
*
|
||||
*
|
||||
* @param template 模板
|
||||
* @param context 内容
|
||||
* @param writer Writer
|
||||
* @param context 内容
|
||||
* @param writer Writer
|
||||
*/
|
||||
public static void merge(Template template, VelocityContext context, Writer writer) {
|
||||
if (template == null) {
|
||||
@@ -270,7 +274,7 @@ public class VelocityUtil {
|
||||
/**
|
||||
* 将Request中的数据转换为模板引擎<br>
|
||||
* 取值包括Session和Request
|
||||
*
|
||||
*
|
||||
* @param context 内容
|
||||
* @param request 请求对象
|
||||
* @return VelocityContext
|
||||
@@ -289,7 +293,7 @@ public class VelocityUtil {
|
||||
|
||||
/**
|
||||
* 将Session中的值放入模板上下文
|
||||
*
|
||||
*
|
||||
* @param context 模板上下文
|
||||
* @param session Session
|
||||
* @return VelocityContext
|
||||
@@ -309,9 +313,10 @@ public class VelocityUtil {
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------- Private method start
|
||||
|
||||
/**
|
||||
* 新建一个初始化后的属性对象
|
||||
*
|
||||
*
|
||||
* @param templateDir 模板所在目录
|
||||
* @return 初始化后的属性对象
|
||||
*/
|
||||
|
@@ -49,7 +49,6 @@ public abstract class AbstractResult implements Result{
|
||||
throw new UnsupportedOperationException("Jcseg result not allow to remove !");
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Override
|
||||
public Iterator<Word> iterator() {
|
||||
return this;
|
||||
|
@@ -63,7 +63,6 @@ public class JcsegResult implements Result{
|
||||
throw new UnsupportedOperationException("Jcseg result not allow to remove !");
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Override
|
||||
public Iterator<Word> iterator() {
|
||||
return this;
|
||||
|
@@ -1,12 +1,6 @@
|
||||
package cn.hutool.extra.tokenizer;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.IterUtil;
|
||||
import cn.hutool.extra.tokenizer.engine.analysis.SmartcnEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.hanlp.HanLPEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.ikanalyzer.IKAnalyzerEngine;
|
||||
@@ -15,6 +9,11 @@ import cn.hutool.extra.tokenizer.engine.jieba.JiebaEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.mmseg.MmsegEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.mynlp.MynlpEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.word.WordEngine;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* 模板引擎单元测试
|
||||
@@ -38,7 +37,7 @@ public class TokenizerUtilTest {
|
||||
public void hanlpTest() {
|
||||
TokenizerEngine engine = new HanLPEngine();
|
||||
Result result = engine.parse(text);
|
||||
String resultStr = CollUtil.join((Iterator<Word>)result, " ");
|
||||
String resultStr = IterUtil.join((Iterator<Word>)result, " ");
|
||||
Assert.assertEquals("这 两 个 方法 的 区别 在于 返回 值", resultStr);
|
||||
}
|
||||
|
||||
@@ -46,7 +45,7 @@ public class TokenizerUtilTest {
|
||||
public void ikAnalyzerTest() {
|
||||
TokenizerEngine engine = new IKAnalyzerEngine();
|
||||
Result result = engine.parse(text);
|
||||
String resultStr = CollUtil.join((Iterator<Word>)result, " ");
|
||||
String resultStr = IterUtil.join((Iterator<Word>)result, " ");
|
||||
Assert.assertEquals("这两个 方法 的 区别 在于 返回值", resultStr);
|
||||
}
|
||||
|
||||
@@ -61,7 +60,7 @@ public class TokenizerUtilTest {
|
||||
public void jiebaTest() {
|
||||
TokenizerEngine engine = new JiebaEngine();
|
||||
Result result = engine.parse(text);
|
||||
String resultStr = CollUtil.join((Iterator<Word>)result, " ");
|
||||
String resultStr = IterUtil.join((Iterator<Word>)result, " ");
|
||||
Assert.assertEquals("这 两个 方法 的 区别 在于 返回值", resultStr);
|
||||
}
|
||||
|
||||
@@ -76,7 +75,7 @@ public class TokenizerUtilTest {
|
||||
public void smartcnTest() {
|
||||
TokenizerEngine engine = new SmartcnEngine();
|
||||
Result result = engine.parse(text);
|
||||
String resultStr = CollUtil.join((Iterator<Word>)result, " ");
|
||||
String resultStr = IterUtil.join((Iterator<Word>)result, " ");
|
||||
Assert.assertEquals("这 两 个 方法 的 区别 在于 返回 值", resultStr);
|
||||
}
|
||||
|
||||
@@ -84,7 +83,7 @@ public class TokenizerUtilTest {
|
||||
public void wordTest() {
|
||||
TokenizerEngine engine = new WordEngine();
|
||||
Result result = engine.parse(text);
|
||||
String resultStr = CollUtil.join((Iterator<Word>)result, " ");
|
||||
String resultStr = IterUtil.join((Iterator<Word>)result, " ");
|
||||
Assert.assertEquals("这两个 方法 的 区别 在于 返回值", resultStr);
|
||||
}
|
||||
|
||||
@@ -94,12 +93,12 @@ public class TokenizerUtilTest {
|
||||
// 此单元测试需要JDK8,默认忽略
|
||||
TokenizerEngine engine = new MynlpEngine();
|
||||
Result result = engine.parse(text);
|
||||
String resultStr = CollUtil.join((Iterator<Word>)result, " ");
|
||||
String resultStr = IterUtil.join((Iterator<Word>)result, " ");
|
||||
Assert.assertEquals("这 两个 方法 的 区别 在于 返回 值", resultStr);
|
||||
}
|
||||
|
||||
private void checkResult(Result result) {
|
||||
String resultStr = CollUtil.join((Iterator<Word>)result, " ");
|
||||
String resultStr = IterUtil.join((Iterator<Word>)result, " ");
|
||||
Assert.assertEquals("这 两个 方法 的 区别 在于 返回 值", resultStr);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user