Browse Source

Merge branch 'master' of https://cloud.finedevelop.com/scm/tc/finekit

* 'master' of https://cloud.finedevelop.com/scm/tc/finekit: (30 commits)
  说明
  说明
  配置监听+错误的插件类
  更新更多的使用FineKit的插件列表
  自定义控件插件
  错误的import
  修改
  修改
  改动
  改动
  按要求增添修改
  一点小修改
  控件设计界面接口
  控件设计界面接口
  新增控件接口
  更新jar重载方法
  修改
  修改
  再次修改
  按要求修改
  ...

# Conflicts:
#	src/main/java/com/fanruan/api/conf/HolderKit.java
#	src/main/java/com/fanruan/api/util/CodeKit.java
#	src/main/java/com/fanruan/api/xml/XmlKit.java
pull/1/head
zjz1993 5 years ago
parent
commit
573c9b9ae7
  1. 2
      .gitignore
  2. 14
      readme.md
  3. 1
      src/main/java/com/fanruan/api/cal/ParameterKit.java
  4. 46
      src/main/java/com/fanruan/api/conf/ConfigurationKit.java
  5. 3
      src/main/java/com/fanruan/api/conf/HolderKit.java
  6. 1
      src/main/java/com/fanruan/api/data/TableDataKit.java
  7. 4
      src/main/java/com/fanruan/api/design/work/ReportletPane.java
  8. 75
      src/main/java/com/fanruan/api/design/work/form/creator/Attribute.java
  9. 80
      src/main/java/com/fanruan/api/design/work/form/creator/OpacityButton.java
  10. 50
      src/main/java/com/fanruan/api/design/work/form/creator/XFieldCreator.java
  11. 17
      src/main/java/com/fanruan/api/design/work/form/creator/XFieldEditor.java
  12. 114
      src/main/java/com/fanruan/api/design/work/form/creator/XOpenCreator.java
  13. 7
      src/main/java/com/fanruan/api/err/ValidationException.java
  14. 11
      src/main/java/com/fanruan/api/generic/Matcher.java
  15. 2
      src/main/java/com/fanruan/api/generic/Runner.java
  16. 6
      src/main/java/com/fanruan/api/net/NetworkKit.java
  17. 4
      src/main/java/com/fanruan/api/report/analy/data/NodeVisitor.java
  18. 31
      src/main/java/com/fanruan/api/report/form/BaseWidget.java
  19. 10
      src/main/java/com/fanruan/api/report/form/CustomWriteAbleRepeatEditor.java
  20. 64
      src/main/java/com/fanruan/api/report/form/category/TextWidget.java
  21. 78
      src/main/java/com/fanruan/api/report/form/describer/EditTextDescriber.java
  22. 51
      src/main/java/com/fanruan/api/report/form/describer/RepeatDescriber.java
  23. 83
      src/main/java/com/fanruan/api/report/form/describer/TextDescriber.java
  24. 32
      src/main/java/com/fanruan/api/report/form/value/InitializerKit.java
  25. 20
      src/main/java/com/fanruan/api/runtime/PluginKit.java
  26. 20
      src/main/java/com/fanruan/api/util/CodeKit.java
  27. 15
      src/main/java/com/fanruan/api/util/RenderKit.java
  28. 24
      src/main/java/com/fanruan/api/xml/XmlKit.java
  29. 13
      src/test/java/com/fanruan/api/plugin/PluginKitTest.java
  30. 27
      src/test/java/com/fanruan/api/util/CodeKitTest.java
  31. 14
      src/test/java/com/fanruan/api/util/RenderKitTest.java
  32. 30
      src/test/java/com/fanruan/api/xml/XmlKitTest.java

2
.gitignore vendored

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

14
readme.md

