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.tags;
020    
021    import java.io.IOException;
022    
023    import javax.servlet.ServletException;
024    import javax.servlet.jsp.JspException;
025    
026    import org.apache.log4j.Logger;
027    import org.apache.wiki.WikiEngine;
028    import org.apache.wiki.ui.EditorManager;
029    
030    
031    /**
032     *  Creates an editor component with all the necessary parts
033     *  to get it working.
034     *  <p>
035     *  In the future, this component should be expanded to provide
036     *  a customized version of the editor according to user preferences.
037     *
038     *  @since 2.2
039     */
040    public class EditorTag extends WikiBodyTag {
041    
042        private static final long serialVersionUID = 0L;
043        private static final Logger log = Logger.getLogger( EditorTag.class );
044        
045        public final int doWikiStartTag()
046            throws IOException
047        {
048            return SKIP_BODY;
049        }
050           
051        public int doEndTag() throws JspException
052        {
053            WikiEngine engine = m_wikiContext.getEngine();
054            EditorManager mgr = engine.getEditorManager();
055            
056            String editorPath = mgr.getEditorPath( m_wikiContext );
057            
058            try
059            {
060                String page = engine.getTemplateManager().findJSP( pageContext,
061                                                                   m_wikiContext.getTemplate(),
062                                                                   editorPath );
063                
064                if( page == null )
065                {
066                    //FIXME: should be I18N ...
067                    pageContext.getOut().println("Unable to find editor '"+editorPath+"'");
068                }
069                else
070                {
071                    pageContext.include( page );
072                }
073            }
074            catch( ServletException e )
075            {
076                log.error("Failed to include editor",e);
077                throw new JspException("Failed to include editor: "+e.getMessage() );
078            }
079            catch( IOException e )
080            {
081                throw new JspException("Could not print Editor tag: "+e.getMessage() );
082            }
083            
084            return EVAL_PAGE;
085        }
086    }