Przeglądaj źródła

优化代码逻辑

zhou-hao 7 lat temu
rodzic
commit
6eecc14b5c
18 zmienionych plików z 380 dodań i 498 usunięć
  1. 1 1
      .travis.yml
  2. 8 1
      hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/AbstractOAuth2CrudServiceTests.java
  3. 1 1
      hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/AbstractService.java
  4. 106 110
      hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/ActionEnter.java
  5. 2 45
      hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/ConfigManager.java
  6. 1 1
      hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/Encoder.java
  7. 10 16
      hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/PathFormat.java
  8. 4 13
      hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/define/BaseState.java
  9. 13 14
      hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/define/MIMEType.java
  10. 61 89
      hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/define/MultiState.java
  11. 9 9
      hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/define/State.java
  12. 0 12
      hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/hunter/FileManager.java
  13. 1 1
      hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/upload/Base64Uploader.java
  14. 3 0
      hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/upload/BinaryUploader.java
  15. 139 138
      hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/upload/StorageManager.java
  16. 1 3
      hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/upload/Uploader.java
  17. 20 0
      hsweb-thirdparty/hsweb-thirdparty-ueditor/src/test/java/com/baidu/ueditor/define/MultiStateTest.java
  18. 0 44
      pom.xml

+ 1 - 1
.travis.yml

@@ -9,7 +9,7 @@ addons:
 jdk:
   - oraclejdk8
 script:
-  - mvn clean test jacoco:report sonar:sonar -Dmaven.test.failure.ignore=true
+  - mvn clean jacoco:report package -Dmaven.test.failure.ignore=true sonar:sonar
 cache:
   directories:
     - '$HOME/.m2/repository'

+ 8 - 1
hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/AbstractOAuth2CrudServiceTests.java

