AddLinks.java
资源名称:Myblog.rar [点击查看]
上传用户:wlfwy2004
上传日期:2016-12-12
资源大小:33978k
文件大小:6k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.opensource.blog.web.action;
- import javax.servlet.http.*;
- import org.apache.struts.action.*;
- import com.opensource.blog.comm.*;
- import com.opensource.blog.exception.*;
- import com.opensource.blog.model.Links;
- import com.opensource.blog.service.*;
- import com.opensource.blog.web.form.*;
- import com.opensource.blog.web.servlet.*;
- public class AddLinks
- extends BaseAction {
- private LinksService linksService;
- public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- ActionMessages errors = new ActionMessages();
- AddLinksForm form = (AddLinksForm) actionForm;
- UserSession us = this.getUserSession(servletRequest);
- if (form.getAction().equalsIgnoreCase("show")) {
- if (form.getLinktype() == 0) {
- form.setAction("addtext");
- }
- if (form.getLinktype() == 1) {
- form.setAction("addpic");
- }
- form.setId(0);
- form.setLinkimgsrc("http://");
- form.setLinktext("");
- form.setLinkurl("http://");
- return actionMapping.findForward("addlinks");
- }
- if (form.getAction().equalsIgnoreCase("addtext")) {
- if (this.getLinksService().getLinksCountByBlogID_Type(us.getBlog().getId().longValue(),
- Constant.LINK_TEXT) >= Constant.LINK_MAX_NUM) {
- errors.add("error.addlinks.linksnummax",
- new ActionMessage("error.addlinks.linksnummax",
- String.valueOf(Constant.LINK_MAX_NUM)));
- saveErrors(servletRequest, errors);
- return actionMapping.findForward("error");
- }
- Links links = new Links();
- links.setBlogid(us.getBlog().getId().longValue());
- links.setLinkimgsrc("");
- links.setLinktext(form.getLinktext());
- links.setLinktype(form.getLinktype());
- links.setLinkurl(form.getLinkurl());
- try {
- links = this.getLinksService().saveLinks(links);
- }
- catch (BlogException ex) {
- errors.add("error.addlinks.addlink",
- new ActionMessage("error.addlinks.addlink"));
- saveErrors(servletRequest, errors);
- return actionMapping.findForward("error");
- }
- ActionForward f = new ActionForward("/blogInfoHigh.do", true);
- return f;
- }
- if (form.getAction().equalsIgnoreCase("addpic")) {
- if (this.getLinksService().getLinksCountByBlogID_Type(us.getBlog().getId().longValue(),
- Constant.LINK_LOGO) > Constant.LINK_MAX_NUM) {
- errors.add("error.addlinks.linksnummax",
- new ActionMessage("error.addlinks.linksnummax",
- String.valueOf(Constant.LINK_MAX_NUM)));
- saveErrors(servletRequest, errors);
- return actionMapping.findForward("error");
- }
- Links links = new Links();
- links.setBlogid(us.getBlog().getId().longValue());
- links.setLinkimgsrc(form.getLinkimgsrc());
- links.setLinktext(form.getLinktext());
- links.setLinktype(form.getLinktype());
- links.setLinkurl(form.getLinkurl());
- try {
- links = this.getLinksService().saveLinks(links);
- }
- catch (BlogException ex1) {
- errors.add("error.addlinks.addlink", new ActionMessage("error.addlinks.addlink"));
- saveErrors(servletRequest, errors);
- return actionMapping.findForward("error");
- }
- ActionForward f = new ActionForward("/blogInfoHigh.do", true);
- return f;
- }
- if (form.getAction().equalsIgnoreCase("edit")) {
- Links links = this.getLinksService().findLinksByID_BlogID(form.getId(),
- us.getBlog().getId().longValue());
- if (links == null) {
- errors.add("error.addlinks.getlink", new ActionMessage("error.addlinks.getlink"));
- saveErrors(servletRequest, errors);
- return actionMapping.findForward("error");
- }
- form.setAction("editdo");
- form.setId(links.getId().longValue());
- form.setLinkimgsrc(links.getLinkimgsrc());
- form.setLinktext(links.getLinktext());
- form.setLinktype(links.getLinktype());
- form.setLinkurl(links.getLinkurl());
- return actionMapping.findForward("addlinks");
- }
- if (form.getAction().equalsIgnoreCase("editdo")) {
- Links links = this.getLinksService().findLinksByID_BlogID(form.getId(),
- us.getBlog().getId().longValue());
- if (links == null) {
- errors.add("error.addlinks.getlink", new ActionMessage("error.addlinks.getlink"));
- saveErrors(servletRequest, errors);
- return actionMapping.findForward("error");
- }
- links.setLinktext(form.getLinktext());
- links.setLinktype(form.getLinktype());
- links.setLinkurl(form.getLinkurl());
- if (form.getLinktype() == 1) {
- links.setLinkimgsrc(form.getLinkimgsrc());
- }
- try {
- links = this.getLinksService().saveLinks(links);
- }
- catch (BlogException ex2) {
- errors.add("error.addlinks.uplink", new ActionMessage("error.addlinks.uplink"));
- saveErrors(servletRequest, errors);
- return actionMapping.findForward("error");
- }
- ActionForward f = new ActionForward("/blogInfoHigh.do", true);
- return f;
- }
- if (form.getAction().equalsIgnoreCase("del")) {
- Links links = this.getLinksService().findLinksByID_BlogID(form.getId(),
- us.getBlog().getId().longValue());
- if (links == null) {
- errors.add("error.addlinks.getlink", new ActionMessage("error.addlinks.getlink"));
- saveErrors(servletRequest, errors);
- return actionMapping.findForward("error");
- }
- try {
- this.getLinksService().removeLinks(links);
- }
- catch (BlogException ex3) {
- errors.add("error.addlinks.getlink", new ActionMessage("error.addlinks.getlink"));
- saveErrors(servletRequest, errors);
- return actionMapping.findForward("error");
- }
- ActionForward f = new ActionForward("/blogInfoHigh.do", true);
- return f;
- }
- return actionMapping.findForward("error");
- }
- public LinksService getLinksService() {
- return linksService;
- }
- public void setLinksService(LinksService linksService) {
- this.linksService = linksService;
- }
- }