FileDocCategorySizeDatePackage
SlideShowRecordDumper.javaAPI DocApache Poi 3.0.14519Mon Jan 01 18:55:34 GMT 2007org.apache.poi.hslf.dev

SlideShowRecordDumper

public class SlideShowRecordDumper extends Object
This class provides a way to view the contents of a powerpoint file. It will use the recored layer to grok the contents of the file, and will print out what it finds.
author
Nick Burch

Fields Summary
private HSLFSlideShow
doc
Constructors Summary
public SlideShowRecordDumper(String fileName)
Constructs a Powerpoint dump from fileName. Parses the document and dumps out the contents

param
fileName The name of the file to read.
throws
IOException if there is a problem while parsing the document.

	doc = new HSLFSlideShow(fileName);
  
Methods Summary
public voidclose()
Shuts things down. Closes underlying streams etc

throws
IOException

	if(doc != null) {
		doc.close();
	}
	doc = null;
  
public intgetDiskLen(org.apache.poi.hslf.record.Record r)

	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	r.writeOut(baos);
	byte[] b = baos.toByteArray();
	return b.length;
  
public static voidmain(java.lang.String[] args)
right now this function takes one parameter: a ppt file, and outputs a dump of what it contains

	if(args.length == 0) {
		System.err.println("Useage: SlideShowRecordDumper <filename>");
		return;
	}

	String filename = args[0];

	SlideShowRecordDumper foo = new SlideShowRecordDumper(filename);

	foo.printDump();
	foo.close();
  
public java.lang.StringmakeHex(int number, int padding)

	String hex = Integer.toHexString(number).toUpperCase();
	while(hex.length() < padding) {
		hex = "0" + hex;
	}
	return hex;
  
public voidprintDump()

	// Prints out the records in the tree
	walkTree(0,0,doc.getRecords());
  
public java.lang.StringreverseHex(java.lang.String s)

	StringBuffer ret = new StringBuffer();

	// Get to a multiple of two
	if((s.length() / 2) * 2 != s.length()) { s = "0" + s; }

	// Break up into blocks
	char[] c = s.toCharArray();
	for(int i=c.length; i>0; i-=2) {
		ret.append(c[i-2]);
		ret.append(c[i-1]);
		if(i != 2) { ret.append(' "); }
	}
	return ret.toString();
  
public voidwalkTree(int depth, int pos, org.apache.poi.hslf.record.Record[] records)

	int indent = depth;
	String ind = "";
	for(int i=0; i<indent; i++) { ind += " "; }

	for(int i=0; i<records.length; i++) {
		Record r = records[i];

		// Figure out how big it is
		int len = getDiskLen(r);

		// Grab the type as hex
		String hexType = makeHex((int)r.getRecordType(),4);
		String rHexType = reverseHex(hexType);

		// Grab the hslf.record type
		Class c = r.getClass();
		String cname = c.toString();
		if(cname.startsWith("class ")) {
			cname = cname.substring(6);
		}
		if(cname.startsWith("org.apache.poi.hslf.record.")) {
			cname = cname.substring(27);
		}

		// Display the record
		System.out.println(ind + "At position " + pos + " (" + makeHex(pos,6) + "):");
		System.out.println(ind + " Record is of type " + cname);
		System.out.println(ind + " Type is " + r.getRecordType() + " (" + hexType + " -> " + rHexType + " )");
		System.out.println(ind + " Len is " + (len-8) + " (" + makeHex((len-8),8) + "), on disk len is " + len );
		System.out.println();

		// If it has children, show them
		if(r.getChildRecords() != null) {
			walkTree((depth+3),pos+8,r.getChildRecords());
		}

		// Wind on the position marker
		pos += len;
	}