make EscherContainerRecord.toString() indent children even if they don't support toString(indent)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1151802 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sergey Vladimirov 2011-07-28 11:45:25 +00:00
parent 49a7f2fc9d
commit 3ca7d0b7d8
1 changed files with 20 additions and 28 deletions

View File

@ -17,14 +17,14 @@
package org.apache.poi.ddf;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.io.PrintWriter;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
/**
* Escher container records store other escher records as children.
@ -223,43 +223,35 @@ public final class EscherContainerRecord extends EscherRecord {
}
public String toString()
{
return toString("");
}
public String toString(String indent)
{
String nl = System.getProperty( "line.separator" );
StringBuffer children = new StringBuffer();
if (_childRecords.size() > 0) {
if ( _childRecords.size() > 0 )
{
children.append( " children: " + nl );
int count = 0;
for ( Iterator<EscherRecord> iterator = _childRecords.iterator(); iterator.hasNext(); )
for ( Iterator<EscherRecord> iterator = _childRecords.iterator(); iterator
.hasNext(); )
{
String newIndent = indent + " ";
EscherRecord record = iterator.next();
children.append(newIndent + "Child " + count + ":" + nl);
if(record instanceof EscherContainerRecord) {
EscherContainerRecord ecr = (EscherContainerRecord)record;
children.append( ecr.toString(newIndent));
} else {
children.append( record.toString() );
}
children.append( " Child " + count + ":" + nl );
String childResult = String.valueOf( record );
childResult = childResult.replaceAll( "\n", "\n " );
children.append( " " );
children.append( childResult );
children.append( nl );
count++;
}
}
return
indent + getClass().getName() + " (" + getRecordName() + "):" + nl +
indent + " isContainer: " + isContainerRecord() + nl +
indent + " options: 0x" + HexDump.toHex( getOptions() ) + nl +
indent + " recordId: 0x" + HexDump.toHex( getRecordId() ) + nl +
indent + " numchildren: " + _childRecords.size() + nl +
indent + children.toString();
return getClass().getName() + " (" + getRecordName() + "):" + nl
+ " isContainer: " + isContainerRecord() + nl
+ " options: 0x" + HexDump.toHex( getOptions() ) + nl
+ " recordId: 0x" + HexDump.toHex( getRecordId() ) + nl
+ " numchildren: " + _childRecords.size() + nl
+ children.toString();
}
public EscherSpRecord getChildById(short recordId) {