Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
add AbstractJsonValueProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
venusdrogon committed Jun 25, 2016
1 parent 5c0f409 commit 4e08615
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 85 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2008 feilong
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.feilong.tools.jsonlib.processor;

import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonValueProcessor;

/**
* The Class AbstractJsonValueProcessor.
*
* @author <a href="http://feitianbenyue.iteye.com/">feilong</a>
* @since 1.7.3
*/
abstract class AbstractJsonValueProcessor implements JsonValueProcessor{

/*
* (non-Javadoc)
*
* @see net.sf.json.processors.JsonValueProcessor#processArrayValue(java.lang.Object, net.sf.json.JsonConfig)
*/
@Override
public Object processArrayValue(Object value,JsonConfig jsonConfig){
return processValue(value, jsonConfig);
}

/*
* (non-Javadoc)
*
* @see net.sf.json.processors.JsonValueProcessor#processObjectValue(java.lang.String, java.lang.Object, net.sf.json.JsonConfig)
*/
@Override
public Object processObjectValue(String key,Object value,JsonConfig jsonConfig){
return processValue(value, jsonConfig);
}

/**
* Process value.
*
* @param value
* the value
* @param jsonConfig
* the json config
* @return the object
*/
protected abstract Object processValue(Object value,JsonConfig jsonConfig);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
import com.feilong.core.lang.NumberUtil;

import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonValueProcessor;

/**
* The Class BigDecimalJsonValueProcessor.
*
* @author <a href="http://feitianbenyue.iteye.com/">feilong</a>
* @since 1.2.2
*/
public class BigDecimalJsonValueProcessor implements JsonValueProcessor{
public class BigDecimalJsonValueProcessor extends AbstractJsonValueProcessor{

/**
* The number pattern.
Expand All @@ -44,48 +43,25 @@ public class BigDecimalJsonValueProcessor implements JsonValueProcessor{
* The Constructor.
*/
public BigDecimalJsonValueProcessor(){
super();
}

/**
* The Constructor.
*
* @param numberPattern
* the number pattern
* 你可以使用 {@link com.feilong.core.NumberPattern}
*/
public BigDecimalJsonValueProcessor(String numberPattern){
super();
this.numberPattern = numberPattern;
}

/*
* (non-Javadoc)
*
* @see net.sf.json.processors.JsonValueProcessor#processArrayValue(java.lang.Object, net.sf.json.JsonConfig)
* @see com.feilong.tools.jsonlib.processor.AbstractJsonValueProcessor#processValue(java.lang.Object, net.sf.json.JsonConfig)
*/
@Override
public Object processArrayValue(Object value,JsonConfig jsonConfig){
return process(value);
}

/*
* (non-Javadoc)
*
* @see net.sf.json.processors.JsonValueProcessor#processObjectValue(java.lang.String, java.lang.Object, net.sf.json.JsonConfig)
*/
@Override
public Object processObjectValue(String key,Object value,JsonConfig jsonConfig){
return process(value);
}

/**
* Process.
*
* @param value
* the value
* @return the object
*/
private Object process(Object value){
protected Object processValue(Object value,JsonConfig jsonConfig){
return value == null ? StringUtils.EMPTY
: (value instanceof BigDecimal ? NumberUtil.toString((Number) value, numberPattern) : value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
import com.feilong.core.date.DateUtil;

import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonValueProcessor;

/**
* 时间转换 日期值处理器实现.
*
* @author <a href="http://feitianbenyue.iteye.com/">feilong</a>
* @since 1.0.5
*/
public class DateJsonValueProcessor implements JsonValueProcessor{
public class DateJsonValueProcessor extends AbstractJsonValueProcessor{

/** The date pattern. */
private String datePattern = DatePattern.COMMON_DATE_AND_TIME;
Expand All @@ -38,7 +37,7 @@ public class DateJsonValueProcessor implements JsonValueProcessor{
* The Constructor.
*
* @param datePattern
* the date pattern
* 你可以使用 {@link com.feilong.core.DatePattern}
*/
public DateJsonValueProcessor(String datePattern){
this.datePattern = datePattern;
Expand All @@ -47,31 +46,10 @@ public DateJsonValueProcessor(String datePattern){
/*
* (non-Javadoc)
*
* @see net.sf.json.processors.JsonValueProcessor#processArrayValue(java.lang.Object, net.sf.json.JsonConfig)
* @see com.feilong.tools.jsonlib.processor.AbstractJsonValueProcessor#processValue(java.lang.Object, net.sf.json.JsonConfig)
*/
@Override
public Object processArrayValue(Object value,JsonConfig jsonConfig){
return process(value);
}

/*
* (non-Javadoc)
*
* @see net.sf.json.processors.JsonValueProcessor#processObjectValue(java.lang.String, java.lang.Object, net.sf.json.JsonConfig)
*/
@Override
public Object processObjectValue(String key,Object value,JsonConfig jsonConfig){
return process(value);
}

/**
* Process.
*
* @param value
* the value
* @return the object
*/
private Object process(Object value){
protected Object processValue(Object value,JsonConfig jsonConfig){
return null == value ? null : (value instanceof Date ? DateUtil.toString((Date) value, datePattern) : value.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,25 @@
package com.feilong.tools.jsonlib.processor;

import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonValueProcessor;

/**
* 过滤敏感信息,最直接的就是像密码这样的内容,不可以输出在控制台,需要转换成***字眼.
*
* @author <a href="http://feitianbenyue.iteye.com/">feilong</a>
* @since 1.2.2
*/
public class SensitiveWordsJsonValueProcessor implements JsonValueProcessor{
public class SensitiveWordsJsonValueProcessor extends AbstractJsonValueProcessor{

/** The default sensitive words. */
private static String DEFAULT_SENSITIVE_WORDS = "******";

/**
* The Constructor.
*/
public SensitiveWordsJsonValueProcessor(){
}

/*
* (non-Javadoc)
*
* @see net.sf.json.processors.JsonValueProcessor#processArrayValue(java.lang.Object, net.sf.json.JsonConfig)
* @see com.feilong.tools.jsonlib.processor.AbstractJsonValueProcessor#processValue(java.lang.Object, net.sf.json.JsonConfig)
*/
@Override
public Object processArrayValue(Object value,JsonConfig jsonConfig){
return processValue(value);
}

/*
* (non-Javadoc)
*
* @see net.sf.json.processors.JsonValueProcessor#processObjectValue(java.lang.String, java.lang.Object, net.sf.json.JsonConfig)
*/
@Override
public Object processObjectValue(String key,Object value,JsonConfig jsonConfig){
return processValue(value);
}

/**
* Process.
*
* @param value
* the value
* @return the object
*/
private static Object processValue(Object value){
protected Object processValue(Object value,JsonConfig jsonConfig){
return null == value ? null : DEFAULT_SENSITIVE_WORDS;
}
}

0 comments on commit 4e08615

Please sign in to comment.