    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;
    022import org.apache.wiki.api.core.Engine;
    023import org.apache.wiki.api.core.Page;
    024import org.apache.wiki.pages.PageManager;
    025
    026import jakarta.servlet.jsp.JspWriter;
    027import java.io.IOException;
    028
    029/**
    030 *  Writes a link to the Wiki PageInfo.  Body of the link becomes the actual text.
    031 *
    032 *  <P><B>Attributes</B></P>
    033 *  <UL>
    034 *    <LI>page - Page name to refer to.  Default is the current page.
    035 *    <LI>title - Is used in page actions to display hover text (tooltip)
    036 *    <LI>accesskey - Set an accesskey (ALT+[Char])
    037 *  </UL>
    038 *
    039 *  @since 2.0
    040 */
    041// FIXME: Refactor together with LinkToTag and EditLinkTag.
    042public class PageInfoLinkTag 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( final String title )
    049    {
    050        m_title = title;
    051    }
    052
    053    public void setAccesskey( final String access )
    054    {
    055        m_accesskey = access;
    056    }
    057
    058    @Override public final int doWikiStartTag() throws IOException {
    059        final Engine engine = m_wikiContext.getEngine();
    060        String     pageName = m_pageName;
    061
    062        if( m_pageName == null ) {
    063            final Page p = m_wikiContext.getPage();
    064            if( p != null ) {
    065                pageName = p.getName();
    066            } else {
    067                return SKIP_BODY;
    068            }
    069        }
    070
    071        if( engine.getManager( PageManager.class ).wikiPageExists(pageName) ) {
    072            final JspWriter out = pageContext.getOut();
    073            final String url = m_wikiContext.getURL( ContextEnum.PAGE_INFO.getRequestContext(), pageName );
    074
    075            switch( m_format ) {
    076              case ANCHOR: out.print("<a class=\"pageinfo\" href=\""+url+"\" accesskey=\"" + m_accesskey + "\" title=\"" + m_title + "\">"); break;
    077              case URL: out.print( url ); break;
    078            }
    079            return EVAL_BODY_INCLUDE;
    080        }
    081        return SKIP_BODY;
    082    }
    083
    084}