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.ui;
21:
22: import com.ecyrd.jspwiki.WikiContext;
23:
24: /**
25: * Describes an editor.
26: *
27: * @author Chuck Smith
28: * @since 2.4.12
29: */
30: public class Editor {
31: private String m_editorName;
32: private WikiContext m_wikiContext;
33: private EditorManager m_editorManager;
34:
35: public Editor(WikiContext wikiContext, String editorName) {
36: m_wikiContext = wikiContext;
37: m_editorName = editorName;
38: m_editorManager = wikiContext.getEngine().getEditorManager();
39: }
40:
41: public String getName() {
42: return m_editorName;
43: }
44:
45: // FIXME: Fails, if the editoriterator is on a non-editor page.
46: /** @deprecated */
47: public String getURL() {
48: String uri = m_wikiContext.getHttpRequest().getRequestURI();
49: String para = m_wikiContext.getHttpRequest().getQueryString();
50:
51: // if para already contains editor parameter, replace instead of append it
52: // FIXME: Should cut out parameter instead of simple setting strin to null, maybe
53: // in futur releases it may change and theres the danger that trailing parameters get lost
54: int idx = para.indexOf(EditorManager.PARA_EDITOR + "=");
55: if (idx >= 0) {
56: para = para.substring(0, idx - 1);
57: }
58:
59: return uri + "?" + para + "&" + EditorManager.PARA_EDITOR
60: + "=" + m_editorName;
61: }
62:
63: /**
64: * Convinience method which returns XHTML for an option element.
65: * @return "selected='selected'", if this editor is selected.
66: */
67: public String isSelected() {
68: return isSelected("selected='selected'", "");
69: }
70:
71: public String isSelected(String ifSelected) {
72: return isSelected(ifSelected, "");
73: }
74:
75: public String isSelected(String ifSelected, String ifNotSelected) {
76: if (m_editorName.equals(m_editorManager
77: .getEditorName(m_wikiContext))) {
78: return ifSelected;
79: }
80: return ifNotSelected;
81: }
82:
83: public String toString() {
84: return m_editorName;
85: }
86: }
|