Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ryanxhl
spring-mvc-mini
提交
13903c46
S
spring-mvc-mini
项目概览
Ryanxhl
/
spring-mvc-mini
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-mvc-mini
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
13903c46
编写于
6月 08, 2015
作者:
H
hot13399
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor. clean code for svn. web.
上级
5a28f0d1
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
477 addition
and
498 deletion
+477
-498
src/main/java/com/spring/mvc/mini/pojo/RequestStatus.java
src/main/java/com/spring/mvc/mini/pojo/RequestStatus.java
+1
-1
src/main/java/com/spring/mvc/mini/web/ObjectClassFormController.java
...va/com/spring/mvc/mini/web/ObjectClassFormController.java
+170
-175
src/main/java/com/spring/mvc/mini/web/ObjectClassListController.java
...va/com/spring/mvc/mini/web/ObjectClassListController.java
+112
-115
src/main/java/com/spring/mvc/mini/web/ObjectClassXmlController.java
...ava/com/spring/mvc/mini/web/ObjectClassXmlController.java
+4
-4
src/main/java/com/spring/mvc/mini/web/RequestStatusController.java
...java/com/spring/mvc/mini/web/RequestStatusController.java
+62
-67
src/main/java/com/spring/mvc/mini/web/UserInfoFormController.java
.../java/com/spring/mvc/mini/web/UserInfoFormController.java
+8
-9
src/main/java/com/spring/mvc/mini/xml/ObjectClassXMLPaser.java
...ain/java/com/spring/mvc/mini/xml/ObjectClassXMLPaser.java
+120
-127
未找到文件。
src/main/java/com/spring/mvc/mini/pojo/RequestStatus.java
浏览文件 @
13903c46
...
...
@@ -81,7 +81,7 @@ public class RequestStatus {
public
String
toString
()
{
return
"RequestStatus [id="
+
id
+
", submitDate="
+
submitDate
+
", commitDate="
+
commitDate
+
", holdDate="
+
holdDate
+
",
o
bjectClassListType="
+
objectClassListType
+
holdDate
+
",
enrichO
bjectClassListType="
+
objectClassListType
+
", userinfo="
+
userinfo
+
", status="
+
status
+
", comments="
+
comments
+
"]"
;
}
...
...
src/main/java/com/spring/mvc/mini/web/ObjectClassFormController.java
浏览文件 @
13903c46
...
...
@@ -6,8 +6,6 @@ import java.util.Calendar;
import
java.util.Date
;
import
javax.mail.Address
;
import
javax.mail.MessagingException
;
import
javax.mail.internet.AddressException
;
import
javax.mail.internet.InternetAddress
;
import
javax.validation.Valid
;
...
...
@@ -34,178 +32,175 @@ import com.spring.mvc.mini.validation.ObjectClassDataValidator;
@Controller
@RequestMapping
(
"/objectclassform"
)
@SessionAttributes
({
"ojbclslisttype"
,
"userinfo"
,
"mocrid"
}
)
@SessionAttributes
({
"ojbclslisttype"
,
"userinfo"
,
"mocrid"
})
public
class
ObjectClassFormController
{
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ObjectClassFormController
.
class
);
@Autowired
RequestStatusJsonParser
rsjm
;
@Autowired
ObjectClassDataValidator
ocdv
;
@Autowired
Properties
properties
;
@Autowired
MailSender
ms
;
@ModelAttribute
public
void
ajaxAttribute
(
WebRequest
request
,
Model
model
)
{
model
.
addAttribute
(
"ajaxRequest"
,
AjaxUtils
.
isAjaxRequest
(
request
));
}
@ModelAttribute
(
"userinfo"
)
public
UserInfo
createUserinfo
()
{
return
new
UserInfo
();
}
@ModelAttribute
(
"mocrid"
)
public
String
createmocrid
()
{
return
String
.
valueOf
(
1
+
rsjm
.
getLatestmocrid
());
}
@RequestMapping
(
method
=
RequestMethod
.
GET
)
public
void
objectClassForm
(
Model
model
,
@ModelAttribute
(
"userinfo"
)
UserInfo
userinfo
,
@ModelAttribute
(
"mocrid"
)
String
mocrid
)
{
ObjectClassListType
ojbclslisttype
=
new
ObjectClassListType
();
ArrayList
<
ObjectClass
>
objclsList
=
new
ArrayList
<
ObjectClass
>();
objclsList
.
add
(
createObjectClassInstance
(
0
,
userinfo
,
mocrid
));
ojbclslisttype
.
setObjectClasses
(
objclsList
);
model
.
addAttribute
(
"ojbclslisttype"
,
ojbclslisttype
);
}
//Add More
@RequestMapping
(
params
={
"objclscount"
},
method
=
RequestMethod
.
POST
)
public
void
objectClassFormWithParam
(
@Valid
ObjectClassListType
ojbclslisttype
,
@ModelAttribute
(
"userinfo"
)
UserInfo
userinfo
,
@ModelAttribute
(
"mocrid"
)
String
mocrid
,
@RequestParam
String
objclscount
,
Model
model
)
{
ArrayList
<
ObjectClass
>
objclsList
=
ojbclslisttype
.
getObjectClasses
();
// for(int i=1;i<Integer.parseInt(objclscount)+1;i++){
objclsList
.
add
(
createObjectClassInstance
(
Integer
.
parseInt
(
objclscount
),
userinfo
,
mocrid
));
// }
ojbclslisttype
.
setObjectClasses
(
objclsList
);
model
.
addAttribute
(
"ojbclslisttype"
,
ojbclslisttype
);
}
//Submit
@RequestMapping
(
method
=
RequestMethod
.
POST
)
public
String
processSubmit
(
ObjectClassListType
ojbclslisttype
,
@ModelAttribute
(
"userinfo"
)
UserInfo
userinfo
,
@ModelAttribute
(
"mocrid"
)
String
mocrid
,
@ModelAttribute
(
"ajaxRequest"
)
boolean
ajaxRequest
,
Model
model
,
RedirectAttributes
redirectAttrs
)
{
if
(
userinfo
.
getUsername
()
==
null
){
String
message
=
"Sorry, Please submit UserInfoForm at first. "
;
model
.
addAttribute
(
"message"
,
message
);
return
null
;
}
ArrayList
<
ObjectClass
>
objclsList
=
ojbclslisttype
.
getObjectClasses
();
try
{
ocdv
.
checkData
(
objclsList
);
ocdv
.
checkmocrid
(
mocrid
,
rsjm
.
getLatestmocrid
());
}
catch
(
Exception
e
)
{
model
.
addAttribute
(
"message"
,
e
.
toString
());
return
null
;
}
StringBuffer
debugmessage
=
new
StringBuffer
();
for
(
ObjectClass
objcls:
objclsList
){
debugmessage
.
append
(
objcls
);
}
LOGGER
.
debug
(
debugmessage
.
toString
());
ArrayList
<
RequestStatus
>
mrsl
=
rsjm
.
readStatus
();
RequestStatus
mrs
=
new
RequestStatus
();
Calendar
cal
=
Calendar
.
getInstance
();
mrs
.
setSubmitDate
(
cal
.
getTime
());
mrs
.
setmocrid
(
Integer
.
parseInt
(
mocrid
));
mrs
.
setObjectClassListType
(
ojbclslisttype
);
mrs
.
setStatus
(
StatusType
.
ongoing
);
mrs
.
setUserinfo
(
userinfo
);
mrsl
.
add
(
mrs
);
RequestStatusListType
mrslt
=
new
RequestStatusListType
();
mrslt
.
setRequestStatuses
(
mrsl
);
rsjm
.
writeStatus
(
mrslt
);
String
message
=
"MO CR:"
+
mocrid
+
" committed. System will send mail to reviewers."
;
StringBuffer
subjectsb
=
new
StringBuffer
();
subjectsb
.
append
(
"Forthcoming approval of MO CR "
);
subjectsb
.
append
(
mocrid
);
subjectsb
.
append
(
" for "
);
for
(
ObjectClass
objcls:
objclsList
){
subjectsb
.
append
(
objcls
.
getAbbreviation
());
}
StringBuffer
textsb
=
new
StringBuffer
();
textsb
.
append
(
"Hi,\r\n\r\nThese MO CR's shall be approved if no other comments.\r\nIf you have any comment, please comment on this page:\r\n"
);
textsb
.
append
(
"http://"
);
textsb
.
append
(
properties
.
getWebHostname
());
textsb
.
append
(
":8080/spring-mvc-mini/requeststatus?mocrid="
);
textsb
.
append
(
mocrid
);
textsb
.
append
(
"\r\nor mailto:"
);
textsb
.
append
(
userinfo
.
getEmail
());
textsb
.
append
(
"\r\n"
);
textsb
.
append
(
"The request will be committed in 5 days.\r\n\r\nThanks.\r\n"
);
textsb
.
append
(
"http://"
);
textsb
.
append
(
properties
.
getWebHostname
());
textsb
.
append
(
":8080/spring-mvc-mini/"
);
try
{
this
.
commitAndSendMail
(
userinfo
,
subjectsb
.
toString
(),
textsb
.
toString
());
}
catch
(
MessagingException
e
)
{
model
.
addAttribute
(
"message"
,
e
.
toString
());
return
null
;
}
// Success response handling
if
(
ajaxRequest
)
{
// prepare model for rendering success message in this request
model
.
addAttribute
(
"message"
,
message
.
toString
());
return
null
;
}
else
{
// store a success message for rendering on the next request after redirect
// redirect back to the form to render the success message along with newly bound values
redirectAttrs
.
addFlashAttribute
(
"message"
,
message
);
return
"redirect:/objectclassform"
;
}
}
private
ObjectClass
createObjectClassInstance
(
int
i
,
UserInfo
userinfo
,
String
mocrid
){
ObjectClass
objcls
=
new
ObjectClass
();
objcls
.
setIntclass
(
rsjm
.
getMaxIntClass
()+
1
+
i
);
Calendar
cal
=
Calendar
.
getInstance
();
Date
currenttime
=
cal
.
getTime
();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"YYYY.MM.DD"
);
objcls
.
setComment
(
"# "
+
userinfo
.
getEmail
()
+
" "
+
sdf
.
format
(
currenttime
)
+
" MO CR "
+
mocrid
);
return
objcls
;
}
public
void
commitAndSendMail
(
UserInfo
userinfo
,
String
subject
,
String
text
)
throws
AddressException
,
MessagingException
{
Address
[]
toAddress
=
{
new
InternetAddress
(
properties
.
getMailto
()),
new
InternetAddress
(
userinfo
.
getEmail
())};
ms
.
sendMail
(
userinfo
.
getUsername
(),
userinfo
.
getPassword
(),
userinfo
.
getEmail
(),
toAddress
,
subject
,
text
);
}
static
Logger
LOG
=
LoggerFactory
.
getLogger
(
ObjectClassFormController
.
class
);
@Autowired
RequestStatusJsonParser
requestStatusJsonParser
;
@Autowired
ObjectClassDataValidator
objectClassDataValidator
;
@Autowired
Properties
properties
;
@Autowired
MailSender
mailSender
;
@ModelAttribute
public
void
ajaxAttribute
(
WebRequest
request
,
Model
model
)
{
model
.
addAttribute
(
"ajaxRequest"
,
AjaxUtils
.
isAjaxRequest
(
request
));
}
@ModelAttribute
(
"userinfo"
)
public
UserInfo
createUserinfo
()
{
return
new
UserInfo
();
}
@ModelAttribute
(
"mocrid"
)
public
String
createmocrid
()
{
return
String
.
valueOf
(
1
+
requestStatusJsonParser
.
getLatestmocrid
());
}
@RequestMapping
(
method
=
RequestMethod
.
GET
)
public
void
HandleObjectClassForm
(
Model
model
,
@ModelAttribute
(
"userinfo"
)
UserInfo
userinfo
,
@ModelAttribute
(
"mocrid"
)
String
mocrid
)
{
ObjectClassListType
type
=
new
ObjectClassListType
();
ArrayList
<
ObjectClass
>
objectClasses
=
new
ArrayList
<
ObjectClass
>();
objectClasses
.
add
(
createObjectClassInstance
(
0
,
userinfo
,
mocrid
));
type
.
setObjectClasses
(
objectClasses
);
model
.
addAttribute
(
"ojbclslisttype"
,
type
);
}
//Add More
@RequestMapping
(
params
=
{
"objclscount"
},
method
=
RequestMethod
.
POST
)
public
void
handleObjectClassFormWithParam
(
@Valid
ObjectClassListType
objectClassListType
,
@ModelAttribute
(
"userinfo"
)
UserInfo
userinfo
,
@ModelAttribute
(
"mocrid"
)
String
mocrid
,
@RequestParam
String
ObjectClassCount
,
Model
model
)
{
ArrayList
<
ObjectClass
>
objectClasses
=
objectClassListType
.
getObjectClasses
();
objectClasses
.
add
(
createObjectClassInstance
(
Integer
.
parseInt
(
ObjectClassCount
),
userinfo
,
mocrid
));
objectClassListType
.
setObjectClasses
(
objectClasses
);
model
.
addAttribute
(
"ojbclslisttype"
,
objectClassListType
);
}
//Submit
@RequestMapping
(
method
=
RequestMethod
.
POST
)
public
String
handleSubmit
(
ObjectClassListType
objectClassListType
,
@ModelAttribute
(
"userinfo"
)
UserInfo
userinfo
,
@ModelAttribute
(
"mocrid"
)
String
mocrid
,
@ModelAttribute
(
"ajaxRequest"
)
boolean
ajaxRequest
,
Model
model
,
RedirectAttributes
redirectAttrs
)
{
if
(
userinfo
.
getUsername
()
==
null
)
{
model
.
addAttribute
(
"message"
,
"Sorry, Please submit UserInfoForm at first. "
);
return
null
;
}
ArrayList
<
ObjectClass
>
objectClasses
=
objectClassListType
.
getObjectClasses
();
try
{
objectClassDataValidator
.
checkData
(
objectClasses
);
objectClassDataValidator
.
checkmocrid
(
mocrid
,
requestStatusJsonParser
.
getLatestmocrid
());
}
catch
(
Exception
e
)
{
model
.
addAttribute
(
"message"
,
e
.
toString
());
return
null
;
}
constructDebugMessage
(
objectClasses
);
RequestStatus
s
=
new
RequestStatus
();
Calendar
cal
=
Calendar
.
getInstance
();
s
.
setSubmitDate
(
cal
.
getTime
());
s
.
setmocrid
(
Integer
.
parseInt
(
mocrid
));
s
.
setObjectClassListType
(
objectClassListType
);
s
.
setStatus
(
StatusType
.
ongoing
);
s
.
setUserinfo
(
userinfo
);
ArrayList
<
RequestStatus
>
l
=
requestStatusJsonParser
.
readStatus
();
l
.
add
(
s
);
RequestStatusListType
type
=
new
RequestStatusListType
();
type
.
setRequestStatuses
(
l
);
requestStatusJsonParser
.
writeStatus
(
type
);
try
{
this
.
commitAndSendMail
(
userinfo
,
constructMailSubject
(
mocrid
,
objectClasses
),
constructMailText
(
userinfo
,
mocrid
));
}
catch
(
Exception
e
)
{
model
.
addAttribute
(
"message"
,
e
.
toString
());
return
null
;
}
String
message
=
"MO CR:"
+
mocrid
+
" committed. System will send mail to reviewers."
;
if
(
ajaxRequest
)
{
model
.
addAttribute
(
"message"
,
message
.
toString
());
return
null
;
}
else
{
redirectAttrs
.
addFlashAttribute
(
"message"
,
message
);
return
"redirect:/objectclassform"
;
}
}
private
String
constructMailText
(
@ModelAttribute
(
"userinfo"
)
UserInfo
userinfo
,
@ModelAttribute
(
"mocrid"
)
String
mocrid
)
{
StringBuffer
textsb
=
new
StringBuffer
();
textsb
.
append
(
"Hi,\r\n\r\nThese MO CR's shall be approved if no other comments.\r\nIf you have any comment, please comment on this page:\r\n"
);
textsb
.
append
(
"http://"
);
textsb
.
append
(
properties
.
getWebHostname
());
textsb
.
append
(
":8080/spring-mvc-mini/requeststatus?mocrid="
);
textsb
.
append
(
mocrid
);
textsb
.
append
(
"\r\nor mailto:"
);
textsb
.
append
(
userinfo
.
getEmail
());
textsb
.
append
(
"\r\n"
);
textsb
.
append
(
"The request will be committed in 5 days.\r\n\r\nThanks.\r\n"
);
textsb
.
append
(
"http://"
);
textsb
.
append
(
properties
.
getWebHostname
());
textsb
.
append
(
":8080/spring-mvc-mini/"
);
return
textsb
.
toString
();
}
private
String
constructMailSubject
(
@ModelAttribute
(
"mocrid"
)
String
mocrid
,
ArrayList
<
ObjectClass
>
objectClasses
)
{
StringBuffer
subjectsb
=
new
StringBuffer
();
subjectsb
.
append
(
"Forthcoming approval of MO CR "
);
subjectsb
.
append
(
mocrid
);
subjectsb
.
append
(
" for "
);
for
(
ObjectClass
objcls
:
objectClasses
)
{
subjectsb
.
append
(
objcls
.
getAbbreviation
());
}
return
subjectsb
.
toString
();
}
private
void
constructDebugMessage
(
ArrayList
<
ObjectClass
>
objectClasses
)
{
StringBuffer
debugmessage
=
new
StringBuffer
();
for
(
ObjectClass
objcls
:
objectClasses
)
{
debugmessage
.
append
(
objcls
);
}
LOG
.
debug
(
debugmessage
.
toString
());
}
private
ObjectClass
createObjectClassInstance
(
int
i
,
UserInfo
userinfo
,
String
mocrid
)
{
ObjectClass
objcls
=
new
ObjectClass
();
objcls
.
setIntclass
(
requestStatusJsonParser
.
getMaxIntClass
()
+
1
+
i
);
Calendar
cal
=
Calendar
.
getInstance
();
Date
currenttime
=
cal
.
getTime
();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"YYYY.MM.DD"
);
objcls
.
setComment
(
"# "
+
userinfo
.
getEmail
()
+
" "
+
sdf
.
format
(
currenttime
)
+
" MO CR "
+
mocrid
);
return
objcls
;
}
public
void
commitAndSendMail
(
UserInfo
userinfo
,
String
subject
,
String
text
)
throws
Exception
{
Address
[]
toAddress
=
{
new
InternetAddress
(
properties
.
getMailto
()),
new
InternetAddress
(
userinfo
.
getEmail
())};
mailSender
.
sendMail
(
userinfo
.
getUsername
(),
userinfo
.
getPassword
(),
userinfo
.
getEmail
(),
toAddress
,
subject
,
text
);
}
}
src/main/java/com/spring/mvc/mini/web/ObjectClassListController.java
浏览文件 @
13903c46
...
...
@@ -24,119 +24,116 @@ import com.spring.mvc.mini.xml.ObjectClassXMLPaser;
@RequestMapping
(
"/objectclasslist"
)
@SessionAttributes
(
"productList"
)
public
class
ObjectClassListController
{
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ObjectClassListController
.
class
);
@Autowired
ObjectClassXMLPaser
ocxp
;
@ModelAttribute
public
void
ajaxAttribute
(
WebRequest
request
,
Model
model
)
{
model
.
addAttribute
(
"ajaxRequest"
,
AjaxUtils
.
isAjaxRequest
(
request
));
}
@RequestMapping
(
method
=
RequestMethod
.
GET
)
public
String
objectClassListType
(
Model
model
,
@ModelAttribute
(
"page"
)
String
page
)
{
ArrayList
<
ObjectClass
>
ojbclslist
=
null
;
try
{
ojbclslist
=
ocxp
.
objectClassMapping
();
Collections
.
reverse
(
ojbclslist
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
PagedListHolder
<
ArrayList
<
ObjectClass
>>
productList
=
new
PagedListHolder
(
ojbclslist
);
productList
.
setPageSize
(
100
);
model
.
addAttribute
(
"productList"
,
productList
);
return
null
;
}
@RequestMapping
(
params
={
"jumppage"
},
method
=
RequestMethod
.
GET
)
public
String
objectClassPagination
(
Model
model
,
@ModelAttribute
(
"jumppage"
)
String
jumppage
,
@ModelAttribute
(
"productList"
)
PagedListHolder
<
ArrayList
<
ObjectClass
>>
productList
)
{
LOGGER
.
info
(
"@RequestMapping(params={\"jumppage\"}, method = RequestMethod.GET)"
);
if
(
jumppage
==
null
)
{
}
else
{
if
(
"next"
.
equals
(
jumppage
))
{
productList
.
nextPage
();
}
else
if
(
"previous"
.
equals
(
jumppage
))
{
productList
.
previousPage
();
}
else
if
(
isInteger
(
jumppage
)
>
0
){
productList
.
setPage
(
isInteger
(
jumppage
));
}
}
model
.
addAttribute
(
"productList"
,
productList
);
return
null
;
}
@RequestMapping
(
params
={
"searchcritical"
},
method
=
RequestMethod
.
GET
)
public
String
objectClassSearch
(
Model
model
,
@ModelAttribute
(
"searchcritical"
)
String
searchcritical
)
{
LOGGER
.
info
(
"@RequestMapping(params={\"searchcritical\"}, method = RequestMethod.GET)"
);
ArrayList
<
ObjectClass
>
searchOjbclslist
=
null
;
if
(
searchcritical
==
null
)
{
}
else
{
ArrayList
<
ObjectClass
>
ojbclslist
=
null
;
searchOjbclslist
=
new
ArrayList
<
ObjectClass
>();
try
{
ojbclslist
=
ocxp
.
objectClassMapping
();
for
(
ObjectClass
ojbcls:
ojbclslist
){
if
(
ojbcls
.
match
(
searchcritical
)){
searchOjbclslist
.
add
(
ojbcls
);
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
PagedListHolder
<
ArrayList
<
ObjectClass
>>
productList
=
new
PagedListHolder
(
searchOjbclslist
);
productList
.
setPageSize
(
50
);
model
.
addAttribute
(
"productList"
,
productList
);
return
null
;
}
@RequestMapping
(
method
=
RequestMethod
.
POST
)
public
String
processSubmit
(
Model
model
,
@ModelAttribute
(
"page"
)
String
page
,
@ModelAttribute
(
"productList"
)
PagedListHolder
<
ArrayList
<
ObjectClass
>>
productList
,
@ModelAttribute
(
"ajaxRequest"
)
boolean
ajaxRequest
,
RedirectAttributes
redirectAttrs
)
{
LOGGER
.
info
(
"@RequestMapping(method=RequestMethod.POST)"
);
String
message
=
"Form submitted successfully. Bound "
;
// Success response handling
if
(
ajaxRequest
)
{
// prepare model for rendering success message in this request
model
.
addAttribute
(
"message"
,
message
);
return
null
;
}
else
{
// store a success message for rendering on the next request after redirect
// redirect back to the form to render the success message along with newly bound values
redirectAttrs
.
addFlashAttribute
(
"message"
,
message
);
return
"redirect:/objectclasslist"
;
}
}
public
int
isInteger
(
String
s
)
{
int
i
;
try
{
i
=
Integer
.
parseInt
(
s
);
}
catch
(
NumberFormatException
e
)
{
return
-
1
;
}
// only got here if we didn't return false
return
i
;
}
static
Logger
LOG
=
LoggerFactory
.
getLogger
(
ObjectClassListController
.
class
);
@Autowired
ObjectClassXMLPaser
objectClassXMLPaser
;
@ModelAttribute
public
void
ajaxAttribute
(
WebRequest
request
,
Model
model
)
{
model
.
addAttribute
(
"ajaxRequest"
,
AjaxUtils
.
isAjaxRequest
(
request
));
}
@RequestMapping
(
method
=
RequestMethod
.
GET
)
public
String
enrichObjectClassListType
(
Model
model
,
@ModelAttribute
(
"page"
)
String
page
)
{
ArrayList
<
ObjectClass
>
ojbclslist
=
getObjectClasses
();
Collections
.
reverse
(
ojbclslist
);
PagedListHolder
<
ArrayList
<
ObjectClass
>>
productList
=
new
PagedListHolder
(
ojbclslist
);
productList
.
setPageSize
(
100
);
model
.
addAttribute
(
"productList"
,
productList
);
return
null
;
}
private
ArrayList
<
ObjectClass
>
getObjectClasses
()
{
ArrayList
<
ObjectClass
>
ojbclslist
=
null
;
try
{
ojbclslist
=
objectClassXMLPaser
.
objectClassMapping
();
}
catch
(
Exception
e
)
{
LOG
.
error
(
"get XML Object Class exception"
,
e
);
}
return
ojbclslist
;
}
@RequestMapping
(
params
=
{
"jumppage"
},
method
=
RequestMethod
.
GET
)
public
String
handleObjectClassPagination
(
Model
model
,
@ModelAttribute
(
"jumppage"
)
String
jumppage
,
@ModelAttribute
(
"productList"
)
PagedListHolder
<
ArrayList
<
ObjectClass
>>
productList
)
{
LOG
.
info
(
"@RequestMapping(params={\"jumppage\"}, method = RequestMethod.GET)"
);
if
(
jumppage
==
null
)
{
}
else
{
if
(
"next"
.
equals
(
jumppage
))
{
productList
.
nextPage
();
}
else
if
(
"previous"
.
equals
(
jumppage
))
{
productList
.
previousPage
();
}
else
if
(
isInteger
(
jumppage
)
>
0
)
{
productList
.
setPage
(
isInteger
(
jumppage
));
}
}
model
.
addAttribute
(
"productList"
,
productList
);
return
null
;
}
@RequestMapping
(
params
=
{
"searchcritical"
},
method
=
RequestMethod
.
GET
)
public
String
searchObjectClass
(
Model
model
,
@ModelAttribute
(
"searchcritical"
)
String
searchcritical
)
{
LOG
.
info
(
"@RequestMapping(params={\"searchcritical\"}, method = RequestMethod.GET)"
);
ArrayList
<
ObjectClass
>
searchOjbclslist
=
null
;
if
(
searchcritical
==
null
)
{
}
else
{
ArrayList
<
ObjectClass
>
ojbclslist
=
getObjectClasses
();
searchOjbclslist
=
new
ArrayList
<
ObjectClass
>();
for
(
ObjectClass
ojbcls
:
ojbclslist
)
{
if
(
ojbcls
.
match
(
searchcritical
))
{
searchOjbclslist
.
add
(
ojbcls
);
}
}
}
PagedListHolder
<
ArrayList
<
ObjectClass
>>
productList
=
new
PagedListHolder
(
searchOjbclslist
);
productList
.
setPageSize
(
50
);
model
.
addAttribute
(
"productList"
,
productList
);
return
null
;
}
@RequestMapping
(
method
=
RequestMethod
.
POST
)
public
String
submit
(
Model
model
,
@ModelAttribute
(
"page"
)
String
page
,
@ModelAttribute
(
"productList"
)
PagedListHolder
<
ArrayList
<
ObjectClass
>>
productList
,
@ModelAttribute
(
"ajaxRequest"
)
boolean
ajaxRequest
,
RedirectAttributes
redirectAttrs
)
{
LOG
.
info
(
"@RequestMapping(method=RequestMethod.POST)"
);
String
message
=
"Form submitted successfully. Bound "
;
if
(
ajaxRequest
)
{
model
.
addAttribute
(
"message"
,
message
);
return
null
;
}
else
{
redirectAttrs
.
addFlashAttribute
(
"message"
,
message
);
return
"redirect:/objectclasslist"
;
}
}
public
int
isInteger
(
String
s
)
{
int
i
;
try
{
i
=
Integer
.
parseInt
(
s
);
}
catch
(
NumberFormatException
e
)
{
return
-
1
;
}
return
i
;
}
}
src/main/java/com/spring/mvc/mini/web/ObjectClassXmlController.java
浏览文件 @
13903c46
...
...
@@ -23,10 +23,10 @@ import com.spring.mvc.mini.xml.ObjectClassXMLPaser;
@RequestMapping
(
"/objectclassxml"
)
public
class
ObjectClassXmlController
{
static
Logger
LOG
GER
=
LoggerFactory
.
getLogger
(
ObjectClassXmlController
.
class
);
static
Logger
LOG
=
LoggerFactory
.
getLogger
(
ObjectClassXmlController
.
class
);
@Autowired
ObjectClassXMLPaser
o
cxp
;
ObjectClassXMLPaser
o
bjectClassXMLPaser
;
@ModelAttribute
public
void
ajaxAttribute
(
WebRequest
request
,
Model
model
)
{
...
...
@@ -34,12 +34,12 @@ public class ObjectClassXmlController {
}
@RequestMapping
(
method
=
RequestMethod
.
GET
)
public
HttpEntity
<
byte
[]>
getXml
(
ModelMap
map
,
HttpServletResponse
response
)
{
public
HttpEntity
<
byte
[]>
get
ObjectClasses
Xml
(
ModelMap
map
,
HttpServletResponse
response
)
{
byte
[]
documentBody
=
null
;
try
{
documentBody
=
o
cxp
.
getTextConent
();
documentBody
=
o
bjectClassXMLPaser
.
getTextConent
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
...
...
src/main/java/com/spring/mvc/mini/web/RequestStatusController.java
浏览文件 @
13903c46
...
...
@@ -28,13 +28,12 @@ import com.spring.mvc.mini.pojo.UserInfo;
@Controller
@RequestMapping
(
"/requeststatus"
)
//@SessionAttributes({"requeststatus"} )
public
class
RequestStatusController
{
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
RequestStatusController
.
class
);
@Autowired
RequestStatusJsonParser
r
sjm
;
RequestStatusJsonParser
r
equestStatusJsonParser
;
@Autowired
MailSender
ms
;
...
...
@@ -44,20 +43,15 @@ public class RequestStatusController {
model
.
addAttribute
(
"ajaxRequest"
,
AjaxUtils
.
isAjaxRequest
(
request
));
}
// @ModelAttribute("requeststatus")
// public miniequestStatus createRequestStatus() {
// return new miniequestStatus();
// }
@RequestMapping
(
method
=
RequestMethod
.
GET
)
public
void
o
bjectClassForm
(
Model
model
)
{
public
void
handleO
bjectClassForm
(
Model
model
)
{
model
.
addAttribute
(
"miniequeststatus"
,
new
RequestStatus
());
}
@RequestMapping
(
params
={
"mocrid"
},
method
=
RequestMethod
.
GET
)
public
void
o
bjectClassFormWithParam
(
@RequestParam
String
mocrid
,
Model
model
)
{
public
void
enrichO
bjectClassFormWithParam
(
@RequestParam
String
mocrid
,
Model
model
)
{
ArrayList
<
RequestStatus
>
mrsList
=
r
sjm
.
readStatus
();
ArrayList
<
RequestStatus
>
mrsList
=
r
equestStatusJsonParser
.
readStatus
();
for
(
RequestStatus
mrs:
mrsList
){
...
...
@@ -70,24 +64,14 @@ public class RequestStatusController {
}
@RequestMapping
(
method
=
RequestMethod
.
POST
)
public
String
processS
ubmit
(
@ModelAttribute
(
"miniequeststatus"
)
RequestStatus
miniequeststatus
,
@ModelAttribute
(
"ajaxRequest"
)
boolean
ajaxRequest
,
Model
model
,
RedirectAttributes
redirectAttrs
)
{
public
String
s
ubmit
(
@ModelAttribute
(
"miniequeststatus"
)
RequestStatus
miniequeststatus
,
@ModelAttribute
(
"ajaxRequest"
)
boolean
ajaxRequest
,
Model
model
,
RedirectAttributes
redirectAttrs
)
{
if
(
miniequeststatus
.
getObjectClassListType
()
==
null
){
ArrayList
<
RequestStatus
>
mrsList
=
rsjm
.
readStatus
();
boolean
boo
=
false
;
for
(
RequestStatus
mrs:
mrsList
){
if
(
mrs
.
getmocrid
()
==
miniequeststatus
.
getmocrid
()){
model
.
addAttribute
(
"miniequeststatus"
,
mrs
);
boo
=
true
;
}
}
ArrayList
<
RequestStatus
>
mrsList
=
requestStatusJsonParser
.
readStatus
();
if
(
boo
){
if
(
isMocridEquals
(
miniequeststatus
,
model
,
mrsList
)
){
model
.
addAttribute
(
"message"
,
"SUCCESS:MO CR ID:"
+
miniequeststatus
.
getmocrid
()+
" is presenting."
);
return
null
;
}
else
{
...
...
@@ -96,72 +80,83 @@ public class RequestStatusController {
}
}
ArrayList
<
RequestStatus
>
mrsl
=
rsjm
.
readStatus
();
ArrayList
<
RequestStatus
>
requestStatuses
=
requestStatusJsonParser
.
readStatus
();
int
index
=
0
;
for
(
RequestStatus
item:
mrsl
){
for
(
RequestStatus
item:
requestStatuses
){
if
(
item
.
getmocrid
()
==
miniequeststatus
.
getmocrid
()){
index
=
mrsl
.
indexOf
(
item
);
index
=
requestStatuses
.
indexOf
(
item
);
break
;
}
}
mrsl
.
get
(
index
).
setComments
(
miniequeststatus
.
getComments
());
mrsl
.
get
(
index
).
setObjectClassListType
(
miniequeststatus
.
getObjectClassListType
());
requestStatuses
.
get
(
index
).
setComments
(
miniequeststatus
.
getComments
());
requestStatuses
.
get
(
index
).
setObjectClassListType
(
miniequeststatus
.
getObjectClassListType
());
RequestStatusListType
mrslt
=
new
RequestStatusListType
();
RequestStatusListType
type
=
new
RequestStatusListType
();
mrslt
.
setRequestStatuses
(
mrsl
);
rsjm
.
writeStatus
(
mrslt
);
LOGGER
.
debug
(
mrslt
.
toString
());
StringBuffer
subjectsb
=
new
StringBuffer
();
subjectsb
.
append
(
"MO CR:"
);
subjectsb
.
append
(
miniequeststatus
.
getmocrid
());
subjectsb
.
append
(
" Updated"
);
StringBuffer
textsb
=
new
StringBuffer
();
textsb
.
append
(
"New Comments: \r\n"
);
textsb
.
append
(
miniequeststatus
.
getComments
());
textsb
.
append
(
" \r\n"
);
type
.
setRequestStatuses
(
requestStatuses
);
requestStatusJsonParser
.
writeStatus
(
type
);
LOGGER
.
debug
(
type
.
toString
());
try
{
if
(!
mrsl
.
get
(
index
).
getObjectClassListType
().
equals
(
miniequeststatus
.
getObjectClassListType
())){
textsb
.
append
(
"Object Classes updated: \r\n"
);
textsb
.
append
(
miniequeststatus
.
getObjectClassListType
().
toString
());
}
textsb
.
append
(
"http://localhost:8080/spring-mvc-mini/requeststatus?mocrid="
);
textsb
.
append
(
miniequeststatus
.
getmocrid
());
textsb
.
append
(
" \r\n"
);
textsb
.
append
(
" \r\n"
);
this
.
commentAndSendMail
(
mrsl
.
get
(
index
).
getUserinfo
(),
subjectsb
.
toString
(),
textsb
.
toString
());
}
catch
(
MessagingException
e
)
{
this
.
commentAndSendMail
(
requestStatuses
.
get
(
index
).
getUserinfo
(),
constructMailSubject
(
miniequeststatus
),
constructMailText
(
miniequeststatus
,
requestStatuses
,
index
));
}
catch
(
Exception
e
)
{
model
.
addAttribute
(
"message"
,
e
.
toString
());
return
null
;
}
catch
(
NullPointerException
e
){
model
.
addAttribute
(
"message"
,
"FAILED:The MO CR id is not existing!"
);
return
null
;
}
String
message
=
"Your update was submitted."
;
// Success response handling
if
(
ajaxRequest
)
{
// prepare model for rendering success message in this request
model
.
addAttribute
(
"message"
,
message
);
return
null
;
}
else
{
// store a success message for rendering on the next request after redirect
// redirect back to the form to render the success message along with newly bound values
// redirectAttrs.addFlashAttribute("message", message);
return
"redirect:/requeststatus"
;
}
}
public
void
commentAndSendMail
(
UserInfo
userinfo
,
String
subject
,
String
text
)
throws
AddressException
,
MessagingException
{
private
String
constructMailText
(
@ModelAttribute
(
"miniequeststatus"
)
RequestStatus
miniequeststatus
,
ArrayList
<
RequestStatus
>
requestStatuses
,
int
index
)
{
StringBuffer
textsb
=
new
StringBuffer
();
textsb
.
append
(
"New Comments: \r\n"
);
textsb
.
append
(
miniequeststatus
.
getComments
());
textsb
.
append
(
" \r\n"
);
if
(!
requestStatuses
.
get
(
index
).
getObjectClassListType
().
equals
(
miniequeststatus
.
getObjectClassListType
())){
textsb
.
append
(
"Object Classes updated: \r\n"
);
textsb
.
append
(
miniequeststatus
.
getObjectClassListType
().
toString
());
}
textsb
.
append
(
"http://localhost:8080/spring-mvc-mini/requeststatus?mocrid="
);
textsb
.
append
(
miniequeststatus
.
getmocrid
());
textsb
.
append
(
" \r\n"
);
textsb
.
append
(
" \r\n"
);
return
textsb
.
toString
();
}
private
String
constructMailSubject
(
@ModelAttribute
(
"miniequeststatus"
)
RequestStatus
miniequeststatus
)
{
StringBuffer
subjectsb
=
new
StringBuffer
();
subjectsb
.
append
(
"MO CR:"
);
subjectsb
.
append
(
miniequeststatus
.
getmocrid
());
subjectsb
.
append
(
" Updated"
);
return
subjectsb
.
toString
();
}
private
boolean
isMocridEquals
(
@ModelAttribute
(
"miniequeststatus"
)
RequestStatus
miniequeststatus
,
Model
model
,
ArrayList
<
RequestStatus
>
mrsList
)
{
boolean
boo
=
false
;
for
(
RequestStatus
mrs:
mrsList
){
if
(
mrs
.
getmocrid
()
==
miniequeststatus
.
getmocrid
()){
model
.
addAttribute
(
"miniequeststatus"
,
mrs
);
boo
=
true
;
}
}
return
boo
;
}
public
void
commentAndSendMail
(
UserInfo
userinfo
,
String
subject
,
String
text
)
throws
Exception
{
Address
[]
toAddress
=
{
new
InternetAddress
(
userinfo
.
getEmail
())};
...
...
src/main/java/com/spring/mvc/mini/web/UserInfoFormController.java
浏览文件 @
13903c46
...
...
@@ -42,13 +42,13 @@ public class UserInfoFormController {
}
@RequestMapping
(
method
=
RequestMethod
.
POST
)
public
String
processS
ubmit
(
UserInfo
userinfo
,
@ModelAttribute
(
"ajaxRequest"
)
boolean
ajaxRequest
,
Model
model
,
RedirectAttributes
redirectAttrs
)
{
public
String
s
ubmit
(
UserInfo
userinfo
,
@ModelAttribute
(
"ajaxRequest"
)
boolean
ajaxRequest
,
Model
model
,
RedirectAttributes
redirectAttrs
)
{
try
{
loginAndSendMail
(
userinfo
);
}
catch
(
Messaging
Exception
e
)
{
}
catch
(
Exception
e
)
{
model
.
addAttribute
(
"message"
,
"Login Failed:"
+
e
.
toString
());
return
null
;
}
...
...
@@ -56,20 +56,19 @@ public class UserInfoFormController {
String
message
=
"Login Successful, Click ObjecClassForm to continue."
;
model
.
addAttribute
(
"userinfo"
,
userinfo
);
// Success response handling
if
(
ajaxRequest
)
{
// prepare model for rendering success message in this request
model
.
addAttribute
(
"message"
,
message
);
return
null
;
}
else
{
// store a success message for rendering on the next request after redirect
// redirect back to the form to render the success message along with newly bound values
redirectAttrs
.
addFlashAttribute
(
"message"
,
message
);
return
"redirect:/"
;
}
}
public
void
loginAndSendMail
(
UserInfo
userinfo
)
throws
AddressException
,
Messaging
Exception
{
public
void
loginAndSendMail
(
UserInfo
userinfo
)
throws
Exception
{
String
subject
=
"Login successfully to mvc mini"
;
String
text
=
"Welcome you,"
+
userinfo
.
getUsername
()+
"!\r\nYou can reserve the object classes now."
;
...
...
src/main/java/com/spring/mvc/mini/xml/ObjectClassXMLPaser.java
浏览文件 @
13903c46
...
...
@@ -28,134 +28,127 @@ import com.spring.mvc.mini.properties.Properties;
import
com.spring.mvc.mini.svn.SVNHandler
;
@Component
public
class
ObjectClassXMLPaser
{
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ObjectClassXMLPaser
.
class
);
public
class
ObjectClassXMLPaser
{
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ObjectClassXMLPaser
.
class
);
@Autowired
private
Properties
properties
;
@Autowired
private
SVNHandler
sh
;
public
ArrayList
<
ObjectClass
>
objectClassMapping
()
throws
Exception
{
LOGGER
.
info
(
"Start to checkout"
);
sh
.
svnCheckout
();
// Get the DOM Builder Factory
DocumentBuilderFactory
factory
=
DocumentBuilderFactory
.
newInstance
();
// Get the DOM Builder
DocumentBuilder
builder
=
factory
.
newDocumentBuilder
();
// Load and Parse the XML document
// document contains the complete XML as a Tree.
File
objclsFile
=
new
File
(
properties
.
getXmlPath
());
Document
document
=
builder
.
parse
(
objclsFile
);
ArrayList
<
ObjectClass
>
objclsList
=
new
ArrayList
<>();
// Iterating through the nodes and extracting the data.
NodeList
nodeList
=
document
.
getDocumentElement
().
getChildNodes
();
ObjectClass
objcls
=
null
;
int
commentcount
=
0
;
int
elementcount
=
0
;
for
(
int
i
=
0
;
i
<
nodeList
.
getLength
();
i
++)
{
Node
node
=
nodeList
.
item
(
i
);
if
(
node
instanceof
Comment
){
objcls
=
new
ObjectClass
();
Comment
c
=
(
Comment
)
node
;
objcls
.
setComment
(
c
.
getData
());
commentcount
++;
}
if
(
node
instanceof
Element
)
{
objcls
.
setId
(((
Element
)
node
).
getAttribute
(
"id"
).
toString
());
objcls
.
setAbbreviation
(((
Element
)
node
).
getAttribute
(
"abbrev"
)
.
toString
());
objcls
.
setIntclass
(
Integer
.
parseInt
(((
Element
)
node
).
getAttribute
(
"intclass"
)));
objcls
.
setName
(((
Element
)
node
).
getAttribute
(
"name"
).
toString
());
objcls
.
setParents
(((
Element
)
node
).
getAttribute
(
"parents"
)
.
toString
());
objcls
.
setPackageName
(((
Element
)
node
).
getAttribute
(
"adaID"
)
.
toString
());
elementcount
++;
objclsList
.
add
(
objcls
);
}
}
LOGGER
.
debug
(
"commentcount is:"
+
commentcount
);
LOGGER
.
debug
(
"elementcount is:"
+
elementcount
);
return
objclsList
;
}
public
void
AddObjectClass
(
ObjectClass
objcls
){
try
{
// Get the DOM Builder Factory
DocumentBuilderFactory
factory
=
DocumentBuilderFactory
.
newInstance
();
// Get the DOM Builder
DocumentBuilder
builder
=
factory
.
newDocumentBuilder
();;
File
objclsFile
=
new
File
(
properties
.
getXmlPath
());
// Load and Parse the XML document
// document contains the complete XML as a Tree.
Document
document
=
builder
.
parse
(
objclsFile
);
// Iterating through the nodes and extracting the data.
Comment
c
=
document
.
createComment
(
objcls
.
getComment
());
document
.
getDocumentElement
().
appendChild
(
c
);
Element
objclselement
=
document
.
createElement
(
"objclass"
);
objclselement
.
setAttribute
(
"id"
,
objcls
.
getId
());
objclselement
.
setAttribute
(
"intclass"
,
String
.
valueOf
(
objcls
.
getIntclass
()));
objclselement
.
setAttribute
(
"abbrev"
,
objcls
.
getAbbreviation
());
objclselement
.
setAttribute
(
"adaID"
,
objcls
.
getPackageName
());
objclselement
.
setAttribute
(
"name"
,
objcls
.
getName
());
objclselement
.
setAttribute
(
"parents"
,
objcls
.
getParents
());
document
.
getDocumentElement
().
appendChild
(
objclselement
);
// write the content into xml file
TransformerFactory
transformerFactory
=
TransformerFactory
.
newInstance
();
Transformer
transformer
=
transformerFactory
.
newTransformer
();
DOMSource
source
=
new
DOMSource
(
document
);
StreamResult
result
=
new
StreamResult
(
new
File
(
properties
.
getXmlPath
()));
// Output to console for testing
// StreamResult result = new StreamResult(System.out);
transformer
.
transform
(
source
,
result
);
}
catch
(
Exception
e
){
LOGGER
.
error
(
e
.
toString
());
}
}
public
byte
[]
getTextConent
()
throws
Exception
{
LOGGER
.
info
(
"Start to checkout"
);
sh
.
svnCheckout
();
Path
path
=
Paths
.
get
(
properties
.
getXmlPath
());
return
Files
.
readAllBytes
(
path
);
}
private
SVNHandler
svnHandler
;
public
ArrayList
<
ObjectClass
>
objectClassMapping
()
throws
Exception
{
LOGGER
.
info
(
"Start to checkout"
);
svnHandler
.
svnCheckout
();
DocumentBuilderFactory
factory
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilder
builder
=
factory
.
newDocumentBuilder
();
File
objectClassesFile
=
new
File
(
properties
.
getXmlPath
());
Document
document
=
builder
.
parse
(
objectClassesFile
);
ArrayList
<
ObjectClass
>
objectClasses
=
new
ArrayList
<>();
NodeList
nodeList
=
document
.
getDocumentElement
().
getChildNodes
();
ObjectClass
objectClass
=
null
;
int
commentcount
=
0
;
int
elementcount
=
0
;
for
(
int
i
=
0
;
i
<
nodeList
.
getLength
();
i
++)
{
Node
node
=
nodeList
.
item
(
i
);
if
(
node
instanceof
Comment
)
{
objectClass
=
setCommentToObject
((
Comment
)
node
);
commentcount
++;
}
if
(
node
instanceof
Element
)
{
setElementToObject
(
objectClass
,
(
Element
)
node
);
elementcount
++;
objectClasses
.
add
(
objectClass
);
}
}
LOGGER
.
debug
(
"commentcount is:"
+
commentcount
);
LOGGER
.
debug
(
"elementcount is:"
+
elementcount
);
return
objectClasses
;
}
private
ObjectClass
setCommentToObject
(
Comment
node
)
{
ObjectClass
objectClass
;
objectClass
=
new
ObjectClass
();
objectClass
.
setComment
(
node
.
getData
());
return
objectClass
;
}
private
void
setElementToObject
(
ObjectClass
objectClass
,
Element
node
)
{
objectClass
.
setId
(
node
.
getAttribute
(
"id"
).
toString
());
objectClass
.
setAbbreviation
(
node
.
getAttribute
(
"abbrev"
)
.
toString
());
objectClass
.
setIntclass
(
Integer
.
parseInt
(
node
.
getAttribute
(
"intclass"
)));
objectClass
.
setName
(
node
.
getAttribute
(
"name"
).
toString
());
objectClass
.
setParents
(
node
.
getAttribute
(
"parents"
)
.
toString
());
objectClass
.
setPackageName
(
node
.
getAttribute
(
"adaID"
)
.
toString
());
}
public
void
AddObjectClass
(
ObjectClass
objectClass
)
{
try
{
DocumentBuilderFactory
factory
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilder
builder
=
factory
.
newDocumentBuilder
();
File
objectClassesFile
=
new
File
(
properties
.
getXmlPath
());
Document
document
=
builder
.
parse
(
objectClassesFile
);
Comment
c
=
document
.
createComment
(
objectClass
.
getComment
());
document
.
getDocumentElement
().
appendChild
(
c
);
document
.
getDocumentElement
().
appendChild
(
getElementOfObjectClass
(
objectClass
,
document
));
TransformerFactory
transformerFactory
=
TransformerFactory
.
newInstance
();
Transformer
transformer
=
transformerFactory
.
newTransformer
();
DOMSource
source
=
new
DOMSource
(
document
);
StreamResult
result
=
new
StreamResult
(
new
File
(
properties
.
getXmlPath
()));
transformer
.
transform
(
source
,
result
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
.
toString
());
}
}
private
Element
getElementOfObjectClass
(
ObjectClass
objectClass
,
Document
document
)
{
Element
e
=
document
.
createElement
(
"objclass"
);
e
.
setAttribute
(
"id"
,
objectClass
.
getId
());
e
.
setAttribute
(
"intclass"
,
String
.
valueOf
(
objectClass
.
getIntclass
()));
e
.
setAttribute
(
"abbrev"
,
objectClass
.
getAbbreviation
());
e
.
setAttribute
(
"adaID"
,
objectClass
.
getPackageName
());
e
.
setAttribute
(
"name"
,
objectClass
.
getName
());
e
.
setAttribute
(
"parents"
,
objectClass
.
getParents
());
return
e
;
}
public
byte
[]
getTextConent
()
throws
Exception
{
LOGGER
.
info
(
"Start to checkout"
);
svnHandler
.
svnCheckout
();
Path
path
=
Paths
.
get
(
properties
.
getXmlPath
());
return
Files
.
readAllBytes
(
path
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录