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;
020
021 import org.apache.wiki.WikiContext;
022
023 /**
024 * Describes an editor.
025 *
026 * @since 2.4.12
027 */
028 public class Editor
029 {
030 private String m_editorName;
031 private WikiContext m_wikiContext;
032 private EditorManager m_editorManager;
033
034 public Editor( WikiContext wikiContext, String editorName )
035 {
036 m_wikiContext = wikiContext;
037 m_editorName = editorName;
038 m_editorManager = wikiContext.getEngine().getEditorManager();
039 }
040
041 public String getName()
042 {
043 return m_editorName;
044 }
045
046 // FIXME: Fails, if the editoriterator is on a non-editor page.
047 /** @deprecated */
048 public String getURL()
049 {
050 String uri = m_wikiContext.getHttpRequest().getRequestURI();
051 String para = m_wikiContext.getHttpRequest().getQueryString();
052
053 // if para already contains editor parameter, replace instead of append it
054 // FIXME: Should cut out parameter instead of simple setting strin to null, maybe
055 // in futur releases it may change and theres the danger that trailing parameters get lost
056 int idx = para.indexOf(EditorManager.PARA_EDITOR + "=");
057 if (idx >= 0)
058 {
059 para = para.substring(0, idx-1);
060 }
061
062 return uri + "?" + para + "&" + EditorManager.PARA_EDITOR + "=" + m_editorName;
063 }
064
065 /**
066 * Convinience method which returns XHTML for an option element.
067 * @return "selected='selected'", if this editor is selected.
068 */
069 public String isSelected( )
070 {
071 return isSelected( "selected='selected'", "" );
072 }
073
074 public String isSelected( String ifSelected )
075 {
076 return isSelected( ifSelected, "" );
077 }
078
079 public String isSelected( String ifSelected, String ifNotSelected )
080 {
081 if ( m_editorName.equals(m_editorManager.getEditorName(m_wikiContext) ) )
082 {
083 return ifSelected;
084 }
085 return ifNotSelected;
086 }
087
088 public String toString()
089 {
090 return m_editorName;
091 }
092 }