01: /*
02: JSPWiki - a JSP-based WikiWiki clone.
03:
04: Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
05:
06: This program is free software; you can redistribute it and/or modify
07: it under the terms of the GNU Lesser General Public License as published by
08: the Free Software Foundation; either version 2.1 of the License, or
09: (at your option) any later version.
10:
11: This program is distributed in the hope that it will be useful,
12: but WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: GNU Lesser General Public License for more details.
15:
16: You should have received a copy of the GNU Lesser General Public License
17: along with this program; if not, write to the Free Software
18: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20: package com.ecyrd.jspwiki.tags;
21:
22: import java.io.IOException;
23:
24: import com.ecyrd.jspwiki.WikiEngine;
25: import com.ecyrd.jspwiki.WikiPage;
26: import com.ecyrd.jspwiki.PageManager;
27: import com.ecyrd.jspwiki.PageLock;
28: import com.ecyrd.jspwiki.providers.ProviderException;
29:
30: import javax.servlet.http.HttpSession;
31:
32: /**
33: *
34: * @author Janne Jalkanen
35: * @since 2.0
36: */
37: public class CheckLockTag extends WikiTagBase {
38: public static final int LOCKED = 0;
39: public static final int NOTLOCKED = 1;
40: public static final int OWNED = 2;
41:
42: private int m_mode;
43:
44: public void setMode(String arg) {
45: if ("locked".equals(arg)) {
46: m_mode = LOCKED;
47: } else if ("owned".equals(arg)) {
48: m_mode = OWNED;
49: } else {
50: m_mode = NOTLOCKED;
51: }
52: }
53:
54: public final int doWikiStartTag() throws IOException,
55: ProviderException {
56: WikiEngine engine = m_wikiContext.getEngine();
57: WikiPage page = m_wikiContext.getPage();
58:
59: if (page != null) {
60: PageManager mgr = engine.getPageManager();
61:
62: PageLock lock = mgr.getCurrentLock(page);
63:
64: HttpSession session = pageContext.getSession();
65:
66: PageLock userLock = (PageLock) session.getAttribute("lock-"
67: + page.getName());
68:
69: if ((lock != null && m_mode == LOCKED && lock != userLock)
70: || (lock != null && m_mode == OWNED && lock == userLock)
71: || (lock == null && m_mode == NOTLOCKED)) {
72: String id = getId();
73:
74: if (id != null && lock != null) {
75: pageContext.setAttribute(id, lock);
76: }
77:
78: return EVAL_BODY_INCLUDE;
79: }
80: }
81:
82: return SKIP_BODY;
83: }
84:
85: }
|