Browse Source

Merge branch 'master' of https://git.fanruan.com/fanruan/finekit

newer
pull/1/head
Palin 5 years ago
parent
commit
35b4637abf
  1. 2
      .gitignore
  2. 41
      docs/claim.md
  3. 6
      readme.md
  4. 10
      src/main/java/com/fanruan/api/cal/CalculatorKit.java
  5. 11
      src/main/java/com/fanruan/api/cal/FormulaKit.java
  6. 37
      src/main/java/com/fanruan/api/cal/ParameterKit.java
  7. 41
      src/main/java/com/fanruan/api/conf/ConfigurationKit.java
  8. 54
      src/main/java/com/fanruan/api/conf/HolderKit.java
  9. 1
      src/main/java/com/fanruan/api/data/TableDataKit.java
  10. 51
      src/main/java/com/fanruan/api/data/open/BaseConnection.java
  11. 60
      src/main/java/com/fanruan/api/data/open/BaseDataModel.java
  12. 63
      src/main/java/com/fanruan/api/data/open/BaseTableData.java
  13. 26
      src/main/java/com/fanruan/api/design/ui/component/UIList.java
  14. 87
      src/main/java/com/fanruan/api/design/ui/component/present/DictionaryPane.java
  15. 4
      src/main/java/com/fanruan/api/design/ui/component/table/action/UITableEditAction.java
  16. 1
      src/main/java/com/fanruan/api/design/ui/component/table/model/UITableModelAdapter.java
  17. 4
      src/main/java/com/fanruan/api/design/ui/container/BasicBeanPane.java
  18. 3
      src/main/java/com/fanruan/api/design/work/DatabaseConnectionPane.java
  19. 15
      src/main/java/com/fanruan/api/design/work/form/basic/AccessiblePropertyEditor.java
  20. 53
      src/main/java/com/fanruan/api/design/work/form/basic/EncoderCellRenderer.java
  21. 12
      src/main/java/com/fanruan/api/design/work/form/basic/Item.java
  22. 15
      src/main/java/com/fanruan/api/design/work/form/basic/ItemCellEditor.java
  23. 15
      src/main/java/com/fanruan/api/design/work/form/basic/UneditableAccessibleEditor.java
  24. 10
      src/main/java/com/fanruan/api/design/work/form/container/AbstractDataModify.java
  25. 20
      src/main/java/com/fanruan/api/design/work/form/container/XLayoutContainer.java
  26. 17
      src/main/java/com/fanruan/api/design/work/form/creator/XFieldEditor.java
  27. 14
      src/main/java/com/fanruan/api/design/work/form/editor/StringEditor.java
  28. 18
      src/main/java/com/fanruan/api/design/work/form/editor/WidgetValueEditor.java
  29. 12
      src/main/java/com/fanruan/api/design/work/form/macro/XCreatorConstants.java
  30. 18
      src/main/java/com/fanruan/api/err/TableDataException.java
  31. 41
      src/main/java/com/fanruan/api/io/ResourceModuleKit.java
  32. 21
      src/main/java/com/fanruan/api/report/BaseHTMLWriterKit.java
  33. 22
      src/main/java/com/fanruan/api/report/PaintKit.java
  34. 10
      src/main/java/com/fanruan/api/report/form/CustomWriteAbleRepeatEditor.java
  35. 213
      src/main/java/com/fanruan/api/security/JwtKit.java
  36. 9
      src/main/java/com/fanruan/api/security/SecurityKit.java
  37. 20
      src/main/java/com/fanruan/api/util/ArrayKit.java
  38. 10
      src/main/java/com/fanruan/api/util/CodeKit.java
  39. 9
      src/main/java/com/fanruan/api/util/GeneralKit.java
  40. 13
      src/main/java/com/fanruan/api/xml/XmlKit.java
  41. 10
      src/test/java/com/fanruan/api/cal/FormulaKitTest.java
  42. 17
      src/test/java/com/fanruan/api/cal/ParameterKitTest.java
  43. 67
      src/test/java/com/fanruan/api/data/open/BaseTableDataTest.java
  44. 4
      src/test/java/com/fanruan/api/function/FunctionKitTest.java
  45. 124
      src/test/java/com/fanruan/api/io/ResourceModuleKitTest.java
  46. 13
      src/test/java/com/fanruan/api/plugin/PluginKitTest.java
  47. 77
      src/test/java/com/fanruan/api/security/JwtKitTest.java
  48. 18
      src/test/java/com/fanruan/api/security/SecurityKitTest.java
  49. 21
      src/test/java/com/fanruan/api/util/ArrayKitTest.java
  50. 14
      src/test/java/com/fanruan/api/util/CodeKitTest.java
  51. 3
      src/test/java/com/fanruan/api/util/GeneralKitTest.java
  52. 21
      src/test/java/com/fanruan/api/util/PaintKitTest.java
  53. 38
      src/test/java/com/fanruan/api/xml/XmlKitTest.java

2
.gitignore vendored

@ -2,5 +2,5 @@
.idea/
target/
.DS_Store
.class_path
.classpath
*.jar

41
docs/claim.md

@ -0,0 +1,41 @@
# 非FineKit中的Open类
com.fr.script.AbstractFunction
com.fr.script.Calculator
com.fr.general.FRFont
com.fr.base.BaseFormula
com.fr.base.Style
com.fr.plugin.ExtraClassManager
com.fr.stable.Primitive
com.fr.stable.os.AbstractOperatingSystem
com.fr.stable.os.Arch
com.fr.stable.os.OperatingSystem
com.fr.plugin.context.PluginContexts
com.fr.config.Status
com.fr.config.holder.Conf
com.fr.stable.ColumnRow
com.fr.web.struct.AssembleComponent
com.fr.web.struct.BaseFilter
com.fr.web.struct.Component
com.fr.web.struct.Registry
com.fr.web.struct.category.ScriptPath
com.fr.web.struct.category.StylePath

6
readme.md

@ -24,12 +24,14 @@ SessionKit#getSession(@NotNull String sessionID);
## 提交新API要求
* 所有的API方法的返回值和参数,仅允许使用JDK自带的类、接口类型、插件抽象类、注解或者使用了@Open标记的对象类型。
* 所有的API方法的返回值和参数,仅允许使用JDK自带的类、接口类型、枚举类型、插件抽象类、注解或者使用了@Open标记的对象类型。
* 所有的API方法均需要有单元测试覆盖。
* 所有的API方法均需要有javadoc文档说明。
开放类列表见:[非FineKit开放类](docs/claim.md)
## 使用方法
先使用maven打包,执行下面的命令(跳过单元测试)
@ -51,7 +53,7 @@ SessionKit#getSession(@NotNull String sessionID);
## 如何判断插件中调用的API需要增加到FineKit中
最简单的原则:除了JDK自带的类、插件接口(包括抽象类)、以及使用了@Open注解标记的类之外,是否还使用了com.fanruan.api(com.fr.third除外)之外的类,如果有则需要修改。
最简单的原则:除了JDK自带的类、插件接口(包括抽象类)、枚举、以及使用了@Open注解标记的类之外,是否还使用了com.fanruan.api(com.fr.third除外)之外的类,如果有则需要修改。
## 如何提交新的API

10
src/main/java/com/fanruan/api/cal/CalculatorKit.java

