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 * (<a> 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 @Override 051 public void initTag() 052 { 053 super.initTag(); 054 m_pageName = m_template = null; 055 m_format = ANCHOR; 056 } 057 058 public void setPage(final String page ) 059 { 060 m_pageName = page; 061 } 062 063 public String getPage() 064 { 065 return m_pageName; 066 } 067 068 069 public String getTemplate() 070 { 071 return m_template; 072 } 073 074 public void setTemplate(final String arg ) 075 { 076 m_template = arg; 077 } 078 079 public void setFormat(final String mode ) 080 { 081 if( "url".equalsIgnoreCase(mode) ) 082 { 083 m_format = URL; 084 } 085 else 086 { 087 m_format = ANCHOR; 088 } 089 } 090 091 @Override 092 public int doEndTag() 093 { 094 try 095 { 096 if( m_format == ANCHOR ) 097 { 098 pageContext.getOut().print("</a>"); 099 } 100 } 101 catch( final IOException e ) 102 { 103 // FIXME: Should do something? 104 } 105 106 return EVAL_PAGE; 107 } 108}