⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hslfslideshow.java

📁 java 读写word excel ppt
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* ====================================================================   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       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;import java.util.*;import java.io.*;import org.apache.poi.POIDocument;import org.apache.poi.util.LittleEndian;import org.apache.poi.util.POILogger;import org.apache.poi.util.POILogFactory;import org.apache.poi.poifs.filesystem.POIFSFileSystem;import org.apache.poi.poifs.filesystem.DocumentEntry;import org.apache.poi.poifs.filesystem.DocumentInputStream;import org.apache.poi.hpsf.PropertySet;import org.apache.poi.hpsf.PropertySetFactory;import org.apache.poi.hpsf.MutablePropertySet;import org.apache.poi.hpsf.SummaryInformation;import org.apache.poi.hpsf.DocumentSummaryInformation;import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException;import org.apache.poi.hslf.exceptions.HSLFException;import org.apache.poi.hslf.record.*;import org.apache.poi.hslf.usermodel.PictureData;/** * This class contains the main functionality for the Powerpoint file  * "reader". It is only a very basic class for now * * @author Nick Burch */public class HSLFSlideShow extends POIDocument{    // For logging    protected POILogger logger = POILogFactory.getLogger(this.getClass());	private InputStream istream;	// Holds metadata on where things are in our document	private CurrentUserAtom currentUser;	// Low level contents of the file	private byte[] _docstream;	// Low level contents	private Record[] _records;	// Raw Pictures contained in the pictures stream	private PictureData[] _pictures;		/**	 * Returns the underlying POIFSFileSystem for the document	 *  that is open.	 */	protected POIFSFileSystem getPOIFSFileSystem() {		return filesystem;	}	/**	 * Constructs a Powerpoint document from fileName. Parses the document 	 * and places all the important stuff into data structures.	 *	 * @param fileName The name of the file to read.	 * @throws IOException if there is a problem while parsing the document.	 */	public HSLFSlideShow(String fileName) throws IOException	{		this(new FileInputStream(fileName));	}  	/**	 * Constructs a Powerpoint document from an input stream. Parses the 	 * document and places all the important stuff into data structures.	 *	 * @param inputStream the source of the data	 * @throws IOException if there is a problem while parsing the document.	 */	public HSLFSlideShow(InputStream inputStream) throws IOException	{		//do Ole stuff		this(new POIFSFileSystem(inputStream));		istream = inputStream;	}	/**	 * Constructs a Powerpoint document from a POIFS Filesystem. Parses the 	 * document and places all the important stuff into data structures.	 *	 * @param filesystem the POIFS FileSystem to read from	 * @throws IOException if there is a problem while parsing the document.	 */	public HSLFSlideShow(POIFSFileSystem filesystem) throws IOException	{		this.filesystem = filesystem;				// First up, grab the "Current User" stream		// We need this before we can detect Encrypted Documents		readCurrentUserStream();				// Next up, grab the data that makes up the 		//  PowerPoint stream		readPowerPointStream();				// Check to see if we have an encrypted document,		//  bailing out if we do		boolean encrypted = EncryptedSlideShow.checkIfEncrypted(this);		if(encrypted) {			throw new EncryptedPowerPointFileException("Encrypted PowerPoint files are not supported");		}		// Now, build records based on the PowerPoint stream		buildRecords();		// Look for Property Streams:		readProperties();				// Look for any other streams		readOtherStreams();		// Look for Picture Streams:		readPictures();	}	/**	 * Constructs a new, empty, Powerpoint document.	 */	public HSLFSlideShow() throws IOException 	{		this(HSLFSlideShow.class.getResourceAsStream("/org/apache/poi/hslf/data/empty.ppt"));	}	/**	 * Shuts things down. Closes underlying streams etc	 *	 * @throws IOException	 */	public void close() throws IOException	{		if(istream != null) {			istream.close();		}		filesystem = null;	}	/**	 * Extracts the main PowerPoint document stream from the 	 *  POI file, ready to be passed 	 *	 * @throws IOException	 */	private void readPowerPointStream() throws IOException	{		// Get the main document stream		DocumentEntry docProps =			(DocumentEntry)filesystem.getRoot().getEntry("PowerPoint Document");		// Grab the document stream		_docstream = new byte[docProps.getSize()];		filesystem.createDocumentInputStream("PowerPoint Document").read(_docstream);	}		/**	 * Builds the list of records, based on the contents  	 *  of the PowerPoint stream	 */	private void buildRecords()	{		// The format of records in a powerpoint file are:		//   <little endian 2 byte "info">		//   <little endian 2 byte "type">		//   <little endian 4 byte "length">		// If it has a zero length, following it will be another record		//		<xx xx yy yy 00 00 00 00> <xx xx yy yy zz zz zz zz>		// If it has a length, depending on its type it may have children or data		// If it has children, these will follow straight away		//		<xx xx yy yy zz zz zz zz <xx xx yy yy zz zz zz zz>>		// If it has data, this will come straigh after, and run for the length		//      <xx xx yy yy zz zz zz zz dd dd dd dd dd dd dd>		// All lengths given exclude the 8 byte record header		// (Data records are known as Atoms)			// Document should start with:		//   0F 00 E8 03 ## ## ## ##	    //     (type 1000 = document, info 00 0f is normal, rest is document length)		//   01 00 E9 03 28 00 00 00		//     (type 1001 = document atom, info 00 01 normal, 28 bytes long)		//   80 16 00 00 E0 10 00 00 xx xx xx xx xx xx xx xx		//   05 00 00 00 0A 00 00 00 xx xx xx		//     (the contents of the document atom, not sure what it means yet)		//   (records then follow)			// When parsing a document, look to see if you know about that type		//  of the current record. If you know it's a type that has children, 		//  process the record's data area looking for more records		// If you know about the type and it doesn't have children, either do		//  something with the data (eg TextRun) or skip over it		// If you don't know about the type, play safe and skip over it (using		//  its length to know where the next record will start)		//        _records = read(_docstream, (int)currentUser.getCurrentEditOffset());	}    private Record[] read(byte[] docstream, int usrOffset){        ArrayList lst = new ArrayList();        while (usrOffset != 0){            UserEditAtom usr = (UserEditAtom) Record.buildRecordAtOffset(docstream, usrOffset);            lst.add(new Integer(usrOffset));            int psrOffset = usr.getPersistPointersOffset();            PersistPtrHolder ptr = (PersistPtrHolder)Record.buildRecordAtOffset(docstream, psrOffset);            lst.add(new Integer(psrOffset));            Hashtable entries = ptr.getSlideLocationsLookup();            for (Iterator it = entries.keySet().iterator(); it.hasNext(); ) {                Integer id = (Integer)it.next();                Integer offset = (Integer)entries.get(id);                lst.add(offset);            }            usrOffset = usr.getLastUserEditAtomOffset();        }        //sort found records by offset.        //(it is not necessary but SlideShow.findMostRecentCoreRecords() expects them sorted)        Object a[] = lst.toArray();        Arrays.sort(a);        Record[] rec = new Record[lst.size()];        for (int i = 0; i < a.length; i++) {            Integer offset = (Integer)a[i];            rec[i] = (Record)Record.buildRecordAtOffset(docstream, offset.intValue());        }        return rec;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -