use of org.apache.poi.util.RecordFormatException in project poi by apache.
the class EscherDggRecord method fillFields.
@Override
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
int bytesRemaining = readHeader(data, offset);
int pos = offset + 8;
int size = 0;
field_1_shapeIdMax = LittleEndian.getInt(data, pos + size);
size += 4;
// field_2_numIdClusters = LittleEndian.getInt( data, pos + size );
size += 4;
field_3_numShapesSaved = LittleEndian.getInt(data, pos + size);
size += 4;
field_4_drawingsSaved = LittleEndian.getInt(data, pos + size);
size += 4;
// Can't rely on field_2_numIdClusters
field_5_fileIdClusters = new FileIdCluster[(bytesRemaining - size) / 8];
for (int i = 0; i < field_5_fileIdClusters.length; i++) {
field_5_fileIdClusters[i] = new FileIdCluster(LittleEndian.getInt(data, pos + size), LittleEndian.getInt(data, pos + size + 4));
maxDgId = Math.max(maxDgId, field_5_fileIdClusters[i].getDrawingGroupId());
size += 8;
}
bytesRemaining -= size;
if (bytesRemaining != 0)
throw new RecordFormatException("Expecting no remaining data but got " + bytesRemaining + " byte(s).");
return 8 + size + bytesRemaining;
}
use of org.apache.poi.util.RecordFormatException in project poi by apache.
the class EscherSpgrRecord method fillFields.
@Override
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
int bytesRemaining = readHeader(data, offset);
int pos = offset + 8;
int size = 0;
field_1_rectX1 = LittleEndian.getInt(data, pos + size);
size += 4;
field_2_rectY1 = LittleEndian.getInt(data, pos + size);
size += 4;
field_3_rectX2 = LittleEndian.getInt(data, pos + size);
size += 4;
field_4_rectY2 = LittleEndian.getInt(data, pos + size);
size += 4;
bytesRemaining -= size;
if (bytesRemaining != 0)
throw new RecordFormatException("Expected no remaining bytes but got " + bytesRemaining);
// System.arraycopy( data, pos + size, remainingData, 0, bytesRemaining );
return 8 + size + bytesRemaining;
}
use of org.apache.poi.util.RecordFormatException in project poi by apache.
the class InternalWorkbook method cloneDrawings.
/**
* Check if the cloned sheet has drawings. If yes, then allocate a new drawing group ID and
* re-generate shape IDs
*
* @param sheet the cloned sheet
*/
public void cloneDrawings(InternalSheet sheet) {
findDrawingGroup();
if (drawingManager == null) {
//this workbook does not have drawings
return;
}
//check if the cloned sheet has drawings
int aggLoc = sheet.aggregateDrawingRecords(drawingManager, false);
if (aggLoc == -1) {
return;
}
EscherAggregate agg = (EscherAggregate) sheet.findFirstRecordBySid(EscherAggregate.sid);
EscherContainerRecord escherContainer = agg.getEscherContainer();
if (escherContainer == null) {
return;
}
EscherDggRecord dgg = drawingManager.getDgg();
//register a new drawing group for the cloned sheet
int dgId = drawingManager.findNewDrawingGroupId();
dgg.addCluster(dgId, 0);
dgg.setDrawingsSaved(dgg.getDrawingsSaved() + 1);
EscherDgRecord dg = null;
for (EscherRecord er : escherContainer) {
if (er instanceof EscherDgRecord) {
dg = (EscherDgRecord) er;
//update id of the drawing in the cloned sheet
dg.setOptions((short) (dgId << 4));
} else if (er instanceof EscherContainerRecord) {
// iterate over shapes and re-generate shapeId
for (EscherRecord er2 : (EscherContainerRecord) er) {
for (EscherRecord shapeChildRecord : (EscherContainerRecord) er2) {
int recordId = shapeChildRecord.getRecordId();
if (recordId == EscherSpRecord.RECORD_ID) {
if (dg == null) {
throw new RecordFormatException("EscherDgRecord wasn't set/processed before.");
}
EscherSpRecord sp = (EscherSpRecord) shapeChildRecord;
int shapeId = drawingManager.allocateShapeId((short) dgId, dg);
//allocateShapeId increments the number of shapes. roll back to the previous value
dg.setNumShapes(dg.getNumShapes() - 1);
sp.setShapeId(shapeId);
} else if (recordId == EscherOptRecord.RECORD_ID) {
EscherOptRecord opt = (EscherOptRecord) shapeChildRecord;
EscherSimpleProperty prop = (EscherSimpleProperty) opt.lookup(EscherProperties.BLIP__BLIPTODISPLAY);
if (prop != null) {
int pictureIndex = prop.getPropertyValue();
// increment reference count for pictures
EscherBSERecord bse = getBSERecord(pictureIndex);
bse.setRef(bse.getRef() + 1);
}
}
}
}
}
}
}
use of org.apache.poi.util.RecordFormatException in project poi by apache.
the class InternalWorkbook method createWorkbook.
/**
* read support for low level
* API. Pass in an array of Record objects, A Workbook
* object is constructed and passed back with all of its initialization set
* to the passed in records and references to those records held. Unlike Sheet
* workbook does not use an offset (its assumed to be 0) since its first in a file.
* If you need an offset then construct a new array with a 0 offset or write your
* own ;-p.
*
* @param recs an array of Record objects
* @return Workbook object
*/
public static InternalWorkbook createWorkbook(List<Record> recs) {
LOG.log(DEBUG, "Workbook (readfile) created with reclen=", recs.size());
InternalWorkbook retval = new InternalWorkbook();
List<Record> records = new ArrayList<Record>(recs.size() / 3);
retval.records.setRecords(records);
boolean eofPassed = false;
for (int k = 0; k < recs.size(); k++) {
Record rec = recs.get(k);
String logObj;
switch(rec.getSid()) {
case EOFRecord.sid:
logObj = "workbook eof";
break;
case BoundSheetRecord.sid:
logObj = "boundsheet";
retval.boundsheets.add((BoundSheetRecord) rec);
retval.records.setBspos(k);
break;
case SSTRecord.sid:
logObj = "sst";
retval.sst = (SSTRecord) rec;
break;
case FontRecord.sid:
logObj = "font";
retval.records.setFontpos(k);
retval.numfonts++;
break;
case ExtendedFormatRecord.sid:
logObj = "XF";
retval.records.setXfpos(k);
retval.numxfs++;
break;
case TabIdRecord.sid:
logObj = "tabid";
retval.records.setTabpos(k);
break;
case ProtectRecord.sid:
logObj = "protect";
retval.records.setProtpos(k);
break;
case BackupRecord.sid:
logObj = "backup";
retval.records.setBackuppos(k);
break;
case ExternSheetRecord.sid:
throw new RecordFormatException("Extern sheet is part of LinkTable");
case NameRecord.sid:
case SupBookRecord.sid:
// LinkTable can start with either of these
LOG.log(DEBUG, "found SupBook record at " + k);
retval.linkTable = new LinkTable(recs, k, retval.records, retval.commentRecords);
k += retval.linkTable.getRecordCount() - 1;
continue;
case FormatRecord.sid:
logObj = "format";
FormatRecord fr = (FormatRecord) rec;
retval.formats.add(fr);
retval.maxformatid = retval.maxformatid >= fr.getIndexCode() ? retval.maxformatid : fr.getIndexCode();
break;
case DateWindow1904Record.sid:
logObj = "datewindow1904";
retval.uses1904datewindowing = ((DateWindow1904Record) rec).getWindowing() == 1;
break;
case PaletteRecord.sid:
logObj = "palette";
retval.records.setPalettepos(k);
break;
case WindowOneRecord.sid:
logObj = "WindowOneRecord";
retval.windowOne = (WindowOneRecord) rec;
break;
case WriteAccessRecord.sid:
logObj = "WriteAccess";
retval.writeAccess = (WriteAccessRecord) rec;
break;
case WriteProtectRecord.sid:
logObj = "WriteProtect";
retval.writeProtect = (WriteProtectRecord) rec;
break;
case FileSharingRecord.sid:
logObj = "FileSharing";
retval.fileShare = (FileSharingRecord) rec;
break;
case NameCommentRecord.sid:
logObj = "NameComment";
final NameCommentRecord ncr = (NameCommentRecord) rec;
retval.commentRecords.put(ncr.getNameText(), ncr);
break;
case HyperlinkRecord.sid:
// Look for other interesting values that follow the EOFRecord
logObj = "Hyperlink";
retval.hyperlinks.add((HyperlinkRecord) rec);
break;
default:
logObj = "(sid=" + rec.getSid() + ")";
break;
}
if (!eofPassed) {
records.add(rec);
}
LOG.log(DEBUG, "found " + logObj + " record at " + k);
if (rec.getSid() == EOFRecord.sid) {
eofPassed = true;
}
}
if (retval.windowOne == null) {
retval.windowOne = createWindowOne();
}
LOG.log(DEBUG, "exit create workbook from existing file function");
return retval;
}
use of org.apache.poi.util.RecordFormatException in project poi by apache.
the class EscherSplitMenuColorsRecord method fillFields.
@Override
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
int bytesRemaining = readHeader(data, offset);
int pos = offset + 8;
int size = 0;
field_1_color1 = LittleEndian.getInt(data, pos + size);
size += 4;
field_2_color2 = LittleEndian.getInt(data, pos + size);
size += 4;
field_3_color3 = LittleEndian.getInt(data, pos + size);
size += 4;
field_4_color4 = LittleEndian.getInt(data, pos + size);
size += 4;
bytesRemaining -= size;
if (bytesRemaining != 0)
throw new RecordFormatException("Expecting no remaining data but got " + bytesRemaining + " byte(s).");
return 8 + size + bytesRemaining;
}
Aggregations