KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > poifs > filesystem > DocumentNode


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18
19 package org.apache.poi.poifs.filesystem;
20
21 import java.util.*;
22
23 import org.apache.poi.poifs.dev.POIFSViewable;
24 import org.apache.poi.poifs.property.DocumentProperty;
25
26 /**
27  * Simple implementation of DocumentEntry
28  *
29  * @author Marc Johnson (mjohnson at apache dot org)
30  */

31
32 public class DocumentNode
33     extends EntryNode
34     implements DocumentEntry, POIFSViewable
35 {
36
37     // underlying POIFSDocument instance
38
private POIFSDocument _document;
39
40     /**
41      * create a DocumentNode. This method is not public by design; it
42      * is intended strictly for the internal use of this package
43      *
44      * @param property the DocumentProperty for this DocumentEntry
45      * @param parent the parent of this entry
46      */

47
48     DocumentNode(final DocumentProperty property, final DirectoryNode parent)
49     {
50         super(property, parent);
51         _document = property.getDocument();
52     }
53
54     /**
55      * get the POIFSDocument
56      *
57      * @return the internal POIFSDocument
58      */

59
60     POIFSDocument getDocument()
61     {
62         return _document;
63     }
64
65     /* ********** START implementation of DocumentEntry ********** */
66
67     /**
68      * get the zize of the document, in bytes
69      *
70      * @return size in bytes
71      */

72
73     public int getSize()
74     {
75         return getProperty().getSize();
76     }
77
78     /* ********** END implementation of DocumentEntry ********** */
79     /* ********** START implementation of Entry ********** */
80
81     /**
82      * is this a DocumentEntry?
83      *
84      * @return true if the Entry is a DocumentEntry, else false
85      */

86
87     public boolean isDocumentEntry()
88     {
89         return true;
90     }
91
92     /* ********** END implementation of Entry ********** */
93     /* ********** START extension of Entry ********** */
94
95     /**
96      * extensions use this method to verify internal rules regarding
97      * deletion of the underlying store.
98      *
99      * @return true if it's ok to delete the underlying store, else
100      * false
101      */

102
103     protected boolean isDeleteOK()
104     {
105         return true;
106     }
107
108     /* ********** END extension of Entry ********** */
109     /* ********** START begin implementation of POIFSViewable ********** */
110
111     /**
112      * Get an array of objects, some of which may implement
113      * POIFSViewable
114      *
115      * @return an array of Object; may not be null, but may be empty
116      */

117
118     public Object JavaDoc [] getViewableArray()
119     {
120         return new Object JavaDoc[ 0 ];
121     }
122
123     /**
124      * Get an Iterator of objects, some of which may implement
125      * POIFSViewable
126      *
127      * @return an Iterator; may not be null, but may have an empty
128      * back end store
129      */

130
131     public Iterator getViewableIterator()
132     {
133         List components = new ArrayList();
134
135         components.add(getProperty());
136         components.add(_document);
137         return components.iterator();
138     }
139
140     /**
141      * Give viewers a hint as to whether to call getViewableArray or
142      * getViewableIterator
143      *
144      * @return true if a viewer should call getViewableArray, false if
145      * a viewer should call getViewableIterator
146      */

147
148     public boolean preferArray()
149     {
150         return false;
151     }
152
153     /**
154      * Provides a short description of the object, to be used when a
155      * POIFSViewable object has not provided its contents.
156      *
157      * @return short description
158      */

159
160     public String JavaDoc getShortDescription()
161     {
162         return getName();
163     }
164
165     /* ********** END begin implementation of POIFSViewable ********** */
166 } // end public class DocumentNode
167

168
Popular Tags