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
023 import org.apache.wiki.WikiPage;
024 import org.apache.wiki.attachment.Attachment;
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 */
037 public class LinkToParentTag
038 extends LinkToTag
039 {
040 private static final long serialVersionUID = 0L;
041
042 public int doWikiStartTag()
043 throws IOException
044 {
045 WikiPage p = m_wikiContext.getPage();
046
047 //
048 // We just simply set the page to be our parent page
049 // and call the superclass.
050 //
051 if( p instanceof Attachment )
052 {
053 setPage( ((Attachment)p).getParentName() );
054 }
055 else
056 {
057 String name = p.getName();
058
059 int entrystart = name.indexOf("_blogentry_");
060
061 if( entrystart != -1 )
062 {
063 setPage( name.substring( 0, entrystart ) );
064 }
065
066 int commentstart = name.indexOf("_comments_");
067
068 if( commentstart != -1 )
069 {
070 setPage( name.substring( 0, commentstart ) );
071 }
072 }
073
074 return super.doWikiStartTag();
075 }
076
077 }