@ -47,13 +47,23 @@ SessionKit#getSession(@NotNull String sessionID);
|插件名|源码| |插件名|源码|
|-----|----| |-----|----|
|redis数据集插件|https://git.fanruan.com/fanruan/demo-tabledata-redis| |redis数据集插件|https://git.fanruan.com/fanruan/demo-tabledata-redis|
|增强公式编辑器插件|https://git.fanruan.com/fanruan/demo-formula-script |增强公式编辑器插件|https://git.fanruan.com/fanruan/demo-formula-script|
|条件属性之文本对齐插件|https://git.fanruan.com/fanruan/demo-highlight-align| |条件属性之文本对齐插件|https://git.fanruan.com/fanruan/demo-highlight-align|
|评分形态插件|https://git.fanruan.com/fanruan/demo-show-present| |评分形态插件|https://git.fanruan.com/fanruan/demo-show-present|
|急速下拉树插件|https://git.fanruan.com/fanruan/demo-widget-ztree|
|网页框插件|https://git.fanruan.com/fanruan/demo-widget-iframe|
## 如何判断插件中调用的API需要增加到FineKit中 ## 如何判断插件中调用的API需要增加到FineKit中
最简单的原则:除了JDK自带的类、插件接口(包括抽象类)、枚举、以及使用了@Open注解标记的类之外,是否还使用了com.fanruan.api(com.fr.third除外)之外的类,如果有则需要修改。 最简单的原则:
1、插件只使用了JDK自带的类、插件接口(包括抽象类)、枚举、以及使用了@Open注解标记的类;
2、插件只使用了包名前缀为com.fr.third的类;
3、插件只使用了包名前缀为com.fanruan.api之外的类;
如果违背了上述三个原则,则需要考虑将使用类加入FineKit中。
## 如何提交新的API ## 如何提交新的API

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

@ -135,5 +135,4 @@ public class ParameterKit {
return parameters; return parameters;
} }
} }

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

@ -1,5 +1,7 @@
package com.fanruan.api.conf; package com.fanruan.api.conf;
import com.fanruan.api.generic.Matcher;
import com.fanruan.api.generic.Runner;
import com.fr.config.Configuration; import com.fr.config.Configuration;
import com.fr.config.holder.ConfigChangeListener; import com.fr.config.holder.ConfigChangeListener;
import com.fr.transaction.Configurations; import com.fr.transaction.Configurations;
@ -9,33 +11,51 @@ import com.fr.transaction.WorkerFacade;
/** /**
* @author richie * @author richie
* @version 10.0 * @version 10.0
* Created by richie on 2019-08-30 * Created by richie on 2019-09-17
* 配置监听管理器 * 配置管理工具类
*/ */
public class ConfigurationKit { public class ConfigurationKit {
/** /**
* 注册监听配置变化的监听器 * 兼容配置缓存失效
* *
* @param listener 监听器 * @param matcher 匹配器
* @param runner 匹配后执行的动作
*/ */
public static void registerListener(ConfigChangeListener listener) { public static void listenCacheChange(final Matcher<Class<? extends Configuration>> matcher, final Runner runner) {
ValidateProxy.getInstance().getValidateManager().registerListener(listener); ValidateProxy.getInstance().getValidateManager().registerListener(new ConfigChangeListener() {
@Override
public boolean accept(Class<? extends Configuration> clazz) {
if (matcher == null) {
return true;
}
return matcher.match(clazz);
}
@Override
public void change() {
if (matcher != null) {
runner.run();
}
}
});
} }
/** /**
* 保存配置 * 在一个事务中修改配置
* *
* @param type 配置的类型 * @param configType 配置类
* @param action 保存动作 * @param runner 执行器
*/ */
public static void modify(Class<? extends Configuration> type, Runner action) { public static void modify(Class<? extends Configuration> configType, Runner runner) {
Configurations.modify(new WorkerFacade(type) { Configurations.modify(new WorkerFacade(configType) {
@Override @Override
public void run() { public void run() {
action.run(); if (runner != null) {
runner.run();
}
} }
}); });
} }
} }

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

@ -1,12 +1,13 @@
package com.fanruan.api.conf; 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.ObjConf;
import com.fanruan.api.conf.impl.ObjectColConf; import com.fanruan.api.conf.impl.ObjectColConf;
import com.fanruan.api.conf.impl.ObjectMapConf; import com.fanruan.api.conf.impl.ObjectMapConf;
import com.fanruan.api.conf.impl.SimConf; import com.fanruan.api.conf.impl.SimConf;
import com.fr.config.holder.Conf; import com.fr.config.holder.Conf;
import com.fr.config.holder.factory.Holders; import com.fr.config.holder.factory.Holders;
import com.fr.config.holder.impl.ColConf;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;

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) { public static void renameTableData(@NotNull String oldName, @NotNull String newName) {
TableDataConfig.getInstance().renameTableData(oldName, newName); TableDataConfig.getInstance().renameTableData(oldName, newName);
} }
} }

4
src/main/java/com/fanruan/api/design/work/ReportletPane.java

