Sonarqube fixes

- replace RuntimeException with application specific runtime exception
- clean-up sources - add braces to if statements and add override annotations
- fix a few hslf blockers

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1776896 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2017-01-02 00:55:49 +00:00
parent f2052fe278
commit b919ad9989
16 changed files with 257 additions and 144 deletions

View File

@ -17,10 +17,12 @@
package org.apache.poi.hslf.record; package org.apache.poi.hslf.record;
import org.apache.poi.util.LittleEndian; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.ByteArrayOutputStream;
import org.apache.poi.hslf.exceptions.HSLFException;
import org.apache.poi.util.LittleEndian;
/** /**
* A ColorSchemeAtom (type 2032). Holds the 8 RGB values for the different * A ColorSchemeAtom (type 2032). Holds the 8 RGB values for the different
@ -97,7 +99,7 @@ public final class ColorSchemeAtom extends RecordAtom {
if(len < 40) { if(len < 40) {
len = 40; len = 40;
if(source.length - start < 40) { if(source.length - start < 40) {
throw new RuntimeException("Not enough data to form a ColorSchemeAtom (always 40 bytes long) - found " + (source.length - start)); throw new HSLFException("Not enough data to form a ColorSchemeAtom (always 40 bytes long) - found " + (source.length - start));
} }
} }
@ -140,7 +142,8 @@ public final class ColorSchemeAtom extends RecordAtom {
/** /**
* We are of type 3999 * We are of type 3999
*/ */
public long getRecordType() { return _type; } @Override
public long getRecordType() { return _type; }
/** /**
@ -155,7 +158,7 @@ public final class ColorSchemeAtom extends RecordAtom {
writeLittleEndian(rgb,baos); writeLittleEndian(rgb,baos);
} catch(IOException ie) { } catch(IOException ie) {
// Should never happen // Should never happen
throw new RuntimeException(ie); throw new HSLFException(ie);
} }
byte[] b = baos.toByteArray(); byte[] b = baos.toByteArray();
System.arraycopy(b,0,ret,0,3); System.arraycopy(b,0,ret,0,3);
@ -174,7 +177,7 @@ public final class ColorSchemeAtom extends RecordAtom {
*/ */
public static int joinRGB(byte[] rgb) { public static int joinRGB(byte[] rgb) {
if(rgb.length != 3) { if(rgb.length != 3) {
throw new RuntimeException("joinRGB accepts a byte array of 3 values, but got one of " + rgb.length + " values!"); throw new HSLFException("joinRGB accepts a byte array of 3 values, but got one of " + rgb.length + " values!");
} }
byte[] with_zero = new byte[4]; byte[] with_zero = new byte[4];
System.arraycopy(rgb,0,with_zero,0,3); System.arraycopy(rgb,0,with_zero,0,3);
@ -188,7 +191,8 @@ public final class ColorSchemeAtom extends RecordAtom {
* Write the contents of the record back, so it can be written * Write the contents of the record back, so it can be written
* to disk * to disk
*/ */
public void writeOut(OutputStream out) throws IOException { @Override
public void writeOut(OutputStream out) throws IOException {
// Header - size or type unchanged // Header - size or type unchanged
out.write(_header); out.write(_header);

View File

@ -20,6 +20,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import org.apache.poi.hslf.exceptions.HSLFException;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.StringUtil; import org.apache.poi.util.StringUtil;
@ -67,6 +68,7 @@ public final class FontEntityAtom extends RecordAtom {
LittleEndian.putInt(_header, 4, _recdata.length); LittleEndian.putInt(_header, 4, _recdata.length);
} }
@Override
public long getRecordType() { public long getRecordType() {
return RecordTypes.FontEntityAtom.typeID; return RecordTypes.FontEntityAtom.typeID;
} }
@ -103,7 +105,7 @@ public final class FontEntityAtom extends RecordAtom {
// Ensure it's not now too long // Ensure it's not now too long
if(name.length() > 32) { if(name.length() > 32) {
throw new RuntimeException("The length of the font name, including null termination, must not exceed 32 characters"); throw new HSLFException("The length of the font name, including null termination, must not exceed 32 characters");
} }
// Everything's happy, so save the name // Everything's happy, so save the name
@ -207,7 +209,8 @@ public final class FontEntityAtom extends RecordAtom {
/** /**
* Write the contents of the record back, so it can be written to disk * Write the contents of the record back, so it can be written to disk
*/ */
public void writeOut(OutputStream out) throws IOException { @Override
public void writeOut(OutputStream out) throws IOException {
out.write(_header); out.write(_header);
out.write(_recdata); out.write(_recdata);
} }

View File

@ -27,6 +27,7 @@ import java.util.Map.Entry;
import java.util.TreeMap; import java.util.TreeMap;
import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException; import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
import org.apache.poi.hslf.exceptions.HSLFException;
import org.apache.poi.util.BitField; import org.apache.poi.util.BitField;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
@ -215,7 +216,7 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom
lastSlideId = nextSlideId; lastSlideId = nextSlideId;
} catch (IOException e) { } catch (IOException e) {
// ByteArrayOutputStream is very unlikely throwing a IO exception (maybe because of OOM ...) // ByteArrayOutputStream is very unlikely throwing a IO exception (maybe because of OOM ...)
throw new RuntimeException(e); throw new HSLFException(e);
} }
} }

View File

@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException; import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
import org.apache.poi.hslf.exceptions.HSLFException;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
@ -180,13 +181,13 @@ public abstract class Record
// Instantiate // Instantiate
toReturn = con.newInstance(new Object[] { b, start, len }); toReturn = con.newInstance(new Object[] { b, start, len });
} catch(InstantiationException ie) { } catch(InstantiationException ie) {
throw new RuntimeException("Couldn't instantiate the class for type with id " + type + " on class " + c + " : " + ie, ie); throw new HSLFException("Couldn't instantiate the class for type with id " + type + " on class " + c + " : " + ie, ie);
} catch(java.lang.reflect.InvocationTargetException ite) { } catch(java.lang.reflect.InvocationTargetException ite) {
throw new RuntimeException("Couldn't instantiate the class for type with id " + type + " on class " + c + " : " + ite + "\nCause was : " + ite.getCause(), ite); throw new HSLFException("Couldn't instantiate the class for type with id " + type + " on class " + c + " : " + ite + "\nCause was : " + ite.getCause(), ite);
} catch(IllegalAccessException iae) { } catch(IllegalAccessException iae) {
throw new RuntimeException("Couldn't access the constructor for type with id " + type + " on class " + c + " : " + iae, iae); throw new HSLFException("Couldn't access the constructor for type with id " + type + " on class " + c + " : " + iae, iae);
} catch(NoSuchMethodException nsme) { } catch(NoSuchMethodException nsme) {
throw new RuntimeException("Couldn't access the constructor for type with id " + type + " on class " + c + " : " + nsme, nsme); throw new HSLFException("Couldn't access the constructor for type with id " + type + " on class " + c + " : " + nsme, nsme);
} }
// Handling for special kinds of records follow // Handling for special kinds of records follow

