Save This Page
Home » poi-src-3.2-FINAL-20081019 » org.apache » poi » hslf » record » [javadoc | source]
    1   /*
    2   * Licensed to the Apache Software Foundation (ASF) under one or more
    3   * contributor license agreements.  See the NOTICE file distributed with
    4   * this work for additional information regarding copyright ownership.
    5   * The ASF licenses this file to You under the Apache License, Version 2.0
    6   * (the "License"); you may not use this file except in compliance with
    7   * the License.  You may obtain a copy of the License at
    8   *
    9   *     http://www.apache.org/licenses/LICENSE-2.0
   10   *
   11   * Unless required by applicable law or agreed to in writing, software
   12   * distributed under the License is distributed on an "AS IS" BASIS,
   13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14   * See the License for the specific language governing permissions and
   15   * limitations under the License.
   16   */
   17   package org.apache.poi.hslf.record;
   18   
   19   import java.io.IOException;
   20   import java.io.OutputStream;
   21   
   22   import org.apache.poi.util.LittleEndian;
   23   
   24   /**
   25    * This class represents a comment on a slide, in the format used by
   26    *  PPT 2000/XP/etc. (PPT 97 uses plain Escher Text Boxes for comments) 
   27    * @author Nick Burch
   28    */
   29   public class Comment2000 extends RecordContainer {
   30   	private byte[] _header;
   31   	private static long _type = 12000;
   32   	
   33   	// Links to our more interesting children
   34   	private CString authorRecord;
   35   	private CString authorInitialsRecord;
   36   	private CString commentRecord;
   37   	private Comment2000Atom commentAtom; 
   38   	
   39   	/** 
   40   	 * Returns the Comment2000Atom of this Comment
   41   	 */ 
   42   	public Comment2000Atom getComment2000Atom() { return commentAtom; }
   43   	
   44   	/**
   45   	 * Get the Author of this comment
   46   	 */
   47   	public String getAuthor() {
   48   		return authorRecord.getText();
   49   	}
   50   	/**
   51   	 * Set the Author of this comment
   52   	 */
   53   	public void setAuthor(String author) {
   54   		authorRecord.setText(author);
   55   	}
   56   
   57   	/**
   58   	 * Get the Author's Initials of this comment
   59   	 */
   60   	public String getAuthorInitials() {
   61   		return authorInitialsRecord.getText();
   62   	}
   63   	/**
   64   	 * Set the Author's Initials of this comment
   65   	 */
   66   	public void setAuthorInitials(String initials) {
   67   		authorInitialsRecord.setText(initials);
   68   	}
   69   
   70   	/**
   71   	 * Get the text of this comment
   72   	 */
   73   	public String getText() {
   74   		return commentRecord.getText();
   75   	}
   76   	/**
   77   	 * Set the text of this comment
   78   	 */
   79   	public void setText(String text) {
   80   		commentRecord.setText(text);
   81   	}
   82   	
   83   	/** 
   84   	 * Set things up, and find our more interesting children
   85   	 */
   86   	protected Comment2000(byte[] source, int start, int len) {
   87   		// Grab the header
   88   		_header = new byte[8];
   89   		System.arraycopy(source,start,_header,0,8);
   90   
   91   		// Find our children
   92   		_children = Record.findChildRecords(source,start+8,len-8);
   93   		findInterestingChildren();
   94   	}
   95   
   96   	/**
   97   	 * Go through our child records, picking out the ones that are
   98   	 *  interesting, and saving those for use by the easy helper
   99   	 *  methods.
  100   	 */	
  101   	private void findInterestingChildren() {
  102   		// First child should be the author
  103   		if(_children[0] instanceof CString) {
  104   			authorRecord = (CString)_children[0];
  105   		} else {
  106   			throw new IllegalStateException("First child record wasn't a CString, was of type " + _children[0].getRecordType());
  107   		}
  108   		// Second child should be the text
  109   		if(_children[1] instanceof CString) {
  110   			commentRecord = (CString)_children[1];
  111   		} else {
  112   			throw new IllegalStateException("Second child record wasn't a CString, was of type " + _children[1].getRecordType());
  113   		}
  114   		// Third child should be the author's initials
  115   		if(_children[2] instanceof CString) {
  116   			authorInitialsRecord = (CString)_children[2];
  117   		} else {
  118   			throw new IllegalStateException("Third child record wasn't a CString, was of type " + _children[2].getRecordType());
  119   		}
  120   		// Fourth child should be the comment atom
  121   		if(_children[3] instanceof Comment2000Atom) {
  122   			commentAtom = (Comment2000Atom)_children[3];
  123   		} else {
  124   			throw new IllegalStateException("Fourth child record wasn't a Comment2000Atom, was of type " + _children[3].getRecordType());
  125   		}
  126   	}
  127   	
  128   	/**
  129   	 * Create a new Comment2000, with blank fields
  130   	 */
  131   	public Comment2000() {
  132   		_header = new byte[8];
  133   		_children = new Record[4];
  134   		
  135   		// Setup our header block
  136   		_header[0] = 0x0f; // We are a container record
  137   		LittleEndian.putShort(_header, 2, (short)_type);
  138   		
  139   		// Setup our child records
  140   		CString csa = new CString();
  141   		CString csb = new CString();
  142   		CString csc = new CString();
  143   		csa.setCount(0x00);
  144   		csb.setCount(0x10);
  145   		csc.setCount(0x20);
  146   		_children[0] = csa;
  147   		_children[1] = csb;
  148   		_children[2] = csc;
  149   		_children[3] = new Comment2000Atom();
  150   		findInterestingChildren();
  151   	}
  152   
  153   	/**
  154   	 * We are of type 1200
  155   	 */
  156   	public long getRecordType() { return _type; }
  157   
  158   	/**
  159   	 * Write the contents of the record back, so it can be written
  160   	 *  to disk
  161   	 */
  162   	public void writeOut(OutputStream out) throws IOException {
  163   		writeOut(_header[0],_header[1],_type,_children,out);
  164   	}
  165   
  166   }

Save This Page
Home » poi-src-3.2-FINAL-20081019 » org.apache » poi » hslf » record » [javadoc | source]