CurrentUserAtompublic 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 |
Fields Summary |
---|
public static final byte[] | atomHeaderStandard Atom header | public static final byte[] | magicNumberThe Powerpoint magic numer | public static final byte[] | ppt97FileVerThe Powerpoint 97 version, major and minor numbers | private int | docFinalVersionAThe version, major and minor numbers | private int | docFinalVersionB | private byte | docMajorNo | private byte | docMinorNo | private long | currentEditOffsetThe Offset into the file for the current edit | private String | lastEditUserThe Username of the last person to edit the file | private long | releaseVersionThe document release version | private byte[] | _contentsOnly 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 long | getCurrentEditOffset()Points to the UserEditAtom return currentEditOffset;
| public int | getDocFinalVersionA()
/* ********************* getter/setter follows *********************** */
return docFinalVersionA;
| public int | getDocFinalVersionB() return docFinalVersionB;
| public byte | getDocMajorNo() return docMajorNo;
| public byte | getDocMinorNo() return docMinorNo;
| public java.lang.String | getLastEditUsername() return lastEditUser;
| public long | getReleaseVersion() return releaseVersion;
| private void | init()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 void | setCurrentEditOffset(long id) currentEditOffset = id;
| public void | setLastEditUsername(java.lang.String u) lastEditUser = u;
| public void | setReleaseVersion(long rv) releaseVersion = rv;
| public void | writeOut(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 void | writeToFS(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");
|
|