first commit
This commit is contained in:
42
src/main/java/com/baidu/ueditor/define/ActionMap.java
Normal file
42
src/main/java/com/baidu/ueditor/define/ActionMap.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package com.baidu.ueditor.define;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* 定义请求action类型
|
||||
* @author hancong03@baidu.com
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public final class ActionMap {
|
||||
|
||||
public static final Map<String, Integer> mapping;
|
||||
// 获取配置请求
|
||||
public static final int CONFIG = 0;
|
||||
public static final int UPLOAD_IMAGE = 1;
|
||||
public static final int UPLOAD_SCRAWL = 2;
|
||||
public static final int UPLOAD_VIDEO = 3;
|
||||
public static final int UPLOAD_FILE = 4;
|
||||
public static final int CATCH_IMAGE = 5;
|
||||
public static final int LIST_FILE = 6;
|
||||
public static final int LIST_IMAGE = 7;
|
||||
|
||||
static {
|
||||
mapping = new HashMap<String, Integer>(){{
|
||||
put( "config", ActionMap.CONFIG );
|
||||
put( "uploadimage", ActionMap.UPLOAD_IMAGE );
|
||||
put( "uploadscrawl", ActionMap.UPLOAD_SCRAWL );
|
||||
put( "uploadvideo", ActionMap.UPLOAD_VIDEO );
|
||||
put( "uploadfile", ActionMap.UPLOAD_FILE );
|
||||
put( "catchimage", ActionMap.CATCH_IMAGE );
|
||||
put( "listfile", ActionMap.LIST_FILE );
|
||||
put( "listimage", ActionMap.LIST_IMAGE );
|
||||
}};
|
||||
}
|
||||
|
||||
public static int getType ( String key ) {
|
||||
return ActionMap.mapping.get( key );
|
||||
}
|
||||
|
||||
}
|
||||
5
src/main/java/com/baidu/ueditor/define/ActionState.java
Normal file
5
src/main/java/com/baidu/ueditor/define/ActionState.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package com.baidu.ueditor.define;
|
||||
|
||||
public enum ActionState {
|
||||
UNKNOW_ERROR
|
||||
}
|
||||
77
src/main/java/com/baidu/ueditor/define/AppInfo.java
Normal file
77
src/main/java/com/baidu/ueditor/define/AppInfo.java
Normal file
@@ -0,0 +1,77 @@
|
||||
package com.baidu.ueditor.define;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class AppInfo {
|
||||
|
||||
public static final int SUCCESS = 0;
|
||||
public static final int MAX_SIZE = 1;
|
||||
public static final int PERMISSION_DENIED = 2;
|
||||
public static final int FAILED_CREATE_FILE = 3;
|
||||
public static final int IO_ERROR = 4;
|
||||
public static final int NOT_MULTIPART_CONTENT = 5;
|
||||
public static final int PARSE_REQUEST_ERROR = 6;
|
||||
public static final int NOTFOUND_UPLOAD_DATA = 7;
|
||||
public static final int NOT_ALLOW_FILE_TYPE = 8;
|
||||
|
||||
public static final int INVALID_ACTION = 101;
|
||||
public static final int CONFIG_ERROR = 102;
|
||||
|
||||
public static final int PREVENT_HOST = 201;
|
||||
public static final int CONNECTION_ERROR = 202;
|
||||
public static final int REMOTE_FAIL = 203;
|
||||
|
||||
public static final int NOT_DIRECTORY = 301;
|
||||
public static final int NOT_EXIST = 302;
|
||||
|
||||
public static final int ILLEGAL = 401;
|
||||
|
||||
public static Map<Integer, String> info = new HashMap<Integer, String>(){{
|
||||
|
||||
put( AppInfo.SUCCESS, "SUCCESS" );
|
||||
|
||||
// 无效的Action
|
||||
put( AppInfo.INVALID_ACTION, "\u65E0\u6548\u7684Action" );
|
||||
// 配置文件初始化失败
|
||||
put( AppInfo.CONFIG_ERROR, "\u914D\u7F6E\u6587\u4EF6\u521D\u59CB\u5316\u5931\u8D25" );
|
||||
// 抓取远程图片失败
|
||||
put( AppInfo.REMOTE_FAIL, "\u6293\u53D6\u8FDC\u7A0B\u56FE\u7247\u5931\u8D25" );
|
||||
|
||||
// 被阻止的远程主机
|
||||
put( AppInfo.PREVENT_HOST, "\u88AB\u963B\u6B62\u7684\u8FDC\u7A0B\u4E3B\u673A" );
|
||||
// 远程连接出错
|
||||
put( AppInfo.CONNECTION_ERROR, "\u8FDC\u7A0B\u8FDE\u63A5\u51FA\u9519" );
|
||||
|
||||
// "文件大小超出限制"
|
||||
put( AppInfo.MAX_SIZE, "\u6587\u4ef6\u5927\u5c0f\u8d85\u51fa\u9650\u5236" );
|
||||
// 权限不足, 多指写权限
|
||||
put( AppInfo.PERMISSION_DENIED, "\u6743\u9650\u4E0D\u8DB3" );
|
||||
// 创建文件失败
|
||||
put( AppInfo.FAILED_CREATE_FILE, "\u521B\u5EFA\u6587\u4EF6\u5931\u8D25" );
|
||||
// IO错误
|
||||
put( AppInfo.IO_ERROR, "IO\u9519\u8BEF" );
|
||||
// 上传表单不是multipart/form-data类型
|
||||
put( AppInfo.NOT_MULTIPART_CONTENT, "\u4E0A\u4F20\u8868\u5355\u4E0D\u662Fmultipart/form-data\u7C7B\u578B" );
|
||||
// 解析上传表单错误
|
||||
put( AppInfo.PARSE_REQUEST_ERROR, "\u89E3\u6790\u4E0A\u4F20\u8868\u5355\u9519\u8BEF" );
|
||||
// 未找到上传数据
|
||||
put( AppInfo.NOTFOUND_UPLOAD_DATA, "\u672A\u627E\u5230\u4E0A\u4F20\u6570\u636E" );
|
||||
// 不允许的文件类型
|
||||
put( AppInfo.NOT_ALLOW_FILE_TYPE, "\u4E0D\u5141\u8BB8\u7684\u6587\u4EF6\u7C7B\u578B" );
|
||||
|
||||
// 指定路径不是目录
|
||||
put( AppInfo.NOT_DIRECTORY, "\u6307\u5B9A\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55" );
|
||||
// 指定路径并不存在
|
||||
put( AppInfo.NOT_EXIST, "\u6307\u5B9A\u8DEF\u5F84\u5E76\u4E0D\u5B58\u5728" );
|
||||
|
||||
// callback参数名不合法
|
||||
put( AppInfo.ILLEGAL, "Callback\u53C2\u6570\u540D\u4E0D\u5408\u6CD5" );
|
||||
|
||||
}};
|
||||
|
||||
public static String getStateInfo ( int key ) {
|
||||
return AppInfo.info.get( key );
|
||||
}
|
||||
|
||||
}
|
||||
90
src/main/java/com/baidu/ueditor/define/BaseState.java
Normal file
90
src/main/java/com/baidu/ueditor/define/BaseState.java
Normal file
@@ -0,0 +1,90 @@
|
||||
package com.baidu.ueditor.define;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baidu.ueditor.Encoder;
|
||||
|
||||
public class BaseState implements State {
|
||||
|
||||
private boolean state = false;
|
||||
private String info = null;
|
||||
|
||||
private Map<String, String> infoMap = new HashMap<String, String>();
|
||||
|
||||
public BaseState () {
|
||||
this.state = true;
|
||||
}
|
||||
|
||||
public BaseState ( boolean state ) {
|
||||
this.setState( state );
|
||||
}
|
||||
|
||||
public BaseState ( boolean state, String info ) {
|
||||
this.setState( state );
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public BaseState ( boolean state, int infoCode ) {
|
||||
this.setState( state );
|
||||
this.info = AppInfo.getStateInfo( infoCode );
|
||||
}
|
||||
|
||||
public boolean isSuccess () {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
public void setState ( boolean state ) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public void setInfo ( String info ) {
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void setInfo ( int infoCode ) {
|
||||
this.info = AppInfo.getStateInfo( infoCode );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSONString() {
|
||||
return this.toString();
|
||||
}
|
||||
|
||||
public String toString () {
|
||||
|
||||
String key = null;
|
||||
String stateVal = this.isSuccess() ? AppInfo.getStateInfo( AppInfo.SUCCESS ) : this.info;
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append( "{\"state\": \"" + stateVal + "\"" );
|
||||
|
||||
Iterator<String> iterator = this.infoMap.keySet().iterator();
|
||||
|
||||
while ( iterator.hasNext() ) {
|
||||
|
||||
key = iterator.next();
|
||||
|
||||
builder.append( ",\"" + key + "\": \"" + this.infoMap.get(key) + "\"" );
|
||||
|
||||
}
|
||||
|
||||
builder.append( "}" );
|
||||
|
||||
return Encoder.toUnicode( builder.toString() );
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putInfo(String name, String val) {
|
||||
this.infoMap.put(name, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putInfo(String name, long val) {
|
||||
this.putInfo(name, val+"");
|
||||
}
|
||||
|
||||
}
|
||||
31
src/main/java/com/baidu/ueditor/define/FileType.java
Normal file
31
src/main/java/com/baidu/ueditor/define/FileType.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.baidu.ueditor.define;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class FileType {
|
||||
|
||||
public static final String JPG = "JPG";
|
||||
|
||||
private static final Map<String, String> types = new HashMap<String, String>(){{
|
||||
|
||||
put( FileType.JPG, ".jpg" );
|
||||
|
||||
}};
|
||||
|
||||
public static String getSuffix ( String key ) {
|
||||
return FileType.types.get( key );
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据给定的文件名,获取其后缀信息
|
||||
* @param filename
|
||||
* @return
|
||||
*/
|
||||
public static String getSuffixByFilename ( String filename ) {
|
||||
|
||||
return filename.substring( filename.lastIndexOf( "." ) ).toLowerCase();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
20
src/main/java/com/baidu/ueditor/define/MIMEType.java
Normal file
20
src/main/java/com/baidu/ueditor/define/MIMEType.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.baidu.ueditor.define;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MIMEType {
|
||||
|
||||
public static final Map<String, String> types = new HashMap<String, String>(){{
|
||||
put( "image/gif", ".gif" );
|
||||
put( "image/jpeg", ".jpg" );
|
||||
put( "image/jpg", ".jpg" );
|
||||
put( "image/png", ".png" );
|
||||
put( "image/bmp", ".bmp" );
|
||||
}};
|
||||
|
||||
public static String getSuffix ( String mime ) {
|
||||
return MIMEType.types.get( mime );
|
||||
}
|
||||
|
||||
}
|
||||
112
src/main/java/com/baidu/ueditor/define/MultiState.java
Normal file
112
src/main/java/com/baidu/ueditor/define/MultiState.java
Normal file
@@ -0,0 +1,112 @@
|
||||
package com.baidu.ueditor.define;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baidu.ueditor.Encoder;
|
||||
|
||||
/**
|
||||
* 多状态集合状态
|
||||
* 其包含了多个状态的集合, 其本身自己也是一个状态
|
||||
* @author hancong03@baidu.com
|
||||
*
|
||||
*/
|
||||
public class MultiState implements State {
|
||||
|
||||
private boolean state = false;
|
||||
private String info = null;
|
||||
private Map<String, Long> intMap = new HashMap<String, Long>();
|
||||
private Map<String, String> infoMap = new HashMap<String, String>();
|
||||
private List<String> stateList = new ArrayList<String>();
|
||||
|
||||
public MultiState ( boolean state ) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public MultiState ( boolean state, String info ) {
|
||||
this.state = state;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public MultiState ( boolean state, int infoKey ) {
|
||||
this.state = state;
|
||||
this.info = AppInfo.getStateInfo( infoKey );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuccess() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
public void addState ( State state ) {
|
||||
stateList.add( state.toJSONString() );
|
||||
}
|
||||
|
||||
/**
|
||||
* 该方法调用无效果
|
||||
*/
|
||||
@Override
|
||||
public void putInfo(String name, String val) {
|
||||
this.infoMap.put(name, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSONString() {
|
||||
|
||||
String stateVal = this.isSuccess() ? AppInfo.getStateInfo( AppInfo.SUCCESS ) : this.info;
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append( "{\"state\": \"" + stateVal + "\"" );
|
||||
|
||||
// 数字转换
|
||||
Iterator<String> iterator = this.intMap.keySet().iterator();
|
||||
|
||||
while ( iterator.hasNext() ) {
|
||||
|
||||
stateVal = iterator.next();
|
||||
|
||||
builder.append( ",\""+ stateVal +"\": " + this.intMap.get( stateVal ) );
|
||||
|
||||
}
|
||||
|
||||
iterator = this.infoMap.keySet().iterator();
|
||||
|
||||
while ( iterator.hasNext() ) {
|
||||
|
||||
stateVal = iterator.next();
|
||||
|
||||
builder.append( ",\""+ stateVal +"\": \"" + this.infoMap.get( stateVal ) + "\"" );
|
||||
|
||||
}
|
||||
|
||||
builder.append( ", list: [" );
|
||||
|
||||
|
||||
iterator = this.stateList.iterator();
|
||||
|
||||
while ( iterator.hasNext() ) {
|
||||
|
||||
builder.append( iterator.next() + "," );
|
||||
|
||||
}
|
||||
|
||||
if ( this.stateList.size() > 0 ) {
|
||||
builder.deleteCharAt( builder.length() - 1 );
|
||||
}
|
||||
|
||||
builder.append( " ]}" );
|
||||
|
||||
return Encoder.toUnicode( builder.toString() );
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putInfo(String name, long val) {
|
||||
this.intMap.put( name, val );
|
||||
}
|
||||
|
||||
}
|
||||
18
src/main/java/com/baidu/ueditor/define/State.java
Normal file
18
src/main/java/com/baidu/ueditor/define/State.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.baidu.ueditor.define;
|
||||
|
||||
/**
|
||||
* 处理状态接口
|
||||
* @author hancong03@baidu.com
|
||||
*
|
||||
*/
|
||||
public interface State {
|
||||
|
||||
public boolean isSuccess();
|
||||
|
||||
public void putInfo(String name, String val);
|
||||
|
||||
public void putInfo(String name, long val);
|
||||
|
||||
public String toJSONString();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user