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.Attachment; 022import org.apache.wiki.api.core.Page; 023 024import java.io.IOException; 025 026/** 027 * Writes a link to a parent of a Wiki page. 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 "anchor" or "url" to output either an <A>... or just the HREF part of one. 033 * </UL> 034 * 035 * @since 2.0 036 */ 037public class LinkToParentTag extends LinkToTag { 038 039 private static final long serialVersionUID = 0L; 040 041 public int doWikiStartTag() throws IOException { 042 final Page p = m_wikiContext.getPage(); 043 044 // We just simply set the page to be our parent page and call the superclass. 045 if( p instanceof Attachment ) { 046 setPage( ((Attachment)p).getParentName() ); 047 } else { 048 final String name = p.getName(); 049 final int entrystart = name.indexOf( "_blogentry_" ); 050 if( entrystart != -1 ) { 051 setPage( name.substring( 0, entrystart ) ); 052 } 053 054 final int commentstart = name.indexOf( "_comments_" ); 055 if( commentstart != -1 ) { 056 setPage( name.substring( 0, commentstart ) ); 057 } 058 } 059 060 return super.doWikiStartTag(); 061 } 062 063}