001 /*
002 Licensed to the Apache Software Foundation (ASF) under one
003 or more contributor license agreements. See the NOTICE file
004 distributed with this work for additional information
005 regarding copyright ownership. The ASF licenses this file
006 to you under the Apache License, Version 2.0 (the
007 "License"); you may not use this file except in compliance
008 with the License. You may obtain a copy of the License at
009
010 http://www.apache.org/licenses/LICENSE-2.0
011
012 Unless required by applicable law or agreed to in writing,
013 software distributed under the License is distributed on an
014 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 KIND, either express or implied. See the License for the
016 specific language governing permissions and limitations
017 under the License.
018 */
019 package org.apache.wiki.ui.admin.beans;
020
021 import javax.management.NotCompliantMBeanException;
022 import javax.servlet.http.HttpServletRequest;
023
024 import org.apache.wiki.WikiContext;
025 import org.apache.wiki.WikiEngine;
026 import org.apache.wiki.ui.admin.AdminBean;
027 import org.apache.wiki.management.SimpleMBean;
028 import org.apache.wiki.util.TextUtil;
029
030 /**
031 * This class is still experimental.
032 *
033 *
034 */
035 public class PlainEditorAdminBean
036 extends SimpleMBean
037 implements AdminBean
038 {
039 private static final String TEMPLATE =
040 "<div>"+
041 "<input type='checkbox' id='ajax' %checked/>Use AJAX?<br />"+
042 "<input type='submit' value='Submit'/>"+
043 "%messages"+
044 "</div>"
045 ;
046
047 private boolean m_checked;
048
049 private static final String[] ATTRIBUTES = {"title","checked"};
050 private static final String[] METHODS = {};
051
052 public PlainEditorAdminBean() throws NotCompliantMBeanException
053 {
054 }
055
056 public String doGet(WikiContext context)
057 {
058 HttpServletRequest req = context.getHttpRequest();
059
060 if( req != null && req.getMethod().equals("POST") && getTitle().equals( req.getParameter("form") ) )
061 {
062 return doPost( context );
063 }
064 String base = TEMPLATE;
065
066 base = TextUtil.replaceString( base, "%checked", "checked='checked'" );
067 base = TextUtil.replaceString( base, "%messages", "" );
068
069 return base;
070 }
071
072 public String doPost( WikiContext context )
073 {
074 HttpServletRequest req = context.getHttpRequest();
075
076 boolean checked = "checked".equals( req.getParameter( "id" ) );
077
078 // Make changes
079
080 String base = TEMPLATE;
081
082 base = TextUtil.replaceString( base, "%checked", checked ? "checked='checked'" : "" );
083 base = TextUtil.replaceString( base, "%messages", "<br /><font color='red'>Your settings have been saved</font>" );
084
085 return base;
086 }
087
088 public String getTitle()
089 {
090 return "Plain editor";
091 }
092
093 public int getType()
094 {
095 return EDITOR;
096 }
097
098 public boolean isEnabled()
099 {
100 return true;
101 }
102
103 public String getId()
104 {
105 return "editor.plain";
106 }
107
108 public boolean getChecked()
109 {
110 return m_checked;
111 }
112
113 public String[] getAttributeNames()
114 {
115 return ATTRIBUTES;
116 }
117
118 public String[] getMethodNames()
119 {
120 return METHODS;
121 }
122
123 public void initialize(WikiEngine engine)
124 {
125 // TODO Auto-generated method stub
126
127 }
128 }