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 */ 019package org.apache.wiki.ui.admin.beans; 020 021import org.apache.wiki.api.core.Context; 022import org.apache.wiki.api.core.Engine; 023import org.apache.wiki.management.SimpleMBean; 024import org.apache.wiki.ui.admin.AdminBean; 025import org.apache.wiki.util.TextUtil; 026 027import javax.management.NotCompliantMBeanException; 028import javax.servlet.http.HttpServletRequest; 029 030/** 031 * This class is still experimental. 032 * 033 * 034 */ 035public class PlainEditorAdminBean extends SimpleMBean implements AdminBean { 036 037 private static final String TEMPLATE = "<div>"+ 038 "<input type='checkbox' id='ajax' %checked/>Use AJAX?<br />" + 039 "<input type='submit' value='Submit'/>" + 040 "%messages" + 041 "</div>"; 042 043 private boolean m_checked; 044 045 private static final String[] ATTRIBUTES = {"title","checked"}; 046 private static final String[] METHODS = {}; 047 048 public PlainEditorAdminBean() throws NotCompliantMBeanException { 049 } 050 051 @Override 052 public String doGet( final Context context) { 053 final HttpServletRequest req = context.getHttpRequest(); 054 if( req != null && req.getMethod().equals("POST") && getTitle().equals( req.getParameter("form") ) ) { 055 return doPost( context ); 056 } 057 String base = TEMPLATE; 058 base = TextUtil.replaceString( base, "%checked", "checked='checked'" ); 059 base = TextUtil.replaceString( base, "%messages", "" ); 060 return base; 061 } 062 063 @Override 064 public String doPost( final Context context ) { 065 final HttpServletRequest req = context.getHttpRequest(); 066 final boolean checked = "checked".equals( req.getParameter( "id" ) ); 067 068 // Make changes 069 String base = TEMPLATE; 070 base = TextUtil.replaceString( base, "%checked", checked ? "checked='checked'" : "" ); 071 base = TextUtil.replaceString( base, "%messages", "<br /><font color='red'>Your settings have been saved</font>" ); 072 return base; 073 } 074 075 @Override 076 public String getTitle() { 077 return "Plain editor"; 078 } 079 080 @Override 081 public int getType() { 082 return EDITOR; 083 } 084 085 public boolean isEnabled() { 086 return true; 087 } 088 089 @Override 090 public String getId() { 091 return "editor.plain"; 092 } 093 094 public boolean getChecked() { 095 return m_checked; 096 } 097 098 @Override 099 public String[] getAttributeNames() { 100 return ATTRIBUTES; 101 } 102 103 @Override 104 public String[] getMethodNames() { 105 return METHODS; 106 } 107 108 @Override 109 public void initialize( final Engine engine ) { 110 } 111 112}