Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gs1-office-web-sit
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
吴迪
gs1-office-web-sit
Commits
1d157555
Commit
1d157555
authored
Dec 05, 2021
by
吴迪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【新增】富文本编辑器配置
parent
3dc3947c
Hide whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
1840 additions
and
16 deletions
+1840
-16
BranchController.java
...io/office/modules/manage/controller/BranchController.java
+103
-0
BranchDao.java
src/main/java/io/office/modules/manage/dao/BranchDao.java
+17
-0
BranchEntity.java
...in/java/io/office/modules/manage/entity/BranchEntity.java
+64
-0
UeditorController.java
...va/io/office/modules/manage/entity/UeditorController.java
+42
-0
BranchService.java
.../java/io/office/modules/manage/service/BranchService.java
+20
-0
BranchServiceImpl.java
...office/modules/manage/service/impl/BranchServiceImpl.java
+30
-0
OAuth2Filter.java
src/main/java/io/office/modules/sys/oauth2/OAuth2Filter.java
+1
-1
ActionEnter.java
...office/modules/ueditor/com/baidu/ueditor/ActionEnter.java
+128
-0
ConfigManager.java
...fice/modules/ueditor/com/baidu/ueditor/ConfigManager.java
+222
-0
Encoder.java
.../io/office/modules/ueditor/com/baidu/ueditor/Encoder.java
+25
-0
PathFormat.java
.../office/modules/ueditor/com/baidu/ueditor/PathFormat.java
+157
-0
ActionMap.java
...e/modules/ueditor/com/baidu/ueditor/define/ActionMap.java
+42
-0
ActionState.java
...modules/ueditor/com/baidu/ueditor/define/ActionState.java
+5
-0
AppInfo.java
...ice/modules/ueditor/com/baidu/ueditor/define/AppInfo.java
+77
-0
BaseState.java
...e/modules/ueditor/com/baidu/ueditor/define/BaseState.java
+92
-0
FileType.java
...ce/modules/ueditor/com/baidu/ueditor/define/FileType.java
+31
-0
MIMEType.java
...ce/modules/ueditor/com/baidu/ueditor/define/MIMEType.java
+20
-0
MultiState.java
.../modules/ueditor/com/baidu/ueditor/define/MultiState.java
+114
-0
State.java
...ffice/modules/ueditor/com/baidu/ueditor/define/State.java
+18
-0
FileManager.java
...modules/ueditor/com/baidu/ueditor/hunter/FileManager.java
+113
-0
ImageHunter.java
...modules/ueditor/com/baidu/ueditor/hunter/ImageHunter.java
+144
-0
Base64Uploader.java
...ules/ueditor/com/baidu/ueditor/upload/Base64Uploader.java
+53
-0
BinaryUploader.java
...ules/ueditor/com/baidu/ueditor/upload/BinaryUploader.java
+107
-0
StorageManager.java
...ules/ueditor/com/baidu/ueditor/upload/StorageManager.java
+156
-0
Uploader.java
...ce/modules/ueditor/com/baidu/ueditor/upload/Uploader.java
+29
-0
application-dev.yml
src/main/resources/application-dev.yml
+4
-1
BikecodeDao.xml
src/main/resources/mapper/manage/BikecodeDao.xml
+0
-14
BranchDao.xml
src/main/resources/mapper/manage/BranchDao.xml
+26
-0
No files found.
src/main/java/io/office/modules/manage/controller/BranchController.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
manage
.
controller
;
import
java.util.Arrays
;
import
java.util.Map
;
import
io.office.modules.app.annotation.Login
;
import
io.office.modules.manage.vo.request.ShortCodeVo
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
io.office.modules.manage.entity.BranchEntity
;
import
io.office.modules.manage.service.BranchService
;
import
io.office.common.utils.PageUtils
;
import
io.office.common.utils.R
;
import
javax.servlet.http.HttpServletRequest
;
/**
* ${comments}
*
* @author wudi
* @email
* @date 2021-12-05 14:35:52
*/
@RestController
@RequestMapping
(
"/branch"
)
public
class
BranchController
{
@Autowired
private
BranchService
branchService
;
/**
* 列表
*/
@RequestMapping
(
"/list"
)
// @RequiresPermissions("manage:branch:list")
public
R
list
(
@RequestParam
Map
<
String
,
Object
>
params
){
PageUtils
page
=
branchService
.
queryPage
(
params
);
return
R
.
ok
().
put
(
"page"
,
page
);
}
/**
* 信息
*/
@RequestMapping
(
"/info/{branchCode}"
)
// @RequiresPermissions("manage:branch:info")
public
R
info
(
@PathVariable
(
"branchCode"
)
String
branchCode
){
BranchEntity
branch
=
branchService
.
getById
(
branchCode
);
return
R
.
ok
().
put
(
"branch"
,
branch
);
}
/**
* 保存
*/
@RequestMapping
(
"/save"
)
// @RequiresPermissions("manage:branch:save")
public
R
save
(
@RequestBody
BranchEntity
branch
){
branchService
.
save
(
branch
);
return
R
.
ok
();
}
/**
* 修改
*/
@RequestMapping
(
"/update"
)
// @RequiresPermissions("manage:branch:update")
public
R
update
(
@RequestBody
BranchEntity
branch
){
branchService
.
updateById
(
branch
);
return
R
.
ok
();
}
/**
* 删除
*/
@RequestMapping
(
"/delete"
)
// @RequiresPermissions("manage:branch:delete")
public
R
delete
(
@RequestBody
String
[]
branchCodes
){
branchService
.
removeByIds
(
Arrays
.
asList
(
branchCodes
));
return
R
.
ok
();
}
@Login
@RequestMapping
(
"/api/getList"
)
// @RequiresPermissions("manage:shortcode:delete")
public
R
getList
(){
return
R
.
ok
().
put
(
"data"
,
branchService
.
list
());
}
}
src/main/java/io/office/modules/manage/dao/BranchDao.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
manage
.
dao
;
import
io.office.modules.manage.entity.BranchEntity
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
org.apache.ibatis.annotations.Mapper
;
/**
* ${comments}
*
* @author wudi
* @email
* @date 2021-12-05 14:35:52
*/
@Mapper
public
interface
BranchDao
extends
BaseMapper
<
BranchEntity
>
{
}
src/main/java/io/office/modules/manage/entity/BranchEntity.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
manage
.
entity
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
java.io.Serializable
;
import
java.util.Date
;
import
lombok.Data
;
/**
* ${comments}
*
* @author wudi
* @email
* @date 2021-12-05 14:35:52
*/
@Data
@TableName
(
"center_outer.dbo.branch"
)
public
class
BranchEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* $column.comments
*/
@TableId
private
String
branchCode
;
/**
* $column.comments
*/
private
String
branchName
;
/**
* $column.comments
*/
private
String
branchAddress
;
/**
* $column.comments
*/
private
String
branchPostcode
;
/**
* $column.comments
*/
private
String
branchContact
;
/**
* $column.comments
*/
private
String
tel1
;
/**
* $column.comments
*/
private
String
tel2
;
/**
* $column.comments
*/
private
String
fax
;
/**
* $column.comments
*/
private
String
rockkey
;
/**
* $column.comments
*/
private
String
branchSimname
;
}
src/main/java/io/office/modules/manage/entity/UeditorController.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
manage
.
entity
;
import
com.alibaba.fastjson.JSONException
;
import
io.office.modules.app.annotation.Login
;
import
io.office.modules.ueditor.com.baidu.ueditor.ActionEnter
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
/**
*
* @description:
*
* @author wudi
* @date 15:47 2021/12/5
*/
@RestController
public
class
UeditorController
{
@Value
(
"${ueditorSavePath}"
)
private
String
ueditorSavePath
;
@Login
@RequestMapping
(
"/ueditorConfig"
)
public
void
getUEditorConfig
(
HttpServletResponse
response
,
HttpServletRequest
request
){
String
rootPath
=
ueditorSavePath
;
try
{
String
exec
=
new
ActionEnter
(
request
,
rootPath
).
exec
();
PrintWriter
writer
=
response
.
getWriter
();
writer
.
write
(
exec
);
writer
.
flush
();
writer
.
close
();
}
catch
(
IOException
|
JSONException
e
)
{
e
.
printStackTrace
();
}
}
}
src/main/java/io/office/modules/manage/service/BranchService.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
manage
.
service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
io.office.common.utils.PageUtils
;
import
io.office.modules.manage.entity.BranchEntity
;
import
java.util.Map
;
/**
* ${comments}
*
* @author wudi
* @email
* @date 2021-12-05 14:35:52
*/
public
interface
BranchService
extends
IService
<
BranchEntity
>
{
PageUtils
queryPage
(
Map
<
String
,
Object
>
params
);
}
src/main/java/io/office/modules/manage/service/impl/BranchServiceImpl.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
manage
.
service
.
impl
;
import
org.springframework.stereotype.Service
;
import
java.util.Map
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
io.office.common.utils.PageUtils
;
import
io.office.common.utils.Query
;
import
io.office.modules.manage.dao.BranchDao
;
import
io.office.modules.manage.entity.BranchEntity
;
import
io.office.modules.manage.service.BranchService
;
@Service
(
"branchService"
)
public
class
BranchServiceImpl
extends
ServiceImpl
<
BranchDao
,
BranchEntity
>
implements
BranchService
{
@Override
public
PageUtils
queryPage
(
Map
<
String
,
Object
>
params
)
{
IPage
<
BranchEntity
>
page
=
this
.
page
(
new
Query
<
BranchEntity
>().
getPage
(
params
),
new
QueryWrapper
<
BranchEntity
>()
);
return
new
PageUtils
(
page
);
}
}
\ No newline at end of file
src/main/java/io/office/modules/sys/oauth2/OAuth2Filter.java
View file @
1d157555
...
...
@@ -49,7 +49,7 @@ public class OAuth2Filter extends AuthenticatingFilter {
return
true
;
}
if
(((
HttpServletRequest
)
request
).
getRequestURI
().
indexOf
(
"uploadFileResource"
)>-
1
)
{
if
(((
HttpServletRequest
)
request
).
getRequestURI
().
indexOf
(
"uploadFileResource"
)>-
1
||
((
HttpServletRequest
)
request
).
getRequestURI
().
indexOf
(
"ueditorConfig"
)>-
1
)
{
return
true
;
}
...
...
src/main/java/io/office/modules/ueditor/com/baidu/ueditor/ActionEnter.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
ueditor
.
com
.
baidu
.
ueditor
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.ActionMap
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.AppInfo
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.BaseState
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.State
;
import
io.office.modules.ueditor.com.baidu.ueditor.hunter.FileManager
;
import
io.office.modules.ueditor.com.baidu.ueditor.hunter.ImageHunter
;
import
io.office.modules.ueditor.com.baidu.ueditor.upload.Uploader
;
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
;
}
}
\ No newline at end of file
src/main/java/io/office/modules/ueditor/com/baidu/ueditor/ConfigManager.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
ueditor
.
com
.
baidu
.
ueditor
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.io.UnsupportedEncodingException
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.ActionMap
;
/**
* 配置管理器
* @author hancong03@baidu.com
*
*/
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
JSONObject
jsonConfig
=
null
;
// 涂鸦上传filename定义
private
final
static
String
SCRAWL_FILE_NAME
=
"scrawl"
;
// 远程图片抓取filename定义
private
final
static
String
REMOTE_FILE_NAME
=
"remote"
;
/*
* 通过一个给定的路径构建一个配置管理器, 该管理器要求地址路径所在目录下必须存在config.properties文件
*/
private
ConfigManager
(
String
rootPath
,
String
contextPath
,
String
uri
)
throws
FileNotFoundException
,
IOException
{
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
();
}
/**
* 配置管理器构造工厂
* @param rootPath 服务器根路径
* @param contextPath 服务器所在项目路径
* @param uri 当前访问的uri
* @return 配置管理器实例或者null
*/
public
static
ConfigManager
getInstance
(
String
rootPath
,
String
contextPath
,
String
uri
)
{
try
{
return
new
ConfigManager
(
rootPath
,
contextPath
,
uri
);
}
catch
(
Exception
e
)
{
return
null
;
}
}
// 验证配置文件加载是否正确
public
boolean
valid
()
{
return
this
.
jsonConfig
!=
null
;
}
public
JSONObject
getAllConfig
()
{
return
this
.
jsonConfig
;
}
public
Map
<
String
,
Object
>
getConfig
(
int
type
)
{
Map
<
String
,
Object
>
conf
=
new
HashMap
<
String
,
Object
>();
String
savePath
=
null
;
switch
(
type
)
{
case
ActionMap
.
UPLOAD_FILE
:
conf
.
put
(
"isBase64"
,
"false"
);
conf
.
put
(
"maxSize"
,
this
.
jsonConfig
.
getLong
(
"fileMaxSize"
)
);
conf
.
put
(
"allowFiles"
,
this
.
getArray
(
"fileAllowFiles"
)
);
conf
.
put
(
"fieldName"
,
this
.
jsonConfig
.
getString
(
"fileFieldName"
)
);
savePath
=
this
.
jsonConfig
.
getString
(
"filePathFormat"
);
break
;
case
ActionMap
.
UPLOAD_IMAGE
:
conf
.
put
(
"isBase64"
,
"false"
);
conf
.
put
(
"maxSize"
,
this
.
jsonConfig
.
getLong
(
"imageMaxSize"
)
);
conf
.
put
(
"allowFiles"
,
this
.
getArray
(
"imageAllowFiles"
)
);
conf
.
put
(
"fieldName"
,
this
.
jsonConfig
.
getString
(
"imageFieldName"
)
);
savePath
=
this
.
jsonConfig
.
getString
(
"imagePathFormat"
);
break
;
case
ActionMap
.
UPLOAD_VIDEO
:
conf
.
put
(
"maxSize"
,
this
.
jsonConfig
.
getLong
(
"videoMaxSize"
)
);
conf
.
put
(
"allowFiles"
,
this
.
getArray
(
"videoAllowFiles"
)
);
conf
.
put
(
"fieldName"
,
this
.
jsonConfig
.
getString
(
"videoFieldName"
)
);
savePath
=
this
.
jsonConfig
.
getString
(
"videoPathFormat"
);
break
;
case
ActionMap
.
UPLOAD_SCRAWL
:
conf
.
put
(
"filename"
,
ConfigManager
.
SCRAWL_FILE_NAME
);
conf
.
put
(
"maxSize"
,
this
.
jsonConfig
.
getLong
(
"scrawlMaxSize"
)
);
conf
.
put
(
"fieldName"
,
this
.
jsonConfig
.
getString
(
"scrawlFieldName"
)
);
conf
.
put
(
"isBase64"
,
"true"
);
savePath
=
this
.
jsonConfig
.
getString
(
"scrawlPathFormat"
);
break
;
case
ActionMap
.
CATCH_IMAGE
:
conf
.
put
(
"filename"
,
ConfigManager
.
REMOTE_FILE_NAME
);
conf
.
put
(
"filter"
,
this
.
getArray
(
"catcherLocalDomain"
)
);
conf
.
put
(
"maxSize"
,
this
.
jsonConfig
.
getLong
(
"catcherMaxSize"
)
);
conf
.
put
(
"allowFiles"
,
this
.
getArray
(
"catcherAllowFiles"
)
);
conf
.
put
(
"fieldName"
,
this
.
jsonConfig
.
getString
(
"catcherFieldName"
)
+
"[]"
);
savePath
=
this
.
jsonConfig
.
getString
(
"catcherPathFormat"
);
break
;
case
ActionMap
.
LIST_IMAGE
:
conf
.
put
(
"allowFiles"
,
this
.
getArray
(
"imageManagerAllowFiles"
)
);
conf
.
put
(
"dir"
,
this
.
jsonConfig
.
getString
(
"imageManagerListPath"
)
);
conf
.
put
(
"count"
,
this
.
jsonConfig
.
getInt
(
"imageManagerListSize"
)
);
break
;
case
ActionMap
.
LIST_FILE
:
conf
.
put
(
"allowFiles"
,
this
.
getArray
(
"fileManagerAllowFiles"
)
);
conf
.
put
(
"dir"
,
this
.
jsonConfig
.
getString
(
"fileManagerListPath"
)
);
conf
.
put
(
"count"
,
this
.
jsonConfig
.
getInt
(
"fileManagerListSize"
)
);
break
;
}
conf
.
put
(
"savePath"
,
savePath
);
conf
.
put
(
"rootPath"
,
this
.
rootPath
);
return
conf
;
}
private
void
initEnv
()
throws
FileNotFoundException
,
IOException
{
File
file
=
new
File
(
this
.
originalPath
);
if
(
!
file
.
isAbsolute
()
)
{
file
=
new
File
(
file
.
getAbsolutePath
()
);
}
this
.
parentPath
=
file
.
getParent
();
String
configContent
=
this
.
readFile
(
this
.
getConfigPath
()
);
try
{
JSONObject
jsonConfig
=
new
JSONObject
(
configContent
);
this
.
jsonConfig
=
jsonConfig
;
}
catch
(
Exception
e
)
{
this
.
jsonConfig
=
null
;
}
}
private
String
getConfigPath
()
{
return
this
.
parentPath
+
File
.
separator
+
ConfigManager
.
configFileName
;
}
private
String
[]
getArray
(
String
key
)
{
JSONArray
jsonArray
=
this
.
jsonConfig
.
getJSONArray
(
key
);
String
[]
result
=
new
String
[
jsonArray
.
length
()
];
for
(
int
i
=
0
,
len
=
jsonArray
.
length
();
i
<
len
;
i
++
)
{
result
[
i
]
=
jsonArray
.
getString
(
i
);
}
return
result
;
}
private
String
readFile
(
String
path
)
throws
IOException
{
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
)
{
return
input
.
replaceAll
(
"/\\*[\\s\\S]*?\\*/"
,
""
);
}
}
src/main/java/io/office/modules/ueditor/com/baidu/ueditor/Encoder.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
ueditor
.
com
.
baidu
.
ueditor
;
public
class
Encoder
{
public
static
String
toUnicode
(
String
input
)
{
StringBuilder
builder
=
new
StringBuilder
();
char
[]
chars
=
input
.
toCharArray
();
for
(
char
ch
:
chars
)
{
if
(
ch
<
256
)
{
builder
.
append
(
ch
);
}
else
{
builder
.
append
(
"\\u"
+
Integer
.
toHexString
(
ch
&
0xffff
)
);
}
}
return
builder
.
toString
();
}
}
\ No newline at end of file
src/main/java/io/office/modules/ueditor/com/baidu/ueditor/PathFormat.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
ueditor
.
com
.
baidu
.
ueditor
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
public
class
PathFormat
{
private
static
final
String
TIME
=
"time"
;
private
static
final
String
FULL_YEAR
=
"yyyy"
;
private
static
final
String
YEAR
=
"yy"
;
private
static
final
String
MONTH
=
"mm"
;
private
static
final
String
DAY
=
"dd"
;
private
static
final
String
HOUR
=
"hh"
;
private
static
final
String
MINUTE
=
"ii"
;
private
static
final
String
SECOND
=
"ss"
;
private
static
final
String
RAND
=
"rand"
;
private
static
Date
currentDate
=
null
;
public
static
String
parse
(
String
input
)
{
Pattern
pattern
=
Pattern
.
compile
(
"\\{([^\\}]+)\\}"
,
Pattern
.
CASE_INSENSITIVE
);
Matcher
matcher
=
pattern
.
matcher
(
input
);
PathFormat
.
currentDate
=
new
Date
();
StringBuffer
sb
=
new
StringBuffer
();
while
(
matcher
.
find
()
)
{
matcher
.
appendReplacement
(
sb
,
PathFormat
.
getString
(
matcher
.
group
(
1
)
)
);
}
matcher
.
appendTail
(
sb
);
return
sb
.
toString
();
}
/**
* 格式化路径, 把windows路径替换成标准路径
* @param input 待格式化的路径
* @return 格式化后的路径
*/
public
static
String
format
(
String
input
)
{
return
input
.
replace
(
"\\"
,
"/"
);
}
public
static
String
parse
(
String
input
,
String
filename
)
{
Pattern
pattern
=
Pattern
.
compile
(
"\\{([^\\}]+)\\}"
,
Pattern
.
CASE_INSENSITIVE
);
Matcher
matcher
=
pattern
.
matcher
(
input
);
String
matchStr
=
null
;
PathFormat
.
currentDate
=
new
Date
();
StringBuffer
sb
=
new
StringBuffer
();
while
(
matcher
.
find
()
)
{
matchStr
=
matcher
.
group
(
1
);
if
(
matchStr
.
indexOf
(
"filename"
)
!=
-
1
)
{
filename
=
filename
.
replace
(
"$"
,
"\\$"
).
replaceAll
(
"[\\/:*?\"<>|]"
,
""
);
matcher
.
appendReplacement
(
sb
,
filename
);
}
else
{
matcher
.
appendReplacement
(
sb
,
PathFormat
.
getString
(
matchStr
)
);
}
}
matcher
.
appendTail
(
sb
);
return
sb
.
toString
();
}
private
static
String
getString
(
String
pattern
)
{
pattern
=
pattern
.
toLowerCase
();
// time 处理
if
(
pattern
.
indexOf
(
PathFormat
.
TIME
)
!=
-
1
)
{
return
PathFormat
.
getTimestamp
();
}
else
if
(
pattern
.
indexOf
(
PathFormat
.
FULL_YEAR
)
!=
-
1
)
{
return
PathFormat
.
getFullYear
();
}
else
if
(
pattern
.
indexOf
(
PathFormat
.
YEAR
)
!=
-
1
)
{
return
PathFormat
.
getYear
();
}
else
if
(
pattern
.
indexOf
(
PathFormat
.
MONTH
)
!=
-
1
)
{
return
PathFormat
.
getMonth
();
}
else
if
(
pattern
.
indexOf
(
PathFormat
.
DAY
)
!=
-
1
)
{
return
PathFormat
.
getDay
();
}
else
if
(
pattern
.
indexOf
(
PathFormat
.
HOUR
)
!=
-
1
)
{
return
PathFormat
.
getHour
();
}
else
if
(
pattern
.
indexOf
(
PathFormat
.
MINUTE
)
!=
-
1
)
{
return
PathFormat
.
getMinute
();
}
else
if
(
pattern
.
indexOf
(
PathFormat
.
SECOND
)
!=
-
1
)
{
return
PathFormat
.
getSecond
();
}
else
if
(
pattern
.
indexOf
(
PathFormat
.
RAND
)
!=
-
1
)
{
return
PathFormat
.
getRandom
(
pattern
);
}
return
pattern
;
}
private
static
String
getTimestamp
()
{
return
System
.
currentTimeMillis
()
+
""
;
}
private
static
String
getFullYear
()
{
return
new
SimpleDateFormat
(
"yyyy"
).
format
(
PathFormat
.
currentDate
);
}
private
static
String
getYear
()
{
return
new
SimpleDateFormat
(
"yy"
).
format
(
PathFormat
.
currentDate
);
}
private
static
String
getMonth
()
{
return
new
SimpleDateFormat
(
"MM"
).
format
(
PathFormat
.
currentDate
);
}
private
static
String
getDay
()
{
return
new
SimpleDateFormat
(
"dd"
).
format
(
PathFormat
.
currentDate
);
}
private
static
String
getHour
()
{
return
new
SimpleDateFormat
(
"HH"
).
format
(
PathFormat
.
currentDate
);
}
private
static
String
getMinute
()
{
return
new
SimpleDateFormat
(
"mm"
).
format
(
PathFormat
.
currentDate
);
}
private
static
String
getSecond
()
{
return
new
SimpleDateFormat
(
"ss"
).
format
(
PathFormat
.
currentDate
);
}
private
static
String
getRandom
(
String
pattern
)
{
int
length
=
0
;
pattern
=
pattern
.
split
(
":"
)[
1
].
trim
();
length
=
Integer
.
parseInt
(
pattern
);
return
(
Math
.
random
()
+
""
).
replace
(
"."
,
""
).
substring
(
0
,
length
);
}
public
static
void
main
(
String
[]
args
)
{
// TODO Auto-generated method stub
}
}
src/main/java/io/office/modules/ueditor/com/baidu/ueditor/define/ActionMap.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
ueditor
.
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
);
}
}
src/main/java/io/office/modules/ueditor/com/baidu/ueditor/define/ActionState.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
ueditor
.
com
.
baidu
.
ueditor
.
define
;
public
enum
ActionState
{
UNKNOW_ERROR
}
src/main/java/io/office/modules/ueditor/com/baidu/ueditor/define/AppInfo.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
ueditor
.
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
);
}
}
src/main/java/io/office/modules/ueditor/com/baidu/ueditor/define/BaseState.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
ueditor
.
com
.
baidu
.
ueditor
.
define
;
import
io.office.modules.ueditor.com.baidu.ueditor.Encoder
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Map
;
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
+
""
);
}
}
src/main/java/io/office/modules/ueditor/com/baidu/ueditor/define/FileType.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
ueditor
.
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
();
}
}
src/main/java/io/office/modules/ueditor/com/baidu/ueditor/define/MIMEType.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
ueditor
.
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
);
}
}
src/main/java/io/office/modules/ueditor/com/baidu/ueditor/define/MultiState.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
ueditor
.
com
.
baidu
.
ueditor
.
define
;
import
io.office.modules.ueditor.com.baidu.ueditor.Encoder
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
/**
* 多状态集合状态
* 其包含了多个状态的集合, 其本身自己也是一个状态
* @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
);
}
}
src/main/java/io/office/modules/ueditor/com/baidu/ueditor/define/State.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
ueditor
.
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
();
}
src/main/java/io/office/modules/ueditor/com/baidu/ueditor/hunter/FileManager.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
ueditor
.
com
.
baidu
.
ueditor
.
hunter
;
import
java.io.File
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Map
;
import
io.office.modules.ueditor.com.baidu.ueditor.PathFormat
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.AppInfo
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.BaseState
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.MultiState
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.State
;
import
org.apache.commons.io.FileUtils
;
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"
);
}
public
State
listFile
(
int
index
)
{
File
dir
=
new
File
(
this
.
dir
);
State
state
=
null
;
if
(
!
dir
.
exists
()
)
{
return
new
BaseState
(
false
,
AppInfo
.
NOT_EXIST
);
}
if
(
!
dir
.
isDirectory
()
)
{
return
new
BaseState
(
false
,
AppInfo
.
NOT_DIRECTORY
);
}
Collection
<
File
>
list
=
FileUtils
.
listFiles
(
dir
,
this
.
allowFiles
,
true
);
if
(
index
<
0
||
index
>
list
.
size
()
)
{
state
=
new
MultiState
(
true
);
}
else
{
Object
[]
fileList
=
Arrays
.
copyOfRange
(
list
.
toArray
(),
index
,
index
+
this
.
count
);
state
=
this
.
getState
(
fileList
);
}
state
.
putInfo
(
"start"
,
index
);
state
.
putInfo
(
"total"
,
list
.
size
()
);
return
state
;
}
private
State
getState
(
Object
[]
files
)
{
MultiState
state
=
new
MultiState
(
true
);
BaseState
fileState
=
null
;
File
file
=
null
;
for
(
Object
obj
:
files
)
{
if
(
obj
==
null
)
{
break
;
}
file
=
(
File
)
obj
;
fileState
=
new
BaseState
(
true
);
fileState
.
putInfo
(
"url"
,
PathFormat
.
format
(
this
.
getPath
(
file
)
)
);
state
.
addState
(
fileState
);
}
return
state
;
}
private
String
getPath
(
File
file
)
{
String
path
=
file
.
getAbsolutePath
();
return
path
.
replace
(
this
.
rootPath
,
"/"
);
}
private
String
[]
getAllowFiles
(
Object
fileExt
)
{
String
[]
exts
=
null
;
String
ext
=
null
;
if
(
fileExt
==
null
)
{
return
new
String
[
0
];
}
exts
=
(
String
[])
fileExt
;
for
(
int
i
=
0
,
len
=
exts
.
length
;
i
<
len
;
i
++
)
{
ext
=
exts
[
i
];
exts
[
i
]
=
ext
.
replace
(
"."
,
""
);
}
return
exts
;
}
}
src/main/java/io/office/modules/ueditor/com/baidu/ueditor/hunter/ImageHunter.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
ueditor
.
com
.
baidu
.
ueditor
.
hunter
;
import
java.net.HttpURLConnection
;
import
java.net.InetAddress
;
import
java.net.URL
;
import
java.net.UnknownHostException
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
import
io.office.modules.ueditor.com.baidu.ueditor.PathFormat
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.AppInfo
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.BaseState
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.MIMEType
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.MultiState
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.State
;
import
io.office.modules.ueditor.com.baidu.ueditor.upload.StorageManager
;
/**
* 图片抓取器
* @author hancong03@baidu.com
*
*/
public
class
ImageHunter
{
private
String
filename
=
null
;
private
String
savePath
=
null
;
private
String
rootPath
=
null
;
private
List
<
String
>
allowTypes
=
null
;
private
long
maxSize
=
-
1
;
private
List
<
String
>
filters
=
null
;
public
ImageHunter
(
Map
<
String
,
Object
>
conf
)
{
this
.
filename
=
(
String
)
conf
.
get
(
"filename"
);
this
.
savePath
=
(
String
)
conf
.
get
(
"savePath"
);
this
.
rootPath
=
(
String
)
conf
.
get
(
"rootPath"
);
this
.
maxSize
=
(
Long
)
conf
.
get
(
"maxSize"
);
this
.
allowTypes
=
Arrays
.
asList
(
(
String
[])
conf
.
get
(
"allowFiles"
)
);
this
.
filters
=
Arrays
.
asList
(
(
String
[])
conf
.
get
(
"filter"
)
);
}
public
State
capture
(
String
[]
list
)
{
MultiState
state
=
new
MultiState
(
true
);
for
(
String
source
:
list
)
{
state
.
addState
(
captureRemoteData
(
source
)
);
}
return
state
;
}
public
State
captureRemoteData
(
String
urlStr
)
{
HttpURLConnection
connection
=
null
;
URL
url
=
null
;
String
suffix
=
null
;
try
{
url
=
new
URL
(
urlStr
);
if
(
!
validHost
(
url
.
getHost
()
)
)
{
return
new
BaseState
(
false
,
AppInfo
.
PREVENT_HOST
);
}
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
connection
.
setInstanceFollowRedirects
(
true
);
connection
.
setUseCaches
(
true
);
if
(
!
validContentState
(
connection
.
getResponseCode
()
)
)
{
return
new
BaseState
(
false
,
AppInfo
.
CONNECTION_ERROR
);
}
suffix
=
MIMEType
.
getSuffix
(
connection
.
getContentType
()
);
if
(
!
validFileType
(
suffix
)
)
{
return
new
BaseState
(
false
,
AppInfo
.
NOT_ALLOW_FILE_TYPE
);
}
if
(
!
validFileSize
(
connection
.
getContentLength
()
)
)
{
return
new
BaseState
(
false
,
AppInfo
.
MAX_SIZE
);
}
String
savePath
=
this
.
getPath
(
this
.
savePath
,
this
.
filename
,
suffix
);
String
physicalPath
=
this
.
rootPath
+
savePath
;
State
state
=
StorageManager
.
saveFileByInputStream
(
connection
.
getInputStream
(),
physicalPath
);
if
(
state
.
isSuccess
()
)
{
state
.
putInfo
(
"url"
,
PathFormat
.
format
(
savePath
)
);
state
.
putInfo
(
"source"
,
urlStr
);
}
return
state
;
}
catch
(
Exception
e
)
{
return
new
BaseState
(
false
,
AppInfo
.
REMOTE_FAIL
);
}
}
private
String
getPath
(
String
savePath
,
String
filename
,
String
suffix
)
{
return
PathFormat
.
parse
(
savePath
+
suffix
,
filename
);
}
private
boolean
validHost
(
String
hostname
)
{
try
{
InetAddress
ip
=
InetAddress
.
getByName
(
hostname
);
if
(
ip
.
isSiteLocalAddress
())
{
return
false
;
}
}
catch
(
UnknownHostException
e
)
{
return
false
;
}
return
!
filters
.
contains
(
hostname
);
}
private
boolean
validContentState
(
int
code
)
{
return
HttpURLConnection
.
HTTP_OK
==
code
;
}
private
boolean
validFileType
(
String
type
)
{
return
this
.
allowTypes
.
contains
(
type
);
}
private
boolean
validFileSize
(
int
size
)
{
return
size
<
this
.
maxSize
;
}
}
src/main/java/io/office/modules/ueditor/com/baidu/ueditor/upload/Base64Uploader.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
ueditor
.
com
.
baidu
.
ueditor
.
upload
;
import
io.office.modules.ueditor.com.baidu.ueditor.PathFormat
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.AppInfo
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.BaseState
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.FileType
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.State
;
import
java.util.Map
;
import
org.apache.commons.codec.binary.Base64
;
public
final
class
Base64Uploader
{
public
static
State
save
(
String
content
,
Map
<
String
,
Object
>
conf
)
{
byte
[]
data
=
decode
(
content
);
long
maxSize
=
((
Long
)
conf
.
get
(
"maxSize"
)).
longValue
();
if
(!
validSize
(
data
,
maxSize
))
{
return
new
BaseState
(
false
,
AppInfo
.
MAX_SIZE
);
}
String
suffix
=
FileType
.
getSuffix
(
"JPG"
);
String
savePath
=
PathFormat
.
parse
((
String
)
conf
.
get
(
"savePath"
),
(
String
)
conf
.
get
(
"filename"
));
savePath
=
savePath
+
suffix
;
String
physicalPath
=
(
String
)
conf
.
get
(
"rootPath"
)
+
savePath
;
State
storageState
=
StorageManager
.
saveBinaryFile
(
data
,
physicalPath
);
if
(
storageState
.
isSuccess
())
{
storageState
.
putInfo
(
"url"
,
PathFormat
.
format
(
savePath
));
storageState
.
putInfo
(
"type"
,
suffix
);
storageState
.
putInfo
(
"original"
,
""
);
}
return
storageState
;
}
private
static
byte
[]
decode
(
String
content
)
{
return
Base64
.
decodeBase64
(
content
);
}
private
static
boolean
validSize
(
byte
[]
data
,
long
length
)
{
return
data
.
length
<=
length
;
}
}
\ No newline at end of file
src/main/java/io/office/modules/ueditor/com/baidu/ueditor/upload/BinaryUploader.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
ueditor
.
com
.
baidu
.
ueditor
.
upload
;
import
io.office.modules.ueditor.com.baidu.ueditor.PathFormat
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.AppInfo
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.BaseState
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.FileType
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.State
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
org.apache.commons.fileupload.FileItemIterator
;
import
org.apache.commons.fileupload.FileItemStream
;
import
org.apache.commons.fileupload.FileUploadException
;
import
org.apache.commons.fileupload.disk.DiskFileItemFactory
;
import
org.apache.commons.fileupload.servlet.ServletFileUpload
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartHttpServletRequest
;
public
class
BinaryUploader
{
public
static
final
State
save
(
HttpServletRequest
request
,
Map
<
String
,
Object
>
conf
)
{
// FileItemStream fileStream = null;
// boolean isAjaxUpload = request.getHeader( "X_Requested_With" ) != null;
if
(!
ServletFileUpload
.
isMultipartContent
(
request
))
{
return
new
BaseState
(
false
,
AppInfo
.
NOT_MULTIPART_CONTENT
);
}
// ServletFileUpload upload = new ServletFileUpload(
// new DiskFileItemFactory());
//
// if ( isAjaxUpload ) {
// upload.setHeaderEncoding( "UTF-8" );
// }
try
{
// FileItemIterator iterator = upload.getItemIterator(request);
//
// while (iterator.hasNext()) {
// fileStream = iterator.next();
//
// if (!fileStream.isFormField())
// break;
// fileStream = null;
// }
//
// if (fileStream == null) {
// return new BaseState(false, AppInfo.NOTFOUND_UPLOAD_DATA);
// }
MultipartHttpServletRequest
multipartRequest
=
(
MultipartHttpServletRequest
)
request
;
MultipartFile
multipartFile
=
multipartRequest
.
getFile
(
conf
.
get
(
"fieldName"
).
toString
());
if
(
multipartFile
==
null
){
return
new
BaseState
(
false
,
AppInfo
.
NOTFOUND_UPLOAD_DATA
);
}
String
savePath
=
(
String
)
conf
.
get
(
"savePath"
);
//String originFileName = fileStream.getName();
String
originFileName
=
multipartFile
.
getOriginalFilename
();
String
suffix
=
FileType
.
getSuffixByFilename
(
originFileName
);
originFileName
=
originFileName
.
substring
(
0
,
originFileName
.
length
()
-
suffix
.
length
());
savePath
=
savePath
+
suffix
;
long
maxSize
=
((
Long
)
conf
.
get
(
"maxSize"
)).
longValue
();
if
(!
validType
(
suffix
,
(
String
[])
conf
.
get
(
"allowFiles"
)))
{
return
new
BaseState
(
false
,
AppInfo
.
NOT_ALLOW_FILE_TYPE
);
}
savePath
=
PathFormat
.
parse
(
savePath
,
originFileName
);
String
physicalPath
=
(
String
)
conf
.
get
(
"rootPath"
)
+
savePath
;
//InputStream is = fileStream.openStream();
InputStream
is
=
multipartFile
.
getInputStream
();
State
storageState
=
StorageManager
.
saveFileByInputStream
(
is
,
physicalPath
,
maxSize
);
is
.
close
();
if
(
storageState
.
isSuccess
())
{
storageState
.
putInfo
(
"url"
,
PathFormat
.
format
(
savePath
));
storageState
.
putInfo
(
"type"
,
suffix
);
storageState
.
putInfo
(
"original"
,
originFileName
+
suffix
);
}
return
storageState
;
// } catch (FileUploadException e) {
// return new BaseState(false, AppInfo.PARSE_REQUEST_ERROR);
}
catch
(
IOException
e
)
{
}
return
new
BaseState
(
false
,
AppInfo
.
IO_ERROR
);
}
private
static
boolean
validType
(
String
type
,
String
[]
allowTypes
)
{
List
<
String
>
list
=
Arrays
.
asList
(
allowTypes
);
return
list
.
contains
(
type
);
}
}
src/main/java/io/office/modules/ueditor/com/baidu/ueditor/upload/StorageManager.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
ueditor
.
com
.
baidu
.
ueditor
.
upload
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.AppInfo
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.BaseState
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.State
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.State
;
import
org.apache.commons.io.FileUtils
;
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
);
}
}
src/main/java/io/office/modules/ueditor/com/baidu/ueditor/upload/Uploader.java
0 → 100644
View file @
1d157555
package
io
.
office
.
modules
.
ueditor
.
com
.
baidu
.
ueditor
.
upload
;
import
io.office.modules.ueditor.com.baidu.ueditor.define.State
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
public
class
Uploader
{
private
HttpServletRequest
request
=
null
;
private
Map
<
String
,
Object
>
conf
=
null
;
public
Uploader
(
HttpServletRequest
request
,
Map
<
String
,
Object
>
conf
)
{
this
.
request
=
request
;
this
.
conf
=
conf
;
}
public
final
State
doExec
()
{
String
filedName
=
(
String
)
this
.
conf
.
get
(
"fieldName"
);
State
state
=
null
;
if
(
"true"
.
equals
(
this
.
conf
.
get
(
"isBase64"
)))
{
state
=
Base64Uploader
.
save
(
this
.
request
.
getParameter
(
filedName
),
this
.
conf
);
}
else
{
state
=
BinaryUploader
.
save
(
this
.
request
,
this
.
conf
);
}
return
state
;
}
}
src/main/resources/application-dev.yml
View file @
1d157555
...
...
@@ -56,6 +56,8 @@ request:
prefix
:
uploadFileResource
file
:
save
:
path
:
/
path
:
/
uploadFileResource/
request
:
prefix
:
http://81.68.189.225:9091/office/uploadFileResource/
ueditorSavePath
:
/uploadFileResource/
\ No newline at end of file
src/main/resources/mapper/manage/BikecodeDao.xml
deleted
100644 → 0
View file @
3dc3947c
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"io.office.modules.manage.dao.BikecodeDao"
>
<!-- 可根据自己的需求,是否要使用 -->
<resultMap
type=
"io.office.modules.manage.entity.BikecodeEntity"
id=
"bikecodeMap"
>
<result
property=
"bikeid"
column=
"bikeid"
/>
<result
property=
"code"
column=
"code"
/>
</resultMap>
</mapper>
\ No newline at end of file
src/main/resources/mapper/manage/BranchDao.xml
0 → 100644
View file @
1d157555
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"io.office.modules.manage.dao.BranchDao"
>
<!-- 可根据自己的需求,是否要使用 -->
<resultMap
type=
"io.office.modules.manage.entity.BranchEntity"
id=
"branchMap"
>
<result
property=
"branchCode"
column=
"branch_code"
/>
<result
property=
"branchName"
column=
"branch_name"
/>
<result
property=
"branchAddress"
column=
"branch_address"
/>
<result
property=
"branchPostcode"
column=
"branch_postcode"
/>
<result
property=
"branchContact"
column=
"branch_contact"
/>
<result
property=
"tel1"
column=
"tel1"
/>
<result
property=
"tel2"
column=
"tel2"
/>
<result
property=
"fax"
column=
"fax"
/>
<result
property=
"rockkey"
column=
"rockkey"
/>
<result
property=
"branchSimname"
column=
"branch_simname"
/>
</resultMap>
</mapper>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment