?? musicaction.java
字號:
}
// 驗證音樂盒的有效性
MusicBoxBean mbox = MusicDAO.getMusicBoxByID(mform.getBox());
if (mbox != null && mbox.getSite().getId() != mform.getSid()) {
msgs.add("name", new ActionMessage("error.mbox_not_available",
new Integer(mform.getBox())));
break;
}
SiteBean site = super.getSiteBean(request);
MusicBean mbean = new MusicBean();
mbean.setSite(site);
mbean.setMusicBox(mbox);
mbean.setTitle(super.autoFiltrate(site, mform.getTitle()));
if (StringUtils.isNotEmpty(mform.getAlbum()))
mbean.setAlbum(mform.getAlbum());
if (StringUtils.isNotEmpty(mform.getSinger()))
mbean.setSinger(mform.getSinger());
if (StringUtils.isNotEmpty(mform.getUrl()))
mbean.setUrl(mform.getUrl());
if (StringUtils.isNotEmpty(mform.getWord())){
String word = StringUtils.abbreviate(super.autoFiltrate(site,
mform.getWord()), MAX_MUSIC_LENGTH);
mbean.setWord(super.filterScriptAndStyle(word));
}
else
mbean.setWord(" ");
mbean.setCreateTime(new Date());
MusicDAO.addMusic(mbean);
break;
}
if (!msgs.isEmpty()) {
saveMessages(request, msgs);
return mapping.findForward("music_add");
}
return makeForward(mapping.findForward("music"), mform.getSid(), "box",
mform.getBox());
}
/**
* 刪除歌曲
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
protected ActionForward doDeleteMusic(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response, String mid)
throws Exception {
MusicForm mform = (MusicForm) form;
ActionMessages msgs = validateSiteOwner(request, response, mform);
if (msgs.isEmpty()) {
int music_id = Integer.parseInt(mid);
MusicBean mbean = MusicDAO.getMusicByID(music_id);
SiteBean site = super.getSiteBean(request);
if (mbean != null && mbean.getSite().getId() == site.getId()) {
MusicDAO.deleteMusic(mbean);
SearchProxy.remove(mbean);
}
}
return makeForward(mapping.findForward("music"), mform.getSid(), "box",
mform.getBox());
}
/**
* 更新歌曲
* 這段代碼很糟糕,shit!
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
protected ActionForward doUpdateMusic(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
MusicForm mform = (MusicForm) form;
super.validateClientId(request, mform);
do{
if (StringUtils.isEmpty(mform.getTitle())){
break;
}
ActionMessages msgs = super.validateSiteOwner(request, response, mform);
if(!msgs.isEmpty()){
saveMessages(request, msgs);
break;
}
SiteBean site = super.getSiteBean(request);
MusicBean mbean = MusicDAO.getMusicByID(mform.getId());
//判斷是否為本站音樂
if(mbean==null ||mbean.getSite().getId()!=site.getId()){
break;
}
if (mbean.getStatus() == MusicBean.STATUS_NORMAL) {
// 驗證新的音樂盒的有效性(移動到其他音樂盒)
if ((mbean.getMusicBox() == null && mform.getBox() > 0)
|| (mbean.getMusicBox() != null && mform.getBox() != mbean
.getMusicBox().getId())) {
MusicBoxBean mbox = MusicDAO
.getMusicBoxByID(mform.getBox());
//判斷是否為本站的音樂盒
if(mbox!=null && mbox.getSite().getId()!=site.getId()){
break;
}
//變換音樂盒
if (mbox != null
&& (mbean.getMusicBox() == null || mbean.getMusicBox()
.getId() != mbox.getId())) {
//兩個音樂盒之間移動或者從無到有
if (mbean.getMusicBox() != null)
mbean.getMusicBox().incMusicCount(-1);
mbean.setMusicBox(mbox);
mbox.incMusicCount(1);
} else if (mbox == null && mbean.getMusicBox() != null) {
//從有到無
mbean.getMusicBox().incMusicCount(-1);
mbean.setMusicBox(null);
}
}
}
//賦新值
if(!StringUtils.equals(mbean.getTitle(), mform.getTitle()))
mbean.setTitle(super.autoFiltrate(site,mform.getTitle()));
if (StringUtils.isNotEmpty(mform.getAlbum()))
mbean.setAlbum(super.autoFiltrate(site,mform.getAlbum()));
if (StringUtils.isNotEmpty(mform.getSinger()))
mbean.setSinger(super.autoFiltrate(site,mform.getSinger()));
if (StringUtils.isNotEmpty(mform.getUrl()))
mbean.setUrl(mform.getUrl());
if (StringUtils.isNotEmpty(mform.getWord())){
String word = StringUtils.abbreviate(super.autoFiltrate(site,
mform.getWord()), MAX_MUSIC_LENGTH);
mbean.setWord(super.filterScriptAndStyle(word));
}
else
mbean.setWord(" ");
if (mbean.getStatus() != MusicBean.STATUS_NORMAL) {
// 網友推薦的情況處理
mbean.getMusicBox().incMusicCount(1);
mbean.setStatus(MusicBean.STATUS_NORMAL);
}
MusicDAO.flush();
break;
}while(true);
return makeForward(mapping.findForward("music"), mform.getSid(), "box",
mform.getBox());
}
/**
* 刪除選中的歌曲
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
protected ActionForward doDeleteSelected(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
MusicForm mform = (MusicForm) form;
ActionMessages msgs = validateSiteOwner(request, response, mform);
if (msgs.isEmpty() && mform.getMid() != null
&& mform.getMid().length > 0) {
SiteBean site = super.getSiteBean(request);
MusicDAO.deleteMusics(site.getId(), mform.getMid());
}
return makeForward(mapping.findForward("music"), mform.getSid(), "box",
mform.getBox());
}
/**
* 刪除音樂盒
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
protected ActionForward doDeleteBox(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response,
String mboxid) throws Exception {
MusicBoxForm mform = (MusicBoxForm) form;
ActionMessages msgs = validateSiteOwner(request, response, mform);
if (msgs.isEmpty()) {
SiteBean site = super.getSiteBean(request);
MusicBoxBean mbox = MusicDAO.getMusicBoxByID(Integer
.parseInt(mboxid));
if (mbox.getSite().getId() == site.getId())
MusicDAO.deleteMusicBox(mbox);
}
return makeForward(mapping.findForward("music"), mform.getSid());
}
/**
* 修改音樂盒
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
protected ActionForward doUpdateBox(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
MusicBoxForm mform = (MusicBoxForm) form;
super.validateClientId(request, mform);
if (StringUtils.isNotEmpty(mform.getName())) {
ActionMessages msgs = validateSiteOwner(request, response, mform);
if (msgs.isEmpty()) {
SiteBean site = super.getSiteBean(request);
MusicBoxBean mbox = MusicDAO.getMusicBoxByID(mform.getId());
if (mbox.getSite().getId() == site.getId()) {
mbox.setName(super.autoFiltrate(site,mform.getName()));
if (StringUtils.isNotEmpty(mform.getDesc())){
String desc = super.autoFiltrate(site,mform.getDesc());
mbox.setDesc(desc);
}
else
mbox.setDesc(null);
MusicDAO.flush();
}
}
}
return makeForward(mapping.findForward("music"), mform.getSid(), "box",
mform.getId());
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -