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;
022import javax.servlet.jsp.JspWriter;
023
024import org.apache.wiki.WikiContext;
025
026/**
027 *  Writes a link to the upload page.  Body of the link becomes the actual text.
028 *  The link is written regardless to whether the page exists or not.
029 *
030 *  <P><B>Attributes</B></P>
031 *  <UL>
032 *    <LI>page - Page name to refer to.  Default is the current page.
033 *    <LI>format - either "anchor" or "url" to output either an <A>... or just the HREF part of one.
034 *  </UL>
035 *
036 *  @since 2.0
037 */
038public class UploadLinkTag
039    extends WikiLinkTag
040{
041    private static final long serialVersionUID = 0L;
042    
043    public final int doWikiStartTag()
044        throws IOException
045    {
046        String     pageName = m_pageName;
047
048        if( m_pageName == null )
049        {
050            if( m_wikiContext.getPage() != null )
051            {
052                pageName = m_wikiContext.getPage().getName();
053            }
054            else
055            {
056                return SKIP_BODY;
057            }
058        }
059
060        JspWriter out = pageContext.getOut();
061
062        String url = m_wikiContext.getURL( WikiContext.UPLOAD,
063                                           pageName );
064
065        switch( m_format )
066        {
067          case ANCHOR:
068            out.print("<a target=\"_new\" class=\"uploadlink\" href=\""+url+"\">");
069            break;
070          case URL:
071            out.print( url );
072            break;
073        }
074
075        return EVAL_BODY_INCLUDE;
076    }
077
078}