⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 musicaction.java

📁 一个简单的blog系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			}
			// 验证音乐盒的有效性
			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 + -