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 java.io.IOException;
022
023/**
024 *  Root class for different internal wiki links.  Cannot be used directly,
025 *  but provides basic stuff for other classes.
026 *  <P>
027 *  Extend from this class if you need the following attributes.
028 *
029 *  <P><B>Attributes</B></P>
030 *  <UL>
031 *    <LI>page - Page name to refer to.  Default is the current page.
032 *    <li>format - Either "url" or "anchor".  If "url", will provide
033 *  just the URL for the link.  If "anchor", will output proper HTML
034 *  (&lt;a&gt; href="...).
035 *  </UL>
036 *
037 *  @since 2.0
038 */
039public abstract class WikiLinkTag extends WikiTagBase {
040
041    private static final long serialVersionUID = 4130732879352134867L;
042    public static final int   ANCHOR = 0;
043    public static final int   URL    = 1;
044
045    protected String m_pageName;
046    protected int    m_format = ANCHOR;
047    protected String m_template;
048
049    
050    public void initTag() 
051    {
052        super.initTag();
053        m_pageName = m_template = null;
054        m_format = ANCHOR;
055    }
056    
057    public void setPage( String page )
058    {
059        m_pageName = page;
060    }
061
062    public String getPage()
063    {
064        return m_pageName;
065    }
066
067
068    public String getTemplate()
069    {
070        return m_template;
071    }
072
073    public void setTemplate( String arg )
074    {
075        m_template = arg;
076    }
077
078    public void setFormat( String mode )
079    {
080        if( "url".equalsIgnoreCase(mode) )
081        {
082            m_format = URL;
083        }
084        else
085        {
086            m_format = ANCHOR;
087        }
088    }
089
090    public int doEndTag()
091    {
092        try
093        {
094            if( m_format == ANCHOR )
095            {
096                pageContext.getOut().print("</a>");
097            }
098        }
099        catch( IOException e )
100        {
101            // FIXME: Should do something?
102        }
103
104        return EVAL_PAGE;
105    }
106}