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: * An atomic record containing information about a comment.
029: *
030: * @author Daniel Noll
031: */
032:
033: public class Comment2000Atom extends RecordAtom {
034: /**
035: * Record header.
036: */
037: private byte[] _header;
038:
039: /**
040: * Record data.
041: */
042: private byte[] _data;
043:
044: /**
045: * Constructs a brand new comment atom record.
046: */
047: protected Comment2000Atom() {
048: _header = new byte[8];
049: _data = new byte[28];
050:
051: LittleEndian.putShort(_header, 2, (short) getRecordType());
052: LittleEndian.putInt(_header, 4, _data.length);
053:
054: // It is fine for the other values to be zero
055: }
056:
057: /**
058: * Constructs the comment atom record from its source data.
059: *
060: * @param source the source data as a byte array.
061: * @param start the start offset into the byte array.
062: * @param len the length of the slice in the byte array.
063: */
064: protected Comment2000Atom(byte[] source, int start, int len) {
065: // Get the header.
066: _header = new byte[8];
067: System.arraycopy(source, start, _header, 0, 8);
068:
069: // Get the record data.
070: _data = new byte[len - 8];
071: System.arraycopy(source, start + 8, _data, 0, len - 8);
072: }
073:
074: /**
075: * Gets the comment number (note - each user normally has their own count).
076: * @return the comment number.
077: */
078: public int getNumber() {
079: return LittleEndian.getInt(_data, 0);
080: }
081:
082: /**
083: * Sets the comment number (note - each user normally has their own count).
084: * @param number the comment number.
085: */
086: public void setNumber(int number) {
087: LittleEndian.putInt(_data, 0, number);
088: }
089:
090: /**
091: * Gets the date the comment was made.
092: * @return the comment date.
093: */
094: public Date getDate() {
095: return SystemTimeUtils.getDate(_data, 4);
096: }
097:
098: /**
099: * Sets the date the comment was made.
100: * @param date the comment date.
101: */
102: public void setDate(Date date) {
103: SystemTimeUtils.storeDate(date, _data, 4);
104: }
105:
106: /**
107: * Gets the X offset of the comment on the page.
108: * @return the X offset.
109: */
110: public int getXOffset() {
111: return LittleEndian.getInt(_data, 20);
112: }
113:
114: /**
115: * Sets the X offset of the comment on the page.
116: * @param xOffset the X offset.
117: */
118: public void setXOffset(int xOffset) {
119: LittleEndian.putInt(_data, 20, xOffset);
120: }
121:
122: /**
123: * Gets the Y offset of the comment on the page.
124: * @return the Y offset.
125: */
126: public int getYOffset() {
127: return LittleEndian.getInt(_data, 24);
128: }
129:
130: /**
131: * Sets the Y offset of the comment on the page.
132: * @param yOffset the Y offset.
133: */
134: public void setYOffset(int yOffset) {
135: LittleEndian.putInt(_data, 24, yOffset);
136: }
137:
138: /**
139: * Gets the record type.
140: * @return the record type.
141: */
142: public long getRecordType() {
143: return RecordTypes.Comment2000Atom.typeID;
144: }
145:
146: /**
147: * Write the contents of the record back, so it can be written
148: * to disk
149: *
150: * @param out the output stream to write to.
151: * @throws IOException if an error occurs.
152: */
153: public void writeOut(OutputStream out) throws IOException {
154: out.write(_header);
155: out.write(_data);
156: }
157: }
|