@ -0,0 +1,4 @@
package com.fanruan.api.design.work;
public class ReportletPane extends com.fr.design.gui.itree.filetree.ReportletPane {
}

75
src/main/java/com/fanruan/api/design/work/form/creator/Attribute.java

@ -0,0 +1,75 @@
package com.fanruan.api.design.work.form.creator;
import com.fanruan.api.log.LogKit;
import com.fr.design.designer.creator.CRPropertyDescriptor;
import java.beans.IntrospectionException;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-09-10
*/
public class Attribute {
private CRPropertyDescriptor descriptor;
public static Attribute newAttribute(String name, Class<?> beanClass) {
return new Attribute(name, beanClass);
}
public static Attribute newAttribute(String name, Class<?> beanClass, String readMethod, String writeMethod) {
return new Attribute(name, beanClass, readMethod, writeMethod);
}
private Attribute(String name, Class<?> beanClass) {
try {
descriptor = new CRPropertyDescriptor(name, beanClass);
} catch (IntrospectionException e) {
LogKit.error(e.getMessage(), e);
}
}
private Attribute(String name, Class<?> beanClass, String readMethod, String writeMethod) {
try {
descriptor = new CRPropertyDescriptor(name, beanClass, readMethod, writeMethod);
} catch (IntrospectionException e) {
LogKit.error(e.getMessage(), e);
}
}
public Attribute keyValue(String name, Object value) {
if (descriptor != null) {
descriptor.putKeyValue(name, value);
}
return this;
}
public Attribute i18n(String i18nName) {
if (descriptor != null) {
descriptor.setI18NName(i18nName);
}
return this;
}
public Attribute editorClass(Class<?> clazz) {
if (descriptor != null) {
descriptor.setEditorClass(clazz);
}
return this;
}
public Attribute rendererClass(Class<?> clazz) {
if (descriptor != null) {
descriptor.setRendererClass(clazz);
}
return this;
}
/**
* 这个属于内部调用的方法外部不应该调用
*/
protected CRPropertyDescriptor toPropertyDescriptor() {
return descriptor;
}
}

80
src/main/java/com/fanruan/api/design/work/form/creator/OpacityButton.java

@ -0,0 +1,80 @@
package com.fanruan.api.design.work.form.creator;
import com.fanruan.api.util.IOKit;
import javax.swing.*;
import java.awt.*;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-09-10
*/
public class OpacityButton extends JButton {
private static final float FULL_OPACITY = 1.0F;
private static final float HALF_OPACITY = 0.4F;
private String name;
private String imagePath;
private float opacity;
public OpacityButton(String name, String imagePath, float opacity) {
this.name = name;
this.imagePath = imagePath;
this.opacity = opacity;
this.draw();
}
private void draw() {
ImageIcon imageIcon = (ImageIcon) IOKit.readIcon(imagePath);
Image img = imageIcon.getImage();
MediaTracker mt = new MediaTracker(this);
int w = 21;
int h = 21;
mt.addImage(img, 0);
try {
mt.waitForAll();
} catch (InterruptedException ignore) {
return;
}
GraphicsConfiguration gc = new JFrame().getGraphicsConfiguration(); // 本地图形设备
Image image = gc.createCompatibleImage(w, h, Transparency.TRANSLUCENT);//建立透明画布
Graphics2D g = (Graphics2D) image.getGraphics(); //在画布上创建画笔
Composite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f); //指定透明度为半透明90%
g.setComposite(alpha);
g.drawImage(img, 0, 0, this); //注意是,将image画到g画笔所在的画布上
g.setColor(Color.black);//设置颜色为黑色
g.drawString(name, 25, 20);//写字
g.dispose(); //释放内存
Composite alpha2 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity);
Image image1 = gc.createCompatibleImage(w, h, Transparency.TRANSLUCENT);
g = (Graphics2D) image1.getGraphics();
g.setComposite(alpha2);
g.drawImage(img, 2, 2, this); //改变图像起始位置,产生动态效果
g.setColor(Color.black);
g.drawString(name, 25, 20);
g.dispose();
this.setIgnoreRepaint(true);
this.setFocusable(false);//设置没有焦点
this.setBorder(null);//设置不画按钮边框
this.setContentAreaFilled(false);//设置不画按钮背景
this.setIcon(new ImageIcon(image1)); //把刚才生成的半透明image变成ImageIcon,贴到按钮上去
this.setRolloverIcon(new ImageIcon(image1));
this.setPressedIcon(new ImageIcon(image));//按下去的图标
}
/**
* 更改组件的可见性
*
* @param visible 设置为true表示可见设置为false表示不可见
*/
public void makeVisible(boolean visible) {
this.opacity = visible ? FULL_OPACITY : HALF_OPACITY;
this.draw();
}
}

