FileDocCategorySizeDatePackage
CurrentUserAtom.javaAPI DocApache Poi 3.0.17666Sun Mar 11 12:59:30 GMT 2007org.apache.poi.hslf.record

CurrentUserAtom

public class CurrentUserAtom extends Object
This is a special kind of Atom, becauase it doesn't live inside the PowerPoint document. Instead, it lives in a seperate stream in the document. As such, it has to be treaded specially
author
Nick Burch

Fields Summary
public static final byte[]
atomHeader
Standard Atom header
public static final byte[]
magicNumber
The Powerpoint magic numer
public static final byte[]
ppt97FileVer
The Powerpoint 97 version, major and minor numbers
private int
docFinalVersionA
The version, major and minor numbers
private int
docFinalVersionB
private byte
docMajorNo
private byte
docMinorNo
private long
currentEditOffset
The Offset into the file for the current edit
private String
lastEditUser
The Username of the last person to edit the file
private long
releaseVersion
The document release version
private byte[]
_contents
Only correct after reading in or writing out
Constructors Summary
public CurrentUserAtom()
Create a new Current User Atom

		_contents = new byte[0];
		throw new RuntimeException("Creation support for Current User Atom not complete");
	
public CurrentUserAtom(POIFSFileSystem fs)
Find the Current User in the filesystem, and create from that

		// Decide how big it is
		DocumentEntry docProps =
			(DocumentEntry)fs.getRoot().getEntry("Current User");
		_contents = new byte[docProps.getSize()];

		// Check it's big enough - if it's not at least 28 bytes long, then
		//  the record is corrupt
		if(_contents.length < 28) {
			throw new CorruptPowerPointFileException("The Current User stream must be at least 28 bytes long, but was only " + _contents.length);
		}

		// Grab the contents
		InputStream in = fs.createDocumentInputStream("Current User");
		in.read(_contents);

		// Set everything up
		init();
	
public CurrentUserAtom(byte[] b)
Create things from the bytes

		_contents = b;
		init();
	
Methods Summary
public longgetCurrentEditOffset()
Points to the UserEditAtom

 return currentEditOffset; 
public intgetDocFinalVersionA()



	/* ********************* getter/setter follows *********************** */

	     return docFinalVersionA; 
public intgetDocFinalVersionB()

 return docFinalVersionB; 
public bytegetDocMajorNo()

 return docMajorNo; 
public bytegetDocMinorNo()

 return docMinorNo; 
public java.lang.StringgetLastEditUsername()

 return lastEditUser; 
public longgetReleaseVersion()

 return releaseVersion; 
private voidinit()
Actually do the creation from a block of bytes

		// Grab the edit offset
		currentEditOffset = LittleEndian.getUInt(_contents,16);

		// Grab the versions
		docFinalVersionA = LittleEndian.getUShort(_contents,20);
		docFinalVersionB = LittleEndian.getUShort(_contents,22);
		docMajorNo = _contents[24];
		docMinorNo = _contents[25];

		// Get the username length
		long usernameLen = LittleEndian.getUShort(_contents,20);
		if(usernameLen > 512) {
			// Handle the case of it being garbage
			System.err.println("Warning - invalid username length " + usernameLen + " found, treating as if there was no username set");
			usernameLen = 0;
		}

		// Now we know the length of the username, 
		//  use this to grab the revision
		if(_contents.length >= 28+(int)usernameLen + 4) {
			releaseVersion = LittleEndian.getUInt(_contents,28+(int)usernameLen);
		} else {
			// No revision given, as not enough data. Odd
			releaseVersion = 0;
		}

		// Grab the unicode username, if stored
		int start = 28+(int)usernameLen+4;
		int len = 2*(int)usernameLen;

		if(_contents.length >= start+len) {
			byte[] textBytes = new byte[len];
			System.arraycopy(_contents,start,textBytes,0,len);
			lastEditUser = StringUtil.getFromUnicodeLE(textBytes);
		} else {
			// Fake from the 8 bit version
			byte[] textBytes = new byte[(int)usernameLen];
			System.arraycopy(_contents,28,textBytes,0,(int)usernameLen);
			lastEditUser = StringUtil.getFromCompressedUnicode(textBytes,0,(int)usernameLen);
		}
	
public voidsetCurrentEditOffset(long id)

 currentEditOffset = id; 
public voidsetLastEditUsername(java.lang.String u)

 lastEditUser = u; 
public voidsetReleaseVersion(long rv)

 releaseVersion = rv; 
public voidwriteOut(java.io.OutputStream out)
Writes ourselves back out

		// Decide on the size
		//  8 = atom header
		//  20 = up to name
		//  4 = revision
		//  3 * len = ascii + unicode
		int size = 8 + 20 + 4 + (3 * lastEditUser.length());
		_contents = new byte[size];

		// First we have a 8 byte atom header
		System.arraycopy(atomHeader,0,_contents,0,4);	
		// Size is 20+user len + revision len(4)
		int atomSize = 20+4+lastEditUser.length();
		LittleEndian.putInt(_contents,4,atomSize);

		// Now we have the size of the details, which is 20
		LittleEndian.putInt(_contents,8,20);

		// Now the ppt magic number (4 bytes)
		System.arraycopy(magicNumber,0,_contents,12,4);

		// Now the current edit offset
		LittleEndian.putInt(_contents,16,(int)currentEditOffset);

		// Now the file versions, 2+2+1+1
		LittleEndian.putShort(_contents,20,(short)docFinalVersionA);
		LittleEndian.putShort(_contents,22,(short)docFinalVersionB);
		_contents[24] = docMajorNo;
		_contents[25] = docMinorNo;

		// 2 bytes blank
		_contents[26] = 0;
		_contents[27] = 0;

		// username in bytes in us ascii
		byte[] asciiUN = new byte[lastEditUser.length()];
		StringUtil.putCompressedUnicode(lastEditUser,asciiUN,0);
		System.arraycopy(asciiUN,0,_contents,28,asciiUN.length);

		// 4 byte release version
		LittleEndian.putInt(_contents,28+asciiUN.length,(int)releaseVersion);

		// username in unicode
		byte [] ucUN = new byte[lastEditUser.length()*2];
		StringUtil.putUnicodeLE(lastEditUser,ucUN,0);
		System.arraycopy(ucUN,0,_contents,28+asciiUN.length+4,ucUN.length);

		// Write out
		out.write(_contents);
	
public voidwriteToFS(org.apache.poi.poifs.filesystem.POIFSFileSystem fs)
Writes ourselves back out to a filesystem

		// Grab contents
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		writeOut(baos);
		ByteArrayInputStream bais = 
			new ByteArrayInputStream(baos.toByteArray());

		// Write out
		fs.createDocument(bais,"Current User");