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