/* * Created on 1.6.2004 * Copyright Basen Ltd. */ package net.killeri.jspwiki; import java.io.IOException; import javax.servlet.jsp.JspWriter; import com.ecyrd.jspwiki.*; import com.ecyrd.jspwiki.providers.ProviderException; import com.ecyrd.jspwiki.tags.WikiTagBase; import com.ecyrd.jspwiki.parser.MarkupParser; /** * @author killer * * Copyright BaseN Ltd. */ public class InsertLeftMenuTag extends WikiTagBase { public static final int HTML = 0; public static final int PLAIN = 1; protected String m_pageName = null; private int m_mode = HTML; public void setPage( String page ) { m_pageName = MarkupParser.cleanLink(page); } public String getPage() { return m_pageName; } public void setMode( String arg ) { if( "plain".equals(arg) ) { m_mode = PLAIN; } else { m_mode = HTML; } } public final int doWikiStartTag() throws IOException, ProviderException { WikiEngine engine = m_wikiContext.getEngine(); WikiPage page; // // NB: The page might not really exist if the user is currently // creating it (i.e. it is not yet in the cache or providers), // AND we got the page from the wikiContext. // if( m_pageName == null ) { page = m_wikiContext.getPage(); if( !engine.pageExists(page) ) return SKIP_BODY; } else { page = engine.getPage( m_pageName ); } String pageName = (String) page.getAttribute( "leftmenu" ); if( pageName == null ) pageName = "LeftMenu"; page = engine.getPage( MarkupParser.cleanLink(pageName) ); if( page != null ) { JspWriter out = pageContext.getOut(); switch(m_mode) { case HTML: out.print( engine.getHTML(m_wikiContext, page) ); break; case PLAIN: out.print( engine.getText(m_wikiContext, page) ); break; } } return SKIP_BODY; } }