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.wiki.api.core.ContextEnum; 022 023import javax.servlet.jsp.JspWriter; 024import java.io.IOException; 025 026 027/** 028 * Writes a link to the upload page. Body of the link becomes the actual text. 029 * The link is written regardless to whether the page exists or not. 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 extends WikiLinkTag { 039 040 private static final long serialVersionUID = 0L; 041 042 @Override 043 public final int doWikiStartTag() throws IOException { 044 String pageName = m_pageName; 045 if( m_pageName == null ) { 046 if( m_wikiContext.getPage() != null ) { 047 pageName = m_wikiContext.getPage().getName(); 048 } else { 049 return SKIP_BODY; 050 } 051 } 052 053 final JspWriter out = pageContext.getOut(); 054 final String url = m_wikiContext.getURL( ContextEnum.PAGE_UPLOAD.getRequestContext(), pageName ); 055 switch( m_format ) { 056 case ANCHOR: 057 out.print( "<a target=\"_new\" class=\"uploadlink\" href=\"" + url + "\">" ); 058 break; 059 case URL: 060 out.print( url ); 061 break; 062 } 063 064 return EVAL_BODY_INCLUDE; 065 } 066 067}