50
src/main/java/com/fanruan/api/design/work/form/creator/XFieldCreator.java

@ -0,0 +1,50 @@
package com.fanruan.api.design.work.form.creator;
import com.fanruan.api.design.DesignKit;
import com.fr.design.form.util.XCreatorConstants;
import com.fr.design.mainframe.widget.editors.InChangeBooleanEditor;
import com.fr.form.ui.Widget;
import com.fr.form.ui.concept.Blankable;
import java.awt.*;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-09-10
* 控件的UI展示和设计类
*/
public abstract class XFieldCreator extends XOpenCreator {
public XFieldCreator(Widget fieldEditor, Dimension dimension) {
super(fieldEditor, dimension);
}
@Override
public Attribute[] attributes() {
Attribute allowBlank = Attribute.newAttribute("allowBlank", this.data.getClass()).i18n(
DesignKit.i18nText("Fine-Design_Form_Allow_Blank"))
.editorClass(InChangeBooleanEditor.class).keyValue(
XCreatorConstants.PROPERTY_VALIDATE, "Fine-Design_Basic_Validate");
Attribute blankErrorMsg = Attribute.newAttribute("errorMessage", this.data.getClass()).i18n(
DesignKit.i18nText("Fine-Design_Report_Engine_Verify_Message"))
.keyValue(XCreatorConstants.PROPERTY_VALIDATE, "Fine-Design_Basic_Validate");
Attribute fontSize = Attribute.newAttribute("fontSize", this.data.getClass(), "getFontSize", "setFontSize")
.i18n(DesignKit.i18nText("Fine-Design_Form_Font_Size"))
.keyValue(XCreatorConstants.PROPERTY_CATEGORY, "Fine-Design_Report_Advanced");
Widget widget = toData();
// 控件类型允许值为空,但是设置了不允许为空,就要设置为空时的提示信息
if (widget instanceof Blankable && !((Blankable) widget).isAllowBlank()) {
return new Attribute[]{
allowBlank, blankErrorMsg, fontSize
};
}
return new Attribute[]{
allowBlank, fontSize
};
}
}

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

@ -1,17 +0,0 @@
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);
}
}

114
src/main/java/com/fanruan/api/design/work/form/creator/XOpenCreator.java