@ -8,6 +8,7 @@ import com.fr.data.TableDataSource;
import com.fr.report.core.namespace.SimpleCellValueNameSpace;
import com.fr.report.report.Report;
import com.fr.script.Calculator;
import com.fr.script.TreeLayerNameSpace;
import com.fr.stable.StringUtils;
import com.fr.stable.script.CalculatorProvider;
import com.fr.stable.script.NameSpace;
@ -95,4 +96,13 @@ public class CalculatorKit {
public static NameSpace createSimpleCellValueNameSpace() {
return SimpleCellValueNameSpace.getInstance();
}
/**
* 创建一个计算树状组件的命名空间
* @param layIndexMap 树状组件中的值
* @return 树状组件的命名空间
*/
public static NameSpace createTreeLayerNameSpace(Map layIndexMap) {
return new TreeLayerNameSpace(layIndexMap);
}
}

11
src/main/java/com/fanruan/api/cal/FormulaKit.java

@ -7,6 +7,7 @@ import com.fr.base.ScriptFormula;
import com.fr.log.FineLoggerFactory;
import com.fr.script.Calculator;
import com.fr.stable.FormulaProvider;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.UtilEvalError;
import com.fr.stable.script.CalculatorProvider;
@ -104,4 +105,14 @@ public class FormulaKit {
}
return checkFormulaContent(formula.getPureContent());
}
/**
* 判断一个对象是否可以转化为公式
* @param object 要判断的字符串
* @return 如果该字符串是以"="开头说明可以转化成公式否则不能转化成公式
*/
public static boolean canBeFormula(Object object){
return StableUtils.canBeFormula(object);
}
}

37
src/main/java/com/fanruan/api/cal/ParameterKit.java