View File

@ -279,7 +279,7 @@ public enum RecordTypes {
// } // }
// } // }
// } catch (IllegalAccessException e){ // } catch (IllegalAccessException e){
// throw new RuntimeException("Failed to initialize records types"); // throw new HSLFException("Failed to initialize records types");
// } // }
// } // }

View File

@ -20,6 +20,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import org.apache.poi.hslf.exceptions.HSLFException;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
/** /**
@ -138,13 +139,15 @@ public final class SlideAtom extends RecordAtom
/** /**
* We are of type 1007 * We are of type 1007
*/ */
public long getRecordType() { return _type; } @Override
public long getRecordType() { return _type; }
/** /**
* Write the contents of the record back, so it can be written * Write the contents of the record back, so it can be written
* to disk * to disk
*/ */
public void writeOut(OutputStream out) throws IOException { @Override
public void writeOut(OutputStream out) throws IOException {
// Header // Header
out.write(_header); out.write(_header);
@ -211,7 +214,7 @@ public final class SlideAtom extends RecordAtom
*/ */
public SSlideLayoutAtom(byte[] data) { public SSlideLayoutAtom(byte[] data) {
if(data.length != 12) { if(data.length != 12) {
throw new RuntimeException("SSlideLayoutAtom created with byte array not 12 bytes long - was " + data.length + " bytes in size"); throw new HSLFException("SSlideLayoutAtom created with byte array not 12 bytes long - was " + data.length + " bytes in size");
} }
// Grab out our data // Grab out our data

View File

@ -17,13 +17,18 @@
package org.apache.poi.hslf.record; package org.apache.poi.hslf.record;
import java.io.*; import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.poi.hslf.model.textproperties.*; import org.apache.poi.hslf.exceptions.HSLFException;
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
import org.apache.poi.hslf.model.textproperties.TextPropCollection.TextPropType; import org.apache.poi.hslf.model.textproperties.TextPropCollection.TextPropType;
import org.apache.poi.util.*; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogger;
/** /**
* A StyleTextPropAtom (type 4001). Holds basic character properties * A StyleTextPropAtom (type 4001). Holds basic character properties
@ -121,7 +126,7 @@ public final class StyleTextPropAtom extends RecordAtom
if(len < 18) { if(len < 18) {
len = 18; len = 18;
if(source.length - start < 18) { if(source.length - start < 18) {
throw new RuntimeException("Not enough data to form a StyleTextPropAtom (min size 18 bytes long) - found " + (source.length - start)); throw new HSLFException("Not enough data to form a StyleTextPropAtom (min size 18 bytes long) - found " + (source.length - start));
} }
} }
@ -167,7 +172,7 @@ public final class StyleTextPropAtom extends RecordAtom
try { try {
updateRawContents(); updateRawContents();
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new HSLFException(e);
} }
} }
@ -175,6 +180,7 @@ public final class StyleTextPropAtom extends RecordAtom
/** /**
* We are of type 4001 * We are of type 4001
*/ */
@Override
public long getRecordType() { return _type; } public long getRecordType() { return _type; }
@ -182,6 +188,7 @@ public final class StyleTextPropAtom extends RecordAtom
* Write the contents of the record back, so it can be written * Write the contents of the record back, so it can be written
* to disk * to disk
*/ */
@Override
public void writeOut(OutputStream out) throws IOException { public void writeOut(OutputStream out) throws IOException {
// First thing to do is update the raw bytes of the contents, based // First thing to do is update the raw bytes of the contents, based
// on the properties // on the properties
@ -203,7 +210,9 @@ public final class StyleTextPropAtom extends RecordAtom
* contains, so we can go ahead and initialise ourselves. * contains, so we can go ahead and initialise ourselves.
*/ */
public void setParentTextSize(int size) { public void setParentTextSize(int size) {
if (initialised) return; if (initialised) {
return;
}
int pos = 0; int pos = 0;
int textHandled = 0; int textHandled = 0;
@ -365,6 +374,7 @@ public final class StyleTextPropAtom extends RecordAtom
* *
* @return the string representation of the record data * @return the string representation of the record data
*/ */
@Override
public String toString(){ public String toString(){
StringBuffer out = new StringBuffer(); StringBuffer out = new StringBuffer();

View File

@ -17,10 +17,12 @@
package org.apache.poi.hslf.record; package org.apache.poi.hslf.record;
import org.apache.poi.util.LittleEndian;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import org.apache.poi.hslf.exceptions.HSLFException;
import org.apache.poi.util.LittleEndian;
/** /**
* A TextHeaderAtom (type 3999). Holds information on what kind of * A TextHeaderAtom (type 3999). Holds information on what kind of
* text is contained in the TextBytesAtom / TextCharsAtom that follows * text is contained in the TextBytesAtom / TextCharsAtom that follows
@ -62,8 +64,10 @@ public final class TextHeaderAtom extends RecordAtom implements ParentAwareRecor
*/ */
public void setIndex(int index) { this.index = index; } public void setIndex(int index) { this.index = index; }
public RecordContainer getParentRecord() { return parentRecord; } @Override
public void setParentRecord(RecordContainer record) { this.parentRecord = record; } public RecordContainer getParentRecord() { return parentRecord; }
@Override
public void setParentRecord(RecordContainer record) { this.parentRecord = record; }
/* *************** record code follows ********************** */ /* *************** record code follows ********************** */
@ -75,7 +79,7 @@ public final class TextHeaderAtom extends RecordAtom implements ParentAwareRecor
if(len < 12) { if(len < 12) {
len = 12; len = 12;
if(source.length - start < 12) { if(source.length - start < 12) {
throw new RuntimeException("Not enough data to form a TextHeaderAtom (always 12 bytes long) - found " + (source.length - start)); throw new HSLFException("Not enough data to form a TextHeaderAtom (always 12 bytes long) - found " + (source.length - start));
} }
} }
@ -102,13 +106,15 @@ public final class TextHeaderAtom extends RecordAtom implements ParentAwareRecor
/** /**
* We are of type 3999 * We are of type 3999
*/ */
public long getRecordType() { return _type; } @Override
public long getRecordType() { return _type; }
/** /**
* Write the contents of the record back, so it can be written * Write the contents of the record back, so it can be written
* to disk * to disk
*/ */
public void writeOut(OutputStream out) throws IOException { @Override
public void writeOut(OutputStream out) throws IOException {
// Header - size or type unchanged // Header - size or type unchanged
out.write(_header); out.write(_header);

View File

@ -112,7 +112,7 @@ public final class TextSpecInfoAtom extends RecordAtom {
try { try {
sir.writeOut(bos); sir.writeOut(bos);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new HSLFException(e);
} }
_data = bos.toByteArray(); _data = bos.toByteArray();

View File

@ -17,13 +17,14 @@
package org.apache.poi.hslf.record; package org.apache.poi.hslf.record;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianConsts;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Map; import java.util.Map;
import org.apache.poi.hslf.exceptions.HSLFException;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianConsts;
/** /**
* A UserEdit Atom (type 4085). Holds information which bits of the file * A UserEdit Atom (type 4085). Holds information which bits of the file
* were last used by powerpoint, the version of powerpoint last used etc. * were last used by powerpoint, the version of powerpoint last used etc.
@ -140,18 +141,20 @@ public final class UserEditAtom extends PositionDependentRecordAtom
/** /**
* We are of type 4085 * We are of type 4085
*/ */
public long getRecordType() { return _type; } @Override
public long getRecordType() { return _type; }
/** /**
* At write-out time, update the references to PersistPtrs and * At write-out time, update the references to PersistPtrs and
* other UserEditAtoms to point to their new positions * other UserEditAtoms to point to their new positions
*/ */
public void updateOtherRecordReferences(Map<Integer,Integer> oldToNewReferencesLookup) { @Override
public void updateOtherRecordReferences(Map<Integer,Integer> oldToNewReferencesLookup) {
// Look up the new positions of our preceding UserEditAtomOffset // Look up the new positions of our preceding UserEditAtomOffset
if(lastUserEditAtomOffset != 0) { if(lastUserEditAtomOffset != 0) {
Integer newLocation = oldToNewReferencesLookup.get(Integer.valueOf(lastUserEditAtomOffset)); Integer newLocation = oldToNewReferencesLookup.get(Integer.valueOf(lastUserEditAtomOffset));
if(newLocation == null) { if(newLocation == null) {
throw new RuntimeException("Couldn't find the new location of the UserEditAtom that used to be at " + lastUserEditAtomOffset); throw new HSLFException("Couldn't find the new location of the UserEditAtom that used to be at " + lastUserEditAtomOffset);
} }
lastUserEditAtomOffset = newLocation.intValue(); lastUserEditAtomOffset = newLocation.intValue();
} }
@ -159,7 +162,7 @@ public final class UserEditAtom extends PositionDependentRecordAtom
// Ditto for our PersistPtr // Ditto for our PersistPtr
Integer newLocation = oldToNewReferencesLookup.get(Integer.valueOf(persistPointersOffset)); Integer newLocation = oldToNewReferencesLookup.get(Integer.valueOf(persistPointersOffset));
if(newLocation == null) { if(newLocation == null) {
throw new RuntimeException("Couldn't find the new location of the PersistPtr that used to be at " + persistPointersOffset); throw new HSLFException("Couldn't find the new location of the PersistPtr that used to be at " + persistPointersOffset);
} }
persistPointersOffset = newLocation.intValue(); persistPointersOffset = newLocation.intValue();
} }
@ -168,7 +171,8 @@ public final class UserEditAtom extends PositionDependentRecordAtom
* Write the contents of the record back, so it can be written * Write the contents of the record back, so it can be written
* to disk * to disk
*/ */
public void writeOut(OutputStream out) throws IOException { @Override
public void writeOut(OutputStream out) throws IOException {
// Header // Header
out.write(_header); out.write(_header);

View File

@ -232,7 +232,9 @@ public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformSh
it.next(); it.next();
} }
if(!isClosed) segInfo.add(SEGMENTINFO_LINETO); if(!isClosed) {
segInfo.add(SEGMENTINFO_LINETO);
}
segInfo.add(new byte[]{0x00, (byte)0x80}); segInfo.add(new byte[]{0x00, (byte)0x80});
AbstractEscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
@ -357,9 +359,11 @@ public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformSh
} }
private void fillPoint(byte xyMaster[], double xyPoints[]) { private void fillPoint(byte xyMaster[], double xyPoints[]) {
int masterCnt = (xyMaster == null) ? 0 : xyMaster.length; if (xyMaster == null || xyPoints == null) {
int pointCnt = (xyPoints == null) ? 0 : xyPoints.length; LOG.log(POILogger.WARN, "Master bytes or points not set - ignore point");
if ((masterCnt != 4 && masterCnt != 8) || pointCnt != 2) { return;
}
if ((xyMaster.length != 4 && xyMaster.length != 8) || xyPoints.length != 2) {
LOG.log(POILogger.WARN, "Invalid number of master bytes for a single point - ignore point"); LOG.log(POILogger.WARN, "Invalid number of master bytes for a single point - ignore point");
return; return;
} }

View File

@ -166,7 +166,9 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape<H
AbstractEscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty p = getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH); EscherSimpleProperty p = getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH);
if(p != null && (p.getPropertyValue() & 0x8) == 0) return null; if(p != null && (p.getPropertyValue() & 0x8) == 0) {
return null;
}
Color clr = getColor(EscherProperties.LINESTYLE__COLOR, EscherProperties.LINESTYLE__OPACITY, -1); Color clr = getColor(EscherProperties.LINESTYLE__COLOR, EscherProperties.LINESTYLE__OPACITY, -1);
return clr == null ? null : clr; return clr == null ? null : clr;
@ -179,7 +181,9 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape<H
AbstractEscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty p = getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH); EscherSimpleProperty p = getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH);
if(p != null && (p.getPropertyValue() & 0x8) == 0) return null; if(p != null && (p.getPropertyValue() & 0x8) == 0) {
return null;
}
Color clr = getColor(EscherProperties.LINESTYLE__BACKCOLOR, EscherProperties.LINESTYLE__OPACITY, -1); Color clr = getColor(EscherProperties.LINESTYLE__BACKCOLOR, EscherProperties.LINESTYLE__OPACITY, -1);
return clr == null ? null : clr; return clr == null ? null : clr;
@ -319,7 +323,9 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape<H
} }
name = name.replace("adj", ""); name = name.replace("adj", "");
if ("".equals(name)) name = "1"; if ("".equals(name)) {
name = "1";
}
short escherProp; short escherProp;
switch (Integer.parseInt(name)) { switch (Integer.parseInt(name)) {
@ -333,7 +339,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape<H
case 8: escherProp = EscherProperties.GEOMETRY__ADJUST8VALUE; break; case 8: escherProp = EscherProperties.GEOMETRY__ADJUST8VALUE; break;
case 9: escherProp = EscherProperties.GEOMETRY__ADJUST9VALUE; break; case 9: escherProp = EscherProperties.GEOMETRY__ADJUST9VALUE; break;
case 10: escherProp = EscherProperties.GEOMETRY__ADJUST10VALUE; break; case 10: escherProp = EscherProperties.GEOMETRY__ADJUST10VALUE; break;
default: throw new RuntimeException(); default: throw new HSLFException();
} }
// TODO: the adjust values need to be corrected somehow depending on the shape width/height // TODO: the adjust values need to be corrected somehow depending on the shape width/height
@ -392,9 +398,13 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape<H
@Override @Override
public Shadow<HSLFShape,HSLFTextParagraph> getShadow() { public Shadow<HSLFShape,HSLFTextParagraph> getShadow() {
AbstractEscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
if (opt == null) return null; if (opt == null) {
return null;
}
EscherProperty shadowType = opt.lookup(EscherProperties.SHADOWSTYLE__TYPE); EscherProperty shadowType = opt.lookup(EscherProperties.SHADOWSTYLE__TYPE);
if (shadowType == null) return null; if (shadowType == null) {
return null;
}
return new Shadow<HSLFShape,HSLFTextParagraph>(){ return new Shadow<HSLFShape,HSLFTextParagraph>(){
@Override @Override

View File

@ -25,6 +25,7 @@ import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherDgRecord; import org.apache.poi.ddf.EscherDgRecord;
import org.apache.poi.ddf.EscherDggRecord; import org.apache.poi.ddf.EscherDggRecord;
import org.apache.poi.ddf.EscherSpRecord; import org.apache.poi.ddf.EscherSpRecord;
import org.apache.poi.hslf.exceptions.HSLFException;
import org.apache.poi.hslf.model.Comment; import org.apache.poi.hslf.model.Comment;
import org.apache.poi.hslf.model.HeadersFooters; import org.apache.poi.hslf.model.HeadersFooters;
import org.apache.poi.hslf.record.ColorSchemeAtom; import org.apache.poi.hslf.record.ColorSchemeAtom;
@ -83,7 +84,7 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTe
// Grab text from SlideListWithTexts entries // Grab text from SlideListWithTexts entries
_paragraphs.addAll(HSLFTextParagraph.findTextParagraphs(_atomSet.getSlideRecords())); _paragraphs.addAll(HSLFTextParagraph.findTextParagraphs(_atomSet.getSlideRecords()));
if (_paragraphs.isEmpty()) { if (_paragraphs.isEmpty()) {
throw new RuntimeException("No text records found for slide"); throw new HSLFException("No text records found for slide");
} }
} else { } else {
// No text on the slide, must just be pictures // No text on the slide, must just be pictures
@ -91,7 +92,9 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTe
// Grab text from slide's PPDrawing // Grab text from slide's PPDrawing
for (List<HSLFTextParagraph> l : HSLFTextParagraph.findTextParagraphs(getPPDrawing(), this)) { for (List<HSLFTextParagraph> l : HSLFTextParagraph.findTextParagraphs(getPPDrawing(), this)) {
if (!_paragraphs.contains(l)) _paragraphs.add(l); if (!_paragraphs.contains(l)) {
_paragraphs.add(l);
}
} }
} }
@ -153,6 +156,7 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTe
* <li> set shapeId for the container descriptor and background * <li> set shapeId for the container descriptor and background
* </p> * </p>
*/ */
@Override
public void onCreate(){ public void onCreate(){
//initialize drawing group id //initialize drawing group id
EscherDggRecord dgg = getSlideShow().getDocumentRecord().getPPDrawingGroup().getEscherDggRecord(); EscherDggRecord dgg = getSlideShow().getDocumentRecord().getPPDrawingGroup().getEscherDggRecord();
@ -176,7 +180,9 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTe
default: default:
break; break;
} }
if(spr != null) spr.setShapeId(allocateShapeId()); if(spr != null) {
spr.setShapeId(allocateShapeId());
}
} }
//PPT doen't increment the number of saved shapes for group descriptor and background //PPT doen't increment the number of saved shapes for group descriptor and background
@ -213,7 +219,9 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTe
@Override @Override
public String getTitle(){ public String getTitle(){
for (List<HSLFTextParagraph> tp : getTextParagraphs()) { for (List<HSLFTextParagraph> tp : getTextParagraphs()) {
if (tp.isEmpty()) continue; if (tp.isEmpty()) {
continue;
}
int type = tp.get(0).getRunType(); int type = tp.get(0).getRunType();
switch (type) { switch (type) {
case TextHeaderAtom.CENTER_TITLE_TYPE: case TextHeaderAtom.CENTER_TITLE_TYPE:
@ -230,7 +238,8 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTe
/** /**
* Returns an array of all the TextRuns found * Returns an array of all the TextRuns found
*/ */
public List<List<HSLFTextParagraph>> getTextParagraphs() { return _paragraphs; } @Override
public List<List<HSLFTextParagraph>> getTextParagraphs() { return _paragraphs; }
/** /**
* Returns the (public facing) page number of this slide * Returns the (public facing) page number of this slide
@ -257,13 +266,18 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTe
* *
* @return the master sheet associated with this slide. * @return the master sheet associated with this slide.
*/ */
public HSLFMasterSheet getMasterSheet(){ @Override
public HSLFMasterSheet getMasterSheet(){
int masterId = getSlideRecord().getSlideAtom().getMasterID(); int masterId = getSlideRecord().getSlideAtom().getMasterID();
for (HSLFSlideMaster sm : getSlideShow().getSlideMasters()) { for (HSLFSlideMaster sm : getSlideShow().getSlideMasters()) {
if (masterId == sm._getSheetNumber()) return sm; if (masterId == sm._getSheetNumber()) {
return sm;
}
} }
for (HSLFTitleMaster tm : getSlideShow().getTitleMasters()) { for (HSLFTitleMaster tm : getSlideShow().getTitleMasters()) {
if (masterId == tm._getSheetNumber()) return tm; if (masterId == tm._getSheetNumber()) {
return tm;
}
} }
return null; return null;
} }
@ -283,6 +297,7 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTe
* @param flag <code>true</code> if the slide follows master, * @param flag <code>true</code> if the slide follows master,
* <code>false</code> otherwise * <code>false</code> otherwise
*/ */
@Override
public void setFollowMasterBackground(boolean flag){ public void setFollowMasterBackground(boolean flag){
SlideAtom sa = getSlideRecord().getSlideAtom(); SlideAtom sa = getSlideRecord().getSlideAtom();
sa.setFollowMasterBackground(flag); sa.setFollowMasterBackground(flag);
@ -294,6 +309,7 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTe
* @return <code>true</code> if the slide follows master background, * @return <code>true</code> if the slide follows master background,
* <code>false</code> otherwise * <code>false</code> otherwise
*/ */
@Override
public boolean getFollowMasterBackground(){ public boolean getFollowMasterBackground(){
SlideAtom sa = getSlideRecord().getSlideAtom(); SlideAtom sa = getSlideRecord().getSlideAtom();
return sa.getFollowMasterBackground(); return sa.getFollowMasterBackground();
@ -305,6 +321,7 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTe
* @param flag <code>true</code> if the slide draws master sheet objects, * @param flag <code>true</code> if the slide draws master sheet objects,
* <code>false</code> otherwise * <code>false</code> otherwise
*/ */
@Override
public void setFollowMasterObjects(boolean flag){ public void setFollowMasterObjects(boolean flag){
SlideAtom sa = getSlideRecord().getSlideAtom(); SlideAtom sa = getSlideRecord().getSlideAtom();
sa.setFollowMasterObjects(flag); sa.setFollowMasterObjects(flag);
@ -338,6 +355,7 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTe
* @return <code>true</code> if the slide draws master sheet objects, * @return <code>true</code> if the slide draws master sheet objects,
* <code>false</code> otherwise * <code>false</code> otherwise
*/ */
@Override
public boolean getFollowMasterObjects(){ public boolean getFollowMasterObjects(){
SlideAtom sa = getSlideRecord().getSlideAtom(); SlideAtom sa = getSlideRecord().getSlideAtom();
return sa.getFollowMasterObjects(); return sa.getFollowMasterObjects();
@ -346,7 +364,8 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTe
/** /**
* Background for this slide. * Background for this slide.
*/ */
public HSLFBackground getBackground() { @Override
public HSLFBackground getBackground() {
if(getFollowMasterBackground()) { if(getFollowMasterBackground()) {
return getMasterSheet().getBackground(); return getMasterSheet().getBackground();
} }
@ -356,6 +375,7 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTe
/** /**
* Color scheme for this slide. * Color scheme for this slide.
*/ */
@Override
public ColorSchemeAtom getColorScheme() { public ColorSchemeAtom getColorScheme() {
if(getFollowMasterScheme()){ if(getFollowMasterScheme()){
return getMasterSheet().getColorScheme(); return getMasterSheet().getColorScheme();
@ -425,6 +445,7 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTe
return new HeadersFooters(this, HeadersFootersContainer.SlideHeadersFootersContainer); return new HeadersFooters(this, HeadersFootersContainer.SlideHeadersFootersContainer);
} }
@Override
protected void onAddTextShape(HSLFTextShape shape) { protected void onAddTextShape(HSLFTextShape shape) {
List<HSLFTextParagraph> newParas = shape.getTextParagraphs(); List<HSLFTextParagraph> newParas = shape.getTextParagraphs();
_paragraphs.add(newParas); _paragraphs.add(newParas);
@ -467,14 +488,13 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTe
draw.draw(graphics); draw.draw(graphics);
} }
@Override
public boolean getFollowMasterColourScheme() { public boolean getFollowMasterColourScheme() {
// TODO Auto-generated method stub
return false; return false;
} }
@Override
public void setFollowMasterColourScheme(boolean follow) { public void setFollowMasterColourScheme(boolean follow) {
// TODO Auto-generated method stub
} }
@Override @Override

View File

@ -27,6 +27,7 @@ import java.util.Map;
import java.util.NavigableMap; import java.util.NavigableMap;
import java.util.TreeMap; import java.util.TreeMap;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException; import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException; import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException;
import org.apache.poi.hslf.record.DocumentEncryptionAtom; import org.apache.poi.hslf.record.DocumentEncryptionAtom;
@ -206,14 +207,8 @@ public class HSLFSlideShowEncrypted implements Closeable {
} catch (Exception e) { } catch (Exception e) {
throw new EncryptedPowerPointFileException(e); throw new EncryptedPowerPointFileException(e);
} finally { } finally {
try { IOUtils.closeQuietly(ccis);
if (ccis != null) { IOUtils.closeQuietly(lei);
ccis.close();
}
lei.close();
} catch (IOException e) {
throw new EncryptedPowerPointFileException(e);
}
} }
} }
@ -465,7 +460,9 @@ public class HSLFSlideShowEncrypted implements Closeable {
recordMap.put(pdr.getLastOnDiskOffset(), r); recordMap.put(pdr.getLastOnDiskOffset(), r);
} }
assert(uea != null && pph != null && uea.getPersistPointersOffset() == pph.getLastOnDiskOffset()); if (uea == null || pph == null || uea.getPersistPointersOffset() != pph.getLastOnDiskOffset()) {
throw new EncryptedDocumentException("UserEditAtom and PersistPtrHolder must exist and their offset need to match.");
}
recordMap.put(pph.getLastOnDiskOffset(), pph); recordMap.put(pph.getLastOnDiskOffset(), pph);
recordMap.put(uea.getLastOnDiskOffset(), uea); recordMap.put(uea.getLastOnDiskOffset(), uea);
@ -508,7 +505,9 @@ public class HSLFSlideShowEncrypted implements Closeable {
recordList.add(r); recordList.add(r);
} }
assert(ptr != null); if (ptr == null || uea == null) {
throw new EncryptedDocumentException("UserEditAtom or PersistPtrholder not found.");
}
if (deaSlideId == -1 && deaOffset == -1) { if (deaSlideId == -1 && deaOffset == -1) {
return records; return records;
} }

View File

@ -74,8 +74,12 @@ implements HSLFShapeContainer, TableShape<HSLFShape,HSLFTextParagraph> {
protected HSLFTable(int numRows, int numCols, ShapeContainer<HSLFShape,HSLFTextParagraph> parent) { protected HSLFTable(int numRows, int numCols, ShapeContainer<HSLFShape,HSLFTextParagraph> parent) {
super(parent); super(parent);
if(numRows < 1) throw new IllegalArgumentException("The number of rows must be greater than 1"); if(numRows < 1) {
if(numCols < 1) throw new IllegalArgumentException("The number of columns must be greater than 1"); throw new IllegalArgumentException("The number of rows must be greater than 1");
}
if(numCols < 1) {
throw new IllegalArgumentException("The number of columns must be greater than 1");
}
double x=0, y=0, tblWidth=0, tblHeight=0; double x=0, y=0, tblWidth=0, tblHeight=0;
cells = new HSLFTableCell[numRows][numCols]; cells = new HSLFTableCell[numRows][numCols];
@ -310,16 +314,16 @@ implements HSLFShapeContainer, TableShape<HSLFShape,HSLFTextParagraph> {
} }
} }
if (lfit < threshold) { if (lfit < threshold && lline != null) {
tc.borderLeft = lline.l; tc.borderLeft = lline.l;
} }
if (tfit < threshold) { if (tfit < threshold && tline != null) {
tc.borderTop = tline.l; tc.borderTop = tline.l;
} }
if (rfit < threshold) { if (rfit < threshold && rline != null) {
tc.borderRight = rline.l; tc.borderRight = rline.l;
} }
if (bfit < threshold) { if (bfit < threshold && bline != null) {
tc.borderBottom = bline.l; tc.borderBottom = bline.l;
} }
} }

View File

@ -36,28 +36,7 @@ import org.apache.poi.hslf.model.textproperties.TextPFException9;
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.model.textproperties.TextPropCollection.TextPropType; import org.apache.poi.hslf.model.textproperties.TextPropCollection.TextPropType;
import org.apache.poi.hslf.record.ColorSchemeAtom; import org.apache.poi.hslf.record.*;
import org.apache.poi.hslf.record.EscherTextboxWrapper;
import org.apache.poi.hslf.record.FontCollection;
import org.apache.poi.hslf.record.InteractiveInfo;
import org.apache.poi.hslf.record.MasterTextPropAtom;
import org.apache.poi.hslf.record.OEPlaceholderAtom;
import org.apache.poi.hslf.record.OutlineTextRefAtom;
import org.apache.poi.hslf.record.PPDrawing;
import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.RecordContainer;
import org.apache.poi.hslf.record.RecordTypes;
import org.apache.poi.hslf.record.RoundTripHFPlaceholder12;
import org.apache.poi.hslf.record.SlideListWithText;
import org.apache.poi.hslf.record.SlidePersistAtom;
import org.apache.poi.hslf.record.StyleTextProp9Atom;
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.record.TextHeaderAtom;
import org.apache.poi.hslf.record.TextRulerAtom;
import org.apache.poi.hslf.record.TextSpecInfoAtom;
import org.apache.poi.hslf.record.TxInteractiveInfoAtom;
import org.apache.poi.sl.draw.DrawPaint; import org.apache.poi.sl.draw.DrawPaint;
import org.apache.poi.sl.usermodel.AutoNumberingScheme; import org.apache.poi.sl.usermodel.AutoNumberingScheme;
import org.apache.poi.sl.usermodel.PaintStyle; import org.apache.poi.sl.usermodel.PaintStyle;
@ -195,7 +174,9 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
private void supplySheet(HSLFSheet sheet) { private void supplySheet(HSLFSheet sheet) {
this._sheet = sheet; this._sheet = sheet;
if (_runs == null) return; if (_runs == null) {
return;
}
for (HSLFTextRun rt : _runs) { for (HSLFTextRun rt : _runs) {
rt.updateSheet(); rt.updateSheet();
} }
@ -232,7 +213,9 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
* @param index * @param index
*/ */
protected void setIndex(int index) { protected void setIndex(int index) {
if (_headerAtom != null) _headerAtom.setIndex(index); if (_headerAtom != null) {
_headerAtom.setIndex(index);
}
} }
/** /**
@ -245,7 +228,9 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
} }
public void setRunType(int runType) { public void setRunType(int runType) {
if (_headerAtom != null) _headerAtom.setTextType(runType); if (_headerAtom != null) {
_headerAtom.setTextType(runType);
}
} }
/** /**
@ -265,8 +250,12 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
if (_ruler == null) { if (_ruler == null) {
_ruler = TextRulerAtom.getParagraphInstance(); _ruler = TextRulerAtom.getParagraphInstance();
Record childAfter = _byteAtom; Record childAfter = _byteAtom;
if (childAfter == null) childAfter = _charAtom; if (childAfter == null) {
if (childAfter == null) childAfter = _headerAtom; childAfter = _charAtom;
}
if (childAfter == null) {
childAfter = _headerAtom;
}
_headerAtom.getParentRecord().addChildAfter(_ruler, childAfter); _headerAtom.getParentRecord().addChildAfter(_ruler, childAfter);
} }
return _ruler; return _ruler;
@ -290,7 +279,9 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
for (; startIdx[0] < records.length; startIdx[0]++) { for (; startIdx[0] < records.length; startIdx[0]++) {
Record r = records[startIdx[0]]; Record r = records[startIdx[0]];
if (r instanceof TextHeaderAtom && (headerAtom == null || r == headerAtom)) break; if (r instanceof TextHeaderAtom && (headerAtom == null || r == headerAtom)) {
break;
}
} }
if (startIdx[0] >= records.length) { if (startIdx[0] >= records.length) {
@ -301,7 +292,9 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
int length; int length;
for (length = 1; startIdx[0] + length < records.length; length++) { for (length = 1; startIdx[0] + length < records.length; length++) {
Record r = records[startIdx[0]+length]; Record r = records[startIdx[0]+length];
if (r instanceof TextHeaderAtom || r instanceof SlidePersistAtom) break; if (r instanceof TextHeaderAtom || r instanceof SlidePersistAtom) {
break;
}
} }
Record result[] = new Record[length]; Record result[] = new Record[length];
@ -383,15 +376,17 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
@Override @Override
public void setTextAlign(TextAlign align) { public void setTextAlign(TextAlign align) {
Integer alignInt = null; Integer alignInt = null;
if (align != null) switch (align) { if (align != null) {
default: switch (align) {
case LEFT: alignInt = TextAlignmentProp.LEFT;break; default:
case CENTER: alignInt = TextAlignmentProp.CENTER; break; case LEFT: alignInt = TextAlignmentProp.LEFT;break;
case RIGHT: alignInt = TextAlignmentProp.RIGHT; break; case CENTER: alignInt = TextAlignmentProp.CENTER; break;
case DIST: alignInt = TextAlignmentProp.DISTRIBUTED; break; case RIGHT: alignInt = TextAlignmentProp.RIGHT; break;
case JUSTIFY: alignInt = TextAlignmentProp.JUSTIFY; break; case DIST: alignInt = TextAlignmentProp.DISTRIBUTED; break;
case JUSTIFY_LOW: alignInt = TextAlignmentProp.JUSTIFYLOW; break; case JUSTIFY: alignInt = TextAlignmentProp.JUSTIFY; break;
case THAI_DIST: alignInt = TextAlignmentProp.THAIDISTRIBUTED; break; case JUSTIFY_LOW: alignInt = TextAlignmentProp.JUSTIFYLOW; break;
case THAI_DIST: alignInt = TextAlignmentProp.THAIDISTRIBUTED; break;
}
} }
setParagraphTextPropVal("alignment", alignInt); setParagraphTextPropVal("alignment", alignInt);
} }
@ -399,7 +394,9 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
@Override @Override
public TextAlign getTextAlign() { public TextAlign getTextAlign() {
TextProp tp = getPropVal(_paragraphStyle, "alignment", this); TextProp tp = getPropVal(_paragraphStyle, "alignment", this);
if (tp == null) return null; if (tp == null) {
return null;
}
switch (tp.getValue()) { switch (tp.getValue()) {
default: default:
case TextAlignmentProp.LEFT: return TextAlign.LEFT; case TextAlignmentProp.LEFT: return TextAlign.LEFT;
@ -415,7 +412,9 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
@Override @Override
public FontAlign getFontAlign() { public FontAlign getFontAlign() {
TextProp tp = getPropVal(_paragraphStyle, FontAlignmentProp.NAME, this); TextProp tp = getPropVal(_paragraphStyle, FontAlignmentProp.NAME, this);
if (tp == null) return null; if (tp == null) {
return null;
}
switch (tp.getValue()) { switch (tp.getValue()) {
case FontAlignmentProp.BASELINE: return FontAlign.BASELINE; case FontAlignmentProp.BASELINE: return FontAlign.BASELINE;
@ -427,18 +426,26 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
} }
public AutoNumberingScheme getAutoNumberingScheme() { public AutoNumberingScheme getAutoNumberingScheme() {
if (styleTextProp9Atom == null) return null; if (styleTextProp9Atom == null) {
return null;
}
TextPFException9[] ant = styleTextProp9Atom.getAutoNumberTypes(); TextPFException9[] ant = styleTextProp9Atom.getAutoNumberTypes();
int level = getIndentLevel(); int level = getIndentLevel();
if (ant == null || level == -1 || level >= ant.length) return null; if (ant == null || level == -1 || level >= ant.length) {
return null;
}
return ant[level].getAutoNumberScheme(); return ant[level].getAutoNumberScheme();
} }
public Integer getAutoNumberingStartAt() { public Integer getAutoNumberingStartAt() {
if (styleTextProp9Atom == null) return null; if (styleTextProp9Atom == null) {
return null;
}
TextPFException9[] ant = styleTextProp9Atom.getAutoNumberTypes(); TextPFException9[] ant = styleTextProp9Atom.getAutoNumberTypes();
int level = getIndentLevel(); int level = getIndentLevel();
if (ant == null || level >= ant.length) return null; if (ant == null || level >= ant.length) {
return null;
}
Short startAt = ant[level].getAutoNumberStartNumber(); Short startAt = ant[level].getAutoNumberStartNumber();
assert(startAt != null); assert(startAt != null);
return startAt.intValue(); return startAt.intValue();
@ -447,7 +454,9 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
@Override @Override
public BulletStyle getBulletStyle() { public BulletStyle getBulletStyle() {
if (!isBullet() && getAutoNumberingScheme() == null) return null; if (!isBullet() && getAutoNumberingScheme() == null) {
return null;
}
return new BulletStyle() { return new BulletStyle() {
@Override @Override
@ -537,7 +546,9 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
@Override @Override
public void setIndentLevel(int level) { public void setIndentLevel(int level) {
if( _paragraphStyle != null ) _paragraphStyle.setIndentLevel((short)level); if( _paragraphStyle != null ) {
_paragraphStyle.setIndentLevel((short)level);
}
} }
/** /**
@ -638,7 +649,9 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
public String getBulletFont() { public String getBulletFont() {
TextProp tp = getPropVal(_paragraphStyle, "bullet.font", this); TextProp tp = getPropVal(_paragraphStyle, "bullet.font", this);
boolean hasFont = getFlag(ParagraphFlagsTextProp.BULLET_HARDFONT_IDX); boolean hasFont = getFlag(ParagraphFlagsTextProp.BULLET_HARDFONT_IDX);
if (tp == null || !hasFont) return getDefaultFontFamily(); if (tp == null || !hasFont) {
return getDefaultFontFamily();
}
PPFont ppFont = getSheet().getSlideShow().getFont(tp.getValue()); PPFont ppFont = getSheet().getSlideShow().getFont(tp.getValue());
assert(ppFont != null); assert(ppFont != null);
return ppFont.getFontName(); return ppFont.getFontName();
@ -682,7 +695,9 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
private Double getPctOrPoints(String propName) { private Double getPctOrPoints(String propName) {
TextProp tp = getPropVal(_paragraphStyle, propName, this); TextProp tp = getPropVal(_paragraphStyle, propName, this);
if (tp == null) return null; if (tp == null) {
return null;
}
int val = tp.getValue(); int val = tp.getValue();
return (val < 0) ? Units.masterToPoints(val) : val; return (val < 0) ? Units.masterToPoints(val) : val;
} }
@ -739,7 +754,9 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
BitMaskTextProp maskProp = (BitMaskTextProp) props.findByName(ParagraphFlagsTextProp.NAME); BitMaskTextProp maskProp = (BitMaskTextProp) props.findByName(ParagraphFlagsTextProp.NAME);
boolean hardAttribute = (maskProp != null && maskProp.getValue() == 0); boolean hardAttribute = (maskProp != null && maskProp.getValue() == 0);
if (hardAttribute) return null; if (hardAttribute) {
return null;
}
HSLFSheet sheet = paragraph.getSheet(); HSLFSheet sheet = paragraph.getSheet();
int txtype = paragraph.getRunType(); int txtype = paragraph.getRunType();
@ -753,7 +770,9 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
for (String pn : propNames) { for (String pn : propNames) {
TextProp prop = master.getStyleAttribute(txtype, paragraph.getIndentLevel(), pn, isChar); TextProp prop = master.getStyleAttribute(txtype, paragraph.getIndentLevel(), pn, isChar);
if (prop != null) return prop; if (prop != null) {
return prop;
}
} }
return null; return null;
@ -791,7 +810,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
} }
List<HSLFTextRun> ltr = p.getTextRuns(); List<HSLFTextRun> ltr = p.getTextRuns();
if (ltr.isEmpty()) { if (ltr.isEmpty()) {
throw new RuntimeException("paragraph without textruns found"); throw new HSLFException("paragraph without textruns found");
} }
lastRun = ltr.get(ltr.size() - 1); lastRun = ltr.get(ltr.size() - 1);
assert (lastRun.getRawText() != null); assert (lastRun.getRawText() != null);
@ -889,9 +908,13 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
int /* headerIdx = -1, */ textIdx = -1, styleIdx = -1; int /* headerIdx = -1, */ textIdx = -1, styleIdx = -1;
for (int i = 0; i < cr.length; i++) { for (int i = 0; i < cr.length; i++) {
Record r = cr[i]; Record r = cr[i];
if (r == headerAtom) ; // headerIdx = i; if (r == headerAtom) {
else if (r == oldRecord || r == newRecord) textIdx = i; ; // headerIdx = i;
else if (r == styleAtom) styleIdx = i; } else if (r == oldRecord || r == newRecord) {
textIdx = i;
} else if (r == styleAtom) {
styleIdx = i;
}
} }
if (textIdx == -1) { if (textIdx == -1) {
@ -957,7 +980,10 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
} }
} }
assert (lastPTPC != null && lastRTPC != null && ptpc != null && rtpc != null); if (lastPTPC == null || lastRTPC == null || ptpc == null || rtpc == null) {
throw new HSLFException("Not all TextPropCollection could be determined.");
}
ptpc.updateTextSize(ptpc.getCharactersCovered() + 1); ptpc.updateTextSize(ptpc.getCharactersCovered() + 1);
rtpc.updateTextSize(rtpc.getCharactersCovered() + 1); rtpc.updateTextSize(rtpc.getCharactersCovered() + 1);
lastPTPC.updateTextSize(lastPTPC.getCharactersCovered() + 1); lastPTPC.updateTextSize(lastPTPC.getCharactersCovered() + 1);
@ -1025,7 +1051,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
try { try {
((EscherTextboxWrapper) _txtbox).writeOut(null); ((EscherTextboxWrapper) _txtbox).writeOut(null);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("failed dummy write", e); throw new HSLFException("failed dummy write", e);
} }
} }
} }
@ -1183,7 +1209,9 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
List<List<HSLFTextParagraph>> runsV = new ArrayList<List<HSLFTextParagraph>>(); List<List<HSLFTextParagraph>> runsV = new ArrayList<List<HSLFTextParagraph>>();
for (EscherTextboxWrapper wrapper : ppdrawing.getTextboxWrappers()) { for (EscherTextboxWrapper wrapper : ppdrawing.getTextboxWrappers()) {
List<HSLFTextParagraph> p = findTextParagraphs(wrapper, sheet); List<HSLFTextParagraph> p = findTextParagraphs(wrapper, sheet);
if (p != null) runsV.add(p); if (p != null) {
runsV.add(p);
}
} }
return runsV; return runsV;
} }
@ -1205,7 +1233,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
if (ota != null) { if (ota != null) {
// if we are based on an outline, there are no further records to be parsed from the wrapper // if we are based on an outline, there are no further records to be parsed from the wrapper
if (sheet == null) { if (sheet == null) {
throw new RuntimeException("Outline atom reference can't be solved without a sheet record"); throw new HSLFException("Outline atom reference can't be solved without a sheet record");
} }
List<List<HSLFTextParagraph>> sheetRuns = sheet.getTextParagraphs(); List<List<HSLFTextParagraph>> sheetRuns = sheet.getTextParagraphs();
@ -1213,9 +1241,13 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
int idx = ota.getTextIndex(); int idx = ota.getTextIndex();
for (List<HSLFTextParagraph> r : sheetRuns) { for (List<HSLFTextParagraph> r : sheetRuns) {
if (r.isEmpty()) continue; if (r.isEmpty()) {
continue;
}
int ridx = r.get(0).getIndex(); int ridx = r.get(0).getIndex();
if (ridx > idx) break; if (ridx > idx) {
break;
}
if (ridx == idx) { if (ridx == idx) {
if (rv == null) { if (rv == null) {
rv = r; rv = r;
@ -1251,7 +1283,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
case 0: break; // nothing found case 0: break; // nothing found
case 1: rv = rvl.get(0); break; // normal case case 1: rv = rvl.get(0); break; // normal case
default: default:
throw new RuntimeException("TextBox contains more than one list of paragraphs."); throw new HSLFException("TextBox contains more than one list of paragraphs.");
} }
} }
} }
@ -1302,7 +1334,9 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
// don't search for RecordTypes.StyleTextPropAtom.typeID here ... see findStyleAtomPresent below // don't search for RecordTypes.StyleTextPropAtom.typeID here ... see findStyleAtomPresent below
} }
if (header == null) break; if (header == null) {
break;
}
if (header.getParentRecord() instanceof SlideListWithText) { if (header.getParentRecord() instanceof SlideListWithText) {
// runs found in PPDrawing are not linked with SlideListWithTexts // runs found in PPDrawing are not linked with SlideListWithTexts
@ -1353,7 +1387,9 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
for (HSLFHyperlink h : links) { for (HSLFHyperlink h : links) {
int csIdx = 0; int csIdx = 0;
for (HSLFTextParagraph p : paragraphs) { for (HSLFTextParagraph p : paragraphs) {
if (csIdx > h.getEndIndex()) break; if (csIdx > h.getEndIndex()) {
break;
}
List<HSLFTextRun> runs = p.getTextRuns(); List<HSLFTextRun> runs = p.getTextRuns();
for (int rlen=0,rIdx=0; rIdx < runs.size(); csIdx+=rlen, rIdx++) { for (int rlen=0,rIdx=0; rIdx < runs.size(); csIdx+=rlen, rIdx++) {
HSLFTextRun run = runs.get(rIdx); HSLFTextRun run = runs.get(rIdx);
@ -1443,7 +1479,9 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
int paraIdx = 0; int paraIdx = 0;
for (TextPropCollection p : paraStyles) { for (TextPropCollection p : paraStyles) {
for (int ccPara = 0, ccStyle = p.getCharactersCovered(); ccPara < ccStyle; paraIdx++) { for (int ccPara = 0, ccStyle = p.getCharactersCovered(); ccPara < ccStyle; paraIdx++) {
if (paraIdx >= paragraphs.size()) return; if (paraIdx >= paragraphs.size()) {
return;
}
HSLFTextParagraph htp = paragraphs.get(paraIdx); HSLFTextParagraph htp = paragraphs.get(paraIdx);
TextPropCollection pCopy = new TextPropCollection(0, TextPropType.paragraph); TextPropCollection pCopy = new TextPropCollection(0, TextPropType.paragraph);
pCopy.copy(p); pCopy.copy(p);
@ -1452,7 +1490,9 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
for (HSLFTextRun trun : htp.getTextRuns()) { for (HSLFTextRun trun : htp.getTextRuns()) {
len += trun.getLength(); len += trun.getLength();
} }
if (paraIdx == paragraphs.size()-1) len++; if (paraIdx == paragraphs.size()-1) {
len++;
}
pCopy.updateTextSize(len); pCopy.updateTextSize(len);
ccPara += len; ccPara += len;
} }
@ -1463,7 +1503,9 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
int paraIdx = 0; int paraIdx = 0;
for (IndentProp p : paraStyles) { for (IndentProp p : paraStyles) {
for (int ccPara = 0, ccStyle = p.getCharactersCovered(); ccPara < ccStyle; paraIdx++) { for (int ccPara = 0, ccStyle = p.getCharactersCovered(); ccPara < ccStyle; paraIdx++) {
if (paraIdx >= paragraphs.size() || ccPara >= ccStyle-1) return; if (paraIdx >= paragraphs.size() || ccPara >= ccStyle-1) {
return;
}
HSLFTextParagraph para = paragraphs.get(paraIdx); HSLFTextParagraph para = paragraphs.get(paraIdx);
int len = 0; int len = 0;
for (HSLFTextRun trun : para.getTextRuns()) { for (HSLFTextRun trun : para.getTextRuns()) {
@ -1517,7 +1559,9 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
switch (cidx) { switch (cidx) {
// Background ... Accent 3 color // Background ... Accent 3 color
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
if (sheet == null) return null; if (sheet == null) {
return null;
}
ColorSchemeAtom ca = sheet.getColorScheme(); ColorSchemeAtom ca = sheet.getColorScheme();
tmp = new Color(ca.getColor(cidx), true); tmp = new Color(ca.getColor(cidx), true);
break; break;