Conditional check for logging to avoid creating too many temporary objects.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353559 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Glen Stampoultzis 2004-06-20 10:18:50 +00:00
parent 7b38e0ceb0
commit 307d2ddc32
5 changed files with 170 additions and 95 deletions

View File

@ -135,17 +135,20 @@ public class Sheet implements Model
if (rec.getSid() == LabelRecord.sid)
{
if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "Hit label record.");
retval.containsLabels = true;
}
else if (rec.getSid() == BOFRecord.sid)
{
bofEofNestingLevel++;
if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "Hit BOF record. Nesting increased to " + bofEofNestingLevel);
}
else if (rec.getSid() == EOFRecord.sid)
{
--bofEofNestingLevel;
if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "Hit EOF record. Nesting decreased to " + bofEofNestingLevel);
if (bofEofNestingLevel == 0) {
records.add(rec);
@ -285,6 +288,7 @@ public class Sheet implements Model
{
retval.cells = new ValueRecordsAggregate();
}
if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "sheet createSheet (existing file) exited");
return retval;
}
@ -344,6 +348,7 @@ public class Sheet implements Model
public static Sheet createSheet(List records, int sheetnum)
{
if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG,
"Sheet createSheet (exisiting file) assumed offset 0");
return createSheet(records, sheetnum, 0);
@ -359,6 +364,7 @@ public class Sheet implements Model
public static Sheet createSheet()
{
if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "Sheet createsheet from scratch called");
Sheet retval = new Sheet();
ArrayList records = new ArrayList(30);
@ -409,6 +415,7 @@ public class Sheet implements Model
records.add(retval.protect);
records.add(retval.createEOF());
retval.records = records;
if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "Sheet createsheet from scratch exit");
return retval;
}
@ -553,6 +560,7 @@ public class Sheet implements Model
public void convertLabelRecords(Workbook wb)
{
if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "convertLabelRecords called");
if (containsLabels)
{
@ -577,6 +585,7 @@ public class Sheet implements Model
}
}
}
if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "convertLabelRecords exit");
}
@ -591,6 +600,8 @@ public class Sheet implements Model
{
checkCells();
checkRows();
if (log.check( POILogger.DEBUG ))
{
log.log(POILogger.DEBUG, "Sheet.getNumRecords");
log.logFormatted(POILogger.DEBUG, "returning % + % + % - 2 = %", new int[]
{
@ -599,6 +610,7 @@ public class Sheet implements Model
records.size() + cells.getPhysicalNumberOfCells()
+ rows.getPhysicalNumberOfRows() - 2
});
}
return records.size() + cells.getPhysicalNumberOfCells()
+ rows.getPhysicalNumberOfRows() - 2;
}
@ -614,6 +626,8 @@ public class Sheet implements Model
//public void setDimensions(short firstrow, short firstcol, short lastrow,
public void setDimensions(int firstrow, short firstcol, int lastrow,
short lastcol)
{
if (log.check( POILogger.DEBUG ))
{
log.log(POILogger.DEBUG, "Sheet.setDimensions");
log.log(POILogger.DEBUG,
@ -621,11 +635,15 @@ public class Sheet implements Model
.append("firstcol").append(firstcol).append("lastrow")
.append(lastrow).append("lastcol").append(lastcol)
.toString());
}
dims.setFirstCol(firstcol);
dims.setFirstRow(firstrow);
dims.setLastCol(lastcol);
dims.setLastRow(lastrow);
log.log(log.DEBUG, "Sheet.setDimensions exiting");
if (log.check( POILogger.DEBUG ))
{
log.log(POILogger.DEBUG, "Sheet.setDimensions exiting");
}
}
/**
@ -647,7 +665,8 @@ public class Sheet implements Model
public void setLoc(int loc)
{
valueRecIterator = null;
log.log(log.DEBUG, "sheet.setLoc(): " + loc);
if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "sheet.setLoc(): " + loc);
this.loc = loc;
}
@ -658,7 +677,8 @@ public class Sheet implements Model
public int getLoc()
{
log.log(log.DEBUG, "sheet.getLoc():" + loc);
if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "sheet.getLoc():" + loc);
return loc;
}
@ -697,6 +717,7 @@ public class Sheet implements Model
public int serialize(int offset, byte [] data)
{
if (log.check( POILogger.DEBUG ))
log.log(log.DEBUG, "Sheet.serialize using offsets");
int pos = offset;
@ -725,6 +746,7 @@ public class Sheet implements Model
}
}
}
if (log.check( POILogger.DEBUG ))
log.log(log.DEBUG, "Sheet.serialize returning ");
return pos-offset;
}
@ -774,6 +796,7 @@ public class Sheet implements Model
public RowRecord createRow(int row)
{
if (log.check( POILogger.DEBUG ))
log.log(log.DEBUG, "create row number " + row);
RowRecord rowrec = new RowRecord();
@ -1020,6 +1043,7 @@ public class Sheet implements Model
{
checkCells();
setLoc(dimsloc);
if (log.check( POILogger.DEBUG ))
log.log(log.DEBUG, "replaceValueRecord ");
cells.insertCell(newval);
@ -1056,6 +1080,7 @@ public class Sheet implements Model
public void addRow(RowRecord row)
{
checkRows();
if (log.check( POILogger.DEBUG ))
log.log(log.DEBUG, "addRow ");
DimensionsRecord d = ( DimensionsRecord ) records.get(getDimsLoc());
@ -1110,6 +1135,7 @@ public class Sheet implements Model
* }
* }
*/
if (log.check( POILogger.DEBUG ))
log.log(log.DEBUG, "exit addRow");
}
@ -1171,6 +1197,7 @@ public class Sheet implements Model
public CellValueRecordInterface getNextValueRecord()
{
if (log.check( POILogger.DEBUG ))
log.log(log.DEBUG, "getNextValue loc= " + loc);
if (valueRecIterator == null)
{
@ -1258,6 +1285,7 @@ public class Sheet implements Model
public RowRecord getNextRow()
{
if (log.check( POILogger.DEBUG ))
log.log(log.DEBUG, "getNextRow loc= " + loc);
if (rowRecIterator == null)
{
@ -1304,6 +1332,7 @@ public class Sheet implements Model
//public RowRecord getRow(short rownum)
public RowRecord getRow(int rownum)
{
if (log.check( POILogger.DEBUG ))
log.log(log.DEBUG, "getNextRow loc= " + loc);
if (rows == null) {
return null;
@ -2072,6 +2101,7 @@ public class Sheet implements Model
public int getDimsLoc()
{
if (log.check( POILogger.DEBUG ))
log.log(log.DEBUG, "getDimsLoc dimsloc= " + dimsloc);
return dimsloc;
}
@ -2525,6 +2555,7 @@ public class Sheet implements Model
protected Record createProtect()
{
if (log.check( POILogger.DEBUG ))
log.log(log.DEBUG, "create protect record with protection disabled");
ProtectRecord retval = new ProtectRecord();

View File

@ -121,6 +121,7 @@ public class Workbook implements Model {
* @return Workbook object
*/
public static Workbook createWorkbook(List recs) {
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "Workbook (readfile) created with reclen=",
new Integer(recs.size()));
Workbook retval = new Workbook();
@ -131,71 +132,85 @@ public class Workbook implements Model {
if (rec.getSid() == EOFRecord.sid) {
records.add(rec);
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found workbook eof record at " + k);
break;
}
switch (rec.getSid()) {
case BoundSheetRecord.sid :
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found boundsheet record at " + k);
retval.boundsheets.add(rec);
retval.records.setBspos( k );
break;
case SSTRecord.sid :
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found sst record at " + k);
retval.sst = ( SSTRecord ) rec;
break;
case FontRecord.sid :
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found font record at " + k);
retval.records.setFontpos( k );
retval.numfonts++;
break;
case ExtendedFormatRecord.sid :
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found XF record at " + k);
retval.records.setXfpos( k );
retval.numxfs++;
break;
case TabIdRecord.sid :
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found tabid record at " + k);
retval.records.setTabpos( k );
break;
case ProtectRecord.sid :
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found protect record at " + k);
retval.records.setProtpos( k );
break;
case BackupRecord.sid :
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found backup record at " + k);
retval.records.setBackuppos( k );
break;
case ExternSheetRecord.sid :
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found extern sheet record at " + k);
retval.externSheet = ( ExternSheetRecord ) rec;
break;
case NameRecord.sid :
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found name record at " + k);
retval.names.add(rec);
// retval.records.namepos = k;
// retval.records.namepos = k;
break;
case SupBookRecord.sid :
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found SupBook record at " + k);
// retval.records.supbookpos = k;
// retval.records.supbookpos = k;
break;
case FormatRecord.sid :
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found format record at " + k);
retval.formats.add(rec);
retval.maxformatid = retval.maxformatid >= ((FormatRecord)rec).getIndexCode() ? retval.maxformatid : ((FormatRecord)rec).getIndexCode();
break;
case DateWindow1904Record.sid :
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found datewindow1904 record at " + k);
retval.uses1904datewindowing = ((DateWindow1904Record)rec).getWindowing() == 1;
break;
case PaletteRecord.sid:
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found palette record at " + k);
retval.records.setPalettepos( k );
default :
@ -203,12 +218,13 @@ public class Workbook implements Model {
records.add(rec);
}
//What if we dont have any ranges and supbooks
// if (retval.records.supbookpos == 0) {
// retval.records.supbookpos = retval.records.bspos + 1;
// retval.records.namepos = retval.records.supbookpos + 1;
// }
// if (retval.records.supbookpos == 0) {
// retval.records.supbookpos = retval.records.bspos + 1;
// retval.records.namepos = retval.records.supbookpos + 1;
// }
retval.records.setRecords(records);
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "exit create workbook from existing file function");
return retval;
}
@ -219,6 +235,7 @@ public class Workbook implements Model {
*/
public static Workbook createWorkbook()
{
if (log.check( POILogger.DEBUG ))
log.log( DEBUG, "creating new workbook from scratch" );
Workbook retval = new Workbook();
ArrayList records = new ArrayList( 30 );
@ -295,6 +312,7 @@ public class Workbook implements Model {
records.add( retval.createEOF() );
retval.records.setRecords(records);
if (log.check( POILogger.DEBUG ))
log.log( DEBUG, "exit create new workbook from scratch" );
return retval;
}
@ -402,6 +420,7 @@ public class Workbook implements Model {
*/
public void setSheetBof(int sheetnum, int pos) {
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "setting bof for sheetnum =", new Integer(sheetnum),
" at pos=", new Integer(pos));
checkSheets(sheetnum);
@ -534,6 +553,7 @@ public class Workbook implements Model {
*/
public int getNumSheets() {
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "getNumSheets=", new Integer(boundsheets.size()));
return boundsheets.size();
}
@ -545,6 +565,7 @@ public class Workbook implements Model {
*/
public int getNumExFormats() {
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "getXF=", new Integer(numxfs));
return numxfs;
}
@ -592,6 +613,7 @@ public class Workbook implements Model {
*/
public int addSSTString(String string, boolean use16bits) {
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "insert to sst string='", string, "' and use16bits= ",
new Boolean(use16bits));
if (sst == null) {
@ -625,6 +647,7 @@ public class Workbook implements Model {
}
String retval = sst.getString(str);
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "Returning SST for index=", new Integer(str),
" String= ", retval);
return retval;
@ -638,6 +661,7 @@ public class Workbook implements Model {
*/
public void insertSST() {
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "creating new SST via insertSST!");
sst = ( SSTRecord ) createSST();
records.add(records.size() - 1, createExtendedSST());
@ -691,6 +715,7 @@ public class Workbook implements Model {
public int serialize( int offset, byte[] data )
{
if (log.check( POILogger.DEBUG ))
log.log( DEBUG, "Serializing Workbook with offsets" );
int pos = 0;
@ -716,6 +741,7 @@ public class Workbook implements Model {
pos += record.serialize( pos + offset, data ); // rec.length;
}
}
if (log.check( POILogger.DEBUG ))
log.log( DEBUG, "Exiting serialize workbook" );
return pos;
}

View File

@ -133,11 +133,13 @@ public class EscherGraphics
public void clipRect(int x, int y, int width, int height)
{
if (logger.check( POILogger.WARN ))
logger.log(POILogger.WARN,"clipRect not supported");
}
public void copyArea(int x, int y, int width, int height, int dx, int dy)
{
if (logger.check( POILogger.WARN ))
logger.log(POILogger.WARN,"copyArea not supported");
}
@ -155,6 +157,7 @@ public class EscherGraphics
public void drawArc(int x, int y, int width, int height,
int startAngle, int arcAngle)
{
if (logger.check( POILogger.WARN ))
logger.log(POILogger.WARN,"drawArc not supported");
}
@ -164,6 +167,7 @@ public class EscherGraphics
Color bgcolor,
ImageObserver observer)
{
if (logger.check( POILogger.WARN ))
logger.log(POILogger.WARN,"drawImage not supported");
return true;
@ -174,6 +178,7 @@ public class EscherGraphics
int sx1, int sy1, int sx2, int sy2,
ImageObserver observer)
{
if (logger.check( POILogger.WARN ))
logger.log(POILogger.WARN,"drawImage not supported");
return true;
}
@ -241,17 +246,20 @@ public class EscherGraphics
public void drawPolyline(int xPoints[], int yPoints[],
int nPoints)
{
if (logger.check( POILogger.WARN ))
logger.log(POILogger.WARN,"drawPolyline not supported");
}
public void drawRect(int x, int y, int width, int height)
{
if (logger.check( POILogger.WARN ))
logger.log(POILogger.WARN,"drawRect not supported");
}
public void drawRoundRect(int x, int y, int width, int height,
int arcWidth, int arcHeight)
{
if (logger.check( POILogger.WARN ))
logger.log(POILogger.WARN,"drawRoundRect not supported");
}
@ -318,12 +326,14 @@ public class EscherGraphics
public void drawString(AttributedCharacterIterator iterator,
int x, int y)
{
if (logger.check( POILogger.WARN ))
logger.log(POILogger.WARN,"drawString not supported");
}
public void fillArc(int x, int y, int width, int height,
int startAngle, int arcAngle)
{
if (logger.check( POILogger.WARN ))
logger.log(POILogger.WARN,"fillArc not supported");
}
@ -384,6 +394,7 @@ public class EscherGraphics
public void fillRoundRect(int x, int y, int width, int height,
int arcWidth, int arcHeight)
{
if (logger.check( POILogger.WARN ))
logger.log(POILogger.WARN,"fillRoundRect not supported");
}
@ -439,16 +450,19 @@ public class EscherGraphics
public void setPaintMode()
{
if (logger.check( POILogger.WARN ))
logger.log(POILogger.WARN,"setPaintMode not supported");
}
public void setXORMode(Color color)
{
if (logger.check( POILogger.WARN ))
logger.log(POILogger.WARN,"setXORMode not supported");
}
public void translate(int x, int y)
{
if (logger.check( POILogger.WARN ))
logger.log(POILogger.WARN,"translate not supported");
}

View File

@ -142,6 +142,7 @@ public class EscherGraphics2d extends Graphics2D
public void draw(Shape shape)
{
if (logger.check( POILogger.WARN ))
logger.log(POILogger.WARN,"copyArea not supported");
}
@ -159,6 +160,7 @@ public class EscherGraphics2d extends Graphics2D
public boolean drawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1,
int sx2, int sy2, Color bgColor, ImageObserver imageobserver)
{
if (logger.check( POILogger.WARN ))
logger.log(POILogger.WARN,"drawImage() not supported");
return true;
}
@ -166,11 +168,11 @@ public class EscherGraphics2d extends Graphics2D
public boolean drawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1,
int sx2, int sy2, ImageObserver imageobserver)
{
logger.log(POILogger.WARN,"drawImage() not supported");
return drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null, imageobserver);
}
public boolean drawImage(Image image, int dx1, int dy1, int dx2, int dy2, Color bgColor, ImageObserver imageobserver)
{
if (logger.check( POILogger.WARN ))
logger.log(POILogger.WARN,"drawImage() not supported");
return true;
}
@ -286,6 +288,7 @@ public class EscherGraphics2d extends Graphics2D
public void fill(Shape shape)
{
if (logger.check( POILogger.WARN ))
logger.log(POILogger.WARN,"fill(Shape) not supported");
}

View File

@ -754,6 +754,7 @@ public class HSSFWorkbook
public byte[] getBytes()
{
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "HSSFWorkbook.getBytes()");
int wbsize = workbook.getSize();