KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dlog4j > tags > DraftTag


1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */

16 package dlog4j.tags;
17
18 import javax.servlet.jsp.JspException JavaDoc;
19 import javax.servlet.jsp.PageContext JavaDoc;
20
21 import net.sf.hibernate.Session;
22 import dlog4j.LogManager;
23 import dlog4j.SiteManager;
24 import dlog4j.formbean.DraftForm;
25 import dlog4j.formbean.LogForm;
26 import dlog4j.formbean.SiteForm;
27
28 /**
29  * 用于根据草稿件的编号获取草稿详细信息的标签
30  * @author Liudong
31  */

32 public class DraftTag extends DlogBaseTag {
33     public final static String JavaDoc PARAM_DRAFT = "draft_id";
34     
35     private int draftId = -1;
36     private String JavaDoc log = null;
37     private String JavaDoc scope = null;
38     
39     public int doEndTag() throws JspException JavaDoc {
40         release();
41         return EVAL_PAGE;
42     }
43     public void release() {
44         draftId = -1;
45         log = null;
46         scope = null;
47     }
48     /**
49      * 查询草稿详细信息并输出变量到页面
50      */

51     public int doStartTag() throws JspException JavaDoc {
52         int did = draftId;
53         if(did==-1)
54         try {
55             did = Integer.parseInt(getParameter(PARAM_DRAFT));
56         }catch(Exception JavaDoc e) {}
57         Session ssn = null;
58         try {
59             ssn = getSession();
60             SiteForm site = SiteManager.getCurrentSite(pageContext.getRequest());
61             DraftForm draft = LogManager.getDraft(ssn,site,did);
62             if(draft!=null)
63                 pageContext.setAttribute(id,draft);
64             if(draft!=null&& log!=null) {
65                 int iScope = PageContext.SESSION_SCOPE;
66                 if("request".equalsIgnoreCase(scope))
67                     iScope = PageContext.REQUEST_SCOPE;
68                 LogForm logForm = (LogForm)pageContext.getAttribute(id,iScope);
69                 if(logForm==null)
70                     logForm = new LogForm();
71                 logForm.setAuthor(draft.getAuthor());
72                 logForm.setAuthorUrl(draft.getAuthorUrl());
73                 logForm.setContent(draft.getContent());
74                 logForm.setLogTime(new java.util.Date JavaDoc());
75                 logForm.setMoodLevel(draft.getMoodLevel());
76                 logForm.setOwner(getLoginUser());
77                 logForm.setRefUrl(draft.getRefUrl());
78                 logForm.setShowFormerly(draft.getShowFormerly());
79                 logForm.setSite(getCurrentSite());
80                 logForm.setTitle(draft.getTitle());
81                 logForm.setUseFace(draft.getUseFace());
82                 logForm.setUseUbb(draft.getUseUbb());
83                 logForm.setWeather(draft.getWeather());
84                 pageContext.setAttribute(log,logForm,iScope);
85             }
86         }catch(Exception JavaDoc e) {
87             throw new JspException JavaDoc(e.fillInStackTrace());
88         }finally {
89             close(ssn);
90         }
91         return SKIP_BODY;
92     }
93     public int getDraftId() {
94         return draftId;
95     }
96     public void setDraftId(int draftId) {
97         this.draftId = draftId;
98     }
99     public void setDraftId(Integer JavaDoc draftId) {
100         this.draftId = draftId.intValue();
101     }
102     public void setDraftId(String JavaDoc draftId) {
103         this.draftId = Integer.parseInt(draftId);
104     }
105     public String JavaDoc getLog() {
106         return log;
107     }
108     public void setLog(String JavaDoc log) {
109         this.log = log;
110     }
111     public String JavaDoc getScope() {
112         return scope;
113     }
114     public void setScope(String JavaDoc scope) {
115         this.scope = scope;
116     }
117 }
118
Popular Tags