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
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));
}
}
/**
* We are of type 3999
*/
- public long getRecordType() { return _type; }
+ @Override
+ public long getRecordType() { return _type; }
/**
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);
*/
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);
* 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);
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;
LittleEndian.putInt(_header, 4, _recdata.length);
}
+ @Override
public long getRecordType() {
return RecordTypes.FontEntityAtom.typeID;
}
// 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
/**
* 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);
}
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;
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);
}
}
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;
// 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
// }
// }
// } catch (IllegalAccessException e){
-// throw new RuntimeException("Failed to initialize records types");
+// throw new HSLFException("Failed to initialize records types");
// }
// }
import java.io.IOException;
import java.io.OutputStream;
+import org.apache.poi.hslf.exceptions.HSLFException;
import org.apache.poi.util.LittleEndian;
/**
/**
* 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);
*/
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
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
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));
}
}
try {
updateRawContents();
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new HSLFException(e);
}
}
/**
* We are of type 4001
*/
+ @Override
public long getRecordType() { return _type; }
* 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
* 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;
*
* @return the string representation of the record data
*/
+ @Override
public String toString(){
StringBuffer out = new StringBuffer();
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
*/
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 ********************** */
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));
}
}
/**
* 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);
try {
sir.writeOut(bos);
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new HSLFException(e);
}
_data = bos.toByteArray();
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.
/**
* 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<Integer,Integer> oldToNewReferencesLookup) {
+ @Override
+ public void updateOtherRecordReferences(Map<Integer,Integer> 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();
}
// 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();
}
* 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);
it.next();
}
- if(!isClosed) segInfo.add(SEGMENTINFO_LINETO);
+ if(!isClosed) {
+ segInfo.add(SEGMENTINFO_LINETO);
+ }
segInfo.add(new byte[]{0x00, (byte)0x80});
AbstractEscherOptRecord opt = getEscherOptRecord();
}
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;
}
AbstractEscherOptRecord opt = getEscherOptRecord();
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);
return clr == null ? null : clr;
AbstractEscherOptRecord opt = getEscherOptRecord();
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);
return clr == null ? null : clr;
}
name = name.replace("adj", "");
- if ("".equals(name)) name = "1";
+ if ("".equals(name)) {
+ name = "1";
+ }
short escherProp;
switch (Integer.parseInt(name)) {
case 8: escherProp = EscherProperties.GEOMETRY__ADJUST8VALUE; break;
case 9: escherProp = EscherProperties.GEOMETRY__ADJUST9VALUE; 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
@Override
public Shadow<HSLFShape,HSLFTextParagraph> 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<HSLFShape,HSLFTextParagraph>(){
@Override
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;
// Grab text from SlideListWithTexts entries
_paragraphs.addAll(HSLFTextParagraph.findTextParagraphs(_atomSet.getSlideRecords()));
if (_paragraphs.isEmpty()) {
- throw new RuntimeException("No text records found for slide");
+ throw new HSLFException("No text records found for slide");
}
} else {
// No text on the slide, must just be pictures
// Grab text from slide's PPDrawing
for (List<HSLFTextParagraph> l : HSLFTextParagraph.findTextParagraphs(getPPDrawing(), this)) {
- if (!_paragraphs.contains(l)) _paragraphs.add(l);
+ if (!_paragraphs.contains(l)) {
+ _paragraphs.add(l);
+ }
}
}
* <li> set shapeId for the container descriptor and background
* </p>
*/
+ @Override
public void onCreate(){
//initialize drawing group id
EscherDggRecord dgg = getSlideShow().getDocumentRecord().getPPDrawingGroup().getEscherDggRecord();
default:
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
@Override
public String getTitle(){
for (List<HSLFTextParagraph> tp : getTextParagraphs()) {
- if (tp.isEmpty()) continue;
+ if (tp.isEmpty()) {
+ continue;
+ }
int type = tp.get(0).getRunType();
switch (type) {
case TextHeaderAtom.CENTER_TITLE_TYPE:
/**
* 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
*
* @return the master sheet associated with this slide.
*/
- public HSLFMasterSheet getMasterSheet(){
+ @Override
+ public HSLFMasterSheet getMasterSheet(){
int masterId = getSlideRecord().getSlideAtom().getMasterID();
for (HSLFSlideMaster sm : getSlideShow().getSlideMasters()) {
- if (masterId == sm._getSheetNumber()) return sm;
+ if (masterId == sm._getSheetNumber()) {
+ return sm;
+ }
}
for (HSLFTitleMaster tm : getSlideShow().getTitleMasters()) {
- if (masterId == tm._getSheetNumber()) return tm;
+ if (masterId == tm._getSheetNumber()) {
+ return tm;
+ }
}
return null;
}
* @param flag <code>true</code> if the slide follows master,
* <code>false</code> otherwise
*/
+ @Override
public void setFollowMasterBackground(boolean flag){
SlideAtom sa = getSlideRecord().getSlideAtom();
sa.setFollowMasterBackground(flag);
* @return <code>true</code> if the slide follows master background,
* <code>false</code> otherwise
*/
+ @Override
public boolean getFollowMasterBackground(){
SlideAtom sa = getSlideRecord().getSlideAtom();
return sa.getFollowMasterBackground();
* @param flag <code>true</code> if the slide draws master sheet objects,
* <code>false</code> otherwise
*/
+ @Override
public void setFollowMasterObjects(boolean flag){
SlideAtom sa = getSlideRecord().getSlideAtom();
sa.setFollowMasterObjects(flag);
* @return <code>true</code> if the slide draws master sheet objects,
* <code>false</code> otherwise
*/
+ @Override
public boolean getFollowMasterObjects(){
SlideAtom sa = getSlideRecord().getSlideAtom();
return sa.getFollowMasterObjects();
/**
* Background for this slide.
*/
- public HSLFBackground getBackground() {
+ @Override
+ public HSLFBackground getBackground() {
if(getFollowMasterBackground()) {
return getMasterSheet().getBackground();
}
/**
* Color scheme for this slide.
*/
+ @Override
public ColorSchemeAtom getColorScheme() {
if(getFollowMasterScheme()){
return getMasterSheet().getColorScheme();
return new HeadersFooters(this, HeadersFootersContainer.SlideHeadersFootersContainer);
}
+ @Override
protected void onAddTextShape(HSLFTextShape shape) {
List<HSLFTextParagraph> newParas = shape.getTextParagraphs();
_paragraphs.add(newParas);
draw.draw(graphics);
}
+ @Override
public boolean getFollowMasterColourScheme() {
- // TODO Auto-generated method stub
return false;
}
+ @Override
public void setFollowMasterColourScheme(boolean follow) {
- // TODO Auto-generated method stub
-
}
@Override
import java.util.NavigableMap;
import java.util.TreeMap;
+import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException;
import org.apache.poi.hslf.record.DocumentEncryptionAtom;
} catch (Exception e) {
throw new EncryptedPowerPointFileException(e);
} finally {
- try {
- if (ccis != null) {
- ccis.close();
- }
- lei.close();
- } catch (IOException e) {
- throw new EncryptedPowerPointFileException(e);
- }
+ IOUtils.closeQuietly(ccis);
+ IOUtils.closeQuietly(lei);
}
}
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(uea.getLastOnDiskOffset(), uea);
recordList.add(r);
}
- assert(ptr != null);
+ if (ptr == null || uea == null) {
+ throw new EncryptedDocumentException("UserEditAtom or PersistPtrholder not found.");
+ }
if (deaSlideId == -1 && deaOffset == -1) {
return records;
}
protected HSLFTable(int numRows, int numCols, ShapeContainer<HSLFShape,HSLFTextParagraph> 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];
}
}
- 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;
}
}
import org.apache.poi.hslf.model.textproperties.TextProp;\r
import org.apache.poi.hslf.model.textproperties.TextPropCollection;\r
import org.apache.poi.hslf.model.textproperties.TextPropCollection.TextPropType;\r
-import org.apache.poi.hslf.record.ColorSchemeAtom;\r
-import org.apache.poi.hslf.record.EscherTextboxWrapper;\r
-import org.apache.poi.hslf.record.FontCollection;\r
-import org.apache.poi.hslf.record.InteractiveInfo;\r
-import org.apache.poi.hslf.record.MasterTextPropAtom;\r
-import org.apache.poi.hslf.record.OEPlaceholderAtom;\r
-import org.apache.poi.hslf.record.OutlineTextRefAtom;\r
-import org.apache.poi.hslf.record.PPDrawing;\r
-import org.apache.poi.hslf.record.Record;\r
-import org.apache.poi.hslf.record.RecordContainer;\r
-import org.apache.poi.hslf.record.RecordTypes;\r
-import org.apache.poi.hslf.record.RoundTripHFPlaceholder12;\r
-import org.apache.poi.hslf.record.SlideListWithText;\r
-import org.apache.poi.hslf.record.SlidePersistAtom;\r
-import org.apache.poi.hslf.record.StyleTextProp9Atom;\r
-import org.apache.poi.hslf.record.StyleTextPropAtom;\r
-import org.apache.poi.hslf.record.TextBytesAtom;\r
-import org.apache.poi.hslf.record.TextCharsAtom;\r
-import org.apache.poi.hslf.record.TextHeaderAtom;\r
-import org.apache.poi.hslf.record.TextRulerAtom;\r
-import org.apache.poi.hslf.record.TextSpecInfoAtom;\r
-import org.apache.poi.hslf.record.TxInteractiveInfoAtom;\r
+import org.apache.poi.hslf.record.*;\r
import org.apache.poi.sl.draw.DrawPaint;\r
import org.apache.poi.sl.usermodel.AutoNumberingScheme;\r
import org.apache.poi.sl.usermodel.PaintStyle;\r
private void supplySheet(HSLFSheet sheet) {\r
this._sheet = sheet;\r
\r
- if (_runs == null) return;\r
+ if (_runs == null) {\r
+ return;\r
+ }\r
for (HSLFTextRun rt : _runs) {\r
rt.updateSheet();\r
}\r
* @param index\r
*/\r
protected void setIndex(int index) {\r
- if (_headerAtom != null) _headerAtom.setIndex(index);\r
+ if (_headerAtom != null) {\r
+ _headerAtom.setIndex(index);\r
+ }\r
}\r
\r
/**\r
}\r
\r
public void setRunType(int runType) {\r
- if (_headerAtom != null) _headerAtom.setTextType(runType);\r
+ if (_headerAtom != null) {\r
+ _headerAtom.setTextType(runType);\r
+ }\r
}\r
\r
/**\r
if (_ruler == null) {\r
_ruler = TextRulerAtom.getParagraphInstance();\r
Record childAfter = _byteAtom;\r
- if (childAfter == null) childAfter = _charAtom;\r
- if (childAfter == null) childAfter = _headerAtom;\r
+ if (childAfter == null) {\r
+ childAfter = _charAtom;\r
+ }\r
+ if (childAfter == null) {\r
+ childAfter = _headerAtom;\r
+ }\r
_headerAtom.getParentRecord().addChildAfter(_ruler, childAfter);\r
}\r
return _ruler;\r
\r
for (; startIdx[0] < records.length; startIdx[0]++) {\r
Record r = records[startIdx[0]];\r
- if (r instanceof TextHeaderAtom && (headerAtom == null || r == headerAtom)) break;\r
+ if (r instanceof TextHeaderAtom && (headerAtom == null || r == headerAtom)) {\r
+ break;\r
+ }\r
}\r
\r
if (startIdx[0] >= records.length) {\r
int length;\r
for (length = 1; startIdx[0] + length < records.length; length++) {\r
Record r = records[startIdx[0]+length];\r
- if (r instanceof TextHeaderAtom || r instanceof SlidePersistAtom) break;\r
+ if (r instanceof TextHeaderAtom || r instanceof SlidePersistAtom) {\r
+ break;\r
+ }\r
}\r
\r
Record result[] = new Record[length];\r
@Override\r
public void setTextAlign(TextAlign align) {\r
Integer alignInt = null;\r
- if (align != null) switch (align) {\r
- default:\r
- case LEFT: alignInt = TextAlignmentProp.LEFT;break;\r
- case CENTER: alignInt = TextAlignmentProp.CENTER; break;\r
- case RIGHT: alignInt = TextAlignmentProp.RIGHT; break;\r
- case DIST: alignInt = TextAlignmentProp.DISTRIBUTED; break;\r
- case JUSTIFY: alignInt = TextAlignmentProp.JUSTIFY; break;\r
- case JUSTIFY_LOW: alignInt = TextAlignmentProp.JUSTIFYLOW; break;\r
- case THAI_DIST: alignInt = TextAlignmentProp.THAIDISTRIBUTED; break;\r
+ if (align != null) {\r
+ switch (align) {\r
+ default:\r
+ case LEFT: alignInt = TextAlignmentProp.LEFT;break;\r
+ case CENTER: alignInt = TextAlignmentProp.CENTER; break;\r
+ case RIGHT: alignInt = TextAlignmentProp.RIGHT; break;\r
+ case DIST: alignInt = TextAlignmentProp.DISTRIBUTED; break;\r
+ case JUSTIFY: alignInt = TextAlignmentProp.JUSTIFY; break;\r
+ case JUSTIFY_LOW: alignInt = TextAlignmentProp.JUSTIFYLOW; break;\r
+ case THAI_DIST: alignInt = TextAlignmentProp.THAIDISTRIBUTED; break;\r
+ }\r
}\r
setParagraphTextPropVal("alignment", alignInt);\r
}\r
@Override\r
public TextAlign getTextAlign() {\r
TextProp tp = getPropVal(_paragraphStyle, "alignment", this);\r
- if (tp == null) return null;\r
+ if (tp == null) {\r
+ return null;\r
+ }\r
switch (tp.getValue()) {\r
default:\r
case TextAlignmentProp.LEFT: return TextAlign.LEFT;\r
@Override\r
public FontAlign getFontAlign() {\r
TextProp tp = getPropVal(_paragraphStyle, FontAlignmentProp.NAME, this);\r
- if (tp == null) return null;\r
+ if (tp == null) {\r
+ return null;\r
+ }\r
\r
switch (tp.getValue()) {\r
case FontAlignmentProp.BASELINE: return FontAlign.BASELINE;\r
}\r
\r
public AutoNumberingScheme getAutoNumberingScheme() {\r
- if (styleTextProp9Atom == null) return null;\r
+ if (styleTextProp9Atom == null) {\r
+ return null;\r
+ }\r
TextPFException9[] ant = styleTextProp9Atom.getAutoNumberTypes();\r
int level = getIndentLevel();\r
- if (ant == null || level == -1 || level >= ant.length) return null;\r
+ if (ant == null || level == -1 || level >= ant.length) {\r
+ return null;\r
+ }\r
return ant[level].getAutoNumberScheme();\r
}\r
\r
public Integer getAutoNumberingStartAt() {\r
- if (styleTextProp9Atom == null) return null;\r
+ if (styleTextProp9Atom == null) {\r
+ return null;\r
+ }\r
TextPFException9[] ant = styleTextProp9Atom.getAutoNumberTypes();\r
int level = getIndentLevel();\r
- if (ant == null || level >= ant.length) return null;\r
+ if (ant == null || level >= ant.length) {\r
+ return null;\r
+ }\r
Short startAt = ant[level].getAutoNumberStartNumber();\r
assert(startAt != null);\r
return startAt.intValue();\r
\r
@Override\r
public BulletStyle getBulletStyle() {\r
- if (!isBullet() && getAutoNumberingScheme() == null) return null;\r
+ if (!isBullet() && getAutoNumberingScheme() == null) {\r
+ return null;\r
+ }\r
\r
return new BulletStyle() {\r
@Override\r
\r
@Override\r
public void setIndentLevel(int level) {\r
- if( _paragraphStyle != null ) _paragraphStyle.setIndentLevel((short)level);\r
+ if( _paragraphStyle != null ) {\r
+ _paragraphStyle.setIndentLevel((short)level);\r
+ }\r
}\r
\r
/**\r
public String getBulletFont() {\r
TextProp tp = getPropVal(_paragraphStyle, "bullet.font", this);\r
boolean hasFont = getFlag(ParagraphFlagsTextProp.BULLET_HARDFONT_IDX);\r
- if (tp == null || !hasFont) return getDefaultFontFamily();\r
+ if (tp == null || !hasFont) {\r
+ return getDefaultFontFamily();\r
+ }\r
PPFont ppFont = getSheet().getSlideShow().getFont(tp.getValue());\r
assert(ppFont != null);\r
return ppFont.getFontName();\r
\r
private Double getPctOrPoints(String propName) {\r
TextProp tp = getPropVal(_paragraphStyle, propName, this);\r
- if (tp == null) return null;\r
+ if (tp == null) {\r
+ return null;\r
+ }\r
int val = tp.getValue();\r
return (val < 0) ? Units.masterToPoints(val) : val;\r
}\r
\r
BitMaskTextProp maskProp = (BitMaskTextProp) props.findByName(ParagraphFlagsTextProp.NAME);\r
boolean hardAttribute = (maskProp != null && maskProp.getValue() == 0);\r
- if (hardAttribute) return null;\r
+ if (hardAttribute) {\r
+ return null;\r
+ }\r
\r
HSLFSheet sheet = paragraph.getSheet();\r
int txtype = paragraph.getRunType();\r
\r
for (String pn : propNames) {\r
TextProp prop = master.getStyleAttribute(txtype, paragraph.getIndentLevel(), pn, isChar);\r
- if (prop != null) return prop;\r
+ if (prop != null) {\r
+ return prop;\r
+ }\r
}\r
\r
return null;\r
}\r
List<HSLFTextRun> ltr = p.getTextRuns();\r
if (ltr.isEmpty()) {\r
- throw new RuntimeException("paragraph without textruns found");\r
+ throw new HSLFException("paragraph without textruns found");\r
}\r
lastRun = ltr.get(ltr.size() - 1);\r
assert (lastRun.getRawText() != null);\r
int /* headerIdx = -1, */ textIdx = -1, styleIdx = -1;\r
for (int i = 0; i < cr.length; i++) {\r
Record r = cr[i];\r
- if (r == headerAtom) ; // headerIdx = i;\r
- else if (r == oldRecord || r == newRecord) textIdx = i;\r
- else if (r == styleAtom) styleIdx = i;\r
+ if (r == headerAtom) {\r
+ ; // headerIdx = i;\r
+ } else if (r == oldRecord || r == newRecord) {\r
+ textIdx = i;\r
+ } else if (r == styleAtom) {\r
+ styleIdx = i;\r
+ }\r
}\r
\r
if (textIdx == -1) {\r
}\r
}\r
\r
- assert (lastPTPC != null && lastRTPC != null && ptpc != null && rtpc != null);\r
+ if (lastPTPC == null || lastRTPC == null || ptpc == null || rtpc == null) {\r
+ throw new HSLFException("Not all TextPropCollection could be determined.");\r
+ }\r
+ \r
ptpc.updateTextSize(ptpc.getCharactersCovered() + 1);\r
rtpc.updateTextSize(rtpc.getCharactersCovered() + 1);\r
lastPTPC.updateTextSize(lastPTPC.getCharactersCovered() + 1);\r
try {\r
((EscherTextboxWrapper) _txtbox).writeOut(null);\r
} catch (IOException e) {\r
- throw new RuntimeException("failed dummy write", e);\r
+ throw new HSLFException("failed dummy write", e);\r
}\r
}\r
}\r
List<List<HSLFTextParagraph>> runsV = new ArrayList<List<HSLFTextParagraph>>();\r
for (EscherTextboxWrapper wrapper : ppdrawing.getTextboxWrappers()) {\r
List<HSLFTextParagraph> p = findTextParagraphs(wrapper, sheet);\r
- if (p != null) runsV.add(p);\r
+ if (p != null) {\r
+ runsV.add(p);\r
+ }\r
}\r
return runsV;\r
}\r
if (ota != null) {\r
// if we are based on an outline, there are no further records to be parsed from the wrapper\r
if (sheet == null) {\r
- throw new RuntimeException("Outline atom reference can't be solved without a sheet record");\r
+ throw new HSLFException("Outline atom reference can't be solved without a sheet record");\r
}\r
\r
List<List<HSLFTextParagraph>> sheetRuns = sheet.getTextParagraphs();\r
\r
int idx = ota.getTextIndex();\r
for (List<HSLFTextParagraph> r : sheetRuns) {\r
- if (r.isEmpty()) continue;\r
+ if (r.isEmpty()) {\r
+ continue;\r
+ }\r
int ridx = r.get(0).getIndex();\r
- if (ridx > idx) break;\r
+ if (ridx > idx) {\r
+ break;\r
+ }\r
if (ridx == idx) {\r
if (rv == null) {\r
rv = r;\r
case 0: break; // nothing found\r
case 1: rv = rvl.get(0); break; // normal case\r
default:\r
- throw new RuntimeException("TextBox contains more than one list of paragraphs.");\r
+ throw new HSLFException("TextBox contains more than one list of paragraphs.");\r
}\r
}\r
}\r
// don't search for RecordTypes.StyleTextPropAtom.typeID here ... see findStyleAtomPresent below\r
}\r
\r
- if (header == null) break;\r
+ if (header == null) {\r
+ break;\r
+ }\r
\r
if (header.getParentRecord() instanceof SlideListWithText) {\r
// runs found in PPDrawing are not linked with SlideListWithTexts\r
for (HSLFHyperlink h : links) {\r
int csIdx = 0;\r
for (HSLFTextParagraph p : paragraphs) {\r
- if (csIdx > h.getEndIndex()) break;\r
+ if (csIdx > h.getEndIndex()) {\r
+ break;\r
+ }\r
List<HSLFTextRun> runs = p.getTextRuns();\r
for (int rlen=0,rIdx=0; rIdx < runs.size(); csIdx+=rlen, rIdx++) {\r
HSLFTextRun run = runs.get(rIdx);\r
int paraIdx = 0;\r
for (TextPropCollection p : paraStyles) {\r
for (int ccPara = 0, ccStyle = p.getCharactersCovered(); ccPara < ccStyle; paraIdx++) {\r
- if (paraIdx >= paragraphs.size()) return;\r
+ if (paraIdx >= paragraphs.size()) {\r
+ return;\r
+ }\r
HSLFTextParagraph htp = paragraphs.get(paraIdx);\r
TextPropCollection pCopy = new TextPropCollection(0, TextPropType.paragraph);\r
pCopy.copy(p);\r
for (HSLFTextRun trun : htp.getTextRuns()) {\r
len += trun.getLength();\r
}\r
- if (paraIdx == paragraphs.size()-1) len++;\r
+ if (paraIdx == paragraphs.size()-1) {\r
+ len++;\r
+ }\r
pCopy.updateTextSize(len);\r
ccPara += len;\r
}\r
int paraIdx = 0;\r
for (IndentProp p : paraStyles) {\r
for (int ccPara = 0, ccStyle = p.getCharactersCovered(); ccPara < ccStyle; paraIdx++) {\r
- if (paraIdx >= paragraphs.size() || ccPara >= ccStyle-1) return;\r
+ if (paraIdx >= paragraphs.size() || ccPara >= ccStyle-1) {\r
+ return;\r
+ }\r
HSLFTextParagraph para = paragraphs.get(paraIdx);\r
int len = 0;\r
for (HSLFTextRun trun : para.getTextRuns()) {\r
switch (cidx) {\r
// Background ... Accent 3 color\r
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:\r
- if (sheet == null) return null;\r
+ if (sheet == null) {\r
+ return null;\r
+ }\r
ColorSchemeAtom ca = sheet.getColorScheme();\r
tmp = new Color(ca.getColor(cidx), true);\r
break;\r