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: package org.apache.poi.hslf.record;
018:
019: import org.apache.poi.util.LittleEndian;
020:
021: import java.io.OutputStream;
022: import java.io.IOException;
023:
024: /**
025: * Tne atom that holds starting and ending character positions of a hyperlink
026: *
027: * @author Yegor Kozlov
028: */
029: public class TxInteractiveInfoAtom extends RecordAtom {
030: /**
031: * Record header.
032: */
033: private byte[] _header;
034:
035: /**
036: * Record data.
037: */
038: private byte[] _data;
039:
040: /**
041: * Constructs a brand new link related atom record.
042: */
043: protected TxInteractiveInfoAtom() {
044: _header = new byte[8];
045: _data = new byte[8];
046:
047: LittleEndian.putShort(_header, 2, (short) getRecordType());
048: LittleEndian.putInt(_header, 4, _data.length);
049: }
050:
051: /**
052: * Constructs the link related atom record from its
053: * source data.
054: *
055: * @param source the source data as a byte array.
056: * @param start the start offset into the byte array.
057: * @param len the length of the slice in the byte array.
058: */
059: protected TxInteractiveInfoAtom(byte[] source, int start, int len) {
060: // Get the header.
061: _header = new byte[8];
062: System.arraycopy(source, start, _header, 0, 8);
063:
064: // Get the record data.
065: _data = new byte[len - 8];
066: System.arraycopy(source, start + 8, _data, 0, len - 8);
067:
068: }
069:
070: /**
071: * Gets the beginning character position
072: *
073: * @return the beginning character position
074: */
075: public int getStartIndex() {
076: return LittleEndian.getInt(_data, 0);
077: }
078:
079: /**
080: * Sets the beginning character position
081: * @param idx the beginning character position
082: */
083: public void setStartIndex(int idx) {
084: LittleEndian.putInt(_data, 0, idx);
085: }
086:
087: /**
088: * Gets the ending character position
089: *
090: * @return the ending character position
091: */
092: public int getEndIndex() {
093: return LittleEndian.getInt(_data, 4);
094: }
095:
096: /**
097: * Sets the ending character position
098: *
099: * @param idx the ending character position
100: */
101: public void setEndIndex(int idx) {
102: LittleEndian.putInt(_data, 4, idx);
103: }
104:
105: /**
106: * Gets the record type.
107: * @return the record type.
108: */
109: public long getRecordType() {
110: return RecordTypes.TxInteractiveInfoAtom.typeID;
111: }
112:
113: /**
114: * Write the contents of the record back, so it can be written
115: * to disk
116: *
117: * @param out the output stream to write to.
118: * @throws java.io.IOException if an error occurs.
119: */
120: public void writeOut(OutputStream out) throws IOException {
121: out.write(_header);
122: out.write(_data);
123: }
124: }
|