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.

SlideListWithText.java 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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.hslf.record;
  16. import java.io.IOException;
  17. import java.io.OutputStream;
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. import org.apache.poi.util.LittleEndian;
  21. /**
  22. * These are tricky beasts. They contain the text of potentially
  23. * many (normal) slides. They are made up of several sets of
  24. * - SlidePersistAtom
  25. * - TextHeaderAtom
  26. * - TextBytesAtom / TextCharsAtom
  27. * - StyleTextPropAtom (optional)
  28. * - TextSpecInfoAtom (optional)
  29. * - InteractiveInfo (optional)
  30. * - TxInteractiveInfoAtom (optional)
  31. * and then the next SlidePersistAtom.
  32. *
  33. * Eventually, Slides will find the blocks that interest them from all
  34. * the SlideListWithText entries, and refere to them
  35. *
  36. * For now, we scan through looking for interesting bits, then creating
  37. * the helpful Sheet from model for them
  38. *
  39. * @author Nick Burch
  40. */
  41. // For now, pretend to be an atom
  42. public final class SlideListWithText extends RecordContainer {
  43. /**
  44. * Instance filed of the record header indicates that this SlideListWithText stores
  45. * references to slides
  46. */
  47. public static final int SLIDES = 0;
  48. /**
  49. * Instance filed of the record header indicates that this SlideListWithText stores
  50. * references to master slides
  51. */
  52. public static final int MASTER = 1;
  53. /**
  54. * Instance filed of the record header indicates that this SlideListWithText stores
  55. * references to notes
  56. */
  57. public static final int NOTES = 2;
  58. private byte[] _header;
  59. private static long _type = 4080;
  60. private SlideAtomsSet[] slideAtomsSets;
  61. /**
  62. * Create a new holder for slide records
  63. */
  64. protected SlideListWithText(byte[] source, int start, int len) {
  65. // Grab the header
  66. _header = new byte[8];
  67. System.arraycopy(source,start,_header,0,8);
  68. // Find our children
  69. _children = Record.findChildRecords(source,start+8,len-8);
  70. // Group our children together into SlideAtomsSets
  71. // That way, model layer code can just grab the sets to use,
  72. // without having to try to match the children together
  73. List<SlideAtomsSet> sets = new ArrayList<SlideAtomsSet>();
  74. for(int i=0; i<_children.length; i++) {
  75. if(_children[i] instanceof SlidePersistAtom) {
  76. // Find where the next SlidePersistAtom is
  77. int endPos = i+1;
  78. while(endPos < _children.length && !(_children[endPos] instanceof SlidePersistAtom)) {
  79. endPos += 1;
  80. }
  81. int clen = endPos - i - 1;
  82. // Create a SlideAtomsSets, not caring if they're empty
  83. //if(emptySet) { continue; }
  84. Record[] spaChildren = new Record[clen];
  85. System.arraycopy(_children,i+1,spaChildren,0,clen);
  86. SlideAtomsSet set = new SlideAtomsSet((SlidePersistAtom)_children[i],spaChildren);
  87. sets.add(set);
  88. // Wind on
  89. i += clen;
  90. }
  91. }
  92. // Turn the list into an array
  93. slideAtomsSets = sets.toArray( new SlideAtomsSet[sets.size()] );
  94. }
  95. /**
  96. * Create a new, empty, SlideListWithText
  97. */
  98. public SlideListWithText(){
  99. _header = new byte[8];
  100. LittleEndian.putUShort(_header, 0, 15);
  101. LittleEndian.putUShort(_header, 2, (int)_type);
  102. LittleEndian.putInt(_header, 4, 0);
  103. // We have no children to start with
  104. _children = new Record[0];
  105. slideAtomsSets = new SlideAtomsSet[0];
  106. }
  107. /**
  108. * Add a new SlidePersistAtom, to the end of the current list,
  109. * and update the internal list of SlidePersistAtoms
  110. * @param spa
  111. */
  112. public void addSlidePersistAtom(SlidePersistAtom spa) {
  113. // Add the new SlidePersistAtom at the end
  114. appendChildRecord(spa);
  115. SlideAtomsSet newSAS = new SlideAtomsSet(spa, new Record[0]);
  116. // Update our SlideAtomsSets with this
  117. SlideAtomsSet[] sas = new SlideAtomsSet[slideAtomsSets.length+1];
  118. System.arraycopy(slideAtomsSets, 0, sas, 0, slideAtomsSets.length);
  119. sas[sas.length-1] = newSAS;
  120. slideAtomsSets = sas;
  121. }
  122. public int getInstance(){
  123. return LittleEndian.getShort(_header, 0) >> 4;
  124. }
  125. public void setInstance(int inst){
  126. LittleEndian.putShort(_header, 0, (short)((inst << 4) | 0xF));
  127. }
  128. /**
  129. * Get access to the SlideAtomsSets of the children of this record
  130. */
  131. public SlideAtomsSet[] getSlideAtomsSets() { return slideAtomsSets; }
  132. /**
  133. * Get access to the SlideAtomsSets of the children of this record
  134. */
  135. public void setSlideAtomsSets( SlideAtomsSet[] sas ) { slideAtomsSets = sas; }
  136. /**
  137. * Return the value we were given at creation
  138. */
  139. public long getRecordType() { return _type; }
  140. /**
  141. * Write the contents of the record back, so it can be written
  142. * to disk
  143. */
  144. public void writeOut(OutputStream out) throws IOException {
  145. writeOut(_header[0],_header[1],_type,_children,out);
  146. }
  147. /**
  148. * Inner class to wrap up a matching set of records that hold the
  149. * text for a given sheet. Contains the leading SlidePersistAtom,
  150. * and all of the records until the next SlidePersistAtom. This
  151. * includes sets of TextHeaderAtom and TextBytesAtom/TextCharsAtom,
  152. * along with some others.
  153. */
  154. public static class SlideAtomsSet {
  155. private SlidePersistAtom slidePersistAtom;
  156. private Record[] slideRecords;
  157. /** Get the SlidePersistAtom, which gives details on the Slide this text is associated with */
  158. public SlidePersistAtom getSlidePersistAtom() { return slidePersistAtom; }
  159. /** Get the Text related records for this slide */
  160. public Record[] getSlideRecords() { return slideRecords; }
  161. /** Create one to hold the Records for one Slide's text */
  162. public SlideAtomsSet(SlidePersistAtom s, Record[] r) {
  163. slidePersistAtom = s;
  164. slideRecords = r;
  165. }
  166. }
  167. }