use of org.apache.poi.hslf.record.Record in project poi by apache.
the class SlideShowRecordDumper method walkTree.
public void walkTree(int depth, int pos, Record[] records, int indent) throws IOException {
String ind = tabs.substring(0, indent);
for (int i = 0; i < records.length; i++) {
Record r = records[i];
if (r == null) {
ps.println(ind + "At position " + pos + " (" + makeHex(pos, 6) + "):");
ps.println(ind + "Warning! Null record found.");
continue;
}
// 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<? extends Record> 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
ps.println(ind + "At position " + pos + " (" + makeHex(pos, 6) + "):");
ps.println(ind + " Record is of type " + cname);
ps.println(ind + " Type is " + r.getRecordType() + " (" + hexType + " -> " + rHexType + " )");
ps.println(ind + " Len is " + (len - 8) + " (" + makeHex((len - 8), 8) + "), on disk len is " + len);
// print additional information for drawings and atoms
if (optEscher && cname.equals("PPDrawing")) {
DefaultEscherRecordFactory factory = new HSLFEscherRecordFactory();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
r.writeOut(baos);
byte[] b = baos.toByteArray();
EscherRecord er = factory.createRecord(b, 0);
er.fillFields(b, 0, factory);
printEscherRecord(er, indent + 1);
} else if (optVerbose && r.getChildRecords() == null) {
String recData = getPrintableRecordContents(r);
ps.println(ind + recData);
}
ps.println();
// If it has children, show them
if (r.getChildRecords() != null) {
walkTree((depth + 3), pos + 8, r.getChildRecords(), indent + 1);
}
// Wind on the position marker
pos += len;
}
}
use of org.apache.poi.hslf.record.Record in project poi by apache.
the class UserEditAndPersistListing method findRecordAtPos.
// Finds the record at a given position
public static Record findRecordAtPos(int pos) {
long type = LittleEndian.getUShort(fileContents, pos + 2);
long rlen = LittleEndian.getUInt(fileContents, pos + 4);
Record r = Record.createRecordForType(type, fileContents, pos, (int) rlen + 8);
return r;
}
use of org.apache.poi.hslf.record.Record in project poi by apache.
the class HSLFSlideShowImpl method getEmbeddedObjects.
/**
* Gets embedded object data from the slide show.
*
* @return the embedded objects.
*/
public HSLFObjectData[] getEmbeddedObjects() {
if (_objects == null) {
List<HSLFObjectData> objects = new ArrayList<HSLFObjectData>();
for (Record r : _records) {
if (r instanceof ExOleObjStg) {
objects.add(new HSLFObjectData((ExOleObjStg) r));
}
}
_objects = objects.toArray(new HSLFObjectData[objects.size()]);
}
return _objects;
}
use of org.apache.poi.hslf.record.Record in project poi by apache.
the class HSLFSlideShowImpl method read.
private Record[] read(byte[] docstream, int usrOffset) throws IOException {
//sort found records by offset.
//(it is not necessary but SlideShow.findMostRecentCoreRecords() expects them sorted)
// offset -> record
NavigableMap<Integer, Record> records = new TreeMap<Integer, Record>();
// offset -> persistId
Map<Integer, Integer> persistIds = new HashMap<Integer, Integer>();
initRecordOffsets(docstream, usrOffset, records, persistIds);
HSLFSlideShowEncrypted decryptData = new HSLFSlideShowEncrypted(docstream, records);
for (Map.Entry<Integer, Record> entry : records.entrySet()) {
Integer offset = entry.getKey();
Record record = entry.getValue();
Integer persistId = persistIds.get(offset);
if (record == null) {
// all plain records have been already added,
// only new records need to be decrypted (tbd #35897)
decryptData.decryptRecord(docstream, persistId, offset);
record = Record.buildRecordAtOffset(docstream, offset);
entry.setValue(record);
}
if (record instanceof PersistRecord) {
((PersistRecord) record).setPersistId(persistId);
}
}
decryptData.close();
return records.values().toArray(new Record[records.size()]);
}
use of org.apache.poi.hslf.record.Record in project poi by apache.
the class HSLFTextParagraph method findStyleAtomPresent.
/**
* Search for a StyleTextPropAtom is for this text header (list of paragraphs)
*
* @param header the header
* @param textLen the length of the rawtext, or -1 if the length is not known
*/
private static StyleTextPropAtom findStyleAtomPresent(TextHeaderAtom header, int textLen) {
boolean afterHeader = false;
StyleTextPropAtom style = null;
for (Record record : header.getParentRecord().getChildRecords()) {
long rt = record.getRecordType();
if (afterHeader && rt == RecordTypes.TextHeaderAtom.typeID) {
// already on the next header, quit searching
break;
}
afterHeader |= (header == record);
if (afterHeader && rt == RecordTypes.StyleTextPropAtom.typeID) {
// found it
style = (StyleTextPropAtom) record;
}
}
if (style == null) {
logger.log(POILogger.INFO, "styles atom doesn't exist. Creating dummy record for later saving.");
style = new StyleTextPropAtom((textLen < 0) ? 1 : textLen);
} else {
if (textLen >= 0) {
style.setParentTextSize(textLen);
}
}
return style;
}
Aggregations