@ -0,0 +1,114 @@
package com.fanruan.api.design.work.form.creator;
import com.fanruan.api.design.DesignKit;
import com.fanruan.api.design.work.form.macro.XCreatorConstants;
import com.fanruan.api.util.ArrayKit;
import com.fr.design.designer.creator.CRPropertyDescriptor;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XWidgetCreator;
import com.fr.design.mainframe.FormDesigner;
import com.fr.form.ui.Widget;
import com.fr.stable.core.PropertyChangeAdapter;
import javax.swing.*;
import java.awt.*;
import java.beans.IntrospectionException;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-09-10
*/
public abstract class XOpenCreator extends XWidgetCreator {
public XOpenCreator(Widget widget, Dimension size) {
super(widget, size);
}
final public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException {
CRPropertyDescriptor[] basic = new CRPropertyDescriptor[]{
new CRPropertyDescriptor("widgetName", this.data.getClass()).setI18NName(DesignKit.i18nText("Fine-Design_Form_Form_Widget_Name")),
new CRPropertyDescriptor("enabled", this.data.getClass()).setI18NName(DesignKit.i18nText("Fine-Design_Report_Enabled"))
.setPropertyChangeListener(new PropertyChangeAdapter() {
@Override
public void propertyChange() {
setEnabled(toData().isEnabled());
}
}),
new CRPropertyDescriptor("visible", this.data.getClass()).setI18NName(
DesignKit.i18nText("Fine-Design_Form_Widget_Visible")).setPropertyChangeListener(new PropertyChangeAdapter() {
@Override
public void propertyChange() {
makeVisible(toData().isVisible());
}
}),
new CRPropertyDescriptor("labelName", this.data.getClass(), "getLabelName", "setLabelName")
.setI18NName(DesignKit.i18nText("Fine-Design_Form_Label_Name"))
.putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Fine-Design_Basic_Advanced")
};
Attribute[] attributes = attributes();
CRPropertyDescriptor[] current = new CRPropertyDescriptor[attributes.length];
for (int i = 0, len = attributes.length; i < len; i++) {
current[i] = attributes[i].toPropertyDescriptor();
}
return ArrayKit.addAll(basic, current);
}
/**
* 控件支持的属性以及操作设置这些属性的方法使用反射调用属性的设置方法
* 示例如果不显示的传入读取和写入方法则默认调用"get+属性名"或者"set+属性名"的方法
*
* @return 控件支持的属性以及操作设置这些属性的方法集合
*/
public abstract Attribute[] attributes();
/**
* 待说明
*
* @return 待说明
*/
public Widget toData() {
return this.data;
}
/**
* 根据Widget的属性值初始化XCreator的属性值
*/
@Override
protected void initXCreatorProperties() {
this.setEnabled(toData().isEnabled());
}
/**
* 待说明
*/
public void recalculateChildrenSize() {
}
protected void makeVisible(boolean visible) {
}
public void paint(Graphics g) {
AlphaComposite composite = this.data.isVisible() ? (AlphaComposite) ((Graphics2D) g).getComposite() : AlphaComposite.getInstance(AlphaComposite.SRC_OVER, HALF_OPACITY);
((Graphics2D) g).setComposite(composite);
super.paint(g);
}
/**
* 重命名
*
* @param designer 表单设计器
* @param creator 当前组件
*/
public void ChangeCreatorName(FormDesigner designer, XCreator creator) {
String oldName = creator.toData().getWidgetName();
String value = JOptionPane.showInputDialog(designer, DesignKit.i18nText("Fine-Design_Form_Change_Widget_Name_Discription"), oldName);
if (value != null) {
designer.renameCreator(creator, value);
}
}
}

7
src/main/java/com/fanruan/api/err/ValidationException.java

@ -0,0 +1,7 @@
package com.fanruan.api.err;
/**
* 验证异常
*/
public class ValidationException extends com.fr.design.Exception.ValidationException {
}

11
src/main/java/com/fanruan/api/generic/Matcher.java

@ -0,0 +1,11 @@
package com.fanruan.api.generic;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-09-17
*/
public interface Matcher<T> {
boolean match(T t);
}

2
src/main/java/com/fanruan/api/conf/Runner.java → src/main/java/com/fanruan/api/generic/Runner.java

@ -1,4 +1,4 @@
package com.fanruan.api.conf; package com.fanruan.api.generic;
/** /**
* @author richie * @author richie

6
src/main/java/com/fanruan/api/net/NetworkKit.java

@ -1,5 +1,6 @@
package com.fanruan.api.net; package com.fanruan.api.net;
import com.fr.base.ServerConfig;
import com.fr.data.NetworkHelper; import com.fr.data.NetworkHelper;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -117,4 +118,9 @@ public class NetworkKit {
public static @Nullable String getHTTPRequestParameter(HttpServletRequest req, String... paraNames) { public static @Nullable String getHTTPRequestParameter(HttpServletRequest req, String... paraNames) {
return NetworkHelper.getHTTPRequestParameter(req, paraNames); return NetworkHelper.getHTTPRequestParameter(req, paraNames);
} }
public static String createServletURL(HttpServletRequest req) {
return NetworkHelper.createServletURL(req, ServerConfig.getInstance().getServletName());
}
} }

4
src/main/java/com/fanruan/api/report/analy/data/NodeVisitor.java

@ -0,0 +1,4 @@
package com.fanruan.api.report.analy.data;
public abstract class NodeVisitor extends com.fr.stable.core.NodeVisitor {
}

31
src/main/java/com/fanruan/api/report/form/BaseWidget.java

@ -0,0 +1,31 @@
package com.fanruan.api.report.form;
import com.fr.data.act.Describer;
import com.fr.data.act.Producer;
import com.fr.form.ui.Widget;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.script.Calculator;
import com.fr.stable.core.NodeVisitor;
import com.fr.stable.web.Repository;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-09-10
* 控件的插件接口
*/
public abstract class BaseWidget extends Widget implements Describer, Producer {
@Override
public boolean isEditor() {
return false;
}
@Override
public JSONObject createJSONConfig(Repository repository, Calculator calculator, NodeVisitor nodeVisitor) throws JSONException {
JSONObject jo = super.createJSONConfig(repository, calculator, nodeVisitor);
mixinJSON(repository, calculator, jo);
return jo;
}
}

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

