import java.util.Iterator;
import java.util.List;
-import org.apache.poi.openxml4j.opc.PackagePart;
-import org.apache.poi.openxml4j.opc.PackageRelationship;
-import org.apache.poi.openxml4j.opc.TargetMode;
+import org.apache.poi.ooxml.POIXMLDocumentPart.RelationPart;
import org.apache.poi.sl.draw.DrawPictureShape;
import org.apache.poi.sl.usermodel.GroupShape;
import org.apache.poi.sl.usermodel.PictureData;
return _grpSpPr;
}
- protected CTGroupTransform2D getSafeXfrm() {
+ private CTGroupTransform2D getSafeXfrm() {
CTGroupTransform2D xfrm = getXfrm();
return (xfrm == null ? getGrpSpPr().addNewXfrm() : xfrm);
}
if (!(pictureData instanceof XSLFPictureData)) {
throw new IllegalArgumentException("pictureData needs to be of type XSLFPictureData");
}
- XSLFPictureData xPictureData = (XSLFPictureData)pictureData;
- PackagePart pic = xPictureData.getPackagePart();
+ RelationPart rp = getSheet().addRelation(null, XSLFRelation.IMAGES, (XSLFPictureData)pictureData);
- PackageRelationship rel = getSheet().getPackagePart().addRelationship(
- pic.getPartName(), TargetMode.INTERNAL, XSLFRelation.IMAGES.getRelation());
-
- XSLFPictureShape sh = getDrawing().createPicture(rel.getId());
+ XSLFPictureShape sh = getDrawing().createPicture(rp.getRelationship().getId());
new DrawPictureShape(sh).resize();
_shapes.add(sh);
sh.setParent(this);
if (!(pictureData instanceof XSLFPictureData)) {
throw new IllegalArgumentException("pictureData needs to be of type XSLFPictureData");
}
- XSLFPictureData xPictureData = (XSLFPictureData)pictureData;
- PackagePart pic = xPictureData.getPackagePart();
- PackageRelationship rel = getSheet().getPackagePart().addRelationship(
- pic.getPartName(), TargetMode.INTERNAL, XSLFRelation.IMAGES.getRelation());
-
- XSLFObjectShape sh = getDrawing().createOleShape(rel.getId());
+ RelationPart rp = getSheet().addRelation(null, XSLFRelation.IMAGES, (XSLFPictureData)pictureData);
+
+ XSLFObjectShape sh = getDrawing().createOleShape(rp.getRelationship().getId());
CTOleObject oleObj = sh.getCTOleObject();
Dimension dim = pictureData.getImageDimension();
oleObj.setImgW(Units.toEMU(dim.getWidth()));
import java.net.URI;
import org.apache.poi.common.usermodel.HyperlinkType;
+import org.apache.poi.ooxml.POIXMLDocumentPart.RelationPart;
import org.apache.poi.openxml4j.opc.PackagePart;
-import org.apache.poi.openxml4j.opc.PackagePartName;
import org.apache.poi.openxml4j.opc.PackageRelationship;
-import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.sl.usermodel.Hyperlink;
import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.util.Internal;
import org.openxmlformats.schemas.drawingml.x2006.main.CTHyperlink;
public class XSLFHyperlink implements Hyperlink<XSLFShape,XSLFTextParagraph> {
- final XSLFSheet _sheet;
- final CTHyperlink _link;
+ private final XSLFSheet _sheet;
+ private final CTHyperlink _link;
XSLFHyperlink(CTHyperlink link, XSLFSheet sheet){
_sheet = sheet;
@Override
public void linkToSlide(Slide<XSLFShape,XSLFTextParagraph> slide) {
- PackagePart thisPP = _sheet.getPackagePart();
- PackagePartName otherPPN = ((XSLFSheet)slide).getPackagePart().getPartName();
if (_link.isSetId() && !_link.getId().isEmpty()) {
- thisPP.removeRelationship(_link.getId());
+ _sheet.getPackagePart().removeRelationship(_link.getId());
}
- PackageRelationship rel =
- thisPP.addRelationship(otherPPN, TargetMode.INTERNAL, XSLFRelation.SLIDE.getRelation());
- _link.setId(rel.getId());
+
+ RelationPart rp = _sheet.addRelation(null, XSLFRelation.SLIDE, (XSLFSheet) slide);
+ _link.setId(rp.getRelationship().getId());
_link.setAction("ppaction://hlinksldjump");
}
import javax.xml.namespace.QName;
-import org.apache.poi.ooxml.POIXMLException;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.sl.usermodel.PictureShape;
* (image lives outside)?
*/
public boolean isExternalLinkedPicture() {
- if (getBlipId() == null && getBlipLink() != null) {
- return true;
- }
- return false;
+ return getBlipId() == null && getBlipLink() != null;
}
/**
public XSLFPictureData getPictureData() {
if(_data == null){
String blipId = getBlipId();
- if (blipId == null) return null;
-
- PackagePart p = getSheet().getPackagePart();
- PackageRelationship rel = p.getRelationship(blipId);
- if (rel != null) {
- try {
- PackagePart imgPart = p.getRelatedPart(rel);
- _data = new XSLFPictureData(imgPart);
- }
- catch (Exception e) {
- throw new POIXMLException(e);
- }
+ if (blipId == null) {
+ return null;
}
+ _data = (XSLFPictureData)getSheet().getRelationById(blipId);
}
return _data;
}
return getBlipFill().getBlip();
}
+ @SuppressWarnings("WeakerAccess")
protected String getBlipLink(){
String link = getBlip().getLink();
if (link.isEmpty()) return null;
return link;
}
-
+
+ @SuppressWarnings("WeakerAccess")
protected String getBlipId(){
String id = getBlip().getEmbed();
if (id.isEmpty()) return null;
return;
}
- String relId = getSheet().importBlip(blipId, p.getSheet().getPackagePart());
+ String relId = getSheet().importBlip(blipId, p.getSheet());
CTPicture ct = (CTPicture)getXmlObject();
CTBlip blip = getBlipFill().getBlip();
if(blip.isSetExtLst()) {
CTOfficeArtExtensionList extLst = blip.getExtLst();
+ //noinspection deprecation
for(CTOfficeArtExtension ext : extLst.getExtArray()){
String xpath = "declare namespace a14='http://schemas.microsoft.com/office/drawing/2010/main' $this//a14:imgProps/a14:imgLayer";
XmlObject[] obj = ext.selectPath(xpath);
if(obj != null && obj.length == 1){
XmlCursor c = obj[0].newCursor();
String id = c.getAttributeText(new QName("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "embed"));//selectPath("declare namespace r='http://schemas.openxmlformats.org/officeDocument/2006/relationships' $this//[@embed]");
- String newId = getSheet().importBlip(id, p.getSheet().getPackagePart());
+ String newId = getSheet().importBlip(id, p.getSheet());
c.setAttributeText(new QName("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "embed"), newId);
c.dispose();
}
import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
-import javax.xml.namespace.QName;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.io.IOException;
import java.util.Map;
import java.util.Optional;
+import javax.xml.namespace.QName;
+
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.ooxml.POIXMLException;
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageNamespaces;
import org.apache.poi.openxml4j.opc.PackagePart;
private final BitSet shapeIds = new BitSet();
- public XSLFSheet() {
+ protected XSLFSheet() {
super();
}
/**
* @since POI 3.14-Beta1
*/
- public XSLFSheet(PackagePart part) {
+ protected XSLFSheet(PackagePart part) {
super(part);
}
throw new IllegalStateException("SlideShow was not found");
}
+ @SuppressWarnings("WeakerAccess")
protected int allocateShapeId() {
final int nextId = shapeIds.nextClearBit(1);
shapeIds.set(nextId);
return nextId;
}
+ @SuppressWarnings("WeakerAccess")
protected void registerShapeId(final int shapeId) {
if (shapeIds.get(shapeId)) {
LOG.log(POILogger.WARN, "shape id "+shapeId+" has been already used.");
shapeIds.set(shapeId);
}
+ @SuppressWarnings("WeakerAccess")
protected void deregisterShapeId(final int shapeId) {
if (!shapeIds.get(shapeId)) {
LOG.log(POILogger.WARN, "shape id "+shapeId+" hasn't been registered.");
shapeIds.clear(shapeId);
}
+ @SuppressWarnings("WeakerAccess")
protected static List<XSLFShape> buildShapes(CTGroupShape spTree, XSLFShapeContainer parent){
final XSLFSheet sheet = (parent instanceof XSLFSheet) ? (XSLFSheet)parent : ((XSLFShape)parent).getSheet();
if (!(pictureData instanceof XSLFPictureData)) {
throw new IllegalArgumentException("pictureData needs to be of type XSLFPictureData");
}
- XSLFPictureData xPictureData = (XSLFPictureData)pictureData;
- PackagePart pic = xPictureData.getPackagePart();
- RelationPart rp = addRelation(null, XSLFRelation.IMAGES, new XSLFPictureData(pic));
+ RelationPart rp = addRelation(null, XSLFRelation.IMAGES, (XSLFPictureData)pictureData);
XSLFPictureShape sh = getDrawing().createPicture(rp.getRelationship().getId());
new DrawPictureShape(sh).resize();
if (!(pictureData instanceof XSLFPictureData)) {
throw new IllegalArgumentException("pictureData needs to be of type XSLFPictureData");
}
- XSLFPictureData xPictureData = (XSLFPictureData)pictureData;
- PackagePart pic = xPictureData.getPackagePart();
-
- RelationPart rp = addRelation(null, XSLFRelation.IMAGES, new XSLFPictureData(pic));
+ RelationPart rp = addRelation(null, XSLFRelation.IMAGES, (XSLFPictureData)pictureData);
XSLFObjectShape sh = getDrawing().createOleShape(rp.getRelationship().getId());
CTOleObject oleObj = sh.getCTOleObject();
protected abstract String getRootElementName();
+ @SuppressWarnings("WeakerAccess")
protected CTGroupShape getSpTree(){
if(_spTree == null) {
XmlObject root = getXmlObject();
* @param src the source sheet
* @return modified <code>this</code>.
*/
+ @SuppressWarnings("unused")
public XSLFSheet appendContent(XSLFSheet src){
int numShapes = getShapes().size();
CTGroupShape spTree = getSpTree();
return null;
}
+ @SuppressWarnings("WeakerAccess")
protected XSLFTextShape getTextShapeByType(Placeholder type){
for(XSLFShape shape : this.getShapes()){
if(shape instanceof XSLFTextShape) {
return null;
}
+ @SuppressWarnings("WeakerAccess")
public XSLFSimpleShape getPlaceholder(Placeholder ph) {
return getPlaceholderByType(ph.ooxmlId);
}
*
* @return all placeholder shapes in this sheet
*/
+ @SuppressWarnings("WeakerAccess")
public XSLFTextShape[] getPlaceholders() {
initPlaceholders();
- return _placeholders.toArray(new XSLFTextShape[_placeholders.size()]);
- }
-
- /**
- * Checks if this <code>sheet</code> displays the specified shape.
- *
- * Subclasses can override it and skip certain shapes from drawings,
- * for instance, slide masters and layouts don't display placeholders
- */
- protected boolean canDraw(XSLFShape shape){
- return true;
+ return _placeholders.toArray(new XSLFTextShape[0]);
}
/**
* Import a picture data from another document.
*
* @param blipId ID of the package relationship to retrieve.
- * @param packagePart package part containing the data to import
+ * @param parent parent document containing the data to import
* @return ID of the created relationship
*/
- String importBlip(String blipId, PackagePart packagePart) {
- PackageRelationship blipRel = packagePart.getRelationship(blipId);
- PackagePart blipPart;
- try {
- blipPart = packagePart.getRelatedPart(blipRel);
- } catch (Exception e){
- throw new POIXMLException(e);
+ String importBlip(String blipId, POIXMLDocumentPart parent) {
+ final XSLFPictureData parData = parent.getRelationPartById(blipId).getDocumentPart();
+ final XSLFPictureData pictureData;
+ if (getPackagePart().getPackage() == parent.getPackagePart().getPackage()) {
+ // handle ref counter correct, if the parent document is the same as this
+ pictureData = parData;
+ } else {
+ XMLSlideShow ppt = getSlideShow();
+ pictureData = ppt.addPicture(parData.getData(), parData.getType());
}
- XSLFPictureData data = new XSLFPictureData(blipPart);
-
- XMLSlideShow ppt = getSlideShow();
- XSLFPictureData pictureData = ppt.addPicture(data.getData(), data.getType());
- PackagePart pic = pictureData.getPackagePart();
-
- RelationPart rp = addRelation(blipId, XSLFRelation.IMAGES, new XSLFPictureData(pic));
+ RelationPart rp = addRelation(blipId, XSLFRelation.IMAGES, pictureData);
return rp.getRelationship().getId();
}
/**
* Import a package part into this sheet.
*/
- PackagePart importPart(PackageRelationship srcRel, PackagePart srcPafrt) {
+ void importPart(PackageRelationship srcRel, PackagePart srcPafrt) {
PackagePart destPP = getPackagePart();
PackagePartName srcPPName = srcPafrt.getPartName();
OPCPackage pkg = destPP.getPackage();
if(pkg.containPart(srcPPName)){
// already exists
- return pkg.getPart(srcPPName);
+ return;
}
destPP.addRelationship(srcPPName, TargetMode.INTERNAL, srcRel.getRelationshipType());
} catch (IOException e){
throw new POIXMLException(e);
}
- return part;
}
/**
@Override
public boolean getFlipHorizontal() {
CTTransform2D xfrm = getXfrm(false);
- return (xfrm == null || !xfrm.isSetFlipH()) ? false : xfrm.getFlipH();
+ return (xfrm != null && xfrm.isSetFlipH()) && xfrm.getFlipH();
}
@Override
public boolean getFlipVertical() {
CTTransform2D xfrm = getXfrm(false);
- return (xfrm == null || !xfrm.isSetFlipV()) ? false : xfrm.getFlipV();
+ return (xfrm != null && xfrm.isSetFlipV()) && xfrm.getFlipV();
}
*
* @return line properties from the theme of null
*/
- CTLineProperties getDefaultLineProperties() {
+ private CTLineProperties getDefaultLineProperties() {
CTShapeStyle style = getSpStyle();
if (style == null) {
return null;
* @return the color of the shape outline or <code>null</code>
* if outline is turned off
*/
+ @SuppressWarnings("WeakerAccess")
public Color getLineColor() {
PaintStyle ps = getLinePaint();
if (ps instanceof SolidPaint) {
return null;
}
+ @SuppressWarnings("WeakerAccess")
protected PaintStyle getLinePaint() {
XSLFSheet sheet = getSheet();
final XSLFTheme theme = sheet.getTheme();
*
* @param width line width in points. <code>0</code> means no line
*/
+ @SuppressWarnings("WeakerAccess")
public void setLineWidth(double width) {
CTLineProperties lnPr = getLn(this, true);
if (lnPr == null) {
/**
* @return line width in points. <code>0</code> means no line.
*/
+ @SuppressWarnings("WeakerAccess")
public double getLineWidth() {
PropertyFetcher<Double> fetcher = new PropertyFetcher<Double>() {
@Override
/**
* @param compound set the line compound style
*/
+ @SuppressWarnings("WeakerAccess")
public void setLineCompound(LineCompound compound) {
CTLineProperties ln = getLn(this, true);
if (ln == null) {
/**
* @return the line compound
*/
+ @SuppressWarnings("WeakerAccess")
public LineCompound getLineCompound() {
PropertyFetcher<Integer> fetcher = new PropertyFetcher<Integer>() {
@Override
*
* @param dash a preset line dashing scheme to stroke thr shape outline
*/
+ @SuppressWarnings("WeakerAccess")
public void setLineDash(LineDash dash) {
CTLineProperties ln = getLn(this, true);
if (ln == null) {
/**
* @return a preset line dashing scheme to stroke the shape outline
*/
+ @SuppressWarnings("WeakerAccess")
public LineDash getLineDash() {
PropertyFetcher<LineDash> fetcher = new PropertyFetcher<LineDash>() {
*
* @param cap the line end cap style
*/
+ @SuppressWarnings("WeakerAccess")
public void setLineCap(LineCap cap) {
CTLineProperties ln = getLn(this, true);
if (ln == null) {
*
* @return the line end cap style
*/
+ @SuppressWarnings("WeakerAccess")
public LineCap getLineCap() {
PropertyFetcher<LineCap> fetcher = new PropertyFetcher<LineCap>() {
@Override
CTBlip blip = fp.getBlipFill().getBlip();
String blipId = blip.getEmbed();
- String relId = getSheet().importBlip(blipId, s.getSheet().getPackagePart());
+ String relId = getSheet().importBlip(blipId, s.getSheet());
blip.setEmbed(relId);
}
*
* @param style the line end docoration style
*/
+ @SuppressWarnings("WeakerAccess")
public void setLineHeadDecoration(DecorationShape style) {
CTLineProperties ln = getLn(this, true);
if (ln == null) {
/**
* @return the line end decoration shape
*/
+ @SuppressWarnings("WeakerAccess")
public DecorationShape getLineHeadDecoration() {
CTLineProperties ln = getLn(this, false);
DecorationShape ds = DecorationShape.NONE;
*
* @param style the decoration width
*/
+ @SuppressWarnings("WeakerAccess")
public void setLineHeadWidth(DecorationSize style) {
CTLineProperties ln = getLn(this, true);
if (ln == null) {
/**
* @return the line end decoration width
*/
+ @SuppressWarnings("WeakerAccess")
public DecorationSize getLineHeadWidth() {
CTLineProperties ln = getLn(this, false);
DecorationSize ds = DecorationSize.MEDIUM;
/**
* Specifies the line end width in relation to the line width.
*/
+ @SuppressWarnings("WeakerAccess")
public void setLineHeadLength(DecorationSize style) {
CTLineProperties ln = getLn(this, true);
if (ln == null) {
/**
* @return the line end decoration length
*/
+ @SuppressWarnings("WeakerAccess")
public DecorationSize getLineHeadLength() {
CTLineProperties ln = getLn(this, false);
/**
* Specifies the line end decoration, such as a triangle or arrowhead.
*/
+ @SuppressWarnings("WeakerAccess")
public void setLineTailDecoration(DecorationShape style) {
CTLineProperties ln = getLn(this, true);
if (ln == null) {
/**
* @return the line end decoration shape
*/
+ @SuppressWarnings("WeakerAccess")
public DecorationShape getLineTailDecoration() {
CTLineProperties ln = getLn(this, false);
/**
* specifies decorations which can be added to the tail of a line.
*/
+ @SuppressWarnings("WeakerAccess")
public void setLineTailWidth(DecorationSize style) {
CTLineProperties ln = getLn(this, true);
if (ln == null) {
/**
* @return the line end decoration width
*/
+ @SuppressWarnings("WeakerAccess")
public DecorationSize getLineTailWidth() {
CTLineProperties ln = getLn(this, false);
DecorationSize ds = DecorationSize.MEDIUM;
/**
* Specifies the line end width in relation to the line width.
*/
+ @SuppressWarnings("WeakerAccess")
public void setLineTailLength(DecorationSize style) {
CTLineProperties ln = getLn(this, true);
if (ln == null) {
/**
* @return the line end decoration length
*/
+ @SuppressWarnings("WeakerAccess")
public DecorationSize getLineTailLength() {
CTLineProperties ln = getLn(this, false);
XSLFGeometryProperties gp = XSLFPropertiesDelegate.getGeometryDelegate(getShapeProperties());
if (gp != null && gp.isSetPrstGeom() && gp.getPrstGeom().isSetAvLst()) {
+ //noinspection deprecation
for (CTGeomGuide g : gp.getPrstGeom().getAvLst().getGdArray()) {
if (g.getName().equals(name)) {
return new Guide(g.getName(), g.getFmla());
*/
@Override
public FillStyle getFillStyle() {
- return new FillStyle() {
- @Override
- public PaintStyle getPaint() {
- return XSLFSimpleShape.this.getFillPaint();
- }
- };
+ return XSLFSimpleShape.this::getFillPaint;
}
@Override
return "sld";
}
+ @SuppressWarnings({"WeakerAccess", "ProtectedMemberInFinalClass"})
protected void removeChartRelation(XSLFChart chart) {
removeRelation(chart);
}
+ @SuppressWarnings({"WeakerAccess", "ProtectedMemberInFinalClass"})
protected void removeLayoutRelation(XSLFSlideLayout layout) {
removeRelation(layout, false);
}
* @return the comments part or {@code null} if there weren't any comments
* @since POI 4.0.0
*/
+ @SuppressWarnings("WeakerAccess")
public XSLFComments getCommentsPart() {
if(_comments == null) {
for (POIXMLDocumentPart p : getRelations()) {
* @return the comment authors part or {@code null} if there weren't any comments
* @since POI 4.0.0
*/
+ @SuppressWarnings("WeakerAccess")
public XSLFCommentAuthors getCommentAuthorsPart() {
if(_commentAuthors == null) {
// first scan the slide relations
final XSLFComments xComments = getCommentsPart();
final XSLFCommentAuthors xAuthors = getCommentAuthorsPart();
if (xComments != null) {
+ //noinspection deprecation
for (final CTComment xc : xComments.getCTCommentsList().getCmArray()) {
comments.add(new XSLFComment(xc, xAuthors));
}
*
* @param value whether shapes on the master slide should be shown or not.
*/
+ @SuppressWarnings("WeakerAccess")
public void setFollowMasterGraphics(boolean value){
_slide.setShowMasterSp(value);
}
if(bgOther.isSetBgPr() && bgOther.getBgPr().isSetBlipFill()){
String idOther = bgOther.getBgPr().getBlipFill().getBlip().getEmbed();
- String idThis = importBlip(idOther, src.getPackagePart());
+ String idThis = importBlip(idOther, src);
bgThis.getBgPr().getBlipFill().getBlip().setEmbed(idThis);
}
/**
* Render this sheet into the supplied graphics object
*
- * @param graphics
+ * @param graphics the graphics context to draw to
*/
@Override
public void draw(Graphics2D graphics){
* @return slide master. Never null.
* @throws IllegalStateException if slide master was not found
*/
+ @SuppressWarnings("WeakerAccess")
public XSLFSlideMaster getSlideMaster() {
if (_master == null) {
for (POIXMLDocumentPart p : getRelations()) {
return _layout.getShowMasterSp();
}
- /**
- * Render this sheet into the supplied graphics object
- */
- @Override
- protected boolean canDraw(XSLFShape shape) {
- return !(shape instanceof XSLFSimpleShape) || !shape.isPlaceholder();
- }
-
-
@Override
public XSLFBackground getBackground() {
CTBackground bg = _layout.getCSld().getBg();
*
* @param slide destination slide
*/
+ @SuppressWarnings("WeakerAccess")
public void copyLayout(XSLFSlide slide) {
for (XSLFShape sh : getShapes()) {
if (sh instanceof XSLFTextShape) {
return props;
}
- /**
- * Render this sheet into the supplied graphics object
- *
- */
- @Override
- protected boolean canDraw(XSLFShape shape) {
- return !(shape instanceof XSLFSimpleShape) || !shape.isPlaceholder();
- }
-
@Override
public XSLFBackground getBackground() {
CTBackground bg = _slide.getCSld().getBg();
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.sl.usermodel.PaintStyle.TexturePaint;
import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.sl.usermodel.PictureData.PictureType;
+import org.apache.poi.sl.usermodel.PictureShape;
import org.apache.poi.sl.usermodel.Shape;
import org.apache.poi.sl.usermodel.ShapeType;
+import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.sl.usermodel.VerticalAlignment;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
public class TestXSLFBugs {
private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
+ @Test
+ public void bug62587() throws IOException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ try (XMLSlideShow ppt = new XMLSlideShow()) {
+ Slide slide = ppt.createSlide();
+ XSLFPictureData pd = ppt.addPicture(slTests.getFile("wrench.emf"), PictureType.EMF);
+ PictureShape ps = slide.createPicture(pd);
+ ps.setAnchor(new Rectangle2D.Double(100,100,100,100));
+ ppt.write(bos);
+ }
+
+ Object[][] pics = {
+ {"santa.wmf", PictureType.WMF, XSLFRelation.IMAGE_WMF},
+ {"tomcat.png",PictureType.PNG, XSLFRelation.IMAGE_PNG},
+ {"clock.jpg", PictureType.JPEG, XSLFRelation.IMAGE_JPEG}
+ };
+
+ try (XMLSlideShow ppt = new XMLSlideShow(new ByteArrayInputStream(bos.toByteArray()))) {
+ XSLFSlide s1 = ppt.getSlides().get(0);
+
+ for (Object[] p : pics) {
+ XSLFSlide s2 = ppt.createSlide();
+ s2.importContent(s1);
+
+ XSLFPictureData pd = ppt.addPicture(slTests.getFile((String)p[0]), (PictureType)p[1]);
+ XSLFPictureShape ps = (XSLFPictureShape) s2.getShapes().get(0);
+ Rectangle2D anchor = ps.getAnchor();
+ s2.removeShape(ps);
+ ps = s2.createPicture(pd);
+ ps.setAnchor(anchor);
+ }
+
+ bos.reset();
+ ppt.write(bos);
+ }
+
+ try (XMLSlideShow ppt = new XMLSlideShow(new ByteArrayInputStream(bos.toByteArray()))) {
+ for (XSLFSlide sl : ppt.getSlides()) {
+ List<RelationPart> rels = sl.getRelationParts();
+ assertEquals(2, rels.size());
+ RelationPart rel0 = rels.get(0);
+ assertEquals("rId1", rel0.getRelationship().getId());
+ assertEquals(XSLFRelation.SLIDE_LAYOUT.getRelation(), rel0.getRelationship().getRelationshipType());
+ RelationPart rel1 = rels.get(1);
+ assertEquals("rId2", rel1.getRelationship().getId());
+ assertEquals(XSLFRelation.IMAGES.getRelation(), rel1.getRelationship().getRelationshipType());
+ }
+ }
+ }
+
+
@Test
public void bug60499() throws IOException, InvalidFormatException {
InputStream is = slTests.openResourceAsStream("bug60499.pptx");
ss.close();
}
- protected String getSlideText(XMLSlideShow ppt, XSLFSlide slide) throws IOException {
- try (SlideShowExtractor extr = new SlideShowExtractor(ppt)) {
+ private String getSlideText(XMLSlideShow ppt, XSLFSlide slide) throws IOException {
+ try (SlideShowExtractor<XSLFShape,XSLFTextParagraph> extr = new SlideShowExtractor<>(ppt)) {
// do not auto-close the slideshow
extr.setFilesystem(null);
extr.setSlidesByDefault(true);
assertEquals(1, slide.getShapes().size());
assertEquals(1, slide.getRelations().size());
- assertRelationEquals(XSLFRelation.SLIDE_LAYOUT, slide.getRelations().get(0));
+
+ final XSLFRelation expected = XSLFRelation.SLIDE_LAYOUT;
+ final POIXMLDocumentPart relation = slide.getRelations().get(0);
+
+ assertEquals(expected.getContentType(), relation.getPackagePart().getContentType());
+ assertEquals(expected.getFileName(expected.getFileNameIndex(relation)), relation.getPackagePart().getPartName().getName());
// Some dummy pictures
byte[][] pics = new byte[15][3];
}
}
- private void assertRelationEquals(XSLFRelation expected, POIXMLDocumentPart relation) {
- assertEquals(expected.getContentType(), relation.getPackagePart().getContentType());
- assertEquals(expected.getFileName(expected.getFileNameIndex(relation)), relation.getPackagePart().getPartName().getName());
- }
-
@Test
public void bug58205() throws IOException {
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("themes.pptx");
@Test
public void testAptia() throws IOException {
- XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("aptia.pptx");
- try {
- XMLSlideShow saved = XSLFTestDataSamples.writeOutAndReadBack(ppt);
- } catch (IOException e) {
- fail("Could not read back saved presentation.");
+ try (XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("aptia.pptx");
+ XMLSlideShow saved = XSLFTestDataSamples.writeOutAndReadBack(ppt)) {
+ assertEquals(ppt.getSlides().size(), saved.getSlides().size());
}
- ppt.close();
}
@Ignore
@Test
public void testDivinoRevelado() throws IOException {
- XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("Divino_Revelado.pptx");
- try {
- XMLSlideShow saved = XSLFTestDataSamples.writeOutAndReadBack(ppt);
- } catch (IOException e) {
- fail("Could not read back saved presentation.");
+ try (XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("Divino_Revelado.pptx");
+ XMLSlideShow saved = XSLFTestDataSamples.writeOutAndReadBack(ppt)){
+ assertEquals(ppt.getSlides().size(), saved.getSlides().size());
}
- ppt.close();
}
@Test