@@ -48,7 +48,9 @@ public class AbstractOAuth2CrudServiceTests {
 
         when(oAuth2Session.request("/test/")).thenReturn(
                 createFixedResponseRequest(
-                        whenRequest("get", ResponseMessage.ok(PagerResult.of(1, Arrays.asList(entity))))));
+                        whenRequest("get", ResponseMessage.ok(PagerResult.of(1, Arrays.asList(entity)))),
+                        whenRequest("post", ResponseMessage.ok("test"))
+                ));
 
 
         when(oAuth2Session.request("/test/test")).thenReturn(
@@ -88,6 +90,10 @@ public class AbstractOAuth2CrudServiceTests {
 
     @Test
     public void testCUD() {
+        String id = testEntityService.insert(TestEntity.builder().build());
+        Assert.assertNotNull(id);
+
+
         TestEntity entity = testEntityService.selectByPk("test");
         Assert.assertNotNull(entity);
 
@@ -108,6 +114,7 @@ public class AbstractOAuth2CrudServiceTests {
 
     @Test
     public void testQuery() {
+
         PagerResult<TestEntity> result = testEntityService.selectPager(new QueryParamEntity().where("name", "test"));
         System.out.println(JSON.toJSONString(result));
 

+ 1 - 1
hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/AbstractService.java

@@ -103,7 +103,7 @@ public abstract class AbstractService<E extends Entity, PK> implements CreateEnt
         validate(() -> validator.validateProperty(data, property, groups));
     }
 
-    protected void tryValidate(Class type, String property, Object value, Class... groups) {
+    protected <T> void tryValidate(Class<T> type, String property, Object value, Class... groups) {
         validate(() -> validator.validateValue(type, property, value, groups));
     }
 

+ 106 - 110
hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/ActionEnter.java

@@ -12,114 +12,110 @@ import javax.servlet.http.HttpServletRequest;
 import java.util.Map;
 
 public class ActionEnter {
-	
-	private HttpServletRequest request = null;
-	
-	private String rootPath = null;
-	private String contextPath = null;
-	
-	private String actionType = null;
-	
-	private ConfigManager configManager = null;
-
-	public ActionEnter ( HttpServletRequest request, String rootPath ) {
-		
-		this.request = request;
-		this.rootPath = rootPath;
-		this.actionType = request.getParameter( "action" );
-		this.contextPath = request.getContextPath();
-		this.configManager = ConfigManager.getInstance( this.rootPath, this.contextPath, request.getRequestURI() );
-	}
-	
-	public String exec () {
-		
-		String callbackName = this.request.getParameter("callback");
-		
-		if ( callbackName != null ) {
-
-			if ( !validCallbackName( callbackName ) ) {
-				return new BaseState( false, AppInfo.ILLEGAL ).toJSONString();
-			}
-			
-			return callbackName+"("+this.invoke()+");";
-			
-		} else {
-			return this.invoke();
-		}
-
-	}
-	
-	public String invoke() {
-		
-		if ( actionType == null || !ActionMap.mapping.containsKey( actionType ) ) {
-			return new BaseState( false, AppInfo.INVALID_ACTION ).toJSONString();
-		}
-		
-		if ( this.configManager == null || !this.configManager.valid() ) {
-			return new BaseState( false, AppInfo.CONFIG_ERROR ).toJSONString();
-		}
-		
-		State state = null;
-		
-		int actionCode = ActionMap.getType(this.actionType);
-		
-		Map<String, Object> conf = null;
-		
-		switch ( actionCode ) {
-		
-			case ActionMap.CONFIG:
-				return this.configManager.getAllConfig().toString();
-				
-			case ActionMap.UPLOAD_IMAGE:
-			case ActionMap.UPLOAD_SCRAWL:
-			case ActionMap.UPLOAD_VIDEO:
-			case ActionMap.UPLOAD_FILE:
-				conf = this.configManager.getConfig( actionCode );
-				state = new Uploader( request, conf ).doExec();
-				break;
-				
-			case ActionMap.CATCH_IMAGE:
-				conf = configManager.getConfig( actionCode );
-				String[] list = this.request.getParameterValues( (String)conf.get( "fieldName" ) );
-				state = new ImageHunter( conf ).capture( list );
-				break;
-				
-			case ActionMap.LIST_IMAGE:
-			case ActionMap.LIST_FILE:
-				conf = configManager.getConfig( actionCode );
-				int start = this.getStartIndex();
-				state = new FileManager( conf ).listFile( start );
-				break;
-				
-		}
-		
-		return state.toJSONString();
-		
-	}
-	
-	public int getStartIndex () {
-		
-		String start = this.request.getParameter( "start" );
-		
-		try {
-			return Integer.parseInt(start);
-		} catch ( Exception e ) {
-			return 0;
-		}
-		
-	}
-	
-	/**
-	 * callback参数验证
-	 */
-	public boolean validCallbackName ( String name ) {
-		
-		if ( name.matches( "^[a-zA-Z_]+[\\w0-9_]*$" ) ) {
-			return true;
-		}
-		
-		return false;
-		
-	}
-	
+
+    private HttpServletRequest request = null;
+
+    private String rootPath = null;
+    private String contextPath = null;
+
+    private String actionType = null;
+
+    private ConfigManager configManager = null;
+
+    public ActionEnter(HttpServletRequest request, String rootPath) {
+
+        this.request = request;
+        this.rootPath = rootPath;
+        this.actionType = request.getParameter("action");
+        this.contextPath = request.getContextPath();
+        this.configManager = ConfigManager.getInstance(this.rootPath, this.contextPath, request.getRequestURI());
+    }
+
+    public String exec() {
+
+        String callbackName = this.request.getParameter("callback");
+
+        if (callbackName != null) {
+
+            if (!validCallbackName(callbackName)) {
+                return new BaseState(false, AppInfo.ILLEGAL).toJSONString();
+            }
+
+            return callbackName + "(" + this.invoke() + ");";
+
+        } else {
+            return this.invoke();
+        }
+
+    }
+
+    public String invoke() {
+
+        if (actionType == null || !ActionMap.mapping.containsKey(actionType)) {
+            return new BaseState(false, AppInfo.INVALID_ACTION).toJSONString();
+        }
+
+        if (this.configManager == null || !this.configManager.valid()) {
+            return new BaseState(false, AppInfo.CONFIG_ERROR).toJSONString();
+        }
+
+        State state = null;
+
+        int actionCode = ActionMap.getType(this.actionType);
+
+        Map<String, Object> conf ;
+
+        switch (actionCode) {
+
+            case ActionMap.CONFIG:
+                return this.configManager.getAllConfig().toString();
+
+            case ActionMap.UPLOAD_IMAGE:
+            case ActionMap.UPLOAD_SCRAWL:
+            case ActionMap.UPLOAD_VIDEO:
+            case ActionMap.UPLOAD_FILE:
+                conf = this.configManager.getConfig(actionCode);
+                state = new Uploader(request, conf).doExec();
+                break;
+
+            case ActionMap.CATCH_IMAGE:
+                conf = configManager.getConfig(actionCode);
+                String[] list = this.request.getParameterValues((String) conf.get("fieldName"));
+                state = new ImageHunter(conf).capture(list);
+                break;
+
+            case ActionMap.LIST_IMAGE:
+            case ActionMap.LIST_FILE:
+                conf = configManager.getConfig(actionCode);
+                int start = this.getStartIndex();
+                state = new FileManager(conf).listFile(start);
+                break;
+
+        }
+
+        return state == null ? "{}" : state.toJSONString();
+
+    }
+
+    public int getStartIndex() {
+
+        String start = this.request.getParameter("start");
+
+        try {
+            return Integer.parseInt(start);
+        } catch (Exception e) {
+            return 0;
+        }
+
+    }
+
+    /**
+     * callback参数验证
+     */
+    public boolean validCallbackName(String name) {
+
+        return name.matches("^[a-zA-Z_]+[\\w0-9_]*$");
+
+    }
+
 }

+ 2 - 45
hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/ConfigManager.java

@@ -19,10 +19,7 @@ import java.util.*;
 public final class ConfigManager {
 
     private final String rootPath;
-    private final String originalPath;
-    // private final String contextPath;
-    private static final String configFileName = "config.json";
-    private String parentPath = null;
+    private static final String configFileName = "ueditor-config.json";
     private JSONObject jsonConfig = null;
     // 涂鸦上传filename定义
     private final static String SCRAWL_FILE_NAME = "scrawl";
@@ -36,18 +33,8 @@ public final class ConfigManager {
 
 
         rootPath = rootPath.replace("\\", "/");
-
         this.rootPath = rootPath;
-        // this.contextPath = contextPath;
-
-        if (contextPath.length() > 0) {
-            this.originalPath = this.rootPath + uri.substring(contextPath.length());
-        } else {
-            this.originalPath = this.rootPath + uri;
-        }
-
         this.initEnv();
-
     }
 
     /**
@@ -149,7 +136,7 @@ public final class ConfigManager {
 
     private void initEnv() throws IOException {
         try {
-            this.jsonConfig = JSON.parseObject(FileUtils.reader2String("ueditor-config.json"));
+            this.jsonConfig = JSON.parseObject(FileUtils.reader2String(configFileName));
         } catch (Exception e) {
             log.warn("read ueditor config file error", e);
             this.jsonConfig = null;
@@ -157,10 +144,6 @@ public final class ConfigManager {
 
     }
 
-    private String getConfigPath() {
-        return this.parentPath + File.separator + ConfigManager.configFileName;
-    }
-
     private String[] getArray(String key) {
 
         JSONArray jsonArray = this.jsonConfig.getJSONArray(key);
@@ -174,32 +157,6 @@ public final class ConfigManager {
 
     }
 
-    private String readFile(String path) throws IOException {
-        Collection<String> str = Collections.synchronizedCollection(new ArrayList<String>());
-
-        StringBuilder builder = new StringBuilder();
-
-        try {
-
-            InputStreamReader reader = new InputStreamReader(new FileInputStream(path), "UTF-8");
-            BufferedReader bfReader = new BufferedReader(reader);
-
-            String tmpContent = null;
-
-            while ((tmpContent = bfReader.readLine()) != null) {
-                builder.append(tmpContent);
-            }
-
-            bfReader.close();
-
-        } catch (UnsupportedEncodingException e) {
-            // 忽略
-        }
-
-        return this.filter(builder.toString());
-
-    }
-
     // 过滤输入字符串, 剔除多行注释以及替换掉反斜杠
     private String filter(String input) {
 

+ 1 - 1
hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/Encoder.java

@@ -12,7 +12,7 @@ public class Encoder {
 			if ( ch < 256 ) {
 				builder.append( ch );
 			} else {
-				builder.append( "\\u" +  Integer.toHexString(ch & 0xffff) );
+				builder.append("\\u").append(Integer.toHexString(ch & 0xffff));
 			}
 			
 		}

+ 10 - 16
hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/PathFormat.java

@@ -63,7 +63,7 @@ public class PathFormat {
 		while ( matcher.find() ) {
 			
 			matchStr = matcher.group( 1 );
-			if ( matchStr.indexOf( "filename" ) != -1 ) {
+			if (matchStr.contains("filename")) {
 				filename = filename.replace( "$", "\\$" ).replaceAll( "[\\/:*?\"<>|]", "" );
 				matcher.appendReplacement(sb, filename );
 			} else {
@@ -82,23 +82,23 @@ public class PathFormat {
 		pattern = pattern.toLowerCase();
 		
 		// time 处理
-		if ( pattern.indexOf( PathFormat.TIME ) != -1 ) {
+		if (pattern.contains(PathFormat.TIME)) {
 			return PathFormat.getTimestamp();
-		} else if ( pattern.indexOf( PathFormat.FULL_YEAR ) != -1 ) {
+		} else if (pattern.contains(PathFormat.FULL_YEAR)) {
 			return PathFormat.getFullYear();
-		} else if ( pattern.indexOf( PathFormat.YEAR ) != -1 ) {
+		} else if (pattern.contains(PathFormat.YEAR)) {
 			return PathFormat.getYear();
-		} else if ( pattern.indexOf( PathFormat.MONTH ) != -1 ) {
+		} else if (pattern.contains(PathFormat.MONTH)) {
 			return PathFormat.getMonth();
-		} else if ( pattern.indexOf( PathFormat.DAY ) != -1 ) {
+		} else if (pattern.contains(PathFormat.DAY)) {
 			return PathFormat.getDay();
-		} else if ( pattern.indexOf( PathFormat.HOUR ) != -1 ) {
+		} else if (pattern.contains(PathFormat.HOUR)) {
 			return PathFormat.getHour();
-		} else if ( pattern.indexOf( PathFormat.MINUTE ) != -1 ) {
+		} else if (pattern.contains(PathFormat.MINUTE)) {
 			return PathFormat.getMinute();
-		} else if ( pattern.indexOf( PathFormat.SECOND ) != -1 ) {
+		} else if (pattern.contains(PathFormat.SECOND)) {
 			return PathFormat.getSecond();
-		} else if ( pattern.indexOf( PathFormat.RAND ) != -1 ) {
+		} else if (pattern.contains(PathFormat.RAND)) {
 			return PathFormat.getRandom(pattern);
 		}
 		
@@ -148,10 +148,4 @@ public class PathFormat {
 		return ( Math.random() + "" ).replace( ".", "" ).substring( 0, length );
 		
 	}
-
-	public static void main(String[] args) {
-		// TODO Auto-generated method stub
-
-	}
-
 }

+ 4 - 13
hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/define/BaseState.java

@@ -11,7 +11,7 @@ public class BaseState implements State {
 	private boolean state = false;
 	private String info = null;
 	
-	private Map<String, String> infoMap = new HashMap<String, String>();
+	private Map<String, String> infoMap = new HashMap<>();
 	
 	public BaseState () {
 		this.state = true;
@@ -53,22 +53,13 @@ public class BaseState implements State {
 	
 	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("{\"state\": \"").append(stateVal).append("\"");
+
+		this.infoMap.forEach((key,value)-> builder.append(",\"").append(key).append("\": \"").append(value).append("\""));
 		
 		builder.append( "}" );
 

+ 13 - 14
hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/define/MIMEType.java

@@ -5,19 +5,18 @@ import java.util.Map;
 
 public class MIMEType {
 
-	public static final Map<String, String> types = new HashMap<String, String>(){ 
-		private static final long serialVersionUID = -2881802098108442811L;
+    public static final Map<String, String> types = new HashMap<>();
+
+    static {
+        types.put("image/gif", ".gif");
+        types.put("image/jpeg", ".jpg");
+        types.put("image/jpg", ".jpg");
+        types.put("image/png", ".png");
+        types.put("image/bmp", ".bmp");
+    }
+
+    public static String getSuffix(String mime) {
+        return MIMEType.types.get(mime);
+    }
 
-	{
-		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 );
-	}
-	
 }

+ 61 - 89
hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/define/MultiState.java

@@ -7,98 +7,70 @@ import java.util.*;
 /**
  * 多状态集合状态
  * 其包含了多个状态的集合, 其本身自己也是一个状态
- * @author hancong03@baidu.com
  *
+ * @author hancong03@baidu.com , zh.sqy@qq.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);
-	}
-	
-	public boolean isSuccess() {
-		return this.state;
-	}
-	
-	public void addState ( State state ) {
-		stateList.add( state.toJSONString() );
-	}
-
-	/**
-	 * 该方法调用无效果
-	 */
-	public void putInfo(String name, String val) {
-		this.infoMap.put(name, val);
-	}
-
-	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());
-
-	}
-
-	public void putInfo(String name, long val) {
-		this.intMap.put( name, val );
-	}
+    private boolean state = false;
+    private String info = null;
+    private Map<String, Long> intMap = new HashMap<>();
+    private Map<String, String> infoMap = new HashMap<>();
+    private List<String> stateList = new ArrayList<>();
+
+    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);
+    }
+
+    public boolean isSuccess() {
+        return this.state;
+    }
+
+    public void addState(State state) {
+        stateList.add(state.toJSONString());
+    }
+
+    /**
+     * 该方法调用无效果
+     */
+    public void putInfo(String name, String val) {
+        this.infoMap.put(name, val);
+    }
+
+    public String toJSONString() {
+
+        String stateVal = this.isSuccess() ? AppInfo.getStateInfo(AppInfo.SUCCESS) : this.info;
+
+        StringBuilder builder = new StringBuilder();
+
+        builder.append("{\"state\": \"").append(stateVal).append("\"");
+
+        //int
+        this.intMap.forEach((k, v) -> builder.append(",\"").append(k).append("\": ").append(v));
+        //string
+        this.infoMap.forEach((k, v) -> builder.append(",\"").append(k).append("\": \"").append(v).append("\""));
+
+        //list
+        builder.append(", list: [").append(String.join(",", this.stateList.toArray(new String[this.stateList.size()])));
+
+        builder.append(" ]}");
+
+        return Encoder.toUnicode(builder.toString());
+
+    }
+
+    public void putInfo(String name, long val) {
+        this.intMap.put(name, val);
+    }
 
 }

+ 9 - 9
hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/define/State.java

@@ -2,17 +2,17 @@ package com.baidu.ueditor.define;
 
 /**
  * 处理状态接口
- * @author hancong03@baidu.com
  *
+ * @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();
+
+    boolean isSuccess();
+
+    void putInfo(String name, String val);
+
+    void putInfo(String name, long val);
+
+    String toJSONString();
 
 }

+ 0 - 12
hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/hunter/FileManager.java

@@ -7,18 +7,11 @@ import java.io.File;
 import java.util.Map;
 
 public class FileManager {
-
-    private String   dir        = null;
     private String   rootPath   = null;
-    private String[] allowFiles = null;
-    private int      count      = 0;
 
     public FileManager(Map<String, Object> conf) {
 
         this.rootPath = (String) conf.get("rootPath");
-        this.dir = this.rootPath + (String) conf.get("dir");
-        this.allowFiles = this.getAllowFiles(conf.get("allowFiles"));
-        this.count = (Integer) conf.get("count");
 
     }
 
@@ -81,9 +74,4 @@ public class FileManager {
 
     }
 
-    public static void main(String[] args) {
-        int n = 13;
-        System.out.println(n > 9 ? (char) (n - 10 + 'A') : n);
-        System.out.println(n > 9 ? (char) (n - 10 + 'A') : 1);
-    }
 }

+ 1 - 1
hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/upload/Base64Uploader.java

@@ -24,7 +24,7 @@ public final class Base64Uploader {
         if (!validSize(data, maxSize)) {
             return new BaseState(false, AppInfo.MAX_SIZE);
         }
-        String suffix = FileType.getSuffix("JPG");
+        String suffix = FileType.getSuffix(FileType.JPG);
         try {
             FileService fileService = Context.FILE_SERVICE;
             String path = fileService.saveStaticFile(new ByteArrayInputStream(data), System.currentTimeMillis() + suffix);

+ 3 - 0
hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/upload/BinaryUploader.java

@@ -5,6 +5,7 @@ import com.baidu.ueditor.define.AppInfo;
 import com.baidu.ueditor.define.BaseState;
 import com.baidu.ueditor.define.FileType;
 import com.baidu.ueditor.define.State;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.fileupload.FileItemIterator;
 import org.apache.commons.fileupload.FileItemStream;
 import org.apache.commons.fileupload.FileUploadException;
@@ -19,6 +20,7 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
+@Slf4j
 public class BinaryUploader {
 
     public static final State save(HttpServletRequest request, Map<String, Object> conf) {
@@ -74,6 +76,7 @@ public class BinaryUploader {
         } catch (FileUploadException e) {
             return new BaseState(false, AppInfo.PARSE_REQUEST_ERROR);
         } catch (IOException e) {
+            log.error(e.getMessage(),e);
         }
         return new BaseState(false, AppInfo.IO_ERROR);
     }

+ 139 - 138
hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/upload/StorageManager.java

@@ -3,147 +3,148 @@ package com.baidu.ueditor.upload;
 import com.baidu.ueditor.define.AppInfo;
 import com.baidu.ueditor.define.BaseState;
 import com.baidu.ueditor.define.State;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FileUtils;
 
 import java.io.*;
 
+@Slf4j
 public class StorageManager {
-	public static final int BUFFER_SIZE = 8192;
-
-	public StorageManager() {
-	}
-
-	public static State saveBinaryFile(byte[] data, String path) {
-		File file = new File(path);
-
-		State state = valid(file);
-
-		if (!state.isSuccess()) {
-			return state;
-		}
-
-		try {
-			BufferedOutputStream bos = new BufferedOutputStream(
-					new FileOutputStream(file));
-			bos.write(data);
-			bos.flush();
-			bos.close();
-		} catch (IOException ioe) {
-			return new BaseState(false, AppInfo.IO_ERROR);
-		}
-
-		state = new BaseState(true, file.getAbsolutePath());
-		state.putInfo( "size", data.length );
-		state.putInfo( "title", file.getName() );
-		return state;
-	}
-
-	public static State saveFileByInputStream(InputStream is, String path,
-			long maxSize) {
-		State state = null;
-
-		File tmpFile = getTmpFile();
-
-		byte[] dataBuf = new byte[ 2048 ];
-		BufferedInputStream bis = new BufferedInputStream(is, StorageManager.BUFFER_SIZE);
-
-		try {
-			BufferedOutputStream bos = new BufferedOutputStream(
-					new FileOutputStream(tmpFile), StorageManager.BUFFER_SIZE);
-
-			int count = 0;
-			while ((count = bis.read(dataBuf)) != -1) {
-				bos.write(dataBuf, 0, count);
-			}
-			bos.flush();
-			bos.close();
-
-			if (tmpFile.length() > maxSize) {
-				tmpFile.delete();
-				return new BaseState(false, AppInfo.MAX_SIZE);
-			}
-
-			state = saveTmpFile(tmpFile, path);
-
-			if (!state.isSuccess()) {
-				tmpFile.delete();
-			}
-
-			return state;
-			
-		} catch (IOException e) {
-		}
-		return new BaseState(false, AppInfo.IO_ERROR);
-	}
-
-	public static State saveFileByInputStream(InputStream is, String path) {
-		State state = null;
-
-		File tmpFile = getTmpFile();
-
-		byte[] dataBuf = new byte[ 2048 ];
-		BufferedInputStream bis = new BufferedInputStream(is, StorageManager.BUFFER_SIZE);
-
-		try {
-			BufferedOutputStream bos = new BufferedOutputStream(
-					new FileOutputStream(tmpFile), StorageManager.BUFFER_SIZE);
-
-			int count = 0;
-			while ((count = bis.read(dataBuf)) != -1) {
-				bos.write(dataBuf, 0, count);
-			}
-			bos.flush();
-			bos.close();
-
-			state = saveTmpFile(tmpFile, path);
-
-			if (!state.isSuccess()) {
-				tmpFile.delete();
-			}
-
-			return state;
-		} catch (IOException e) {
-		}
-		return new BaseState(false, AppInfo.IO_ERROR);
-	}
-
-	private static File getTmpFile() {
-		File tmpDir = FileUtils.getTempDirectory();
-		String tmpFileName = (Math.random() * 10000 + "").replace(".", "");
-		return new File(tmpDir, tmpFileName);
-	}
-
-	private static State saveTmpFile(File tmpFile, String path) {
-		State state = null;
-		File targetFile = new File(path);
-
-		if (targetFile.canWrite()) {
-			return new BaseState(false, AppInfo.PERMISSION_DENIED);
-		}
-		try {
-			FileUtils.moveFile(tmpFile, targetFile);
-		} catch (IOException e) {
-			return new BaseState(false, AppInfo.IO_ERROR);
-		}
-
-		state = new BaseState(true);
-		state.putInfo( "size", targetFile.length() );
-		state.putInfo( "title", targetFile.getName() );
-		
-		return state;
-	}
-
-	private static State valid(File file) {
-		File parentPath = file.getParentFile();
-
-		if ((!parentPath.exists()) && (!parentPath.mkdirs())) {
-			return new BaseState(false, AppInfo.FAILED_CREATE_FILE);
-		}
-
-		if (!parentPath.canWrite()) {
-			return new BaseState(false, AppInfo.PERMISSION_DENIED);
-		}
-
-		return new BaseState(true);
-	}
+    public static final int BUFFER_SIZE = 8192;
+
+    public StorageManager() {
+    }
+
+    public static State saveBinaryFile(byte[] data, String path) {
+        File file = new File(path);
+
+        State state = valid(file);
+
+        if (!state.isSuccess()) {
+            return state;
+        }
+
+        try {
+            BufferedOutputStream bos = new BufferedOutputStream(
+                    new FileOutputStream(file));
+            bos.write(data);
+            bos.flush();
+            bos.close();
+        } catch (IOException ioe) {
+            return new BaseState(false, AppInfo.IO_ERROR);
+        }
+
+        state = new BaseState(true, file.getAbsolutePath());
+        state.putInfo("size", data.length);
+        state.putInfo("title", file.getName());
+        return state;
+    }
+
+    public static State saveFileByInputStream(InputStream is, String path,
+                                              long maxSize) {
+
+        File tmpFile = getTmpFile();
+
+        byte[] dataBuf = new byte[2048];
+        BufferedInputStream bis = new BufferedInputStream(is, StorageManager.BUFFER_SIZE);
+
+        try {
+            BufferedOutputStream bos = new BufferedOutputStream(
+                    new FileOutputStream(tmpFile), StorageManager.BUFFER_SIZE);
+
+            int count = 0;
+            while ((count = bis.read(dataBuf)) != -1) {
+                bos.write(dataBuf, 0, count);
+            }
+            bos.flush();
+            bos.close();
+
+            if (tmpFile.length() > maxSize) {
+                tmpFile.delete();
+                return new BaseState(false, AppInfo.MAX_SIZE);
+            }
+
+            State state = saveTmpFile(tmpFile, path);
+
+            if (!state.isSuccess()) {
+                tmpFile.delete();
+            }
+
+            return state;
+
+        } catch (IOException e) {
+        }
+        return new BaseState(false, AppInfo.IO_ERROR);
+    }
+
+    public static State saveFileByInputStream(InputStream is, String path) {
+        State state;
+
+        File tmpFile = getTmpFile();
+
+        byte[] dataBuf = new byte[2048];
+        BufferedInputStream bis = new BufferedInputStream(is, StorageManager.BUFFER_SIZE);
+
+        try {
+            BufferedOutputStream bos = new BufferedOutputStream(
+                    new FileOutputStream(tmpFile), StorageManager.BUFFER_SIZE);
+
+            int count = 0;
+            while ((count = bis.read(dataBuf)) != -1) {
+                bos.write(dataBuf, 0, count);
+            }
+            bos.flush();
+            bos.close();
+
+            state = saveTmpFile(tmpFile, path);
+
+            if (!state.isSuccess()) {
+                tmpFile.delete();
+            }
+
+            return state;
+        } catch (IOException e) {
+            return new BaseState(false, AppInfo.IO_ERROR);
+        }
+    }
+
+    private static File getTmpFile() {
+        File tmpDir = FileUtils.getTempDirectory();
+        String tmpFileName = (Math.random() * 10000 + "").replace(".", "");
+        return new File(tmpDir, tmpFileName);
+    }
+
+    private static State saveTmpFile(File tmpFile, String path) {
+        State state = null;
+        File targetFile = new File(path);
+
+        if (targetFile.canWrite()) {
+            return new BaseState(false, AppInfo.PERMISSION_DENIED);
+        }
+        try {
+            FileUtils.moveFile(tmpFile, targetFile);
+        } catch (IOException e) {
+            return new BaseState(false, AppInfo.IO_ERROR);
+        }
+
+        state = new BaseState(true);
+        state.putInfo("size", targetFile.length());
+        state.putInfo("title", targetFile.getName());
+
+        return state;
+    }
+
+    private static State valid(File file) {
+        File parentPath = file.getParentFile();
+
+        if ((!parentPath.exists()) && (!parentPath.mkdirs())) {
+            return new BaseState(false, AppInfo.FAILED_CREATE_FILE);
+        }
+
+        if (!parentPath.canWrite()) {
+            return new BaseState(false, AppInfo.PERMISSION_DENIED);
+        }
+
+        return new BaseState(true);
+    }
 }

+ 1 - 3
hsweb-thirdparty/hsweb-thirdparty-ueditor/src/main/java/com/baidu/ueditor/upload/Uploader.java

@@ -6,8 +6,6 @@ import javax.servlet.http.HttpServletRequest;
 import java.util.Map;
 
 public class Uploader {
-	public static String downloadApi = null;
-
 	private HttpServletRequest request = null;
 	private Map<String, Object> conf = null;
 
@@ -18,7 +16,7 @@ public class Uploader {
 
 	public final State doExec() {
 		String filedName = (String) this.conf.get("fieldName");
-		State state = null;
+		State state;
 
 		if ("true".equals(this.conf.get("isBase64"))) {
 			state = Base64Uploader.save(this.request.getParameter(filedName),

+ 20 - 0
hsweb-thirdparty/hsweb-thirdparty-ueditor/src/test/java/com/baidu/ueditor/define/MultiStateTest.java

@@ -0,0 +1,20 @@
+package com.baidu.ueditor.define;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class MultiStateTest {
+
+    @Test
+    public void toJSONString(){
+        MultiState state=new MultiState(true);
+
+        state.addState(new BaseState());
+        state.putInfo("test",1);
+        state.putInfo("test","1");
+
+        System.out.println(state.toJSONString());
+
+    }
+}

+ 0 - 44
pom.xml

@@ -179,12 +179,6 @@
     <build>
 
         <plugins>
-            <!--<plugin>-->
-                <!--<groupId>org.eluder.coveralls</groupId>-->
-                <!--<artifactId>coveralls-maven-plugin</artifactId>-->
-                <!--<version>4.3.0</version>-->
-            <!--</plugin>-->
-
             <plugin>
                 <groupId>org.jacoco</groupId>
                 <artifactId>jacoco-maven-plugin</artifactId>
@@ -205,44 +199,6 @@
                 </executions>
             </plugin>
 
-
-
-            <!--<plugin>-->
-                <!--<groupId>org.codehaus.mojo</groupId>-->
-                <!--<artifactId>cobertura-maven-plugin</artifactId>-->
-                <!--<version>2.7</version>-->
-                <!--<configuration>-->
-                    <!--<formats>-->
-                        <!--<format>xml</format>-->
-                        <!--<format>html</format>-->
-                    <!--</formats>-->
-                    <!--<aggregate>true</aggregate>-->
-                    <!--<instrumentation>-->
-                        <!--<excludes>-->
-                            <!--<exclude>**/*Test.class</exclude>-->
-                            <!--<exclude>**/*Tests.class</exclude>-->
-                            <!--<exclude>**/*Entity.class</exclude>-->
-                            <!--<exclude>**/*Configuration.class</exclude>-->
-                        <!--</excludes>-->
-                    <!--</instrumentation>-->
-                <!--</configuration>-->
-                <!--<executions>-->
-                    <!--<execution>-->
-                        <!--<phase>package</phase>-->
-                        <!--<goals>-->
-                            <!--<goal>cobertura</goal>-->
-                        <!--</goals>-->
-                    <!--</execution>-->
-                <!--</executions>-->
-                <!--<dependencies>-->
-                    <!--<dependency>-->
-                        <!--<groupId>org.codehaus.javancss</groupId>-->
-                        <!--<artifactId>javancss</artifactId>-->
-                        <!--<version>33.54</version>-->
-                    <!--</dependency>-->
-                <!--</dependencies>-->
-            <!--</plugin>-->
-
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-scm-plugin</artifactId>