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 java.io.IOException;
021: import java.io.OutputStream;
022: import java.util.Date;
023:
024: import org.apache.poi.hslf.util.SystemTimeUtils;
025: import org.apache.poi.util.LittleEndian;
026:
027: /**
028: * Tne atom that holds metadata on Links in the document.
029: * (The actual link is held Document.ExObjList.ExHyperlink)
030: *
031: * @author Nick Burch
032: * @author Yegor Kozlov
033: */
034:
035: public class InteractiveInfoAtom extends RecordAtom {
036:
037: /**
038: * Action Table
039: */
040: public static final int ACTION_NONE = 0;
041: public static final int ACTION_MACRO = 1;
042: public static final int ACTION_RUNPROGRAM = 2;
043: public static final int ACTION_JUMP = 3;
044: public static final int ACTION_HYPERLINK = 4;
045: public static final int ACTION_OLE = 5;
046: public static final int ACTION_MEDIA = 6;
047: public static final int ACTION_CUSTOMSHOW = 7;
048:
049: /**
050: * Jump Table
051: */
052: public static final int JUMP_NONE = 0;
053: public static final int JUMP_NEXTSLIDE = 1;
054: public static final int JUMP_PREVIOUSSLIDE = 2;
055: public static final int JUMP_FIRSTSLIDE = 3;
056: public static final int JUMP_LASTSLIDE = 4;
057: public static final int JUMP_LASTSLIDEVIEWED = 5;
058: public static final int JUMP_ENDSHOW = 6;
059:
060: /**
061: * Record header.
062: */
063: private byte[] _header;
064:
065: /**
066: * Record data.
067: */
068: private byte[] _data;
069:
070: /**
071: * Constructs a brand new link related atom record.
072: */
073: protected InteractiveInfoAtom() {
074: _header = new byte[8];
075: _data = new byte[16];
076:
077: LittleEndian.putShort(_header, 2, (short) getRecordType());
078: LittleEndian.putInt(_header, 4, _data.length);
079:
080: // It is fine for the other values to be zero
081: }
082:
083: /**
084: * Constructs the link related atom record from its
085: * source data.
086: *
087: * @param source the source data as a byte array.
088: * @param start the start offset into the byte array.
089: * @param len the length of the slice in the byte array.
090: */
091: protected InteractiveInfoAtom(byte[] source, int start, int len) {
092: // Get the header.
093: _header = new byte[8];
094: System.arraycopy(source, start, _header, 0, 8);
095:
096: // Get the record data.
097: _data = new byte[len - 8];
098: System.arraycopy(source, start + 8, _data, 0, len - 8);
099:
100: // Must be at least 16 bytes long
101: if (_data.length < 16) {
102: throw new IllegalArgumentException(
103: "The length of the data for a InteractiveInfoAtom must be at least 16 bytes, but was only "
104: + _data.length);
105: }
106:
107: // First 4 bytes - no idea, normally 0
108: // Second 4 bytes - the id of the link (from 1 onwards)
109: // Third 4 bytes - no idea, normally 4
110: // Fourth 4 bytes - no idea, normally 8
111: }
112:
113: /**
114: * Gets the link number. You will normally look the
115: * ExHyperlink with this number to get the details.
116: * @return the link number
117: */
118: public int getHyperlinkID() {
119: return LittleEndian.getInt(_data, 4);
120: }
121:
122: /**
123: * Sets the persistent unique identifier of the link
124: *
125: * @param number the persistent unique identifier of the link
126: */
127: public void setHyperlinkID(int number) {
128: LittleEndian.putInt(_data, 4, number);
129: }
130:
131: /**
132: * a reference to a sound in the sound collection.
133: */
134: public int getSoundRef() {
135: return LittleEndian.getInt(_data, 0);
136: }
137:
138: /**
139: * a reference to a sound in the sound collection.
140: *
141: * @param val a reference to a sound in the sound collection
142: */
143: public void setSoundRef(int val) {
144: LittleEndian.putInt(_data, 0, val);
145: }
146:
147: /**
148: * Hyperlink Action.
149: * <p>
150: * see <code>ACTION_*</code> constants for the list of actions
151: * </p>
152: *
153: * @return hyperlink action.
154: */
155: public byte getAction() {
156: return _data[8];
157: }
158:
159: /**
160: * Hyperlink Action
161: * <p>
162: * see <code>ACTION_*</code> constants for the list of actions
163: * </p>
164: *
165: * @param val hyperlink action.
166: */
167: public void setAction(byte val) {
168: _data[8] = val;
169: }
170:
171: /**
172: * Only valid when action == OLEAction. OLE verb to use, 0 = first verb, 1 = second verb, etc.
173: */
174: public byte getOleVerb() {
175: return _data[9];
176: }
177:
178: /**
179: * Only valid when action == OLEAction. OLE verb to use, 0 = first verb, 1 = second verb, etc.
180: */
181: public void setOleVerb(byte val) {
182: _data[9] = val;
183: }
184:
185: /**
186: * Jump
187: * <p>
188: * see <code>JUMP_*</code> constants for the list of actions
189: * </p>
190: *
191: * @return jump
192: */
193: public byte getJump() {
194: return _data[10];
195: }
196:
197: /**
198: * Jump
199: * <p>
200: * see <code>JUMP_*</code> constants for the list of actions
201: * </p>
202: *
203: * @param val jump
204: */
205: public void setJump(byte val) {
206: _data[10] = val;
207: }
208:
209: /**
210: * Flags
211: * <p>
212: * <li> Bit 1: Animated. If 1, then button is animated
213: * <li> Bit 2: Stop sound. If 1, then stop current sound when button is pressed.
214: * <li> Bit 3: CustomShowReturn. If 1, and this is a jump to custom show,
215: * then return to this slide after custom show.
216: * </p>
217: */
218: public byte getFlags() {
219: return _data[11];
220: }
221:
222: /**
223: * Flags
224: * <p>
225: * <li> Bit 1: Animated. If 1, then button is animated
226: * <li> Bit 2: Stop sound. If 1, then stop current sound when button is pressed.
227: * <li> Bit 3: CustomShowReturn. If 1, and this is a jump to custom show,
228: * then return to this slide after custom show.
229: * </p>
230: */
231: public void setFlags(byte val) {
232: _data[11] = val;
233: }
234:
235: /**
236: * hyperlink type
237: *
238: * @return hyperlink type
239: */
240: public byte getHyperlinkType() {
241: return _data[12];
242: }
243:
244: /**
245: * hyperlink type
246: *
247: * @param val hyperlink type
248: */
249: public void setHyperlinkType(byte val) {
250: _data[12] = val;
251: }
252:
253: /**
254: * Gets the record type.
255: * @return the record type.
256: */
257: public long getRecordType() {
258: return RecordTypes.InteractiveInfoAtom.typeID;
259: }
260:
261: /**
262: * Write the contents of the record back, so it can be written
263: * to disk
264: *
265: * @param out the output stream to write to.
266: * @throws IOException if an error occurs.
267: */
268: public void writeOut(OutputStream out) throws IOException {
269: out.write(_header);
270: out.write(_data);
271: }
272: }
|