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 a specific Link in the document.
029: * (The actual link is held in a sibling CString record)
030: *
031: * @author Nick Burch
032: */
033:
034: public class ExHyperlinkAtom extends RecordAtom {
035: /**
036: * Record header.
037: */
038: private byte[] _header;
039:
040: /**
041: * Record data.
042: */
043: private byte[] _data;
044:
045: /**
046: * Constructs a brand new link related atom record.
047: */
048: protected ExHyperlinkAtom() {
049: _header = new byte[8];
050: _data = new byte[4];
051:
052: LittleEndian.putShort(_header, 2, (short) getRecordType());
053: LittleEndian.putInt(_header, 4, _data.length);
054:
055: // It is fine for the other values to be zero
056: }
057:
058: /**
059: * Constructs the link related atom record from its
060: * source data.
061: *
062: * @param source the source data as a byte array.
063: * @param start the start offset into the byte array.
064: * @param len the length of the slice in the byte array.
065: */
066: protected ExHyperlinkAtom(byte[] source, int start, int len) {
067: // Get the header.
068: _header = new byte[8];
069: System.arraycopy(source, start, _header, 0, 8);
070:
071: // Get the record data.
072: _data = new byte[len - 8];
073: System.arraycopy(source, start + 8, _data, 0, len - 8);
074:
075: // Must be at least 4 bytes long
076: if (_data.length < 4) {
077: throw new IllegalArgumentException(
078: "The length of the data for a ExHyperlinkAtom must be at least 4 bytes, but was only "
079: + _data.length);
080: }
081: }
082:
083: /**
084: * Gets the link number. This will match the one in the
085: * InteractiveInfoAtom which uses the link.
086: * @return the link number
087: */
088: public int getNumber() {
089: return LittleEndian.getInt(_data, 0);
090: }
091:
092: /**
093: * Sets the link number
094: * @param number the link number.
095: */
096: public void setNumber(int number) {
097: LittleEndian.putInt(_data, 0, number);
098: }
099:
100: /**
101: * Gets the record type.
102: * @return the record type.
103: */
104: public long getRecordType() {
105: return RecordTypes.ExHyperlinkAtom.typeID;
106: }
107:
108: /**
109: * Write the contents of the record back, so it can be written
110: * to disk
111: *
112: * @param out the output stream to write to.
113: * @throws IOException if an error occurs.
114: */
115: public void writeOut(OutputStream out) throws IOException {
116: out.write(_header);
117: out.write(_data);
118: }
119: }
|