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 TextHeaderAtom (type 3999). Holds information on what kind of
026: * text is contained in the TextBytesAtom / TextCharsAtom that follows
027: * straight after
028: *
029: * @author Nick Burch
030: */
031:
032: public class TextHeaderAtom extends RecordAtom implements
033: ParentAwareRecord {
034: private byte[] _header;
035: private static long _type = 3999l;
036: private RecordContainer parentRecord;
037:
038: public static final int TITLE_TYPE = 0;
039: public static final int BODY_TYPE = 1;
040: public static final int NOTES_TYPE = 2;
041: public static final int OTHER_TYPE = 4;
042: public static final int CENTRE_BODY_TYPE = 5;
043: public static final int CENTER_TITLE_TYPE = 6;
044: public static final int HALF_BODY_TYPE = 7;
045: public static final int QUARTER_BODY_TYPE = 8;
046:
047: /** The kind of text it is */
048: private int textType;
049:
050: public int getTextType() {
051: return textType;
052: }
053:
054: public void setTextType(int type) {
055: textType = type;
056: }
057:
058: public RecordContainer getParentRecord() {
059: return parentRecord;
060: }
061:
062: public void setParentRecord(RecordContainer record) {
063: this .parentRecord = record;
064: }
065:
066: /* *************** record code follows ********************** */
067:
068: /**
069: * For the TextHeader Atom
070: */
071: protected TextHeaderAtom(byte[] source, int start, int len) {
072: // Sanity Checking - we're always 12 bytes long
073: if (len < 12) {
074: len = 12;
075: if (source.length - start < 12) {
076: throw new RuntimeException(
077: "Not enough data to form a TextHeaderAtom (always 12 bytes long) - found "
078: + (source.length - start));
079: }
080: }
081:
082: // Get the header
083: _header = new byte[8];
084: System.arraycopy(source, start, _header, 0, 8);
085:
086: // Grab the type
087: textType = (int) LittleEndian.getInt(source, start + 8);
088: }
089:
090: /**
091: * Create a new TextHeader Atom, for an unknown type of text
092: */
093: public TextHeaderAtom() {
094: _header = new byte[8];
095: LittleEndian.putUShort(_header, 0, 0);
096: LittleEndian.putUShort(_header, 2, (int) _type);
097: LittleEndian.putInt(_header, 4, 4);
098:
099: textType = OTHER_TYPE;
100: }
101:
102: /**
103: * We are of type 3999
104: */
105: public long getRecordType() {
106: return _type;
107: }
108:
109: /**
110: * Write the contents of the record back, so it can be written
111: * to disk
112: */
113: public void writeOut(OutputStream out) throws IOException {
114: // Header - size or type unchanged
115: out.write(_header);
116:
117: // Write out our type
118: writeLittleEndian(textType, out);
119: }
120: }
|