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.

Comment2000.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 org.apache.poi.util.LittleEndian;
  19. import org.apache.poi.util.POILogger;
  20. /**
  21. * This class represents a comment on a slide, in the format used by
  22. * PPT 2000/XP/etc. (PPT 97 uses plain Escher Text Boxes for comments)
  23. * @author Nick Burch
  24. */
  25. public final class Comment2000 extends RecordContainer {
  26. private byte[] _header;
  27. private static final long _type = RecordTypes.Comment2000.typeID;
  28. // Links to our more interesting children
  29. /**
  30. * An optional string that specifies the name of the author of the presentation comment.
  31. */
  32. private CString authorRecord;
  33. /**
  34. * An optional string record that specifies the text of the presentation comment
  35. */
  36. private CString authorInitialsRecord;
  37. /**
  38. * An optional string record that specifies the initials of the author of the presentation comment
  39. */
  40. private CString commentRecord;
  41. /**
  42. * A Comment2000Atom record that specifies the settings for displaying the presentation comment
  43. */
  44. private Comment2000Atom commentAtom;
  45. /**
  46. * Returns the Comment2000Atom of this Comment
  47. */
  48. public Comment2000Atom getComment2000Atom() { return commentAtom; }
  49. /**
  50. * Get the Author of this comment
  51. */
  52. public String getAuthor() {
  53. return authorRecord == null ? null : authorRecord.getText();
  54. }
  55. /**
  56. * Set the Author of this comment
  57. */
  58. public void setAuthor(String author) {
  59. authorRecord.setText(author);
  60. }
  61. /**
  62. * Get the Author's Initials of this comment
  63. */
  64. public String getAuthorInitials() {
  65. return authorInitialsRecord == null ? null : authorInitialsRecord.getText();
  66. }
  67. /**
  68. * Set the Author's Initials of this comment
  69. */
  70. public void setAuthorInitials(String initials) {
  71. authorInitialsRecord.setText(initials);
  72. }
  73. /**
  74. * Get the text of this comment
  75. */
  76. public String getText() {
  77. return commentRecord == null ? null : commentRecord.getText();
  78. }
  79. /**
  80. * Set the text of this comment
  81. */
  82. public void setText(String text) {
  83. commentRecord.setText(text);
  84. }
  85. /**
  86. * Set things up, and find our more interesting children
  87. */
  88. protected Comment2000(byte[] source, int start, int len) {
  89. // Grab the header
  90. _header = new byte[8];
  91. System.arraycopy(source,start,_header,0,8);
  92. // Find our children
  93. _children = org.apache.poi.hslf.record.Record.findChildRecords(source,start+8,len-8);
  94. findInterestingChildren();
  95. }
  96. /**
  97. * Go through our child records, picking out the ones that are
  98. * interesting, and saving those for use by the easy helper
  99. * methods.
  100. */
  101. private void findInterestingChildren() {
  102. for(org.apache.poi.hslf.record.Record r : _children){
  103. if (r instanceof CString){
  104. CString cs = (CString)r;
  105. int recInstance = cs.getOptions() >> 4;
  106. switch(recInstance){
  107. case 0: authorRecord = cs; break;
  108. case 1: commentRecord = cs; break;
  109. case 2: authorInitialsRecord = cs; break;
  110. default: break;
  111. }
  112. } else if (r instanceof Comment2000Atom){
  113. commentAtom = (Comment2000Atom)r;
  114. } else {
  115. logger.log(POILogger.WARN, "Unexpected record with type="+r.getRecordType()+" in Comment2000: " + r.getClass().getName());
  116. }
  117. }
  118. }
  119. /**
  120. * Create a new Comment2000, with blank fields
  121. */
  122. public Comment2000() {
  123. _header = new byte[8];
  124. _children = new org.apache.poi.hslf.record.Record[4];
  125. // Setup our header block
  126. _header[0] = 0x0f; // We are a container record
  127. LittleEndian.putShort(_header, 2, (short)_type);
  128. // Setup our child records
  129. CString csa = new CString();
  130. CString csb = new CString();
  131. CString csc = new CString();
  132. csa.setOptions(0x00);
  133. csb.setOptions(0x10);
  134. csc.setOptions(0x20);
  135. _children[0] = csa;
  136. _children[1] = csb;
  137. _children[2] = csc;
  138. _children[3] = new Comment2000Atom();
  139. findInterestingChildren();
  140. }
  141. /**
  142. * We are of type 1200
  143. */
  144. public long getRecordType() { return _type; }
  145. /**
  146. * Write the contents of the record back, so it can be written
  147. * to disk
  148. */
  149. public void writeOut(OutputStream out) throws IOException {
  150. writeOut(_header[0],_header[1],_type,_children,out);
  151. }
  152. }