From 2ed838fe7c36cdb98f18c57bbde7ef6427037222 Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Mon, 2 Jan 2017 00:55:49 +0000 Subject: [PATCH] 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 --- .../poi/hslf/record/ColorSchemeAtom.java | 18 +- .../poi/hslf/record/FontEntityAtom.java | 7 +- .../poi/hslf/record/PersistPtrHolder.java | 3 +- .../org/apache/poi/hslf/record/Record.java | 9 +- .../apache/poi/hslf/record/RecordTypes.java | 2 +- .../org/apache/poi/hslf/record/SlideAtom.java | 9 +- .../poi/hslf/record/StyleTextPropAtom.java | 22 ++- .../poi/hslf/record/TextHeaderAtom.java | 18 +- .../poi/hslf/record/TextSpecInfoAtom.java | 2 +- .../apache/poi/hslf/record/UserEditAtom.java | 20 +- .../poi/hslf/usermodel/HSLFFreeformShape.java | 12 +- .../poi/hslf/usermodel/HSLFSimpleShape.java | 22 ++- .../apache/poi/hslf/usermodel/HSLFSlide.java | 44 +++-- .../usermodel/HSLFSlideShowEncrypted.java | 19 +- .../apache/poi/hslf/usermodel/HSLFTable.java | 16 +- .../poi/hslf/usermodel/HSLFTextParagraph.java | 178 +++++++++++------- 16 files changed, 257 insertions(+), 144 deletions(-) diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java index 9d14b7bff5..c720a555ce 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java @@ -17,10 +17,12 @@ package org.apache.poi.hslf.record; -import org.apache.poi.util.LittleEndian; +import java.io.ByteArrayOutputStream; import java.io.IOException; 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 @@ -97,7 +99,7 @@ public final class ColorSchemeAtom extends RecordAtom { if(len < 40) { len = 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 */ - public long getRecordType() { return _type; } + @Override + public long getRecordType() { return _type; } /** @@ -155,7 +158,7 @@ public final class ColorSchemeAtom extends RecordAtom { writeLittleEndian(rgb,baos); } catch(IOException ie) { // Should never happen - throw new RuntimeException(ie); + throw new HSLFException(ie); } byte[] b = baos.toByteArray(); System.arraycopy(b,0,ret,0,3); @@ -174,7 +177,7 @@ public final class ColorSchemeAtom extends RecordAtom { */ public static int joinRGB(byte[] rgb) { 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]; 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 * to disk */ - public void writeOut(OutputStream out) throws IOException { + @Override + public void writeOut(OutputStream out) throws IOException { // Header - size or type unchanged out.write(_header); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java index 23a7fe1e40..80126fdb9f 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java @@ -20,6 +20,7 @@ package org.apache.poi.hslf.record; import java.io.IOException; import java.io.OutputStream; +import org.apache.poi.hslf.exceptions.HSLFException; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.StringUtil; @@ -67,6 +68,7 @@ public final class FontEntityAtom extends RecordAtom { LittleEndian.putInt(_header, 4, _recdata.length); } + @Override public long getRecordType() { return RecordTypes.FontEntityAtom.typeID; } @@ -103,7 +105,7 @@ public final class FontEntityAtom extends RecordAtom { // Ensure it's not now too long 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 @@ -207,7 +209,8 @@ public final class FontEntityAtom extends RecordAtom { /** * 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(_recdata); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java b/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java index 85f0eb9273..8a1c482696 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java @@ -27,6 +27,7 @@ import java.util.Map.Entry; import java.util.TreeMap; 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.LittleEndian; import org.apache.poi.util.POILogger; @@ -215,7 +216,7 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom lastSlideId = nextSlideId; } catch (IOException e) { // ByteArrayOutputStream is very unlikely throwing a IO exception (maybe because of OOM ...) - throw new RuntimeException(e); + throw new HSLFException(e); } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Record.java b/src/scratchpad/src/org/apache/poi/hslf/record/Record.java index e2987b3d62..73017b798d 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Record.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Record.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.List; 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.POILogFactory; import org.apache.poi.util.POILogger; @@ -180,13 +181,13 @@ public abstract class Record // Instantiate toReturn = con.newInstance(new Object[] { b, start, len }); } 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) { - 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) { - 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) { - 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 diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java b/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java index 6e3932606a..c0c57255f3 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java @@ -279,7 +279,7 @@ public enum RecordTypes { // } // } // } catch (IllegalAccessException e){ -// throw new RuntimeException("Failed to initialize records types"); +// throw new HSLFException("Failed to initialize records types"); // } // } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtom.java index 68f75c09b1..16be0c6a80 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtom.java @@ -20,6 +20,7 @@ package org.apache.poi.hslf.record; import java.io.IOException; import java.io.OutputStream; +import org.apache.poi.hslf.exceptions.HSLFException; import org.apache.poi.util.LittleEndian; /** @@ -138,13 +139,15 @@ public final class SlideAtom extends RecordAtom /** * 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 * to disk */ - public void writeOut(OutputStream out) throws IOException { + @Override + public void writeOut(OutputStream out) throws IOException { // Header out.write(_header); @@ -211,7 +214,7 @@ public final class SlideAtom extends RecordAtom */ public SSlideLayoutAtom(byte[] data) { 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 diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java index bfb9d741ab..238385b684 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java @@ -17,13 +17,18 @@ 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.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.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 @@ -121,7 +126,7 @@ public final class StyleTextPropAtom extends RecordAtom if(len < 18) { len = 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 { updateRawContents(); } 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 */ + @Override 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 * to disk */ + @Override public void writeOut(OutputStream out) throws IOException { // First thing to do is update the raw bytes of the contents, based // on the properties @@ -203,7 +210,9 @@ public final class StyleTextPropAtom extends RecordAtom * contains, so we can go ahead and initialise ourselves. */ public void setParentTextSize(int size) { - if (initialised) return; + if (initialised) { + return; + } int pos = 0; int textHandled = 0; @@ -365,6 +374,7 @@ public final class StyleTextPropAtom extends RecordAtom * * @return the string representation of the record data */ + @Override public String toString(){ StringBuffer out = new StringBuffer(); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java index 3fab236a1c..2d4f41bddc 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java @@ -17,10 +17,12 @@ package org.apache.poi.hslf.record; -import org.apache.poi.util.LittleEndian; import java.io.IOException; 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 * 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 RecordContainer getParentRecord() { return parentRecord; } - public void setParentRecord(RecordContainer record) { this.parentRecord = record; } + @Override + public RecordContainer getParentRecord() { return parentRecord; } + @Override + public void setParentRecord(RecordContainer record) { this.parentRecord = record; } /* *************** record code follows ********************** */ @@ -75,7 +79,7 @@ public final class TextHeaderAtom extends RecordAtom implements ParentAwareRecor if(len < 12) { len = 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 */ - public long getRecordType() { return _type; } + @Override + public long getRecordType() { return _type; } /** * 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 { // Header - size or type unchanged out.write(_header); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java index d18054ee61..7f87086bfa 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java @@ -112,7 +112,7 @@ public final class TextSpecInfoAtom extends RecordAtom { try { sir.writeOut(bos); } catch (IOException e) { - throw new RuntimeException(e); + throw new HSLFException(e); } _data = bos.toByteArray(); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java index b1bd6bba3e..54a0e5033a 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java @@ -17,13 +17,14 @@ 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.OutputStream; 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 * 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 */ - public long getRecordType() { return _type; } + @Override + public long getRecordType() { return _type; } /** * At write-out time, update the references to PersistPtrs and * other UserEditAtoms to point to their new positions */ - public void updateOtherRecordReferences(Map oldToNewReferencesLookup) { + @Override + public void updateOtherRecordReferences(Map oldToNewReferencesLookup) { // Look up the new positions of our preceding UserEditAtomOffset if(lastUserEditAtomOffset != 0) { Integer newLocation = oldToNewReferencesLookup.get(Integer.valueOf(lastUserEditAtomOffset)); 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(); } @@ -159,7 +162,7 @@ public final class UserEditAtom extends PositionDependentRecordAtom // Ditto for our PersistPtr Integer newLocation = oldToNewReferencesLookup.get(Integer.valueOf(persistPointersOffset)); 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(); } @@ -168,7 +171,8 @@ public final class UserEditAtom extends PositionDependentRecordAtom * 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 { // Header out.write(_header); diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java index ee8c50a716..dc05075368 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java @@ -232,7 +232,9 @@ public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformSh it.next(); } - if(!isClosed) segInfo.add(SEGMENTINFO_LINETO); + if(!isClosed) { + segInfo.add(SEGMENTINFO_LINETO); + } segInfo.add(new byte[]{0x00, (byte)0x80}); AbstractEscherOptRecord opt = getEscherOptRecord(); @@ -357,9 +359,11 @@ public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformSh } private void fillPoint(byte xyMaster[], double xyPoints[]) { - int masterCnt = (xyMaster == null) ? 0 : xyMaster.length; - int pointCnt = (xyPoints == null) ? 0 : xyPoints.length; - if ((masterCnt != 4 && masterCnt != 8) || pointCnt != 2) { + if (xyMaster == null || xyPoints == null) { + LOG.log(POILogger.WARN, "Master bytes or points not set - ignore point"); + 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"); return; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java index d8352e5bf0..8618dbeb0e 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java @@ -166,7 +166,9 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape getShadow() { AbstractEscherOptRecord opt = getEscherOptRecord(); - if (opt == null) return null; + if (opt == null) { + return null; + } EscherProperty shadowType = opt.lookup(EscherProperties.SHADOWSTYLE__TYPE); - if (shadowType == null) return null; + if (shadowType == null) { + return null; + } return new Shadow(){ @Override diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java index d3a613222b..a37b7abbca 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java @@ -25,6 +25,7 @@ import org.apache.poi.ddf.EscherContainerRecord; import org.apache.poi.ddf.EscherDgRecord; import org.apache.poi.ddf.EscherDggRecord; 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.HeadersFooters; import org.apache.poi.hslf.record.ColorSchemeAtom; @@ -83,7 +84,7 @@ public final class HSLFSlide extends HSLFSheet implements Slide 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 set shapeId for the container descriptor and background *

*/ + @Override public void onCreate(){ //initialize drawing group id EscherDggRecord dgg = getSlideShow().getDocumentRecord().getPPDrawingGroup().getEscherDggRecord(); @@ -176,7 +180,9 @@ public final class HSLFSlide extends HSLFSheet implements Slide tp : getTextParagraphs()) { - if (tp.isEmpty()) continue; + if (tp.isEmpty()) { + continue; + } int type = tp.get(0).getRunType(); switch (type) { case TextHeaderAtom.CENTER_TITLE_TYPE: @@ -230,7 +238,8 @@ public final class HSLFSlide extends HSLFSheet implements Slide> getTextParagraphs() { return _paragraphs; } + @Override + public List> getTextParagraphs() { return _paragraphs; } /** * Returns the (public facing) page number of this slide @@ -257,13 +266,18 @@ public final class HSLFSlide extends HSLFSheet implements Slidetrue if the slide follows master, * false otherwise */ + @Override public void setFollowMasterBackground(boolean flag){ SlideAtom sa = getSlideRecord().getSlideAtom(); sa.setFollowMasterBackground(flag); @@ -294,6 +309,7 @@ public final class HSLFSlide extends HSLFSheet implements Slidetrue if the slide follows master background, * false otherwise */ + @Override public boolean getFollowMasterBackground(){ SlideAtom sa = getSlideRecord().getSlideAtom(); return sa.getFollowMasterBackground(); @@ -305,6 +321,7 @@ public final class HSLFSlide extends HSLFSheet implements Slidetrue if the slide draws master sheet objects, * false otherwise */ + @Override public void setFollowMasterObjects(boolean flag){ SlideAtom sa = getSlideRecord().getSlideAtom(); sa.setFollowMasterObjects(flag); @@ -338,6 +355,7 @@ public final class HSLFSlide extends HSLFSheet implements Slidetrue if the slide draws master sheet objects, * false otherwise */ + @Override public boolean getFollowMasterObjects(){ SlideAtom sa = getSlideRecord().getSlideAtom(); return sa.getFollowMasterObjects(); @@ -346,7 +364,8 @@ public final class HSLFSlide extends HSLFSheet implements Slide newParas = shape.getTextParagraphs(); _paragraphs.add(newParas); @@ -467,14 +488,13 @@ public final class HSLFSlide extends HSLFSheet implements Slide { protected HSLFTable(int numRows, int numCols, ShapeContainer parent) { super(parent); - if(numRows < 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"); + if(numRows < 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; cells = new HSLFTableCell[numRows][numCols]; @@ -310,16 +314,16 @@ implements HSLFShapeContainer, TableShape { } } - if (lfit < threshold) { + if (lfit < threshold && lline != null) { tc.borderLeft = lline.l; } - if (tfit < threshold) { + if (tfit < threshold && tline != null) { tc.borderTop = tline.l; } - if (rfit < threshold) { + if (rfit < threshold && rline != null) { tc.borderRight = rline.l; } - if (bfit < threshold) { + if (bfit < threshold && bline != null) { tc.borderBottom = bline.l; } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java index 322cb10d2b..4cb3a310c3 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java @@ -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.TextPropCollection; import org.apache.poi.hslf.model.textproperties.TextPropCollection.TextPropType; -import org.apache.poi.hslf.record.ColorSchemeAtom; -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.hslf.record.*; import org.apache.poi.sl.draw.DrawPaint; import org.apache.poi.sl.usermodel.AutoNumberingScheme; import org.apache.poi.sl.usermodel.PaintStyle; @@ -195,7 +174,9 @@ public final class HSLFTextParagraph implements TextParagraph= records.length) { @@ -301,7 +292,9 @@ public final class HSLFTextParagraph implements TextParagraph= ant.length) return null; + if (ant == null || level == -1 || level >= ant.length) { + return null; + } return ant[level].getAutoNumberScheme(); } public Integer getAutoNumberingStartAt() { - if (styleTextProp9Atom == null) return null; + if (styleTextProp9Atom == null) { + return null; + } TextPFException9[] ant = styleTextProp9Atom.getAutoNumberTypes(); int level = getIndentLevel(); - if (ant == null || level >= ant.length) return null; + if (ant == null || level >= ant.length) { + return null; + } Short startAt = ant[level].getAutoNumberStartNumber(); assert(startAt != null); return startAt.intValue(); @@ -447,7 +454,9 @@ public final class HSLFTextParagraph implements TextParagraph ltr = p.getTextRuns(); if (ltr.isEmpty()) { - throw new RuntimeException("paragraph without textruns found"); + throw new HSLFException("paragraph without textruns found"); } lastRun = ltr.get(ltr.size() - 1); assert (lastRun.getRawText() != null); @@ -889,9 +908,13 @@ public final class HSLFTextParagraph implements TextParagraph> runsV = new ArrayList>(); for (EscherTextboxWrapper wrapper : ppdrawing.getTextboxWrappers()) { List p = findTextParagraphs(wrapper, sheet); - if (p != null) runsV.add(p); + if (p != null) { + runsV.add(p); + } } return runsV; } @@ -1205,7 +1233,7 @@ public final class HSLFTextParagraph implements TextParagraph> sheetRuns = sheet.getTextParagraphs(); @@ -1213,9 +1241,13 @@ public final class HSLFTextParagraph implements TextParagraph r : sheetRuns) { - if (r.isEmpty()) continue; + if (r.isEmpty()) { + continue; + } int ridx = r.get(0).getIndex(); - if (ridx > idx) break; + if (ridx > idx) { + break; + } if (ridx == idx) { if (rv == null) { rv = r; @@ -1251,7 +1283,7 @@ public final class HSLFTextParagraph implements TextParagraph h.getEndIndex()) break; + if (csIdx > h.getEndIndex()) { + break; + } List runs = p.getTextRuns(); for (int rlen=0,rIdx=0; rIdx < runs.size(); csIdx+=rlen, rIdx++) { HSLFTextRun run = runs.get(rIdx); @@ -1443,7 +1479,9 @@ public final class HSLFTextParagraph implements TextParagraph= paragraphs.size()) return; + if (paraIdx >= paragraphs.size()) { + return; + } HSLFTextParagraph htp = paragraphs.get(paraIdx); TextPropCollection pCopy = new TextPropCollection(0, TextPropType.paragraph); pCopy.copy(p); @@ -1452,7 +1490,9 @@ public final class HSLFTextParagraph implements TextParagraph= paragraphs.size() || ccPara >= ccStyle-1) return; + if (paraIdx >= paragraphs.size() || ccPara >= ccStyle-1) { + return; + } HSLFTextParagraph para = paragraphs.get(paraIdx); int len = 0; for (HSLFTextRun trun : para.getTextRuns()) { @@ -1517,7 +1559,9 @@ public final class HSLFTextParagraph implements TextParagraph