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

📄 diaryaction.java

📁 个人Blog java编写的Blog可以直接使用!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		ActionMessages msgs = new ActionMessages();
		DiaryForm log = (DiaryForm) form;

		while (true) {
			UserBean loginUser = super.getLoginUser(request, response);
			if (loginUser == null) {
				msgs.add("log", new ActionMessage("error.user_not_login"));
				break;
			}
			if (loginUser.getStatus() != UserBean.STATUS_NORMAL) {
				msgs.add("log", new ActionMessage("error.user_not_available"));
				break;
			}
			SiteBean site = super.getSiteByID(log.getSid());
			if (site == null) {
				msgs.add("log", new ActionMessage("error.site_not_available"));
				break;
			}
			// 用户欲操作的日记分类被允许
			DiaryBean journal = DiaryDAO.getDiaryByID(log.getId());
			if (journal == null
					|| journal.getStatus() != DiaryBean.STATUS_DRAFT
					|| journal.getOwner().getId() != loginUser.getId()) {
				msgs.add("draft", new ActionMessage("error.draft_not_exists"));
				break;
			}
			boolean catalog_can_access = false;
			// 站长可以访问站内的任何分类
			if (site.isOwner(loginUser)) {
				catalog_can_access = true;
			} else {
				// 列出用户在该站点可访问的日记分类
				List catalogs = CatalogDAO.listCatalogs(site, loginUser, true);
				for (int i = 0; catalogs != null && i < catalogs.size(); i++) {
					CatalogBean t_catalog = (CatalogBean) catalogs.get(i);
					if (t_catalog.getId() == log.getCatalogId()) {
						catalog_can_access = true;
						break;
					}
				}
			}
			if (!catalog_can_access) {
				msgs.add("log", new ActionMessage("error.catalog_deny",
						new Integer(log.getCatalogId())));
				break;
			}
			// 读取并更新草稿件,然后把状态设为正常
			journal.setClient(new ClientInfo(request, log.getClientType()));
			journal.setViewCount(0);
			journal.setStatus(DiaryBean.STATUS_NORMAL);
			journal.setWriteTime(new Date());
			DiaryDAO.flush();
			break;
		}
		if (!msgs.isEmpty()) {
			saveMessages(request, msgs);
			return mapping.findForward("editlog");
		}
		return makeForward(mapping.findForward("diary"), log.getSid());
	}
	/**
	 * 发表草稿
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @param identity 如果该值为WML则表示来自WML页面
	 * @return
	 * @throws Exception
	 */
	protected ActionForward doPublishDraft(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response, String identity)
			throws Exception {
		ActionMessages msgs = new ActionMessages();
		DiaryForm log = (DiaryForm) form;
		//super.validateClientId(request, log);
		while (true) {
			// 检测日记表单域的值
			if (StringUtils.isEmpty(log.getTitle())) {
				msgs.add("title", new ActionMessage("error.empty_not_allowed"));
				break;
			}
			if (StringUtils.isEmpty(log.getContent())) {
				msgs.add("content",
						new ActionMessage("error.empty_not_allowed"));
				break;
			}
			UserBean loginUser = super.getLoginUser(request, response);
			if (loginUser == null) {
				msgs.add("log", new ActionMessage("error.user_not_login"));
				break;
			}
			if (loginUser.getStatus() != UserBean.STATUS_NORMAL) {
				msgs.add("log", new ActionMessage("error.user_not_available"));
				break;
			}
			SiteBean site = super.getSiteByID(log.getSid());
			if (site == null) {
				msgs.add("log", new ActionMessage("error.site_not_available"));
				break;
			}
			boolean catalog_can_access = false;
			CatalogBean catalog = null;
			// 站长可以访问站内的任何分类
			if (site.isOwner(loginUser)) {
				catalog = CatalogDAO.getCatalogByID(log.getCatalogId());
				if (catalog.getSite().getId() == site.getId())
					catalog_can_access = true;
			} else {
				// 列出用户在该站点可访问的日记分类
				List catalogs = CatalogDAO.listCatalogs(site, loginUser, true);
				for (int i = 0; catalogs != null && i < catalogs.size(); i++) {
					CatalogBean t_catalog = (CatalogBean) catalogs.get(i);
					if (t_catalog.getId() == log.getCatalogId()) {
						catalog = t_catalog;
						catalog_can_access = true;
						break;
					}
				}
			}
			if (!catalog_can_access) {
				msgs.add("log", new ActionMessage("error.catalog_deny",
						new Integer(log.getCatalogId())));
				break;
			}
			// 用户欲操作的日记分类被允许
			DiaryBean journal = DiaryDAO.getDiaryByID(log.getId());
			if (journal == null
					|| journal.getStatus() != DiaryBean.STATUS_DRAFT) {
				msgs.add("draft", new ActionMessage("error.draft_not_exists"));
				break;
			}
			// 检查背景音乐是否有效
			MusicBean song = MusicDAO.getMusicByID(log.getBgSound());
			if (song != null && song.getSite().getId() == site.getId()) {
				journal.setBgSound(song);
			}
			if (StringUtils.isEmpty(log.getWeather()))
				journal.setWeather(DEFAULT_WEATHER);
			else
				journal.setWeather(log.getWeather());
			if (StringUtils.isEmpty(log.getAuthor()))
				journal.setAuthor(loginUser.getNickname());
			else
				journal.setAuthor(log.getAuthor());
			if (StringUtils.isEmpty(log.getTags()))
				journal.setKeyword(null);
			else
				journal.setKeyword(log.getTags());
			if (StringUtils.isEmpty(log.getAuthorUrl()))
				journal.setAuthorUrl(null);
			else
				journal.setAuthorUrl(log.getAuthorUrl());
			if (StringUtils.isEmpty(log.getRefUrl()))
				journal.setRefUrl(null);
			else
				journal.setRefUrl(log.getRefUrl());
			// 读取并更新草稿件,然后把状态设为正常
			journal.setCatalog(catalog);
			journal.setClient(new ClientInfo(request, log.getClientType()));
			String ssn_id = RequestUtils.getDlogSessionId(request);
			boolean wml = WML_IDENTITY.equalsIgnoreCase(identity);
			String content = autoCompileContent(request, site, log.getContent(), loginUser.getId(), ssn_id, wml);
			journal.setContent(content);
			journal.setSize(content.getBytes().length);
			journal.setMoodLevel(log.getMoodLevel());
			journal.setReplyNotify(log.getNotify());
			journal.setViewCount(0);
			journal.setStatus(DiaryBean.STATUS_NORMAL);
			journal.setTitle(log.getTitle());
			journal.setWriteTime(new Date());
			DiaryDAO.create(journal, log.getBookmark() == 1);
			// 检索上传的信息
			pickupUploadFileItems(request, response, loginUser.getId(), site, journal
					.getId(), DiaryBean.TYPE_DIARY);
			break;
		}
		if (!msgs.isEmpty()) {
			saveMessages(request, msgs);
			return mapping.findForward("editlog");
		}
		return makeForward(mapping.findForward("diary"), log.getSid());
	}

	/**
	 * TODO:执行Trackback过程
	 * 
	 * @param log
	 * @param ref_url
	 */
	private void trackBack(DiaryBean log, String ref_url) {

	}

	/**
	 * 将日记存为草稿
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	protected ActionForward doSaveAsDraft(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionMessages msgs = new ActionMessages();
		DiaryForm log = (DiaryForm) form;
		//super.validateClientId(request, log);
		UserBean loginUser = super.getLoginUser(request, response);
		while (true) {
			if (loginUser == null) {
				msgs.add("log", new ActionMessage("error.user_not_login"));
				break;
			}
			if (loginUser.getStatus() != UserBean.STATUS_NORMAL) {
				msgs.add("log", new ActionMessage("error.user_not_available"));
				break;
			}
			
			SiteBean site = super.getSiteByID(log.getSid());
			if (site == null) {
				msgs.add("log", new ActionMessage("error.site_not_available"));
				break;
			}
			boolean catalog_can_access = false;
			CatalogBean catalog = null;
			// 站长可以访问站内的任何分类
			if (site.isOwner(loginUser)) {
				catalog = CatalogDAO.getCatalogByID(log.getCatalogId());
				if (catalog.getSite().getId() == site.getId())
					catalog_can_access = true;
			} else {
				// 列出用户在该站点可访问的日记分类
				List catalogs = CatalogDAO.listCatalogs(site, loginUser, true);
				for (int i = 0; catalogs != null && i < catalogs.size(); i++) {
					CatalogBean t_catalog = (CatalogBean) catalogs.get(i);
					if (t_catalog.getId() == log.getCatalogId()
							&& t_catalog.getSite().getId() == site.getId()) {
						catalog = t_catalog;
						catalog_can_access = true;
						break;
					}
				}
			}
			//用户欲操作的日记分类不被允许
			if(!catalog_can_access){
				msgs.add("log", new ActionMessage("error.catalog_deny",
						new Integer(log.getCatalogId())));
				break;
			}
			// 检测日记表单域的值
			if (StringUtils.isEmpty(log.getTitle())){
				msgs.add("title", new ActionMessage(
						"error.empty_not_allowed"));
				break;
			}
			if (StringUtils.isEmpty(log.getContent())){
				msgs.add("content", new ActionMessage(
						"error.empty_not_allowed"));
				break;
			}
			if (StringUtils.isEmpty(log.getWeather()))
				log.setWeather(DEFAULT_WEATHER);
			if (StringUtils.isEmpty(log.getAuthor()))
				log.setAuthor(loginUser.getNickname());
			if (StringUtils.isEmpty(log.getTags()))
				log.setTags(null);
			if (StringUtils.isEmpty(log.getAuthorUrl()))
				log.setAuthorUrl(null);
			if (StringUtils.isEmpty(log.getRefUrl()))
				log.setRefUrl(null);
			// 创建JournalBean
			DiaryBean journal = new DiaryBean();
			journal.setOwner(loginUser);
			journal.setSite(site);
			journal.setAuthor(super.autoFiltrate(site,log.getAuthor()));
			journal.setAuthorUrl(log.getAuthorUrl());
			journal.setCatalog(catalog);
			journal.setClient(new ClientInfo(request, log
					.getClientType()));
			journal.setContent(super.autoFiltrate(site,log.getContent()));
			journal.setMoodLevel(log.getMoodLevel());
			journal.setRefUrl(log.getRefUrl());
			journal.setReplyNotify(log.getNotify());
			journal.setStatus(DiaryBean.STATUS_DRAFT);
			journal.setKeyword(super.autoFiltrate(site,log.getTags()));
			journal.setTitle(super.autoFiltrate(site,log.getTitle()));
			journal.setWeather(log.getWeather());
			journal.setWriteTime(DateUtils.mergeDateTime(log.getWriteDate(), log.getWriteTime()).getTime());
			Date curTime = new Date();
			if(journal.getWriteTime()==null || journal.getWriteTime().after(curTime))
				journal.setWriteTime(curTime);
			DiaryDAO.create(journal, false);
			//检索上传的信息
			super.pickupUploadFileItems(request, response, loginUser
					.getId(), site, journal.getId(), DiaryBean.TYPE_DIARY);
		
			break;
		}
		if (!msgs.isEmpty()) {
			saveMessages(request, msgs);
			return mapping.findForward("addlog");
		}
		return makeForward(mapping.findForward("draft"), log.getSid());
	}
	
	/**
	 * 自动汇编内容
	 * @param site
	 * @param content
	 * @param uid
	 * @param ssn_id
	 * @param wml
	 * @return
	 */
	private String autoCompileContent(HttpServletRequest req, SiteBean site,
			String content, int uid, String ssn_id, boolean wml) {
		StringBuffer text = new StringBuffer();
		// 根据网站的安全标志决定是否对内容进行敏感字词过滤
		text.append(super.autoFiltrate(site, content));
		if (wml) {
			text.append("<p>");
			// 加载附件
			String context_path = req.getContextPath();
			List files = FCKUploadFileDAO.listOrphanFiles(uid, ssn_id);
			for (int i = 0; files != null && i < files.size(); i++) {
				FckUploadFileBean file = (FckUploadFileBean) files.get(i);
				String uri = context_path + file.getUri();
				text.append(MessageFormat.format(img_pattern, new String[]{uri}));
			}
			text.append("</p>");
		}
		return text.toString();
	}
	
	private final static String img_pattern = "<img src=\"{0}\" alt=\"\"/>";
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -