Fixed unused imports compiler warnings (and some others)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@805262 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2009-08-18 02:41:45 +00:00
parent 37bbf5d179
commit 995d8fe73f
170 changed files with 2860 additions and 3873 deletions

View File

@ -1,195 +0,0 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.dev;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.IOException;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.eventmodel.*;
import org.apache.poi.hssf.eventusermodel.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.eventusermodel.HSSFRequest;
import org.apache.poi.hssf.eventusermodel.HSSFListener;
import org.apache.poi.hssf.eventusermodel.HSSFEventFactory;
/**
* Event Factory version of HSSF test class.
* @author andy
*/
//JMH
//public class EFHSSF
//{
// String infile;
// String outfile;
// HSSFWorkbook workbook = null;
// HSSFSheet cursheet = null;
//
// /** Creates a new instance of EFHSSF */
//
// public EFHSSF()
// {
// }
//
// public void setInputFile(String infile)
// {
// this.infile = infile;
// }
//
// public void setOutputFile(String outfile)
// {
// this.outfile = outfile;
// }
//
// public void run()
// throws IOException
// {
// FileInputStream fin = new FileInputStream(infile);
// POIFSFileSystem poifs = new POIFSFileSystem(fin);
// InputStream din = poifs.createDocumentInputStream("Workbook");
// HSSFRequest req = new HSSFRequest();
//
// req.addListenerForAllRecords(new EFHSSFListener(this));
// HSSFEventFactory factory = new HSSFEventFactory();
//
// factory.processEvents(req, din);
// fin.close();
// din.close();
// FileOutputStream fout = new FileOutputStream(outfile);
//
// workbook.write(fout);
// fout.close();
// System.out.println("done.");
// }
//
// public void recordHandler(Record record)
// {
// HSSFRow row = null;
// HSSFCell cell = null;
// int sheetnum = -1;
//
// switch (record.getSid())
// {
//
// case BOFRecord.sid :
// BOFRecord bof = ( BOFRecord ) record;
//
// if (bof.getType() == bof.TYPE_WORKBOOK)
// {
// workbook = new HSSFWorkbook();
// }
// else if (bof.getType() == bof.TYPE_WORKSHEET)
// {
// sheetnum++;
// cursheet = workbook.getSheetAt(sheetnum);
// }
// break;
//
// case BoundSheetRecord.sid :
// BoundSheetRecord bsr = ( BoundSheetRecord ) record;
//
// workbook.createSheet(bsr.getSheetname());
// break;
//
// case RowRecord.sid :
// RowRecord rowrec = ( RowRecord ) record;
//
// cursheet.createRow(rowrec.getRowNumber());
// break;
//
// case NumberRecord.sid :
// NumberRecord numrec = ( NumberRecord ) record;
//
// row = cursheet.getRow(numrec.getRow());
// cell = row.createCell(numrec.getColumn(),
// HSSFCell.CELL_TYPE_NUMERIC);
// cell.setCellValue(numrec.getValue());
// break;
//
// case SSTRecord.sid :
// SSTRecord sstrec = ( SSTRecord ) record;
//
// for (int k = 0; k < sstrec.getNumUniqueStrings(); k++)
// {
// workbook.addSSTString(new UnicodeString(sstrec.getString(k)));
// }
// break;
//
// case LabelSSTRecord.sid :
// LabelSSTRecord lrec = ( LabelSSTRecord ) record;
//
// row = cursheet.getRow(lrec.getRow());
// cell = row.createCell(lrec.getColumn(),
// HSSFCell.CELL_TYPE_STRING);
// cell.setCellValue(workbook.getSSTString(lrec.getSSTIndex()));
// break;
// }
// }
//
// public static void main(String [] args)
// {
// if ((args.length < 2) || !args[ 0 ].equals("--help"))
// {
// try
// {
// EFHSSF viewer = new EFHSSF();
//
// viewer.setInputFile(args[ 0 ]);
// viewer.setOutputFile(args[ 1 ]);
// viewer.run();
// }
// catch (IOException e)
// {
// e.printStackTrace();
// }
// }
// else
// {
// System.out.println("EFHSSF");
// System.out.println(
// "General testbed for HSSFEventFactory based testing and "
// + "Code examples");
// System.out.println("Usage: java org.apache.poi.hssf.dev.EFHSSF "
// + "file1 file2");
// System.out.println(
// " --will rewrite the file reading with the event api");
// System.out.println("and writing with the standard API");
// }
// }
//}
//
//class EFHSSFListener
// implements HSSFListener
//{
// EFHSSF efhssf;
//
// public EFHSSFListener(EFHSSF efhssf)
// {
// this.efhssf = efhssf;
// }
//
// public void processRecord(Record record)
// {
// efhssf.recordHandler(record);
// }
//}

View File

@ -14,16 +14,23 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.model; package org.apache.poi.hssf.model;
import org.apache.poi.hssf.record.*; import java.util.Iterator;
import java.util.List;
import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherProperty;
import org.apache.poi.ddf.EscherSimpleProperty;
import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
import org.apache.poi.hssf.record.NoteRecord;
import org.apache.poi.hssf.record.NoteStructureSubRecord;
import org.apache.poi.hssf.record.ObjRecord;
import org.apache.poi.hssf.record.SubRecord;
import org.apache.poi.hssf.usermodel.HSSFComment; import org.apache.poi.hssf.usermodel.HSSFComment;
import org.apache.poi.hssf.usermodel.HSSFShape; import org.apache.poi.hssf.usermodel.HSSFShape;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.ddf.*;
import java.util.List;
import java.util.Iterator;
/** /**
* Represents a cell comment. * Represents a cell comment.
@ -32,9 +39,9 @@ import java.util.Iterator;
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public class CommentShape extends TextboxShape { public final class CommentShape extends TextboxShape {
private NoteRecord note; private NoteRecord _note;
/** /**
* Creates the low-level records for a comment. * Creates the low-level records for a comment.
@ -46,10 +53,10 @@ public class CommentShape extends TextboxShape {
{ {
super(hssfShape, shapeId); super(hssfShape, shapeId);
note = createNoteRecord(hssfShape, shapeId); _note = createNoteRecord(hssfShape, shapeId);
ObjRecord obj = getObjRecord(); ObjRecord obj = getObjRecord();
List records = obj.getSubRecords(); List<SubRecord> records = obj.getSubRecords();
int cmoIdx = 0; int cmoIdx = 0;
for (int i = 0; i < records.size(); i++) { for (int i = 0; i < records.size(); i++) {
Object r = records.get(i); Object r = records.get(i);
@ -96,9 +103,9 @@ public class CommentShape extends TextboxShape {
super.addStandardOptions(shape, opt); super.addStandardOptions(shape, opt);
//remove unnecessary properties inherited from TextboxShape //remove unnecessary properties inherited from TextboxShape
java.util.List props = opt.getEscherProperties(); List<EscherProperty> props = opt.getEscherProperties();
for ( Iterator iterator = props.iterator(); iterator.hasNext(); ) { for (Iterator<EscherProperty> iterator = props.iterator(); iterator.hasNext(); ) {
EscherProperty prop = (EscherProperty) iterator.next(); EscherProperty prop = iterator.next();
switch (prop.getId()){ switch (prop.getId()){
case EscherProperties.TEXT__TEXTLEFT: case EscherProperties.TEXT__TEXTLEFT:
case EscherProperties.TEXT__TEXTRIGHT: case EscherProperties.TEXT__TEXTRIGHT:
@ -127,7 +134,6 @@ public class CommentShape extends TextboxShape {
*/ */
public NoteRecord getNoteRecord() public NoteRecord getNoteRecord()
{ {
return note; return _note;
} }
} }

View File