@ -1,10 +0,0 @@
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 {
}

64
src/main/java/com/fanruan/api/report/form/category/TextWidget.java

@ -0,0 +1,64 @@
package com.fanruan.api.report.form.category;
import com.fanruan.api.report.form.BaseWidget;
import com.fanruan.api.report.form.describer.TextDescriber;
import com.fanruan.api.util.ArrayKit;
import com.fanruan.api.xml.XmlKit;
import com.fr.stable.script.CalculatorProvider;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-09-10
*/
public abstract class TextWidget extends BaseWidget {
private TextDescriber textDescriber;
/**
* 获取联动参数
*
* @param c 当前算子
* @return 放回当前控件依赖的参数
*/
public String[] dependence(CalculatorProvider c) {
return ArrayKit.EMPTY_STRING_ARRAY;
}
/**
* 获取支持的事件
*
* @return 当前控件支持的事件
*/
public String[] supportedEvents() {
return new String[]{AFTERINIT, BEFOREEDIT, AFTEREDIT, STOPEDIT};
}
@Override
public void readXML(XMLableReader reader) {
if (reader.isChildNode()) {
String tagName = reader.getTagName();
if (TextDescriber.XML_TAG.equals(tagName)) {
textDescriber = (TextDescriber) XmlKit.readXMLable(reader);
}
}
}
@Override
public void writeXML(XMLPrintWriter writer) {
if (textDescriber != null) {
XmlKit.writeXMLable(writer, textDescriber, TextDescriber.XML_TAG);
}
}
@Override
public Object clone() throws CloneNotSupportedException {
TextWidget cloned = (TextWidget) super.clone();
if (textDescriber != null) {
cloned.textDescriber = (TextDescriber) textDescriber.clone();
}
return cloned;
}
}

78
src/main/java/com/fanruan/api/report/form/describer/EditTextDescriber.java

@ -0,0 +1,78 @@
package com.fanruan.api.report.form.describer;
import com.fanruan.api.cal.FormulaKit;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.GeneralKit;
import com.fanruan.api.util.StringKit;
import com.fr.data.act.Describer;
import com.fr.json.JSONObject;
import com.fr.stable.script.CalculatorProvider;
import com.fr.stable.web.Repository;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLable;
import com.fr.stable.xml.XMLableReader;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-09-10
*/
public class EditTextDescriber implements Describer, XMLable {
public static final String XML_TAG = "EditTextDescriber";
private boolean directEdit = true;
private String waterMark;
public EditTextDescriber() {
}
public boolean isDirectEdit() {
return this.directEdit;
}
public void setDirectEdit(boolean directEdit) {
this.directEdit = directEdit;
}
public void setWaterMark(String waterMark) {
this.waterMark = waterMark;
}
public String getWaterMark() {
return waterMark;
}
@Override
public void mixinJSON(Repository repo, CalculatorProvider c, JSONObject jo) {
jo.put("directEdit", directEdit);
if (StringKit.isNotBlank(waterMark)) {
if (FormulaKit.canBeFormula(waterMark)) {
try {
jo.put("watermark", GeneralKit.objectToString(FormulaKit.newFormula(waterMark).eval(c)));
} catch (Exception e) {
LogKit.error(e.getMessage(), e);
}
} else {
jo.put("watermark", waterMark);
}
}
}
@Override
public void readXML(XMLableReader xmLableReader) {
}
@Override
public void writeXML(XMLPrintWriter xmlPrintWriter) {
}
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}

51
src/main/java/com/fanruan/api/report/form/describer/RepeatDescriber.java

@ -0,0 +1,51 @@
package com.fanruan.api.report.form.describer;
import com.fr.data.act.Describer;
import com.fr.json.JSONObject;
import com.fr.stable.script.CalculatorProvider;
import com.fr.stable.web.Repository;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLable;
import com.fr.stable.xml.XMLableReader;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-09-10
*/
public class RepeatDescriber implements Describer, XMLable {
public static final String XML_TAG = "RepeatDescriber";
private boolean removeRepeat = true;
public boolean isRemoveRepeat() {
return this.removeRepeat;
}
public void setRemoveRepeat(boolean removeRepeat) {
this.removeRepeat = removeRepeat;
}
@Override
public void mixinJSON(Repository repo, CalculatorProvider c, JSONObject jo) {
if (removeRepeat) {
jo.put("norepeat", true);
}
}
@Override
public void readXML(XMLableReader xmLableReader) {
}
@Override
public void writeXML(XMLPrintWriter xmlPrintWriter) {
}
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}

