001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hslf.record;
019:
020: import org.apache.poi.util.LittleEndian;
021: import java.io.IOException;
022: import java.io.OutputStream;
023:
024: /**
025: * A SlidePersist Atom (type 1011). Holds information on the text of a
026: * given slide, which are stored in the same SlideListWithText
027: *
028: * @author Nick Burch
029: */
030:
031: public class SlidePersistAtom extends RecordAtom {
032: private byte[] _header;
033: private static long _type = 1011l;
034:
035: /**
036: * Slide reference ID. Should correspond to the PersistPtr
037: * "sheet ID" of the matching slide/notes record
038: */
039: private int refID;
040: private boolean hasShapesOtherThanPlaceholders;
041: /** Number of placeholder texts that will follow in the SlideListWithText */
042: private int numPlaceholderTexts;
043: /**
044: * The internal identifier (256+), which is used to tie slides
045: * and notes together
046: */
047: private int slideIdentifier;
048: /** Reserved fields. Who knows what they do */
049: private byte[] reservedFields;
050:
051: public int getRefID() {
052: return refID;
053: }
054:
055: public int getSlideIdentifier() {
056: return slideIdentifier;
057: }
058:
059: public int getNumPlaceholderTexts() {
060: return numPlaceholderTexts;
061: }
062:
063: public boolean getHasShapesOtherThanPlaceholders() {
064: return hasShapesOtherThanPlaceholders;
065: }
066:
067: // Only set these if you know what you're doing!
068: public void setRefID(int id) {
069: refID = id;
070: }
071:
072: public void setSlideIdentifier(int id) {
073: slideIdentifier = id;
074: }
075:
076: /* *************** record code follows ********************** */
077:
078: /**
079: * For the SlidePersist Atom
080: */
081: protected SlidePersistAtom(byte[] source, int start, int len) {
082: // Sanity Checking
083: if (len < 8) {
084: len = 8;
085: }
086:
087: // Get the header
088: _header = new byte[8];
089: System.arraycopy(source, start, _header, 0, 8);
090:
091: // Grab the reference ID
092: refID = (int) LittleEndian.getInt(source, start + 8);
093:
094: // Next up is a set of flags, but only bit 3 is used!
095: int flags = (int) LittleEndian.getInt(source, start + 12);
096: if (flags == 4) {
097: hasShapesOtherThanPlaceholders = true;
098: } else {
099: hasShapesOtherThanPlaceholders = false;
100: }
101:
102: // Now the number of Placeholder Texts
103: numPlaceholderTexts = (int) LittleEndian.getInt(source,
104: start + 16);
105:
106: // Last useful one is the unique slide identifier
107: slideIdentifier = (int) LittleEndian.getInt(source, start + 20);
108:
109: // Finally you have typically 4 or 8 bytes of reserved fields,
110: // all zero running from 24 bytes in to the end
111: reservedFields = new byte[len - 24];
112: System.arraycopy(source, start + 24, reservedFields, 0,
113: reservedFields.length);
114: }
115:
116: /**
117: * Create a new SlidePersistAtom, for use with a new Slide
118: */
119: public SlidePersistAtom() {
120: _header = new byte[8];
121: LittleEndian.putUShort(_header, 0, 0);
122: LittleEndian.putUShort(_header, 2, (int) _type);
123: LittleEndian.putInt(_header, 4, 20);
124:
125: hasShapesOtherThanPlaceholders = true;
126: reservedFields = new byte[4];
127: }
128:
129: /**
130: * We are of type 1011
131: */
132: public long getRecordType() {
133: return _type;
134: }
135:
136: /**
137: * Write the contents of the record back, so it can be written
138: * to disk
139: */
140: public void writeOut(OutputStream out) throws IOException {
141: // Header - size or type unchanged
142: out.write(_header);
143:
144: // Compute the flags part - only bit 3 is used
145: int flags = 0;
146: if (hasShapesOtherThanPlaceholders) {
147: flags = 4;
148: }
149:
150: // Write out our fields
151: writeLittleEndian(refID, out);
152: writeLittleEndian(flags, out);
153: writeLittleEndian(numPlaceholderTexts, out);
154: writeLittleEndian(slideIdentifier, out);
155: out.write(reservedFields);
156: }
157: }
|