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 */
019 package org.apache.wiki.tags;
020
021 import java.io.IOException;
022 import javax.servlet.jsp.JspWriter;
023
024 import org.apache.wiki.WikiContext;
025 import org.apache.wiki.WikiEngine;
026 import org.apache.wiki.WikiPage;
027
028 /**
029 * Writes a link to the Wiki PageInfo. Body of the link becomes the actual text.
030 *
031 * <P><B>Attributes</B></P>
032 * <UL>
033 * <LI>page - Page name to refer to. Default is the current page.
034 * <LI>title - Is used in page actions to display hover text (tooltip)
035 * <LI>accesskey - Set an accesskey (ALT+[Char])
036 * </UL>
037 *
038 * @since 2.0
039 */
040 // FIXME: Refactor together with LinkToTag and EditLinkTag.
041 public class PageInfoLinkTag
042 extends WikiLinkTag
043 {
044 private static final long serialVersionUID = 0L;
045 public String m_title = "";
046 public String m_accesskey = "";
047
048 public void setTitle( String title )
049 {
050 m_title = title;
051 }
052
053 public void setAccesskey( String access )
054 {
055 m_accesskey = access;
056 }
057
058 public final int doWikiStartTag()
059 throws IOException
060 {
061 WikiEngine engine = m_wikiContext.getEngine();
062 String pageName = m_pageName;
063
064 if( m_pageName == null )
065 {
066 WikiPage p = m_wikiContext.getPage();
067
068 if( p != null )
069 {
070 pageName = p.getName();
071 }
072 else
073 {
074 return SKIP_BODY;
075 }
076 }
077
078 if( engine.pageExists(pageName) )
079 {
080 JspWriter out = pageContext.getOut();
081
082 String url = m_wikiContext.getURL( WikiContext.INFO, pageName );
083
084 switch( m_format )
085 {
086 case ANCHOR:
087 out.print("<a class=\"pageinfo\" href=\""+url+"\" accesskey=\""
088 + m_accesskey + "\" title=\"" + m_title + "\">");
089 break;
090 case URL:
091 out.print( url );
092 break;
093 }
094
095 return EVAL_BODY_INCLUDE;
096 }
097
098 return SKIP_BODY;
099 }
100 }