Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzlite
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzlite
提交
c6531eaf
提交
c6531eaf
编写于
9月 24, 2020
作者:
sq3536
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reset
上级
898e4350
变更
4
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
670 行增加
和
491 行删除
+670
-491
getters.ts
app_web/src/store/getters.ts
+0
-113
mutations.ts
app_web/src/store/mutations.ts
+0
-294
auth-guard.ts
app_web/src/utils/auth-guard/auth-guard.ts
+0
-84
Inflector.java
...src/main/java/cn/ibizlab/core/lite/service/Inflector.java
+670
-0
未找到文件。
app_web/src/store/getters.ts
已删除
100644 → 0
浏览文件 @
898e4350
/**
* 获取部门成员
*
* @param state
*/
export
const
getDepartmentPersonnel
=
(
state
:
any
)
=>
()
=>
{
return
state
.
departmentPersonnel
;
}
/**
* 获取代码表对象
*
* @param state
*/
export
const
getCodeList
=
(
state
:
any
)
=>
(
srfkey
:
string
)
=>
{
return
state
.
codelists
.
find
((
_codelist
:
any
)
=>
Object
.
is
(
_codelist
.
srfkey
,
srfkey
));
}
/**
* 获取代码表
*
* @param state
*/
export
const
getCodeListItems
=
(
state
:
any
)
=>
(
srfkey
:
string
)
=>
{
let
items
:
any
[]
=
[];
const
codelist
=
state
.
codelists
.
find
((
_codelist
:
any
)
=>
Object
.
is
(
_codelist
.
srfkey
,
srfkey
));
if
(
!
codelist
)
{
console
.
log
(
`----
${
srfkey
}
----代码表不存在`
);
}
else
{
items
=
[...
codelist
.
items
];
}
return
items
;
}
/**
* 获取本地应用数据
*
* @param state
*/
export
const
getLocalData
=
(
state
:
any
)
=>
()
=>
{
return
state
.
localdata
;
}
/**
* 获取应用数据
*
* @param state
*/
export
const
getAppData
=
(
state
:
any
)
=>
()
=>
{
let
result
:
any
=
JSON
.
parse
(
JSON
.
stringify
(
state
.
appdata
));
if
(
state
.
localdata
&&
Object
.
keys
(
state
.
localdata
).
length
>
0
){
let
copyContext
:
any
=
result
.
context
?
result
.
context
:{};
Object
.
assign
(
copyContext
,
state
.
localdata
);
result
.
context
=
copyContext
;
}
return
result
;
}
/**
* 获取导航标签页面
*
* @param state
*/
export
const
getPage
=
(
state
:
any
)
=>
(
arg
:
any
)
=>
{
let
page
:
any
=
null
;
if
(
isNaN
(
arg
))
{
const
index
=
state
.
pageTagList
.
findIndex
((
page
:
any
)
=>
Object
.
is
(
page
.
fullPath
,
arg
));
if
(
index
>=
0
)
{
page
=
state
.
pageTagList
[
index
];
}
}
else
{
page
=
state
.
pageTagList
[
arg
];
}
return
page
;
}
/**
* 获取 z-index
*
* @param state
*/
export
const
getZIndex
=
(
state
:
any
)
=>
()
=>
{
return
state
.
zIndex
;
}
/**
* 获取视图split
*
* @param state
*/
export
const
getViewSplit
=
(
state
:
any
)
=>
(
viewUID
:
string
)
=>
{
return
state
.
viewSplit
[
viewUID
];
}
/**
* 获取单位数据
*
* @param state
*/
export
const
getOrgData
=
(
state
:
any
)
=>
(
srfkey
:
string
)
=>
{
let
orgData
=
state
.
orgDataMap
[
srfkey
];
return
orgData
;
}
/**
* 获取部门数据
*
* @param state
*/
export
const
getDepData
=
(
state
:
any
)
=>
(
srfkey
:
string
)
=>
{
let
depData
=
state
.
depDataMap
[
srfkey
];
return
depData
;
}
\ No newline at end of file
app_web/src/store/mutations.ts
已删除
100644 → 0
浏览文件 @
898e4350
import
{
Environment
}
from
'@/environments/environment'
;
/**
* 添加部门成员
*
* @param state
* @param codelists
*/
export
const
addDepartmentPersonnel
=
(
state
:
any
,
departmentPersonnel
:
Array
<
any
>
)
=>
{
state
.
departmentPersonnel
=
[];
state
.
departmentPersonnel
=
[...
departmentPersonnel
];
}
/**
* 添加代码表
*
* @param state
* @param codelists
*/
export
const
addCodeLists
=
(
state
:
any
,
codelists
:
any
)
=>
{
state
.
codelists
=
[];
state
.
codelists
=
[...
codelists
];
}
/**
* 添加本地应用数据
*
* @param state
* @param localdata
*/
export
const
addLocalData
=
(
state
:
any
,
localdata
:
any
=
{})
=>
{
Object
.
assign
(
state
.
localdata
,
localdata
);
localStorage
.
setItem
(
'localdata'
,
JSON
.
stringify
(
state
.
localdata
));
}
/**
* 添加应用数据
*
* @param state
* @param localdata
*/
export
const
addAppData
=
(
state
:
any
,
appdata
:
string
)
=>
{
state
.
appdata
=
appdata
;
}
/**
* 修改应用数据
*
* @param state
* @param localdata
*/
export
const
updateAppData
=
(
state
:
any
,
appdata
:
string
)
=>
{
state
.
appdata
=
appdata
;
}
/**
* 更新代码表值
*
* @param state
* @param param1
*/
export
const
updateCodeList
=
(
state
:
any
,
{
srfkey
,
items
}:
{
srfkey
:
string
,
items
:
any
[]
})
=>
{
const
index
=
state
.
codelists
.
findIndex
((
_codelist
:
any
)
=>
Object
.
is
(
_codelist
.
srfkey
,
srfkey
));
if
(
index
===
-
1
)
{
console
.
log
(
`
${
srfkey
}
---- 代码表不存在`
);
return
;
}
state
.
codelists
[
index
].
items
=
[...
items
];
}
/**
* 修改主题
*
* @param state
* @param val
*/
export
const
setCurrentSelectTheme
=
(
state
:
any
,
val
:
any
)
=>
{
state
.
selectTheme
=
val
;
}
/**
* 修改字体
*
* @param state
* @param val
*/
export
const
setCurrentSelectFont
=
(
state
:
any
,
val
:
any
)
=>
{
state
.
selectFont
=
val
;
}
/**
* 重置分页导航数据
*
* @param state
*/
export
const
resetRootStateData
=
(
state
:
any
)
=>
{
state
.
pageTagList
=
[];
state
.
pageMetas
=
[];
state
.
historyPathList
=
[];
}
/**
* 添加导航页面
*
* @param state
* @param arg
*/
export
const
addPage
=
(
state
:
any
,
arg
:
any
)
=>
{
if
(
!
arg
)
{
return
;
}
// 视图类型为REDIRECTVIEW和NOTAB的视图不添加缓存
if
(
Object
.
is
(
arg
.
meta
.
viewType
,
'REDIRECTVIEW'
)
||
Object
.
is
(
arg
.
meta
.
viewType
,
'NOTAB'
)){
return
;
}
else
if
(
Object
.
is
(
arg
.
meta
.
viewType
,
'APPINDEX'
))
{
window
.
sessionStorage
.
setItem
(
Environment
.
AppName
,
arg
.
fullPath
);
}
else
{
const
page
:
any
=
{};
const
pageMeta
:
any
=
{};
Object
.
assign
(
page
,
arg
);
Object
.
assign
(
pageMeta
,
page
.
meta
,
{
info
:
null
});
const
index
=
state
.
pageTagList
.
findIndex
((
tag
:
any
)
=>
Object
.
is
(
tag
.
fullPath
,
page
.
fullPath
));
if
(
index
<
0
)
{
state
.
pageTagList
.
push
(
page
);
state
.
pageMetas
.
push
(
pageMeta
);
}
else
{
const
index2
=
state
.
historyPathList
.
indexOf
(
page
.
fullPath
);
if
(
index2
>=
0
)
{
state
.
historyPathList
.
splice
(
index2
,
1
);
}
}
state
.
historyPathList
.
push
(
page
.
fullPath
);
}
}
/**
* 删除导航页面
*
* @param state
* @param arg
*/
export
const
deletePage
=
(
state
:
any
,
arg
:
any
)
=>
{
let
delPage
:
any
=
null
;
if
(
isNaN
(
arg
))
{
const
index
=
state
.
pageTagList
.
findIndex
((
page
:
any
)
=>
Object
.
is
(
page
.
fullPath
,
arg
));
if
(
index
>=
0
)
{
delPage
=
state
.
pageTagList
[
index
];
state
.
pageTagList
.
splice
(
index
,
1
);
state
.
pageMetas
.
splice
(
index
,
1
);
}
}
else
{
delPage
=
state
.
pageTagList
[
arg
];
state
.
pageTagList
.
splice
(
arg
,
1
);
state
.
pageMetas
.
splice
(
arg
,
1
);
}
const
index
=
state
.
historyPathList
.
findIndex
((
path
:
any
)
=>
Object
.
is
(
path
,
delPage
.
fullPath
));
if
(
index
>=
0
)
{
state
.
historyPathList
.
splice
(
index
,
1
);
}
}
/**
* 设置导航页面
*
* @param state
* @param arg
*/
export
const
setCurPage
=
(
state
:
any
,
arg
:
any
)
=>
{
let
page
:
any
=
null
;
if
(
isNaN
(
arg
))
{
const
index
=
state
.
pageTagList
.
findIndex
((
page
:
any
)
=>
Object
.
is
(
page
.
fullPath
,
arg
));
if
(
index
>=
0
)
{
page
=
state
.
pageTagList
[
index
];
}
}
else
{
page
=
state
.
pageTagList
[
arg
];
}
if
(
page
)
{
const
index
=
state
.
historyPathList
.
findIndex
((
path
:
any
)
=>
Object
.
is
(
path
,
page
.
fullPath
));
if
(
index
>=
0
)
{
state
.
historyPathList
.
splice
(
index
,
1
);
state
.
historyPathList
.
push
(
page
.
fullPath
);
}
}
}
/**
* 设置导航页面标题
*
* @param state
* @param param1
*/
export
const
setCurPageCaption
=
(
state
:
any
,
{
route
,
caption
,
info
}:
{
route
:
any
,
caption
:
string
|
null
,
info
:
string
|
null
})
=>
{
if
(
route
)
{
const
index
=
state
.
pageTagList
.
findIndex
((
page
:
any
)
=>
Object
.
is
(
page
.
fullPath
,
route
.
fullPath
));
if
(
index
>=
0
)
{
state
.
pageMetas
[
index
].
caption
=
caption
;
state
.
pageMetas
[
index
].
info
=
info
;
}
}
}
/**
* 添加当前视图视图标识
*
* @param state
* @param param1
*/
export
const
addCurPageViewtag
=
(
state
:
any
,
{
fullPath
,
viewtag
}:
{
fullPath
:
string
,
viewtag
:
string
})
=>
{
const
index
=
state
.
pageTagList
.
findIndex
((
page
:
any
)
=>
Object
.
is
(
page
.
fullPath
,
fullPath
));
if
(
index
>=
0
)
{
state
.
pageTagList
[
index
].
viewtag
=
viewtag
;
}
}
/**
* 删除所有导航页面
*
* @param state
*/
export
const
removeAllPage
=
(
state
:
any
)
=>
{
if
(
state
.
pageTagList
.
length
>
0
)
{
state
.
pageMetas
=
[];
state
.
pageTagList
=
[];
state
.
historyPathList
=
[];
}
}
/**
* 删除其他导航页面
*
* @param state
*/
export
const
removeOtherPage
=
(
state
:
any
)
=>
{
if
(
state
.
historyPathList
.
length
>
0
)
{
const
curPath
=
state
.
historyPathList
[
state
.
historyPathList
.
length
-
1
];
const
index
=
state
.
pageTagList
.
findIndex
((
page
:
any
)
=>
Object
.
is
(
page
.
fullPath
,
curPath
));
if
(
index
>=
0
)
{
const
page
=
state
.
pageTagList
[
index
];
const
meta
:
any
=
{};
Object
.
assign
(
meta
,
page
.
meta
);
state
.
pageTagList
=
[];
state
.
pageMetas
=
[];
state
.
historyPathList
=
[];
state
.
historyPathList
.
push
(
page
.
fullPath
);
state
.
pageTagList
.
push
(
page
);
state
.
pageMetas
.
push
(
meta
);
}
}
}
/**
* 更新 z-index
*
* @param state
* @param zIndex
*/
export
const
updateZIndex
=
(
state
:
any
,
zIndex
:
number
)
=>
{
state
.
zIndex
=
zIndex
;
}
/**
* 设置视图split
*
* @param state
* @param {viewSplit: number, viewUID: string}
*/
export
const
setViewSplit
=
(
state
:
any
,
args
:
{
viewSplit
:
number
,
viewUID
:
string
})
=>
{
state
.
viewSplit
[
args
.
viewUID
]
=
args
.
viewSplit
;
}
/**
* 添加单位数据
*
* @param state
* @param args
*/
export
const
addOrgData
=
(
state
:
any
,
args
:
{
srfkey
:
string
,
orgData
:
any
})
=>
{
if
(
args
&&
args
.
srfkey
&&
args
.
orgData
){
state
.
orgDataMap
[
args
.
srfkey
]
=
JSON
.
parse
(
JSON
.
stringify
(
args
.
orgData
));
}
}
/**
* 添加部门数据
*
* @param state
* @param args
*/
export
const
addDepData
=
(
state
:
any
,
args
:
{
srfkey
:
string
,
depData
:
any
})
=>
{
if
(
args
&&
args
.
srfkey
&&
args
.
depData
){
state
.
depDataMap
[
args
.
srfkey
]
=
JSON
.
parse
(
JSON
.
stringify
(
args
.
depData
));
}
}
\ No newline at end of file
app_web/src/utils/auth-guard/auth-guard.ts
已删除
100644 → 0
浏览文件 @
898e4350
import
{
Http
}
from
'../http/http'
;
/**
* AuthGuard net 对象
* 调用 getInstance() 获取实例
*
* @class Http
*/
export
class
AuthGuard
{
/**
* 获取 Auth 单例对象
*
* @static
* @returns {Auth}
* @memberof Auth
*/
public
static
getInstance
():
AuthGuard
{
if
(
!
AuthGuard
.
auth
)
{
AuthGuard
.
auth
=
new
AuthGuard
();
}
return
this
.
auth
;
}
/**
* 单例变量声明
*
* @private
* @static
* @type {AuthGuard}
* @memberof AuthGuard
*/
private
static
auth
:
AuthGuard
;
/**
* Creates an instance of AuthGuard.
* 私有构造,拒绝通过 new 创建对象
*
* @memberof AuthGuard
*/
private
constructor
()
{
}
/**
* post请求
*
* @param {string} url url 请求路径
* @param {*} [params={}] 请求参数
* @returns {Promise<any>} 请求相响应对象
* @memberof AuthGuard
*/
public
authGuard
(
url
:
string
,
params
:
any
=
{},
router
:
any
):
Promise
<
boolean
>
{
return
new
Promise
((
resolve
:
any
,
reject
:
any
)
=>
{
const
get
:
Promise
<
any
>
=
Http
.
getInstance
().
get
(
url
);
get
.
then
((
response
:
any
)
=>
{
if
(
response
&&
response
.
status
===
200
)
{
let
{
data
}:
{
data
:
any
}
=
response
;
if
(
data
)
{
// token认证把用户信息放入应用级数据
if
(
localStorage
.
getItem
(
'user'
)){
let
user
:
any
=
JSON
.
parse
(
localStorage
.
getItem
(
'user'
)
as
string
);
let
localAppData
:
any
=
{};
if
(
user
.
sessionParams
){
localAppData
=
{
context
:
user
.
sessionParams
};
Object
.
assign
(
localAppData
,
data
);
}
data
=
JSON
.
parse
(
JSON
.
stringify
(
localAppData
));
}
if
(
localStorage
.
getItem
(
'localdata'
)){
router
.
app
.
$store
.
commit
(
'addLocalData'
,
JSON
.
parse
(
localStorage
.
getItem
(
'localdata'
)
as
string
));
}
router
.
app
.
$store
.
commit
(
'addAppData'
,
data
);
// 提交统一资源数据
router
.
app
.
$store
.
dispatch
(
'authresource/commitAuthData'
,
data
);
}
}
resolve
(
true
);
}).
catch
((
error
:
any
)
=>
{
resolve
(
true
);
console
.
error
(
"获取应用数据出现异常"
);
});
});
}
}
ibzlite-core/src/main/java/cn/ibizlab/core/lite/service/Inflector.java
0 → 100644
浏览文件 @
c6531eaf
package
cn
.
ibizlab
.
core
.
lite
.
service
;
/*
* JBoss DNA (http://www.jboss.org/dna)
* See the COPYRIGHT.txt file distributed with this work for information
* regarding copyright ownership. Some portions may be licensed
* to Red Hat, Inc. under one or more contributor license agreements.
* See the AUTHORS.txt file in the distribution for a full listing of
* individual contributors.
*
* JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
* is licensed to you under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* JBoss DNA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
import
java.util.HashSet
;
import
java.util.LinkedList
;
import
java.util.Set
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* Transforms words to singular, plural, humanized (human readable), underscore,
* camel case, or ordinal form. This is inspired by the
* <a href="http://api.rubyonrails.org/classes/Inflector.html">Inflector</a>
* class in <a href="http://www.rubyonrails.org">Ruby on Rails</a>, which is
* distributed under the
* <a href="http://wiki.rubyonrails.org/rails/pages/License">Rails license</a>.
*
* @author Randall Hauch
*/
public
class
Inflector
{
protected
static
final
Inflector
INSTANCE
=
new
Inflector
();
public
static
final
Inflector
getInstance
()
{
return
INSTANCE
;
}
protected
class
Rule
{
protected
final
String
expression
;
protected
final
Pattern
expressionPattern
;
protected
final
String
replacement
;
protected
Rule
(
String
expression
,
String
replacement
)
{
this
.
expression
=
expression
;
this
.
replacement
=
replacement
!=
null
?
replacement
:
""
;
this
.
expressionPattern
=
Pattern
.
compile
(
this
.
expression
,
Pattern
.
CASE_INSENSITIVE
);
}
/**
* Apply the rule against the input string, returning the modified string or
* null if the rule didn't apply (and no modifications were made)
*
* @param input the input string
* @return the modified string if this rule applied, or null if the input was
* not modified by this rule
*/
protected
String
apply
(
String
input
)
{
Matcher
matcher
=
this
.
expressionPattern
.
matcher
(
input
);
if
(!
matcher
.
find
())
{
return
null
;
}
return
matcher
.
replaceAll
(
this
.
replacement
);
}
@Override
public
int
hashCode
()
{
return
expression
.
hashCode
();
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
obj
==
this
)
{
return
true
;
}
if
(
obj
!=
null
&&
obj
.
getClass
()
==
this
.
getClass
())
{
final
Rule
that
=
(
Rule
)
obj
;
if
(
this
.
expression
.
equalsIgnoreCase
(
that
.
expression
))
{
return
true
;
}
}
return
false
;
}
@Override
public
String
toString
()
{
return
expression
+
", "
+
replacement
;
}
}
private
LinkedList
<
Rule
>
plurals
=
new
LinkedList
<
Rule
>();
private
LinkedList
<
Rule
>
singulars
=
new
LinkedList
<
Rule
>();
/**
* The lowercase words that are to be excluded and not processed. This map can
* be modified by the users via {@link #getUncountables()}.
*/
private
final
Set
<
String
>
uncountables
=
new
HashSet
<
String
>();
public
Inflector
()
{
initialize
();
}
protected
Inflector
(
Inflector
original
)
{
this
.
plurals
.
addAll
(
original
.
plurals
);
this
.
singulars
.
addAll
(
original
.
singulars
);
this
.
uncountables
.
addAll
(
original
.
uncountables
);
}
@Override
public
Inflector
clone
()
{
return
new
Inflector
(
this
);
}
// ------------------------------------------------------------------------------------------------
// Usage functions
// ------------------------------------------------------------------------------------------------
/**
* Returns the plural form of the word in the string.
*
* Examples:
*
* <pre>
* inflector.pluralize("post") #=> "posts"
* inflector.pluralize("octopus") #=> "octopi"
* inflector.pluralize("sheep") #=> "sheep"
* inflector.pluralize("words") #=> "words"
* inflector.pluralize("the blue mailman") #=> "the blue mailmen"
* inflector.pluralize("CamelOctopus") #=> "CamelOctopi"
* </pre>
*
*
*
* Note that if the {@link Object#toString()} is called on the supplied object,
* so this method works for non-strings, too.
*
*
* @param word the word that is to be pluralized.
* @return the pluralized form of the word, or the word itself if it could not
* be pluralized
* @see #singularize(Object)
*/
public
String
pluralize
(
Object
word
)
{
if
(
word
==
null
)
{
return
null
;
}
String
wordStr
=
word
.
toString
().
trim
();
if
(
wordStr
.
length
()
==
0
)
{
return
wordStr
;
}
if
(
isUncountable
(
wordStr
))
{
return
wordStr
;
}
for
(
Rule
rule
:
this
.
plurals
)
{
String
result
=
rule
.
apply
(
wordStr
);
if
(
result
!=
null
)
{
return
result
;
}
}
return
wordStr
;
}
public
String
pluralize
(
Object
word
,
int
count
)
{
if
(
word
==
null
)
{
return
null
;
}
if
(
count
==
1
||
count
==
-
1
)
{
return
word
.
toString
();
}
return
pluralize
(
word
);
}
/**
* Returns the singular form of the word in the string.
*
* Examples:
*
* <pre>
* inflector.singularize("posts") #=> "post"
* inflector.singularize("octopi") #=> "octopus"
* inflector.singularize("sheep") #=> "sheep"
* inflector.singularize("words") #=> "word"
* inflector.singularize("the blue mailmen") #=> "the blue mailman"
* inflector.singularize("CamelOctopi") #=> "CamelOctopus"
* </pre>
*
*
*
* Note that if the {@link Object#toString()} is called on the supplied object,
* so this method works for non-strings, too.
*
*
* @param word the word that is to be pluralized.
* @return the pluralized form of the word, or the word itself if it could not
* be pluralized
* @see #pluralize(Object)
*/
public
String
singularize
(
Object
word
)
{
if
(
word
==
null
)
{
return
null
;
}
String
wordStr
=
word
.
toString
().
trim
();
if
(
wordStr
.
length
()
==
0
)
{
return
wordStr
;
}
if
(
isUncountable
(
wordStr
))
{
return
wordStr
;
}
for
(
Rule
rule
:
this
.
singulars
)
{
String
result
=
rule
.
apply
(
wordStr
);
if
(
result
!=
null
)
{
return
result
;
}
}
return
wordStr
;
}
/**
* Converts strings to lowerCamelCase. This method will also use any extra
* delimiter characters to identify word boundaries.
*
* Examples:
*
* <pre>
* inflector.lowerCamelCase("active_record") #=> "activeRecord"
* inflector.lowerCamelCase("first_name") #=> "firstName"
* inflector.lowerCamelCase("name") #=> "name"
* inflector.lowerCamelCase("the-first_name",'-') #=> "theFirstName"
* </pre>
*
*
*
* @param lowerCaseAndUnderscoredWord the word that is to be converted to camel
* case
* @param delimiterChars optional characters that are used to
* delimit word boundaries
* @return the lower camel case version of the word
* @see #underscore(String, char[])
* @see #camelCase(String, boolean, char[])
* @see #upperCamelCase(String, char[])
*/
public
String
lowerCamelCase
(
String
lowerCaseAndUnderscoredWord
,
char
...
delimiterChars
)
{
return
camelCase
(
lowerCaseAndUnderscoredWord
,
false
,
delimiterChars
);
}
/**
* Converts strings to UpperCamelCase. This method will also use any extra
* delimiter characters to identify word boundaries.
*
* Examples:
*
* <pre>
* inflector.upperCamelCase("active_record") #=> "SctiveRecord"
* inflector.upperCamelCase("first_name") #=> "FirstName"
* inflector.upperCamelCase("name") #=> "Name"
* inflector.lowerCamelCase("the-first_name",'-') #=> "TheFirstName"
* </pre>
*
*
*
* @param lowerCaseAndUnderscoredWord the word that is to be converted to camel
* case
* @param delimiterChars optional characters that are used to
* delimit word boundaries
* @return the upper camel case version of the word
* @see #underscore(String, char[])
* @see #camelCase(String, boolean, char[])
* @see #lowerCamelCase(String, char[])
*/
public
String
upperCamelCase
(
String
lowerCaseAndUnderscoredWord
,
char
...
delimiterChars
)
{
return
camelCase
(
lowerCaseAndUnderscoredWord
,
true
,
delimiterChars
);
}
/**
* By default, this method converts strings to UpperCamelCase. If the
* <code>uppercaseFirstLetter</code> argument to false, then this method
* produces lowerCamelCase. This method will also use any extra delimiter
* characters to identify word boundaries.
*
* Examples:
*
* <pre>
* inflector.camelCase("active_record",false) #=> "activeRecord"
* inflector.camelCase("active_record",true) #=> "ActiveRecord"
* inflector.camelCase("first_name",false) #=> "firstName"
* inflector.camelCase("first_name",true) #=> "FirstName"
* inflector.camelCase("name",false) #=> "name"
* inflector.camelCase("name",true) #=> "Name"
* </pre>
*
*
*
* @param lowerCaseAndUnderscoredWord the word that is to be converted to camel
* case
* @param uppercaseFirstLetter true if the first character is to be
* uppercased, or false if the first
* character is to be lowercased
* @param delimiterChars optional characters that are used to
* delimit word boundaries
* @return the camel case version of the word
* @see #underscore(String, char[])
* @see #upperCamelCase(String, char[])
* @see #lowerCamelCase(String, char[])
*/
public
String
camelCase
(
String
lowerCaseAndUnderscoredWord
,
boolean
uppercaseFirstLetter
,
char
...
delimiterChars
)
{
if
(
lowerCaseAndUnderscoredWord
==
null
)
{
return
null
;
}
lowerCaseAndUnderscoredWord
=
lowerCaseAndUnderscoredWord
.
trim
();
if
(
lowerCaseAndUnderscoredWord
.
length
()
==
0
)
{
return
""
;
}
if
(
uppercaseFirstLetter
)
{
String
result
=
lowerCaseAndUnderscoredWord
;
// Replace any extra delimiters with underscores (before the underscores are
// converted in the next step)...
if
(
delimiterChars
!=
null
)
{
for
(
char
delimiterChar
:
delimiterChars
)
{
result
=
result
.
replace
(
delimiterChar
,
'_'
);
}
}
// Change the case at the beginning at after each underscore ...
return
replaceAllWithUppercase
(
result
,
"(^|_)(.)"
,
2
);
}
if
(
lowerCaseAndUnderscoredWord
.
length
()
<
2
)
{
return
lowerCaseAndUnderscoredWord
;
}
return
""
+
Character
.
toLowerCase
(
lowerCaseAndUnderscoredWord
.
charAt
(
0
))
+
camelCase
(
lowerCaseAndUnderscoredWord
,
true
,
delimiterChars
).
substring
(
1
);
}
/**
* Makes an underscored form from the expression in the string (the reverse of
* the {@link #camelCase(String, boolean, char[]) camelCase} method. Also
* changes any characters that match the supplied delimiters into underscore.
*
* Examples:
*
* <pre>
* inflector.underscore("activeRecord") #=> "active_record"
* inflector.underscore("ActiveRecord") #=> "active_record"
* inflector.underscore("firstName") #=> "first_name"
* inflector.underscore("FirstName") #=> "first_name"
* inflector.underscore("name") #=> "name"
* inflector.underscore("The.firstName") #=> "the_first_name"
* </pre>
*
*
*
* @param camelCaseWord the camel-cased word that is to be converted;
* @param delimiterChars optional characters that are used to delimit word
* boundaries (beyond capitalization)
* @return a lower-cased version of the input, with separate words delimited by
* the underscore character.
*/
public
String
underscore
(
String
camelCaseWord
,
char
...
delimiterChars
)
{
if
(
camelCaseWord
==
null
)
{
return
null
;
}
String
result
=
camelCaseWord
.
trim
();
if
(
result
.
length
()
==
0
)
{
return
""
;
}
result
=
result
.
replaceAll
(
"([A-Z]+)([A-Z][a-z])"
,
"$1_$2"
);
result
=
result
.
replaceAll
(
"([a-z\\d])([A-Z])"
,
"$1_$2"
);
result
=
result
.
replace
(
'-'
,
'_'
);
if
(
delimiterChars
!=
null
)
{
for
(
char
delimiterChar
:
delimiterChars
)
{
result
=
result
.
replace
(
delimiterChar
,
'_'
);
}
}
return
result
.
toLowerCase
();
}
/**
* Returns a copy of the input with the first character converted to uppercase
* and the remainder to lowercase.
*
* @param words the word to be capitalized
* @return the string with the first character capitalized and the remaining
* characters lowercased
*/
public
String
capitalize
(
String
words
)
{
if
(
words
==
null
)
{
return
null
;
}
String
result
=
words
.
trim
();
if
(
result
.
length
()
==
0
)
{
return
""
;
}
if
(
result
.
length
()
==
1
)
{
return
result
.
toUpperCase
();
}
return
""
+
Character
.
toUpperCase
(
result
.
charAt
(
0
))
+
result
.
substring
(
1
).
toLowerCase
();
}
/**
* Capitalizes the first word and turns underscores into spaces and strips
* trailing "_id" and any supplied removable tokens. Like
* {@link #titleCase(String, String[])}, this is meant for creating pretty
* output.
*
* Examples:
*
* <pre>
* inflector.humanize("employee_salary") #=> "Employee salary"
* inflector.humanize("author_id") #=> "Author"
* </pre>
*
*
*
* @param lowerCaseAndUnderscoredWords the input to be humanized
* @param removableTokens optional array of tokens that are to be
* removed
* @return the humanized string
* @see #titleCase(String, String[])
*/
public
String
humanize
(
String
lowerCaseAndUnderscoredWords
,
String
...
removableTokens
)
{
if
(
lowerCaseAndUnderscoredWords
==
null
)
{
return
null
;
}
String
result
=
lowerCaseAndUnderscoredWords
.
trim
();
if
(
result
.
length
()
==
0
)
{
return
""
;
}
// Remove a trailing "_id" token
result
=
result
.
replaceAll
(
"_id$"
,
""
);
// Remove all of the tokens that should be removed
if
(
removableTokens
!=
null
)
{
for
(
String
removableToken
:
removableTokens
)
{
result
=
result
.
replaceAll
(
removableToken
,
""
);
}
}
result
=
result
.
replaceAll
(
"_+"
,
" "
);
// replace all adjacent underscores with a single space
return
capitalize
(
result
);
}
/**
* Capitalizes all the words and replaces some characters in the string to
* create a nicer looking title. Underscores are changed to spaces, a trailing
* "_id" is removed, and any of the supplied tokens are removed. Like
* {@link #humanize(String, String[])}, this is meant for creating pretty
* output.
*
* Examples:
*
* <pre>
* inflector.titleCase("man from the boondocks") #=> "Man From The Boondocks"
* inflector.titleCase("x-men: the last stand") #=> "X Men: The Last Stand"
* </pre>
*
*
*
* @param words the input to be turned into title case
* @param removableTokens optional array of tokens that are to be removed
* @return the title-case version of the supplied words
*/
public
String
titleCase
(
String
words
,
String
...
removableTokens
)
{
String
result
=
humanize
(
words
,
removableTokens
);
result
=
replaceAllWithUppercase
(
result
,
"\\b([a-z])"
,
1
);
// change first char of each word to uppercase
return
result
;
}
/**
* Turns a non-negative number into an ordinal string used to denote the
* position in an ordered sequence, such as 1st, 2nd, 3rd, 4th.
*
* @param number the non-negative number
* @return the string with the number and ordinal suffix
*/
public
String
ordinalize
(
int
number
)
{
int
remainder
=
number
%
100
;
String
numberStr
=
Integer
.
toString
(
number
);
if
(
11
<=
number
&&
number
<=
13
)
{
return
numberStr
+
"th"
;
}
remainder
=
number
%
10
;
if
(
remainder
==
1
)
{
return
numberStr
+
"st"
;
}
if
(
remainder
==
2
)
{
return
numberStr
+
"nd"
;
}
if
(
remainder
==
3
)
{
return
numberStr
+
"rd"
;
}
return
numberStr
+
"th"
;
}
// ------------------------------------------------------------------------------------------------
// Management methods
// ------------------------------------------------------------------------------------------------
/**
* Determine whether the supplied word is considered uncountable by the
* {@link #pluralize(Object) pluralize} and {@link #singularize(Object)
* singularize} methods.
*
* @param word the word
* @return true if the plural and singular forms of the word are the same
*/
public
boolean
isUncountable
(
String
word
)
{
if
(
word
==
null
)
{
return
false
;
}
String
trimmedLower
=
word
.
trim
().
toLowerCase
();
return
this
.
uncountables
.
contains
(
trimmedLower
);
}
/**
* Get the set of words that are not processed by the Inflector. The resulting
* map is directly modifiable.
*
* @return the set of uncountable words
*/
public
Set
<
String
>
getUncountables
()
{
return
uncountables
;
}
public
void
addPluralize
(
String
rule
,
String
replacement
)
{
final
Rule
pluralizeRule
=
new
Rule
(
rule
,
replacement
);
this
.
plurals
.
addFirst
(
pluralizeRule
);
}
public
void
addSingularize
(
String
rule
,
String
replacement
)
{
final
Rule
singularizeRule
=
new
Rule
(
rule
,
replacement
);
this
.
singulars
.
addFirst
(
singularizeRule
);
}
public
void
addIrregular
(
String
singular
,
String
plural
)
{
// CheckArg.isNotEmpty(singular, "singular rule");
// CheckArg.isNotEmpty(plural, "plural rule");
String
singularRemainder
=
singular
.
length
()
>
1
?
singular
.
substring
(
1
)
:
""
;
String
pluralRemainder
=
plural
.
length
()
>
1
?
plural
.
substring
(
1
)
:
""
;
addPluralize
(
"("
+
singular
.
charAt
(
0
)
+
")"
+
singularRemainder
+
"$"
,
"$1"
+
pluralRemainder
);
addSingularize
(
"("
+
plural
.
charAt
(
0
)
+
")"
+
pluralRemainder
+
"$"
,
"$1"
+
singularRemainder
);
}
public
void
addUncountable
(
String
...
words
)
{
if
(
words
==
null
||
words
.
length
==
0
)
{
return
;
}
for
(
String
word
:
words
)
{
if
(
word
!=
null
)
{
uncountables
.
add
(
word
.
trim
().
toLowerCase
());
}
}
}
/**
* Utility method to replace all occurrences given by the specific backreference
* with its uppercased form, and remove all other backreferences.
*
* The Java {@link Pattern regular expression processing} does not use the
* preprocessing directives <code>\l</code>, <code>\u</code>,
* <code>\L</code>, and <code>\U</code>. If so, such directives could be used in
* the replacement string to uppercase or lowercase the backreferences. For
* example, <code>\L1</code> would lowercase the first backreference, and
* <code>\u3</code> would uppercase the 3rd backreference.
*
*
* @param input
* @param regex
* @param groupNumberToUppercase
* @return the input string with the appropriate characters converted to
* upper-case
*/
protected
static
String
replaceAllWithUppercase
(
String
input
,
String
regex
,
int
groupNumberToUppercase
)
{
Pattern
underscoreAndDotPattern
=
Pattern
.
compile
(
regex
);
Matcher
matcher
=
underscoreAndDotPattern
.
matcher
(
input
);
StringBuffer
sb
=
new
StringBuffer
();
while
(
matcher
.
find
())
{
matcher
.
appendReplacement
(
sb
,
matcher
.
group
(
groupNumberToUppercase
).
toUpperCase
());
}
matcher
.
appendTail
(
sb
);
return
sb
.
toString
();
}
/**
* Completely remove all rules within this inflector.
*/
public
void
clear
()
{
this
.
uncountables
.
clear
();
this
.
plurals
.
clear
();
this
.
singulars
.
clear
();
}
protected
void
initialize
()
{
Inflector
inflect
=
this
;
inflect
.
addPluralize
(
"$"
,
"s"
);
inflect
.
addPluralize
(
"s$"
,
"s"
);
inflect
.
addPluralize
(
"(ax|test)is$"
,
"$1es"
);
inflect
.
addPluralize
(
"(octop|vir)us$"
,
"$1i"
);
inflect
.
addPluralize
(
"(octop|vir)i$"
,
"$1i"
);
// already plural
inflect
.
addPluralize
(
"(alias|status)$"
,
"$1es"
);
inflect
.
addPluralize
(
"(bu)s$"
,
"$1ses"
);
inflect
.
addPluralize
(
"(buffal|tomat)o$"
,
"$1oes"
);
inflect
.
addPluralize
(
"([ti])um$"
,
"$1a"
);
inflect
.
addPluralize
(
"([ti])a$"
,
"$1a"
);
// already plural
inflect
.
addPluralize
(
"sis$"
,
"ses"
);
inflect
.
addPluralize
(
"(?:([^f])fe|([lr])f)$"
,
"$1$2ves"
);
inflect
.
addPluralize
(
"(hive)$"
,
"$1s"
);
inflect
.
addPluralize
(
"([^aeiouy]|qu)y$"
,
"$1ies"
);
inflect
.
addPluralize
(
"(x|ch|ss|sh)$"
,
"$1es"
);
inflect
.
addPluralize
(
"(matr|vert|ind)ix|ex$"
,
"$1ices"
);
inflect
.
addPluralize
(
"([m|l])ouse$"
,
"$1ice"
);
inflect
.
addPluralize
(
"([m|l])ice$"
,
"$1ice"
);
inflect
.
addPluralize
(
"^(ox)$"
,
"$1en"
);
inflect
.
addPluralize
(
"(quiz)$"
,
"$1zes"
);
// Need to check for the following words that are already pluralized:
inflect
.
addPluralize
(
"(people|men|children|sexes|moves|stadiums)$"
,
"$1"
);
// irregulars
inflect
.
addPluralize
(
"(oxen|octopi|viri|aliases|quizzes)$"
,
"$1"
);
// special rules
inflect
.
addSingularize
(
"s$"
,
""
);
inflect
.
addSingularize
(
"(s|si|u)s$"
,
"$1s"
);
// '-us' and '-ss' are already singular
inflect
.
addSingularize
(
"(n)ews$"
,
"$1ews"
);
inflect
.
addSingularize
(
"([ti])a$"
,
"$1um"
);
inflect
.
addSingularize
(
"((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$"
,
"$1$2sis"
);
inflect
.
addSingularize
(
"(^analy)ses$"
,
"$1sis"
);
inflect
.
addSingularize
(
"(^analy)sis$"
,
"$1sis"
);
// already singular, but ends in 's'
inflect
.
addSingularize
(
"([^f])ves$"
,
"$1fe"
);
inflect
.
addSingularize
(
"(hive)s$"
,
"$1"
);
inflect
.
addSingularize
(
"(tive)s$"
,
"$1"
);
inflect
.
addSingularize
(
"([lr])ves$"
,
"$1f"
);
inflect
.
addSingularize
(
"([^aeiouy]|qu)ies$"
,
"$1y"
);
inflect
.
addSingularize
(
"(s)eries$"
,
"$1eries"
);
inflect
.
addSingularize
(
"(m)ovies$"
,
"$1ovie"
);
inflect
.
addSingularize
(
"(x|ch|ss|sh)es$"
,
"$1"
);
inflect
.
addSingularize
(
"([m|l])ice$"
,
"$1ouse"
);
inflect
.
addSingularize
(
"(bus)es$"
,
"$1"
);
inflect
.
addSingularize
(
"(o)es$"
,
"$1"
);
inflect
.
addSingularize
(
"(shoe)s$"
,
"$1"
);
inflect
.
addSingularize
(
"(cris|ax|test)is$"
,
"$1is"
);
// already singular, but ends in 's'
inflect
.
addSingularize
(
"(cris|ax|test)es$"
,
"$1is"
);
inflect
.
addSingularize
(
"(octop|vir)i$"
,
"$1us"
);
inflect
.
addSingularize
(
"(octop|vir)us$"
,
"$1us"
);
// already singular, but ends in 's'
inflect
.
addSingularize
(
"(alias|status)es$"
,
"$1"
);
inflect
.
addSingularize
(
"(alias|status)$"
,
"$1"
);
// already singular, but ends in 's'
inflect
.
addSingularize
(
"^(ox)en"
,
"$1"
);
inflect
.
addSingularize
(
"(vert|ind)ices$"
,
"$1ex"
);
inflect
.
addSingularize
(
"(matr)ices$"
,
"$1ix"
);
inflect
.
addSingularize
(
"(quiz)zes$"
,
"$1"
);
inflect
.
addIrregular
(
"person"
,
"people"
);
inflect
.
addIrregular
(
"man"
,
"men"
);
inflect
.
addIrregular
(
"child"
,
"children"
);
inflect
.
addIrregular
(
"sex"
,
"sexes"
);
inflect
.
addIrregular
(
"move"
,
"moves"
);
inflect
.
addIrregular
(
"stadium"
,
"stadiums"
);
inflect
.
addUncountable
(
"equipment"
,
"information"
,
"rice"
,
"money"
,
"species"
,
"series"
,
"fish"
,
"sheep"
);
}
}
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录