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