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.attachment;
020
021import org.apache.wiki.WikiEngine;
022import org.apache.wiki.WikiPage;
023
024/**
025 *  Describes an attachment.  Attachments are actually derivatives of
026 *  a WikiPage, since they do actually have a WikiName as well.
027 *
028 */
029public class Attachment
030    extends WikiPage
031{
032    private String m_fileName;
033    private String m_parentName;
034    private boolean m_cacheable = true;
035
036    /**
037     *  Creates a new attachment.  The final name of the attachment will be 
038     *  a synthesis of the parent page name and the file name.
039     *  
040     *  @param engine     The WikiEngine which is hosting this attachment.
041     *  @param parentPage The page which will contain this attachment.
042     *  @param fileName   The file name for the attachment.
043     */
044    public Attachment( WikiEngine engine, String parentPage, String fileName )
045    {
046        super( engine, parentPage+"/"+fileName );
047
048        m_parentName = parentPage;
049        m_fileName   = fileName;
050    }
051
052    /**
053     *  Returns a human-readable, only-debugging-suitable description.
054     *  
055     *  @return A debugging string
056     */
057    public String toString()
058    {
059        return "Attachment ["+getName()+";mod="+getLastModified()+"]";
060    }
061
062    /**
063     *  Returns the file name of the attachment.
064     *  
065     *  @return A String with the file name.
066     */
067    public String getFileName()
068    {
069        return m_fileName;
070    }
071
072    /**
073     *  Sets the file name of this attachment. 
074     *  
075     *  @param name The name of the attachment.  Must be a legal file name without
076     *              the path.
077     */
078    public void setFileName( String name )
079    {
080        m_fileName = name;
081    }
082
083    /**
084     *  Returns the name of the parent of this Attachment, i.e. the page
085     *  which contains this attachment.
086     *  
087     *  @return String depicting the parent of the attachment.
088     */
089    public String getParentName()
090    {
091        return m_parentName;
092    }
093
094    /**
095     *  Returns true, if this attachment can be cached by the user agent.  By default
096     *  attachments are cacheable.
097     *  
098     *  @return False, if the attachment should not be cached by the user agent.
099     *  @since 2.5.34
100     */
101    public boolean isCacheable()
102    {
103        return m_cacheable;
104    }
105
106    /**
107     *  Sets this attachment to be cacheable or not.  This mostly concerns things
108     *  like DynamicAttachments, but it may be useful for certain AttachmentProviders
109     *  as well.
110     *  
111     *  @param value True or false, depending on whether you want this attachment
112     *               to be cacheable or not.
113     *  @since 2.5.34
114     */
115    public void setCacheable(boolean value)
116    {
117        m_cacheable = value;
118    }
119}