findbugs fixes

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1715087 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2015-11-19 01:44:38 +00:00
parent e2bc07e9d1
commit 07dc2b9e08
4 changed files with 328 additions and 291 deletions

View File

@ -462,15 +462,12 @@ public final class FormulaParser {
// reset and let caller use explicit range operator
resetPointer(colonPos);
if (!part1.isCell()) {
String prefix;
if (sheetIden == null) {
prefix = "";
} else {
String prefix = "";
if (sheetIden != null) {
prefix = "'" + sheetIden.getSheetIdentifier().getName() + '!';
}
throw new FormulaParseException(prefix + part1.getRep() + "' is not a proper reference.");
}
return createAreaRefParseNode(sheetIden, part1, part2);
}
return createAreaRefParseNode(sheetIden, part1, part2);
}

View File

@ -18,6 +18,8 @@
package org.apache.poi.hdgf.dev;
import java.io.File;
import java.io.PrintStream;
import java.util.Arrays;
import org.apache.poi.hdgf.HDGFDiagram;
import org.apache.poi.hdgf.chunks.Chunk;
@ -33,6 +35,15 @@ import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
* of a Visio file
*/
public final class VSDDumper {
final static String tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
final PrintStream ps;
final HDGFDiagram hdgf;
VSDDumper(PrintStream ps, HDGFDiagram hdgf) {
this.ps = ps;
this.hdgf = hdgf;
}
public static void main(String[] args) throws Exception {
if(args.length == 0) {
System.err.println("Use:");
@ -40,84 +51,87 @@ public final class VSDDumper {
System.exit(1);
}
HDGFDiagram hdgf = new HDGFDiagram(
new NPOIFSFileSystem(new File(args[0]))
);
NPOIFSFileSystem poifs = new NPOIFSFileSystem(new File(args[0]));
HDGFDiagram hdgf = new HDGFDiagram(poifs);
System.out.println("Opened " + args[0]);
System.out.println("The document claims a size of " +
hdgf.getDocumentSize() + " (" +
Long.toHexString(hdgf.getDocumentSize()) + ")");
System.out.println();
dumpStream(hdgf.getTrailerStream(), 0);
PrintStream ps = System.out;
ps.println("Opened " + args[0]);
VSDDumper vd = new VSDDumper(ps, hdgf);
vd.dumpFile();
poifs.close();
}
public static void dumpStream(Stream stream, int indent) {
String ind = "";
for(int i=0; i<indent; i++) {
ind += " ";
}
String ind2 = ind + " ";
String ind3 = ind2 + " ";
public void dumpFile() {
dumpVal("Claimed document size", hdgf.getDocumentSize(), 0);
ps.println();
dumpStream(hdgf.getTrailerStream(), 0);
}
private void dumpStream(Stream stream, int indent) {
Pointer ptr = stream.getPointer();
System.out.println(ind + "Stream at\t" + ptr.getOffset() +
" - " + Integer.toHexString(ptr.getOffset()));
System.out.println(ind + " Type is\t" + ptr.getType() +
" - " + Integer.toHexString(ptr.getType()));
System.out.println(ind + " Format is\t" + ptr.getFormat() +
" - " + Integer.toHexString(ptr.getFormat()));
System.out.println(ind + " Length is\t" + ptr.getLength() +
" - " + Integer.toHexString(ptr.getLength()));
dumpVal("Stream at", ptr.getOffset(), indent);
dumpVal("Type is", ptr.getType(), indent+1);
dumpVal("Format is", ptr.getFormat(), indent+1);
dumpVal("Length is", ptr.getLength(), indent+1);
if(ptr.destinationCompressed()) {
int decompLen = stream._getContentsLength();
System.out.println(ind + " DC.Length is\t" + decompLen +
" - " + Integer.toHexString(decompLen));
dumpVal("DC.Length is", stream._getContentsLength(), indent+1);
}
System.out.println(ind + " Compressed is\t" + ptr.destinationCompressed());
System.out.println(ind + " Stream is\t" + stream.getClass().getName());
dumpVal("Compressed is", ptr.destinationCompressed(), indent+1);
dumpVal("Stream is", stream.getClass().getName(), indent+1);
byte[] db = stream._getStore()._getContents();
String ds = "";
if(db.length >= 8) {
for(int i=0; i<8; i++) {
if(i>0) ds += ", ";
ds += db[i];
}
}
System.out.println(ind + " First few bytes are\t" + ds);
String ds = (db.length >= 8) ? Arrays.toString(db) : "[]";
dumpVal("First few bytes are", ds, indent+1);
if(stream instanceof PointerContainingStream) {
PointerContainingStream pcs = (PointerContainingStream)stream;
System.out.println(ind + " Has " +
pcs.getPointedToStreams().length + " children:");
if (stream instanceof PointerContainingStream) {
Stream streams[] = ((PointerContainingStream)stream).getPointedToStreams();
dumpVal("Nbr of children", streams.length, indent+1);
for(int i=0; i<pcs.getPointedToStreams().length; i++) {
dumpStream(pcs.getPointedToStreams()[i], (indent+1));
for(Stream s : streams) {
dumpStream(s, indent+1);
}
}
if(stream instanceof ChunkStream) {
ChunkStream cs = (ChunkStream)stream;
System.out.println(ind + " Has " + cs.getChunks().length +
" chunks:");
Chunk chunks[] = ((ChunkStream)stream).getChunks();
dumpVal("Nbr of chunks", chunks.length, indent+1);
for(int i=0; i<cs.getChunks().length; i++) {
Chunk chunk = cs.getChunks()[i];
System.out.println(ind2 + "" + chunk.getName());
System.out.println(ind2 + " Length is " + chunk._getContents().length + " (" + Integer.toHexString(chunk._getContents().length) + ")");
System.out.println(ind2 + " OD Size is " + chunk.getOnDiskSize() + " (" + Integer.toHexString(chunk.getOnDiskSize()) + ")");
System.out.println(ind2 + " T / S is " + chunk.getTrailer() + " / " + chunk.getSeparator());
System.out.println(ind2 + " Holds " + chunk.getCommands().length + " commands");
for(int j=0; j<chunk.getCommands().length; j++) {
Command command = chunk.getCommands()[j];
System.out.println(ind3 + "" +
command.getDefinition().getName() +
" " + command.getValue()
);
}
for(Chunk chunk : chunks) {
dumpChunk(chunk, indent+1);
}
}
}
private void dumpChunk(Chunk chunk, int indent) {
dumpVal(chunk.getName(), "", indent);
dumpVal("Length is", chunk._getContents().length, indent);
dumpVal("OD Size is", chunk.getOnDiskSize(), indent);
dumpVal("T / S is", chunk.getTrailer() + " / " + chunk.getSeparator(), indent);
Command commands[] = chunk.getCommands();
dumpVal("Nbr of commands", commands.length, indent);
for(Command command : commands) {
dumpVal(command.getDefinition().getName(), ""+command.getValue(), indent+1);
}
}
private void dumpVal(String label, long value, int indent) {
ps.print(tabs.substring(0,indent));
ps.print(label);
ps.print('\t');
ps.print(value);
ps.print(" (0x");
ps.print(Long.toHexString(value));
ps.println(")");
}
private void dumpVal(String label, boolean value, int indent) {
dumpVal(label, Boolean.toString(value), indent);
}
private void dumpVal(String label, String value, int indent) {
ps.print(tabs.substring(0,indent));
ps.print(label);
ps.print('\t');
ps.println(value);
}
}

View File

@ -19,17 +19,22 @@ package org.apache.poi.hslf.dev;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.io.PrintStream;
import java.util.List;
import java.util.Locale;
import org.apache.poi.hslf.record.Record;
import org.apache.poi.util.HexDump;
import org.apache.poi.ddf.DefaultEscherRecordFactory;
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherTextboxRecord;
import org.apache.poi.hslf.record.*;
import org.apache.poi.hslf.record.EscherTextboxWrapper;
import org.apache.poi.hslf.record.HSLFEscherRecordFactory;
import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.StyleTextPropAtom;
import org.apache.poi.hslf.record.TextBytesAtom;
import org.apache.poi.hslf.record.TextCharsAtom;
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.util.HexDump;
/**
* This class provides a way to view the contents of a powerpoint file.
@ -39,209 +44,203 @@ import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
* @author Nick Burch
*/
public final class SlideShowRecordDumper {
private boolean optVerbose;
private boolean optEscher;
private HSLFSlideShowImpl doc;
final static String tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
private boolean optVerbose;
private boolean optEscher;
private HSLFSlideShowImpl doc;
private final PrintStream ps;
/**
* right now this function takes one parameter: a ppt file, and outputs
* a dump of what it contains
*/
public static void main(String args[]) throws IOException
{
String filename = "";
boolean verbose = false;
boolean escher = false;
/**
* right now this function takes one parameter: a ppt file, and outputs a
* dump of what it contains
*/
public static void main(String args[]) throws IOException {
String filename = "";
boolean verbose = false;
boolean escher = false;
int ndx=0;
for (; ndx<args.length; ndx++) {
if (!args[ndx].substring(0,1).equals("-"))
break;
int ndx = 0;
for (; ndx < args.length; ndx++) {
if (!args[ndx].substring(0, 1).equals("-"))
break;
if (args[ndx].equals("-escher")) {
escher = true;
} else if (args[ndx].equals("-verbose")) {
verbose = true;
} else {
printUsage();
return;
}
}
// parsed any options, expect exactly one remaining arg (filename)
if (ndx != args.length-1) {
printUsage();
return;
}
filename = args[ndx];
SlideShowRecordDumper foo = new SlideShowRecordDumper(filename, verbose, escher);
foo.printDump();
}
public static void printUsage() {
System.err.println("Usage: SlideShowRecordDumper [-escher] [-verbose] <filename>");
System.err.println("Valid Options:");
System.err.println("-escher\t\t: dump contents of escher records");
System.err.println("-verbose\t: dump binary contents of each record");
}
/**
* Constructs a Powerpoint dump from fileName. Parses the document
* and dumps out the contents
*
* @param fileName The name of the file to read.
* @throws IOException if there is a problem while parsing the document.
*/
public SlideShowRecordDumper(String fileName, boolean verbose, boolean escher) throws IOException
{
optVerbose = verbose;
optEscher = escher;
doc = new HSLFSlideShowImpl(fileName);
}
public void printDump() throws IOException {
// Prints out the records in the tree
walkTree(0,0,doc.getRecords());
}
public String makeHex(int number, int padding) {
String hex = Integer.toHexString(number).toUpperCase(Locale.ROOT);
while(hex.length() < padding) {
hex = "0" + hex;
}
return hex;
}
public String reverseHex(String s) {
StringBuffer ret = new StringBuffer();
// Get to a multiple of two
if((s.length() / 2) * 2 != s.length()) { s = "0" + s; }
// Break up into blocks
char[] c = s.toCharArray();
for(int i=c.length; i>0; i-=2) {
ret.append(c[i-2]);
ret.append(c[i-1]);
if(i != 2) { ret.append(' '); }
}
return ret.toString();
}
public int getDiskLen(Record r) throws IOException {
if (r == null) return 0;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
r.writeOut(baos);
byte[] b = baos.toByteArray();
return b.length;
}
public String getPrintableRecordContents(Record r) throws IOException {
if (r==null) return "<<null>>";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
r.writeOut(baos);
byte[] b = baos.toByteArray();
return HexDump.dump(b, 0, 0);
}
public String printEscherRecord( EscherRecord er ) {
String nl = System.getProperty( "line.separator" );
StringBuffer buf = new StringBuffer();
if (er instanceof EscherContainerRecord) {
buf.append(printEscherContainerRecord( (EscherContainerRecord)er ));
} else if (er instanceof EscherTextboxRecord) {
buf.append("EscherTextboxRecord:" + nl);
EscherTextboxWrapper etw = new EscherTextboxWrapper((EscherTextboxRecord)er);
Record children[] = etw.getChildRecords();
for (int j=0; j<children.length; j++) {
if (children[j] instanceof StyleTextPropAtom) {
// need preceding Text[Chars|Bytes]Atom to initialize the data structure
if (j > 0 && (children[j-1] instanceof TextCharsAtom ||
children[j-1] instanceof TextBytesAtom)) {
int size = (children[j-1] instanceof TextCharsAtom) ?
((TextCharsAtom)children[j-1]).getText().length() :
((TextBytesAtom)children[j-1]).getText().length();
StyleTextPropAtom tsp = (StyleTextPropAtom)children[j];
tsp.setParentTextSize(size);
} else {
buf.append("Error! Couldn't find preceding TextAtom for style\n");
}
buf.append(children[j].toString() + nl );
} else {
buf.append(children[j].toString() + nl );
}
}
} else {
buf.append( er.toString() );
}
return buf.toString();
}
public String printEscherContainerRecord( EscherContainerRecord ecr ) {
String indent = "";
String nl = System.getProperty( "line.separator" );
StringBuffer children = new StringBuffer();
int count = 0;
for ( Iterator<EscherRecord> iterator = ecr.getChildIterator(); iterator.hasNext(); )
{
if (count < 1) {
children.append( " children: " + nl );
if (args[ndx].equals("-escher")) {
escher = true;
} else if (args[ndx].equals("-verbose")) {
verbose = true;
} else {
printUsage();
return;
}
String newIndent = " ";
EscherRecord record = iterator.next();
children.append(newIndent + "Child " + count + ":" + nl);
children.append( printEscherRecord(record) );
count++;
}
return
indent + ecr.getClass().getName() + " (" + ecr.getRecordName() + "):" + nl +
indent + " isContainer: " + ecr.isContainerRecord() + nl +
indent + " options: 0x" + HexDump.toHex( ecr.getOptions() ) + nl +
indent + " recordId: 0x" + HexDump.toHex( ecr.getRecordId() ) + nl +
indent + " numchildren: " + ecr.getChildRecords().size() + nl +
indent + children.toString();
}
// parsed any options, expect exactly one remaining arg (filename)
if (ndx != args.length - 1) {
printUsage();
return;
}
filename = args[ndx];
SlideShowRecordDumper foo = new SlideShowRecordDumper(System.out,
filename, verbose, escher);
foo.printDump();
}
public static void printUsage() {
System.err.println("Usage: SlideShowRecordDumper [-escher] [-verbose] <filename>");
System.err.println("Valid Options:");
System.err.println("-escher\t\t: dump contents of escher records");
System.err.println("-verbose\t: dump binary contents of each record");
}
/**
* Constructs a Powerpoint dump from fileName. Parses the document
* and dumps out the contents
*
* @param fileName The name of the file to read.
* @throws IOException if there is a problem while parsing the document.
*/
public SlideShowRecordDumper(PrintStream ps, String fileName, boolean verbose, boolean escher)
throws IOException {
this.ps = ps;
optVerbose = verbose;
optEscher = escher;
doc = new HSLFSlideShowImpl(fileName);
}
public void walkTree(int depth, int pos, Record[] records) throws IOException {
int indent = depth;
String ind = "";
for(int i=0; i<indent; i++) { ind += " "; }
public void printDump() throws IOException {
// Prints out the records in the tree
walkTree(0, 0, doc.getRecords(), 0);
}
for(int i=0; i<records.length; i++) {
Record r = records[i];
if (r == null) {
System.out.println(ind + "At position " + pos + " (" + makeHex(pos,6) + "):");
System.out.println(ind + "Warning! Null record found.");
continue;
public String makeHex(int number, int padding) {
String hex = Integer.toHexString(number).toUpperCase(Locale.ROOT);
while (hex.length() < padding) {
hex = "0" + hex;
}
return hex;
}
public String reverseHex(String s) {
StringBuilder ret = new StringBuilder();
// Get to a multiple of two
int pos = 0;
if ((s.length() & 1) == 1) {
ret.append(0);
pos++;
}
for (char c : s.toCharArray()) {
if (pos > 0 && (pos & 1) == 0) {
ret.append(' ');
}
ret.append(c);
pos++;
}
return ret.toString();
}
public int getDiskLen(Record r) throws IOException {
int diskLen = 0;
if (r != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
r.writeOut(baos);
diskLen = baos.size();
}
return diskLen;
}
public String getPrintableRecordContents(Record r) throws IOException {
if (r == null) {
return "<<null>>";
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
r.writeOut(baos);
byte[] b = baos.toByteArray();
return HexDump.dump(b, 0, 0);
}
public void printEscherRecord(EscherRecord er, int indent) {
if (er instanceof EscherContainerRecord) {
printEscherContainerRecord( (EscherContainerRecord)er, indent );
} else if (er instanceof EscherTextboxRecord) {
printEscherTextBox( (EscherTextboxRecord)er, indent );
} else {
ps.print( tabs.substring(0, indent) );
ps.println( er.toString() );
}
}
// Figure out how big it is
int len = getDiskLen(r);
private void printEscherTextBox( EscherTextboxRecord tbRecord, int indent ) {
String ind = tabs.substring(0, indent);
ps.println(ind+"EscherTextboxRecord:");
// Grab the type as hex
String hexType = makeHex((int)r.getRecordType(),4);
String rHexType = reverseHex(hexType);
EscherTextboxWrapper etw = new EscherTextboxWrapper(tbRecord);
Record prevChild = null;
for (Record child : etw.getChildRecords()) {
if (child instanceof StyleTextPropAtom) {
// need preceding Text[Chars|Bytes]Atom to initialize the data structure
String text = null;
if (prevChild instanceof TextCharsAtom) {
text = ((TextCharsAtom)prevChild).getText();
} else if (prevChild instanceof TextBytesAtom) {
text = ((TextBytesAtom)prevChild).getText();
} else {
ps.println(ind+"Error! Couldn't find preceding TextAtom for style");
continue;
}
StyleTextPropAtom tsp = (StyleTextPropAtom)child;
tsp.setParentTextSize(text.length());
}
ps.println(ind+child.toString());
prevChild = child;
}
}
private void printEscherContainerRecord( EscherContainerRecord ecr, int indent ) {
String ind = tabs.substring(0, indent);
ps.println(ind + ecr.getClass().getName() + " (" + ecr.getRecordName() + "):");
ps.println(ind + " isContainer: " + ecr.isContainerRecord());
ps.println(ind + " options: 0x" + HexDump.toHex( ecr.getOptions() ));
ps.println(ind + " recordId: 0x" + HexDump.toHex( ecr.getRecordId() ));
List<EscherRecord> childRecords = ecr.getChildRecords();
ps.println(ind + " numchildren: " + childRecords.size());
ps.println(ind + " children: ");
int count = 0;
for ( EscherRecord record : childRecords ) {
ps.println(ind + " Child " + count + ":");
printEscherRecord(record, indent+1);
count++;
}
}
public void walkTree(int depth, int pos, Record[] records, int indent) throws IOException {
String ind = tabs.substring(0, indent);
for (int i = 0; i < records.length; i++) {
Record r = records[i];
if (r == null) {
ps.println(ind + "At position " + pos + " (" + makeHex(pos, 6) + "):");
ps.println(ind + "Warning! Null record found.");
continue;
}
// Figure out how big it is
int len = getDiskLen(r);
// Grab the type as hex
String hexType = makeHex((int) r.getRecordType(), 4);
String rHexType = reverseHex(hexType);
// Grab the hslf.record type
Class<? extends Record> c = r.getClass();
@ -254,10 +253,10 @@ public final class SlideShowRecordDumper {
}
// Display the record
System.out.println(ind + "At position " + pos + " (" + makeHex(pos,6) + "):");
System.out.println(ind + " Record is of type " + cname);
System.out.println(ind + " Type is " + r.getRecordType() + " (" + hexType + " -> " + rHexType + " )");
System.out.println(ind + " Len is " + (len-8) + " (" + makeHex((len-8),8) + "), on disk len is " + len );
ps.println(ind + "At position " + pos + " (" + makeHex(pos,6) + "):");
ps.println(ind + " Record is of type " + cname);
ps.println(ind + " Type is " + r.getRecordType() + " (" + hexType + " -> " + rHexType + " )");
ps.println(ind + " Len is " + (len-8) + " (" + makeHex((len-8),8) + "), on disk len is " + len );
// print additional information for drawings and atoms
if (optEscher && cname.equals("PPDrawing")) {
@ -270,18 +269,18 @@ public final class SlideShowRecordDumper {
EscherRecord er = factory.createRecord(b, 0);
er.fillFields(b, 0, factory);
System.out.println( printEscherRecord( er ) );
printEscherRecord( er, indent+1 );
} else if(optVerbose && r.getChildRecords() == null) {
String recData = getPrintableRecordContents(r);
System.out.println(ind + recData );
ps.println(ind + recData );
}
System.out.println();
ps.println();
// If it has children, show them
if(r.getChildRecords() != null) {
walkTree((depth+3),pos+8,r.getChildRecords());
walkTree((depth+3),pos+8,r.getChildRecords(), indent+1);
}
// Wind on the position marker

View File

@ -21,7 +21,6 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.poi.hssf.record.chart.*;
import org.apache.poi.hssf.record.BOFRecord;
import org.apache.poi.hssf.record.DimensionsRecord;
import org.apache.poi.hssf.record.EOFRecord;
@ -35,6 +34,38 @@ import org.apache.poi.hssf.record.RecordBase;
import org.apache.poi.hssf.record.SCLRecord;
import org.apache.poi.hssf.record.UnknownRecord;
import org.apache.poi.hssf.record.VCenterRecord;
import org.apache.poi.hssf.record.chart.AreaFormatRecord;
import org.apache.poi.hssf.record.chart.AxisLineFormatRecord;
import org.apache.poi.hssf.record.chart.AxisOptionsRecord;
import org.apache.poi.hssf.record.chart.AxisParentRecord;
import org.apache.poi.hssf.record.chart.AxisRecord;
import org.apache.poi.hssf.record.chart.AxisUsedRecord;
import org.apache.poi.hssf.record.chart.BarRecord;
import org.apache.poi.hssf.record.chart.BeginRecord;
import org.apache.poi.hssf.record.chart.CategorySeriesAxisRecord;
import org.apache.poi.hssf.record.chart.ChartFormatRecord;
import org.apache.poi.hssf.record.chart.ChartRecord;
import org.apache.poi.hssf.record.chart.ChartTitleFormatRecord;
import org.apache.poi.hssf.record.chart.DataFormatRecord;
import org.apache.poi.hssf.record.chart.DefaultDataLabelTextPropertiesRecord;
import org.apache.poi.hssf.record.chart.EndRecord;
import org.apache.poi.hssf.record.chart.FontBasisRecord;
import org.apache.poi.hssf.record.chart.FontIndexRecord;
import org.apache.poi.hssf.record.chart.FrameRecord;
import org.apache.poi.hssf.record.chart.LegendRecord;
import org.apache.poi.hssf.record.chart.LineFormatRecord;
import org.apache.poi.hssf.record.chart.LinkedDataRecord;
import org.apache.poi.hssf.record.chart.PlotAreaRecord;
import org.apache.poi.hssf.record.chart.PlotGrowthRecord;
import org.apache.poi.hssf.record.chart.SeriesIndexRecord;
import org.apache.poi.hssf.record.chart.SeriesRecord;
import org.apache.poi.hssf.record.chart.SeriesTextRecord;
import org.apache.poi.hssf.record.chart.SeriesToChartGroupRecord;
import org.apache.poi.hssf.record.chart.SheetPropertiesRecord;
import org.apache.poi.hssf.record.chart.TextRecord;
import org.apache.poi.hssf.record.chart.TickRecord;
import org.apache.poi.hssf.record.chart.UnitsRecord;
import org.apache.poi.hssf.record.chart.ValueRangeRecord;
import org.apache.poi.ss.formula.ptg.Area3DPtg;
import org.apache.poi.ss.formula.ptg.AreaPtgBase;
import org.apache.poi.ss.formula.ptg.Ptg;
@ -51,7 +82,8 @@ public final class HSSFChart {
private ChartRecord chartRecord;
private LegendRecord legendRecord;
private ChartTitleFormatRecord chartTitleFormat;
@SuppressWarnings("unused")
private ChartTitleFormatRecord chartTitleFormat;
private SeriesTextRecord chartTitleText;
private List<ValueRangeRecord> valueRanges = new ArrayList<ValueRangeRecord>();
@ -111,7 +143,7 @@ public final class HSSFChart {
* NOTE: Does not yet work... checking it in just so others
* can take a look.
*/
public void createBarChart( HSSFWorkbook workbook, HSSFSheet sheet )
public void createBarChart( HSSFWorkbook workbook, HSSFSheet parentSheet )
{
List<Record> records = new ArrayList<Record>();
@ -175,7 +207,7 @@ public final class HSSFChart {
sheet.insertChartRecords( records );
parentSheet.insertChartRecords( records );
workbook.insertChartRecord();
}
@ -201,7 +233,7 @@ public final class HSSFChart {
} else if(r instanceof LegendRecord) {
lastChart.legendRecord = (LegendRecord)r;
} else if(r instanceof SeriesRecord) {
HSSFSeries series = lastChart.new HSSFSeries( (SeriesRecord)r );
HSSFSeries series = new HSSFSeries( (SeriesRecord)r );
lastChart.series.add(series);
lastSeries = series;
} else if(r instanceof ChartTitleFormatRecord) {
@ -213,8 +245,7 @@ public final class HSSFChart {
SeriesTextRecord str = (SeriesTextRecord)r;
if(lastChart.legendRecord == null &&
lastChart.series.size() > 0) {
HSSFSeries series = (HSSFSeries)
lastChart.series.get(lastChart.series.size()-1);
HSSFSeries series = lastChart.series.get(lastChart.series.size()-1);
series.seriesTitleText = str;
} else {
lastChart.chartTitleText = str;
@ -244,8 +275,7 @@ public final class HSSFChart {
}
}
return (HSSFChart[])
charts.toArray( new HSSFChart[charts.size()] );
return charts.toArray( new HSSFChart[charts.size()] );
}
/** Get the X offset of the chart */
@ -270,8 +300,7 @@ public final class HSSFChart {
* Returns the series of the chart
*/
public HSSFSeries[] getSeries() {
return (HSSFSeries[])
series.toArray(new HSSFSeries[series.size()]);
return series.toArray(new HSSFSeries[series.size()]);
}
/**
@ -307,7 +336,7 @@ public final class HSSFChart {
* @param minorUnit minor unit value; Double.NaN - automatic; null - no change
*/
public void setValueRange( int axisIndex, Double minimum, Double maximum, Double majorUnit, Double minorUnit){
ValueRangeRecord valueRange = (ValueRangeRecord)valueRanges.get( axisIndex );
ValueRangeRecord valueRange = valueRanges.get( axisIndex );
if( valueRange == null ) return;
if( minimum != null ){
valueRange.setAutomaticMinimum(minimum.isNaN());
@ -962,7 +991,7 @@ public final class HSSFChart {
/**
* A series in a chart
*/
public class HSSFSeries {
public static class HSSFSeries {
private SeriesRecord series;
private SeriesTextRecord seriesTitleText;
private LinkedDataRecord dataName;
@ -1225,13 +1254,13 @@ public final class HSSFChart {
newSeries = new HSSFSeries(seriesRecord);
newRecord = seriesRecord;
} else if (record instanceof LinkedDataRecord) {
LinkedDataRecord linkedDataRecord = (LinkedDataRecord) ((LinkedDataRecord)record).clone();
LinkedDataRecord linkedDataRecord = ((LinkedDataRecord)record).clone();
if (newSeries != null) {
newSeries.insertData(linkedDataRecord);
}
newRecord = linkedDataRecord;
} else if (record instanceof DataFormatRecord) {
DataFormatRecord dataFormatRecord = (DataFormatRecord) ((DataFormatRecord)record).clone();
DataFormatRecord dataFormatRecord = ((DataFormatRecord)record).clone();
dataFormatRecord.setSeriesIndex((short)seriesIdx) ;
dataFormatRecord.setSeriesNumber((short)seriesIdx) ;
@ -1267,8 +1296,7 @@ public final class HSSFChart {
return newSeries;
}
public boolean removeSeries(HSSFSeries series) {
int idx = 0;
public boolean removeSeries(HSSFSeries remSeries) {
int deep = 0;
int chartDeep = -1;
int lastSeriesDeep = -1;
@ -1282,7 +1310,6 @@ public final class HSSFChart {
Iterator<RecordBase> iter = records.iterator();
while (iter.hasNext()) {
RecordBase record = iter.next();
idx++;
if (record instanceof BeginRecord) {
deep++;
@ -1311,7 +1338,7 @@ public final class HSSFChart {
}
} else if (record instanceof SeriesRecord) {
if (chartEntered) {
if (series.series == record) {
if (remSeries.series == record) {
lastSeriesDeep = deep;
removeSeries = true;
} else {