1    
2    /* ====================================================================
3     * The Apache Software License, Version 1.1
4     *
5     * Copyright (c) 2002 The Apache Software Foundation.  All rights
6     * reserved.
7     *
8     * Redistribution and use in source and binary forms, with or without
9     * modification, are permitted provided that the following conditions
10    * are met:
11    *
12    * 1. Redistributions of source code must retain the above copyright
13    *    notice, this list of conditions and the following disclaimer.
14    *
15    * 2. Redistributions in binary form must reproduce the above copyright
16    *    notice, this list of conditions and the following disclaimer in
17    *    the documentation and/or other materials provided with the
18    *    distribution.
19    *
20    * 3. The end-user documentation included with the redistribution,
21    *    if any, must include the following acknowledgment:
22    *       "This product includes software developed by the
23    *        Apache Software Foundation (http://www.apache.org/)."
24    *    Alternately, this acknowledgment may appear in the software itself,
25    *    if and wherever such third-party acknowledgments normally appear.
26    *
27    * 4. The names "Apache" and "Apache Software Foundation" and
28    *    "Apache POI" must not be used to endorse or promote products
29    *    derived from this software without prior written permission. For
30    *    written permission, please contact apache@apache.org.
31    *
32    * 5. Products derived from this software may not be called "Apache",
33    *    "Apache POI", nor may "Apache" appear in their name, without
34    *    prior written permission of the Apache Software Foundation.
35    *
36    * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37    * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38    * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39    * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40    * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41    * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42    * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43    * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44    * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45    * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46    * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47    * SUCH DAMAGE.
48    * ====================================================================
49    *
50    * This software consists of voluntary contributions made by many
51    * individuals on behalf of the Apache Software Foundation.  For more
52    * information on the Apache Software Foundation, please see
53    * <http://www.apache.org/>.
54    */
55   
56   package org.apache.poi.poifs.filesystem;
57   
58   import java.util.*;
59   
60   import org.apache.poi.poifs.dev.POIFSViewable;
61   import org.apache.poi.poifs.property.DocumentProperty;
62   
63   /**
64    * Simple implementation of DocumentEntry
65    *
66    * @author Marc Johnson (mjohnson at apache dot org)
67    */
68   
69   public class DocumentNode
70       extends EntryNode
71       implements DocumentEntry, POIFSViewable
72   {
73   
74       // underlying POIFSDocument instance
75       private POIFSDocument _document;
76   
77       /**
78        * create a DocumentNode. This method is not public by design; it
79        * is intended strictly for the internal use of this package
80        *
81        * @param property the DocumentProperty for this DocumentEntry
82        * @param parent the parent of this entry
83        */
84   
85       DocumentNode(final DocumentProperty property, final DirectoryNode parent)
86       {
87           super(property, parent);
88           _document = property.getDocument();
89       }
90   
91       /**
92        * get the POIFSDocument
93        *
94        * @return the internal POIFSDocument
95        */
96   
97       POIFSDocument getDocument()
98       {
99           return _document;
100      }
101  
102      /* ********** START implementation of DocumentEntry ********** */
103  
104      /**
105       * get the zize of the document, in bytes
106       *
107       * @return size in bytes
108       */
109  
110      public int getSize()
111      {
112          return getProperty().getSize();
113      }
114  
115      /* **********  END  implementation of DocumentEntry ********** */
116      /* ********** START implementation of Entry ********** */
117  
118      /**
119       * is this a DocumentEntry?
120       *
121       * @return true if the Entry is a DocumentEntry, else false
122       */
123  
124      public boolean isDocumentEntry()
125      {
126          return true;
127      }
128  
129      /* **********  END  implementation of Entry ********** */
130      /* ********** START extension of Entry ********** */
131  
132      /**
133       * extensions use this method to verify internal rules regarding
134       * deletion of the underlying store.
135       *
136       * @return true if it's ok to delete the underlying store, else
137       *         false
138       */
139  
140      protected boolean isDeleteOK()
141      {
142          return true;
143      }
144  
145      /* **********  END  extension of Entry ********** */
146      /* ********** START begin implementation of POIFSViewable ********** */
147  
148      /**
149       * Get an array of objects, some of which may implement
150       * POIFSViewable
151       *
152       * @return an array of Object; may not be null, but may be empty
153       */
154  
155      public Object [] getViewableArray()
156      {
157          return new Object[ 0 ];
158      }
159  
160      /**
161       * Get an Iterator of objects, some of which may implement
162       * POIFSViewable
163       *
164       * @return an Iterator; may not be null, but may have an empty
165       * back end store
166       */
167  
168      public Iterator getViewableIterator()
169      {
170          List components = new ArrayList();
171  
172          components.add(getProperty());
173          components.add(_document);
174          return components.iterator();
175      }
176  
177      /**
178       * Give viewers a hint as to whether to call getViewableArray or
179       * getViewableIterator
180       *
181       * @return true if a viewer should call getViewableArray, false if
182       *         a viewer should call getViewableIterator
183       */
184  
185      public boolean preferArray()
186      {
187          return false;
188      }
189  
190      /**
191       * Provides a short description of the object, to be used when a
192       * POIFSViewable object has not provided its contents.
193       *
194       * @return short description
195       */
196  
197      public String getShortDescription()
198      {
199          return getName();
200      }
201  
202      /* **********  END  begin implementation of POIFSViewable ********** */
203  }   // end public class DocumentNode
204  
205