@ -72,7 +72,6 @@ import org.apache.poi.hssf.record.StyleRecord;
import org.apache.poi.hssf.record.SupBookRecord; import org.apache.poi.hssf.record.SupBookRecord;
import org.apache.poi.hssf.record.TabIdRecord; import org.apache.poi.hssf.record.TabIdRecord;
import org.apache.poi.hssf.record.UnicodeString; import org.apache.poi.hssf.record.UnicodeString;
import org.apache.poi.hssf.record.UnknownRecord;
import org.apache.poi.hssf.record.UseSelFSRecord; import org.apache.poi.hssf.record.UseSelFSRecord;
import org.apache.poi.hssf.record.WindowOneRecord; import org.apache.poi.hssf.record.WindowOneRecord;
import org.apache.poi.hssf.record.WindowProtectRecord; import org.apache.poi.hssf.record.WindowProtectRecord;
@ -271,19 +270,19 @@ public final class Workbook implements Model {
case WindowOneRecord.sid: case WindowOneRecord.sid:
if (log.check( POILogger.DEBUG )) if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found WindowOneRecord at " + k); log.log(DEBUG, "found WindowOneRecord at " + k);
retval.windowOne = (WindowOneRecord) rec; retval.windowOne = (WindowOneRecord) rec;
break; break;
case WriteAccessRecord.sid: case WriteAccessRecord.sid:
if (log.check( POILogger.DEBUG )) if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found WriteAccess at " + k); log.log(DEBUG, "found WriteAccess at " + k);
retval.writeAccess = (WriteAccessRecord) rec; retval.writeAccess = (WriteAccessRecord) rec;
break; break;
case WriteProtectRecord.sid: case WriteProtectRecord.sid:
if (log.check( POILogger.DEBUG )) if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found WriteProtect at " + k); log.log(DEBUG, "found WriteProtect at " + k);
retval.writeProtect = (WriteProtectRecord) rec; retval.writeProtect = (WriteProtectRecord) rec;
break; break;
case FileSharingRecord.sid: case FileSharingRecord.sid:
if (log.check( POILogger.DEBUG )) if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found FileSharing at " + k); log.log(DEBUG, "found FileSharing at " + k);
retval.fileShare = (FileSharingRecord) rec; retval.fileShare = (FileSharingRecord) rec;
@ -296,7 +295,7 @@ public final class Workbook implements Model {
// retval.records.supbookpos = retval.records.bspos + 1; // retval.records.supbookpos = retval.records.bspos + 1;
// retval.records.namepos = retval.records.supbookpos + 1; // retval.records.namepos = retval.records.supbookpos + 1;
// } // }
// Look for other interesting values that // Look for other interesting values that
// follow the EOFRecord // follow the EOFRecord
for ( ; k < recs.size(); k++) { for ( ; k < recs.size(); k++) {
@ -307,7 +306,7 @@ public final class Workbook implements Model {
break; break;
} }
} }
if (retval.windowOne == null) { if (retval.windowOne == null) {
retval.windowOne = createWindowOne(); retval.windowOne = createWindowOne();
} }
@ -388,7 +387,7 @@ public final class Workbook implements Model {
retval.records.setBspos(records.size() - 1); retval.records.setBspos(records.size() - 1);
} }
records.add( retval.createCountry() ); records.add( retval.createCountry() );
for ( int k = 0; k < nBoundSheets; k++ ) { for ( int k = 0; k < nBoundSheets; k++ ) {
retval.getOrCreateLinkTable().checkExternSheet(k); retval.getOrCreateLinkTable().checkExternSheet(k);
} }
retval.sst = new SSTRecord(); retval.sst = new SSTRecord();
@ -452,7 +451,7 @@ public final class Workbook implements Model {
return retval; return retval;
} }
/** /**
* Retrieves the index of the given font * Retrieves the index of the given font
*/ */
@ -468,7 +467,7 @@ public final class Workbook implements Model {
return i; return i;
} }
} }
throw new IllegalArgumentException("Could not find that font!"); throw new IllegalArgumentException("Could not find that font!");
} }
/** /**
@ -487,10 +486,10 @@ public final class Workbook implements Model {
numfonts++; numfonts++;
return rec; return rec;
} }
/** /**
* Removes the given font record from the * Removes the given font record from the
* file's list. This will make all * file's list. This will make all
* subsequent font indicies drop by one, * subsequent font indicies drop by one,
* so you'll need to update those yourself! * so you'll need to update those yourself!
*/ */
@ -553,7 +552,7 @@ public final class Workbook implements Model {
} }
/** /**
* Determines whether a workbook contains the provided sheet name. For the purpose of * Determines whether a workbook contains the provided sheet name. For the purpose of
* comparison, long names are truncated to 31 chars. * comparison, long names are truncated to 31 chars.
* *
* @param name the name to test (case insensitive match) * @param name the name to test (case insensitive match)
@ -580,18 +579,18 @@ public final class Workbook implements Model {
} }
return false; return false;
} }
/** /**
* sets the order of appearance for a given sheet. * sets the order of appearance for a given sheet.
* *
* @param sheetname the name of the sheet to reorder * @param sheetname the name of the sheet to reorder
* @param pos the position that we want to insert the sheet into (0 based) * @param pos the position that we want to insert the sheet into (0 based)
*/ */
public void setSheetOrder(String sheetname, int pos ) { public void setSheetOrder(String sheetname, int pos ) {
int sheetNumber = getSheetIndex(sheetname); int sheetNumber = getSheetIndex(sheetname);
//remove the sheet that needs to be reordered and place it in the spot we want //remove the sheet that needs to be reordered and place it in the spot we want
boundsheets.add(pos, boundsheets.remove(sheetNumber)); boundsheets.add(pos, boundsheets.remove(sheetNumber));
} }
/** /**
@ -606,7 +605,7 @@ public final class Workbook implements Model {
/** /**
* Gets the hidden flag for a given sheet. * Gets the hidden flag for a given sheet.
* Note that a sheet could instead be * Note that a sheet could instead be
* set to be very hidden, which is different * set to be very hidden, which is different
* ({@link #isSheetVeryHidden(int)}) * ({@link #isSheetVeryHidden(int)})
* *
@ -619,8 +618,8 @@ public final class Workbook implements Model {
/** /**
* Gets the very hidden flag for a given sheet. * Gets the very hidden flag for a given sheet.
* This is different from the normal * This is different from the normal
* hidden flag * hidden flag
* ({@link #isSheetHidden(int)}) * ({@link #isSheetHidden(int)})
* *
* @param sheetnum the sheet number (0 based) * @param sheetnum the sheet number (0 based)
@ -632,20 +631,20 @@ public final class Workbook implements Model {
/** /**
* Hide or unhide a sheet * Hide or unhide a sheet
* *
* @param sheetnum The sheet number * @param sheetnum The sheet number
* @param hidden True to mark the sheet as hidden, false otherwise * @param hidden True to mark the sheet as hidden, false otherwise
*/ */
public void setSheetHidden(int sheetnum, boolean hidden) { public void setSheetHidden(int sheetnum, boolean hidden) {
getBoundSheetRec(sheetnum).setHidden(hidden); getBoundSheetRec(sheetnum).setHidden(hidden);
} }
/** /**
* Hide or unhide a sheet. * Hide or unhide a sheet.
* 0 = not hidden * 0 = not hidden
* 1 = hidden * 1 = hidden
* 2 = very hidden. * 2 = very hidden.
* *
* @param sheetnum The sheet number * @param sheetnum The sheet number
* @param hidden 0 for not hidden, 1 for hidden, 2 for very hidden * @param hidden 0 for not hidden, 1 for hidden, 2 for very hidden
*/ */
@ -664,8 +663,8 @@ public final class Workbook implements Model {
bsr.setHidden(h); bsr.setHidden(h);
bsr.setVeryHidden(vh); bsr.setVeryHidden(vh);
} }
/** /**
* get the sheet's index * get the sheet's index
* @param name sheet name * @param name sheet name
@ -713,18 +712,18 @@ public final class Workbook implements Model {
boundsheets.remove(sheetIndex); boundsheets.remove(sheetIndex);
fixTabIdRecord(); fixTabIdRecord();
} }
// Within NameRecords, it's ok to have the formula // Within NameRecords, it's ok to have the formula
// part point at deleted sheets. It's also ok to // part point at deleted sheets. It's also ok to
// have the ExternSheetNumber point at deleted // have the ExternSheetNumber point at deleted
// sheets. // sheets.
// However, the sheet index must be adjusted, or // However, the sheet index must be adjusted, or
// excel will break. (Sheet index is either 0 for // excel will break. (Sheet index is either 0 for
// global, or 1 based index to sheet) // global, or 1 based index to sheet)
int sheetNum1Based = sheetIndex + 1; int sheetNum1Based = sheetIndex + 1;
for(int i=0; i<getNumNames(); i++) { for(int i=0; i<getNumNames(); i++) {
NameRecord nr = getNameRecord(i); NameRecord nr = getNameRecord(i);
if(nr.getSheetNumber() == sheetNum1Based) { if(nr.getSheetNumber() == sheetNum1Based) {
// Excel re-writes these to point to no sheet // Excel re-writes these to point to no sheet
nr.setSheetNumber(0); nr.setSheetNumber(0);
@ -790,10 +789,10 @@ public final class Workbook implements Model {
return retval; return retval;
} }
/** /**
* Removes the given ExtendedFormatRecord record from the * Removes the given ExtendedFormatRecord record from the
* file's list. This will make all * file's list. This will make all
* subsequent font indicies drop by one, * subsequent font indicies drop by one,
* so you'll need to update those yourself! * so you'll need to update those yourself!
*/ */
@ -818,14 +817,14 @@ public final class Workbook implements Model {
numxfs++; numxfs++;
return xf; return xf;
} }
/** /**
* Returns the StyleRecord for the given * Returns the StyleRecord for the given
* xfIndex, or null if that ExtendedFormat doesn't * xfIndex, or null if that ExtendedFormat doesn't
* have a Style set. * have a Style set.
*/ */
public StyleRecord getStyleRecord(int xfIndex) { public StyleRecord getStyleRecord(int xfIndex) {
// Style records always follow after // Style records always follow after
// the ExtendedFormat records // the ExtendedFormat records
for(int i=records.getXfpos(); i<records.size(); i++) { for(int i=records.getXfpos(); i<records.size(); i++) {
Record r = records.get(i); Record r = records.get(i);
@ -848,11 +847,11 @@ public final class Workbook implements Model {
* records collection * records collection
*/ */
public StyleRecord createStyleRecord(int xfIndex) { public StyleRecord createStyleRecord(int xfIndex) {
// Style records always follow after // Style records always follow after
// the ExtendedFormat records // the ExtendedFormat records
StyleRecord newSR = new StyleRecord(); StyleRecord newSR = new StyleRecord();
newSR.setXFIndex(xfIndex); newSR.setXFIndex(xfIndex);
// Find the spot // Find the spot
int addAt = -1; int addAt = -1;
for(int i=records.getXfpos(); i<records.size() && for(int i=records.getXfpos(); i<records.size() &&
@ -869,7 +868,7 @@ public final class Workbook implements Model {
throw new IllegalStateException("No XF Records found!"); throw new IllegalStateException("No XF Records found!");
} }
records.add(addAt, newSR); records.add(addAt, newSR);
return newSR; return newSR;
} }
@ -976,7 +975,7 @@ public final class Workbook implements Model {
// Let's skip RECALCID records, as they are only use for optimization // Let's skip RECALCID records, as they are only use for optimization
if ( record.getSid() != RecalcIdRecord.sid || ( (RecalcIdRecord) record ).isNeeded() ) if ( record.getSid() != RecalcIdRecord.sid || ( (RecalcIdRecord) record ).isNeeded() )
{ {
int len = 0; int len = 0;
if (record instanceof SSTRecord) if (record instanceof SSTRecord)
{ {
sst = (SSTRecord)record; sst = (SSTRecord)record;
@ -1090,7 +1089,7 @@ public final class Workbook implements Model {
} }
/** /**
* creates the TabId record containing an array * creates the TabId record containing an array
*/ */
private static TabIdRecord createTabId() { private static TabIdRecord createTabId() {
return new TabIdRecord(); return new TabIdRecord();
@ -1121,7 +1120,7 @@ public final class Workbook implements Model {
private static ProtectRecord createProtect() { private static ProtectRecord createProtect() {
// by default even when we support it we won't // by default even when we support it we won't
// want it to be protected // want it to be protected
return new ProtectRecord(false); return new ProtectRecord(false);
} }
/** /**
@ -1251,7 +1250,7 @@ public final class Workbook implements Model {
* @param id the number of the format record to create (meaning its position in * @param id the number of the format record to create (meaning its position in
* a file as M$ Excel would create it.) * a file as M$ Excel would create it.)
*/ */
private static FormatRecord createFormat(int id) { private static FormatRecord createFormat(int id) {
// we'll need multiple editions for // we'll need multiple editions for
// the different formats // the different formats
@ -1674,7 +1673,7 @@ public final class Workbook implements Model {
private static PaletteRecord createPalette() { private static PaletteRecord createPalette() {
return new PaletteRecord(); return new PaletteRecord();
} }
/** /**
* @return a new UseSelFS object with the use natural language flag set to 0 (false) * @return a new UseSelFS object with the use natural language flag set to 0 (false)
*/ */
@ -1724,7 +1723,7 @@ public final class Workbook implements Model {
retval.setNumStringsPerBucket(( short ) 0x8); retval.setNumStringsPerBucket(( short ) 0x8);
return retval; return retval;
} }
/** /**
* lazy initialization * lazy initialization
* Note - creating the link table causes creation of 1 EXTERNALBOOK and 1 EXTERNALSHEET record * Note - creating the link table causes creation of 1 EXTERNALBOOK and 1 EXTERNALSHEET record
@ -1784,7 +1783,7 @@ public final class Workbook implements Model {
public int getExternalSheetIndex(String workbookName, String sheetName) { public int getExternalSheetIndex(String workbookName, String sheetName) {
return getOrCreateLinkTable().getExternalSheetIndex(workbookName, sheetName); return getOrCreateLinkTable().getExternalSheetIndex(workbookName, sheetName);
} }
/** gets the total number of names /** gets the total number of names
* @return number of names * @return number of names
@ -1817,7 +1816,7 @@ public final class Workbook implements Model {
*/ */
public NameRecord addName(NameRecord name) public NameRecord addName(NameRecord name)
{ {
LinkTable linkTable = getOrCreateLinkTable(); LinkTable linkTable = getOrCreateLinkTable();
if(linkTable.nameAlreadyExists(name)) { if(linkTable.nameAlreadyExists(name)) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
@ -1828,7 +1827,7 @@ public final class Workbook implements Model {
return name; return name;
} }
/** /**
* Generates a NameRecord to represent a built-in region * Generates a NameRecord to represent a built-in region
* @return a new NameRecord * @return a new NameRecord
@ -1837,11 +1836,11 @@ public final class Workbook implements Model {
if (sheetNumber < 0 || sheetNumber+1 > Short.MAX_VALUE) { if (sheetNumber < 0 || sheetNumber+1 > Short.MAX_VALUE) {
throw new IllegalArgumentException("Sheet number ["+sheetNumber+"]is not valid "); throw new IllegalArgumentException("Sheet number ["+sheetNumber+"]is not valid ");
} }
NameRecord name = new NameRecord(builtInName, sheetNumber); NameRecord name = new NameRecord(builtInName, sheetNumber);
while(linkTable.nameAlreadyExists(name)) { while(linkTable.nameAlreadyExists(name)) {
throw new RuntimeException("Builtin (" + builtInName throw new RuntimeException("Builtin (" + builtInName
+ ") already exists for sheet (" + sheetNumber + ")"); + ") already exists for sheet (" + sheetNumber + ")");
} }
addName(name); addName(name);
@ -1853,7 +1852,7 @@ public final class Workbook implements Model {
* @param nameIndex name index * @param nameIndex name index
*/ */
public void removeName(int nameIndex){ public void removeName(int nameIndex){
if (linkTable.getNumNames() > nameIndex) { if (linkTable.getNumNames() > nameIndex) {
int idx = findFirstRecordLocBySid(NameRecord.sid); int idx = findFirstRecordLocBySid(NameRecord.sid);
records.remove(idx + nameIndex); records.remove(idx + nameIndex);
@ -1912,7 +1911,7 @@ public final class Workbook implements Model {
return maxformatid; return maxformatid;
} }
/** /**
* Returns the first occurance of a record matching a particular sid. * Returns the first occurance of a record matching a particular sid.
@ -1920,7 +1919,7 @@ public final class Workbook implements Model {
public Record findFirstRecordBySid(short sid) { public Record findFirstRecordBySid(short sid) {
for (Iterator iterator = records.iterator(); iterator.hasNext(); ) { for (Iterator iterator = records.iterator(); iterator.hasNext(); ) {
Record record = ( Record ) iterator.next(); Record record = ( Record ) iterator.next();
if (record.getSid() == sid) { if (record.getSid() == sid) {
return record; return record;
} }
@ -1966,7 +1965,7 @@ public final class Workbook implements Model {
{ {
return hyperlinks; return hyperlinks;
} }
public List<Record> getRecords() { public List<Record> getRecords() {
return records.getRecords(); return records.getRecords();
} }
@ -1980,7 +1979,7 @@ public final class Workbook implements Model {
public boolean isUsing1904DateWindowing() { public boolean isUsing1904DateWindowing() {
return uses1904datewindowing; return uses1904datewindowing;
} }
/** /**
* Returns the custom palette in use for this workbook; if a custom palette record * Returns the custom palette in use for this workbook; if a custom palette record
* does not exist, then it is created. * does not exist, then it is created.
@ -2004,7 +2003,7 @@ public final class Workbook implements Model {
} }
return palette; return palette;
} }
/** /**
* Finds the primary drawing group, if one already exists * Finds the primary drawing group, if one already exists
*/ */
@ -2060,7 +2059,7 @@ public final class Workbook implements Model {
} }
/** /**
* Creates a primary drawing group record. If it already * Creates a primary drawing group record. If it already
* exists then it's modified. * exists then it's modified.
*/ */
public void createDrawingGroup() { public void createDrawingGroup() {
@ -2124,7 +2123,7 @@ public final class Workbook implements Model {
} }
} }
public WindowOneRecord getWindowOne() { public WindowOneRecord getWindowOne() {
return windowOne; return windowOne;
} }
@ -2172,8 +2171,8 @@ public final class Workbook implements Model {
if (writeProtect == null) { if (writeProtect == null) {
writeProtect = new WriteProtectRecord(); writeProtect = new WriteProtectRecord();
int i = 0; int i = 0;
for (i = 0; for (i = 0;
i < records.size() && !(records.get(i) instanceof BOFRecord); i < records.size() && !(records.get(i) instanceof BOFRecord);
i++) { i++) {
} }
records.add(i+1, writeProtect); records.add(i+1, writeProtect);
@ -2185,8 +2184,8 @@ public final class Workbook implements Model {
if (writeAccess == null) { if (writeAccess == null) {
writeAccess = createWriteAccess(); writeAccess = createWriteAccess();
int i = 0; int i = 0;
for (i = 0; for (i = 0;
i < records.size() && !(records.get(i) instanceof InterfaceEndRecord); i < records.size() && !(records.get(i) instanceof InterfaceEndRecord);
i++) { i++) {
} }
records.add(i+1, writeAccess); records.add(i+1, writeAccess);
@ -2198,15 +2197,15 @@ public final class Workbook implements Model {
if (fileShare == null) { if (fileShare == null) {
fileShare = new FileSharingRecord(); fileShare = new FileSharingRecord();
int i = 0; int i = 0;
for (i = 0; for (i = 0;
i < records.size() && !(records.get(i) instanceof WriteAccessRecord); i < records.size() && !(records.get(i) instanceof WriteAccessRecord);
i++) { i++) {
} }
records.add(i+1, fileShare); records.add(i+1, fileShare);
} }
return fileShare; return fileShare;
} }
/** /**
* is the workbook protected with a password (not encrypted)? * is the workbook protected with a password (not encrypted)?
*/ */

View File

@ -22,7 +22,6 @@ import org.apache.poi.hssf.record.cf.BorderFormatting;
import org.apache.poi.hssf.record.cf.FontFormatting; import org.apache.poi.hssf.record.cf.FontFormatting;
import org.apache.poi.hssf.record.cf.PatternFormatting; import org.apache.poi.hssf.record.cf.PatternFormatting;
import org.apache.poi.hssf.record.formula.Ptg; import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.ss.formula.Formula; import org.apache.poi.ss.formula.Formula;
import org.apache.poi.ss.formula.FormulaType; import org.apache.poi.ss.formula.FormulaType;
@ -32,7 +31,7 @@ import org.apache.poi.util.LittleEndianOutput;
/** /**
* Conditional Formatting Rule Record (0x01B1).<br/> * Conditional Formatting Rule Record (0x01B1).<br/>
* *
* @author Dmitriy Kumshayev * @author Dmitriy Kumshayev
*/ */
public final class CFRuleRecord extends StandardRecord { public final class CFRuleRecord extends StandardRecord {
@ -101,10 +100,10 @@ public final class CFRuleRecord extends StandardRecord {
private BorderFormatting borderFormatting; private BorderFormatting borderFormatting;
private PatternFormatting patternFormatting; private PatternFormatting patternFormatting;
private Formula field_17_formula1; private Formula field_17_formula1;
private Formula field_18_formula2; private Formula field_18_formula2;
/** Creates new CFRuleRecord */ /** Creates new CFRuleRecord */
private CFRuleRecord(byte conditionType, byte comparisonOperation) private CFRuleRecord(byte conditionType, byte comparisonOperation)
{ {
@ -124,9 +123,9 @@ public final class CFRuleRecord extends StandardRecord {
field_17_formula1=Formula.create(Ptg.EMPTY_PTG_ARRAY); field_17_formula1=Formula.create(Ptg.EMPTY_PTG_ARRAY);
field_18_formula2=Formula.create(Ptg.EMPTY_PTG_ARRAY); field_18_formula2=Formula.create(Ptg.EMPTY_PTG_ARRAY);
} }
private CFRuleRecord(byte conditionType, byte comparisonOperation, Ptg[] formula1, Ptg[] formula2) { private CFRuleRecord(byte conditionType, byte comparisonOperation, Ptg[] formula1, Ptg[] formula2) {
this(conditionType, comparisonOperation); this(conditionType, comparisonOperation);
field_17_formula1 = Formula.create(formula1); field_17_formula1 = Formula.create(formula1);
field_18_formula2 = Formula.create(formula2); field_18_formula2 = Formula.create(formula2);
} }
@ -199,7 +198,7 @@ public final class CFRuleRecord extends StandardRecord {
return null; return null;
} }
} }
public boolean containsAlignFormattingBlock() public boolean containsAlignFormattingBlock()
{ {
return getOptionFlag(align); return getOptionFlag(align);
@ -208,7 +207,7 @@ public final class CFRuleRecord extends StandardRecord {
{ {
setOptionFlag(false,align); setOptionFlag(false,align);
} }
public boolean containsBorderFormattingBlock() public boolean containsBorderFormattingBlock()
{ {
return getOptionFlag(bord); return getOptionFlag(bord);
@ -229,7 +228,7 @@ public final class CFRuleRecord extends StandardRecord {
return null; return null;
} }
} }
public boolean containsPatternFormattingBlock() public boolean containsPatternFormattingBlock()
{ {
return getOptionFlag(patt); return getOptionFlag(patt);
@ -250,7 +249,7 @@ public final class CFRuleRecord extends StandardRecord {
return null; return null;
} }
} }
public boolean containsProtectionFormattingBlock() public boolean containsProtectionFormattingBlock()
{ {
return getOptionFlag(prot); return getOptionFlag(prot);
@ -259,7 +258,7 @@ public final class CFRuleRecord extends StandardRecord {
{ {
setOptionFlag(false,prot); setOptionFlag(false,prot);
} }
public void setComparisonOperation(byte operation) public void setComparisonOperation(byte operation)
{ {
field_2_comparison_operator = operation; field_2_comparison_operator = operation;
@ -269,7 +268,7 @@ public final class CFRuleRecord extends StandardRecord {
{ {
return field_2_comparison_operator; return field_2_comparison_operator;
} }
/** /**
* get the option flags * get the option flags
@ -279,7 +278,7 @@ public final class CFRuleRecord extends StandardRecord {
public int getOptions() public int getOptions()
{ {
return field_5_options; return field_5_options;
} }
private boolean isModified(BitField field) private boolean isModified(BitField field)
{ {
@ -290,7 +289,7 @@ public final class CFRuleRecord extends StandardRecord {
{ {
field_5_options = field.setBoolean(field_5_options, !modified); field_5_options = field.setBoolean(field_5_options, !modified);
} }
public boolean isLeftBorderModified() public boolean isLeftBorderModified()
{ {
return isModified(bordLeft); return isModified(bordLeft);
@ -300,7 +299,7 @@ public final class CFRuleRecord extends StandardRecord {
{ {
setModified(modified,bordLeft); setModified(modified,bordLeft);
} }
public boolean isRightBorderModified() public boolean isRightBorderModified()
{ {
return isModified(bordRight); return isModified(bordRight);
@ -310,7 +309,7 @@ public final class CFRuleRecord extends StandardRecord {
{ {
setModified(modified,bordRight); setModified(modified,bordRight);
} }
public boolean isTopBorderModified() public boolean isTopBorderModified()
{ {
return isModified(bordTop); return isModified(bordTop);
@ -320,7 +319,7 @@ public final class CFRuleRecord extends StandardRecord {
{ {
setModified(modified,bordTop); setModified(modified,bordTop);
} }
public boolean isBottomBorderModified() public boolean isBottomBorderModified()
{ {
return isModified(bordBot); return isModified(bordBot);
@ -330,7 +329,7 @@ public final class CFRuleRecord extends StandardRecord {
{ {
setModified(modified,bordBot); setModified(modified,bordBot);
} }
public boolean isTopLeftBottomRightBorderModified() public boolean isTopLeftBottomRightBorderModified()
{ {
return isModified(bordTlBr); return isModified(bordTlBr);
@ -340,7 +339,7 @@ public final class CFRuleRecord extends StandardRecord {
{ {
setModified(modified,bordTlBr); setModified(modified,bordTlBr);
} }
public boolean isBottomLeftTopRightBorderModified() public boolean isBottomLeftTopRightBorderModified()
{ {
return isModified(bordBlTr); return isModified(bordBlTr);
@ -350,7 +349,7 @@ public final class CFRuleRecord extends StandardRecord {
{ {
setModified(modified,bordBlTr); setModified(modified,bordBlTr);
} }
public boolean isPatternStyleModified() public boolean isPatternStyleModified()
{ {
return isModified(pattStyle); return isModified(pattStyle);
@ -360,7 +359,7 @@ public final class CFRuleRecord extends StandardRecord {
{ {
setModified(modified,pattStyle); setModified(modified,pattStyle);
} }
public boolean isPatternColorModified() public boolean isPatternColorModified()
{ {
return isModified(pattCol); return isModified(pattCol);
@ -370,7 +369,7 @@ public final class CFRuleRecord extends StandardRecord {
{ {
setModified(modified,pattCol); setModified(modified,pattCol);
} }
public boolean isPatternBackgroundColorModified() public boolean isPatternBackgroundColorModified()
{ {
return isModified(pattBgCol); return isModified(pattBgCol);
@ -380,7 +379,7 @@ public final class CFRuleRecord extends StandardRecord {
{ {
setModified(modified,pattBgCol); setModified(modified,pattBgCol);
} }
private boolean getOptionFlag(BitField field) private boolean getOptionFlag(BitField field)
{ {
return field.isSet(field_5_options); return field.isSet(field_5_options);
@ -390,12 +389,12 @@ public final class CFRuleRecord extends StandardRecord {
{ {
field_5_options = field.setBoolean(field_5_options, flag); field_5_options = field.setBoolean(field_5_options, flag);
} }
/** /**
* get the stack of the 1st expression as a list * get the stack of the 1st expression as a list
* *
* @return list of tokens (casts stack to a list and returns it!) * @return list of tokens (casts stack to a list and returns it!)
* this method can return null is we are unable to create Ptgs from * this method can return null is we are unable to create Ptgs from
* existing excel file * existing excel file
* callers should check for null! * callers should check for null!
*/ */
@ -432,7 +431,7 @@ public final class CFRuleRecord extends StandardRecord {
private static int getFormulaSize(Formula formula) { private static int getFormulaSize(Formula formula) {
return formula.getEncodedTokenSize(); return formula.getEncodedTokenSize();
} }
/** /**
* called by the class that is responsible for writing this sucker. * called by the class that is responsible for writing this sucker.
* Subclasses should implement this so that their data is passed back in a * Subclasses should implement this so that their data is passed back in a
@ -441,30 +440,30 @@ public final class CFRuleRecord extends StandardRecord {
* @param out the stream to write to * @param out the stream to write to
*/ */
public void serialize(LittleEndianOutput out) { public void serialize(LittleEndianOutput out) {
int formula1Len=getFormulaSize(field_17_formula1); int formula1Len=getFormulaSize(field_17_formula1);
int formula2Len=getFormulaSize(field_18_formula2); int formula2Len=getFormulaSize(field_18_formula2);
out.writeByte(field_1_condition_type); out.writeByte(field_1_condition_type);
out.writeByte(field_2_comparison_operator); out.writeByte(field_2_comparison_operator);
out.writeShort(formula1Len); out.writeShort(formula1Len);
out.writeShort(formula2Len); out.writeShort(formula2Len);
out.writeInt(field_5_options); out.writeInt(field_5_options);
out.writeShort(field_6_not_used); out.writeShort(field_6_not_used);
if (containsFontFormattingBlock()) { if (containsFontFormattingBlock()) {
byte[] fontFormattingRawRecord = fontFormatting.getRawRecord(); byte[] fontFormattingRawRecord = fontFormatting.getRawRecord();
out.write(fontFormattingRawRecord); out.write(fontFormattingRawRecord);
} }
if (containsBorderFormattingBlock()) { if (containsBorderFormattingBlock()) {
borderFormatting.serialize(out); borderFormatting.serialize(out);
} }
if (containsPatternFormattingBlock()) { if (containsPatternFormattingBlock()) {
patternFormatting.serialize(out); patternFormatting.serialize(out);
} }
field_17_formula1.serializeTokens(out); field_17_formula1.serializeTokens(out);
field_18_formula2.serializeTokens(out); field_18_formula2.serializeTokens(out);
} }
@ -499,7 +498,7 @@ public final class CFRuleRecord extends StandardRecord {
} }
return buffer.toString(); return buffer.toString();
} }
public Object clone() { public Object clone() {
CFRuleRecord rec = new CFRuleRecord(field_1_condition_type, field_2_comparison_operator); CFRuleRecord rec = new CFRuleRecord(field_1_condition_type, field_2_comparison_operator);
rec.field_5_options = field_5_options; rec.field_5_options = field_5_options;
@ -524,7 +523,7 @@ public final class CFRuleRecord extends StandardRecord {
* this call will produce the wrong results if the formula contains any cell references * this call will produce the wrong results if the formula contains any cell references
* One approach might be to apply the inverse of SharedFormulaRecord.convertSharedFormulas(Stack, int, int) * One approach might be to apply the inverse of SharedFormulaRecord.convertSharedFormulas(Stack, int, int)
* Note - two extra parameters (rowIx & colIx) will be required. They probably come from one of the Region objects. * Note - two extra parameters (rowIx & colIx) will be required. They probably come from one of the Region objects.
* *
* @return <code>null</code> if <tt>formula</tt> was null. * @return <code>null</code> if <tt>formula</tt> was null.
*/ */
private static Ptg[] parseFormula(String formula, HSSFSheet sheet) { private static Ptg[] parseFormula(String formula, HSSFSheet sheet) {

View File

@ -18,7 +18,6 @@
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.HexDump; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.LittleEndianOutput;
/** /**

View File

@ -17,7 +17,6 @@
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;

View File

@ -19,7 +19,6 @@ package org.apache.poi.hssf.record;
import org.apache.poi.hssf.util.CellRangeAddress8Bit; import org.apache.poi.hssf.util.CellRangeAddress8Bit;
import org.apache.poi.util.HexDump; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.LittleEndianOutput;
/** /**
@ -59,7 +58,7 @@ public final class SelectionRecord extends StandardRecord {
field_3_col_active_cell = in.readShort(); field_3_col_active_cell = in.readShort();
field_4_active_cell_ref_index = in.readShort(); field_4_active_cell_ref_index = in.readShort();
int field_5_num_refs = in.readUShort(); int field_5_num_refs = in.readUShort();
field_6_refs = new CellRangeAddress8Bit[field_5_num_refs]; field_6_refs = new CellRangeAddress8Bit[field_5_num_refs];
for (int i = 0; i < field_6_refs.length; i++) { for (int i = 0; i < field_6_refs.length; i++) {
field_6_refs[i] = new CellRangeAddress8Bit(in); field_6_refs[i] = new CellRangeAddress8Bit(in);
@ -141,7 +140,7 @@ public final class SelectionRecord extends StandardRecord {
return sb.toString(); return sb.toString();
} }
protected int getDataSize() { protected int getDataSize() {
return 9 // 1 byte + 4 shorts return 9 // 1 byte + 4 shorts
+ CellRangeAddress8Bit.getEncodedSize(field_6_refs.length); + CellRangeAddress8Bit.getEncodedSize(field_6_refs.length);
} }
public void serialize(LittleEndianOutput out) { public void serialize(LittleEndianOutput out) {

View File

@ -17,7 +17,6 @@
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import org.apache.poi.hssf.record.formula.Area3DPtg; import org.apache.poi.hssf.record.formula.Area3DPtg;
@ -26,7 +25,6 @@ import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.hssf.record.formula.Ref3DPtg; import org.apache.poi.hssf.record.formula.Ref3DPtg;
import org.apache.poi.hssf.record.formula.RefPtg; import org.apache.poi.hssf.record.formula.RefPtg;
import org.apache.poi.util.HexDump; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianByteArrayInputStream; import org.apache.poi.util.LittleEndianByteArrayInputStream;
import org.apache.poi.util.LittleEndianInput; import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.LittleEndianOutput;
@ -37,6 +35,7 @@ import org.apache.poi.util.LittleEndianOutputStream;
*/ */
public abstract class SubRecord { public abstract class SubRecord {
protected SubRecord() { protected SubRecord() {
// no fields to initialise
} }
public static SubRecord createSubRecord(LittleEndianInput in) { public static SubRecord createSubRecord(LittleEndianInput in) {
@ -78,8 +77,8 @@ public abstract class SubRecord {
public abstract void serialize(LittleEndianOutput out); public abstract void serialize(LittleEndianOutput out);
public abstract Object clone(); public abstract Object clone();
private static final class UnknownSubRecord extends SubRecord { private static final class UnknownSubRecord extends SubRecord {
private final int _sid; private final int _sid;
@ -118,7 +117,7 @@ public abstract class SubRecord {
private static final class LbsDataSubRecord extends SubRecord { private static final class LbsDataSubRecord extends SubRecord {
public static final int sid = 0x0013; public static final int sid = 0x0013;
private int _unknownShort1; private int _unknownShort1;
private int _unknownInt4; private int _unknownInt4;
private Ptg _linkPtg; private Ptg _linkPtg;
@ -137,8 +136,8 @@ public abstract class SubRecord {
if (linkSize > 0) { if (linkSize > 0) {
int formulaSize = in.readUShort(); int formulaSize = in.readUShort();
_unknownInt4 = in.readInt(); _unknownInt4 = in.readInt();
byte[] buf = new byte[formulaSize]; byte[] buf = new byte[formulaSize];
in.readFully(buf); in.readFully(buf);
_linkPtg = readRefPtg(buf); _linkPtg = readRefPtg(buf);
@ -152,7 +151,7 @@ public abstract class SubRecord {
default: default:
throw new RecordFormatException("Unexpected leftover bytes"); throw new RecordFormatException("Unexpected leftover bytes");
} }
} else { } else {
_unknownInt4 = 0; _unknownInt4 = 0;
_linkPtg = null; _linkPtg = null;
@ -165,11 +164,11 @@ public abstract class SubRecord {
_comboStyle = in.readUShort(); _comboStyle = in.readUShort();
_lineCount = in.readUShort(); _lineCount = in.readUShort();
_unknownShort13 = in.readUShort(); _unknownShort13 = in.readUShort();
} }
protected int getDataSize() { protected int getDataSize() {
int result = 2; // 2 initial shorts int result = 2; // 2 initial shorts
// optional link formula // optional link formula
if (_linkPtg != null) { if (_linkPtg != null) {
result += 2; // encoded Ptg size result += 2; // encoded Ptg size

View File

@ -17,7 +17,6 @@
package org.apache.poi.hssf.record.formula; package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.record.UnicodeString;
import org.apache.poi.hssf.record.constant.ConstantValueParser; import org.apache.poi.hssf.record.constant.ConstantValueParser;
import org.apache.poi.hssf.record.constant.ErrorConstant; import org.apache.poi.hssf.record.constant.ErrorConstant;
import org.apache.poi.util.LittleEndianInput; import org.apache.poi.util.LittleEndianInput;
@ -25,20 +24,20 @@ import org.apache.poi.util.LittleEndianOutput;
/** /**
* ArrayPtg - handles arrays * ArrayPtg - handles arrays
* *
* The ArrayPtg is a little weird, the size of the Ptg when parsing initially only * The ArrayPtg is a little weird, the size of the Ptg when parsing initially only
* includes the Ptg sid and the reserved bytes. The next Ptg in the expression then follows. * includes the Ptg sid and the reserved bytes. The next Ptg in the expression then follows.
* It is only after the "size" of all the Ptgs is met, that the ArrayPtg data is actually * It is only after the "size" of all the Ptgs is met, that the ArrayPtg data is actually
* held after this. So Ptg.createParsedExpression keeps track of the number of * held after this. So Ptg.createParsedExpression keeps track of the number of
* ArrayPtg elements and need to parse the data upto the FORMULA record size. * ArrayPtg elements and need to parse the data upto the FORMULA record size.
* *
* @author Jason Height (jheight at chariot dot net dot au) * @author Jason Height (jheight at chariot dot net dot au)
*/ */
public final class ArrayPtg extends Ptg { public final class ArrayPtg extends Ptg {
public static final byte sid = 0x20; public static final byte sid = 0x20;
private static final int RESERVED_FIELD_LEN = 7; private static final int RESERVED_FIELD_LEN = 7;
/** /**
* The size of the plain tArray token written within the standard formula tokens * The size of the plain tArray token written within the standard formula tokens
* (not including the data which comes after all formula tokens) * (not including the data which comes after all formula tokens)
*/ */
@ -48,7 +47,7 @@ public final class ArrayPtg extends Ptg {
// TODO - fix up field visibility and subclasses // TODO - fix up field visibility and subclasses
private final byte[] field_1_reserved; private final byte[] field_1_reserved;
// data from these fields comes after the Ptg data of all tokens in current formula // data from these fields comes after the Ptg data of all tokens in current formula
private int token_1_columns; private int token_1_columns;
private short token_2_rows; private short token_2_rows;
@ -78,7 +77,7 @@ public final class ArrayPtg extends Ptg {
vv[getValueIndex(c, r)] = rowData[c]; vv[getValueIndex(c, r)] = rowData[c];
} }
} }
token_3_arrayValues = vv; token_3_arrayValues = vv;
field_1_reserved = DEFAULT_RESERVED_DATA; field_1_reserved = DEFAULT_RESERVED_DATA;
} }
@ -98,13 +97,13 @@ public final class ArrayPtg extends Ptg {
} }
return result; return result;
} }
public boolean isBaseToken() { public boolean isBaseToken() {
return false; return false;
} }
/** /**
* Read in the actual token (array) values. This occurs * Read in the actual token (array) values. This occurs
* AFTER the last Ptg in the expression. * AFTER the last Ptg in the expression.
* See page 304-305 of Excel97-2007BinaryFileFormat(xls)Specification.pdf * See page 304-305 of Excel97-2007BinaryFileFormat(xls)Specification.pdf
*/ */
@ -116,10 +115,10 @@ public final class ArrayPtg extends Ptg {
//Which is not explicitly documented. //Which is not explicitly documented.
nColumns++; nColumns++;
nRows++; nRows++;
token_1_columns = nColumns; token_1_columns = nColumns;
token_2_rows = nRows; token_2_rows = nRows;
int totalCount = nRows * nColumns; int totalCount = nRows * nColumns;
token_3_arrayValues = ConstantValueParser.parse(in, totalCount); token_3_arrayValues = ConstantValueParser.parse(in, totalCount);
} }
@ -143,11 +142,11 @@ public final class ArrayPtg extends Ptg {
*/ */
/* package */ int getValueIndex(int colIx, int rowIx) { /* package */ int getValueIndex(int colIx, int rowIx) {
if(colIx < 0 || colIx >= token_1_columns) { if(colIx < 0 || colIx >= token_1_columns) {
throw new IllegalArgumentException("Specified colIx (" + colIx throw new IllegalArgumentException("Specified colIx (" + colIx
+ ") is outside the allowed range (0.." + (token_1_columns-1) + ")"); + ") is outside the allowed range (0.." + (token_1_columns-1) + ")");
} }
if(rowIx < 0 || rowIx >= token_2_rows) { if(rowIx < 0 || rowIx >= token_2_rows) {
throw new IllegalArgumentException("Specified rowIx (" + rowIx throw new IllegalArgumentException("Specified rowIx (" + rowIx
+ ") is outside the allowed range (0.." + (token_2_rows-1) + ")"); + ") is outside the allowed range (0.." + (token_2_rows-1) + ")");
} }
return rowIx * token_1_columns + colIx; return rowIx * token_1_columns + colIx;
@ -176,7 +175,7 @@ public final class ArrayPtg extends Ptg {
/** This size includes the size of the array Ptg plus the Array Ptg Token value size*/ /** This size includes the size of the array Ptg plus the Array Ptg Token value size*/
public int getSize() { public int getSize() {
return PLAIN_TOKEN_SIZE return PLAIN_TOKEN_SIZE
// data written after the all tokens: // data written after the all tokens:
+ 1 + 2 // column, row + 1 + 2 // column, row
+ ConstantValueParser.getEncodedSize(token_3_arrayValues); + ConstantValueParser.getEncodedSize(token_3_arrayValues);
@ -200,7 +199,7 @@ public final class ArrayPtg extends Ptg {
b.append("}"); b.append("}");
return b.toString(); return b.toString();
} }
private static String getConstantText(Object o) { private static String getConstantText(Object o) {
if (o == null) { if (o == null) {
@ -220,7 +219,7 @@ public final class ArrayPtg extends Ptg {
} }
throw new IllegalArgumentException("Unexpected constant class (" + o.getClass().getName() + ")"); throw new IllegalArgumentException("Unexpected constant class (" + o.getClass().getName() + ")");
} }
public byte getDefaultOperandClass() { public byte getDefaultOperandClass() {
return Ptg.CLASS_ARRAY; return Ptg.CLASS_ARRAY;
} }

View File

@ -22,11 +22,10 @@ import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndianInput; import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.LittleEndianOutput;
import org.apache.poi.ss.SpreadsheetVersion;
/** /**
* ReferencePtgBase - handles references (such as A1, A2, IA4) * ReferencePtgBase - handles references (such as A1, A2, IA4)
* *
* @author Andrew C. Oliver (acoliver@apache.org) * @author Andrew C. Oliver (acoliver@apache.org)
* @author Jason Height (jheight at chariot dot net dot au) * @author Jason Height (jheight at chariot dot net dot au)
*/ */

View File

@ -19,7 +19,6 @@ package org.apache.poi.hssf.record.formula.atp;
import org.apache.poi.hssf.record.formula.eval.BoolEval; import org.apache.poi.hssf.record.formula.eval.BoolEval;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.record.formula.eval.EvaluationException; import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.OperandResolver; import org.apache.poi.hssf.record.formula.eval.OperandResolver;
import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.eval.ValueEval;

View File

@ -22,15 +22,14 @@ import java.util.GregorianCalendar;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.record.formula.eval.EvaluationException; import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.OperandResolver; import org.apache.poi.hssf.record.formula.eval.OperandResolver;
import org.apache.poi.hssf.record.formula.eval.StringEval; import org.apache.poi.hssf.record.formula.eval.StringEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.record.formula.functions.FreeRefFunction; import org.apache.poi.hssf.record.formula.functions.FreeRefFunction;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.formula.EvaluationWorkbook; import org.apache.poi.ss.formula.EvaluationWorkbook;
import org.apache.poi.ss.usermodel.DateUtil;
/** /**
* Implementation of Excel 'Analysis ToolPak' function YEARFRAC()<br/> * Implementation of Excel 'Analysis ToolPak' function YEARFRAC()<br/>
* *

View File

@ -17,13 +17,8 @@
package org.apache.poi.hssf.usermodel; package org.apache.poi.hssf.usermodel;
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherClientAnchorRecord;
import org.apache.poi.ddf.EscherChildAnchorRecord;
public class HSSFChildAnchor public final class HSSFChildAnchor extends HSSFAnchor {
extends HSSFAnchor
{
public HSSFChildAnchor() public HSSFChildAnchor()
{ {
} }
@ -50,5 +45,4 @@ public class HSSFChildAnchor
{ {
return dy1 > dy2; return dy1 > dy2;
} }
} }

View File

@ -14,54 +14,50 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.usermodel; package org.apache.poi.hssf.usermodel;
import org.apache.poi.ss.usermodel.CreationHelper; import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Sheet;
public class HSSFCreationHelper implements CreationHelper { public class HSSFCreationHelper implements CreationHelper {
private HSSFWorkbook workbook; private HSSFWorkbook workbook;
private HSSFDataFormat dataFormat; private HSSFDataFormat dataFormat;
HSSFCreationHelper(HSSFWorkbook wb) { HSSFCreationHelper(HSSFWorkbook wb) {
workbook = wb; workbook = wb;
// Create the things we only ever need one of // Create the things we only ever need one of
dataFormat = new HSSFDataFormat(workbook.getWorkbook()); dataFormat = new HSSFDataFormat(workbook.getWorkbook());
} }
/**
* Creates a new HSSFRichTextString for you.
*/
public HSSFRichTextString createRichTextString(String text) { public HSSFRichTextString createRichTextString(String text) {
return new HSSFRichTextString(text); return new HSSFRichTextString(text);
} }
public HSSFDataFormat createDataFormat() { public HSSFDataFormat createDataFormat() {
return dataFormat; return dataFormat;
} }
public HSSFHyperlink createHyperlink(int type) { public HSSFHyperlink createHyperlink(int type) {
return new HSSFHyperlink(type); return new HSSFHyperlink(type);
} }
/** /**
* Creates a HSSFFormulaEvaluator, the object that evaluates formula cells. * Creates a HSSFFormulaEvaluator, the object that evaluates formula cells.
* *
* @return a HSSFFormulaEvaluator instance * @return a HSSFFormulaEvaluator instance
*/ */
public HSSFFormulaEvaluator createFormulaEvaluator(){ public HSSFFormulaEvaluator createFormulaEvaluator(){
return new HSSFFormulaEvaluator(workbook); return new HSSFFormulaEvaluator(workbook);
} }
/**
* Creates a HSSFClientAnchor. Use this object to position drawing object in a sheet
*
* @return a HSSFClientAnchor instance
* @see org.apache.poi.ss.usermodel.Drawing
*/
public HSSFClientAnchor createClientAnchor(){
return new HSSFClientAnchor();
}
/**
* Creates a HSSFClientAnchor. Use this object to position drawing object in a sheet
*
* @return a HSSFClientAnchor instance
* @see org.apache.poi.ss.usermodel.Drawing
*/
public HSSFClientAnchor createClientAnchor(){
return new HSSFClientAnchor();
}
} }

View File

@ -17,21 +17,11 @@
package org.apache.poi.hssf.usermodel; package org.apache.poi.hssf.usermodel;
import org.apache.poi.ss.usermodel.DataFormatter;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.FieldPosition;
import java.text.Format; import java.text.Format;
import java.text.ParsePosition;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date; import org.apache.poi.ss.usermodel.DataFormatter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** /**
* HSSFDataFormatter contains methods for formatting the value stored in an * HSSFDataFormatter contains methods for formatting the value stored in an
@ -73,7 +63,6 @@ import java.util.regex.Pattern;
* cell's data format string. * cell's data format string.
* *
* @author James May (james dot may at fmr dot com) * @author James May (james dot may at fmr dot com)
*
*/ */
public final class HSSFDataFormatter extends DataFormatter { public final class HSSFDataFormatter extends DataFormatter {

View File

@ -19,9 +19,6 @@ package org.apache.poi.hssf.usermodel;
import org.apache.poi.ss.usermodel.RichTextString; import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
/** /**
* A textbox is a shape that may hold a rich text string. * A textbox is a shape that may hold a rich text string.
* *

View File

@ -21,78 +21,69 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.DocumentNode; import org.apache.poi.poifs.filesystem.DocumentNode;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
/** /**
* A lister of the entries in POIFS files. * A lister of the entries in POIFS files.
* *
* Much simpler than {@link POIFSViewer} * Much simpler than {@link POIFSViewer}
*/ */
public class POIFSLister { public class POIFSLister {
/** /**
* Display the entries of multiple POIFS files * Display the entries of multiple POIFS files
* *
* @param args the names of the files to be displayed * @param args the names of the files to be displayed
*/ */
public static void main(final String args[]) throws IOException { public static void main(final String args[]) throws IOException {
if (args.length == 0) if (args.length == 0) {
{ System.err.println("Must specify at least one file to view");
System.err.println("Must specify at least one file to view"); System.exit(1);
System.exit(1); }
}
boolean withSizes = false; boolean withSizes = false;
for (int j = 0; j < args.length; j++) { for (int j = 0; j < args.length; j++) {
if(args[j].equalsIgnoreCase("-size") || if (args[j].equalsIgnoreCase("-size") || args[j].equalsIgnoreCase("-sizes")) {
args[j].equalsIgnoreCase("-sizes")) { withSizes = true;
withSizes = true; } else {
} else { viewFile(args[j], withSizes);
viewFile(args[j], withSizes); }
} }
} }
}
public static void viewFile(final String filename, boolean withSizes) throws IOException public static void viewFile(final String filename, boolean withSizes) throws IOException {
{ POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename));
POIFSFileSystem fs = new POIFSFileSystem( displayDirectory(fs.getRoot(), "", withSizes);
new FileInputStream(filename) }
);
displayDirectory(fs.getRoot(), "", withSizes); public static void displayDirectory(DirectoryNode dir, String indent, boolean withSizes) {
} System.out.println(indent + dir.getName() + " -");
String newIndent = indent + " ";
public static void displayDirectory(DirectoryNode dir, String indent, boolean withSizes) {
System.out.println(indent + dir.getName() + " -"); boolean hadChildren = false;
String newIndent = indent + " "; for (Iterator it = dir.getEntries(); it.hasNext();) {
hadChildren = true;
boolean hadChildren = false; Object entry = it.next();
for(Iterator it = dir.getEntries(); it.hasNext(); ) { if (entry instanceof DirectoryNode) {
hadChildren = true; displayDirectory((DirectoryNode) entry, newIndent, withSizes);
Object entry = it.next(); } else {
if(entry instanceof DirectoryNode) { DocumentNode doc = (DocumentNode) entry;
displayDirectory((DirectoryNode)entry, newIndent, withSizes); String name = doc.getName();
} else { String size = "";
DocumentNode doc = (DocumentNode)entry; if (name.charAt(0) < 10) {
String name = doc.getName(); String altname = "(0x0" + (int) name.charAt(0) + ")" + name.substring(1);
String size = ""; name = name.substring(1) + " <" + altname + ">";
if(name.charAt(0) < 10) { }
String altname = "(0x0" + (int)name.charAt(0) + ")" + name.substring(1); if (withSizes) {
name = name.substring(1) + " <" + altname + ">"; size = " [" + doc.getSize() + " / 0x" + Integer.toHexString(doc.getSize())
} + "]";
if(withSizes) { }
size = " [" + System.out.println(newIndent + name + size);
doc.getSize() + " / 0x" + }
Integer.toHexString(doc.getSize()) + }
"]"; if (!hadChildren) {
} System.out.println(newIndent + "(no children)");
System.out.println(newIndent + name + size); }
} }
} }
if(!hadChildren) {
System.out.println(newIndent + "(no children)");
}
}
}

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,44 +14,35 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.poifs.property; package org.apache.poi.poifs.property;
import java.util.*;
import java.io.IOException; import java.io.IOException;
import java.util.*;
import org.apache.poi.poifs.storage.SmallDocumentBlock;
/** /**
* Directory property * Directory property
* *
* @author Marc Johnson (mjohnson at apache dot org) * @author Marc Johnson (mjohnson at apache dot org)
*/ */
public class DirectoryProperty extends Property implements Parent { // TODO - fix instantiable superclass
public class DirectoryProperty /** List of Property instances */
extends Property private List<Property> _children;
implements Parent
{
// List of Property instances /** set of children's names */
private List _children; private Set<String> _children_names;
// set of children's names
private Set _children_names;
/** /**
* Default constructor * Default constructor
* *
* @param name the name of the directory * @param name the name of the directory
*/ */
public DirectoryProperty(String name) public DirectoryProperty(String name)
{ {
super(); super();
_children = new ArrayList(); _children = new ArrayList<Property>();
_children_names = new HashSet(); _children_names = new HashSet<String>();
setName(name); setName(name);
setSize(0); setSize(0);
setPropertyType(PropertyConstants.DIRECTORY_TYPE); setPropertyType(PropertyConstants.DIRECTORY_TYPE);
@ -67,13 +57,12 @@ public class DirectoryProperty
* @param array byte data * @param array byte data
* @param offset offset into byte data * @param offset offset into byte data
*/ */
protected DirectoryProperty(final int index, final byte [] array, protected DirectoryProperty(final int index, final byte [] array,
final int offset) final int offset)
{ {
super(index, array, offset); super(index, array, offset);
_children = new ArrayList(); _children = new ArrayList<Property>();
_children_names = new HashSet(); _children_names = new HashSet<String>();
} }
/** /**
@ -84,8 +73,7 @@ public class DirectoryProperty
* *
* @return true if the name change could be made, else false * @return true if the name change could be made, else false
*/ */
public boolean changeName(Property property, String newName)
public boolean changeName(final Property property, final String newName)
{ {
boolean result; boolean result;
String oldName = property.getName(); String oldName = property.getName();
@ -116,8 +104,7 @@ public class DirectoryProperty
* *
* @return true if the Property could be deleted, else false * @return true if the Property could be deleted, else false
*/ */
public boolean deleteChild(Property property)
public boolean deleteChild(final Property property)
{ {
boolean result = _children.remove(property); boolean result = _children.remove(property);
@ -128,9 +115,7 @@ public class DirectoryProperty
return result; return result;
} }
public static class PropertyComparator public static class PropertyComparator implements Comparator<Property> {
implements Comparator
{
/** /**
* Object equality, implemented as object identity * Object equality, implemented as object identity
@ -139,7 +124,6 @@ public class DirectoryProperty
* *
* @return true if identical, else false * @return true if identical, else false
*/ */
public boolean equals(Object o) public boolean equals(Object o)
{ {
return this == o; return this == o;
@ -160,12 +144,11 @@ public class DirectoryProperty
* zero if o1 == o2, * zero if o1 == o2,
* positive value if o1 > o2. * positive value if o1 > o2.
*/ */
public int compare(Property o1, Property o2)
public int compare(Object o1, Object o2)
{ {
String VBA_PROJECT = "_VBA_PROJECT"; String VBA_PROJECT = "_VBA_PROJECT";
String name1 = (( Property ) o1).getName(); String name1 = o1.getName();
String name2 = (( Property ) o2).getName(); String name2 = o2.getName();
int result = name1.length() - name2.length(); int result = name1.length() - name2.length();
if (result == 0) if (result == 0)
@ -200,14 +183,11 @@ public class DirectoryProperty
} }
return result; return result;
} }
} // end private class PropertyComparator }
/* ********** START extension of Property ********** */
/** /**
* @return true if a directory type Property * @return true if a directory type Property
*/ */
public boolean isDirectory() public boolean isDirectory()
{ {
return true; return true;
@ -217,13 +197,11 @@ public class DirectoryProperty
* Perform whatever activities need to be performed prior to * Perform whatever activities need to be performed prior to
* writing * writing
*/ */
protected void preWrite() protected void preWrite()
{ {
if (_children.size() > 0) if (_children.size() > 0)
{ {
Property[] children = Property[] children = _children.toArray(new Property[ 0 ]);
( Property [] ) _children.toArray(new Property[ 0 ]);
Arrays.sort(children, new PropertyComparator()); Arrays.sort(children, new PropertyComparator());
int midpoint = children.length / 2; int midpoint = children.length / 2;
@ -259,17 +237,13 @@ public class DirectoryProperty
} }
} }
/* ********** END extension of Property ********** */
/* ********** START implementation of Parent ********** */
/** /**
* Get an iterator over the children of this Parent; all elements * Get an iterator over the children of this Parent; all elements
* are instances of Property. * are instances of Property.
* *
* @return Iterator of children; may refer to an empty collection * @return Iterator of children; may refer to an empty collection
*/ */
public Iterator<Property> getChildren()
public Iterator getChildren()
{ {
return _children.iterator(); return _children.iterator();
} }
@ -282,7 +256,6 @@ public class DirectoryProperty
* @exception IOException if we already have a child with the same * @exception IOException if we already have a child with the same
* name * name
*/ */
public void addChild(final Property property) public void addChild(final Property property)
throws IOException throws IOException
{ {
@ -295,7 +268,4 @@ public class DirectoryProperty
_children_names.add(name); _children_names.add(name);
_children.add(property); _children.add(property);
} }
}
/* ********** END implementation of Parent ********** */
} // end public class DirectoryProperty

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,20 +14,19 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.poifs.property; package org.apache.poi.poifs.property;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList;
import java.util.*; import java.util.List;
import java.util.Stack;
import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.poifs.filesystem.BATManaged; import org.apache.poi.poifs.filesystem.BATManaged;
import org.apache.poi.poifs.storage.BlockWritable; import org.apache.poi.poifs.storage.BlockWritable;
import org.apache.poi.poifs.storage.PropertyBlock; import org.apache.poi.poifs.storage.PropertyBlock;
import org.apache.poi.poifs.storage.RawDataBlock;
import org.apache.poi.poifs.storage.RawDataBlockList; import org.apache.poi.poifs.storage.RawDataBlockList;
/** /**
@ -38,22 +36,15 @@ import org.apache.poi.poifs.storage.RawDataBlockList;
* *
* @author Marc Johnson (mjohnson at apache dot org) * @author Marc Johnson (mjohnson at apache dot org)
*/ */
public final class PropertyTable implements BATManaged, BlockWritable {
public class PropertyTable
implements BATManaged, BlockWritable
{
private int _start_block; private int _start_block;
private List _properties; private List<Property> _properties;
private BlockWritable[] _blocks; private BlockWritable[] _blocks;
/**
* Default constructor
*/
public PropertyTable() public PropertyTable()
{ {
_start_block = POIFSConstants.END_OF_CHAIN; _start_block = POIFSConstants.END_OF_CHAIN;
_properties = new ArrayList(); _properties = new ArrayList<Property>();
addProperty(new RootProperty()); addProperty(new RootProperty());
_blocks = null; _blocks = null;
} }
@ -69,7 +60,6 @@ public class PropertyTable
* @exception IOException if anything goes wrong (which should be * @exception IOException if anything goes wrong (which should be
* a result of the input being NFG) * a result of the input being NFG)
*/ */
public PropertyTable(final int startBlock, public PropertyTable(final int startBlock,
final RawDataBlockList blockList) final RawDataBlockList blockList)
throws IOException throws IOException
@ -87,8 +77,7 @@ public class PropertyTable
* *
* @param property the new Property to manage * @param property the new Property to manage
*/ */
public void addProperty(Property property)
public void addProperty(final Property property)
{ {
_properties.add(property); _properties.add(property);
} }
@ -98,7 +87,6 @@ public class PropertyTable
* *
* @param property the Property to be removed * @param property the Property to be removed
*/ */
public void removeProperty(final Property property) public void removeProperty(final Property property)
{ {
_properties.remove(property); _properties.remove(property);
@ -109,7 +97,6 @@ public class PropertyTable
* *
* @return the root property * @return the root property
*/ */
public RootProperty getRoot() public RootProperty getRoot()
{ {
@ -120,11 +107,9 @@ public class PropertyTable
/** /**
* Prepare to be written * Prepare to be written
*/ */
public void preWrite() public void preWrite()
{ {
Property[] properties = Property[] properties = _properties.toArray(new Property[ 0 ]);
( Property [] ) _properties.toArray(new Property[ 0 ]);
// give each property its index // give each property its index
for (int k = 0; k < properties.length; k++) for (int k = 0; k < properties.length; k++)
@ -147,7 +132,6 @@ public class PropertyTable
* *
* @return start block index * @return start block index
*/ */
public int getStartBlock() public int getStartBlock()
{ {
return _start_block; return _start_block;
@ -164,12 +148,12 @@ public class PropertyTable
// property has no children // property has no children
return; return;
} }
Stack children = new Stack(); Stack<Property> children = new Stack<Property>();
children.push(_properties.get(index)); children.push(_properties.get(index));
while (!children.empty()) while (!children.empty())
{ {
Property property = ( Property ) children.pop(); Property property = children.pop();
root.addChild(property); root.addChild(property);
if (property.isDirectory()) if (property.isDirectory())
@ -189,14 +173,11 @@ public class PropertyTable
} }
} }
/* ********** START implementation of BATManaged ********** */
/** /**
* Return the number of BigBlock's this instance uses * Return the number of BigBlock's this instance uses
* *
* @return count of BigBlock instances * @return count of BigBlock instances
*/ */
public int countBlocks() public int countBlocks()
{ {
return (_blocks == null) ? 0 return (_blocks == null) ? 0
@ -209,15 +190,11 @@ public class PropertyTable
* @param index index into the array of BigBlock instances making * @param index index into the array of BigBlock instances making
* up the the filesystem * up the the filesystem
*/ */
public void setStartBlock(final int index) public void setStartBlock(final int index)
{ {
_start_block = index; _start_block = index;
} }
/* ********** END implementation of BATManaged ********** */
/* ********** START implementation of BlockWritable ********** */
/** /**
* Write the storage to an OutputStream * Write the storage to an OutputStream
* *
@ -227,7 +204,6 @@ public class PropertyTable
* @exception IOException on problems writing to the specified * @exception IOException on problems writing to the specified
* stream * stream
*/ */
public void writeBlocks(final OutputStream stream) public void writeBlocks(final OutputStream stream)
throws IOException throws IOException
{ {
@ -239,7 +215,4 @@ public class PropertyTable
} }
} }
} }
}
/* ********** END implementation of BlockWritable ********** */
} // end public class PropertyTable

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,14 +14,9 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.poifs.property; package org.apache.poi.poifs.property;
import java.util.*;
import java.io.IOException;
import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.poifs.storage.SmallDocumentBlock; import org.apache.poi.poifs.storage.SmallDocumentBlock;
@ -31,14 +25,7 @@ import org.apache.poi.poifs.storage.SmallDocumentBlock;
* *
* @author Marc Johnson (mjohnson at apache dot org) * @author Marc Johnson (mjohnson at apache dot org)
*/ */
public final class RootProperty extends DirectoryProperty {
public class RootProperty
extends DirectoryProperty
{
/**
* Default constructor
*/
RootProperty() RootProperty()
{ {
@ -57,7 +44,6 @@ public class RootProperty
* @param array byte data * @param array byte data
* @param offset offset into byte data * @param offset offset into byte data
*/ */
protected RootProperty(final int index, final byte [] array, protected RootProperty(final int index, final byte [] array,
final int offset) final int offset)
{ {
@ -69,10 +55,8 @@ public class RootProperty
* *
* @param size size in terms of small blocks * @param size size in terms of small blocks
*/ */
public void setSize(int size) public void setSize(int size)
{ {
super.setSize(SmallDocumentBlock.calcSize(size)); super.setSize(SmallDocumentBlock.calcSize(size));
} }
} // end public class RootProperty }

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,6 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.poifs.storage; package org.apache.poi.poifs.storage;
@ -26,7 +24,6 @@ import java.util.Arrays;
import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.util.IntegerField; import org.apache.poi.util.IntegerField;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.LittleEndianConsts;
/** /**
@ -35,10 +32,7 @@ import org.apache.poi.util.LittleEndianConsts;
* *
* @author Marc Johnson (mjohnson at apache dot org) * @author Marc Johnson (mjohnson at apache dot org)
*/ */
public final class BATBlock extends BigBlock {
public class BATBlock
extends BigBlock
{
private static final int _entries_per_block = private static final int _entries_per_block =
POIFSConstants.BIG_BLOCK_SIZE / LittleEndianConsts.INT_SIZE; POIFSConstants.BIG_BLOCK_SIZE / LittleEndianConsts.INT_SIZE;
private static final int _entries_per_xbat_block = _entries_per_block private static final int _entries_per_xbat_block = _entries_per_block

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,6 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.poifs.storage; package org.apache.poi.poifs.storage;
@ -43,9 +41,7 @@ import org.apache.poi.util.LittleEndianConsts;
* *
* @author Marc Johnson (mjohnson at apache dot org) * @author Marc Johnson (mjohnson at apache dot org)
*/ */
public final class BlockAllocationTableReader {
public class BlockAllocationTableReader
{
private IntList _entries; private IntList _entries;
/** /**
@ -154,12 +150,6 @@ public class BlockAllocationTableReader
setEntries(blocks, raw_block_list); setEntries(blocks, raw_block_list);
} }
/**
* Constructor BlockAllocationTableReader
*
*
*/
BlockAllocationTableReader() BlockAllocationTableReader()
{ {
_entries = new IntList(); _entries = new IntList();
@ -177,17 +167,16 @@ public class BlockAllocationTableReader
* *
* @exception IOException if there is a problem acquiring the blocks * @exception IOException if there is a problem acquiring the blocks
*/ */
ListManagedBlock [] fetchBlocks(final int startBlock, ListManagedBlock [] fetchBlocks(final int startBlock,
final int headerPropertiesStartBlock, final int headerPropertiesStartBlock,
final BlockList blockList) final BlockList blockList)
throws IOException throws IOException
{ {
List blocks = new ArrayList(); List<ListManagedBlock> blocks = new ArrayList<ListManagedBlock>();
int currentBlock = startBlock; int currentBlock = startBlock;
boolean firstPass = true; boolean firstPass = true;
ListManagedBlock dataBlock = null; ListManagedBlock dataBlock = null;
// Process the chain from the start to the end // Process the chain from the start to the end
// Normally we have header, data, end // Normally we have header, data, end
// Sometimes we have data, header, end // Sometimes we have data, header, end
@ -216,9 +205,8 @@ public class BlockAllocationTableReader
} }
} }
} }
return ( ListManagedBlock [] ) blocks return blocks.toArray(new ListManagedBlock[blocks.size()]);
.toArray(new ListManagedBlock[ blocks.size() ]);
} }
// methods for debugging reader // methods for debugging reader
@ -230,7 +218,6 @@ public class BlockAllocationTableReader
* *
* @return true if the specific block is used, else false * @return true if the specific block is used, else false
*/ */
boolean isUsed(final int index) boolean isUsed(final int index)
{ {
boolean rval = false; boolean rval = false;
@ -238,9 +225,8 @@ public class BlockAllocationTableReader
try try
{ {
rval = _entries.get(index) != -1; rval = _entries.get(index) != -1;
} } catch (IndexOutOfBoundsException e) {
catch (IndexOutOfBoundsException ignored) // ignored
{
} }
return rval; return rval;
} }
@ -256,7 +242,6 @@ public class BlockAllocationTableReader
* *
* @exception IOException if the current block is unused * @exception IOException if the current block is unused
*/ */
int getNextBlockIndex(final int index) int getNextBlockIndex(final int index)
throws IOException throws IOException
{ {
@ -264,10 +249,7 @@ public class BlockAllocationTableReader
{ {
return _entries.get(index); return _entries.get(index);
} }
else throw new IOException("index " + index + " is unused");
{
throw new IOException("index " + index + " is unused");
}
} }
/** /**
@ -276,10 +258,7 @@ public class BlockAllocationTableReader
* @param blocks the array of blocks containing the indices * @param blocks the array of blocks containing the indices
* @param raw_blocks the list of blocks being managed. Unused * @param raw_blocks the list of blocks being managed. Unused
* blocks will be eliminated from the list * blocks will be eliminated from the list
*
* @exception IOException
*/ */
private void setEntries(final ListManagedBlock [] blocks, private void setEntries(final ListManagedBlock [] blocks,
final BlockList raw_blocks) final BlockList raw_blocks)
throws IOException throws IOException
@ -308,5 +287,4 @@ public class BlockAllocationTableReader
} }
raw_blocks.setBAT(this); raw_blocks.setBAT(this);
} }
} // end class BlockAllocationTableReader }

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,20 +14,15 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.poifs.storage; package org.apache.poi.poifs.storage;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.*;
import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.poifs.filesystem.BATManaged; import org.apache.poi.poifs.filesystem.BATManaged;
import org.apache.poi.util.IntList; import org.apache.poi.util.IntList;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianConsts;
/** /**
* This class manages and creates the Block Allocation Table, which is * This class manages and creates the Block Allocation Table, which is
@ -45,10 +39,7 @@ import org.apache.poi.util.LittleEndianConsts;
* *
* @author Marc Johnson (mjohnson at apache dot org) * @author Marc Johnson (mjohnson at apache dot org)
*/ */
public final class BlockAllocationTableWriter implements BlockWritable, BATManaged {
public class BlockAllocationTableWriter
implements BlockWritable, BATManaged
{
private IntList _entries; private IntList _entries;
private BATBlock[] _blocks; private BATBlock[] _blocks;
private int _start_block; private int _start_block;
@ -56,7 +47,6 @@ public class BlockAllocationTableWriter
/** /**
* create a BlockAllocationTableWriter * create a BlockAllocationTableWriter
*/ */
public BlockAllocationTableWriter() public BlockAllocationTableWriter()
{ {
_start_block = POIFSConstants.END_OF_CHAIN; _start_block = POIFSConstants.END_OF_CHAIN;
@ -69,7 +59,6 @@ public class BlockAllocationTableWriter
* *
* @return start block index of BAT blocks * @return start block index of BAT blocks
*/ */
public int createBlocks() public int createBlocks()
{ {
int xbat_blocks = 0; int xbat_blocks = 0;
@ -92,11 +81,8 @@ public class BlockAllocationTableWriter
// stable ... we're OK // stable ... we're OK
break; break;
} }
else bat_blocks = calculated_bat_blocks;
{ xbat_blocks = calculated_xbat_blocks;
bat_blocks = calculated_bat_blocks;
xbat_blocks = calculated_xbat_blocks;
}
} }
int startBlock = allocateSpace(bat_blocks); int startBlock = allocateSpace(bat_blocks);
@ -112,7 +98,6 @@ public class BlockAllocationTableWriter
* *
* @return the starting index of the blocks * @return the starting index of the blocks
*/ */
public int allocateSpace(final int blockCount) public int allocateSpace(final int blockCount)
{ {
int startBlock = _entries.size(); int startBlock = _entries.size();
@ -136,7 +121,6 @@ public class BlockAllocationTableWriter
* *
* @return the starting block index * @return the starting block index
*/ */
public int getStartBlock() public int getStartBlock()
{ {
return _start_block; return _start_block;
@ -145,14 +129,11 @@ public class BlockAllocationTableWriter
/** /**
* create the BATBlocks * create the BATBlocks
*/ */
void simpleCreateBlocks() void simpleCreateBlocks()
{ {
_blocks = BATBlock.createBATBlocks(_entries.toArray()); _blocks = BATBlock.createBATBlocks(_entries.toArray());
} }
/* ********** START implementation of BlockWritable ********** */
/** /**
* Write the storage to an OutputStream * Write the storage to an OutputStream
* *
@ -162,7 +143,6 @@ public class BlockAllocationTableWriter
* @exception IOException on problems writing to the specified * @exception IOException on problems writing to the specified
* stream * stream
*/ */
public void writeBlocks(final OutputStream stream) public void writeBlocks(final OutputStream stream)
throws IOException throws IOException
{ {
@ -172,15 +152,11 @@ public class BlockAllocationTableWriter
} }
} }
/* ********** END implementation of BlockWritable ********** */
/* ********** START implementation of BATManaged ********** */
/** /**
* Return the number of BigBlock's this instance uses * Return the number of BigBlock's this instance uses
* *
* @return count of BigBlock instances * @return count of BigBlock instances
*/ */
public int countBlocks() public int countBlocks()
{ {
return _blocks.length; return _blocks.length;
@ -188,15 +164,9 @@ public class BlockAllocationTableWriter
/** /**
* Set the start block for this instance * Set the start block for this instance
*
* @param start_block
*/ */
public void setStartBlock(int start_block) public void setStartBlock(int start_block)
{ {
_start_block = start_block; _start_block = start_block;
} }
}
/* ********** END implementation of BATManaged ********** */
} // end class BlockAllocationTableWriter

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,30 +14,20 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.poifs.storage; package org.apache.poi.poifs.storage;
import java.io.*; import java.io.IOException;
import java.util.*;
/** /**
* A simple implementation of BlockList * A simple implementation of BlockList
* *
* @author Marc Johnson (mjohnson at apache dot org * @author Marc Johnson (mjohnson at apache dot org
*/ */
abstract class BlockListImpl implements BlockList {
class BlockListImpl
implements BlockList
{
private ListManagedBlock[] _blocks; private ListManagedBlock[] _blocks;
private BlockAllocationTableReader _bat; private BlockAllocationTableReader _bat;
/**
* Constructor BlockListImpl
*/
protected BlockListImpl() protected BlockListImpl()
{ {
_blocks = new ListManagedBlock[ 0 ]; _blocks = new ListManagedBlock[ 0 ];
@ -50,21 +39,17 @@ class BlockListImpl
* *
* @param blocks blocks to be managed * @param blocks blocks to be managed
*/ */
protected void setBlocks(final ListManagedBlock [] blocks) protected void setBlocks(final ListManagedBlock [] blocks)
{ {
_blocks = blocks; _blocks = blocks;
} }
/* ********** START implementation of BlockList ********** */
/** /**
* remove the specified block from the list * remove the specified block from the list
* *
* @param index the index of the specified block; if the index is * @param index the index of the specified block; if the index is
* out of range, that's ok * out of range, that's ok
*/ */
public void zap(final int index) public void zap(final int index)
{ {
if ((index >= 0) && (index < _blocks.length)) if ((index >= 0) && (index < _blocks.length))
@ -72,13 +57,13 @@ class BlockListImpl
_blocks[ index ] = null; _blocks[ index ] = null;
} }
} }
/** /**
* Unit testing method. Gets, without sanity checks or * Unit testing method. Gets, without sanity checks or
* removing. * removing.
*/ */
protected ListManagedBlock get(final int index) throws IOException { protected ListManagedBlock get(final int index) {
return _blocks[index]; return _blocks[index];
} }
/** /**
@ -91,7 +76,6 @@ class BlockListImpl
* @exception IOException if the index is out of range or has * @exception IOException if the index is out of range or has
* already been removed * already been removed
*/ */
public ListManagedBlock remove(final int index) public ListManagedBlock remove(final int index)
throws IOException throws IOException
{ {
@ -112,7 +96,7 @@ class BlockListImpl
catch (ArrayIndexOutOfBoundsException ignored) catch (ArrayIndexOutOfBoundsException ignored)
{ {
throw new IOException("Cannot remove block[ " + index throw new IOException("Cannot remove block[ " + index
+ " ]; out of range[ 0 - " + + " ]; out of range[ 0 - " +
(_blocks.length-1) + " ]"); (_blocks.length-1) + " ]");
} }
return result; return result;
@ -128,7 +112,6 @@ class BlockListImpl
* *
* @exception IOException if blocks are missing * @exception IOException if blocks are missing
*/ */
public ListManagedBlock [] fetchBlocks(final int startBlock, final int headerPropertiesStartBlock) public ListManagedBlock [] fetchBlocks(final int startBlock, final int headerPropertiesStartBlock)
throws IOException throws IOException
{ {
@ -144,10 +127,7 @@ class BlockListImpl
* set the associated BlockAllocationTable * set the associated BlockAllocationTable
* *
* @param bat the associated BlockAllocationTable * @param bat the associated BlockAllocationTable
*
* @exception IOException
*/ */
public void setBAT(final BlockAllocationTableReader bat) public void setBAT(final BlockAllocationTableReader bat)
throws IOException throws IOException
{ {
@ -158,7 +138,4 @@ class BlockListImpl
} }
_bat = bat; _bat = bat;
} }
}
/* ********** END implementation of BlockList ********** */
} // end package-scope class BlockListImpl

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,23 +14,17 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.poifs.storage; package org.apache.poi.poifs.storage;
import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.util.IntegerField;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LongField;
import org.apache.poi.util.ShortField;
/** /**
* Constants used in reading/writing the Header block * Constants used in reading/writing the Header block
* *
* @author Marc Johnson (mjohnson at apache dot org) * @author Marc Johnson (mjohnson at apache dot org)
*/ */
public interface HeaderBlockConstants public interface HeaderBlockConstants
{ {
public static final long _signature = 0xE11AB1A1E011CFD0L; public static final long _signature = 0xE11AB1A1E011CFD0L;

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,29 +14,22 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.poifs.storage; package org.apache.poi.poifs.storage;
import java.io.*; import java.io.IOException;
import java.io.OutputStream;
import java.util.*; import java.util.List;
import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.poifs.property.Property; import org.apache.poi.poifs.property.Property;
import org.apache.poi.util.IntegerField;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianConsts;
/** /**
* A block of Property instances * A block of Property instances
* *
* @author Marc Johnson (mjohnson at apache dot org) * @author Marc Johnson (mjohnson at apache dot org)
*/ */
public final class PropertyBlock extends BigBlock {
public class PropertyBlock
extends BigBlock
{
private static final int _properties_per_block = private static final int _properties_per_block =
POIFSConstants.BIG_BLOCK_SIZE / POIFSConstants.PROPERTY_SIZE; POIFSConstants.BIG_BLOCK_SIZE / POIFSConstants.PROPERTY_SIZE;
private Property[] _properties; private Property[] _properties;

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,25 +14,20 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.poifs.storage; package org.apache.poi.poifs.storage;
import java.io.IOException;
import org.apache.poi.poifs.property.RootProperty; import org.apache.poi.poifs.property.RootProperty;
import java.util.*;
import java.io.*;
/** /**
* This class implements reading the small document block list from an * This class implements reading the small document block list from an
* existing file * existing file
* *
* @author Marc Johnson (mjohnson at apache dot org) * @author Marc Johnson (mjohnson at apache dot org)
*/ */
public final class SmallBlockTableReader {
public class SmallBlockTableReader
{
/** /**
* fetch the small document block list from an existing file * fetch the small document block list from an existing file
@ -48,7 +42,6 @@ public class SmallBlockTableReader
* *
* @exception IOException * @exception IOException
*/ */
public static BlockList getSmallDocumentBlocks( public static BlockList getSmallDocumentBlocks(
final RawDataBlockList blockList, final RootProperty root, final RawDataBlockList blockList, final RootProperty root,
final int sbatStart) final int sbatStart)

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,12 +14,9 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.util; package org.apache.poi.util;
import java.util.*;
/** /**
* A List of int's; as full an implementation of the java.util.List * A List of int's; as full an implementation of the java.util.List
* interface as possible, with an eye toward minimal creation of * interface as possible, with an eye toward minimal creation of
@ -47,7 +43,6 @@ import java.util.*;
* *
* @author Marc Johnson * @author Marc Johnson
*/ */
public class IntList public class IntList
{ {
private int[] _array; private int[] _array;
@ -62,14 +57,14 @@ public class IntList
public IntList() public IntList()
{ {
this(_default_size); this(_default_size);
} }
public IntList(final int initialCapacity) public IntList(final int initialCapacity)
{ {
this(initialCapacity,0); this(initialCapacity,0);
} }
/** /**
* create a copy of an existing IntList * create a copy of an existing IntList
* *
@ -94,17 +89,17 @@ public class IntList
_array = new int[ initialCapacity ]; _array = new int[ initialCapacity ];
if (fillval != 0) { if (fillval != 0) {
fillval = fillvalue; fillval = fillvalue;
fillArray(fillval, _array, 0); fillArray(fillval, _array, 0);
} }
_limit = 0; _limit = 0;
} }
private void fillArray(int val, int[] array, int index) { private void fillArray(int val, int[] array, int index) {
for (int k = index; k < array.length; k++) { for (int k = index; k < array.length; k++) {
array[k] = val; array[k] = val;
} }
} }
/** /**
* add the specfied value at the specified index * add the specfied value at the specified index
* *
@ -653,11 +648,11 @@ public class IntList
int size = (new_size == _array.length) ? new_size + 1 int size = (new_size == _array.length) ? new_size + 1
: new_size; : new_size;
int[] new_array = new int[ size ]; int[] new_array = new int[ size ];
if (fillval != 0) { if (fillval != 0) {
fillArray(fillval, new_array, _array.length); fillArray(fillval, new_array, _array.length);
} }
System.arraycopy(_array, 0, new_array, 0, _limit); System.arraycopy(_array, 0, new_array, 0, _limit);
_array = new_array; _array = new_array;
} }

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,12 +14,9 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.util; package org.apache.poi.util;
import java.util.*;
/** /**
* A logger class that strives to make it as easy as possible for * A logger class that strives to make it as easy as possible for
* developers to write log calls, while simultaneously making those * developers to write log calls, while simultaneously making those
@ -31,14 +27,13 @@ import java.util.*;
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
* @author Nicola Ken Barozzi (nicolaken at apache.org) * @author Nicola Ken Barozzi (nicolaken at apache.org)
*/ */
public class NullLogger extends POILogger public class NullLogger extends POILogger
{ {
public void initialize(final String cat) public void initialize(final String cat)
{ {
//do nothing //do nothing
} }
/** /**
* Log a message * Log a message
* *
@ -462,5 +457,5 @@ public class NullLogger extends POILogger
//do nothing //do nothing
} }
} }

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,12 +14,9 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.util; package org.apache.poi.util;
import java.util.*;
/** /**
* A List of short's; as full an implementation of the java.util.List * A List of short's; as full an implementation of the java.util.List
* interface as possible, with an eye toward minimal creation of * interface as possible, with an eye toward minimal creation of

View File

@ -22,7 +22,6 @@ import java.util.*;
import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.util.IOUtils; import org.apache.poi.util.IOUtils;
import org.apache.poi.util.PackageHelper; import org.apache.poi.util.PackageHelper;
import org.apache.xmlbeans.XmlException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.*; import org.apache.poi.openxml4j.opc.*;

View File

@ -26,7 +26,6 @@ import java.util.Map.Entry;
import org.apache.poi.ss.usermodel.FontFamily; import org.apache.poi.ss.usermodel.FontFamily;
import org.apache.poi.ss.usermodel.FontScheme; import org.apache.poi.ss.usermodel.FontScheme;
import org.apache.poi.ss.usermodel.BuiltinFormats; import org.apache.poi.ss.usermodel.BuiltinFormats;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.xssf.usermodel.XSSFCellStyle; import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont; import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder; import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
@ -80,17 +79,17 @@ public class StylesTable extends POIXMLDocumentPart {
* Create a new, empty StylesTable * Create a new, empty StylesTable
*/ */
public StylesTable() { public StylesTable() {
super(); super();
doc = StyleSheetDocument.Factory.newInstance(); doc = StyleSheetDocument.Factory.newInstance();
doc.addNewStyleSheet(); doc.addNewStyleSheet();
// Initialization required in order to make the document readable by MSExcel // Initialization required in order to make the document readable by MSExcel
initialize(); initialize();
} }
public StylesTable(PackagePart part, PackageRelationship rel) throws IOException { public StylesTable(PackagePart part, PackageRelationship rel) throws IOException {
super(part, rel); super(part, rel);
readFrom(part.getInputStream()); readFrom(part.getInputStream());
} }
/** /**
* Read this shared styles table from an XML file. * Read this shared styles table from an XML file.
@ -107,13 +106,13 @@ public class StylesTable extends POIXMLDocumentPart {
numberFormats.put((int)nfmt.getNumFmtId(), nfmt.getFormatCode()); numberFormats.put((int)nfmt.getNumFmtId(), nfmt.getFormatCode());
} }
if(doc.getStyleSheet().getFonts() != null){ if(doc.getStyleSheet().getFonts() != null){
int idx = 0; int idx = 0;
for (CTFont font : doc.getStyleSheet().getFonts().getFontArray()) { for (CTFont font : doc.getStyleSheet().getFonts().getFontArray()) {
XSSFFont f = new XSSFFont(font, idx); XSSFFont f = new XSSFFont(font, idx);
fonts.add(f); fonts.add(f);
idx++; idx++;
} }
} }
if(doc.getStyleSheet().getFills() != null) if(doc.getStyleSheet().getFills() != null)
for (CTFill fill : doc.getStyleSheet().getFills().getFillArray()) { for (CTFill fill : doc.getStyleSheet().getFills().getFillArray()) {
fills.add(new XSSFCellFill(fill)); fills.add(new XSSFCellFill(fill));
@ -149,7 +148,7 @@ public class StylesTable extends POIXMLDocumentPart {
return numberFormats.get(idx); return numberFormats.get(idx);
} }
public int putNumberFormat(String fmt) { public int putNumberFormat(String fmt) {
if (numberFormats.containsValue(fmt)) { if (numberFormats.containsValue(fmt)) {
// Find the key, and return that // Find the key, and return that
for(Integer key : numberFormats.keySet() ) { for(Integer key : numberFormats.keySet() ) {
@ -174,12 +173,12 @@ public class StylesTable extends POIXMLDocumentPart {
} }
public int putFont(XSSFFont font) { public int putFont(XSSFFont font) {
int idx = fonts.indexOf(font); int idx = fonts.indexOf(font);
if (idx != -1) { if (idx != -1) {
return idx; return idx;
} }
fonts.add(font); fonts.add(font);
return fonts.size() - 1; return fonts.size() - 1;
} }
public XSSFCellStyle getStyleAt(int idx) { public XSSFCellStyle getStyleAt(int idx) {
@ -205,42 +204,42 @@ public class StylesTable extends POIXMLDocumentPart {
return borders.get(idx); return borders.get(idx);
} }
public int putBorder(XSSFCellBorder border) { public int putBorder(XSSFCellBorder border) {
int idx = borders.indexOf(border); int idx = borders.indexOf(border);
if (idx != -1) { if (idx != -1) {
return idx; return idx;
} }
borders.add(border); borders.add(border);
return borders.size() - 1; return borders.size() - 1;
} }
public XSSFCellFill getFillAt(int idx) { public XSSFCellFill getFillAt(int idx) {
return fills.get(idx); return fills.get(idx);
} }
public List<XSSFCellBorder> getBorders(){ public List<XSSFCellBorder> getBorders(){
return borders; return borders;
} }
public List<XSSFCellFill> getFills(){ public List<XSSFCellFill> getFills(){
return fills; return fills;
} }
public List<XSSFFont> getFonts(){ public List<XSSFFont> getFonts(){
return fonts; return fonts;
} }
public Map<Integer, String> getNumberFormats(){ public Map<Integer, String> getNumberFormats(){
return numberFormats; return numberFormats;
} }
public int putFill(XSSFCellFill fill) { public int putFill(XSSFCellFill fill) {
int idx = fills.indexOf(fill); int idx = fills.indexOf(fill);
if (idx != -1) { if (idx != -1) {
return idx; return idx;
} }
fills.add(fill); fills.add(fill);
return fills.size() - 1; return fills.size() - 1;
} }
public CTXf getCellXfAt(int idx) { public CTXf getCellXfAt(int idx) {
@ -315,31 +314,31 @@ public class StylesTable extends POIXMLDocumentPart {
} }
doc.getStyleSheet().setNumFmts(formats); doc.getStyleSheet().setNumFmts(formats);
int idx; int idx;
// Fonts // Fonts
CTFonts ctFonts = CTFonts.Factory.newInstance(); CTFonts ctFonts = CTFonts.Factory.newInstance();
ctFonts.setCount(fonts.size()); ctFonts.setCount(fonts.size());
CTFont[] ctfnt = new CTFont[fonts.size()]; CTFont[] ctfnt = new CTFont[fonts.size()];
idx = 0; idx = 0;
for(XSSFFont f : fonts) ctfnt[idx++] = f.getCTFont(); for(XSSFFont f : fonts) ctfnt[idx++] = f.getCTFont();
ctFonts.setFontArray(ctfnt); ctFonts.setFontArray(ctfnt);
doc.getStyleSheet().setFonts(ctFonts); doc.getStyleSheet().setFonts(ctFonts);
// Fills // Fills
CTFills ctFills = CTFills.Factory.newInstance(); CTFills ctFills = CTFills.Factory.newInstance();
ctFills.setCount(fills.size()); ctFills.setCount(fills.size());
CTFill[] ctf = new CTFill[fills.size()]; CTFill[] ctf = new CTFill[fills.size()];
idx = 0; idx = 0;
for(XSSFCellFill f : fills) ctf[idx++] = f.getCTFill(); for(XSSFCellFill f : fills) ctf[idx++] = f.getCTFill();
ctFills.setFillArray(ctf); ctFills.setFillArray(ctf);
doc.getStyleSheet().setFills(ctFills); doc.getStyleSheet().setFills(ctFills);
// Borders // Borders
CTBorders ctBorders = CTBorders.Factory.newInstance(); CTBorders ctBorders = CTBorders.Factory.newInstance();
ctBorders.setCount(borders.size()); ctBorders.setCount(borders.size());
CTBorder[] ctb = new CTBorder[borders.size()]; CTBorder[] ctb = new CTBorder[borders.size()];
idx = 0; idx = 0;
for(XSSFCellBorder b : borders) ctb[idx++] = b.getCTBorder(); for(XSSFCellBorder b : borders) ctb[idx++] = b.getCTBorder();
ctBorders.setBorderArray(ctb); ctBorders.setBorderArray(ctb);
doc.getStyleSheet().setBorders(ctBorders); doc.getStyleSheet().setBorders(ctBorders);
@ -376,13 +375,13 @@ public class StylesTable extends POIXMLDocumentPart {
doc.save(out, options); doc.save(out, options);
} }
@Override @Override
protected void commit() throws IOException { protected void commit() throws IOException {
PackagePart part = getPackagePart(); PackagePart part = getPackagePart();
OutputStream out = part.getOutputStream(); OutputStream out = part.getOutputStream();
writeTo(out); writeTo(out);
out.close(); out.close();
} }
private void initialize() { private void initialize() {
//CTFont ctFont = createDefaultFont(); //CTFont ctFont = createDefaultFont();
@ -452,36 +451,35 @@ public class StylesTable extends POIXMLDocumentPart {
return this.dxfs.size(); return this.dxfs.size();
} }
public XSSFCellStyle createCellStyle() { public XSSFCellStyle createCellStyle() {
CTXf xf = CTXf.Factory.newInstance(); CTXf xf = CTXf.Factory.newInstance();
xf.setNumFmtId(0); xf.setNumFmtId(0);
xf.setFontId(0); xf.setFontId(0);
xf.setFillId(0); xf.setFillId(0);
xf.setBorderId(0); xf.setBorderId(0);
xf.setXfId(0); xf.setXfId(0);
int xfSize = styleXfs.size(); int xfSize = styleXfs.size();
int indexXf = putCellXf(xf); int indexXf = putCellXf(xf);
return new XSSFCellStyle(indexXf - 1, xfSize - 1, this); return new XSSFCellStyle(indexXf - 1, xfSize - 1, this);
} }
/**
* Finds a font that matches the one with the supplied attributes
*/
public XSSFFont findFont(short boldWeight, short color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline) {
for (XSSFFont font : fonts) {
if ( (font.getBoldweight() == boldWeight)
&& font.getColor() == color
&& font.getFontHeight() == fontHeight
&& font.getFontName().equals(name)
&& font.getItalic() == italic
&& font.getStrikeout() == strikeout
&& font.getTypeOffset() == typeOffset
&& font.getUnderline() == underline)
{
return font;
}
}
return null;
}
/**
* Finds a font that matches the one with the supplied attributes
*/
public XSSFFont findFont(short boldWeight, short color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline) {
for (XSSFFont font : fonts) {
if ( (font.getBoldweight() == boldWeight)
&& font.getColor() == color
&& font.getFontHeight() == fontHeight
&& font.getFontName().equals(name)
&& font.getItalic() == italic
&& font.getStrikeout() == strikeout
&& font.getTypeOffset() == typeOffset
&& font.getUnderline() == underline)
{
return font;
}
}
return null;
}
} }

View File

@ -17,49 +17,48 @@
package org.apache.poi.xssf.usermodel; package org.apache.poi.xssf.usermodel;
import org.apache.poi.ss.usermodel.CreationHelper; import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.Hyperlink;
import org.apache.poi.ss.usermodel.RichTextString;
public class XSSFCreationHelper implements CreationHelper { public class XSSFCreationHelper implements CreationHelper {
private XSSFWorkbook workbook; private XSSFWorkbook workbook;
XSSFCreationHelper(XSSFWorkbook wb) { XSSFCreationHelper(XSSFWorkbook wb) {
workbook = wb; workbook = wb;
} }
/** /**
* Creates a new XSSFRichTextString for you. * Creates a new XSSFRichTextString for you.
*/ */
public XSSFRichTextString createRichTextString(String text) { public XSSFRichTextString createRichTextString(String text) {
XSSFRichTextString rt = new XSSFRichTextString(text); XSSFRichTextString rt = new XSSFRichTextString(text);
rt.setStylesTableReference(workbook.getStylesSource()); rt.setStylesTableReference(workbook.getStylesSource());
return rt; return rt;
} }
public XSSFDataFormat createDataFormat() { public XSSFDataFormat createDataFormat() {
return workbook.createDataFormat(); return workbook.createDataFormat();
} }
public XSSFHyperlink createHyperlink(int type) { public XSSFHyperlink createHyperlink(int type) {
return new XSSFHyperlink(type); return new XSSFHyperlink(type);
} }
/** /**
* Creates a XSSFFormulaEvaluator, the object that evaluates formula cells. * Creates a XSSFFormulaEvaluator, the object that evaluates formula cells.
* *
* @return a XSSFFormulaEvaluator instance * @return a XSSFFormulaEvaluator instance
*/ */
public XSSFFormulaEvaluator createFormulaEvaluator(){ public XSSFFormulaEvaluator createFormulaEvaluator() {
return new XSSFFormulaEvaluator(workbook); return new XSSFFormulaEvaluator(workbook);
} }
/** /**
* Creates a XSSFClientAnchor. Use this object to position drawing object in a sheet * Creates a XSSFClientAnchor. Use this object to position drawing object in
* * a sheet
* @return a XSSFClientAnchor instance *
* @see org.apache.poi.ss.usermodel.Drawing * @return a XSSFClientAnchor instance
*/ * @see org.apache.poi.ss.usermodel.Drawing
public XSSFClientAnchor createClientAnchor(){ */
return new XSSFClientAnchor(); public XSSFClientAnchor createClientAnchor() {
} return new XSSFClientAnchor();
}
} }

View File

@ -53,7 +53,6 @@ import org.apache.poi.xssf.model.CalculationChain;
import org.apache.poi.xssf.model.SharedStringsTable; import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.model.StylesTable; import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.model.MapInfo; import org.apache.poi.xssf.model.MapInfo;
import org.apache.poi.xssf.extractor.XSSFExportToXml;
import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions; import org.apache.xmlbeans.XmlOptions;
@ -570,7 +569,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
throw new IllegalStateException("There are no defined names in this workbook"); throw new IllegalStateException("There are no defined names in this workbook");
} }
if (nameIndex < 0 || nameIndex > nNames) { if (nameIndex < 0 || nameIndex > nNames) {
throw new IllegalArgumentException("Specified name index " + nameIndex throw new IllegalArgumentException("Specified name index " + nameIndex
+ " is outside the allowable range (0.." + (nNames-1) + ")."); + " is outside the allowable range (0.." + (nNames-1) + ").");
} }
return namedRanges.get(nameIndex); return namedRanges.get(nameIndex);
@ -636,7 +635,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
* @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java) * @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
* @return String Null if no print area has been defined * @return String Null if no print area has been defined
*/ */
public String getPrintArea(int sheetIndex) { public String getPrintArea(int sheetIndex) {
XSSFName name = getBuiltInName(XSSFName.BUILTIN_PRINT_AREA, sheetIndex); XSSFName name = getBuiltInName(XSSFName.BUILTIN_PRINT_AREA, sheetIndex);
if (name == null) return null; if (name == null) return null;
//adding one here because 0 indicates a global named region; doesnt make sense for print areas //adding one here because 0 indicates a global named region; doesnt make sense for print areas
@ -975,7 +974,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
r = escapedName + "!$" + rowRef.getCellRefParts()[1] + ":$" + rowRef2.getCellRefParts()[1]; r = escapedName + "!$" + rowRef.getCellRefParts()[1] + ":$" + rowRef2.getCellRefParts()[1];
} }
} }
StringBuffer rng = new StringBuffer(); StringBuffer rng = new StringBuffer();
rng.append(c); rng.append(c);
if(rng.length() > 0 && r.length() > 0) rng.append(','); if(rng.length() > 0 && r.length() > 0) rng.append(',');
@ -1243,7 +1242,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
} }
return embedds; return embedds;
} }
public boolean isHidden() { public boolean isHidden() {
throw new RuntimeException("Not implemented yet"); throw new RuntimeException("Not implemented yet");
} }
@ -1280,7 +1279,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
* Fired when a formula is deleted from this workbook, * Fired when a formula is deleted from this workbook,
* for example when calling cell.setCellFormula(null) * for example when calling cell.setCellFormula(null)
* *
* @see XSSFCell#setCellFormula(String) * @see XSSFCell#setCellFormula(String)
*/ */
protected void onDeleteFormula(XSSFCell cell){ protected void onDeleteFormula(XSSFCell cell){
if(calcChain != null) { if(calcChain != null) {
@ -1294,7 +1293,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
* <p> * <p>
* The calculation chain object specifies the order in which the cells in a workbook were last calculated * The calculation chain object specifies the order in which the cells in a workbook were last calculated
* </p> * </p>
* *
* @return the <code>CalculationChain</code> object or <code>null</code> if not defined * @return the <code>CalculationChain</code> object or <code>null</code> if not defined
*/ */
public CalculationChain getCalculationChain(){ public CalculationChain getCalculationChain(){
@ -1302,19 +1301,19 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
} }
/** /**
* *
* @return a collection of custom XML mappings defined in this workbook * @return a collection of custom XML mappings defined in this workbook
*/ */
public Collection<XSSFMap> getCustomXMLMappings(){ public Collection<XSSFMap> getCustomXMLMappings(){
return mapInfo == null ? new ArrayList<XSSFMap>() : mapInfo.getAllXSSFMaps(); return mapInfo == null ? new ArrayList<XSSFMap>() : mapInfo.getAllXSSFMaps();
} }
/** /**
* *
* @return the helper class used to query the custom XML mapping defined in this workbook * @return the helper class used to query the custom XML mapping defined in this workbook
*/ */
public MapInfo getMapInfo(){ public MapInfo getMapInfo(){
return mapInfo; return mapInfo;
} }
} }

View File

@ -18,119 +18,151 @@
package org.apache.poi.xssf.usermodel.extensions; package org.apache.poi.xssf.usermodel.extensions;
import org.apache.poi.ss.usermodel.HeaderFooter; import org.apache.poi.ss.usermodel.HeaderFooter;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.helpers.HeaderFooterHelper; import org.apache.poi.xssf.usermodel.helpers.HeaderFooterHelper;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
/** /**
* Parent class of all XSSF headers and footers. * Parent class of all XSSF headers and footers.
* *
* For a list of all the different fields that can be * For a list of all the different fields that can be placed into a header or
* placed into a header or footer, such as page number, * footer, such as page number, bold, underline etc, see the follow formatting
* bold, underline etc, see the follow formatting syntax * syntax
* *
*<b> Header/Footer Formatting Syntax</b> *<b> Header/Footer Formatting Syntax</b>
*<p> *<p>
* There are a number of formatting codes that can be written inline with the actual header / footer text, which * There are a number of formatting codes that can be written inline with the
* affect the formatting in the header or footer. * actual header / footer text, which affect the formatting in the header or
* footer.
*</p> *</p>
* *
* This example shows the text "Center Bold Header" on the first line (center section), and the date on the second * This example shows the text "Center Bold Header" on the first line (center
* line (center section). * section), and the date on the second line (center section). &CCenter
* &CCenter &"-,Bold"Bold &"-,Regular"Header_x000A_&D * &"-,Bold"Bold &"-,Regular"Header_x000A_&D
* *
* <b>General Rules:</b> * <b>General Rules:</b> There is no required order in which these codes must
* There is no required order in which these codes must appear. * appear. The first occurrence of the following codes turns the formatting ON,
* The first occurrence of the following codes turns the formatting ON, the second occurrence turns it OFF again: * the second occurrence turns it OFF again:
* *
* <dl> * <dl>
* <dt> &L </dt> <dd>code for "left section" (there are three header / footer locations, "left", "center", and "right"). When * <dt>&L</dt>
* two or more occurrences of this section marker exist, the contents from all markers are concatenated, in the * <dd>code for "left section" (there are three header / footer locations,
* order of appearance, and placed into the left section.</dd> * "left", "center", and "right"). When two or more occurrences of this section
* <dt> &P </dt> <dd> code for "current page #"</dd> * marker exist, the contents from all markers are concatenated, in the order of
* <dt> &N </dt> <dd> code for "total pages"</dd> * appearance, and placed into the left section.</dd>
* <dt>&font size </dt> <dd> code for "text font size", where font size is a font size in points.</dd> * <dt>&P</dt>
* <dt> &K </dt> <dd> code for "text font color" * <dd>code for "current page #"</dd>
* RGB Color is specified as RRGGBB * <dt>&N</dt>
* Theme Color is specifed as TTSNN where TT is the theme color Id, S is either "+" or "-" of the tint/shade * <dd>code for "total pages"</dd>
* value, NN is the tint/shade value.</dd> * <dt>&font size</dt>
* <dt> &S </dt> <dd> code for "text strikethrough" on / off</dd> * <dd>code for "text font size", where font size is a font size in points.</dd>
* <dt> &X </dt> <dd> code for "text super script" on / off</dd> * <dt>&K</dt>
* <dt> &Y </dt> <dd> code for "text subscript" on / off</dd> * <dd>code for "text font color" RGB Color is specified as RRGGBB Theme Color
* <dt> &C </dt> <dd> code for "center section". When two or more occurrences of this section marker exist, the contents * is specifed as TTSNN where TT is the theme color Id, S is either "+" or "-"
* from all markers are concatenated, in the order of appearance, and placed into the center section. * of the tint/shade value, NN is the tint/shade value.</dd>
* SpreadsheetML Reference Material - Worksheets 1966</dd> * <dt>&S</dt>
* <dt> &D </dt> <dd> code for "date"</dd> * <dd>code for "text strikethrough" on / off</dd>
* <dt> &T </dt> <dd> code for "time"</dd> * <dt>&X</dt>
* <dt> &G </dt> <dd> code for "picture as background"</dd> * <dd>code for "text super script" on / off</dd>
* <dt> &U </dt> <dd> code for "text single underline"</dd> * <dt>&Y</dt>
* <dt> &E </dt> <dd> code for "double underline"</dd> * <dd>code for "text subscript" on / off</dd>
* <dt> &R </dt> <dd> code for "right section". When two or more occurrences of this section marker exist, the contents * <dt>&C</dt>
* from all markers are concatenated, in the order of appearance, and placed into the right section.</dd> * <dd>code for "center section". When two or more occurrences of this section
* <dt> &Z </dt> <dd> code for "this workbook's file path"</dd> * marker exist, the contents from all markers are concatenated, in the order of
* <dt> &F </dt> <dd> code for "this workbook's file name"</dd> * appearance, and placed into the center section. SpreadsheetML Reference
* <dt> &A </dt> <dd> code for "sheet tab name"</dd> * Material - Worksheets 1966</dd>
* <dt> &+ </dt> <dd> code for add to page #.</dd> * <dt>&D</dt>
* <dt> &- </dt> <dd> code for subtract from page #.</dd> * <dd>code for "date"</dd>
* <dt> &"font name,font type" - code for "text font name" and "text font type", where font name and font type * <dt>&T</dt>
* are strings specifying the name and type of the font, separated by a comma. When a hyphen appears in font * <dd>code for "time"</dd>
* name, it means "none specified". Both of font name and font type can be localized values.</dd> * <dt>&G</dt>
* <dt> &"-,Bold" </dt> <dd> code for "bold font style"</dd> * <dd>code for "picture as background"</dd>
* <dt> &B </dt> <dd> also means "bold font style"</dd> * <dt>&U</dt>
* <dt> &"-,Regular" </dt> <dd> code for "regular font style"</dd> * <dd>code for "text single underline"</dd>
* <dt> &"-,Italic" </dt> <dd> code for "italic font style"</dd> * <dt>&E</dt>
* <dt> &I </dt> <dd> also means "italic font style"</dd> * <dd>code for "double underline"</dd>
* <dt> &"-,Bold Italic" </dt> <dd> code for "bold italic font style"</dd> * <dt>&R</dt>
* <dt> &O </dt> <dd> code for "outline style"</dd> * <dd>code for "right section". When two or more occurrences of this section
* <dt> &H </dt> <dd> code for "shadow style"</dd> * marker exist, the contents from all markers are concatenated, in the order of
* appearance, and placed into the right section.</dd>
* <dt>&Z</dt>
* <dd>code for "this workbook's file path"</dd>
* <dt>&F</dt>
* <dd>code for "this workbook's file name"</dd>
* <dt>&A</dt>
* <dd>code for "sheet tab name"</dd>
* <dt>&+</dt>
* <dd>code for add to page #.</dd>
* <dt>&-</dt>
* <dd>code for subtract from page #.</dd>
* <dt>&"font name,font type" - code for "text font name" and "text font type",
* where font name and font type are strings specifying the name and type of the
* font, separated by a comma. When a hyphen appears in font name, it means
* "none specified". Both of font name and font type can be localized
* values.</dd>
* <dt>&"-,Bold"</dt>
* <dd>code for "bold font style"</dd>
* <dt>&B</dt>
* <dd>also means "bold font style"</dd>
* <dt>&"-,Regular"</dt>
* <dd>code for "regular font style"</dd>
* <dt>&"-,Italic"</dt>
* <dd>code for "italic font style"</dd>
* <dt>&I</dt>
* <dd>also means "italic font style"</dd>
* <dt>&"-,Bold Italic"</dt>
* <dd>code for "bold italic font style"</dd>
* <dt>&O</dt>
* <dd>code for "outline style"</dd>
* <dt>&H</dt>
* <dd>code for "shadow style"</dd>
* </dl> * </dl>
* *
* *
*/ */
public abstract class XSSFHeaderFooter implements HeaderFooter { public abstract class XSSFHeaderFooter implements HeaderFooter {
private HeaderFooterHelper helper; private HeaderFooterHelper helper;
private CTHeaderFooter headerFooter; private CTHeaderFooter headerFooter;
private boolean stripFields = false; private boolean stripFields = false;
/** /**
* Create an instance of XSSFHeaderFooter from the supplied XML bean * Create an instance of XSSFHeaderFooter from the supplied XML bean
*
* @param headerFooter * @param headerFooter
*/ */
public XSSFHeaderFooter(CTHeaderFooter headerFooter) { public XSSFHeaderFooter(CTHeaderFooter headerFooter) {
this.headerFooter = headerFooter; this.headerFooter = headerFooter;
this.helper = new HeaderFooterHelper(); this.helper = new HeaderFooterHelper();
} }
/**
* Returns the underlying CTHeaderFooter xml bean
*
* @return the underlying CTHeaderFooter xml bean
*/
public CTHeaderFooter getHeaderFooter() {
return this.headerFooter;
}
public String getValue() {
String value = getText();
if(value == null)
return "";
return value;
}
/** /**
* Are fields currently being stripped from * Returns the underlying CTHeaderFooter xml bean
* the text that this {@link XSSFHeaderFooter} returns? *
* Default is false, but can be changed * @return the underlying CTHeaderFooter xml bean
*/
public CTHeaderFooter getHeaderFooter() {
return this.headerFooter;
}
public String getValue() {
String value = getText();
if (value == null)
return "";
return value;
}
/**
* Are fields currently being stripped from the text that this
* {@link XSSFHeaderFooter} returns? Default is false, but can be changed
*/ */
public boolean areFieldsStripped() { public boolean areFieldsStripped() {
return stripFields; return stripFields;
} }
/** /**
* Should fields (eg macros) be stripped from * Should fields (eg macros) be stripped from the text that this class
* the text that this class returns? * returns? Default is not to strip.
* Default is not to strip. *
* @param stripFields * @param stripFields
*/ */
public void setAreFieldsStripped(boolean stripFields) { public void setAreFieldsStripped(boolean stripFields) {
@ -138,69 +170,66 @@ public abstract class XSSFHeaderFooter implements HeaderFooter {
} }
/** /**
* Removes any fields (eg macros, page markers etc) * Removes any fields (eg macros, page markers etc) from the string.
* from the string. * Normally used to make some text suitable for showing to humans, and the
* Normally used to make some text suitable for showing * resultant text should not normally be saved back into the document!
* to humans, and the resultant text should not normally
* be saved back into the document!
*/ */
public static String stripFields(String text) { public static String stripFields(String text) {
return org.apache.poi.hssf.usermodel.HeaderFooter.stripFields(text); return org.apache.poi.hssf.usermodel.HeaderFooter.stripFields(text);
} }
public abstract String getText();
public abstract String getText();
protected abstract void setText(String text);
/** protected abstract void setText(String text);
* get the text representing the center part of this element
*/
public String getCenter() {
String text = helper.getCenterSection(getText());
if(stripFields)
return stripFields(text);
return text;
}
/** /**
* get the text representing the left part of this element * get the text representing the center part of this element
*/ */
public String getLeft() { public String getCenter() {
String text = helper.getLeftSection(getText()); String text = helper.getCenterSection(getText());
if(stripFields) if (stripFields)
return stripFields(text); return stripFields(text);
return text; return text;
} }
/** /**
* get the text representing the right part of this element * get the text representing the left part of this element
*/ */
public String getRight() { public String getLeft() {
String text = helper.getRightSection(getText()); String text = helper.getLeftSection(getText());
if(stripFields) if (stripFields)
return stripFields(text); return stripFields(text);
return text; return text;
} }
/** /**
* set a centered string value for this element * get the text representing the right part of this element
*/ */
public void setCenter(String newCenter) { public String getRight() {
setText(helper.setCenterSection(getText(), newCenter)); String text = helper.getRightSection(getText());
} if (stripFields)
return stripFields(text);
return text;
}
/** /**
* set a left string value for this element * set a centered string value for this element
*/ */
public void setLeft(String newLeft) { public void setCenter(String newCenter) {
setText(helper.setLeftSection(getText(), newLeft)); setText(helper.setCenterSection(getText(), newCenter));
} }
/** /**
* set a right string value for this element * set a left string value for this element
*/ */
public void setRight(String newRight) { public void setLeft(String newLeft) {
setText(helper.setRightSection(getText(), newRight)); setText(helper.setLeftSection(getText(), newLeft));
} }
/**
* set a right string value for this element
*/
public void setRight(String newRight) {
setText(helper.setRightSection(getText(), newRight));
}
} }

View File

@ -17,7 +17,6 @@
package org.apache.poi.openxml4j.opc; package org.apache.poi.openxml4j.opc;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -37,8 +36,6 @@ import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.internal.ContentTypeManager; import org.apache.poi.openxml4j.opc.internal.ContentTypeManager;
import org.apache.poi.openxml4j.opc.internal.FileHelper; import org.apache.poi.openxml4j.opc.internal.FileHelper;
import org.apache.poi.util.TempFile; import org.apache.poi.util.TempFile;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.POILogger;
import org.dom4j.Document; import org.dom4j.Document;
import org.dom4j.DocumentHelper; import org.dom4j.DocumentHelper;
import org.dom4j.Element; import org.dom4j.Element;
@ -64,19 +61,19 @@ public final class TestPackage extends TestCase {
//ZipFileAssert.assertEquals(originalFile, targetFile); //ZipFileAssert.assertEquals(originalFile, targetFile);
assertTrue(targetFile.delete()); assertTrue(targetFile.delete());
} }
/** /**
* Test that when we create a new Package, we give it * Test that when we create a new Package, we give it
* the correct default content types * the correct default content types
*/ */
public void testCreateGetsContentTypes() throws Exception { public void testCreateGetsContentTypes() throws Exception {
File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestCreatePackageTMP.docx"); File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestCreatePackageTMP.docx");
// Zap the target file, in case of an earlier run // Zap the target file, in case of an earlier run
if(targetFile.exists()) targetFile.delete(); if(targetFile.exists()) targetFile.delete();
OPCPackage pkg = OPCPackage.create(targetFile); OPCPackage pkg = OPCPackage.create(targetFile);
// Check it has content types for rels and xml // Check it has content types for rels and xml
ContentTypeManager ctm = getContentTypeManager(pkg); ContentTypeManager ctm = getContentTypeManager(pkg);
assertEquals( assertEquals(
@ -108,7 +105,7 @@ public final class TestPackage extends TestCase {
// Zap the target file, in case of an earlier run // Zap the target file, in case of an earlier run
if(targetFile.exists()) targetFile.delete(); if(targetFile.exists()) targetFile.delete();
// Create a package // Create a package
OPCPackage pkg = OPCPackage.create(targetFile); OPCPackage pkg = OPCPackage.create(targetFile);
PackagePartName corePartName = PackagingURIHelper PackagePartName corePartName = PackagingURIHelper
@ -142,7 +139,7 @@ public final class TestPackage extends TestCase {
//ZipFileAssert.assertEquals(expectedFile, targetFile); //ZipFileAssert.assertEquals(expectedFile, targetFile);
assertTrue(targetFile.delete()); assertTrue(targetFile.delete());
} }
/** /**
* Tests that we can create a new package, add a core * Tests that we can create a new package, add a core
* document and another part, save and re-load and * document and another part, save and re-load and
@ -151,7 +148,7 @@ public final class TestPackage extends TestCase {
public void testCreatePackageWithCoreDocument() throws Exception { public void testCreatePackageWithCoreDocument() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
OPCPackage pkg = OPCPackage.create(baos); OPCPackage pkg = OPCPackage.create(baos);
// Add a core document // Add a core document
PackagePartName corePartName = PackagingURIHelper.createPartName("/xl/workbook.xml"); PackagePartName corePartName = PackagingURIHelper.createPartName("/xl/workbook.xml");
// Create main part relationship // Create main part relationship
@ -162,7 +159,7 @@ public final class TestPackage extends TestCase {
OutputStream coreOut = corePart.getOutputStream(); OutputStream coreOut = corePart.getOutputStream();
coreOut.write("<dummy-xml />".getBytes()); coreOut.write("<dummy-xml />".getBytes());
coreOut.close(); coreOut.close();
// And another bit // And another bit
PackagePartName sheetPartName = PackagingURIHelper.createPartName("/xl/worksheets/sheet1.xml"); PackagePartName sheetPartName = PackagingURIHelper.createPartName("/xl/worksheets/sheet1.xml");
PackageRelationship rel = PackageRelationship rel =
@ -184,8 +181,8 @@ public final class TestPackage extends TestCase {
assertEquals("/", coreRel.getSourceURI().toString()); assertEquals("/", coreRel.getSourceURI().toString());
assertEquals("/xl/workbook.xml", coreRel.getTargetURI().toString()); assertEquals("/xl/workbook.xml", coreRel.getTargetURI().toString());
assertNotNull(pkg.getPart(coreRel)); assertNotNull(pkg.getPart(coreRel));
// Save and re-load // Save and re-load
pkg.close(); pkg.close();
File tmp = TempFile.createTempFile("testCreatePackageWithCoreDocument", ".zip"); File tmp = TempFile.createTempFile("testCreatePackageWithCoreDocument", ".zip");
@ -290,7 +287,7 @@ public final class TestPackage extends TestCase {
//ZipFileAssert.assertEquals(expectedFile, targetFile); //ZipFileAssert.assertEquals(expectedFile, targetFile);
assertTrue(targetFile.delete()); assertTrue(targetFile.delete());
} }
/** /**
* Checks that we can write a package to a simple * Checks that we can write a package to a simple
* OutputStream, in addition to the normal writing * OutputStream, in addition to the normal writing
@ -318,15 +315,15 @@ public final class TestPackage extends TestCase {
*/ */
public void testOpenFromInputStream() throws Exception { public void testOpenFromInputStream() throws Exception {
String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx"); String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");
FileInputStream finp = new FileInputStream(originalFile); FileInputStream finp = new FileInputStream(originalFile);
OPCPackage p = OPCPackage.open(finp); OPCPackage p = OPCPackage.open(finp);
assertNotNull(p); assertNotNull(p);
assertNotNull(p.getRelationships()); assertNotNull(p.getRelationships());
assertEquals(12, p.getParts().size()); assertEquals(12, p.getParts().size());
// Check it has the usual bits // Check it has the usual bits
assertTrue(p.hasRelationships()); assertTrue(p.hasRelationships());
assertTrue(p.containPart(PackagingURIHelper.createPartName("/_rels/.rels"))); assertTrue(p.containPart(PackagingURIHelper.createPartName("/_rels/.rels")));
@ -407,7 +404,7 @@ public final class TestPackage extends TestCase {
// Don't save modifications // Don't save modifications
p.revert(); p.revert();
} }
public void testDeletePartRecursive() throws InvalidFormatException { public void testDeletePartRecursive() throws InvalidFormatException {
TreeMap<PackagePartName, String> expectedValues; TreeMap<PackagePartName, String> expectedValues;
TreeMap<PackagePartName, String> values; TreeMap<PackagePartName, String> values;
@ -445,7 +442,7 @@ public final class TestPackage extends TestCase {
// Don't save modifications // Don't save modifications
p.revert(); p.revert();
} }
private static ContentTypeManager getContentTypeManager(OPCPackage pkg) throws Exception { private static ContentTypeManager getContentTypeManager(OPCPackage pkg) throws Exception {
Field f = OPCPackage.class.getDeclaredField("contentTypeManager"); Field f = OPCPackage.class.getDeclaredField("contentTypeManager");
f.setAccessible(true); f.setAccessible(true);

View File

@ -24,7 +24,6 @@ import junit.framework.TestCase;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.PictureData;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@ -35,8 +34,8 @@ public class TestLoadSaveXSSF extends TestCase {
String filename; String filename;
protected void setUp() throws Exception { protected void setUp() {
super.setUp();
System.setProperty("org.apache.poi.util.POILogger", org.apache.poi.util.CommonsLogger.class.getName()); System.setProperty("org.apache.poi.util.POILogger", org.apache.poi.util.CommonsLogger.class.getName());
filename = System.getProperty("XSSF.testdata.path"); filename = System.getProperty("XSSF.testdata.path");
if (filename == null) { if (filename == null) {
@ -52,12 +51,12 @@ public class TestLoadSaveXSSF extends TestCase {
Row row = sheet.getRow(0); Row row = sheet.getRow(0);
Cell cell = row.getCell((short) 1); Cell cell = row.getCell((short) 1);
assertNotNull(cell); assertNotNull(cell);
assertEquals(111.0, cell.getNumericCellValue()); assertEquals(111.0, cell.getNumericCellValue(), 0.0);
cell = row.getCell((short) 0); cell = row.getCell((short) 0);
assertEquals("Lorem", cell.getRichStringCellValue().getString()); assertEquals("Lorem", cell.getRichStringCellValue().getString());
} }
// TODO filename string hard coded in XSSFWorkbook constructor in order to make ant test-ooxml target be successfull. // TODO filename string hard coded in XSSFWorkbook constructor in order to make ant test-ooxml target be successful.
public void testLoadStyles() throws Exception { public void testLoadStyles() throws Exception {
XSSFWorkbook workbook = new XSSFWorkbook(new File(filename, "styles.xlsx").getAbsolutePath()); XSSFWorkbook workbook = new XSSFWorkbook(new File(filename, "styles.xlsx").getAbsolutePath());
Sheet sheet = workbook.getSheetAt(0); Sheet sheet = workbook.getSheetAt(0);
@ -67,11 +66,10 @@ public class TestLoadSaveXSSF extends TestCase {
// assertNotNull(style); // assertNotNull(style);
} }
// TODO filename string hard coded in XSSFWorkbook constructor in order to make ant test-ooxml target be successfull. // TODO filename string hard coded in XSSFWorkbook constructor in order to make ant test-ooxml target be successful.
public void testLoadPictures() throws Exception { public void testLoadPictures() throws Exception {
XSSFWorkbook workbook = new XSSFWorkbook(new File(filename, "picture.xlsx").getAbsolutePath()); XSSFWorkbook workbook = new XSSFWorkbook(new File(filename, "picture.xlsx").getAbsolutePath());
List<XSSFPictureData> pictures = workbook.getAllPictures(); List<XSSFPictureData> pictures = workbook.getAllPictures();
assertEquals(1, pictures.size()); assertEquals(1, pictures.size());
} }
} }

View File

@ -17,21 +17,17 @@
package org.apache.poi.xssf.usermodel; package org.apache.poi.xssf.usermodel;
import java.io.File;
import java.util.List; import java.util.List;
import junit.framework.TestCase; import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues; import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples;
public class TestXSSFBugs extends BaseTestBugzillaIssues { public final class TestXSSFBugs extends BaseTestBugzillaIssues {
@Override @Override
protected XSSFITestDataProvider getTestDataProvider(){ protected XSSFITestDataProvider getTestDataProvider(){
return XSSFITestDataProvider.getInstance(); return XSSFITestDataProvider.getInstance();

View File

@ -17,29 +17,16 @@
package org.apache.poi.xssf.usermodel; package org.apache.poi.xssf.usermodel;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
import junit.framework.TestCase;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.ss.usermodel.BaseTestDataFormat;
import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFITestDataProvider;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType;
/** /**
* Tests for {@link XSSFDataFormat} * Tests for {@link XSSFDataFormat}
* *
*/ */
public final class TestXSSFDataFormat extends BaseTestDataFormat { public final class TestXSSFDataFormat extends BaseTestDataFormat {
@Override @Override
protected ITestDataProvider getTestDataProvider(){ protected ITestDataProvider getTestDataProvider(){
return XSSFITestDataProvider.getInstance(); return XSSFITestDataProvider.getInstance();

View File

@ -17,12 +17,8 @@
package org.apache.poi.xssf.usermodel; package org.apache.poi.xssf.usermodel;
import junit.framework.TestCase;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
@ -38,14 +34,14 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignRun;
public final class TestXSSFFont extends BaseTestFont{ public final class TestXSSFFont extends BaseTestFont{
@Override @Override
protected XSSFITestDataProvider getTestDataProvider(){ protected XSSFITestDataProvider getTestDataProvider() {
return XSSFITestDataProvider.getInstance(); return XSSFITestDataProvider.getInstance();
} }
public void testDefaultFont() { public void testDefaultFont() {
baseTestDefaultFont("Calibri", (short)220, IndexedColors.BLACK.getIndex()); baseTestDefaultFont("Calibri", (short) 220, IndexedColors.BLACK.getIndex());
} }
public void testConstructor() { public void testConstructor() {
XSSFFont xssfFont=new XSSFFont(); XSSFFont xssfFont=new XSSFFont();
@ -160,7 +156,7 @@ public final class TestXSSFFont extends BaseTestFont{
xssfFont.setUnderline(Font.U_DOUBLE); xssfFont.setUnderline(Font.U_DOUBLE);
assertEquals(ctFont.getUArray().length,1); assertEquals(ctFont.getUArray().length,1);
assertEquals(STUnderlineValues.DOUBLE,ctFont.getUArray(0).getVal()); assertEquals(STUnderlineValues.DOUBLE,ctFont.getUArray(0).getVal());
xssfFont.setUnderline(FontUnderline.DOUBLE_ACCOUNTING); xssfFont.setUnderline(FontUnderline.DOUBLE_ACCOUNTING);
assertEquals(ctFont.getUArray().length,1); assertEquals(ctFont.getUArray().length,1);
assertEquals(STUnderlineValues.DOUBLE_ACCOUNTING,ctFont.getUArray(0).getVal()); assertEquals(STUnderlineValues.DOUBLE_ACCOUNTING,ctFont.getUArray(0).getVal());

View File

@ -17,7 +17,6 @@
package org.apache.poi.xssf.usermodel; package org.apache.poi.xssf.usermodel;
import junit.framework.TestCase;
import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.ss.usermodel.BaseTestNamedRange; import org.apache.poi.ss.usermodel.BaseTestNamedRange;
@ -37,7 +36,7 @@ public final class TestXSSFName extends BaseTestNamedRange {
// First test that setting RR&C for same sheet more than once only creates a // First test that setting RR&C for same sheet more than once only creates a
// single Print_Titles built-in record // single Print_Titles built-in record
XSSFWorkbook wb = getTestDataProvider().createWorkbook(); XSSFWorkbook wb = getTestDataProvider().createWorkbook();
XSSFSheet sheet = wb.createSheet("First Sheet"); wb.createSheet("First Sheet");
wb.setRepeatingRowsAndColumns(0, -1, -1, -1, -1); wb.setRepeatingRowsAndColumns(0, -1, -1, -1, -1);
@ -77,7 +76,7 @@ public final class TestXSSFName extends BaseTestNamedRange {
// check that setting RR&C on a second sheet causes a new Print_Titles built-in // check that setting RR&C on a second sheet causes a new Print_Titles built-in
// name to be created // name to be created
sheet = nwb.createSheet("SecondSheet"); nwb.createSheet("SecondSheet");
nwb.setRepeatingRowsAndColumns(1, 1, 2, 0, 0); nwb.setRepeatingRowsAndColumns(1, 1, 2, 0, 0);
assertEquals(2, nwb.getNumberOfNames()); assertEquals(2, nwb.getNumberOfNames());
@ -88,6 +87,4 @@ public final class TestXSSFName extends BaseTestNamedRange {
nwb.setRepeatingRowsAndColumns(1, -1, -1, -1, -1); nwb.setRepeatingRowsAndColumns(1, -1, -1, -1, -1);
} }
} }

View File

@ -17,7 +17,6 @@
package org.apache.poi.xssf.usermodel; package org.apache.poi.xssf.usermodel;
import junit.framework.TestCase;
import org.apache.poi.ss.usermodel.ClientAnchor; import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.BaseTestPicture; import org.apache.poi.ss.usermodel.BaseTestPicture;
import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFITestDataProvider;

View File

@ -17,14 +17,12 @@
package org.apache.poi.xssf.usermodel; package org.apache.poi.xssf.usermodel;
import junit.framework.TestCase;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.POIXMLDocumentPart;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing;
import java.util.List;
import java.util.Arrays; import java.util.Arrays;
import java.io.IOException; import java.util.List;
import junit.framework.TestCase;
import org.apache.poi.xssf.XSSFTestDataSamples;
/** /**
* @author Yegor Kozlov * @author Yegor Kozlov

View File

@ -187,13 +187,13 @@ public class TestXSSFPrintSetup extends TestCase {
pMargins.setHeader(1.5); pMargins.setHeader(1.5);
pMargins.setFooter(2); pMargins.setFooter(2);
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet); XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
assertEquals(1.5, printSetup.getHeaderMargin()); assertEquals(1.5, printSetup.getHeaderMargin(), 0.0);
assertEquals(2.0, printSetup.getFooterMargin()); assertEquals(2.0, printSetup.getFooterMargin(), 0.0);
printSetup.setHeaderMargin(5); printSetup.setHeaderMargin(5);
printSetup.setFooterMargin(3.5); printSetup.setFooterMargin(3.5);
assertEquals(5.0, pMargins.getHeader()); assertEquals(5.0, pMargins.getHeader(), 0.0);
assertEquals(3.5, pMargins.getFooter()); assertEquals(3.5, pMargins.getFooter(), 0.0);
} }
public void testSetGetCopies() { public void testSetGetCopies() {

View File

@ -17,23 +17,9 @@
package org.apache.poi.xssf.usermodel; package org.apache.poi.xssf.usermodel;
import java.io.*;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.ss.usermodel.Cell; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.model.CommentsTable;
import org.apache.xmlbeans.XmlOptions;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
/** /**
* Tests functionality of the XSSFRichTextRun object * Tests functionality of the XSSFRichTextRun object
@ -42,7 +28,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
*/ */
public final class TestXSSFRichTextString extends TestCase { public final class TestXSSFRichTextString extends TestCase {
public void testCreate() throws Exception { public void testCreate() {
XSSFRichTextString rt = new XSSFRichTextString("Apache POI"); XSSFRichTextString rt = new XSSFRichTextString("Apache POI");
assertEquals("Apache POI", rt.getString()); assertEquals("Apache POI", rt.getString());
@ -59,7 +45,7 @@ public final class TestXSSFRichTextString extends TestCase {
} }
public void testApplyFont() throws Exception { public void testApplyFont() {
XSSFRichTextString rt = new XSSFRichTextString(); XSSFRichTextString rt = new XSSFRichTextString();
rt.append("123"); rt.append("123");
@ -85,7 +71,7 @@ public final class TestXSSFRichTextString extends TestCase {
assertEquals(1, rt.getLengthOfFormattingRun(3)); assertEquals(1, rt.getLengthOfFormattingRun(3));
} }
public void testClearFormatting() throws Exception { public void testClearFormatting() {
XSSFRichTextString rt = new XSSFRichTextString("Apache POI"); XSSFRichTextString rt = new XSSFRichTextString("Apache POI");
assertEquals("Apache POI", rt.getString()); assertEquals("Apache POI", rt.getString());
@ -105,10 +91,9 @@ public final class TestXSSFRichTextString extends TestCase {
rt.clearFormatting(); rt.clearFormatting();
assertEquals("Apache POI", rt.getString()); assertEquals("Apache POI", rt.getString());
assertEquals(0, rt.numFormattingRuns()); assertEquals(0, rt.numFormattingRuns());
} }
public void testGetFonts() throws Exception { public void testGetFonts() {
XSSFRichTextString rt = new XSSFRichTextString(); XSSFRichTextString rt = new XSSFRichTextString();
@ -129,6 +114,5 @@ public final class TestXSSFRichTextString extends TestCase {
XSSFFont font2$ = rt.getFontOfFormattingRun(1); XSSFFont font2$ = rt.getFontOfFormattingRun(1);
assertEquals(font2.getBold(), font2$.getBold()); assertEquals(font2.getBold(), font2$.getBold());
assertEquals(font2.getFontName(), font2$.getFontName()); assertEquals(font2.getFontName(), font2$.getFontName());
} }
} }

View File

@ -17,21 +17,9 @@
package org.apache.poi.xssf.usermodel; package org.apache.poi.xssf.usermodel;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Iterator;
import junit.framework.TestCase;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.xssf.model.SharedStringsTable; import org.apache.poi.ss.usermodel.BaseTestRow;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFCell;
/** /**
* Tests for XSSFRow * Tests for XSSFRow

View File

@ -18,19 +18,23 @@
package org.apache.poi.xssf.usermodel; package org.apache.poi.xssf.usermodel;
import java.io.File; import java.io.File;
import java.util.Iterator;
import junit.framework.TestCase; import org.apache.poi.ss.usermodel.BaseTestSheet;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.model.CommentsTable; import org.apache.poi.xssf.model.CommentsTable;
import org.apache.poi.xssf.model.StylesTable; import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.model.CalculationChain;
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper; import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
import org.apache.poi.xssf.XSSFTestDataSamples; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
import org.apache.poi.xssf.XSSFITestDataProvider; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPane;
public class TestXSSFSheet extends BaseTestSheet { public class TestXSSFSheet extends BaseTestSheet {
@ -205,14 +209,14 @@ public class TestXSSFSheet extends BaseTestSheet {
CTWorksheet ctWorksheet = sheet.getCTWorksheet(); CTWorksheet ctWorksheet = sheet.getCTWorksheet();
sheet.createFreezePane(2, 4); sheet.createFreezePane(2, 4);
assertEquals((double) 2, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getXSplit()); assertEquals(2.0, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getXSplit(), 0.0);
assertEquals(STPane.BOTTOM_RIGHT, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getActivePane()); assertEquals(STPane.BOTTOM_RIGHT, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getActivePane());
sheet.createFreezePane(3, 6, 10, 10); sheet.createFreezePane(3, 6, 10, 10);
assertEquals((double) 3, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getXSplit()); assertEquals(3.0, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getXSplit(), 0.0);
// assertEquals(10, sheet.getTopRow()); // assertEquals(10, sheet.getTopRow());
// assertEquals(10, sheet.getLeftCol()); // assertEquals(10, sheet.getLeftCol());
sheet.createSplitPane(4, 8, 12, 12, 1); sheet.createSplitPane(4, 8, 12, 12, 1);
assertEquals((double) 8, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getYSplit()); assertEquals(8.0, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getYSplit(), 0.0);
assertEquals(STPane.BOTTOM_RIGHT, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getActivePane()); assertEquals(STPane.BOTTOM_RIGHT, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getActivePane());
} }
@ -375,15 +379,15 @@ public class TestXSSFSheet extends BaseTestSheet {
public void testSetColumnGroupCollapsed(){ public void testSetColumnGroupCollapsed(){
Workbook wb = new XSSFWorkbook(); Workbook wb = new XSSFWorkbook();
XSSFSheet sheet1 =(XSSFSheet) wb.createSheet(); XSSFSheet sheet1 =(XSSFSheet) wb.createSheet();
CTCols cols=sheet1.getCTWorksheet().getColsArray(0); CTCols cols=sheet1.getCTWorksheet().getColsArray(0);
assertEquals(0,cols.sizeOfColArray()); assertEquals(0,cols.sizeOfColArray());
sheet1.groupColumn( (short)4, (short)7 ); sheet1.groupColumn( (short)4, (short)7 );
sheet1.groupColumn( (short)9, (short)12 ); sheet1.groupColumn( (short)9, (short)12 );
assertEquals(2,cols.sizeOfColArray()); assertEquals(2,cols.sizeOfColArray());
assertEquals(false,cols.getColArray(0).isSetHidden()); assertEquals(false,cols.getColArray(0).isSetHidden());
assertEquals(true, cols.getColArray(0).isSetCollapsed()); assertEquals(true, cols.getColArray(0).isSetCollapsed());
assertEquals(5, cols.getColArray(0).getMin()); // 1 based assertEquals(5, cols.getColArray(0).getMin()); // 1 based
@ -395,7 +399,7 @@ public class TestXSSFSheet extends BaseTestSheet {
sheet1.groupColumn( (short)10, (short)11 ); sheet1.groupColumn( (short)10, (short)11 );
assertEquals(4,cols.sizeOfColArray()); assertEquals(4,cols.sizeOfColArray());
assertEquals(false,cols.getColArray(0).isSetHidden()); assertEquals(false,cols.getColArray(0).isSetHidden());
assertEquals(true, cols.getColArray(0).isSetCollapsed()); assertEquals(true, cols.getColArray(0).isSetCollapsed());
assertEquals(5, cols.getColArray(0).getMin()); // 1 based assertEquals(5, cols.getColArray(0).getMin()); // 1 based
@ -412,11 +416,11 @@ public class TestXSSFSheet extends BaseTestSheet {
assertEquals(true, cols.getColArray(3).isSetCollapsed()); assertEquals(true, cols.getColArray(3).isSetCollapsed());
assertEquals(13, cols.getColArray(3).getMin()); // 1 based assertEquals(13, cols.getColArray(3).getMin()); // 1 based
assertEquals(13, cols.getColArray(3).getMax()); // 1 based assertEquals(13, cols.getColArray(3).getMax()); // 1 based
// collapse columns - 1 // collapse columns - 1
sheet1.setColumnGroupCollapsed( (short)5, true ); sheet1.setColumnGroupCollapsed( (short)5, true );
assertEquals(5,cols.sizeOfColArray()); assertEquals(5,cols.sizeOfColArray());
assertEquals(true, cols.getColArray(0).isSetHidden()); assertEquals(true, cols.getColArray(0).isSetHidden());
assertEquals(true, cols.getColArray(0).isSetCollapsed()); assertEquals(true, cols.getColArray(0).isSetCollapsed());
assertEquals(5, cols.getColArray(0).getMin()); // 1 based assertEquals(5, cols.getColArray(0).getMin()); // 1 based
@ -501,7 +505,7 @@ public class TestXSSFSheet extends BaseTestSheet {
//outline level 2: the line under ==> collapsed==True //outline level 2: the line under ==> collapsed==True
assertEquals(2,cols.getColArray(3).getOutlineLevel()); assertEquals(2,cols.getColArray(3).getOutlineLevel());
assertEquals(true,cols.getColArray(4).isSetCollapsed()); assertEquals(true,cols.getColArray(4).isSetCollapsed());
assertEquals(false,cols.getColArray(0).isSetHidden()); assertEquals(false,cols.getColArray(0).isSetHidden());
assertEquals(true, cols.getColArray(0).isSetCollapsed()); assertEquals(true, cols.getColArray(0).isSetCollapsed());
assertEquals(5, cols.getColArray(0).getMin()); // 1 based assertEquals(5, cols.getColArray(0).getMin()); // 1 based
@ -610,7 +614,7 @@ public class TestXSSFSheet extends BaseTestSheet {
sheet1.groupRow( 7, 14 ); sheet1.groupRow( 7, 14 );
sheet1.groupRow( 16, 19 ); sheet1.groupRow( 16, 19 );
assertEquals(14,sheet1.getPhysicalNumberOfRows()); assertEquals(14,sheet1.getPhysicalNumberOfRows());
assertEquals(false,sheet1.getRow(6).getCTRow().isSetCollapsed()); assertEquals(false,sheet1.getRow(6).getCTRow().isSetCollapsed());
assertEquals(false,sheet1.getRow(6).getCTRow().isSetHidden()); assertEquals(false,sheet1.getRow(6).getCTRow().isSetHidden());
assertEquals(false,sheet1.getRow(7).getCTRow().isSetCollapsed()); assertEquals(false,sheet1.getRow(7).getCTRow().isSetCollapsed());
@ -625,7 +629,7 @@ public class TestXSSFSheet extends BaseTestSheet {
assertEquals(false,sheet1.getRow(18).getCTRow().isSetHidden()); assertEquals(false,sheet1.getRow(18).getCTRow().isSetHidden());
//collapsed //collapsed
sheet1.setRowGroupCollapsed( 7, true ); sheet1.setRowGroupCollapsed( 7, true );
assertEquals(false,sheet1.getRow(6).getCTRow().isSetCollapsed()); assertEquals(false,sheet1.getRow(6).getCTRow().isSetCollapsed());
assertEquals(false,sheet1.getRow(6).getCTRow().isSetHidden()); assertEquals(false,sheet1.getRow(6).getCTRow().isSetHidden());
@ -698,7 +702,7 @@ public class TestXSSFSheet extends BaseTestSheet {
// XML is 1 based, POI is 0 based // XML is 1 based, POI is 0 based
assertEquals(2, col.getMin()); assertEquals(2, col.getMin());
assertEquals(2, col.getMax()); assertEquals(2, col.getMax());
assertEquals(22.0, col.getWidth()); assertEquals(22.0, col.getWidth(), 0.0);
// Now set another // Now set another
sheet.setColumnWidth(3, 33 * 256); sheet.setColumnWidth(3, 33 * 256);
@ -711,12 +715,11 @@ public class TestXSSFSheet extends BaseTestSheet {
col = cols.getColArray(0); col = cols.getColArray(0);
assertEquals(2, col.getMin()); // POI 1 assertEquals(2, col.getMin()); // POI 1
assertEquals(2, col.getMax()); assertEquals(2, col.getMax());
assertEquals(22.0, col.getWidth()); assertEquals(22.0, col.getWidth(), 0.0);
col = cols.getColArray(1); col = cols.getColArray(1);
assertEquals(4, col.getMin()); // POI 3 assertEquals(4, col.getMin()); // POI 3
assertEquals(4, col.getMax()); assertEquals(4, col.getMax());
assertEquals(33.0, col.getWidth()); assertEquals(33.0, col.getWidth(), 0.0);
} }
} }

View File

@ -20,31 +20,26 @@ package org.apache.poi.xssf.usermodel;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.zip.CRC32;
import java.util.List; import java.util.List;
import java.util.zip.CRC32;
import junit.framework.TestCase; import org.apache.poi.POIXMLProperties;
import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.openxml4j.opc.*; import org.apache.poi.openxml4j.opc.*;
import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart; import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.util.TempFile; import org.apache.poi.util.TempFile;
import org.apache.poi.POIXMLProperties; import org.apache.poi.xssf.XSSFITestDataProvider;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet; import org.apache.poi.xssf.XSSFTestDataSamples;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook; import org.apache.poi.xssf.model.StylesTable;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbookPr; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbookPr;
public final class TestXSSFWorkbook extends BaseTestWorkbook { public final class TestXSSFWorkbook extends BaseTestWorkbook {
@Override @Override
protected XSSFITestDataProvider getTestDataProvider(){ protected XSSFITestDataProvider getTestDataProvider(){
return XSSFITestDataProvider.getInstance(); return XSSFITestDataProvider.getInstance();
} }
/** /**
@ -53,94 +48,94 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
public void testSaveLoadNew() throws Exception { public void testSaveLoadNew() throws Exception {
XSSFWorkbook workbook = new XSSFWorkbook(); XSSFWorkbook workbook = new XSSFWorkbook();
//check that the default date system is set to 1900 //check that the default date system is set to 1900
CTWorkbookPr pr = workbook.getCTWorkbook().getWorkbookPr(); CTWorkbookPr pr = workbook.getCTWorkbook().getWorkbookPr();
assertNotNull(pr); assertNotNull(pr);
assertTrue(pr.isSetDate1904()); assertTrue(pr.isSetDate1904());
assertFalse("XSSF must use the 1900 date system", pr.getDate1904()); assertFalse("XSSF must use the 1900 date system", pr.getDate1904());
Sheet sheet1 = workbook.createSheet("sheet1"); Sheet sheet1 = workbook.createSheet("sheet1");
Sheet sheet2 = workbook.createSheet("sheet2"); Sheet sheet2 = workbook.createSheet("sheet2");
workbook.createSheet("sheet3"); workbook.createSheet("sheet3");
RichTextString rts = workbook.getCreationHelper().createRichTextString("hello world"); RichTextString rts = workbook.getCreationHelper().createRichTextString("hello world");
sheet1.createRow(0).createCell((short)0).setCellValue(1.2); sheet1.createRow(0).createCell((short)0).setCellValue(1.2);
sheet1.createRow(1).createCell((short)0).setCellValue(rts); sheet1.createRow(1).createCell((short)0).setCellValue(rts);
sheet2.createRow(0); sheet2.createRow(0);
assertEquals(0, workbook.getSheetAt(0).getFirstRowNum()); assertEquals(0, workbook.getSheetAt(0).getFirstRowNum());
assertEquals(1, workbook.getSheetAt(0).getLastRowNum()); assertEquals(1, workbook.getSheetAt(0).getLastRowNum());
assertEquals(0, workbook.getSheetAt(1).getFirstRowNum()); assertEquals(0, workbook.getSheetAt(1).getFirstRowNum());
assertEquals(0, workbook.getSheetAt(1).getLastRowNum()); assertEquals(0, workbook.getSheetAt(1).getLastRowNum());
assertEquals(0, workbook.getSheetAt(2).getFirstRowNum()); assertEquals(0, workbook.getSheetAt(2).getFirstRowNum());
assertEquals(0, workbook.getSheetAt(2).getLastRowNum()); assertEquals(0, workbook.getSheetAt(2).getLastRowNum());
File file = TempFile.createTempFile("poi-", ".xlsx"); File file = TempFile.createTempFile("poi-", ".xlsx");
OutputStream out = new FileOutputStream(file); OutputStream out = new FileOutputStream(file);
workbook.write(out); workbook.write(out);
out.close(); out.close();
// Check the package contains what we'd expect it to // Check the package contains what we'd expect it to
OPCPackage pkg = OPCPackage.open(file.toString()); OPCPackage pkg = OPCPackage.open(file.toString());
PackagePart wbRelPart = PackagePart wbRelPart =
pkg.getPart(PackagingURIHelper.createPartName("/xl/_rels/workbook.xml.rels")); pkg.getPart(PackagingURIHelper.createPartName("/xl/_rels/workbook.xml.rels"));
assertNotNull(wbRelPart); assertNotNull(wbRelPart);
assertTrue(wbRelPart.isRelationshipPart()); assertTrue(wbRelPart.isRelationshipPart());
assertEquals(ContentTypes.RELATIONSHIPS_PART, wbRelPart.getContentType()); assertEquals(ContentTypes.RELATIONSHIPS_PART, wbRelPart.getContentType());
PackagePart wbPart = PackagePart wbPart =
pkg.getPart(PackagingURIHelper.createPartName("/xl/workbook.xml")); pkg.getPart(PackagingURIHelper.createPartName("/xl/workbook.xml"));
// Links to the three sheets, shared strings and styles // Links to the three sheets, shared strings and styles
assertTrue(wbPart.hasRelationships()); assertTrue(wbPart.hasRelationships());
assertEquals(5, wbPart.getRelationships().size()); assertEquals(5, wbPart.getRelationships().size());
// Load back the XSSFWorkbook // Load back the XSSFWorkbook
workbook = new XSSFWorkbook(pkg); workbook = new XSSFWorkbook(pkg);
assertEquals(3, workbook.getNumberOfSheets()); assertEquals(3, workbook.getNumberOfSheets());
assertNotNull(workbook.getSheetAt(0)); assertNotNull(workbook.getSheetAt(0));
assertNotNull(workbook.getSheetAt(1)); assertNotNull(workbook.getSheetAt(1));
assertNotNull(workbook.getSheetAt(2)); assertNotNull(workbook.getSheetAt(2));
assertNotNull(workbook.getSharedStringSource()); assertNotNull(workbook.getSharedStringSource());
assertNotNull(workbook.getStylesSource()); assertNotNull(workbook.getStylesSource());
assertEquals(0, workbook.getSheetAt(0).getFirstRowNum()); assertEquals(0, workbook.getSheetAt(0).getFirstRowNum());
assertEquals(1, workbook.getSheetAt(0).getLastRowNum()); assertEquals(1, workbook.getSheetAt(0).getLastRowNum());
assertEquals(0, workbook.getSheetAt(1).getFirstRowNum()); assertEquals(0, workbook.getSheetAt(1).getFirstRowNum());
assertEquals(0, workbook.getSheetAt(1).getLastRowNum()); assertEquals(0, workbook.getSheetAt(1).getLastRowNum());
assertEquals(0, workbook.getSheetAt(2).getFirstRowNum()); assertEquals(0, workbook.getSheetAt(2).getFirstRowNum());
assertEquals(0, workbook.getSheetAt(2).getLastRowNum()); assertEquals(0, workbook.getSheetAt(2).getLastRowNum());
sheet1 = workbook.getSheetAt(0); sheet1 = workbook.getSheetAt(0);
assertEquals(1.2, sheet1.getRow(0).getCell(0).getNumericCellValue(), 0.0001); assertEquals(1.2, sheet1.getRow(0).getCell(0).getNumericCellValue(), 0.0001);
assertEquals("hello world", sheet1.getRow(1).getCell(0).getRichStringCellValue().getString()); assertEquals("hello world", sheet1.getRow(1).getCell(0).getRichStringCellValue().getString());
} }
public void testExisting() throws Exception { public void testExisting() throws Exception {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx"); XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
assertNotNull(workbook.getSharedStringSource()); assertNotNull(workbook.getSharedStringSource());
assertNotNull(workbook.getStylesSource()); assertNotNull(workbook.getStylesSource());
// And check a few low level bits too // And check a few low level bits too
OPCPackage pkg = OPCPackage.open(HSSFTestDataSamples.openSampleFileStream("Formatting.xlsx")); OPCPackage pkg = OPCPackage.open(HSSFTestDataSamples.openSampleFileStream("Formatting.xlsx"));
PackagePart wbPart = PackagePart wbPart =
pkg.getPart(PackagingURIHelper.createPartName("/xl/workbook.xml")); pkg.getPart(PackagingURIHelper.createPartName("/xl/workbook.xml"));
// Links to the three sheets, shared, styles and themes // Links to the three sheets, shared, styles and themes
assertTrue(wbPart.hasRelationships()); assertTrue(wbPart.hasRelationships());
assertEquals(6, wbPart.getRelationships().size()); assertEquals(6, wbPart.getRelationships().size());
} }
public void testGetCellStyleAt(){ public void testGetCellStyleAt(){
XSSFWorkbook workbook = new XSSFWorkbook(); XSSFWorkbook workbook = new XSSFWorkbook();
short i = 0; short i = 0;
//get default style //get default style
CellStyle cellStyleAt = workbook.getCellStyleAt(i); CellStyle cellStyleAt = workbook.getCellStyleAt(i);
assertNotNull(cellStyleAt); assertNotNull(cellStyleAt);
//get custom style //get custom style
StylesTable styleSource = workbook.getStylesSource(); StylesTable styleSource = workbook.getStylesSource();
XSSFCellStyle customStyle = new XSSFCellStyle(styleSource); XSSFCellStyle customStyle = new XSSFCellStyle(styleSource);
@ -149,9 +144,9 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
customStyle.setFont(font); customStyle.setFont(font);
int x = styleSource.putStyle(customStyle); int x = styleSource.putStyle(customStyle);
cellStyleAt = workbook.getCellStyleAt((short)x); cellStyleAt = workbook.getCellStyleAt((short)x);
assertNotNull(cellStyleAt); assertNotNull(cellStyleAt);
} }
public void testGetFontAt(){ public void testGetFontAt(){
XSSFWorkbook workbook = new XSSFWorkbook(); XSSFWorkbook workbook = new XSSFWorkbook();
StylesTable styleSource = workbook.getStylesSource(); StylesTable styleSource = workbook.getStylesSource();
@ -159,7 +154,7 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
//get default font //get default font
Font fontAt = workbook.getFontAt(i); Font fontAt = workbook.getFontAt(i);
assertNotNull(fontAt); assertNotNull(fontAt);
//get customized font //get customized font
XSSFFont customFont = new XSSFFont(); XSSFFont customFont = new XSSFFont();
customFont.setItalic(true); customFont.setItalic(true);
@ -167,23 +162,23 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
fontAt = workbook.getFontAt((short)x); fontAt = workbook.getFontAt((short)x);
assertNotNull(fontAt); assertNotNull(fontAt);
} }
public void testGetNumCellStyles(){ public void testGetNumCellStyles(){
XSSFWorkbook workbook = new XSSFWorkbook(); XSSFWorkbook workbook = new XSSFWorkbook();
short i = workbook.getNumCellStyles(); short i = workbook.getNumCellStyles();
//get default cellStyles //get default cellStyles
assertEquals(1, i); assertEquals(1, i);
//get wrong value //get wrong value
assertNotSame(2, i); assertNotSame(2, i);
} }
public void testLoadSave() { public void testLoadSave() {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx"); XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
assertEquals(3, workbook.getNumberOfSheets()); assertEquals(3, workbook.getNumberOfSheets());
assertEquals("dd/mm/yyyy", workbook.getSheetAt(0).getRow(1).getCell(0).getRichStringCellValue().getString()); assertEquals("dd/mm/yyyy", workbook.getSheetAt(0).getRow(1).getCell(0).getRichStringCellValue().getString());
assertNotNull(workbook.getSharedStringSource()); assertNotNull(workbook.getSharedStringSource());
assertNotNull(workbook.getStylesSource()); assertNotNull(workbook.getStylesSource());
// Write out, and check // Write out, and check
// Load up again, check all still there // Load up again, check all still there
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(workbook); XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(workbook);
@ -191,7 +186,7 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
assertNotNull(wb2.getSheetAt(0)); assertNotNull(wb2.getSheetAt(0));
assertNotNull(wb2.getSheetAt(1)); assertNotNull(wb2.getSheetAt(1));
assertNotNull(wb2.getSheetAt(2)); assertNotNull(wb2.getSheetAt(2));
assertEquals("dd/mm/yyyy", wb2.getSheetAt(0).getRow(1).getCell(0).getRichStringCellValue().getString()); assertEquals("dd/mm/yyyy", wb2.getSheetAt(0).getRow(1).getCell(0).getRichStringCellValue().getString());
assertEquals("yyyy/mm/dd", wb2.getSheetAt(0).getRow(2).getCell(0).getRichStringCellValue().getString()); assertEquals("yyyy/mm/dd", wb2.getSheetAt(0).getRow(2).getCell(0).getRichStringCellValue().getString());
assertEquals("yyyy-mm-dd", wb2.getSheetAt(0).getRow(3).getCell(0).getRichStringCellValue().getString()); assertEquals("yyyy-mm-dd", wb2.getSheetAt(0).getRow(3).getCell(0).getRichStringCellValue().getString());
@ -199,14 +194,14 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
assertNotNull(wb2.getSharedStringSource()); assertNotNull(wb2.getSharedStringSource());
assertNotNull(wb2.getStylesSource()); assertNotNull(wb2.getStylesSource());
} }
public void testStyles() { public void testStyles() {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx"); XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
StylesTable ss = workbook.getStylesSource(); StylesTable ss = workbook.getStylesSource();
assertNotNull(ss); assertNotNull(ss);
StylesTable st = ss; StylesTable st = ss;
// Has 8 number formats // Has 8 number formats
assertEquals(8, st._getNumberFormatSize()); assertEquals(8, st._getNumberFormatSize());
// Has 2 fonts // Has 2 fonts
@ -215,20 +210,20 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
assertEquals(2, st.getFills().size()); assertEquals(2, st.getFills().size());
// Has 1 border // Has 1 border
assertEquals(1, st.getBorders().size()); assertEquals(1, st.getBorders().size());
// Add two more styles // Add two more styles
assertEquals(StylesTable.FIRST_CUSTOM_STYLE_ID + 8, assertEquals(StylesTable.FIRST_CUSTOM_STYLE_ID + 8,
st.putNumberFormat("testFORMAT")); st.putNumberFormat("testFORMAT"));
assertEquals(StylesTable.FIRST_CUSTOM_STYLE_ID + 8, assertEquals(StylesTable.FIRST_CUSTOM_STYLE_ID + 8,
st.putNumberFormat("testFORMAT")); st.putNumberFormat("testFORMAT"));
assertEquals(StylesTable.FIRST_CUSTOM_STYLE_ID + 9, assertEquals(StylesTable.FIRST_CUSTOM_STYLE_ID + 9,
st.putNumberFormat("testFORMAT2")); st.putNumberFormat("testFORMAT2"));
assertEquals(10, st._getNumberFormatSize()); assertEquals(10, st._getNumberFormatSize());
// Save, load back in again, and check // Save, load back in again, and check
workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook); workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
ss = workbook.getStylesSource(); ss = workbook.getStylesSource();
assertNotNull(ss); assertNotNull(ss);
@ -238,77 +233,77 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
assertEquals(1, st.getBorders().size()); assertEquals(1, st.getBorders().size());
} }
public void testIncrementSheetId() throws Exception { public void testIncrementSheetId() {
XSSFWorkbook wb = getTestDataProvider().createWorkbook(); XSSFWorkbook wb = getTestDataProvider().createWorkbook();
int sheetId = (int)wb.createSheet().sheet.getSheetId(); int sheetId = (int)wb.createSheet().sheet.getSheetId();
assertEquals(1, sheetId); assertEquals(1, sheetId);
sheetId = (int)wb.createSheet().sheet.getSheetId(); sheetId = (int)wb.createSheet().sheet.getSheetId();
assertEquals(2, sheetId); assertEquals(2, sheetId);
//test file with gaps in the sheetId sequence //test file with gaps in the sheetId sequence
wb = getTestDataProvider().openSampleWorkbook("47089.xlsm"); wb = getTestDataProvider().openSampleWorkbook("47089.xlsm");
int lastSheetId = (int)wb.getSheetAt(wb.getNumberOfSheets() - 1).sheet.getSheetId(); int lastSheetId = (int)wb.getSheetAt(wb.getNumberOfSheets() - 1).sheet.getSheetId();
sheetId = (int)wb.createSheet().sheet.getSheetId(); sheetId = (int)wb.createSheet().sheet.getSheetId();
assertEquals(lastSheetId+1, sheetId); assertEquals(lastSheetId+1, sheetId);
} }
/** /**
* Test setting of core properties such as Title and Author * Test setting of core properties such as Title and Author
*/ */
public void testWorkbookProperties() throws Exception { public void testWorkbookProperties() {
XSSFWorkbook workbook = new XSSFWorkbook(); XSSFWorkbook workbook = new XSSFWorkbook();
POIXMLProperties props = workbook.getProperties(); POIXMLProperties props = workbook.getProperties();
assertNotNull(props); assertNotNull(props);
//the Application property must be set for new workbooks, see Bugzilla #47559 //the Application property must be set for new workbooks, see Bugzilla #47559
assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication()); assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());
PackagePropertiesPart opcProps = props.getCoreProperties().getUnderlyingProperties(); PackagePropertiesPart opcProps = props.getCoreProperties().getUnderlyingProperties();
assertNotNull(opcProps); assertNotNull(opcProps);
opcProps.setTitleProperty("Testing Bugzilla #47460"); opcProps.setTitleProperty("Testing Bugzilla #47460");
assertEquals("Apache POI", opcProps.getCreatorProperty().getValue()); assertEquals("Apache POI", opcProps.getCreatorProperty().getValue());
opcProps.setCreatorProperty("poi-dev@poi.apache.org"); opcProps.setCreatorProperty("poi-dev@poi.apache.org");
workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook); workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
assertEquals("Apache POI", workbook.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication()); assertEquals("Apache POI", workbook.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
opcProps = workbook.getProperties().getCoreProperties().getUnderlyingProperties(); opcProps = workbook.getProperties().getCoreProperties().getUnderlyingProperties();
assertEquals("Testing Bugzilla #47460", opcProps.getTitleProperty().getValue()); assertEquals("Testing Bugzilla #47460", opcProps.getTitleProperty().getValue());
assertEquals("poi-dev@poi.apache.org", opcProps.getCreatorProperty().getValue()); assertEquals("poi-dev@poi.apache.org", opcProps.getCreatorProperty().getValue());
} }
/** /**
* Verify that the attached test data was not modified. If this test method * Verify that the attached test data was not modified. If this test method
* fails, the test data is not working properly. * fails, the test data is not working properly.
*/ */
public void test47668() throws Exception { public void test47668() throws Exception {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("47668.xlsx"); XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("47668.xlsx");
List<XSSFPictureData> allPictures = workbook.getAllPictures(); List<XSSFPictureData> allPictures = workbook.getAllPictures();
assertEquals(2, allPictures.size()); assertEquals(2, allPictures.size());
PackagePartName imagePartName = PackagingURIHelper PackagePartName imagePartName = PackagingURIHelper
.createPartName("/xl/media/image1.jpeg"); .createPartName("/xl/media/image1.jpeg");
PackagePart imagePart = workbook.getPackage().getPart(imagePartName); PackagePart imagePart = workbook.getPackage().getPart(imagePartName);
assertNotNull(imagePart); assertNotNull(imagePart);
for (XSSFPictureData pictureData : allPictures) { for (XSSFPictureData pictureData : allPictures) {
PackagePart picturePart = pictureData.getPackagePart(); PackagePart picturePart = pictureData.getPackagePart();
assertSame(imagePart, picturePart); assertSame(imagePart, picturePart);
} }
XSSFSheet sheet0 = workbook.getSheetAt(0); XSSFSheet sheet0 = workbook.getSheetAt(0);
XSSFDrawing drawing0 = sheet0.createDrawingPatriarch(); XSSFDrawing drawing0 = sheet0.createDrawingPatriarch();
XSSFPictureData pictureData0 = (XSSFPictureData) drawing0.getRelations().get(0); XSSFPictureData pictureData0 = (XSSFPictureData) drawing0.getRelations().get(0);
byte[] data0 = pictureData0.getData(); byte[] data0 = pictureData0.getData();
CRC32 crc0 = new CRC32(); CRC32 crc0 = new CRC32();
crc0.update(data0); crc0.update(data0);
XSSFSheet sheet1 = workbook.getSheetAt(1); XSSFSheet sheet1 = workbook.getSheetAt(1);
XSSFDrawing drawing1 = sheet1.createDrawingPatriarch(); XSSFDrawing drawing1 = sheet1.createDrawingPatriarch();
XSSFPictureData pictureData1 = (XSSFPictureData) drawing1.getRelations().get(0); XSSFPictureData pictureData1 = (XSSFPictureData) drawing1.getRelations().get(0);
byte[] data1 = pictureData1.getData(); byte[] data1 = pictureData1.getData();
CRC32 crc1 = new CRC32(); CRC32 crc1 = new CRC32();
crc1.update(data1); crc1.update(data1);
assertEquals(crc0.getValue(), crc1.getValue()); assertEquals(crc0.getValue(), crc1.getValue());
} }
} }

View File

@ -22,11 +22,10 @@ import java.util.Arrays;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
public class TestCTColComparator extends TestCase { public final class TestCTColComparator extends TestCase {
public void testCompare() { public void testCompare() {
CTColComparator comparator = new CTColComparator(); CTColComparator comparator = new CTColComparator();
CTCol o1 = CTCol.Factory.newInstance(); CTCol o1 = CTCol.Factory.newInstance();
@ -44,7 +43,7 @@ public class TestCTColComparator extends TestCase {
o4.setMax(80); o4.setMax(80);
assertEquals(-1, comparator.compare(o3, o4)); assertEquals(-1, comparator.compare(o3, o4));
} }
public void testArraysSort() { public void testArraysSort() {
CTColComparator comparator = new CTColComparator(); CTColComparator comparator = new CTColComparator();
CTCol o1 = CTCol.Factory.newInstance(); CTCol o1 = CTCol.Factory.newInstance();
@ -73,5 +72,4 @@ public class TestCTColComparator extends TestCase {
assertEquals(8, cols[1].getMax()); assertEquals(8, cols[1].getMax());
assertEquals(80, cols[2].getMax()); assertEquals(80, cols[2].getMax());
} }
} }

View File

@ -21,7 +21,7 @@ import java.math.BigInteger;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.openxmlformats.schemas.officeDocument.x2006.math.STSpacingRule; import org.apache.poi.POIXMLDocument;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTInd; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTInd;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc;
@ -40,29 +40,27 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
/** /**
* Tests for XWPF Paragraphs * Tests for XWPF Paragraphs
*/ */
public class TestXWPFParagraph extends TestCase { public final class TestXWPFParagraph extends TestCase {
/** /**
* A simple file * A simple file
*/ */
private XWPFDocument xml; private XWPFDocument xml;
private File file;
/*
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
file = new File( File file = new File(
System.getProperty("HWPF.testdata.path") + System.getProperty("HWPF.testdata.path") +
File.separator + "ThreeColHead.docx" File.separator + "ThreeColHead.docx"
); );
assertTrue(file.exists()); assertTrue(file.exists());
xml = new XWPFDocument(POIXMLDocument.openPackage(file.toString())); xml = new XWPFDocument(POIXMLDocument.openPackage(file.toString()));
} }
*/
/** /**
* Check that we get the right paragraph from the header * Check that we get the right paragraph from the header
*/ */
/* public void disabled_testHeaderParagraph() {
public void testHeaderParagraph() throws Exception {
XWPFHeader hdr = xml.getHeaderFooterPolicy().getDefaultHeader(); XWPFHeader hdr = xml.getHeaderFooterPolicy().getDefaultHeader();
assertNotNull(hdr); assertNotNull(hdr);
@ -74,12 +72,11 @@ public class TestXWPFParagraph extends TestCase {
assertEquals("First header column!\tMid header\tRight header!", p assertEquals("First header column!\tMid header\tRight header!", p
.getText()); .getText());
} }
*/
/** /**
* Check that we get the right paragraphs from the document * Check that we get the right paragraphs from the document
*/ */
/* public void disabled_testDocumentParagraph() {
public void testDocumentParagraph() throws Exception {
XWPFParagraph[] ps = xml.getParagraphs(); XWPFParagraph[] ps = xml.getParagraphs();
assertEquals(10, ps.length); assertEquals(10, ps.length);
@ -100,23 +97,23 @@ public class TestXWPFParagraph extends TestCase {
assertFalse(ps[4].isEmpty()); assertFalse(ps[4].isEmpty());
assertEquals("More on page one", ps[4].getText()); assertEquals("More on page one", ps[4].getText());
} }
*/
public void testSetGetBorderTop() { public void testSetGetBorderTop() {
//new clean instance of paragraph //new clean instance of paragraph
XWPFDocument doc = new XWPFDocument(); XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph(); XWPFParagraph p = doc.createParagraph();
assertEquals(STBorder.NONE.intValue(), p.getBorderTop().getValue()); assertEquals(STBorder.NONE.intValue(), p.getBorderTop().getValue());
CTP ctp = p.getCTP(); CTP ctp = p.getCTP();
CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr(); CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr();
//bordi //bordi
CTPBdr bdr = ppr.addNewPBdr(); CTPBdr bdr = ppr.addNewPBdr();
CTBorder borderTop = bdr.addNewTop(); CTBorder borderTop = bdr.addNewTop();
borderTop.setVal(STBorder.DOUBLE); borderTop.setVal(STBorder.DOUBLE);
bdr.setTop(borderTop); bdr.setTop(borderTop);
assertEquals(Borders.DOUBLE, p.getBorderTop()); assertEquals(Borders.DOUBLE, p.getBorderTop());
p.setBorderTop(Borders.SINGLE); p.setBorderTop(Borders.SINGLE);
assertEquals(STBorder.SINGLE, borderTop.getVal()); assertEquals(STBorder.SINGLE, borderTop.getVal());
@ -128,7 +125,7 @@ public class TestXWPFParagraph extends TestCase {
XWPFParagraph p = doc.createParagraph(); XWPFParagraph p = doc.createParagraph();
assertEquals(STJc.LEFT.intValue(), p.getAlignment().getValue()); assertEquals(STJc.LEFT.intValue(), p.getAlignment().getValue());
CTP ctp = p.getCTP(); CTP ctp = p.getCTP();
CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr(); CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr();
@ -140,7 +137,7 @@ public class TestXWPFParagraph extends TestCase {
assertEquals(STJc.BOTH, ppr.getJc().getVal()); assertEquals(STJc.BOTH, ppr.getJc().getVal());
} }
public void testSetGetSpacing() { public void testSetGetSpacing() {
XWPFDocument doc = new XWPFDocument(); XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph(); XWPFParagraph p = doc.createParagraph();
@ -149,7 +146,7 @@ public class TestXWPFParagraph extends TestCase {
CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr(); CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr();
assertEquals(-1, p.getSpacingAfter()); assertEquals(-1, p.getSpacingAfter());
CTSpacing spacing = ppr.addNewSpacing(); CTSpacing spacing = ppr.addNewSpacing();
spacing.setAfter(new BigInteger("10")); spacing.setAfter(new BigInteger("10"));
assertEquals(10, p.getSpacingAfter()); assertEquals(10, p.getSpacingAfter());
@ -166,7 +163,7 @@ public class TestXWPFParagraph extends TestCase {
CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr(); CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr();
assertEquals(STLineSpacingRule.INT_AUTO, p.getSpacingLineRule().getValue()); assertEquals(STLineSpacingRule.INT_AUTO, p.getSpacingLineRule().getValue());
CTSpacing spacing = ppr.addNewSpacing(); CTSpacing spacing = ppr.addNewSpacing();
spacing.setLineRule(STLineSpacingRule.AT_LEAST); spacing.setLineRule(STLineSpacingRule.AT_LEAST);
assertEquals(LineSpacingRule.AT_LEAST, p.getSpacingLineRule()); assertEquals(LineSpacingRule.AT_LEAST, p.getSpacingLineRule());
@ -174,18 +171,18 @@ public class TestXWPFParagraph extends TestCase {
p.setSpacingAfter(100); p.setSpacingAfter(100);
assertEquals(100, spacing.getAfter().intValue()); assertEquals(100, spacing.getAfter().intValue());
} }
public void testSetGetIndentation() { public void testSetGetIndentation() {
XWPFDocument doc = new XWPFDocument(); XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph(); XWPFParagraph p = doc.createParagraph();
assertEquals(-1, p.getIndentationLeft()); assertEquals(-1, p.getIndentationLeft());
CTP ctp = p.getCTP(); CTP ctp = p.getCTP();
CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr(); CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr();
assertEquals(-1, p.getIndentationLeft()); assertEquals(-1, p.getIndentationLeft());
CTInd ind = ppr.addNewInd(); CTInd ind = ppr.addNewInd();
ind.setLeft(new BigInteger("10")); ind.setLeft(new BigInteger("10"));
assertEquals(10, p.getIndentationLeft()); assertEquals(10, p.getIndentationLeft());
@ -193,7 +190,7 @@ public class TestXWPFParagraph extends TestCase {
p.setIndentationLeft(100); p.setIndentationLeft(100);
assertEquals(100, ind.getLeft().intValue()); assertEquals(100, ind.getLeft().intValue());
} }
public void testSetGetVerticalAlignment() { public void testSetGetVerticalAlignment() {
//new clean instance of paragraph //new clean instance of paragraph
XWPFDocument doc = new XWPFDocument(); XWPFDocument doc = new XWPFDocument();
@ -240,6 +237,4 @@ public class TestXWPFParagraph extends TestCase {
p.setPageBreak(true); p.setPageBreak(true);
assertEquals(STOnOff.TRUE, ppr.getPageBreakBefore().getVal()); assertEquals(STOnOff.TRUE, ppr.getPageBreakBefore().getVal());
} }
} }

View File

@ -17,16 +17,12 @@
package org.apache.poi.hdf.extractor; package org.apache.poi.hdf.extractor;
import java.util.*;
/** /**
* Comment me * Comment me
* *
* @author Ryan Ackley * @author Ryan Ackley
*/ */
public final class StyleSheet {
public final class StyleSheet
{
private static final int NIL_STYLE = 4095; private static final int NIL_STYLE = 4095;
private static final int PAP_TYPE = 1; private static final int PAP_TYPE = 1;

View File

@ -17,37 +17,25 @@
package org.apache.poi.hdf.model; package org.apache.poi.hdf.model;
//import java.io;
import java.util.ArrayList;
import java.io.InputStream;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.TreeSet;
import org.apache.poi.hdf.model.hdftypes.*;
import org.apache.poi.hdf.event.HDFLowLevelParsingListener; import org.apache.poi.hdf.event.HDFLowLevelParsingListener;
import org.apache.poi.hdf.model.util.BTreeSet; import org.apache.poi.hdf.model.hdftypes.*;
import org.apache.poi.hdf.model.util.ParsingState; import org.apache.poi.hdf.model.util.ParsingState;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSDocument;
import org.apache.poi.poifs.filesystem.DocumentEntry; import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
/** /**
* The Object Factory takes in a stream and creates the low level objects * The Object Factory takes in a stream and creates the low level objects
* that represent the data. * that represent the data.
* @author andy * @author andy
*/ */
public final class HDFObjectFactory public final class HDFObjectFactory {
{
/** OLE stuff*/ /** OLE stuff*/
private POIFSFileSystem _filesystem; private POIFSFileSystem _filesystem;
@ -193,36 +181,26 @@ public final class HDFObjectFactory
{ {
throw new IOException("The text piece table is corrupted"); throw new IOException("The text piece table is corrupted");
} }
else //parse out the text pieces
{ int pieceTableSize = LittleEndian.getInt(_tableBuffer, ++pos);
//parse out the text pieces pos += 4;
int pieceTableSize = LittleEndian.getInt(_tableBuffer, ++pos); int pieces = (pieceTableSize - 4) / 12;
pos += 4; for (int x = 0; x < pieces; x++) {
int pieces = (pieceTableSize - 4) / 12; int filePos = LittleEndian.getInt(_tableBuffer, pos + ((pieces + 1) * 4) + (x * 8) + 2);
for (int x = 0; x < pieces; x++) boolean unicode = false;
{ if ((filePos & 0x40000000) == 0) {
int filePos = LittleEndian.getInt(_tableBuffer, pos + ((pieces + 1) * 4) + (x * 8) + 2); unicode = true;
boolean unicode = false; } else {
if ((filePos & 0x40000000) == 0) unicode = false;
{ filePos &= ~(0x40000000);//gives me FC in doc stream
unicode = true; filePos /= 2;
}
else
{
unicode = false;
filePos &= ~(0x40000000);//gives me FC in doc stream
filePos /= 2;
}
int totLength = LittleEndian.getInt(_tableBuffer, pos + (x + 1) * 4) -
LittleEndian.getInt(_tableBuffer, pos + (x * 4));
TextPiece piece = new TextPiece(filePos, totLength, unicode);
_listener.text(piece);
} }
int totLength = LittleEndian.getInt(_tableBuffer, pos + (x + 1) * 4) -
LittleEndian.getInt(_tableBuffer, pos + (x * 4));
TextPiece piece = new TextPiece(filePos, totLength, unicode);
_listener.text(piece);
} }
} }
/** /**
* initializes all of the formatting properties for a Word Document * initializes all of the formatting properties for a Word Document
@ -532,10 +510,7 @@ public final class HDFObjectFactory
{ {
break; break;
} }
else x++;
{
x++;
}
} }
//do the header sections //do the header sections
for (; x < arraySize; x++)// && sectionEnd <= end; x++) for (; x < arraySize; x++)// && sectionEnd <= end; x++)

View File

@ -17,9 +17,6 @@
package org.apache.poi.hdf.model.hdftypes; package org.apache.poi.hdf.model.hdftypes;
import org.apache.poi.util.BitField;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hdf.model.hdftypes.definitions.FIBAbstractType; import org.apache.poi.hdf.model.hdftypes.definitions.FIBAbstractType;

View File

@ -17,7 +17,6 @@
package org.apache.poi.hdf.model.hdftypes; package org.apache.poi.hdf.model.hdftypes;
import java.util.*;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.hdf.model.hdftypes.definitions.TCAbstractType; import org.apache.poi.hdf.model.hdftypes.definitions.TCAbstractType;
@ -29,9 +28,7 @@ import org.apache.poi.hdf.model.hdftypes.definitions.TCAbstractType;
* *
* @author Ryan Ackley * @author Ryan Ackley
*/ */
public final class StyleSheet implements HDFType {
public final class StyleSheet implements HDFType
{
private static final int NIL_STYLE = 4095; private static final int NIL_STYLE = 4095;
private static final int PAP_TYPE = 1; private static final int PAP_TYPE = 1;

View File

@ -18,12 +18,8 @@
package org.apache.poi.hdf.model.hdftypes.definitions; package org.apache.poi.hdf.model.hdftypes.definitions;
import org.apache.poi.util.BitField; import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.StringUtil;
import org.apache.poi.util.HexDump;
import org.apache.poi.hdf.model.hdftypes.HDFType; import org.apache.poi.hdf.model.hdftypes.HDFType;
/** /**

View File

@ -22,7 +22,6 @@ package org.apache.poi.hdf.model.hdftypes.definitions;
import org.apache.poi.util.BitField; import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.StringUtil;
import org.apache.poi.util.HexDump; import org.apache.poi.util.HexDump;
import org.apache.poi.hdf.model.hdftypes.HDFType; import org.apache.poi.hdf.model.hdftypes.HDFType;

View File

@ -18,11 +18,9 @@
package org.apache.poi.hdf.model.hdftypes.definitions; package org.apache.poi.hdf.model.hdftypes.definitions;
import org.apache.poi.util.BitField; import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.StringUtil;
import org.apache.poi.util.HexDump; import org.apache.poi.util.HexDump;
import org.apache.poi.hdf.model.hdftypes.HDFType; import org.apache.poi.hdf.model.hdftypes.HDFType;

View File

@ -18,12 +18,8 @@
package org.apache.poi.hdf.model.hdftypes.definitions; package org.apache.poi.hdf.model.hdftypes.definitions;
import org.apache.poi.util.BitField; import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.StringUtil;
import org.apache.poi.util.HexDump;
import org.apache.poi.hdf.model.hdftypes.HDFType; import org.apache.poi.hdf.model.hdftypes.HDFType;
/** /**

View File

@ -18,11 +18,6 @@
package org.apache.poi.hdf.model.hdftypes.definitions; package org.apache.poi.hdf.model.hdftypes.definitions;
import org.apache.poi.util.BitField;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.StringUtil;
import org.apache.poi.util.HexDump;
import org.apache.poi.hdf.model.hdftypes.HDFType; import org.apache.poi.hdf.model.hdftypes.HDFType;
/** /**

View File

@ -17,12 +17,6 @@
package org.apache.poi.hdf.model.hdftypes.definitions; package org.apache.poi.hdf.model.hdftypes.definitions;
import org.apache.poi.util.BitField;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.StringUtil;
import org.apache.poi.util.HexDump;
import org.apache.poi.hdf.model.hdftypes.HDFType; import org.apache.poi.hdf.model.hdftypes.HDFType;
/** /**

View File

@ -17,13 +17,8 @@
package org.apache.poi.hdf.model.hdftypes.definitions; package org.apache.poi.hdf.model.hdftypes.definitions;
import org.apache.poi.util.BitField; import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.StringUtil;
import org.apache.poi.util.HexDump;
import org.apache.poi.hdf.model.hdftypes.HDFType; import org.apache.poi.hdf.model.hdftypes.HDFType;
/** /**

View File

@ -26,9 +26,6 @@ import org.apache.poi.hslf.record.PersistPtrHolder;
import org.apache.poi.hslf.record.Record; import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.UserEditAtom; import org.apache.poi.hslf.record.UserEditAtom;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.DocumentInputStream;
import org.apache.poi.util.LittleEndian;
/** /**
* This class provides helper functions for determining if a * This class provides helper functions for determining if a
@ -95,7 +92,9 @@ public final class EncryptedSlideShow
hss.getUnderlyingBytes(), hss.getUnderlyingBytes(),
(int)cua.getCurrentEditOffset() (int)cua.getCurrentEditOffset()
); );
} catch(ArrayIndexOutOfBoundsException e) {} } catch (ArrayIndexOutOfBoundsException e) {
return null;
}
if(r == null) { return null; } if(r == null) { return null; }
if(! (r instanceof UserEditAtom)) { return null; } if(! (r instanceof UserEditAtom)) { return null; }
UserEditAtom uea = (UserEditAtom)r; UserEditAtom uea = (UserEditAtom)r;

View File

@ -26,7 +26,6 @@ import java.io.InputStream;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.zip.InflaterInputStream; import java.util.zip.InflaterInputStream;
import java.util.zip.DeflaterOutputStream;
/** /**
* Represents EMF (Windows Enhanced Metafile) picture data. * Represents EMF (Windows Enhanced Metafile) picture data.

View File

@ -23,7 +23,6 @@ import org.apache.poi.hslf.usermodel.PictureData;
import java.awt.*; import java.awt.*;
import java.io.*; import java.io.*;
import java.util.zip.DeflaterOutputStream; import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;
/** /**
* Represents a metafile picture which can be one of the following types: EMF, WMF, or PICT. * Represents a metafile picture which can be one of the following types: EMF, WMF, or PICT.

View File

@ -17,14 +17,14 @@
package org.apache.poi.hslf.blip; package org.apache.poi.hslf.blip;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.InflaterInputStream;
import org.apache.poi.hslf.exceptions.HSLFException;
import org.apache.poi.hslf.model.Picture; import org.apache.poi.hslf.model.Picture;
import org.apache.poi.hslf.model.Shape; import org.apache.poi.hslf.model.Shape;
import org.apache.poi.hslf.exceptions.HSLFException;
import org.apache.poi.util.LittleEndian;
import java.io.*;
import java.util.zip.InflaterInputStream;
import java.util.zip.DeflaterOutputStream;
/** /**
* Represents Macintosh PICT picture data. * Represents Macintosh PICT picture data.

View File

@ -25,7 +25,6 @@ import org.apache.poi.hslf.exceptions.HSLFException;
import java.io.*; import java.io.*;
import java.util.zip.InflaterInputStream; import java.util.zip.InflaterInputStream;
import java.util.zip.DeflaterOutputStream;
/** /**
* Represents a WMF (Windows Metafile) picture data. * Represents a WMF (Windows Metafile) picture data.

View File

@ -17,11 +17,9 @@
package org.apache.poi.hslf.dev; package org.apache.poi.hslf.dev;
import java.util.*;
import java.io.*; import java.io.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSDocument;
import org.apache.poi.poifs.filesystem.DocumentEntry; import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.ddf.*; import org.apache.poi.ddf.*;

View File

@ -33,7 +33,6 @@ import org.apache.poi.hslf.record.EscherTextboxWrapper;
import org.apache.poi.hslf.record.TextCharsAtom; import org.apache.poi.hslf.record.TextCharsAtom;
import org.apache.poi.hslf.record.TextBytesAtom; import org.apache.poi.hslf.record.TextBytesAtom;
import org.apache.poi.hslf.record.StyleTextPropAtom; import org.apache.poi.hslf.record.StyleTextPropAtom;
import org.apache.poi.hslf.record.Record;
/** /**
* This class provides a way to view the contents of a powerpoint file. * This class provides a way to view the contents of a powerpoint file.

View File

@ -22,7 +22,6 @@ import org.apache.poi.hslf.model.textproperties.BitMaskTextProp;
import org.apache.poi.hslf.model.textproperties.TextProp; import org.apache.poi.hslf.model.textproperties.TextProp;
import org.apache.poi.hslf.model.textproperties.TextPropCollection; import org.apache.poi.hslf.model.textproperties.TextPropCollection;
import org.apache.poi.hslf.record.*; import org.apache.poi.hslf.record.*;
import org.apache.poi.hslf.record.StyleTextPropAtom.*;
import java.util.LinkedList; import java.util.LinkedList;

View File

@ -17,18 +17,13 @@
package org.apache.poi.hslf.dev; package org.apache.poi.hslf.dev;
import org.apache.poi.hslf.*; import java.io.ByteArrayOutputStream;
import org.apache.poi.hslf.record.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSDocument;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.DocumentInputStream;
import org.apache.poi.util.LittleEndian;
import java.io.*;
import java.util.Hashtable; import java.util.Hashtable;
import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.record.*;
import org.apache.poi.util.LittleEndian;
/** /**
* Uses record level code to locate UserEditAtom records, and other * Uses record level code to locate UserEditAtom records, and other
* persistence related atoms. Tries to match them together, to help * persistence related atoms. Tries to match them together, to help

View File

@ -21,9 +21,7 @@ import java.io.*;
import java.util.Vector; import java.util.Vector;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSDocument;
import org.apache.poi.poifs.filesystem.DocumentEntry; import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.DocumentInputStream;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.hslf.record.CString; import org.apache.poi.hslf.record.CString;

View File

@ -20,7 +20,6 @@ package org.apache.poi.hslf.model;
import org.apache.poi.ddf.*; import org.apache.poi.ddf.*;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
import org.apache.poi.util.HexDump;
import java.awt.geom.*; import java.awt.geom.*;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -18,9 +18,6 @@
package org.apache.poi.hslf.model; package org.apache.poi.hslf.model;
import org.apache.poi.hslf.record.SheetContainer; import org.apache.poi.hslf.record.SheetContainer;
import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.RecordTypes;
import org.apache.poi.hslf.record.OEPlaceholderAtom;
import org.apache.poi.hslf.model.textproperties.TextProp; import org.apache.poi.hslf.model.textproperties.TextProp;
/** /**
@ -55,5 +52,4 @@ public abstract class MasterSheet extends Sheet {
TextShape tx = (TextShape)shape; TextShape tx = (TextShape)shape;
return tx.getPlaceholderAtom() != null; return tx.getPlaceholderAtom() != null;
} }
} }

View File

@ -28,13 +28,11 @@ import org.apache.poi.util.POILogger;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.awt.*; import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.List; import java.util.List;
import java.util.Arrays;
/** /**

View File

@ -21,7 +21,6 @@ import org.apache.poi.ddf.*;
import org.apache.poi.hslf.record.OEPlaceholderAtom; import org.apache.poi.hslf.record.OEPlaceholderAtom;
import org.apache.poi.hslf.exceptions.HSLFException; import org.apache.poi.hslf.exceptions.HSLFException;
import java.util.List;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
/** /**

View File

@ -19,7 +19,6 @@ package org.apache.poi.hslf.model;
import org.apache.poi.ddf.*; import org.apache.poi.ddf.*;
import org.apache.poi.hslf.record.ColorSchemeAtom; import org.apache.poi.hslf.record.ColorSchemeAtom;
import org.apache.poi.hslf.record.PPDrawing;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;

View File

@ -20,7 +20,6 @@ package org.apache.poi.hslf.model;
import org.apache.poi.ddf.*; import org.apache.poi.ddf.*;
import org.apache.poi.hslf.record.*; import org.apache.poi.hslf.record.*;
import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.util.POILogger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;

View File

@ -18,7 +18,6 @@
package org.apache.poi.hslf.model; package org.apache.poi.hslf.model;
import org.apache.poi.ddf.*; import org.apache.poi.ddf.*;
import org.apache.poi.hslf.record.TextHeaderAtom;
import java.awt.*; import java.awt.*;

View File

@ -17,22 +17,24 @@
package org.apache.poi.hslf.model; package org.apache.poi.hslf.model;
import org.apache.poi.hslf.usermodel.RichTextRun; import java.awt.Color;
import org.apache.poi.hslf.record.TextRulerAtom; import java.awt.Font;
import org.apache.poi.util.POILogger; import java.awt.Graphics2D;
import org.apache.poi.util.POILogFactory;
import java.text.AttributedString;
import java.text.AttributedCharacterIterator;
import java.text.BreakIterator;
import java.awt.font.TextAttribute;
import java.awt.font.LineBreakMeasurer;
import java.awt.font.TextLayout;
import java.awt.font.FontRenderContext; import java.awt.font.FontRenderContext;
import java.awt.*; import java.awt.font.LineBreakMeasurer;
import java.awt.geom.Rectangle2D; import java.awt.font.TextAttribute;
import java.awt.font.TextLayout;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.text.AttributedCharacterIterator;
import java.text.AttributedString;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hslf.record.TextRulerAtom;
import org.apache.poi.hslf.usermodel.RichTextRun;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
/** /**
* Paint text into java.awt.Graphics2D * Paint text into java.awt.Graphics2D
@ -162,7 +164,7 @@ public final class TextPainter {
int paragraphStart = it.getBeginIndex(); int paragraphStart = it.getBeginIndex();
int paragraphEnd = it.getEndIndex(); int paragraphEnd = it.getEndIndex();
ArrayList lines = new ArrayList(); List<TextElement> lines = new ArrayList<TextElement>();
LineBreakMeasurer measurer = new LineBreakMeasurer(it, frc); LineBreakMeasurer measurer = new LineBreakMeasurer(it, frc);
measurer.setPosition(paragraphStart); measurer.setPosition(paragraphStart);
while (measurer.getPosition() < paragraphEnd) { while (measurer.getPosition() < paragraphEnd) {
@ -296,7 +298,7 @@ public final class TextPainter {
//finally draw the text fragments //finally draw the text fragments
TextElement[] elems = new TextElement[lines.size()]; TextElement[] elems = new TextElement[lines.size()];
return (TextElement[])lines.toArray(elems); return lines.toArray(elems);
} }
public static class TextElement { public static class TextElement {

View File

@ -19,7 +19,6 @@ package org.apache.poi.hslf.model;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Vector; import java.util.Vector;
import java.util.List;
import org.apache.poi.hslf.model.textproperties.TextPropCollection; import org.apache.poi.hslf.model.textproperties.TextPropCollection;
import org.apache.poi.hslf.record.*; import org.apache.poi.hslf.record.*;

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -30,7 +29,6 @@ import java.awt.geom.AffineTransform;
import java.awt.font.FontRenderContext; import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout; import java.awt.font.TextLayout;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator;
/** /**
* A common superclass of all shapes that can hold text. * A common superclass of all shapes that can hold text.
@ -88,7 +86,7 @@ public abstract class TextShape extends SimpleShape {
/** /**
* Create a TextBox object and initialize it from the supplied Record container. * Create a TextBox object and initialize it from the supplied Record container.
* *
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of the shape * @param parent the parent of the shape
*/ */
@ -230,23 +228,23 @@ public abstract class TextShape extends SimpleShape {
String fntname = rt.getFontName(); String fntname = rt.getFontName();
Font font = new Font(fntname, style, size); Font font = new Font(fntname, style, size);
float width = 0, height = 0, leading = 0; float width = 0, height = 0, leading = 0;
String[] lines = txt.split("\n"); String[] lines = txt.split("\n");
for (int i = 0; i < lines.length; i++) { for (int i = 0; i < lines.length; i++) {
if(lines[i].length() == 0) continue; if(lines[i].length() == 0) continue;
TextLayout layout = new TextLayout(lines[i], font, _frc); TextLayout layout = new TextLayout(lines[i], font, _frc);
leading = Math.max(leading, layout.getLeading()); leading = Math.max(leading, layout.getLeading());
width = Math.max(width, layout.getAdvance()); width = Math.max(width, layout.getAdvance());
height = Math.max(height, (height + (layout.getDescent() + layout.getAscent()))); height = Math.max(height, (height + (layout.getDescent() + layout.getAscent())));
} }
// add one character to width // add one character to width
Rectangle2D charBounds = font.getMaxCharBounds(_frc); Rectangle2D charBounds = font.getMaxCharBounds(_frc);
width += getMarginLeft() + getMarginRight() + charBounds.getWidth(); width += getMarginLeft() + getMarginRight() + charBounds.getWidth();
// add leading to height // add leading to height
height += getMarginTop() + getMarginBottom() + leading; height += getMarginTop() + getMarginBottom() + leading;
Rectangle2D anchor = getAnchor2D(); Rectangle2D anchor = getAnchor2D();

View File

@ -19,9 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Date;
import org.apache.poi.hslf.util.SystemTimeUtils;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
/** /**
@ -29,8 +27,7 @@ import org.apache.poi.util.LittleEndian;
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public final class AnimationInfoAtom extends RecordAtom public final class AnimationInfoAtom extends RecordAtom {
{
/** /**
* whether the animation plays in the reverse direction * whether the animation plays in the reverse direction

View File

@ -17,7 +17,6 @@
package org.apache.poi.hslf.record; package org.apache.poi.hslf.record;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.StringUtil; import org.apache.poi.util.StringUtil;
import java.io.IOException; import java.io.IOException;
@ -29,9 +28,7 @@ import java.io.OutputStream;
* *
* @author Nick Burch * @author Nick Burch
*/ */
public final class DocumentEncryptionAtom extends RecordAtom {
public final class DocumentEncryptionAtom extends RecordAtom
{
private byte[] _header; private byte[] _header;
private static long _type = 12052l; private static long _type = 12052l;

View File

@ -17,11 +17,6 @@
package org.apache.poi.hslf.record; package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogger;
/** /**
* A container record that specifies information about a movie stored externally. * A container record that specifies information about a movie stored externally.
@ -50,5 +45,4 @@ public final class ExAviMovie extends ExMCIMovie {
public long getRecordType() { public long getRecordType() {
return RecordTypes.ExAviMovie.typeID; return RecordTypes.ExAviMovie.typeID;
} }
} }

View File

@ -17,11 +17,6 @@
package org.apache.poi.hslf.record; package org.apache.poi.hslf.record;
import java.io.OutputStream;
import java.io.IOException;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogger;
/** /**
* A container record that specifies information about an ActiveX control. It contains: * A container record that specifies information about an ActiveX control. It contains:

View File

@ -14,15 +14,12 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hslf.record; package org.apache.poi.hslf.record;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Date;
import org.apache.poi.hslf.util.SystemTimeUtils;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
/** /**
@ -31,9 +28,7 @@ import org.apache.poi.util.LittleEndian;
* *
* @author Nick Burch * @author Nick Burch
*/ */
public final class ExHyperlinkAtom extends RecordAtom {
public class ExHyperlinkAtom extends RecordAtom
{
/** /**
* Record header. * Record header.
*/ */
@ -53,7 +48,7 @@ public class ExHyperlinkAtom extends RecordAtom
LittleEndian.putShort(_header, 2, (short)getRecordType()); LittleEndian.putShort(_header, 2, (short)getRecordType());
LittleEndian.putInt(_header, 4, _data.length); LittleEndian.putInt(_header, 4, _data.length);
// It is fine for the other values to be zero // It is fine for the other values to be zero
} }
@ -69,11 +64,11 @@ public class ExHyperlinkAtom extends RecordAtom
// Get the header. // Get the header.
_header = new byte[8]; _header = new byte[8];
System.arraycopy(source,start,_header,0,8); System.arraycopy(source,start,_header,0,8);
// Get the record data. // Get the record data.
_data = new byte[len-8]; _data = new byte[len-8];
System.arraycopy(source,start+8,_data,0,len-8); System.arraycopy(source,start+8,_data,0,len-8);
// Must be at least 4 bytes long // Must be at least 4 bytes long
if(_data.length < 4) { if(_data.length < 4) {
throw new IllegalArgumentException("The length of the data for a ExHyperlinkAtom must be at least 4 bytes, but was only " + _data.length); throw new IllegalArgumentException("The length of the data for a ExHyperlinkAtom must be at least 4 bytes, but was only " + _data.length);
@ -96,7 +91,7 @@ public class ExHyperlinkAtom extends RecordAtom
public void setNumber(int number) { public void setNumber(int number) {
LittleEndian.putInt(_data,0,number); LittleEndian.putInt(_data,0,number);
} }
/** /**
* Gets the record type. * Gets the record type.
* @return the record type. * @return the record type.

View File

@ -19,9 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Date;
import org.apache.poi.hslf.util.SystemTimeUtils;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
/** /**

View File

@ -18,7 +18,6 @@
package org.apache.poi.hslf.record; package org.apache.poi.hslf.record;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.StringUtil;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;

View File

@ -14,15 +14,12 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hslf.record; package org.apache.poi.hslf.record;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Date;
import org.apache.poi.hslf.util.SystemTimeUtils;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
/** /**
@ -32,9 +29,7 @@ import org.apache.poi.util.LittleEndian;
* @author Nick Burch * @author Nick Burch
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public class InteractiveInfoAtom extends RecordAtom {
public class InteractiveInfoAtom extends RecordAtom
{
/** /**
* Action Table * Action Table
@ -92,7 +87,7 @@ public class InteractiveInfoAtom extends RecordAtom
LittleEndian.putShort(_header, 2, (short)getRecordType()); LittleEndian.putShort(_header, 2, (short)getRecordType());
LittleEndian.putInt(_header, 4, _data.length); LittleEndian.putInt(_header, 4, _data.length);
// It is fine for the other values to be zero // It is fine for the other values to be zero
} }
@ -108,16 +103,16 @@ public class InteractiveInfoAtom extends RecordAtom
// Get the header. // Get the header.
_header = new byte[8]; _header = new byte[8];
System.arraycopy(source,start,_header,0,8); System.arraycopy(source,start,_header,0,8);
// Get the record data. // Get the record data.
_data = new byte[len-8]; _data = new byte[len-8];
System.arraycopy(source,start+8,_data,0,len-8); System.arraycopy(source,start+8,_data,0,len-8);
// Must be at least 16 bytes long // Must be at least 16 bytes long
if(_data.length < 16) { if(_data.length < 16) {
throw new IllegalArgumentException("The length of the data for a InteractiveInfoAtom must be at least 16 bytes, but was only " + _data.length); throw new IllegalArgumentException("The length of the data for a InteractiveInfoAtom must be at least 16 bytes, but was only " + _data.length);
} }
// First 4 bytes - no idea, normally 0 // First 4 bytes - no idea, normally 0
// Second 4 bytes - the id of the link (from 1 onwards) // Second 4 bytes - the id of the link (from 1 onwards)
// Third 4 bytes - no idea, normally 4 // Third 4 bytes - no idea, normally 4
@ -141,7 +136,7 @@ public class InteractiveInfoAtom extends RecordAtom
public void setHyperlinkID(int number) { public void setHyperlinkID(int number) {
LittleEndian.putInt(_data,4,number); LittleEndian.putInt(_data,4,number);
} }
/** /**
* a reference to a sound in the sound collection. * a reference to a sound in the sound collection.
*/ */

View File

@ -21,25 +21,21 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import org.apache.poi.util.LittleEndian;
/** /**
* Master slide * Master slide
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public final class MainMaster extends SheetContainer {
public final class MainMaster extends SheetContainer
{
private byte[] _header; private byte[] _header;
private static long _type = 1016; private static long _type = 1016;
// Links to our more interesting children // Links to our more interesting children
private SlideAtom slideAtom; private SlideAtom slideAtom;
private PPDrawing ppDrawing; private PPDrawing ppDrawing;
private TxMasterStyleAtom[] txmasters; private TxMasterStyleAtom[] txmasters;
private ColorSchemeAtom[] clrscheme; private ColorSchemeAtom[] clrscheme;
private ColorSchemeAtom _colorScheme; private ColorSchemeAtom _colorScheme;
/** /**
* Returns the SlideAtom of this Slide * Returns the SlideAtom of this Slide
@ -52,9 +48,9 @@ public final class MainMaster extends SheetContainer
*/ */
public PPDrawing getPPDrawing() { return ppDrawing; } public PPDrawing getPPDrawing() { return ppDrawing; }
public TxMasterStyleAtom[] getTxMasterStyleAtoms() { return txmasters; } public TxMasterStyleAtom[] getTxMasterStyleAtoms() { return txmasters; }
public ColorSchemeAtom[] getColorSchemeAtoms() { return clrscheme; } public ColorSchemeAtom[] getColorSchemeAtoms() { return clrscheme; }
/** /**
* Set things up, and find our more interesting children * Set things up, and find our more interesting children
@ -67,27 +63,27 @@ public final class MainMaster extends SheetContainer
// Find our children // Find our children
_children = Record.findChildRecords(source,start+8,len-8); _children = Record.findChildRecords(source,start+8,len-8);
ArrayList tx = new ArrayList(); ArrayList tx = new ArrayList();
ArrayList clr = new ArrayList(); ArrayList clr = new ArrayList();
// Find the interesting ones in there // Find the interesting ones in there
for(int i=0; i<_children.length; i++) { for(int i=0; i<_children.length; i++) {
if(_children[i] instanceof SlideAtom) { if(_children[i] instanceof SlideAtom) {
slideAtom = (SlideAtom)_children[i]; slideAtom = (SlideAtom)_children[i];
} else if(_children[i] instanceof PPDrawing) { } else if(_children[i] instanceof PPDrawing) {
ppDrawing = (PPDrawing)_children[i]; ppDrawing = (PPDrawing)_children[i];
} else if(_children[i] instanceof TxMasterStyleAtom) { } else if(_children[i] instanceof TxMasterStyleAtom) {
tx.add(_children[i]); tx.add(_children[i]);
} else if(_children[i] instanceof ColorSchemeAtom) { } else if(_children[i] instanceof ColorSchemeAtom) {
clr.add(_children[i]); clr.add(_children[i]);
} }
if(ppDrawing != null && _children[i] instanceof ColorSchemeAtom) { if(ppDrawing != null && _children[i] instanceof ColorSchemeAtom) {
_colorScheme = (ColorSchemeAtom)_children[i]; _colorScheme = (ColorSchemeAtom)_children[i];
} }
} }
txmasters = (TxMasterStyleAtom[])tx.toArray(new TxMasterStyleAtom[tx.size()]); txmasters = (TxMasterStyleAtom[])tx.toArray(new TxMasterStyleAtom[tx.size()]);
clrscheme = (ColorSchemeAtom[])clr.toArray(new ColorSchemeAtom[clr.size()]); clrscheme = (ColorSchemeAtom[])clr.toArray(new ColorSchemeAtom[clr.size()]);
} }
/** /**
@ -103,8 +99,7 @@ public final class MainMaster extends SheetContainer
writeOut(_header[0],_header[1],_type,_children,out); writeOut(_header[0],_header[1],_type,_children,out);
} }
public ColorSchemeAtom getColorScheme(){ public ColorSchemeAtom getColorScheme(){
return _colorScheme; return _colorScheme;
} }
} }

View File

@ -19,9 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Date;
import org.apache.poi.hslf.util.SystemTimeUtils;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
/** /**

View File

@ -22,7 +22,6 @@ import org.apache.poi.util.POILogger;
import org.apache.poi.ddf.*; import org.apache.poi.ddf.*;
import org.apache.poi.hslf.model.ShapeTypes; import org.apache.poi.hslf.model.ShapeTypes;
import org.apache.poi.hslf.model.Shape;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
@ -44,16 +43,15 @@ import java.util.Iterator;
// For now, pretending to be an atom. Might not always be, but that // For now, pretending to be an atom. Might not always be, but that
// would require a wrapping class // would require a wrapping class
public final class PPDrawing extends RecordAtom public final class PPDrawing extends RecordAtom {
{
private byte[] _header; private byte[] _header;
private long _type; private long _type;
private EscherRecord[] childRecords; private EscherRecord[] childRecords;
private EscherTextboxWrapper[] textboxWrappers; private EscherTextboxWrapper[] textboxWrappers;
//cached EscherDgRecord //cached EscherDgRecord
private EscherDgRecord dg; private EscherDgRecord dg;
/** /**
* Get access to the underlying Escher Records * Get access to the underlying Escher Records
@ -110,7 +108,7 @@ public final class PPDrawing extends RecordAtom
public PPDrawing(){ public PPDrawing(){
_header = new byte[8]; _header = new byte[8];
LittleEndian.putUShort(_header, 0, 15); LittleEndian.putUShort(_header, 0, 15);
LittleEndian.putUShort(_header, 2, (int)RecordTypes.PPDrawing.typeID); LittleEndian.putUShort(_header, 2, RecordTypes.PPDrawing.typeID);
LittleEndian.putInt(_header, 4, 0); LittleEndian.putInt(_header, 4, 0);
textboxWrappers = new EscherTextboxWrapper[]{}; textboxWrappers = new EscherTextboxWrapper[]{};
@ -122,7 +120,7 @@ public final class PPDrawing extends RecordAtom
*/ */
private void findEscherChildren(DefaultEscherRecordFactory erf, byte[] source, int startPos, int lenToGo, Vector found) { private void findEscherChildren(DefaultEscherRecordFactory erf, byte[] source, int startPos, int lenToGo, Vector found) {
int escherBytes = LittleEndian.getInt( source, startPos + 4 ) + 8; int escherBytes = LittleEndian.getInt( source, startPos + 4 ) + 8;
// Find the record // Find the record
EscherRecord r = erf.createRecord(source,startPos); EscherRecord r = erf.createRecord(source,startPos);
@ -137,16 +135,16 @@ public final class PPDrawing extends RecordAtom
logger.log(POILogger.WARN, "Hit short DDF record at " + startPos + " - " + size); logger.log(POILogger.WARN, "Hit short DDF record at " + startPos + " - " + size);
} }
/** /**
* Sanity check. Always advance the cursor by the correct value. * Sanity check. Always advance the cursor by the correct value.
* *
* getRecordSize() must return exatcly the same number of bytes that was written in fillFields. * getRecordSize() must return exatcly the same number of bytes that was written in fillFields.
* Sometimes it is not so, see an example in bug #44770. Most likely reason is that one of ddf records calculates wrong size. * Sometimes it is not so, see an example in bug #44770. Most likely reason is that one of ddf records calculates wrong size.
*/ */
if(size != escherBytes){ if(size != escherBytes){
logger.log(POILogger.WARN, "Record length=" + escherBytes + " but getRecordSize() returned " + r.getRecordSize() + "; record: " + r.getClass()); logger.log(POILogger.WARN, "Record length=" + escherBytes + " but getRecordSize() returned " + r.getRecordSize() + "; record: " + r.getClass());
size = escherBytes; size = escherBytes;
} }
startPos += size; startPos += size;
lenToGo -= size; lenToGo -= size;
if(lenToGo >= 8) { if(lenToGo >= 8) {
@ -163,13 +161,13 @@ public final class PPDrawing extends RecordAtom
EscherTextboxRecord tbr = (EscherTextboxRecord)toSearch[i]; EscherTextboxRecord tbr = (EscherTextboxRecord)toSearch[i];
EscherTextboxWrapper w = new EscherTextboxWrapper(tbr); EscherTextboxWrapper w = new EscherTextboxWrapper(tbr);
found.add(w); found.add(w);
for (int j = i; j >= 0; j--) { for (int j = i; j >= 0; j--) {
if(toSearch[j] instanceof EscherSpRecord){ if(toSearch[j] instanceof EscherSpRecord){
EscherSpRecord sp = (EscherSpRecord)toSearch[j]; EscherSpRecord sp = (EscherSpRecord)toSearch[j];
w.setShapeId(sp.getShapeId()); w.setShapeId(sp.getShapeId());
break; break;
} }
} }
} else { } else {
// If it has children, walk them // If it has children, walk them
if(toSearch[i].isContainerRecord()) { if(toSearch[i].isContainerRecord()) {
@ -297,23 +295,22 @@ public final class PPDrawing extends RecordAtom
textboxWrappers = tw; textboxWrappers = tw;
} }
/** /**
* Return EscherDgRecord which keeps track of the number of shapes and shapeId in this drawing group * Return EscherDgRecord which keeps track of the number of shapes and shapeId in this drawing group
* *
* @return EscherDgRecord * @return EscherDgRecord
*/ */
public EscherDgRecord getEscherDgRecord(){ public EscherDgRecord getEscherDgRecord(){
if(dg == null){ if(dg == null){
EscherContainerRecord dgContainer = (EscherContainerRecord)childRecords[0]; EscherContainerRecord dgContainer = (EscherContainerRecord)childRecords[0];
for(Iterator<EscherRecord> it = dgContainer.getChildIterator(); it.hasNext();){ for(Iterator<EscherRecord> it = dgContainer.getChildIterator(); it.hasNext();){
EscherRecord r = it.next(); EscherRecord r = it.next();
if(r instanceof EscherDgRecord){ if(r instanceof EscherDgRecord){
dg = (EscherDgRecord)r; dg = (EscherDgRecord)r;
break; break;
} }
} }
} }
return dg; return dg;
} }
} }

View File

@ -23,7 +23,6 @@ import org.apache.poi.util.LittleEndian;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.util.List;
import java.util.Iterator; import java.util.Iterator;
/** /**

View File

@ -19,10 +19,6 @@ package org.apache.poi.hslf.record;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Date;
import org.apache.poi.hslf.util.SystemTimeUtils;
import org.apache.poi.util.LittleEndian;
/** /**
* An atom record that specifies that a shape is a header or footer placeholder shape * An atom record that specifies that a shape is a header or footer placeholder shape
@ -30,9 +26,7 @@ import org.apache.poi.util.LittleEndian;
* @since PowerPoint 2007 * @since PowerPoint 2007
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public final class RoundTripHFPlaceholder12 extends RecordAtom {
public final class RoundTripHFPlaceholder12 extends RecordAtom
{
/** /**
* Record header. * Record header.
*/ */

View File

@ -17,7 +17,6 @@
package org.apache.poi.hslf.record; package org.apache.poi.hslf.record;
import org.apache.poi.util.ArrayUtil;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import java.io.IOException; import java.io.IOException;
@ -46,26 +45,25 @@ import java.util.Vector;
*/ */
// For now, pretend to be an atom // For now, pretend to be an atom
public final class SlideListWithText extends RecordContainer public final class SlideListWithText extends RecordContainer {
{
/** /**
* Instance filed of the record header indicates that this SlideListWithText stores * Instance filed of the record header indicates that this SlideListWithText stores
* references to slides * references to slides
*/ */
public static final int SLIDES = 0; public static final int SLIDES = 0;
/** /**
* Instance filed of the record header indicates that this SlideListWithText stores * Instance filed of the record header indicates that this SlideListWithText stores
* references to master slides * references to master slides
*/ */
public static final int MASTER = 1; public static final int MASTER = 1;
/** /**
* Instance filed of the record header indicates that this SlideListWithText stores * Instance filed of the record header indicates that this SlideListWithText stores
* references to notes * references to notes
*/ */
public static final int NOTES = 2; public static final int NOTES = 2;
private byte[] _header; private byte[] _header;
private static long _type = 4080; private static long _type = 4080;
private SlideAtomsSet[] slideAtomsSets; private SlideAtomsSet[] slideAtomsSets;
@ -148,23 +146,23 @@ public final class SlideListWithText extends RecordContainer
slideAtomsSets = sas; slideAtomsSets = sas;
} }
public int getInstance(){ public int getInstance(){
return LittleEndian.getShort(_header, 0) >> 4; return LittleEndian.getShort(_header, 0) >> 4;
} }
public void setInstance(int inst){ public void setInstance(int inst){
LittleEndian.putShort(_header, (short)((inst << 4) | 0xF)); LittleEndian.putShort(_header, (short)((inst << 4) | 0xF));
} }
/** /**
* Get access to the SlideAtomsSets of the children of this record * Get access to the SlideAtomsSets of the children of this record
*/ */
public SlideAtomsSet[] getSlideAtomsSets() { return slideAtomsSets; } public SlideAtomsSet[] getSlideAtomsSets() { return slideAtomsSets; }
/** /**
* Get access to the SlideAtomsSets of the children of this record * Get access to the SlideAtomsSets of the children of this record
*/ */
public void setSlideAtomsSets( SlideAtomsSet[] sas ) { slideAtomsSets = sas; } public void setSlideAtomsSets( SlideAtomsSet[] sas ) { slideAtomsSets = sas; }
/** /**
* Return the value we were given at creation * Return the value we were given at creation

View File

@ -17,8 +17,6 @@
package org.apache.poi.hslf.record; package org.apache.poi.hslf.record;
import org.apache.poi.util.POILogger;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.IOException; import java.io.IOException;

View File

@ -17,11 +17,8 @@
package org.apache.poi.hslf.record; package org.apache.poi.hslf.record;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.zip.InflaterInputStream;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;

View File

@ -17,11 +17,8 @@
package org.apache.poi.hslf.record; package org.apache.poi.hslf.record;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.zip.InflaterInputStream;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;

File diff suppressed because it is too large Load Diff

View File

@ -17,7 +17,6 @@
package org.apache.poi.hwpf.model; package org.apache.poi.hwpf.model;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hwpf.model.types.DOPAbstractType; import org.apache.poi.hwpf.model.types.DOPAbstractType;
/** /**
@ -25,13 +24,10 @@ import org.apache.poi.hwpf.model.types.DOPAbstractType;
* *
* @author Ryan Ackley * @author Ryan Ackley
*/ */
public final class DocumentProperties extends DOPAbstractType {
public final class DocumentProperties extends DOPAbstractType
{
public DocumentProperties(byte[] tableStream, int offset) public DocumentProperties(byte[] tableStream, int offset) {
{ super.fillFields(tableStream, offset);
super.fillFields(tableStream, offset); }
}
} }

Some files were not shown because too many files have changed in this diff Show More