@ -1,8 +1,11 @@
package com.fanruan.api.cal;
import com.fanruan.api.util.ArrayKit;
import com.fanruan.api.util.AssistKit;
import com.fr.base.Parameter;
import com.fr.base.ParameterHelper;
import com.fr.base.ParameterMapNameSpace;
import com.fr.stable.ArrayUtils;
import com.fr.stable.ParameterProvider;
import com.fr.stable.script.NameSpace;
import org.jetbrains.annotations.NotNull;
@ -39,6 +42,7 @@ public class ParameterKit {
/**
* 根据参数名创建新的参数对象
*
* @param name 参数名
* @return 参数对象
*/
@ -98,14 +102,37 @@ public class ParameterKit {
public static @NotNull NameSpace createParameterMapNameSpace(ParameterProvider[] ps) {
return ParameterMapNameSpace.create(ps);
}
/**
* 获得新的参数集合
* 获得新的参数集数组新的参数结中参数的值是通过设定的同名参数传递进去的
*
* @param paramTexts sql语句
* @param ps 旧的参数集合
* @return 新参数集合
* @param ps 用于传值的参数数组
* @return 新参数素组
*/
public static ParameterProvider[] analyzeAndUnionSameParameters(String[] paramTexts, Parameter[] ps){
return ParameterHelper.analyzeAndUnionSameParameters(paramTexts, ps);
public static ParameterProvider[] analyzeAndUnionSameParameters(String[] paramTexts, ParameterProvider[] ps) {
ParameterProvider[] parameters = ParameterKit.analyze4Parameters(paramTexts, false);
if (ArrayUtils.isEmpty(parameters)) {
return parameters;
}
if (ArrayKit.isNotEmpty(ps)) {
for (ParameterProvider newParameter : parameters) {
ParameterProvider existParameter = null;
for (ParameterProvider p : ps) {
if (AssistKit.equals(p.getName(), newParameter.getName())) {
existParameter = p;
break;
}
}
if (existParameter != null) {
newParameter.setValue(existParameter.getValue());
}
}
}
return parameters;
}
}

41
src/main/java/com/fanruan/api/conf/ConfigurationKit.java

@ -1,41 +0,0 @@
package com.fanruan.api.conf;
import com.fr.config.Configuration;
import com.fr.config.holder.ConfigChangeListener;
import com.fr.transaction.Configurations;
import com.fr.transaction.ValidateProxy;
import com.fr.transaction.WorkerFacade;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-30
* 配置监听管理器
*/
public class ConfigurationKit {
/**
* 注册监听配置变化的监听器
*
* @param listener 监听器
*/
public static void registerListener(ConfigChangeListener listener) {
ValidateProxy.getInstance().getValidateManager().registerListener(listener);
}
/**
* 保存配置
*
* @param type 配置的类型
* @param action 保存动作
*/
public static void modify(Class<? extends Configuration> type, Runner action) {
Configurations.modify(new WorkerFacade(type) {
@Override
public void run() {
action.run();
}
});
}
}

54
src/main/java/com/fanruan/api/conf/HolderKit.java

@ -1,5 +1,6 @@
package com.fanruan.api.conf;
import com.fanruan.api.conf.impl.ColConf;
import com.fanruan.api.conf.impl.ObjConf;
import com.fanruan.api.conf.impl.ObjectColConf;
import com.fanruan.api.conf.impl.ObjectMapConf;
@ -16,11 +17,13 @@ import java.util.Map;
* 配置对象操作类
* TODO:补充单元测试
*/
@SuppressWarnings("unchecked")
public class HolderKit {
/**
* 初始化一个基本对象类型的配置
* @param t 初始值
*
* @param t 初始值
* @param <T> 类型
* @return 配置对象
*/
@ -30,9 +33,10 @@ public class HolderKit {
/**
* 初始化一个对象类型的配置
* @param t 初始值
*
* @param t 初始值
* @param type 对象class类
* @param <T> 类型
* @param <T> 类型
* @return 配置对象
*/
public static <T> Conf<T> obj(T t, Class<T> type) {
@ -41,9 +45,10 @@ public class HolderKit {
/**
* 初始化一个集合类型的配置
*
* @param collection 初始值
* @param type 对象class类型
* @param <T> 类型
* @param type 对象class类型
* @param <T> 类型
* @return 配置对象
*/
public static <T> ObjectColConf<Collection<T>> objCollection(Collection<T> collection, Class<T> type) {
@ -52,10 +57,11 @@ public class HolderKit {
/**
* 初始化一个集合类型的配置
*
* @param collection 初始值
* @param type 对象class类型
* @param order 是否是有序的配置
* @param <T> 类型
* @param type 对象class类型
* @param order 是否是有序的配置
* @param <T> 类型
* @return 配置对象
*/
public static <T> ObjectColConf<Collection<T>> objCollection(Collection<T> collection, Class<T> type, boolean order) {
@ -64,11 +70,12 @@ public class HolderKit {
/**
* 初始化一个字典类型的配置
* @param map 初始值
* @param keyType 键class类型
*
* @param map 初始值
* @param keyType 键class类型
* @param valueType 值class类型
* @param <K> 键类型
* @param <V> 值类型
* @param <K> 键类型
* @param <V> 值类型
* @return 配置对象
*/
public static <K, V> ObjectMapConf<Map<K, V>> objMap(Map<K, V> map, Class<K> keyType, Class<V> valueType) {
@ -77,15 +84,28 @@ public class HolderKit {
/**
* 初始化一个字典类型的配置
* @param map 初始值
* @param keyType 键class类型
*
* @param map 初始值
* @param keyType 键class类型
* @param valueType 值class类型
* @param order 是否是有序配置
* @param <K> 键类型
* @param <V> 值类型
* @param order 是否是有序配置
* @param <K> 键类型
* @param <V> 值类型
* @return 配置对象
*/
public static <K, V> ObjectMapConf<Map<K, V>> objMap(Map<K, V> map, Class<K> keyType, Class<V> valueType, boolean order) {
return new ObjectMapConf<>(map, keyType, valueType, order);
}
/**
* 初始化一个集合类型的配置
*
* @param collection 集合
* @param valueType 值类型
* @param <K> 类型
* @return 配置对象
*/
public static <K> ColConf<Collection<K>> collection(Collection<K> collection, Class<K> valueType) {
return new ColConf(collection, valueType);
}
}

1
src/main/java/com/fanruan/api/data/TableDataKit.java

@ -74,4 +74,5 @@ public class TableDataKit {
public static void renameTableData(@NotNull String oldName, @NotNull String newName) {
TableDataConfig.getInstance().renameTableData(oldName, newName);
}
}

51
src/main/java/com/fanruan/api/data/open/BaseConnection.java

@ -0,0 +1,51 @@
package com.fanruan.api.data.open;
import com.fanruan.api.util.ArrayKit;
import com.fr.data.impl.AbstractDatabaseConnection;
import com.fr.data.impl.Connection;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-09-06
* 用于数据连接插件的抽象类
*/
public abstract class BaseConnection extends AbstractDatabaseConnection {
/**
* 测试连接
*
* @throws Exception 异常
*/
@Override
public abstract void testConnection() throws Exception;
/**
* 创建连接
*
* @return 返回连接
* @throws Exception 异常
*/
@Override
public java.sql.Connection createConnection() throws Exception {
return Connection.IGNORE;
}
/**
* 连接成功或失败时给出的信息
*
* @return 信息
*/
@Override
public abstract String connectMessage(boolean status);
/**
* 获取数据连接的摘要信息
*
* @return 摘要
*/
public String[] summary(String... args) {
return ArrayKit.EMPTY_STRING_ARRAY;
}
}

60
src/main/java/com/fanruan/api/data/open/BaseDataModel.java

@ -0,0 +1,60 @@
package com.fanruan.api.data.open;
import com.fanruan.api.err.TableDataException;
import com.fr.data.AbstractDataModel;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-09-04
* 二维表模型
*/
public abstract class BaseDataModel extends AbstractDataModel {
/**
* 获取数据集的列数
*
* @return 列数
* @throws TableDataException 如果获取数据集列数失败则抛出此异常
*/
@Override
public abstract int getColumnCount() throws TableDataException;
/**
* 获取数据集指定列的列名
*
* @param rowIndex 列序号
* @return 类名
* @throws TableDataException 如果获取列名失败则抛出此异常
*/
@Override
public abstract String getColumnName(int rowIndex) throws TableDataException;
/**
* 湖区数据集的行数
*
* @return 行数
* @throws TableDataException 如果获取数据集行数失败则抛出此异常
*/
@Override
public abstract int getRowCount() throws TableDataException;
/**
* 获取数据集中指定位置的值
*
* @param rowIndex
* @param columnIndex
* @return
* @throws TableDataException 如果获取值失败则抛出此异常
*/
@Override
public abstract Object getValueAt(int rowIndex, int columnIndex) throws TableDataException;
/**
* 释放一些构建数据集过程中占用的资源
*
* @throws Exception 释放资源时发生错误则抛出此异常
*/
@Override
public abstract void release() throws Exception;
}

63
src/main/java/com/fanruan/api/data/open/BaseTableData.java

@ -0,0 +1,63 @@
package com.fanruan.api.data.open;
import com.fr.data.AbstractParameterTableData;
import com.fr.general.data.DataModel;
import com.fr.script.Calculator;
import com.fr.stable.ParameterProvider;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-09-04
* 插件的数据集接口
*/
public abstract class BaseTableData extends AbstractParameterTableData {
/**
* 实现这个方法来返回一个数据集
*
* @param calculator 算子
* @return 数据集二维表对象
*/
@Override
public abstract DataModel createDataModel(Calculator calculator);
/**
* 返回获取数据的执行对象
* 系统取数时调用此方法来返回一个获取数据的执行对象
* 注意 当数据集需要根据不同参数来多次取数时此方法在一个计算过程中会被多次调用
*
* @param calculator 算子
* @param rowCount 要获取数据的行数
* @return 数据集二维表对象
*/
@Override
public DataModel createDataModel(Calculator calculator, int rowCount) {
return createDataModel(calculator);
}
/**
* 返回获取数据的执行对象
* 系统取数时调用此方法来返回一个获取数据的执行对象
* 注意 当数据集需要根据不同参数来多次取数时此方法在一个计算过程中会被多次调用
*
* @param calculator 算子
* @param name 数据集的名字
* @return 数据集二维表对象
*/
@Override
public DataModel createDataModel(Calculator calculator, String name) {
return createDataModel(calculator);
}
/**
* 获取数据集中定义的参数
*
* @param calculator 算子
* @return 参数数组
*/
@Override
public ParameterProvider[] getParameters(Calculator calculator) {
return super.getParameters(calculator);
}
}

26
src/main/java/com/fanruan/api/design/ui/component/UIList.java

@ -0,0 +1,26 @@
package com.fanruan.api.design.ui.component;
import javax.swing.*;
import java.util.Vector;
/**
* @author Kalven
* @version 10.0
* Created by Kalven on 2019/9/4
* 列表组件
*/
public class UIList extends com.fr.design.gui.ilist.UIList {
public UIList(ListModel dataModel) {
super(dataModel);
}
public UIList(Object[] listData) {
super(listData);
}
public UIList(Vector<?> listData) {
super(listData);
}
}

87
src/main/java/com/fanruan/api/design/ui/component/present/DictionaryPane.java

@ -0,0 +1,87 @@
package com.fanruan.api.design.ui.component.present;
import com.fanruan.api.design.DesignKit;
import com.fr.data.Dictionary;
import com.fr.data.impl.DynamicSQLDict;
import com.fr.design.beans.FurtherBasicBeanPane;
import com.fr.design.constants.LayoutConstants;
import com.fr.design.data.DataCreatorUI;
import com.fr.design.gui.frpane.UIComboBoxPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.present.dict.CustomDictPane;
import com.fr.design.present.dict.DatabaseDictPane;
import com.fr.design.present.dict.FormulaDictPane;
import com.fr.design.present.dict.TableDataDictPane;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
/**
* @author Kalven
* @version 10.0
* Created by Kalven on 2019/9/4
* 数据字典容器获取数据字典
*/
public class DictionaryPane extends UIComboBoxPane<Dictionary> implements DataCreatorUI {
private TableDataDictPane tableDataDictPane;
@Override
protected void initLayout() {
this.setLayout(new BorderLayout(0, 4));
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
double[] columnSize = {p, f};
double[] rowSize = {p, p};
int[][] rowCount = {{1, 1}, {1, 1}};
Component[][] components = new Component[][]{
new Component[]{new UILabel(DesignKit.i18nText("Fine-Design_Basic_Type_Set"), UILabel.LEFT), jcb},
new Component[]{null, null}
};
JPanel northPane = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_HUGER, LayoutConstants.VGAP_MEDIUM);
this.add(northPane, BorderLayout.NORTH);
this.add(cardPane, BorderLayout.CENTER);
}
@Override
protected String title4PopupWindow() {
return DesignKit.i18nText("Fine-Design_Form_DS_Dictionary");
}
@Override
public JComponent toSwingComponent() {
return this;
}
@Override
public void populateBean(Dictionary ob) {
for (int i = 0; i < this.cards.size(); i++) {
FurtherBasicBeanPane pane = cards.get(i);
if (pane.accept(ob)) {
pane.populateBean(ob);
jcb.setSelectedIndex(i);
} else {
pane.reset();
}
}
if (ob instanceof DynamicSQLDict) {
jcb.setSelectedIndex(1);
tableDataDictPane.populateBean((DynamicSQLDict) ob);
}
}
@Override
protected List<FurtherBasicBeanPane<? extends Dictionary>> initPaneList() {
List<FurtherBasicBeanPane<? extends Dictionary>> paneList = new ArrayList<FurtherBasicBeanPane<? extends Dictionary>>();
paneList.add(new DatabaseDictPane());
paneList.add(tableDataDictPane = new TableDataDictPane());
paneList.add(new CustomDictPane());
paneList.add(new FormulaDictPane());
return paneList;
}
}

4
src/main/java/com/fanruan/api/design/ui/component/table/action/UITableEditAction.java

@ -5,8 +5,8 @@ import java.awt.event.ActionEvent;
public class UITableEditAction extends com.fr.design.gui.itableeditorpane.UITableEditAction {
@Override
public void checkEnabled() {
}
public void checkEnabled(){};
@Override
public void actionPerformed(ActionEvent e) {

1
src/main/java/com/fanruan/api/design/ui/component/table/model/UITableModelAdapter.java

@ -20,6 +20,7 @@ public abstract class UITableModelAdapter<T> extends com.fr.design.gui.itableedi
super(strings);
}
@Override
public abstract UITableEditAction[] createAction();

4
src/main/java/com/fanruan/api/design/ui/container/BasicBeanPane.java

@ -1,4 +0,0 @@
package com.fanruan.api.design.ui.container;
public abstract class BasicBeanPane<T> extends com.fr.design.beans.BasicBeanPane<T> {
}

3
src/main/java/com/fanruan/api/design/work/DatabaseConnectionPane.java

@ -4,7 +4,6 @@ package com.fanruan.api.design.work;
import com.fanruan.api.design.ui.component.UIButton;
import com.fanruan.api.design.ui.component.UIComboBox;
import com.fanruan.api.design.ui.component.UILabel;
import com.fanruan.api.design.ui.container.BasicBeanPane;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.macro.EncodeConstants;
import com.fanruan.api.util.ArrayKit;
@ -31,7 +30,7 @@ import java.awt.event.WindowEvent;
*
* @param <E> 数据连接类型
*/
public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connection> extends BasicBeanPane<Connection> {
public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connection> extends com.fr.design.beans.BasicBeanPane<Connection> {
private UILabel message;
private UIButton okButton;

15
src/main/java/com/fanruan/api/design/work/form/basic/AccessiblePropertyEditor.java

@ -0,0 +1,15 @@
package com.fanruan.api.design.work.form.basic;
import com.fr.design.mainframe.widget.accessibles.AccessibleEditor;
/**
* @author Kalven
* @version 10.0
* Created by Kalven on 2019/9/4
* 可以通过按钮或其他方式进去编辑面板的编辑器
*/
public class AccessiblePropertyEditor extends com.fr.design.mainframe.widget.accessibles.AccessiblePropertyEditor {
public AccessiblePropertyEditor(AccessibleEditor editor) {
super(editor);
}
}

53
src/main/java/com/fanruan/api/design/work/form/basic/EncoderCellRenderer.java

@ -0,0 +1,53 @@
package com.fanruan.api.design.work.form.basic;
import com.fr.design.designer.properties.Encoder;
import com.fr.design.mainframe.widget.renderer.GenericCellRenderer;
import java.awt.*;
/**
* @author Kalven
* @version 10.0
* Created by Kalven on 2019/9/4
* 根据控件属性渲染单元格
*/
public class EncoderCellRenderer extends GenericCellRenderer {
private static int LEFT = 1;
protected Encoder encoder;
protected Object value;
public EncoderCellRenderer(Encoder encoder) {
this.encoder = encoder;
}
@Override
public void paint(Graphics g) {
int width = getWidth();
int height = getHeight();
g.setColor(getBackground());
g.fillRect(0, 0, width, height);
int x = LEFT;
g.setColor(getForeground());
FontMetrics fm = g.getFontMetrics();
int y = ((height - fm.getHeight()) / 2) + fm.getAscent();
String txt = getValueText();
if (txt != null) {
g.drawString(txt, x, y);
}
if (getBorder() != null) {
getBorder().paintBorder(this, g, 0, 0, width, height);
}
}
@Override
public void setValue(Object value) {
this.value = value;
}
private String getValueText() {
return encoder.encode(value);
}
}

12
src/main/java/com/fanruan/api/design/work/form/basic/Item.java

@ -0,0 +1,12 @@
package com.fanruan.api.design.work.form.basic;
/**
* @author Kalven
* @version 10.0
* Created by Kalven on 2019/9/4
*/
public class Item extends com.fr.design.designer.properties.items.Item {
public Item(String name, Object value) {
super(name, value);
}
}

15
src/main/java/com/fanruan/api/design/work/form/basic/ItemCellEditor.java

@ -0,0 +1,15 @@
package com.fanruan.api.design.work.form.basic;
import com.fr.design.designer.properties.items.Item;
/**
* @author Kalven
* @version 10.0
* Created by Kalven on 2019/9/4
* 用作左中右对齐设置的下拉框Editor
*/
public class ItemCellEditor extends com.fr.design.mainframe.widget.editors.ItemCellEditor {
public ItemCellEditor(Item[] items) {
super(items);
}
}

15
src/main/java/com/fanruan/api/design/work/form/basic/UneditableAccessibleEditor.java

@ -0,0 +1,15 @@
package com.fanruan.api.design.work.form.basic;
import com.fr.design.designer.properties.Encoder;
/**
* @author Kalven
* @version 10.0
* Created by Kalven on 2019/9/4
* 无法修改的编辑器
*/
public abstract class UneditableAccessibleEditor extends com.fr.design.mainframe.widget.accessibles.UneditableAccessibleEditor {
public UneditableAccessibleEditor(Encoder enc) {
super(enc);
}
}

10
src/main/java/com/fanruan/api/design/work/form/container/AbstractDataModify.java

@ -0,0 +1,10 @@
package com.fanruan.api.design.work.form.container;
/**
* 抽象数据定义实现数据可序列化
* @author Kalven
* @version 10.0
* Created by Kalven on 2019/9/3
*/
public abstract class AbstractDataModify<T> extends com.fr.design.widget.ui.AbstractDataModify<T> {
}

20
src/main/java/com/fanruan/api/design/work/form/container/XLayoutContainer.java

@ -0,0 +1,20 @@
package com.fanruan.api.design.work.form.container;
import com.fr.form.ui.container.WLayout;
import java.awt.*;
/**
*
* 属性设置部分布局容器
* @author Kalven
* @version 10.0
* Created by Kalven on 2019/9/3
*/
public abstract class XLayoutContainer extends com.fr.design.designer.creator.XLayoutContainer {
public XLayoutContainer(WLayout widget, Dimension initSize) {
super(widget, initSize);
this.addContainerListener(this);
}
}

17
src/main/java/com/fanruan/api/design/work/form/creator/XFieldEditor.java

@ -0,0 +1,17 @@
package com.fanruan.api.design.work.form.creator;
import com.fr.form.ui.FieldEditor;
import java.awt.*;
/**
* 控件树
* @author Kalven
* @version 10.0
* Created by Kalven on 2019/9/3
*/
public abstract class XFieldEditor extends com.fr.design.designer.creator.XFieldEditor {
public XFieldEditor(FieldEditor widget, Dimension initSize) {
super(widget, initSize);
}
}

14
src/main/java/com/fanruan/api/design/work/form/editor/StringEditor.java

@ -0,0 +1,14 @@
package com.fanruan.api.design.work.form.editor;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-09-05
* 字符串编辑器
*/
public class StringEditor extends com.fr.design.mainframe.widget.editors.StringEditor {
public StringEditor() {
super();
}
}

18
src/main/java/com/fanruan/api/design/work/form/editor/WidgetValueEditor.java

@ -0,0 +1,18 @@
package com.fanruan.api.design.work.form.editor;
/**
* @author Kalven
* @version 10.0
* Created by Kalven on 2019/9/4
* 控件值编辑器
*/
public class WidgetValueEditor extends com.fr.design.mainframe.widget.editors.WidgetValueEditor {
public WidgetValueEditor(Object o) {
super(o);
}
public WidgetValueEditor(Object o, boolean onlyServer) {
super(o, onlyServer);
}
}

12
src/main/java/com/fanruan/api/design/work/form/macro/XCreatorConstants.java

@ -0,0 +1,12 @@
package com.fanruan.api.design.work.form.macro;
/**
* 存放XCreator的常量
* @author Kalven
* @version 10.0
* Created by Kalven on 2019/9/3
*/
public class XCreatorConstants {
public static final String PROPERTY_CATEGORY = com.fr.design.form.util.XCreatorConstants.PROPERTY_CATEGORY;
}

18
src/main/java/com/fanruan/api/err/TableDataException.java

@ -0,0 +1,18 @@
package com.fanruan.api.err;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-09-04
* 数据集异常
*/
public class TableDataException extends com.fr.general.data.TableDataException {
public TableDataException(String s) {
super(s);
}
public TableDataException(String s, Throwable throwable) {
super(s, throwable);
}
}

41
src/main/java/com/fanruan/api/io/ResourceModuleKit.java

@ -0,0 +1,41 @@
package com.fanruan.api.io;
import com.fr.io.base.provider.RepositoryFactoryProvider;
import com.fr.io.context.ResourceModuleContext;
import org.jetbrains.annotations.NotNull;
/**
*
* 资源仓库插件开发套件
*
* @author rinoux
* @version 10.0
* Created by rinoux on 2019/9/5
*/
public class ResourceModuleKit {
/**
* 添加一个资源仓库工厂
*
* @param factory 工厂
* @param <T> 工厂类型
*/
public static <T extends RepositoryFactoryProvider> void addFactory(@NotNull T factory) {
ResourceModuleContext.addFactory(factory);
}
/**
* 移除一个资源仓库工厂
*
* @param factory 工厂
* @param <T> 工厂类型
*/
public static <T extends RepositoryFactoryProvider> void removeFactory(@NotNull T factory) {
ResourceModuleContext.removeFactory(factory.getIdentity());
}
}

21
src/main/java/com/fanruan/api/report/BaseHTMLWriterKit.java

@ -0,0 +1,21 @@
package com.fanruan.api.report;
import com.fr.stable.html.Tag;
import com.fr.stable.web.Repository;
import com.fr.web.BaseHTMLWriterUtils;
import java.awt.*;
public class BaseHTMLWriterKit {
/**
* 根据原始的图片和指定的尺寸以及报表上下文生成图片的HTML标签该方法只生成一个简单的img标签
* @param image 原始图片
* @param dimension 指定尺寸
* @param repo 报表上下文
* @return img图片标签
*/
public static Tag createImageTag4RepoWithCheckVml(Image image, Dimension dimension, Repository repo){
return BaseHTMLWriterUtils.createImageTag4RepoWithCheckVml(image, dimension, repo);
}
}

22
src/main/java/com/fanruan/api/report/PaintKit.java

@ -0,0 +1,22 @@
package com.fanruan.api.report;
import com.fr.base.Style;
import com.fr.report.cell.cellattr.core.CellUtils;
import java.awt.*;
public class PaintKit {
/**
* 如果value是ImageWithSuffix类的一个实例则创建一个宽为width高为height,类型为TYPE_4BYTE_ABGR的image,并将其按照比例和Style绘制
* @param value 传入的需要判断为是否是ImageWithSuffix实例的对象
* @param resolution 缩放比例的分母缩放比例为1/resolution
* @param style 绘制image的style
* @param width 绘制image的宽
* @param height 绘制image的高
* @return 返回宽为width高为height,类型为TYPE_4BYTE_ABGR的image
*/
public static Image value2Image(Object value, int resolution, Style style, int width, int height){
return CellUtils.value2Image(value, resolution, style, width, height);
}
}

10
src/main/java/com/fanruan/api/report/form/CustomWriteAbleRepeatEditor.java

@ -0,0 +1,10 @@
package com.fanruan.api.report.form;
/**
* 允许自定义值的允许直接编辑的带重复的 --- 下拉框 下拉复选框 下拉树
* @author Kalven
* @version 10.0
* Created by Kalven on 2019/9/4
*/
public abstract class CustomWriteAbleRepeatEditor extends com.fr.form.ui.CustomWriteAbleRepeatEditor {
}

213
src/main/java/com/fanruan/api/security/JwtKit.java

@ -0,0 +1,213 @@
package com.fanruan.api.security;
import com.fanruan.api.log.LogKit;
import com.fr.cert.token.JwtBuilder;
import com.fr.cert.token.Jwts;
import com.fr.cert.token.SignatureAlgorithm;
import com.fr.cert.token.SignatureException;
import com.fr.cert.token.impl.DefaultClaims;
import com.fr.security.KeySecretSeedConfig;
import com.fr.security.SecurityToolbox;
import java.io.IOException;
import java.security.Key;
import java.util.Date;
import java.util.Map;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-09-03
* 用于生成和解析基于JWT的token
*/
public class JwtKit {
private static final String JWT_ID = "jwt";
private static final String ISSUER = "fanruan";
private static final SignatureAlgorithm DEFAULT_ALGORITHM = SignatureAlgorithm.HS256;
/**
* 创建完整token
*
* @param issuer jwt签发者
* @param subject jwt所面向的用户
* @param audience 接收jwt的一方
* @param expiration jwt的过期时间这个过期时间必须要大于签发时间
* @param notBeforeTime 定义在什么时间之前该jwt都是不可用的.
* @param issuerAtTime jwt的签发时间
* @param jwtId jwt的唯一身份标识主要用来作为一次性token,从而回避重放攻击
* @param algorithm 加密算法
* @param secretKey 秘钥
* @return 签名后的token
*/
public static String createJWT(String issuer, String subject, String audience, Date expiration, Date notBeforeTime,
Date issuerAtTime, String jwtId, SignatureAlgorithm algorithm, Key secretKey) {
JwtBuilder builder = Jwts.builder()
.setIssuer(issuer)
.setSubject(subject)
.setAudience(audience)
.setExpiration(expiration)
.setNotBefore(notBeforeTime)
.setIssuedAt(issuerAtTime)
.setId(jwtId)
.signWith(algorithm, secretKey);
return builder.compact();
}
/**
* 创建默认的token用不超时
*
* @param subject 主题
* @return token
*/
public static String createDefaultJWT(String subject) {
JwtBuilder builder = Jwts.builder()
.setIssuer(ISSUER)
.setIssuedAt(new Date())
.setSubject(subject)
.setId(JWT_ID)
.signWith(DEFAULT_ALGORITHM, getKeyBytes());
return builder.compact();
}
/**
* 创建默认的token
*
* @param subject 主题
* @param description 描述
* @return token
*/
public static String createDefaultJWT(String subject, String description) {
JwtBuilder builder = Jwts.builder()
.setIssuer(ISSUER)
.setIssuedAt(new Date())
.setSubject(subject)
.setDescription(description)
.setId(JWT_ID)
.signWith(DEFAULT_ALGORITHM, getKeyBytes());
return builder.compact();
}
/**
* 创建默认token
*
* @param subject 主题
* @param description 描述
* @param timeout 超时时长
* @return token
*/
public static String createDefaultJWT(String subject, String description, long timeout) {
Date currentTime = new Date();
Date timeoutTime = new Date(currentTime.getTime() + timeout);
JwtBuilder builder = Jwts.builder()
.setIssuer(ISSUER)
.setIssuedAt(currentTime)
.setExpiration(timeoutTime)
.setSubject(subject)
.setDescription(description)
.setId(JWT_ID)
.signWith(DEFAULT_ALGORITHM, getKeyBytes());
return builder.compact();
}
/**
* 创建有超时时限的token
*
* @param subject 主题
* @param timeout 超时时长
* @return token
*/
public static String createDefaultJWT(String subject, long timeout) {
Date currentTime = new Date();
Date timeoutTime = new Date(currentTime.getTime() + timeout);
JwtBuilder builder = Jwts.builder()
.setIssuer(ISSUER)
.setIssuedAt(currentTime)
.setExpiration(timeoutTime)
.setSubject(subject)
.setId(JWT_ID)
.signWith(DEFAULT_ALGORITHM, getKeyBytes());
return builder.compact();
}
/**
* 解析token
*
* @param jwt token字符串
* @return 签名通过之后的结果集
* @throws SignatureException 签名错误异常
*/
public static Map<String, Object> parseJWT(String jwt) {
try {
return Jwts.parser().setSigningKey(getKeyBytes()).parseClaimsJws(jwt).getBody();
} catch (SignatureException e) {
LogKit.warn(e.getMessage());
}
return new DefaultClaims();
}
/**
* 根据自定义的key创建token
*
* @param signatureKey 秘钥
* @param claims token携带的信息
* @return token
*/
public static String createVariedJWT(String signatureKey, Map<String, Object> claims) {
JwtBuilder builder = Jwts.builder()
.setIssuer(ISSUER)
.setIssuedAt(new Date())
.setClaims(claims)
.setId(JWT_ID)
.signWith(DEFAULT_ALGORITHM, signatureKey);
return builder.compact();
}
/**
* 根据自定义的key创建token
*
* @param signatureKey 秘钥
* @param timeout 有效期
* @param claims token携带的信息
* @return token
*/
public static String createVariedJWT(String signatureKey, long timeout, Map<String, Object> claims) {
Date currentTime = new Date();
Date timeoutTime = new Date(currentTime.getTime() + timeout);
JwtBuilder builder = Jwts.builder()
.setIssuer(ISSUER)
.setIssuedAt(new Date())
.setExpiration(timeoutTime)
.setClaims(claims)
.setId(JWT_ID)
.signWith(DEFAULT_ALGORITHM, signatureKey);
return builder.compact();
}
/**
* 解析token, 先对key进行utf-8解码
*
* @param jwt token字符串
* @param signatureKey 秘钥
* @return 签名通过之后的结果集
* @throws SignatureException 签名错误异常
*/
public static Map<String, Object> parseJWT(String jwt, String signatureKey) {
try {
return Jwts.parser().setSigningKey(signatureKey).parseClaimsJws(jwt).getBody();
} catch (SignatureException e) {
LogKit.warn(e.getMessage());
}
return new DefaultClaims();
}
private static byte[] getKeyBytes() {
try {
return SecurityToolbox.base642Byte(KeySecretSeedConfig.getInstance().getTrustSeed());
} catch (IOException e) {
LogKit.error("key secret seed base64 decode error");
}
return new byte[0];
}
}

9
src/main/java/com/fanruan/api/security/SecurityKit.java

@ -35,4 +35,13 @@ public class SecurityKit {
public static String passwordDecode(String passwordText) {
return CodeUtils.passwordDecode(passwordText);
}
/**
* 给字符串加密
* @param passwordText 待加密的字符串
* @return 解加密的字符串
*/
public static String passwordEncode(String passwordText) {
return CodeUtils.passwordEncode(passwordText);
}
}

20
src/main/java/com/fanruan/api/util/ArrayKit.java

@ -2,6 +2,8 @@ package com.fanruan.api.util;
import com.fr.stable.ArrayUtils;
import java.util.List;
/**
* @author richie
* @version 10.0
@ -91,4 +93,22 @@ public class ArrayKit {
public static <T> boolean isNotEmpty(T[] array) {
return ArrayUtils.isNotEmpty(array);
}
/**
* 返回一个ArrayList
* @param array 数组
* @return 链表
* */
public static <T> List<T> toList(T[] array) {
return ArrayUtils.toList(array);
}
/**
* 求数组长度
* @param array 数组
* @return 长度
*/
public static int getLength(Object array) {
return ArrayUtils.getLength(array);
}
}

10
src/main/java/com/fanruan/api/util/CodeKit.java

@ -12,4 +12,14 @@ public class CodeKit {
public static String passwordDecode(String passwordText) {
return CodeUtils.passwordDecode(passwordText);
}
/**
* 将经过处理的中日韩文字符串解码成原先的中日韩文
* @param text 经过处理的中日韩文字
* @return 中日韩文字
* @throws Exception
*/
public static String cjkDecode(String text) throws Exception {
return CodeUtils.cjkDecode(text);
}
}

9
src/main/java/com/fanruan/api/util/GeneralKit.java

@ -3,7 +3,12 @@ package com.fanruan.api.util;
import com.fr.base.FRContext;
import com.fr.general.ComparatorUtils;
import com.fr.general.GeneralUtils;
import com.fr.general.xml.GeneralXMLTools;
import com.fr.stable.CommonUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLable;
import com.fr.stable.xml.XMLableReader;
import com.fr.third.guava.base.Objects;
import com.fr.stable.StableUtils;
import org.jetbrains.annotations.NotNull;
@ -83,7 +88,7 @@ public class GeneralKit {
public static String join(Object[] array, String se) {
return StableUtils.join(array, se);
}
/*
/**
* 返回国际化区属
* @return 国际化后区域属性
*/
@ -91,4 +96,6 @@ public class GeneralKit {
public static Locale getLocale() {
return FRContext.getLocale();
}
}

13
src/main/java/com/fanruan/api/xml/XmlKit.java

@ -3,11 +3,13 @@ package com.fanruan.api.xml;
import com.fr.data.core.DataCoreXmlUtils;
import com.fr.data.impl.Connection;
import com.fr.general.xml.GeneralXMLTools;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.ParameterProvider;
import com.fr.stable.xml.XMLReadable;
import com.fr.stable.xml.XMLTools;
import com.fr.stable.xml.XMLable;
import com.fr.stable.xml.XMLableReader;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.StableXMLUtils;
import java.io.InputStream;
@ -76,4 +78,13 @@ public class XmlKit {
DataCoreXmlUtils.writeXMLConnection(writer, connection);
}
/**
*读出xml参数
* @param reader xml读出对象
* @return 返回保存参数数组
*/
public static ParameterProvider readParameter(XMLableReader reader) {
return StableXMLUtils.readParameter(reader);
}
}

10
src/test/java/com/fanruan/api/cal/FormulaKitTest.java

@ -72,4 +72,14 @@ public class FormulaKitTest extends Prepare {
assertEquals(true, FormulaKit.checkFormulaContent(new Formula("=")));
assertEquals(false, FormulaKit.checkFormulaContent("="));
}
@Test
public void canBeFormula() {
String s1 = "=1";
String s2 = "=a+b+";
String s3 = "ppp";
Assert.assertTrue(FormulaKit.canBeFormula(s1));
Assert.assertTrue(FormulaKit.canBeFormula(s2));
Assert.assertFalse(FormulaKit.canBeFormula(s3));
}
}

17
src/test/java/com/fanruan/api/cal/ParameterKitTest.java

@ -111,7 +111,22 @@ public class ParameterKitTest extends Prepare {
@Test
public void newParameter2() {
ParameterProvider provider = ParameterKit.newParameter("p1");
Assert.assertEquals(provider.getName(),"p1");
Assert.assertEquals(provider.getName(), "p1");
Assert.assertEquals("", provider.getValue());
}
@Test
public void analyzeAndUnionSameParameters() {
ParameterProvider p1 = ParameterKit.newParameter("p1", 100);
ParameterProvider p2 = ParameterKit.newParameter("p2", 200);
ParameterProvider[] providers = ParameterKit.analyzeAndUnionSameParameters(
new String[]{"select * from td where name = ${p1} and age = ${p3}"},
new ParameterProvider[]{p1, p2});
for (ParameterProvider provider : providers) {
if ("p1".equals(provider.getName())) {
Assert.assertEquals(100, provider.getValue());
}
}
}
}

67
src/test/java/com/fanruan/api/data/open/BaseTableDataTest.java

@ -0,0 +1,67 @@
package com.fanruan.api.data.open;
import com.fr.general.data.DataModel;
import com.fr.script.Calculator;
import org.junit.Assert;
import org.junit.Test;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-09-04
*/
public class BaseTableDataTest {
@Test
public void testCreate() throws Exception {
Calculator calculator = Calculator.createCalculator();
DemoTableData tableData = new DemoTableData();
DataModel model = tableData.createDataModel(calculator);
Object r = model.getValueAt(0, 0);
Assert.assertTrue(model.hasRow(0));
Assert.assertFalse(model.hasRow(1));
Assert.assertEquals(1, model.getColumnCount());
Assert.assertEquals(1, model.getRowCount());
Assert.assertEquals("abc", r);
}
private static class DemoTableData extends BaseTableData {
@Override
public DataModel createDataModel(Calculator calculator) {
return new BaseDataModel() {
@Override
public int getColumnCount() {
return 1;
}
@Override
public String getColumnName(int i) {
return "test";
}
@Override
public boolean hasRow(int i) {
return i < 1;
}
@Override
public int getRowCount() {
return 1;
}
@Override
public Object getValueAt(int i, int i1) {
return "abc";
}
@Override
public void release() throws Exception {
}
};
}
}
}

4
src/test/java/com/fanruan/api/function/FunctionKitTest.java

@ -42,4 +42,8 @@ public class FunctionKitTest extends Prepare {
assertNotEquals("OK", result);
}
@Test
public void generateFunctionID() {
assertEquals(FunctionKit.generateFunctionID("com.fr.plugin.widget.ztree"),169608572);
}
}

124
src/test/java/com/fanruan/api/io/ResourceModuleKitTest.java

@ -0,0 +1,124 @@
package com.fanruan.api.io;
import com.fr.io.base.provider.FactoryLoaderProvider;
import com.fr.io.base.provider.RepositoryFactoryProvider;
import com.fr.io.base.provider.RepositoryInstallerProvider;
import com.fr.io.base.provider.RepositoryManagerProvider;
import com.fr.io.config.RepositoryConfig;
import com.fr.io.config.ResourceModuleConfigProvider;
import com.fr.io.context.RepositoryContextProvider;
import com.fr.io.context.ResourceModuleContext;
import com.fr.io.lock.LockFactory;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
/**
* ResourceModuleKit Tester.
*
* @author <Authors name>
* @version 1.0
* @since <pre>9月 5, 2019</pre>
*/
public class ResourceModuleKitTest {
@Before
public void before() throws Exception {
final FactoryLoaderProvider loaderProvider = new FactoryLoaderProvider() {
final Map<String, RepositoryFactoryProvider> map = new HashMap<>();
@Override
public <T extends RepositoryConfig> void add(RepositoryFactoryProvider<T> factory) {
map.put(factory.getIdentity(), factory);
}
@Override
public void remove(String identity) {
map.remove(identity);
}
@Override
@SuppressWarnings("unchecked")
public <T extends RepositoryConfig> RepositoryFactoryProvider<T> get(String identity) {
return map.get(identity);
}
};
ResourceModuleContext.setRepositoryContext(new RepositoryContextProvider() {
@Override
public FactoryLoaderProvider getFactoryLoader() {
return loaderProvider;
}
@Override
public ResourceModuleConfigProvider getConfig() {
return null;
}
@Override
public RepositoryManagerProvider getManager() {
return null;
}
@Override
public RepositoryInstallerProvider getInstaller() {
return null;
}
@Override
public LockFactory getLockFactory() {
return null;
}
});
}
@After
public void after() throws Exception {
ResourceModuleContext.setRepositoryContext(null);
}
/**
* Method: addFactory(@NotNull T factory)
*/
@Test
public void testAddFactory() throws Exception {
RepositoryFactoryProvider factory = EasyMock.createMock(RepositoryFactoryProvider.class);
EasyMock.expect(factory.getIdentity()).andReturn("MockRF").anyTimes();
EasyMock.replay(factory);
Assert.assertNull(ResourceModuleContext.getFactory("MockRF"));
ResourceModuleKit.addFactory(factory);
Assert.assertNotNull(ResourceModuleContext.getFactory("MockRF"));
}
/**
* Method: addFactory(@NotNull T factory)
*/
@Test
public void testRemoveFactory() throws Exception {
RepositoryFactoryProvider factory = EasyMock.createMock(RepositoryFactoryProvider.class);
EasyMock.expect(factory.getIdentity()).andReturn("MockRF").anyTimes();
EasyMock.replay(factory);
Assert.assertNull(ResourceModuleContext.getFactory("MockRF"));
ResourceModuleKit.addFactory(factory);
Assert.assertNotNull(ResourceModuleContext.getFactory("MockRF"));
ResourceModuleKit.removeFactory(factory);
Assert.assertNull(ResourceModuleContext.getFactory("MockRF"));
}
}

13
src/test/java/com/fanruan/api/plugin/PluginKitTest.java

@ -0,0 +1,13 @@
package com.fanruan.api.plugin;
import com.fanruan.api.runtime.PluginKit;
import org.junit.Assert;
import org.junit.Test;
public class PluginKitTest {
@Test
public void getArray() {
Assert.assertFalse(PluginKit.isCurrentPluginAvailable());
}
}

77
src/test/java/com/fanruan/api/security/JwtKitTest.java

@ -0,0 +1,77 @@
package com.fanruan.api.security;
import com.fanruan.api.Prepare;
import com.fr.cert.token.JwtBuilder;
import com.fr.cert.token.Jwts;
import com.fr.cert.token.SignatureAlgorithm;
import com.fr.security.SecurityToolbox;
import com.fr.stable.CodeUtils;
import org.junit.Assert;
import org.junit.Test;
import java.io.UnsupportedEncodingException;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-09-03
*/
public class JwtKitTest extends Prepare {
@Test
public void testCreateDefaultJWT() throws Exception {
String tokenCN = JwtKit.createDefaultJWT("你好,我是中国人");
Map<String, Object> claims = JwtKit.parseJWT(tokenCN);
Assert.assertEquals("你好,我是中国人", CodeUtils.cjkDecode(String.valueOf(claims.get("sub"))));
String tokenEN = JwtKit.createDefaultJWT("Hello, world");
Map<String, Object> claims2 = JwtKit.parseJWT(tokenEN);
Assert.assertEquals("Hello, world", CodeUtils.cjkDecode(String.valueOf(claims2.get("sub"))));
}
@Test
public void testClaims() throws Exception {
String token = JwtKit.createDefaultJWT("千万", "我是千万的爹");
Map<String, Object> claims2 = JwtKit.parseJWT(token);
String text = CodeUtils.cjkDecode(String.valueOf(claims2.get("description")));
Assert.assertEquals("我是千万的爹", text);
}
@Test
public void test1() throws UnsupportedEncodingException {
String token = createToken().compact();
Assert.assertEquals(Jwts.parser().setSigningKey("abc=啊").parseClaimsJws(token).getBody().getSubject(), "hello.cpt");
token = createToken().signWithBase64SecretKey(SignatureAlgorithm.HS256, SecurityToolbox.byte2Base64("abc=啊".getBytes())).compact();
Assert.assertEquals(Jwts.parser()
.setBase64SigningKey(SecurityToolbox.byte2Base64("abc=啊".getBytes()))
.parseClaimsJws(token).getBody().getSubject(), "hello.cpt");
token = createToken()
.signWith(SignatureAlgorithm.HS256, "abc=啊".getBytes("GBK"))
.compact();
Assert.assertEquals("hello.cpt", Jwts.parser().setSigningKey("abc=啊".getBytes("GBK")).parseClaimsJws(token).getBody().getSubject());
}
private JwtBuilder createToken() {
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
Calendar calendar = Calendar.getInstance();
calendar.set(2019, Calendar.FEBRUARY, 20, 18, 0, 0);
Date currentTime = calendar.getTime();
calendar.set(2029, Calendar.FEBRUARY, 20, 18, 0, 0);
Date expirationTime = calendar.getTime();
return Jwts.builder()
.setHeaderParam("typ", "JWT")
.setIssuer("fanruan")
.setSubject("hello.cpt")
.setExpiration(expirationTime)
.setIssuedAt(currentTime)
.setId("01")
.signWith(signatureAlgorithm, "abc=啊");
}
}

18
src/test/java/com/fanruan/api/security/SecurityKitTest.java

@ -0,0 +1,18 @@
package com.fanruan.api.security;
import java.util.*;
import com.fr.stable.CommonCodeUtils;
import org.junit.Assert;
import org.junit.Test;
public class SecurityKitTest {
@Test
public void passwordDecode(){
Assert.assertEquals(SecurityKit.passwordDecode("1234"), CommonCodeUtils.passwordDecode("1234"));
}
@Test
public void passwordEncode(){
Assert.assertEquals(SecurityKit.passwordEncode("1234"), CommonCodeUtils.passwordEncode("1234"));
}
}

21
src/test/java/com/fanruan/api/util/ArrayKitTest.java

@ -1,6 +1,8 @@
package com.fanruan.api.util;
import com.fanruan.api.Prepare;
import java.util.*;
import org.junit.Assert;
import org.junit.Test;
@ -97,4 +99,23 @@ public class ArrayKitTest extends Prepare {
Assert.assertEquals(ArrayKit.addAll(longTestArray, 5L,6L), longTestResult);
Assert.assertEquals(ArrayKit.addAll(shortTestArray, new Short("5"),new Short("6")), shortTestResult);
}
@Test
public void toList() throws Exception{
Integer array[] = {1,2,3};
ArrayList<Integer> result = new ArrayList<Integer>();
result.add(1);
result.add(2);
result.add(3);
Assert.assertEquals(ArrayKit.toList(array),result);
}
@Test
public void getLength() {
int[] a = new int[0];
int[] b = new int[2];
Assert.assertEquals(ArrayKit.getLength(a),0);
Assert.assertEquals(ArrayKit.getLength(null),0);
Assert.assertEquals(ArrayKit.getLength(b),2);
}
}

14
src/test/java/com/fanruan/api/util/CodeKitTest.java

@ -1,5 +1,6 @@
package com.fanruan.api.util;
import com.fr.stable.CodeUtils;
import com.fr.stable.CommonCodeUtils;
import org.junit.Assert;
import org.junit.Test;
@ -9,4 +10,17 @@ public class CodeKitTest {
public void passwordDecode(String passwordText) {
Assert.assertEquals(CodeKit.passwordDecode(passwordText), 123);
}
@Test
public void cjkDecode() {
String s = "中文 한글 日本語";
String encode = CodeUtils.cjkEncode(s);
try {
String decode = CodeKit.cjkDecode(encode);
Assert.assertTrue(s.equals(decode));
} catch (Exception e) {
}
}
}

3
src/test/java/com/fanruan/api/util/GeneralKitTest.java

@ -2,6 +2,8 @@ package com.fanruan.api.util;
import com.fanruan.api.Prepare;
import com.fr.general.GeneralUtils;
import com.fr.stable.AssistUtils;
import com.fr.stable.xml.XMLableReader;
import org.junit.Assert;
import org.junit.Test;
@ -52,4 +54,5 @@ public class GeneralKitTest extends Prepare {
public void getLocale() {
Assert.assertEquals(GeneralKit.getLocale(), Locale.CHINA);
}
}

21
src/test/java/com/fanruan/api/util/PaintKitTest.java

@ -0,0 +1,21 @@
package com.fanruan.api.util;
import com.fanruan.api.report.PaintKit;
import com.fr.base.Style;
import org.junit.Assert;
import org.junit.Test;
import java.awt.*;
import java.awt.image.BufferedImage;
public class PaintKitTest {
@Test
public void value2Image() {
BufferedImage bi = new BufferedImage(40, 50, BufferedImage.TYPE_BYTE_GRAY);
Style style = Style.getInstance();
Image image = PaintKit.value2Image(bi, 1, style, 30, 50);
Assert.assertEquals(30, image.getWidth(null));
Assert.assertEquals(50, image.getHeight(null));
}
}

38
src/test/java/com/fanruan/api/xml/XmlKitTest.java

@ -0,0 +1,38 @@
package com.fanruan.api.xml;
import com.fr.base.Parameter;
import com.fr.base.TableData;
import com.fr.plugin.db.json.core.JSONTableData;
import com.fr.stable.ParameterProvider;
import com.fr.stable.bridge.StableFactory;
import com.fr.stable.xml.StableXMLUtils;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLUtils;
import com.fr.stable.xml.XMLableReader;
import com.fr.third.javax.xml.stream.XMLStreamException;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.*;
public class XmlKitTest {
@Test
public void readParameter() {
try {
XMLableReader xml = XMLableReader.createXMLableReader("<!-- Edited by XMLSpy® -->\n" +
"<note>\n" +
"<Parameter>Tove</Parameter>\n" +
"<from>Jani</from>\n" +
"<heading>Reminder</heading>\n" +
"<body>Don't forget me this weekend!</body>\n" +
"</note>");
Parameter parameter = new Parameter("test", 1);
StableFactory.registerXMLDescription("Parameter",parameter);
Parameter p = (Parameter)XmlKit.readParameter(xml);
Assert.assertTrue(p.getName().equals("test"));
} catch (XMLStreamException e) {
e.printStackTrace();
}
}
}
Loading…
Cancel
Save