Row row = sheet.getRow(i - sheet.getFirstRowNum());
if (row != null) {
short h = row.getHeight();
- int height = Math.round(Math.max(1, h / (res / 70 * 20) + 3));
+ int height = (int)Math.round(Math.max(1., ((double)h) / (((double)res) / 70. * 20.) + 3.));
System.out.printf("%d: %d (%d @ %d)%n", i, height, h, res);
setRowHeight(i, height);
}
import org.apache.poi.xssf.usermodel.XSSFWorkbook;\r
import org.apache.poi.openxml4j.opc.OPCPackage;\r
import org.apache.poi.openxml4j.opc.PackagePart;\r
+import org.apache.poi.xslf.usermodel.XSLFSlideShow;\r
import org.apache.poi.xwpf.usermodel.XWPFDocument;\r
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;\r
import org.apache.poi.hwpf.HWPFDocument;\r
-import org.apache.poi.xslf.XSLFSlideShow;\r
import org.apache.poi.hssf.usermodel.HSSFWorkbook;\r
\r
import java.io.InputStream;\r
import java.io.InputStream;
import org.apache.poi.extractor.ExtractorFactory;
-import org.apache.poi.xslf.XSLFSlideShow;
import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
+import org.apache.poi.xslf.usermodel.XSLFSlideShow;
import org.junit.Test;
public class XSLFFileHandler extends SlideShowHandler {
* Escher format. We don't attempt to understand the contents, since
* they will be in the parent's format, not Escher format.
*/
-public class EscherTextboxRecord extends EscherRecord implements Cloneable {
+public final class EscherTextboxRecord extends EscherRecord implements Cloneable {
public static final short RECORD_ID = (short)0xF00D;
public static final String RECORD_DESCRIPTION = "msofbtClientTextbox";
return 1;
}
+
+
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + id;
+ result = prime * result + length;
+ result = prime * result + offset;
+ return result;
+ }
+
+
+
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ PropertyListEntry other = (PropertyListEntry) obj;
+ if (id != other.id)
+ return false;
+ if (length != other.length)
+ return false;
+ if (offset != other.offset)
+ return false;
+ return true;
+ }
+
+
+
public String toString()
{
final StringBuffer b = new StringBuffer();
int dimsloc = -1;
if (rs.peekNextSid() != BOFRecord.sid) {
- throw new RuntimeException("BOF record expected");
+ throw new RecordFormatException("BOF record expected");
}
BOFRecord bof = (BOFRecord) rs.getNext();
if (RecordOrderer.isRowBlockRecord(recSid)) {
//only add the aggregate once
if (rra != null) {
- throw new RuntimeException("row/cell records found in the wrong place");
+ throw new RecordFormatException("row/cell records found in the wrong place");
}
RowBlocksReader rbr = new RowBlocksReader(rs);
_mergedCellsTable.addRecords(rbr.getLooseMergedCells());
records.add(rec);
}
if (windowTwo == null) {
- throw new RuntimeException("WINDOW2 was not found");
+ throw new RecordFormatException("WINDOW2 was not found");
}
if (_dimensions == null) {
// Excel seems to always write the DIMENSION record, but tolerates when it is not present
try {
_destList.add((Record)r.clone());
} catch (CloneNotSupportedException e) {
- throw new RuntimeException(e);
+ throw new RecordFormatException(e);
}
}
}
Record rec = (Record) ((Record) rb).clone();
clonedRecords.add(rec);
} catch (CloneNotSupportedException e) {
- throw new RuntimeException(e);
+ throw new RecordFormatException(e);
}
}
return createSheet(new RecordStream(clonedRecords, 0));
}
@Override
- public abstract CFHeaderBase clone();
+ public abstract CFHeaderBase clone(); // NOSONAR
}
void serialize(LittleEndianOutput out);
int getDataSize();
void appendToString(StringBuffer buffer);
- KeyData clone();
+ KeyData clone(); // NOSONAR
}
- public static class Rc4KeyData implements KeyData {
+ public static final class Rc4KeyData implements KeyData, Cloneable {
private static final int ENCRYPTION_OTHER_RC4 = 1;
private static final int ENCRYPTION_OTHER_CAPI_2 = 2;
private static final int ENCRYPTION_OTHER_CAPI_3 = 3;
}
}
- public static class XorKeyData implements KeyData {
+ public static final class XorKeyData implements KeyData, Cloneable {
/**
* key (2 bytes): An unsigned integer that specifies the obfuscation key.
* See [MS-OFFCRYPTO], 2.3.6.2 section, the first step of initializing XOR
* @author Andrew C. Oliver (acoliver at apache dot org)
* @author Jason Height (jheight at chariot dot net dot au)
*/
-public class IndexRecord extends StandardRecord implements Cloneable {
+public final class IndexRecord extends StandardRecord implements Cloneable {
public final static short sid = 0x020B;
private int field_2_first_row; // first row on the sheet
private int field_3_last_row_add1; // last row
import org.apache.poi.hssf.record.CFRuleBase;
import org.apache.poi.hssf.record.CFRuleRecord;
import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.RecordFormatException;
import org.apache.poi.ss.formula.FormulaShifter;
import org.apache.poi.ss.formula.ptg.AreaErrPtg;
import org.apache.poi.ss.formula.ptg.AreaPtg;
+ " this file will cause problems with old Excel versions");
}
if (pRules.length != pHeader.getNumberOfConditionalFormats()) {
- throw new RuntimeException("Mismatch number of rules");
+ throw new RecordFormatException("Mismatch number of rules");
}
header = pHeader;
rules = new ArrayList<CFRuleBase>(pRules.length);
public CFRecordsAggregate cloneCFAggregate() {
CFRuleBase[] newRecs = new CFRuleBase[rules.size()];
for (int i = 0; i < newRecs.length; i++) {
- newRecs[i] = (CFRuleRecord) getRule(i).clone();
+ newRecs[i] = getRule(i).clone();
}
- return new CFRecordsAggregate((CFHeaderBase)header.clone(), newRecs);
+ return new CFRecordsAggregate(header.clone(), newRecs);
}
/**
protected class ChainLoopDetector {
private boolean[] used_blocks;
protected ChainLoopDetector(long rawSize) {
- int numBlocks = (int)Math.ceil( rawSize / getBlockStoreBlockSize() );
+ int numBlocks = (int)Math.ceil( ((double)rawSize) / getBlockStoreBlockSize() );
used_blocks = new boolean[numBlocks];
}
protected void claim(int offset) {
public int countBlocks()
{
int size = _properties.size() * POIFSConstants.PROPERTY_SIZE;
- return (int)Math.ceil(size / _bigBigBlockSize.getBigBlockSize());
+ return (int)Math.ceil( ((double)size) / _bigBigBlockSize.getBigBlockSize());
}
/**
* This is a replacement for {@link java.awt.Insets} which works on doubles\r
* instead of ints\r
*/\r
-public class Insets2D implements Cloneable {\r
+public final class Insets2D implements Cloneable {\r
\r
/**\r
* The inset from the top.\r
import org.apache.poi.poifs.filesystem.OPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.xslf.XSLFSlideShow;
import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
import org.apache.poi.xslf.usermodel.XSLFRelation;
+import org.apache.poi.xslf.usermodel.XSLFSlideShow;
import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor;
import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
import org.apache.poi.xssf.usermodel.XSSFRelation;
public final static String NAMESPACE_DCTERMS_URI = "http://purl.org/dc/terms/";
+ private final static String DEFAULT_DATEFORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
+ private final static String ALTERNATIVE_DATEFORMAT = "yyyy-MM-dd'T'HH:mm:ss.SS'Z'";
+
+
/**
* Constructor.
*
try {
this.created = setDateValue(created);
} catch (InvalidFormatException e) {
- new IllegalArgumentException("created : "
- + e.getLocalizedMessage());
+ throw new IllegalArgumentException("created : "
+ + e.getLocalizedMessage(), e);
}
}
try {
this.lastPrinted = setDateValue(lastPrinted);
} catch (InvalidFormatException e) {
- new IllegalArgumentException("lastPrinted : "
- + e.getLocalizedMessage());
+ throw new IllegalArgumentException("lastPrinted : "
+ + e.getLocalizedMessage(), e);
}
}
try {
this.modified = setDateValue(modified);
} catch (InvalidFormatException e) {
- new IllegalArgumentException("modified : "
- + e.getLocalizedMessage());
+ throw new IllegalArgumentException("modified : "
+ + e.getLocalizedMessage(), e);
}
}
if (s == null || s.equals("")) {
return new Nullable<Date>();
}
- SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT);
+ if (!s.endsWith("Z")) {
+ s += "Z";
+ }
+ SimpleDateFormat df = new SimpleDateFormat(DEFAULT_DATEFORMAT, Locale.ROOT);
df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
Date d = df.parse(s, 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));
+ }
if (d == null) {
throw new InvalidFormatException("Date not well formated");
}
return "";
}
- SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT);
+ SimpleDateFormat df = new SimpleDateFormat(DEFAULT_DATEFORMAT, Locale.ROOT);
df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
return df.format(date);
}
\r
import java.io.ByteArrayInputStream;\r
import java.io.ByteArrayOutputStream;\r
+import java.io.IOException;\r
import java.math.BigInteger;\r
import java.security.cert.CRLException;\r
import java.security.cert.CertificateEncodingException;\r
}\r
\r
private BigInteger getCrlNumber(X509CRL crl) {\r
+ byte[] crlNumberExtensionValue = crl.getExtensionValue(Extension.cRLNumber.getId());\r
+ if (null == crlNumberExtensionValue) {\r
+ return null;\r
+ }\r
+\r
try {\r
- byte[] crlNumberExtensionValue = crl.getExtensionValue(Extension.cRLNumber.getId());\r
- if (null == crlNumberExtensionValue) {\r
- return null;\r
+ ASN1InputStream asn1IS1 = null, asn1IS2 = null;\r
+ try {\r
+ asn1IS1 = new ASN1InputStream(crlNumberExtensionValue);\r
+ ASN1OctetString octetString = (ASN1OctetString)asn1IS1.readObject();\r
+ byte[] octets = octetString.getOctets();\r
+ asn1IS2 = new ASN1InputStream(octets);\r
+ ASN1Integer integer = (ASN1Integer)asn1IS2.readObject();\r
+ return integer.getPositiveValue();\r
+ } finally {\r
+ asn1IS2.close();\r
+ asn1IS1.close();\r
}\r
-\r
- @SuppressWarnings("resource")\r
- ASN1InputStream asn1InputStream = new ASN1InputStream(crlNumberExtensionValue);\r
- ASN1OctetString octetString = (ASN1OctetString)asn1InputStream.readObject();\r
- byte[] octets = octetString.getOctets();\r
- asn1InputStream = new ASN1InputStream(octets);\r
- ASN1Integer integer = (ASN1Integer)asn1InputStream.readObject();\r
- BigInteger crlNumber = integer.getPositiveValue();\r
- return crlNumber;\r
- } catch (Exception e) {\r
+ } catch (IOException e) {\r
throw new RuntimeException("I/O error: " + e.getMessage(), e);\r
}\r
}\r
+++ /dev/null
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (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
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-package org.apache.poi.xslf;
-
-import java.io.IOException;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.apache.poi.POIXMLDocument;
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
-import org.apache.poi.openxml4j.opc.OPCPackage;
-import org.apache.poi.openxml4j.opc.PackagePart;
-import org.apache.poi.openxml4j.opc.PackageRelationship;
-import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
-import org.apache.poi.util.Internal;
-import org.apache.poi.xslf.usermodel.XMLSlideShow;
-import org.apache.poi.xslf.usermodel.XSLFRelation;
-import org.apache.xmlbeans.XmlException;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentList;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTSlide;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdList;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMaster;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdList;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
-import org.openxmlformats.schemas.presentationml.x2006.main.CmLstDocument;
-import org.openxmlformats.schemas.presentationml.x2006.main.NotesDocument;
-import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument;
-import org.openxmlformats.schemas.presentationml.x2006.main.SldDocument;
-import org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument;
-
-/**
- * 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;
-
- @SuppressWarnings("deprecation")
- public XSLFSlideShow(OPCPackage container) throws OpenXML4JException, IOException, XmlException {
- super(container);
-
- if(getCorePart().getContentType().equals(XSLFRelation.THEME_MANAGER.getContentType())) {
- 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
-
- 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
- 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
- public CTSlideIdList getSlideReferences() {
- 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
- * masters themselves
- */
- @Internal
- public CTSlideMasterIdList getSlideMasterReferences() {
- return getPresentation().getSldMasterIdLst();
- }
-
- public PackagePart getSlideMasterPart(CTSlideMasterIdListEntry master) throws IOException, XmlException {
- try {
- PackagePart corePart = getCorePart();
- return corePart.getRelatedPart(
- corePart.getRelationship(master.getId2())
- );
- } catch(InvalidFormatException e) {
- throw new XmlException(e);
- }
- }
- /**
- * Returns the low level slide master object from
- * the supplied slide master reference
- */
- @Internal
- public CTSlideMaster getSlideMaster(CTSlideMasterIdListEntry master) throws IOException, XmlException {
- PackagePart masterPart = getSlideMasterPart(master);
- SldMasterDocument masterDoc =
- SldMasterDocument.Factory.parse(masterPart.getInputStream());
- return masterDoc.getSldMaster();
- }
-
- public PackagePart getSlidePart(CTSlideIdListEntry slide) throws IOException, XmlException {
- try {
- 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
- public CTSlide getSlide(CTSlideIdListEntry slide) throws IOException, XmlException {
- PackagePart slidePart = getSlidePart(slide);
- SldDocument slideDoc =
- SldDocument.Factory.parse(slidePart.getInputStream());
- return slideDoc.getSld();
- }
-
- /**
- * Gets the PackagePart of the notes for the
- * given slide, or null if there isn't one.
- */
- 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));
- } 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
- 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
- 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.Factory.parse(cPart.getInputStream());
- return commDoc.getCmLst();
- } catch(InvalidFormatException e) {
- throw new IllegalStateException(e);
- }
- }
-
- /**
- * Get the document's embedded files.
- */
- @Override
- public List<PackagePart> getAllEmbedds() throws OpenXML4JException {
- return embedds;
- }
-
-}
import org.apache.poi.POIXMLTextExtractor;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
-import org.apache.poi.xslf.XSLFSlideShow;
import org.apache.poi.xslf.usermodel.DrawingParagraph;
import org.apache.poi.xslf.usermodel.DrawingTextBody;
import org.apache.poi.xslf.usermodel.DrawingTextPlaceholder;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import org.apache.poi.xslf.usermodel.XSLFSlideLayout;
import org.apache.poi.xslf.usermodel.XSLFSlideMaster;
+import org.apache.poi.xslf.usermodel.XSLFSlideShow;
import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.presentationml.x2006.main.CTComment;
import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentAuthor;
import org.apache.poi.util.POILogger;
import org.apache.poi.util.PackageHelper;
import org.apache.poi.util.Units;
-import org.apache.poi.xslf.XSLFSlideShow;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
}
}
- // TODO get rid of this method
- @Deprecated
- public XSLFSlideShow _getXSLFSlideShow() throws OpenXML4JException, IOException, XmlException{
- return new XSLFSlideShow(getPackage());
- }
-
@Override
protected void onDocumentRead() throws IOException {
try {
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (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
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.xslf.usermodel;
+
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.poi.POIXMLDocument;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
+import org.apache.poi.util.Internal;
+import org.apache.xmlbeans.XmlException;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentList;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTSlide;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdList;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMaster;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdList;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
+import org.openxmlformats.schemas.presentationml.x2006.main.CmLstDocument;
+import org.openxmlformats.schemas.presentationml.x2006.main.NotesDocument;
+import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument;
+import org.openxmlformats.schemas.presentationml.x2006.main.SldDocument;
+import org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument;
+
+/**
+ * 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;
+
+ @SuppressWarnings("deprecation")
+ public XSLFSlideShow(OPCPackage container) throws OpenXML4JException, IOException, XmlException {
+ super(container);
+
+ if(getCorePart().getContentType().equals(XSLFRelation.THEME_MANAGER.getContentType())) {
+ 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
+
+ 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
+ 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
+ public CTSlideIdList getSlideReferences() {
+ 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
+ * masters themselves
+ */
+ @Internal
+ public CTSlideMasterIdList getSlideMasterReferences() {
+ return getPresentation().getSldMasterIdLst();
+ }
+
+ public PackagePart getSlideMasterPart(CTSlideMasterIdListEntry master) throws IOException, XmlException {
+ try {
+ PackagePart corePart = getCorePart();
+ return corePart.getRelatedPart(
+ corePart.getRelationship(master.getId2())
+ );
+ } catch(InvalidFormatException e) {
+ throw new XmlException(e);
+ }
+ }
+ /**
+ * Returns the low level slide master object from
+ * the supplied slide master reference
+ */
+ @Internal
+ public CTSlideMaster getSlideMaster(CTSlideMasterIdListEntry master) throws IOException, XmlException {
+ PackagePart masterPart = getSlideMasterPart(master);
+ SldMasterDocument masterDoc =
+ SldMasterDocument.Factory.parse(masterPart.getInputStream());
+ return masterDoc.getSldMaster();
+ }
+
+ public PackagePart getSlidePart(CTSlideIdListEntry slide) throws IOException, XmlException {
+ try {
+ 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
+ public CTSlide getSlide(CTSlideIdListEntry slide) throws IOException, XmlException {
+ PackagePart slidePart = getSlidePart(slide);
+ SldDocument slideDoc =
+ SldDocument.Factory.parse(slidePart.getInputStream());
+ return slideDoc.getSld();
+ }
+
+ /**
+ * Gets the PackagePart of the notes for the
+ * given slide, or null if there isn't one.
+ */
+ 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));
+ } 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
+ 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
+ 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.Factory.parse(cPart.getInputStream());
+ return commDoc.getCmLst();
+ } catch(InvalidFormatException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Get the document's embedded files.
+ */
+ @Override
+ public List<PackagePart> getAllEmbedds() throws OpenXML4JException {
+ return embedds;
+ }
+
+}
package org.apache.poi;
import org.apache.poi.util.IOUtils;
-import org.apache.poi.xslf.XSLFSlideShow;
+import org.apache.poi.xslf.usermodel.XSLFSlideShow;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.util.PackageHelper;
-import org.apache.poi.xslf.XSLFSlideShow;
+import org.apache.poi.xslf.usermodel.XSLFSlideShow;
import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
==================================================================== */
package org.apache.poi.extractor;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
-import junit.framework.TestCase;
-
import org.apache.poi.POIDataSamples;
import org.apache.poi.POIOLE2TextExtractor;
import org.apache.poi.POITextExtractor;
import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor;
import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
+import org.junit.BeforeClass;
+import org.junit.Test;
/**
* Test that the extractor factory plays nicely
*/
-public class TestExtractorFactory extends TestCase {
- private File txt;
+public class TestExtractorFactory {
+ private static File txt;
- private File xls;
- private File xlsx;
- private File xlsxStrict;
- private File xltx;
- private File xlsEmb;
+ private static File xls;
+ private static File xlsx;
+ private static File xlsxStrict;
+ private static File xltx;
+ private static File xlsEmb;
- private File doc;
- private File doc6;
- private File doc95;
- private File docx;
- private File dotx;
- private File docEmb;
- private File docEmbOOXML;
+ private static File doc;
+ private static File doc6;
+ private static File doc95;
+ private static File docx;
+ private static File dotx;
+ private static File docEmb;
+ private static File docEmbOOXML;
- private File ppt;
- private File pptx;
+ private static File ppt;
+ private static File pptx;
- private File msg;
- private File msgEmb;
- private File msgEmbMsg;
+ private static File msg;
+ private static File msgEmb;
+ private static File msgEmbMsg;
- private File vsd;
- private File vsdx;
+ private static File vsd;
+ private static File vsdx;
- private File pub;
+ private static File pub;
- private File getFileAndCheck(POIDataSamples samples, String name) {
+ private static File getFileAndCheck(POIDataSamples samples, String name) {
File file = samples.getFile(name);
assertNotNull("Did not get a file for " + name, file);
return file;
}
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+
+ @BeforeClass
+ public static void setUp() throws Exception {
POIDataSamples ssTests = POIDataSamples.getSpreadSheetInstance();
xls = getFileAndCheck(ssTests, "SampleSS.xls");
msgEmbMsg = getFileAndCheck(olTests, "attachment_msg_pdf.msg");
}
+ @Test
public void testFile() throws Exception {
// Excel
POITextExtractor xlsExtractor = ExtractorFactory.createExtractor(xls);
}
}
+ @Test
public void testInputStream() throws Exception {
// Excel
assertTrue(
}
}
+ @Test
public void testPOIFS() throws Exception {
// Excel
assertTrue(
}
}
+ @Test
public void testPackage() throws Exception {
// Excel
POIXMLTextExtractor extractor = ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString(), PackageAccess.READ));
}
}
+ @Test
public void testPreferEventBased() throws Exception {
assertFalse(ExtractorFactory.getPreferEventExtractor());
assertFalse(ExtractorFactory.getThreadPrefersEventExtractors());
* does poifs embeded, but will do ooxml ones
* at some point.
*/
+ @Test
public void testEmbeded() throws Exception {
POIOLE2TextExtractor ext;
POITextExtractor[] embeds;
import javax.imageio.ImageIO;
import org.apache.poi.POIXMLDocumentPart;
-import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.sl.usermodel.PictureData.PictureType;
import org.apache.poi.xslf.usermodel.DrawingParagraph;
import org.apache.poi.xslf.usermodel.DrawingTextBody;
public class TestXSLFBugs {
@Test
- @SuppressWarnings("deprecation")
public void bug51187() throws Exception {
XMLSlideShow ss1 = XSLFTestDataSamples.openSampleDocument("51187.pptx");
// Check the relations on it
// Note - rId3 is a self reference
- PackagePart slidePart = ss1._getXSLFSlideShow().getSlidePart(
- ss1._getXSLFSlideShow().getSlideReferences().getSldIdArray(0)
- );
- assertEquals("/ppt/slides/slide1.xml", slidePart.getPartName().toString());
- assertEquals("/ppt/slideLayouts/slideLayout12.xml", slidePart.getRelationship("rId1").getTargetURI().toString());
- assertEquals("/ppt/notesSlides/notesSlide1.xml", slidePart.getRelationship("rId2").getTargetURI().toString());
- assertEquals("/ppt/slides/slide1.xml", slidePart.getRelationship("rId3").getTargetURI().toString());
- assertEquals("/ppt/media/image1.png", slidePart.getRelationship("rId4").getTargetURI().toString());
+ XSLFSlide slide0 = ss1.getSlides().get(0);
+
+ assertEquals("/ppt/slides/slide1.xml", slide0.getPackagePart().getPartName().toString());
+ assertEquals("/ppt/slideLayouts/slideLayout12.xml", slide0.getRelationById("rId1").getPackageRelationship().getTargetURI().toString());
+ assertEquals("/ppt/notesSlides/notesSlide1.xml", slide0.getRelationById("rId2").getPackageRelationship().getTargetURI().toString());
+ assertEquals("/ppt/slides/slide1.xml", slide0.getRelationById("rId3").getPackageRelationship().getTargetURI().toString());
+ assertEquals("/ppt/media/image1.png", slide0.getRelationById("rId4").getPackageRelationship().getTargetURI().toString());
// Save and re-load
XMLSlideShow ss2 = XSLFTestDataSamples.writeOutAndReadBack(ss1);
ss1.close();
assertEquals(1, ss2.getSlides().size());
- slidePart = ss2._getXSLFSlideShow().getSlidePart(
- ss2._getXSLFSlideShow().getSlideReferences().getSldIdArray(0)
- );
- assertEquals("/ppt/slides/slide1.xml", slidePart.getPartName().toString());
- assertEquals("/ppt/slideLayouts/slideLayout12.xml", slidePart.getRelationship("rId1").getTargetURI().toString());
- assertEquals("/ppt/notesSlides/notesSlide1.xml", slidePart.getRelationship("rId2").getTargetURI().toString());
+ slide0 = ss2.getSlides().get(0);
+ assertEquals("/ppt/slides/slide1.xml", slide0.getPackagePart().getPartName().toString());
+ assertEquals("/ppt/slideLayouts/slideLayout12.xml", slide0.getRelationById("rId1").getPackageRelationship().getTargetURI().toString());
+ assertEquals("/ppt/notesSlides/notesSlide1.xml", slide0.getRelationById("rId2").getPackageRelationship().getTargetURI().toString());
// TODO Fix this
- assertEquals("/ppt/slides/slide1.xml", slidePart.getRelationship("rId3").getTargetURI().toString());
- assertEquals("/ppt/media/image1.png", slidePart.getRelationship("rId4").getTargetURI().toString());
+ assertEquals("/ppt/slides/slide1.xml", slide0.getRelationById("rId3").getPackageRelationship().getTargetURI().toString());
+ assertEquals("/ppt/media/image1.png", slide0.getRelationById("rId4").getPackageRelationship().getTargetURI().toString());
ss2.close();
}
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.xslf.usermodel.XSLFRelation;
+import org.apache.poi.xslf.usermodel.XSLFSlideShow;
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
import org.apache.poi.POITextExtractor;
import org.apache.poi.extractor.ExtractorFactory;
import org.apache.poi.openxml4j.opc.OPCPackage;
-import org.apache.poi.xslf.XSLFSlideShow;
+import org.apache.poi.xslf.usermodel.XSLFSlideShow;
import junit.framework.TestCase;
boolean isMV = false;
boolean isVL = false;
int typeId = typeAndMV;
- if( (typeAndMV & Types.MULTIVALUED_FLAG) > 0 ) {
+ if( (typeAndMV & Types.MULTIVALUED_FLAG) != 0 ) {
isMV = true;
typeId -= Types.MULTIVALUED_FLAG;
}
package org.apache.poi.hslf.model.textproperties;
-import org.apache.poi.hslf.record.Record;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;