001: /*
002: JSPWiki - a JSP-based WikiWiki clone.
003:
004: Copyright (C) 2001-2007 JSPWiki development group
005:
006: This program is free software; you can redistribute it and/or modify
007: it under the terms of the GNU Lesser General Public License as published by
008: the Free Software Foundation; either version 2.1 of the License, or
009: (at your option) any later version.
010:
011: This program is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: GNU Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public License
017: along with this program; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020: package com.ecyrd.jspwiki.ui.admin.beans;
021:
022: import javax.management.NotCompliantMBeanException;
023: import javax.servlet.http.HttpServletRequest;
024:
025: import com.ecyrd.jspwiki.TextUtil;
026: import com.ecyrd.jspwiki.WikiContext;
027: import com.ecyrd.jspwiki.WikiEngine;
028: import com.ecyrd.jspwiki.ui.admin.AdminBean;
029: import com.ecyrd.management.SimpleMBean;
030:
031: /**
032: * This class is still experimental.
033: *
034: * @author jalkanen
035: *
036: */
037: public class PlainEditorAdminBean extends SimpleMBean implements
038: AdminBean {
039: private static final String TEMPLATE = "<div>"
040: + "<input type='checkbox' id='ajax' %checked/>Use AJAX?<br />"
041: + "<input type='submit' value='Submit'/>" + "%messages"
042: + "</div>";
043:
044: private boolean m_checked = false;
045:
046: private static final String[] ATTRIBUTES = { "title", "checked" };
047: private static final String[] METHODS = {};
048:
049: public PlainEditorAdminBean() throws NotCompliantMBeanException {
050: }
051:
052: public String doGet(WikiContext context) {
053: HttpServletRequest req = context.getHttpRequest();
054:
055: if (req != null && req.getMethod().equals("POST")
056: && getTitle().equals(req.getParameter("form"))) {
057: return doPost(context);
058: }
059: String base = TEMPLATE;
060:
061: base = TextUtil.replaceString(base, "%checked",
062: "checked='checked'");
063: base = TextUtil.replaceString(base, "%messages", "");
064:
065: return base;
066: }
067:
068: public String doPost(WikiContext context) {
069: HttpServletRequest req = context.getHttpRequest();
070:
071: boolean checked = "checked".equals(req.getParameter("id"));
072:
073: // Make changes
074:
075: String base = TEMPLATE;
076:
077: base = TextUtil.replaceString(base, "%checked",
078: checked ? "checked='checked'" : "");
079: base = TextUtil
080: .replaceString(base, "%messages",
081: "<br /><font color='red'>Your settings have been saved</font>");
082:
083: return base;
084: }
085:
086: public String getTitle() {
087: return "Plain editor";
088: }
089:
090: public int getType() {
091: return EDITOR;
092: }
093:
094: public boolean isEnabled() {
095: return true;
096: }
097:
098: public String getId() {
099: return "editor.plain";
100: }
101:
102: public boolean getChecked() {
103: return m_checked;
104: }
105:
106: public String[] getAttributeNames() {
107: return ATTRIBUTES;
108: }
109:
110: public String[] getMethodNames() {
111: return METHODS;
112: }
113:
114: public void initialize(WikiEngine engine) {
115: // TODO Auto-generated method stub
116:
117: }
118: }
|