Skip to content

Commit ee53995

Browse files
author
Ray
committed
Obejct operations component - EasyCommons
New version EasyMonitor 1.4.2 release. Obejct 对象操作组件(对象属性抽取,对象属性置空,对象内容过滤;支持 `FieldExpression`) - EasyCommons Obejct operations component(Object property extract, Object property set null, Object content filter; support `FieldExpression`)
1 parent 7b5ef21 commit ee53995

7 files changed

+379
-17
lines changed

.gitattributes

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1 @@
1-
# Auto detect text files and perform LF normalization
2-
* text=auto
3-
4-
# Custom for Visual Studio
5-
*.cs diff=csharp
6-
7-
# Standard to msysgit
8-
*.doc diff=astextplain
9-
*.DOC diff=astextplain
10-
*.docx diff=astextplain
11-
*.DOCX diff=astextplain
12-
*.dot diff=astextplain
13-
*.DOT diff=astextplain
14-
*.pdf diff=astextplain
15-
*.PDF diff=astextplain
16-
*.rtf diff=astextplain
17-
*.RTF diff=astextplain
1+
* linguist-language=Java

doc/API-en.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# EasyCommons-EasyObjectUtils
2+
3+
---------------
4+
EasyImageUtils is [EasyCommons](https://github.com/ushelp/EasyCommons "EasyCommons") project group image processing component.
5+
6+
7+
EasyObjectUtils is EasyCommons project group Obejct operations component.
8+
9+
## 1. EasyObject FieldExpression language
10+
11+
EasyObjectUtils the tools used to **EasyObject FieldExpression (field expression) language** for property positioning when you operate object.
12+
13+
**Syntax:**
14+
```
15+
Specified attributes: property
16+
Specify the attribute that: property.property
17+
Each object in the specified collection: {collection}
18+
Each object in the specified array: [array] Attribute specifies for each object in the collection: {collection} .property
19+
Attribute specifies for each object in the array: [array] .property
20+
21+
Alias definitions (only for EasyObjectExtract): FieldExpression#Alias
22+
```
23+
24+
## 2. API
25+
EasyObjectUtils It includes the following components:
26+
27+
1. **EasyObjectExtract**:Extraction of the object. Using field expression from the object (`FieldExpression`) to extract the specified property deposited **key-value** Map collection.
28+
**Scene**: JSON output, specify the output attributes and values extracted from the object.
29+
```JAVA
30+
/**
31+
* Two ways to modify the properties file (instead of store method):
32+
* - Merge: The Properties object into the specified file (add, change, delete)
33+
* - Modify: Modify the Properties object to the specified file (add, change, delete the original file does not include having a parameter)
34+
*
35+
*@param object the object data to be extracted
36+
*@param collection object data set to be extracted
37+
*@param array array object data to be extracted
38+
*@param fieldExpressionAndOutNameMap Map list field expression and output alias, optional default field expression name as the output name
39+
*@param fieldExpressions A list of the fields to be extracted expression, variable parameters, is case-sensitive; support hash character alias definition
40+
*@return Map collection extracted results
41+
*/
42+
Map extract(object [, fieldExpressionAndOutNameMap], fieldExpressions)
43+
List<Map> extract(collection [, fieldExpressionAndOutNameMap], fieldExpressions)
44+
List<Map> extract(array [, fieldExpressionAndOutNameMap], fieldExpressions)
45+
```
46+
** Example:**
47+
```JAVA
48+
List<Map> list = EasyObjectExtract.extract(getData(),
49+
"userId", "name", "status", "{sysRoles}.name#roleNames",
50+
"{sysRoles}.roleId#roleIds");
51+
```
52+
53+
2. **EasyObjectFilter**:Object filtering. The JavaBean object properties of special characters (<,>, ...) to filter out, into the escape character; or custom character transformation maps.
54+
**Scene** : the special character JavaBean object properties contains a string to filter into character entity; or a character string property objects included replacing all the specified character. For example, the data in the file upload Struts2 package submitted to the object, a special string to the user object may contain submitted escaped.
55+
```JAVA
56+
/**
57+
* Special character filtering object attribute contains the string, the default Replace <,> is the character entity & lt ;, & gt
58+
*
59+
*@param object Object to filter content
60+
*@param collection set of objects you want to filter content
61+
*@param array object array to filter content
62+
*@param specialCharacterMap Filter mapping listparam specialCharacterMap custom (key for the character you want to filter, value character filtered)
63+
*@param DoNotFieldArray does not filter the array of field names
64+
*/
65+
filter(object [, specialCharacterMap] [, doNotFieldArray]);
66+
filter(collection [, specialCharacterMap] [, doNotFieldArray]);
67+
filter(array [, specialCharacterMap] [, doNotFieldArray]);
68+
```
69+
70+
**Example:**
71+
```JAVA
72+
Map replaceMap=new HashMap();
73+
replaceMap.put("drug","*");
74+
replaceMap.put("fuck","F***");
75+
EasyObjectExtract.filter(news,replaceMap);
76+
```
77+
78+
3. **EasyObjectSetNull**:Object Properties empty. Using field expressions (`FieldExpression`) specified property set to null object.
79+
**Scene** : Hibernate object loaded some delay attribute set can not be loaded is empty, to prevent abnormal when no session serialized property.
80+
```JAVA
81+
/**
82+
* The field is set to the value specified for the null FieldExpression
83+
*
84+
*@param Object setNUll of the object to be over
85+
*@param Collection of objects you want to lead a collection of objects setNUll
86+
*@param Array array object to object to lead setNUll
87+
* Expression array list fieldExpressions segmentparam, uncertain parameters
88+
*/
89+
setNull(Object, fieldExpressions)
90+
setNull(Collection, fieldExpressions)
91+
setNull(Object[], fieldExpressions)
92+
```
93+
**Example:**
94+
```JAVA
95+
EasyObjectSetNull.setNull(users, "password","{roles}.rights");
96+
```
97+
98+
## 3. Maven
99+
```XML
100+
<!-- EasyObjectUtils -->
101+
<dependency>
102+
<groupId>cn.easyproject</groupId>
103+
<artifactId>easycommons-object</artifactId>
104+
<version>1.7.4-RELEASE</version>
105+
</dependency>
106+
```
107+
108+
109+
## End
110+
111+
[Comments](http://www.easyproject.cn/easycommons/en/index.jsp#about 'Comments')
112+
113+
If you have more comments, suggestions or ideas, please contact me.
114+
115+
116+
117+
[http://www.easyproject.cn](http://www.easyproject.cn "EasyProject Home")
118+
119+
120+
121+
[http://www.easyproject.cn](http://www.easyproject.cn "EasyProject Home")

doc/API-zh.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# EasyCommons-EasyObjectUtils
2+
3+
---------------
4+
EasyObjectUtils 是 [EasyCommons](https://github.com/ushelp/EasyCommons "EasyCommons") 项目组下的对象操作组件。
5+
6+
## 1. EasyObject FieldExpression(字段表达式)
7+
8+
EasyObjectUtils的 工具类中在操作对象时使用到了**EasyObject FieldExpression(字段表达式)语言**来进行属性定位。
9+
10+
语法:
11+
```
12+
指定属性: property
13+
指定属性的属性:property.property
14+
指定集合中每一个对象: {collection}
15+
指定数组中每一个对象: [array]
16+
指定集合中每一个对象的属性:{collection}.property
17+
指定数组中每一个对象的属性:[array].property
18+
19+
别名定义(仅适用于EasyObjectExtract):FieldExpression#Alias
20+
```
21+
22+
## 2. API 简介
23+
EasyObjectUtils 包括如下组件:
24+
25+
1. **EasyObjectExtract**:对象抽取。 从对象中使用字段表达式(`FieldExpression`)抽取指定属性以 **key-value** 存入Map集合。
26+
**适合场景**:JSON输出时,从对象中抽取指定输出属性和值。
27+
```JAVA
28+
/**
29+
* 两种properties文件修改方式(代替store方法):
30+
* - merge:将Properties对象合并到指定文件(增,改,删)
31+
* - modify:将Properties对象修改到指定文件(增,改,不包括删除原文件中具有的参数)
32+
*
33+
* @param object 要抽取数据的对象
34+
* @param collection 要抽取数据的对象集合
35+
* @param array 要抽取数据的对象数组
36+
* @param fieldExpressionAndOutNameMap 字段表达式和输出别名的映射列表,可选,默认字段表达式名作为输出名
37+
* @param fieldExpressions 要抽取的字段表达式列表,不定参,区分大小写;支持#号分隔的别名定义
38+
* @return 抽取的Map集合结果
39+
*/
40+
Map extract(object [, fieldExpressionAndOutNameMap], fieldExpressions)
41+
List<Map> extract(collection [, fieldExpressionAndOutNameMap], fieldExpressions)
42+
List<Map> extract(array [, fieldExpressionAndOutNameMap], fieldExpressions)
43+
```
44+
45+
**demo:**
46+
```JAVA
47+
List<Map> list = EasyObjectExtract.extract(getData(),
48+
"userId", "name", "status", "{sysRoles}.name#roleNames",
49+
"{sysRoles}.roleId#roleIds");
50+
```
51+
52+
2. **EasyObjectFilter**:对象过滤。将JavaBean对象属性中的特殊字符(<,>,...)全部过滤掉,转为转义符;或者自定义字符转换映射。
53+
**适合场景**:将JavaBean对象属性中的字符串包含的特殊字符进行过滤转换为字符实体;或将对象字符串属性中包含的字符全部替换为指定字符。例如,在Struts2中文件上传时提交的数据封装到对象后,对对象中可能包含的用户提交的的特殊字符串的进行转义。
54+
```JAVA
55+
/**
56+
* 过滤对象中字符串属性中包含的特殊字符,默认替换<, >为字符实体&lt;, &gt
57+
*
58+
* @param object 要过滤内容的对象
59+
* @param collection 要过滤内容的对象集合
60+
* @param array 要过滤内容的对象数组
61+
* @param specialCharacterMap 自定义的过滤映射列表(key为要过滤的字符,value为过滤后的字符)
62+
* @param doNotFieldArray 不进行过滤的字段名数组
63+
*/
64+
filter(object [, specialCharacterMap] [, doNotFieldArray]);
65+
filter(collection [, specialCharacterMap] [, doNotFieldArray]);
66+
filter(array [, specialCharacterMap] [, doNotFieldArray]);
67+
```
68+
**demo:**
69+
```JAVA
70+
Map replaceMap=new HashMap();
71+
replaceMap.put("drug","*");
72+
replaceMap.put("fuck","F***");
73+
EasyObjectExtract.filter(news,replaceMap);
74+
```
75+
76+
3. **EasyObjectSetNull**:对象属性置空。使用字段表达式(`FieldExpression`)将对象中指定属性设置为null。
77+
**适合场景**:将Hibernate加载的对象中有些延迟无法加载的属性设置为空 ,防止在序列化属性时出现no session异常。
78+
```JAVA
79+
/**
80+
* 将FieldExpression指定的字段值设置为null
81+
*
82+
* @param object 要过setNUll的对象
83+
* @param collection 要要过setNUll的对象的对象集合
84+
* @param array 要要过setNUll的对象的对象数组
85+
* @param fieldExpressions 段表达式数组列表,不定参
86+
*/
87+
setNull(Object, fieldExpressions)
88+
setNull(Collection, fieldExpressions)
89+
setNull(Object[], fieldExpressions)
90+
```
91+
**demo:**
92+
```JAVA
93+
EasyObjectSetNull.setNull(users, "password","{roles}.rights");
94+
```
95+
96+
## 3. Maven
97+
```XML
98+
<!-- EasyObjectUtils -->
99+
<dependency>
100+
<groupId>cn.easyproject</groupId>
101+
<artifactId>easycommons-object</artifactId>
102+
<version>1.7.4-RELEASE</version>
103+
</dependency>
104+
```
105+
106+
## 结束
107+
108+
[留言评论](http://www.easyproject.cn/easycommons/zh-cn/index.jsp#about '留言评论')
109+
110+
如果您有更好意见,建议或想法,请联系我。
111+
112+
113+
联系、反馈、定制、培训 Email:<[email protected]>
114+
115+
<p>
116+
<strong>支付宝钱包扫一扫捐助:</strong>
117+
</p>
118+
<p>
119+
120+
<img alt="支付宝钱包扫一扫捐助" src="http://www.easyproject.cn/images/s.png" title="支付宝钱包扫一扫捐助" height="256" width="256"></img>
121+
122+
123+
[http://www.easyproject.cn](http://www.easyproject.cn "EasyProject Home")
Binary file not shown.
Binary file not shown.
11 KB
Binary file not shown.

0 commit comments

Comments
 (0)