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; 020 021import org.apache.wiki.api.core.Context; 022 023 024/** 025 * Describes an editor. 026 * 027 * @since 2.4.12 028 */ 029public class Editor { 030 031 private final String m_editorName; 032 private final Context m_wikiContext; 033 private final EditorManager m_editorManager; 034 035 public Editor( final Context wikiContext, final String editorName ) { 036 m_wikiContext = wikiContext; 037 m_editorName = editorName; 038 m_editorManager = wikiContext.getEngine().getManager( EditorManager.class ); 039 } 040 041 public String getName() { 042 return m_editorName; 043 } 044 045 /** 046 * Convenience method which returns XHTML for an option element. 047 * @return "selected='selected'", if this editor is selected. 048 */ 049 public String isSelected( ) 050 { 051 return isSelected( "selected='selected'", "" ); 052 } 053 054 public String isSelected( final String ifSelected ) 055 { 056 return isSelected( ifSelected, "" ); 057 } 058 059 public String isSelected( final String ifSelected, final String ifNotSelected ) { 060 if( m_editorName.equals( m_editorManager.getEditorName( m_wikiContext ) ) ) { 061 return ifSelected; 062 } 063 return ifNotSelected; 064 } 065 066 /** {@inheritDoc} */ 067 @Override 068 public String toString() { 069 return m_editorName; 070 } 071 072}