2006-03-19 10:59:23 -05:00
|
|
|
|
|
|
|
/* ====================================================================
|
2006-12-22 14:18:16 -05:00
|
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
contributor license agreements. See the NOTICE file distributed with
|
|
|
|
this work for additional information regarding copyright ownership.
|
|
|
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
(the "License"); you may not use this file except in compliance with
|
|
|
|
the License. You may obtain a copy of the License at
|
2006-03-19 10:59:23 -05:00
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
==================================================================== */
|
|
|
|
|
|
|
|
|
|
|
|
package org.apache.poi.hslf.record;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Master container for Document. There is one of these for every
|
|
|
|
* slideshow, and it holds lots of definitions, and some summaries.
|
|
|
|
*
|
|
|
|
* @author Nick Burch
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class Document extends PositionDependentRecordContainer
|
|
|
|
{
|
|
|
|
private byte[] _header;
|
|
|
|
private static long _type = 1000;
|
|
|
|
|
|
|
|
// Links to our more interesting children
|
|
|
|
private DocumentAtom documentAtom;
|
2006-03-19 11:09:51 -05:00
|
|
|
private Environment environment;
|
2006-03-26 11:20:08 -05:00
|
|
|
private PPDrawingGroup ppDrawing;
|
2006-03-19 10:59:23 -05:00
|
|
|
private SlideListWithText[] slwts;
|
2007-01-17 13:09:24 -05:00
|
|
|
private ExObjList exObjList; // Can be null
|
2006-03-19 10:59:23 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the DocumentAtom of this Document
|
|
|
|
*/
|
|
|
|
public DocumentAtom getDocumentAtom() { return documentAtom; }
|
|
|
|
/**
|
|
|
|
* Returns the Environment of this Notes, which lots of
|
|
|
|
* settings for the document in it
|
|
|
|
*/
|
2006-03-19 11:09:51 -05:00
|
|
|
public Environment getEnvironment() { return environment; }
|
2006-03-26 11:20:08 -05:00
|
|
|
/**
|
|
|
|
* Returns the PPDrawingGroup, which holds an Escher Structure
|
|
|
|
* that contains information on pictures in the slides.
|
|
|
|
*/
|
|
|
|
public PPDrawingGroup getPPDrawingGroup() { return ppDrawing; }
|
2007-01-17 13:09:24 -05:00
|
|
|
/**
|
|
|
|
* Returns the ExObjList, which holds the references to
|
|
|
|
* external objects used in the slides. This may be null, if
|
|
|
|
* there are no external references.
|
|
|
|
*/
|
|
|
|
public ExObjList getExObjList() { return exObjList; }
|
2006-06-27 07:42:29 -04:00
|
|
|
|
2006-03-19 10:59:23 -05:00
|
|
|
/**
|
|
|
|
* Returns all the SlideListWithTexts that are defined for
|
|
|
|
* this Document. They hold the text, and some of the text
|
|
|
|
* properties, which are referred to by the slides.
|
2006-06-27 07:42:29 -04:00
|
|
|
* This will normally return an array of size 2 or 3
|
2006-03-19 10:59:23 -05:00
|
|
|
*/
|
|
|
|
public SlideListWithText[] getSlideListWithTexts() { return slwts; }
|
2006-06-27 07:42:29 -04:00
|
|
|
/**
|
|
|
|
* Returns the SlideListWithText that deals with the
|
|
|
|
* Master Slides
|
|
|
|
*/
|
|
|
|
public SlideListWithText getMasterSlideListWithText() {
|
|
|
|
if(slwts.length > 0) { return slwts[0]; }
|
|
|
|
return null; }
|
|
|
|
/**
|
|
|
|
* Returns the SlideListWithText that deals with the
|
|
|
|
* Slides, or null if there isn't one
|
|
|
|
*/
|
|
|
|
public SlideListWithText getSlideSlideListWithText() {
|
|
|
|
if(slwts.length > 1) { return slwts[1]; }
|
|
|
|
return null; }
|
|
|
|
/**
|
|
|
|
* Returns the SlideListWithText that deals with the
|
|
|
|
* notes, or null if there isn't one
|
|
|
|
*/
|
|
|
|
public SlideListWithText getNotesSlideListWithText() {
|
|
|
|
if(slwts.length > 2) { return slwts[2]; }
|
|
|
|
return null; }
|
2006-03-19 10:59:23 -05:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set things up, and find our more interesting children
|
|
|
|
*/
|
|
|
|
protected Document(byte[] source, int start, int len) {
|
|
|
|
// Grab the header
|
|
|
|
_header = new byte[8];
|
|
|
|
System.arraycopy(source,start,_header,0,8);
|
|
|
|
|
|
|
|
// Find our children
|
|
|
|
_children = Record.findChildRecords(source,start+8,len-8);
|
2006-03-26 12:37:04 -05:00
|
|
|
|
2006-03-19 10:59:23 -05:00
|
|
|
// Our first one should be a document atom
|
|
|
|
if(! (_children[0] instanceof DocumentAtom)) {
|
|
|
|
throw new IllegalStateException("The first child of a Document must be a DocumentAtom");
|
|
|
|
}
|
|
|
|
documentAtom = (DocumentAtom)_children[0];
|
2006-06-27 07:42:29 -04:00
|
|
|
|
2006-03-19 10:59:23 -05:00
|
|
|
// Find how many SlideListWithTexts we have
|
2006-06-27 07:42:29 -04:00
|
|
|
// Also, grab the Environment and PPDrawing records
|
|
|
|
// on our way past
|
2006-03-19 10:59:23 -05:00
|
|
|
int slwtcount = 0;
|
|
|
|
for(int i=1; i<_children.length; i++) {
|
|
|
|
if(_children[i] instanceof SlideListWithText) {
|
|
|
|
slwtcount++;
|
|
|
|
}
|
2006-03-19 11:09:51 -05:00
|
|
|
if(_children[i] instanceof Environment) {
|
|
|
|
environment = (Environment)_children[i];
|
2006-03-19 10:59:23 -05:00
|
|
|
}
|
2006-03-26 11:20:08 -05:00
|
|
|
if(_children[i] instanceof PPDrawingGroup) {
|
|
|
|
ppDrawing = (PPDrawingGroup)_children[i];
|
|
|
|
}
|
2007-01-17 13:09:24 -05:00
|
|
|
if(_children[i] instanceof ExObjList) {
|
|
|
|
exObjList = (ExObjList)_children[i];
|
|
|
|
}
|
2006-03-19 10:59:23 -05:00
|
|
|
}
|
2006-06-27 07:42:29 -04:00
|
|
|
|
|
|
|
// You should only every have 1, 2 or 3 SLWTs
|
|
|
|
// (normally it's 2, or 3 if you have notes)
|
|
|
|
// Complain if it's not
|
|
|
|
if(slwtcount == 0) {
|
|
|
|
System.err.println("No SlideListWithText's found - there should normally be at least one!");
|
|
|
|
}
|
|
|
|
if(slwtcount > 3) {
|
|
|
|
System.err.println("Found " + slwtcount + " SlideListWithTexts - normally there should only be three!");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now grab all the SLWTs
|
2006-03-19 10:59:23 -05:00
|
|
|
slwts = new SlideListWithText[slwtcount];
|
|
|
|
slwtcount = 0;
|
|
|
|
for(int i=1; i<_children.length; i++) {
|
|
|
|
if(_children[i] instanceof SlideListWithText) {
|
|
|
|
slwts[slwtcount] = (SlideListWithText)_children[i];
|
|
|
|
slwtcount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-03-26 12:37:04 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a new SlideListWithText record, at the appropriate
|
2006-06-27 07:42:29 -04:00
|
|
|
* point in the child records.
|
2006-03-26 12:37:04 -05:00
|
|
|
*/
|
|
|
|
public void addSlideListWithText(SlideListWithText slwt) {
|
|
|
|
// The new SlideListWithText should go in
|
|
|
|
// just before the EndDocumentRecord
|
|
|
|
Record endDoc = _children[_children.length - 1];
|
|
|
|
if(endDoc.getRecordType() != RecordTypes.EndDocument.typeID) {
|
|
|
|
throw new IllegalStateException("The last child record of a Document should be EndDocument, but it was " + endDoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add in the record
|
|
|
|
addChildBefore(slwt, endDoc);
|
|
|
|
|
|
|
|
// Updated our cached list of SlideListWithText records
|
2006-06-27 07:42:29 -04:00
|
|
|
int newSize = slwts.length + 1;
|
|
|
|
SlideListWithText[] nl = new SlideListWithText[newSize];
|
2006-03-26 12:37:04 -05:00
|
|
|
System.arraycopy(slwts, 0, nl, 0, slwts.length);
|
|
|
|
nl[nl.length-1] = slwt;
|
|
|
|
slwts = nl;
|
|
|
|
}
|
2006-03-19 10:59:23 -05:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We are of type 1000
|
|
|
|
*/
|
|
|
|
public long getRecordType() { return _type; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write the contents of the record back, so it can be written
|
|
|
|
* to disk
|
|
|
|
*/
|
|
|
|
public void writeOut(OutputStream out) throws IOException {
|
|
|
|
writeOut(_header[0],_header[1],_type,_children,out);
|
|
|
|
}
|
|
|
|
}
|