83
src/main/java/com/fanruan/api/report/form/describer/TextDescriber.java

@ -0,0 +1,83 @@
package com.fanruan.api.report.form.describer;
import com.fanruan.api.util.StringKit;
import com.fr.data.act.Describer;
import com.fr.json.JSONObject;
import com.fr.stable.StringUtils;
import com.fr.stable.script.CalculatorProvider;
import com.fr.stable.web.Repository;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLable;
import com.fr.stable.xml.XMLableReader;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-09-10
*/
public class TextDescriber implements Describer, XMLable {
public static final String XML_TAG = "TextDescriber";
private boolean allowBlank = true;
private String errorMessage;
private int fontSize = 12;
public TextDescriber() {
}
public TextDescriber(boolean allowBlank) {
this.allowBlank = allowBlank;
}
public boolean isAllowBlank() {
return this.allowBlank;
}
public void setAllowBlank(boolean allowBlank) {
this.allowBlank = allowBlank;
}
public int getFontSize() {
return this.fontSize;
}
public void setFontSize(int size) {
this.fontSize = size;
}
public String getErrorMessage() {
return errorMessage == null ? StringUtils.EMPTY : errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
@Override
public void readXML(XMLableReader xmLableReader) {
}
@Override
public void writeXML(XMLPrintWriter xmlPrintWriter) {
}
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
@Override
public void mixinJSON(Repository repo, CalculatorProvider c, JSONObject jo) {
if (!allowBlank) {
jo.put("allowBlank", true);
}
if (StringKit.isNotEmpty(errorMessage)) {
jo.put("errorMessage", errorMessage);
}
jo.put("fontSize", this.fontSize);
}
}

32
src/main/java/com/fanruan/api/report/form/value/InitializerKit.java

@ -0,0 +1,32 @@
package com.fanruan.api.report.form.value;
import com.fr.form.ui.WidgetValue;
import com.fr.form.ui.concept.data.ValueInitializer;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/9/17
* 初始化工具类
*/
public class InitializerKit {
/**
* 初始化化一个控件值对象
*
* @return 控件值
*/
public static ValueInitializer newValue() {
return new WidgetValue();
}
/**
* 初始化一个控件值对象
*
* @param value 控件值的值
* @return 控件值
*/
public static ValueInitializer newValue(Object value) {
return new WidgetValue(value);
}
}

20
src/main/java/com/fanruan/api/runtime/PluginKit.java

@ -1,20 +0,0 @@
package com.fanruan.api.runtime;
import com.fr.plugin.context.PluginContexts;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-30
* 插件相关的工具类
*/
public class PluginKit {
/**
* 当前插件是否可用例如插件授权文件过期时该犯法会返回false
* @return 插件可用则返回true不可用则返回false
*/
public static boolean isCurrentPluginAvailable() {
return PluginContexts.currentContext().isAvailable();
}
}

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

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

15
src/main/java/com/fanruan/api/util/RenderKit.java

@ -1,7 +1,10 @@
package com.fanruan.api.util; package com.fanruan.api.util;
import com.fr.base.TemplateUtils; import com.fr.base.TemplateUtils;
import com.fr.script.Calculator;
import com.fr.stable.script.CalculatorProvider;
import java.util.Collections;
import java.util.Map; import java.util.Map;
/** /**
@ -19,4 +22,16 @@ public class RenderKit {
public static String renderParameter4Tpl(String text, Map<String, Object> map) throws Exception { public static String renderParameter4Tpl(String text, Map<String, Object> map) throws Exception {
return TemplateUtils.renderParameter4Tpl(text, map); return TemplateUtils.renderParameter4Tpl(text, map);
} }
/**
* 根据参数, 来计算文档字符串
* @param s 待渲染的文本模板
* @param c 参数集合
* @return 返回渲染后的文本
* @throws Exception 渲染过程中出现错误则抛出此异常
*/
public static String render(String s, Calculator c) throws Exception {
return TemplateUtils.render(s, c);
}
} }

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

