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 Notes Atom (type 1009). Holds information on the parent Notes, such
026: * as what slide it is tied to
027: *
028: * @author Nick Burch
029: */
030:
031: public class NotesAtom extends RecordAtom {
032: private byte[] _header;
033: private static long _type = 1009l;
034:
035: private int slideID;
036: private boolean followMasterObjects;
037: private boolean followMasterScheme;
038: private boolean followMasterBackground;
039: private byte[] reserved;
040:
041: public int getSlideID() {
042: return slideID;
043: }
044:
045: public void setSlideID(int id) {
046: slideID = id;
047: }
048:
049: public boolean getFollowMasterObjects() {
050: return followMasterObjects;
051: }
052:
053: public boolean getFollowMasterScheme() {
054: return followMasterScheme;
055: }
056:
057: public boolean getFollowMasterBackground() {
058: return followMasterBackground;
059: }
060:
061: public void setFollowMasterObjects(boolean flag) {
062: followMasterObjects = flag;
063: }
064:
065: public void setFollowMasterScheme(boolean flag) {
066: followMasterScheme = flag;
067: }
068:
069: public void setFollowMasterBackground(boolean flag) {
070: followMasterBackground = flag;
071: }
072:
073: /* *************** record code follows ********************** */
074:
075: /**
076: * For the Notes Atom
077: */
078: protected NotesAtom(byte[] source, int start, int len) {
079: // Sanity Checking
080: if (len < 8) {
081: len = 8;
082: }
083:
084: // Get the header
085: _header = new byte[8];
086: System.arraycopy(source, start, _header, 0, 8);
087:
088: // Get the slide ID
089: slideID = (int) LittleEndian.getInt(source, start + 8);
090:
091: // Grok the flags, stored as bits
092: int flags = LittleEndian.getUShort(source, start + 12);
093: if ((flags & 4) == 4) {
094: followMasterBackground = true;
095: } else {
096: followMasterBackground = false;
097: }
098: if ((flags & 2) == 2) {
099: followMasterScheme = true;
100: } else {
101: followMasterScheme = false;
102: }
103: if ((flags & 1) == 1) {
104: followMasterObjects = true;
105: } else {
106: followMasterObjects = false;
107: }
108:
109: // There might be 2 more bytes, which are a reserved field
110: reserved = new byte[len - 14];
111: System.arraycopy(source, start + 14, reserved, 0,
112: reserved.length);
113: }
114:
115: /**
116: * We are of type 1009
117: */
118: public long getRecordType() {
119: return _type;
120: }
121:
122: /**
123: * Write the contents of the record back, so it can be written
124: * to disk
125: */
126: public void writeOut(OutputStream out) throws IOException {
127: // Header
128: out.write(_header);
129:
130: // Slide ID
131: writeLittleEndian(slideID, out);
132:
133: // Flags
134: short flags = 0;
135: if (followMasterObjects) {
136: flags += 1;
137: }
138: if (followMasterScheme) {
139: flags += 2;
140: }
141: if (followMasterBackground) {
142: flags += 4;
143: }
144: writeLittleEndian(flags, out);
145:
146: // Reserved fields
147: out.write(reserved);
148: }
149: }
|