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 023import org.apache.wiki.WikiPage; 024import org.apache.wiki.attachment.Attachment; 025 026/** 027 * Includes the body, if the current page is of proper type. 028 * 029 * <B>Attributes</B> 030 * <UL> 031 * <LI>type - either "page", "attachment" or "weblogentry" 032 * </UL> 033 * 034 * @since 2.0 035 */ 036public class PageTypeTag 037 extends WikiTagBase 038{ 039 private static final long serialVersionUID = 0L; 040 041 private String m_type; 042 043 public void initTag() 044 { 045 super.initTag(); 046 m_type = null; 047 } 048 049 public void setType( String arg ) 050 { 051 m_type = arg.toLowerCase(); 052 } 053 054 public final int doWikiStartTag() 055 throws IOException 056 { 057 WikiPage page = m_wikiContext.getPage(); 058 059 if( page != null ) 060 { 061 if( m_type.equals("attachment") && page instanceof Attachment ) 062 { 063 return EVAL_BODY_INCLUDE; 064 } 065 066 if( m_type.equals("page") && !(page instanceof Attachment) ) 067 { 068 return EVAL_BODY_INCLUDE; 069 } 070 071 if( m_type.equals("weblogentry") && !(page instanceof Attachment) && page.getName().indexOf("_blogentry_") != -1 ) 072 { 073 return EVAL_BODY_INCLUDE; 074 } 075 } 076 077 return SKIP_BODY; 078 } 079}