You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DocumentNode.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.poifs.filesystem;
  16. import java.util.ArrayList;
  17. import java.util.Iterator;
  18. import java.util.List;
  19. import org.apache.poi.poifs.dev.POIFSViewable;
  20. import org.apache.poi.poifs.property.DocumentProperty;
  21. /**
  22. * Simple implementation of DocumentEntry for OPOIFS
  23. */
  24. public class DocumentNode
  25. extends EntryNode
  26. implements DocumentEntry, POIFSViewable
  27. {
  28. // underlying POIFSDocument instance
  29. private POIFSDocument _document;
  30. /**
  31. * create a DocumentNode. This method is not public by design; it
  32. * is intended strictly for the internal use of this package
  33. *
  34. * @param property the DocumentProperty for this DocumentEntry
  35. * @param parent the parent of this entry
  36. */
  37. DocumentNode(final DocumentProperty property, final DirectoryNode parent)
  38. {
  39. super(property, parent);
  40. _document = property.getDocument();
  41. }
  42. /**
  43. * get the POIFSDocument
  44. *
  45. * @return the internal POIFSDocument
  46. */
  47. POIFSDocument getDocument()
  48. {
  49. return _document;
  50. }
  51. /* ********** START implementation of DocumentEntry ********** */
  52. /**
  53. * get the zize of the document, in bytes
  54. *
  55. * @return size in bytes
  56. */
  57. public int getSize()
  58. {
  59. return getProperty().getSize();
  60. }
  61. /* ********** END implementation of DocumentEntry ********** */
  62. /* ********** START implementation of Entry ********** */
  63. /**
  64. * is this a DocumentEntry?
  65. *
  66. * @return true if the Entry is a DocumentEntry, else false
  67. */
  68. @Override
  69. public boolean isDocumentEntry()
  70. {
  71. return true;
  72. }
  73. /* ********** END implementation of Entry ********** */
  74. /* ********** START extension of Entry ********** */
  75. /**
  76. * extensions use this method to verify internal rules regarding
  77. * deletion of the underlying store.
  78. *
  79. * @return true if it's ok to delete the underlying store, else
  80. * false
  81. */
  82. @Override
  83. protected boolean isDeleteOK()
  84. {
  85. return true;
  86. }
  87. /* ********** END extension of Entry ********** */
  88. /* ********** START begin implementation of POIFSViewable ********** */
  89. /**
  90. * Get an array of objects, some of which may implement
  91. * POIFSViewable
  92. *
  93. * @return an array of Object; may not be null, but may be empty
  94. */
  95. public Object [] getViewableArray()
  96. {
  97. return new Object[ 0 ];
  98. }
  99. /**
  100. * Get an Iterator of objects, some of which may implement
  101. * POIFSViewable
  102. *
  103. * @return an Iterator; may not be null, but may have an empty
  104. * back end store
  105. */
  106. public Iterator<Object> getViewableIterator()
  107. {
  108. List<Object> components = new ArrayList<>();
  109. components.add(getProperty());
  110. if (_document != null) {
  111. components.add(_document);
  112. }
  113. return components.iterator();
  114. }
  115. /**
  116. * Give viewers a hint as to whether to call getViewableArray or
  117. * getViewableIterator
  118. *
  119. * @return true if a viewer should call getViewableArray, false if
  120. * a viewer should call getViewableIterator
  121. */
  122. public boolean preferArray()
  123. {
  124. return false;
  125. }
  126. /**
  127. * Provides a short description of the object, to be used when a
  128. * POIFSViewable object has not provided its contents.
  129. *
  130. * @return short description
  131. */
  132. public String getShortDescription()
  133. {
  134. return getName();
  135. }
  136. /* ********** END begin implementation of POIFSViewable ********** */
  137. } // end public class DocumentNode