@ -3,12 +3,14 @@ package com.fanruan.api.xml;
import com.fr.data.core.DataCoreXmlUtils; import com.fr.data.core.DataCoreXmlUtils;
import com.fr.data.impl.Connection; import com.fr.data.impl.Connection;
import com.fr.general.xml.GeneralXMLTools; 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.XMLReadable;
import com.fr.stable.xml.XMLTools; import com.fr.stable.xml.XMLTools;
import com.fr.stable.xml.XMLable; import com.fr.stable.xml.XMLable;
import com.fr.stable.xml.XMLableReader; import com.fr.stable.xml.XMLableReader;
import com.fr.stable.xml.XMLWriter; import com.fr.stable.xml.XMLWriter;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.StableXMLUtils;
import java.io.InputStream; import java.io.InputStream;
@ -60,6 +62,7 @@ public class XmlKit {
/** /**
* 从xml中读取数据连接对象 * 从xml中读取数据连接对象
*
* @param reader xml读取器 * @param reader xml读取器
* @return 数据连接对象 * @return 数据连接对象
*/ */
@ -81,7 +84,24 @@ public class XmlKit {
* @param xmlable xml文件 * @param xmlable xml文件
* @return 返回字符串 * @return 返回字符串
* */ * */
public static String writeXMLableAsString(XMLWriter xmlable){ public static String writeXMLableAsString(XMLWriter xmlable) {
return GeneralXMLTools.writeXMLableAsString(xmlable); return GeneralXMLTools.writeXMLableAsString(xmlable);
} }
/**
* 读出xml参数
*
* @param reader xml读出对象
* @return 返回保存参数数组
*/
public static ParameterProvider readParameter(XMLableReader reader) {
return StableXMLUtils.readParameter(reader);
}
/**
* 读出xml参数
* @param writer xml读出对象
*/
public static void writeParameters(XMLPrintWriter writer, ParameterProvider[] parameter) {
StableXMLUtils.writeParameters(writer,parameter);
}
} }

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

@ -1,13 +0,0 @@
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());
}
}

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

@ -1,5 +1,6 @@
package com.fanruan.api.util; package com.fanruan.api.util;
import com.fr.stable.CodeUtils;
import com.fr.stable.CommonCodeUtils; import com.fr.stable.CommonCodeUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -9,4 +10,30 @@ public class CodeKitTest {
public void javascriptEncode() { public void javascriptEncode() {
Assert.assertEquals(CodeKit.javascriptEncode("console.log(123)"), "console.log(123)"); Assert.assertEquals(CodeKit.javascriptEncode("console.log(123)"), "console.log(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) {
}
}
@Test
public void encodeURIComponent() {
String s = "123";
String encode = CodeUtils.encodeURIComponent(s);
try {
String decode = CodeKit.encodeURIComponent(encode);
Assert.assertTrue(s.equals(decode));
} catch (Exception e) {
}
}
} }

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

@ -1,13 +1,12 @@
package com.fanruan.api.util; package com.fanruan.api.util;
import com.fanruan.api.Prepare; import com.fanruan.api.Prepare;
import com.fr.script.Calculator;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static org.junit.Assert.*;
/** /**
* @author richie * @author richie
@ -25,4 +24,15 @@ public class RenderKitTest extends Prepare {
String text = "${name} is ${age} years old, he earned ${salary} dollars per month."; String text = "${name} is ${age} years old, he earned ${salary} dollars per month.";
Assert.assertEquals("Alex is 20 years old, he earned 100 dollars per month.", RenderKit.renderParameter4Tpl(text, map)); Assert.assertEquals("Alex is 20 years old, he earned 100 dollars per month.", RenderKit.renderParameter4Tpl(text, map));
} }
@Test
public void render() throws Exception{
Calculator c = Calculator.createCalculator();
Map<String, Object> map = new HashMap<>();
map.put("p1",1);
map.put("p2",2);
String s = "abc${p1}xyz${p2}";
Assert.assertEquals("abcxyz", RenderKit.render(s,c));
}
} }

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

@ -0,0 +1,30 @@
package com.fanruan.api.xml;
import com.fr.base.Parameter;
import com.fr.stable.bridge.StableFactory;
import com.fr.stable.xml.XMLableReader;
import com.fr.third.javax.xml.stream.XMLStreamException;
import org.junit.Assert;
import org.junit.Test;
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