* @exception UnsupportedEncodingException if the section's codepage is not
* supported.
*/
+ @SuppressWarnings("unchecked")
public Section(final byte[] src, final int offset)
throws UnsupportedEncodingException
{
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
PropertyListEntry other = (PropertyListEntry) obj;
- if (id != other.id)
+ if (id != other.id) {
return false;
- if (length != other.length)
+ }
+ if (length != other.length) {
return false;
- if (offset != other.offset)
+ }
+ if (offset != other.offset) {
return false;
+ }
return true;
}
protected class ChainLoopDetector {
private boolean[] used_blocks;
protected ChainLoopDetector(long rawSize) {
- int numBlocks = (int)Math.ceil( ((double)rawSize) / getBlockStoreBlockSize() );
+ int blkSize = getBlockStoreBlockSize();
+ int numBlocks = (int)(rawSize / blkSize);
+ if ((rawSize % blkSize) != 0) {
+ numBlocks++;
+ }
used_blocks = new boolean[numBlocks];
}
protected void claim(int offset) {
*/
public int countBlocks()
{
- int size = _properties.size() * POIFSConstants.PROPERTY_SIZE;
- return (int)Math.ceil( ((double)size) / _bigBigBlockSize.getBigBlockSize());
+ long rawSize = _properties.size() * POIFSConstants.PROPERTY_SIZE;
+ int blkSize = _bigBigBlockSize.getBigBlockSize();
+ int numBlocks = (int)(rawSize / blkSize);
+ if ((rawSize % blkSize) != 0) {
+ numBlocks++;
+ }
+ return numBlocks;
}
/**
public static BATBlockAndIndex getBATBlockAndIndex(final int offset,
final HeaderBlock header, final List<BATBlock> bats) {
POIFSBigBlockSize bigBlockSize = header.getBigBlockSize();
+ int entriesPerBlock = bigBlockSize.getBATEntriesPerBlock();
- int whichBAT = (int)Math.floor(offset / bigBlockSize.getBATEntriesPerBlock());
- int index = offset % bigBlockSize.getBATEntriesPerBlock();
+ int whichBAT = offset / entriesPerBlock;
+ int index = offset % entriesPerBlock;
return new BATBlockAndIndex( index, bats.get(whichBAT) );
}
public static BATBlockAndIndex getSBATBlockAndIndex(final int offset,
final HeaderBlock header, final List<BATBlock> sbats) {
POIFSBigBlockSize bigBlockSize = header.getBigBlockSize();
+ int entriesPerBlock = bigBlockSize.getBATEntriesPerBlock();
// SBATs are so much easier, as they're chained streams
- int whichSBAT = (int)Math.floor(offset / bigBlockSize.getBATEntriesPerBlock());
- int index = offset % bigBlockSize.getBATEntriesPerBlock();
+ int whichSBAT = offset / entriesPerBlock;
+ int index = offset % entriesPerBlock;
return new BATBlockAndIndex( index, sbats.get(whichSBAT) );
}
double n = (N - 1) * dn + 1;
if (n == 1d) {
result = StatsLib.kthSmallest(ds, 1);
- } else if (n == N) {
+ } else if (Double.compare(n, N) == 0) {
result = StatsLib.kthLargest(ds, 1);
} else {
int k = (int) n;
double d1 = NumericFunction.singleOperandEvaluate(arg1, srcRowIndex, srcColumnIndex);
double logE = Math.log(d0);
double base = d1;
- if (base == Math.E) {
+ if (Double.compare(base, Math.E) == 0) {
result = logE;
} else {
result = logE / Math.log(base);
\r
import org.apache.poi.ss.format.SimpleFraction;\r
import org.apache.poi.ss.formula.eval.NotImplementedException;\r
+import org.apache.poi.util.POILogFactory;\r
+import org.apache.poi.util.POILogger;\r
\r
/**\r
* <p>Format class that handles Excel style fractions, such as "# #/#" and "#/###"</p>\r
\r
@SuppressWarnings("serial")\r
public class FractionFormat extends Format {\r
- private final static Pattern DENOM_FORMAT_PATTERN = Pattern.compile("(?:(#+)|(\\d+))");\r
+ private static final POILogger LOGGER = POILogFactory.getLogger(FractionFormat.class); \r
+ private static final Pattern DENOM_FORMAT_PATTERN = Pattern.compile("(?:(#+)|(\\d+))");\r
\r
//this was chosen to match the earlier limitation of max denom power\r
//it can be expanded to get closer to Excel's calculations\r
//but as of this writing, the numerators and denominators\r
//with formats of that nature on very small values were quite\r
//far from Excel's calculations\r
- private final static int MAX_DENOM_POW = 4;\r
+ private static final int MAX_DENOM_POW = 4;\r
\r
//there are two options:\r
//a) an exact denominator is specified in the formatString\r
fract = SimpleFraction.buildFractionMaxDenominator(decPart, maxDenom);\r
}\r
} catch (RuntimeException e){\r
- e.printStackTrace();\r
+ LOGGER.log(POILogger.WARN, "Can't format fraction", e);\r
return Double.toString(doubleValue);\r
}\r
\r
if (isHSSF) {\r
w *= 1 - anchor.getDx1()/1024d;\r
} else {\r
- w -= anchor.getDx1()/EMU_PER_PIXEL;\r
+ w -= anchor.getDx1()/(double)EMU_PER_PIXEL;\r
}\r
\r
while(col2 < anchor.getCol2()){\r
if (isHSSF) {\r
w += sheet.getColumnWidthInPixels(col2) * anchor.getDx2()/1024d;\r
} else {\r
- w += anchor.getDx2()/EMU_PER_PIXEL;\r
+ w += anchor.getDx2()/(double)EMU_PER_PIXEL;\r
}\r
\r
double h = 0;\r
if (isHSSF) {\r
h *= 1 - anchor.getDy1()/256d;\r
} else {\r
- h -= anchor.getDy1()/EMU_PER_PIXEL;\r
+ h -= anchor.getDy1()/(double)EMU_PER_PIXEL;\r
}\r
\r
while(row2 < anchor.getRow2()){\r
if (isHSSF) {\r
h += getRowHeightInPixels(sheet,row2) * anchor.getDy2()/256;\r
} else {\r
- h += anchor.getDy2()/EMU_PER_PIXEL;\r
+ h += anchor.getDy2()/(double)EMU_PER_PIXEL;\r
}\r
\r
- return new Dimension((int)w*EMU_PER_PIXEL, (int)h*EMU_PER_PIXEL);\r
+ w *= EMU_PER_PIXEL;\r
+ h *= EMU_PER_PIXEL;\r
+ \r
+ return new Dimension((int)Math.rint(w), (int)Math.rint(h));\r
}\r
\r
\r
* @return string of 8 (zero padded) uppercase hex chars and prefixed with '0x'
*/
public static String intToHex(int value) {
- return xpad(value & 0xFFFFFFFF, 8, "0x");
+ return xpad(value & 0xFFFFFFFFL, 8, "0x");
}
/**
* @return string of 4 (zero padded) uppercase hex chars and prefixed with '0x'
*/
public static String shortToHex(int value) {
- return xpad(value & 0xFFFF, 4, "0x");
+ return xpad(value & 0xFFFFL, 4, "0x");
}
/**
* @return string of 2 (zero padded) uppercase hex chars and prefixed with '0x'
*/
public static String byteToHex(int value) {
- return xpad(value & 0xFF, 2, "0x");
+ return xpad(value & 0xFFL, 2, "0x");
}
private static String xpad(long value, int pad, String prefix) {
* @throws InvalidFormatException
* Throws if the date format isnot valid.
*/
- private Nullable<Date> setDateValue(String s) throws InvalidFormatException {
- if (s == null || s.equals("")) {
+ private Nullable<Date> setDateValue(String dateStr) throws InvalidFormatException {
+ if (dateStr == null || dateStr.equals("")) {
return new Nullable<Date>();
}
- if (!s.endsWith("Z")) {
- s += "Z";
- }
+ String dateTzStr = dateStr.endsWith("Z") ? dateStr : (dateStr + "Z");
SimpleDateFormat df = new SimpleDateFormat(DEFAULT_DATEFORMAT, Locale.ROOT);
df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
- Date d = df.parse(s, new ParsePosition(0));
+ Date d = df.parse(dateTzStr, new ParsePosition(0));
if (d == null) {
df = new SimpleDateFormat(ALTERNATIVE_DATEFORMAT, Locale.ROOT);
df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
- d = df.parse(s, new ParsePosition(0));
+ d = df.parse(dateTzStr, new ParsePosition(0));
}
if (d == null) {
throw new InvalidFormatException("Date not well formated");
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
/**
* Experimental class to do low level processing of pptx files.
- *
+ *
* Most users should use the higher level {@link XMLSlideShow} instead.
- *
+ *
* If you are using these low level classes, then you
* will almost certainly need to refer to the OOXML
* specifications from
* http://www.ecma-international.org/publications/standards/Ecma-376.htm
- *
+ *
* WARNING - APIs expected to change rapidly
*/
public class XSLFSlideShow extends POIXMLDocument {
private PresentationDocument presentationDoc;
- /**
- * The embedded OLE2 files in the OPC package
- */
- private List<PackagePart> embedds;
+ /**
+ * The embedded OLE2 files in the OPC package
+ */
+ private List<PackagePart> embedds;
- @SuppressWarnings("deprecation")
+ @SuppressWarnings("deprecation")
public XSLFSlideShow(OPCPackage container) throws OpenXML4JException, IOException, XmlException {
super(container);
-
+
if(getCorePart().getContentType().equals(XSLFRelation.THEME_MANAGER.getContentType())) {
- rebase(getPackage());
+ rebase(getPackage());
}
-
+
presentationDoc =
PresentationDocument.Factory.parse(getCorePart().getInputStream());
-
- embedds = new LinkedList<PackagePart>();
- for (CTSlideIdListEntry ctSlide : getSlideReferences().getSldIdArray()) {
- PackagePart corePart = getCorePart();
- PackagePart slidePart = corePart.getRelatedPart(
- corePart.getRelationship(ctSlide.getId2()));
- for(PackageRelationship rel : slidePart.getRelationshipsByType(OLE_OBJECT_REL_TYPE))
- embedds.add(slidePart.getRelatedPart(rel)); // TODO: Add this reference to each slide as well
+ embedds = new LinkedList<PackagePart>();
+ for (CTSlideIdListEntry ctSlide : getSlideReferences().getSldIdArray()) {
+ PackagePart corePart = getCorePart();
+ PackagePart slidePart = corePart.getRelatedPart(corePart.getRelationship(ctSlide.getId2()));
+
+ for(PackageRelationship rel : slidePart.getRelationshipsByType(OLE_OBJECT_REL_TYPE)) {
+ // TODO: Add this reference to each slide as well
+ embedds.add(slidePart.getRelatedPart(rel));
+ }
- for(PackageRelationship rel : slidePart.getRelationshipsByType(PACK_OBJECT_REL_TYPE))
- embedds.add(slidePart.getRelatedPart(rel));
+ for (PackageRelationship rel : slidePart.getRelationshipsByType(PACK_OBJECT_REL_TYPE)) {
+ embedds.add(slidePart.getRelatedPart(rel));
+ }
}
}
public XSLFSlideShow(String file) throws OpenXML4JException, IOException, XmlException {
this(openPackage(file));
}
-
+
/**
* Returns the low level presentation base object
*/
- @Internal
+ @Internal
public CTPresentation getPresentation() {
return presentationDoc.getPresentation();
}
-
+
/**
* Returns the references from the presentation to its
* slides.
* You'll need these to figure out the slide ordering,
* and to get at the actual slides themselves
*/
- @Internal
+ @Internal
public CTSlideIdList getSlideReferences() {
- if(! getPresentation().isSetSldIdLst()) {
- getPresentation().setSldIdLst(
- CTSlideIdList.Factory.newInstance()
- );
- }
- return getPresentation().getSldIdLst();
+ if(! getPresentation().isSetSldIdLst()) {
+ getPresentation().setSldIdLst(CTSlideIdList.Factory.newInstance());
+ }
+ return getPresentation().getSldIdLst();
}
-
+
/**
* Returns the references from the presentation to its
* slide masters.
- * You'll need these to get at the actual slide
+ * You'll need these to get at the actual slide
* masters themselves
*/
- @Internal
+ @Internal
public CTSlideMasterIdList getSlideMasterReferences() {
return getPresentation().getSldMasterIdLst();
}
-
+
public PackagePart getSlideMasterPart(CTSlideMasterIdListEntry master) throws IOException, XmlException {
try {
- PackagePart corePart = getCorePart();
+ PackagePart corePart = getCorePart();
return corePart.getRelatedPart(
corePart.getRelationship(master.getId2())
);
* Returns the low level slide master object from
* the supplied slide master reference
*/
- @Internal
+ @Internal
public CTSlideMaster getSlideMaster(CTSlideMasterIdListEntry master) throws IOException, XmlException {
PackagePart masterPart = getSlideMasterPart(master);
SldMasterDocument masterDoc =
public PackagePart getSlidePart(CTSlideIdListEntry slide) throws IOException, XmlException {
try {
- PackagePart corePart = getCorePart();
- return corePart.getRelatedPart(
- corePart.getRelationship(slide.getId2())
- );
+ PackagePart corePart = getCorePart();
+ return corePart.getRelatedPart(corePart.getRelationship(slide.getId2()));
} catch(InvalidFormatException e) {
throw new XmlException(e);
}
* Returns the low level slide object from
* the supplied slide reference
*/
- @Internal
+ @Internal
public CTSlide getSlide(CTSlideIdListEntry slide) throws IOException, XmlException {
PackagePart slidePart = getSlidePart(slide);
SldDocument slideDoc =
public PackagePart getNodesPart(CTSlideIdListEntry parentSlide) throws IOException, XmlException {
PackageRelationshipCollection notes;
PackagePart slidePart = getSlidePart(parentSlide);
-
+
try {
notes = slidePart.getRelationshipsByType(XSLFRelation.NOTES.getRelation());
} catch(InvalidFormatException e) {
throw new IllegalStateException(e);
}
-
+
if(notes.size() == 0) {
// No notes for this slide
return null;
if(notes.size() > 1) {
throw new IllegalStateException("Expecting 0 or 1 notes for a slide, but found " + notes.size());
}
-
+
try {
- return slidePart.getRelatedPart(notes.getRelationship(0));
+ return slidePart.getRelatedPart(notes.getRelationship(0));
} catch(InvalidFormatException e) {
throw new IllegalStateException(e);
}
* Returns the low level notes object for the given
* slide, as found from the supplied slide reference
*/
- @Internal
+ @Internal
public CTNotesSlide getNotes(CTSlideIdListEntry slide) throws IOException, XmlException {
PackagePart notesPart = getNodesPart(slide);
if(notesPart == null)
return null;
-
+
NotesDocument notesDoc =
NotesDocument.Factory.parse(notesPart.getInputStream());
-
+
return notesDoc.getNotes();
}
-
+
/**
* Returns all the comments for the given slide
*/
- @Internal
+ @Internal
public CTCommentList getSlideComments(CTSlideIdListEntry slide) throws IOException, XmlException {
PackageRelationshipCollection commentRels;
PackagePart slidePart = getSlidePart(slide);
-
+
try {
commentRels = slidePart.getRelationshipsByType(XSLFRelation.COMMENTS.getRelation());
} catch(InvalidFormatException e) {
throw new IllegalStateException(e);
}
-
+
if(commentRels.size() == 0) {
// No comments for this slide
return null;
if(commentRels.size() > 1) {
throw new IllegalStateException("Expecting 0 or 1 comments for a slide, but found " + commentRels.size());
}
-
+
try {
PackagePart cPart = slidePart.getRelatedPart(
commentRels.getRelationship(0)
);
- CmLstDocument commDoc =
+ CmLstDocument commDoc =
CmLstDocument.Factory.parse(cPart.getInputStream());
return commDoc.getCmLst();
} catch(InvalidFormatException e) {
}
}
- /**
- * Get the document's embedded files.
- */
- @Override
- public List<PackagePart> getAllEmbedds() throws OpenXML4JException {
- return embedds;
- }
+ /**
+ * Get the document's embedded files.
+ */
+ @Override
+ public List<PackagePart> getAllEmbedds() throws OpenXML4JException {
+ return embedds;
+ }
}
Element currentBlock, Range textRange, int currentTableLevel,
String hyperlink );
- protected void processImage( Element currentBlock, boolean inlined,
- Picture picture )
- {
+ protected void processImage( Element currentBlock, boolean inlined, Picture picture ) {
PicturesManager fileManager = getPicturesManager();
- if ( fileManager != null )
- {
- final int aspectRatioX = picture.getHorizontalScalingFactor();
- final int aspectRatioY = picture.getVerticalScalingFactor();
-
- final float imageWidth = aspectRatioX > 0 ? picture.getDxaGoal()
- * aspectRatioX / 1000 / AbstractWordUtils.TWIPS_PER_INCH
- : picture.getDxaGoal() / AbstractWordUtils.TWIPS_PER_INCH;
- final float imageHeight = aspectRatioY > 0 ? picture.getDyaGoal()
- * aspectRatioY / 1000 / AbstractWordUtils.TWIPS_PER_INCH
- : picture.getDyaGoal() / AbstractWordUtils.TWIPS_PER_INCH;
+ if ( fileManager != null ) {
+ final float aspectRatioX = picture.getHorizontalScalingFactor();
+ final float aspectRatioY = picture.getVerticalScalingFactor();
+
+ float imageWidth = picture.getDxaGoal();
+ if (aspectRatioX > 0) {
+ imageWidth *= aspectRatioX / 1000f;
+ }
+ imageWidth /= AbstractWordUtils.TWIPS_PER_INCH;
+
+ float imageHeight = picture.getDyaGoal();
+ if (aspectRatioY > 0) {
+ imageHeight *= aspectRatioY / 1000f;
+ }
+ imageHeight /= AbstractWordUtils.TWIPS_PER_INCH;
String url = fileManager.savePicture( picture.getContent(),
picture.suggestPictureType(),
//byte cInc = (byte)(((byte)(param & 0xfe00) >>> 4) >> 1);
byte cInc = (byte) ((operand & 0xff00) >>> 8);
- cInc = (byte) (cInc >>> 1);
+ cInc >>>= 1;
if (cInc != 0)
{
newCHP.setHps (Math.max (newCHP.getHps () + (cInc * 2), 2));