]> source.dussan.org Git - poi.git/commitdiff
#62393 - Inconsistent slide import behavior depending on Mac OS X Version
authorAndreas Beeker <kiwiwings@apache.org>
Mon, 21 May 2018 14:20:11 +0000 (14:20 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Mon, 21 May 2018 14:20:11 +0000 (14:20 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1831974 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java
src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFHyperlink.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java

index 3a19020a3aca83a594f054e59014a14185278e4c..bdf768d50db05fadf5f2a8eddc8e0e59b4bddc5b 100644 (file)
@@ -458,7 +458,7 @@ public abstract class PackagePart implements RelationshipSource, Comparable<Pack
         * @see org.apache.poi.openxml4j.opc.RelationshipSource#isRelationshipExists(org.apache.poi.openxml4j.opc.PackageRelationship)
         */
        public boolean isRelationshipExists(PackageRelationship rel) {
-               return _relationships.getRelationshipByID(rel.getId()) != null;
+               return rel != null && _relationships.getRelationshipByID(rel.getId()) != null;
        }
 
    /**
index 8e5cf9163e2abdb58de61951899b93dc5df33bc2..c4bf023c290dbe669baeac176445873210ff4ee9 100644 (file)
@@ -193,6 +193,9 @@ public final class PackageRelationshipCollection implements
      *            The relationship to add.
      */
     public void addRelationship(PackageRelationship relPart) {
+        if (relPart == null || relPart.getId() == null || relPart.getId().isEmpty()) {
+            throw new IllegalArgumentException("invalid relationship part/id");
+        }
         relationshipsByID.put(relPart.getId(), relPart);
         relationshipsByType.put(relPart.getRelationshipType(), relPart);
     }
@@ -227,8 +230,7 @@ public final class PackageRelationshipCollection implements
 
         PackageRelationship rel = new PackageRelationship(container,
                 sourcePart, targetUri, targetMode, relationshipType, id);
-        relationshipsByID.put(rel.getId(), rel);
-        relationshipsByType.put(rel.getRelationshipType(), rel);
+        addRelationship(rel);
         if (targetMode == TargetMode.INTERNAL){
             internalRelationshipsByTargetName.put(targetUri.toASCIIString(), rel);
         }
index e806861d29d7ae14b2f9d2e70b68bcce34952eaa..a5b80e8d6f803c67f508cd6846b7a0db3f3c2944 100644 (file)
@@ -50,14 +50,18 @@ public class XSLFHyperlink implements Hyperlink<XSLFShape,XSLFTextParagraph> {
 
     @Override
     public String getAddress() {
-        String id = _link.getId();
+        final String id = _link.getId();
         if (id == null || id.isEmpty()) {
             return _link.getAction();
         }
 
-        URI targetURI = _sheet.getPackagePart().getRelationship(id).getTargetURI();
-        
-        return targetURI.toASCIIString();
+        final PackageRelationship rel = _sheet.getPackagePart().getRelationship(id);
+        if (rel == null) {
+            return null;
+        }
+
+        final URI targetURI = rel.getTargetURI();
+        return (targetURI == null) ? null : targetURI.toASCIIString();
     }
 
     @Override
index 4c7486ddbcb7143a78e9e0c67c85554e952a86a0..52b49c475123b8379c24c49f7f2d9183ade6c752 100644 (file)
@@ -30,6 +30,8 @@ import org.apache.poi.openxml4j.opc.PackageRelationship;
 import org.apache.poi.sl.usermodel.PictureShape;
 import org.apache.poi.sl.usermodel.Placeholder;
 import org.apache.poi.util.Beta;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlObject;
@@ -52,6 +54,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTPictureNonVisual;
 @Beta
 public class XSLFPictureShape extends XSLFSimpleShape
     implements PictureShape<XSLFShape,XSLFTextParagraph> {
+    private static final POILogger LOG = POILogFactory.getLogger(XSLFPictureShape.class);
+
     private XSLFPictureData _data;
 
     /*package*/ XSLFPictureShape(CTPicture shape, XSLFSheet sheet) {
@@ -201,6 +205,11 @@ public class XSLFPictureShape extends XSLFSimpleShape
 
         XSLFPictureShape p = (XSLFPictureShape)sh;
         String blipId = p.getBlipId();
+        if (blipId == null) {
+            LOG.log(POILogger.WARN, "unable to copy invalid picture shape");
+            return;
+        }
+
         String relId = getSheet().importBlip(blipId, p.getSheet().getPackagePart());
 
         CTPicture ct = (CTPicture)getXmlObject();
index a6320d6c2e05e301aefd88a3537f47f4e90e8c94..dcd6be9d07545714a286675d6a8174ab386ee908 100644 (file)
@@ -658,7 +658,7 @@ implements XSLFShapeContainer, Sheet<XSLFShape,XSLFTextParagraph> {
         PackagePart blipPart;
         try {
             blipPart = packagePart.getRelatedPart(blipRel);
-        } catch (InvalidFormatException e){
+        } catch (Exception e){
             throw new POIXMLException(e);
         }
         XSLFPictureData data = new XSLFPictureData(blipPart);
index 2113c5397c80c7727d2d583a36f5ada3ac7b0cb4..5646fd40e21e564aafe7664c426cece47e61f0c3 100644 (file)
@@ -30,6 +30,8 @@ import org.apache.poi.sl.usermodel.PaintStyle;
 import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
 import org.apache.poi.sl.usermodel.TextRun;
 import org.apache.poi.util.Beta;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
 import org.apache.poi.xslf.model.CharacterPropertyFetcher;
 import org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties;
 import org.apache.xmlbeans.XmlObject;
@@ -40,6 +42,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBodyProperties;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTTextField;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTTextFont;
@@ -54,6 +57,8 @@ import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;
  */
 @Beta
 public class XSLFTextRun implements TextRun {
+    private static final POILogger LOG = POILogFactory.getLogger(XSLFTextRun.class);
+
     private final XmlObject _r;
     private final XSLFTextParagraph _p;
 
@@ -107,7 +112,8 @@ public class XSLFTextRun implements TextRun {
     @Override
     public void setFontColor(PaintStyle color) {
         if (!(color instanceof SolidPaint)) {
-            throw new IllegalArgumentException("Currently only SolidPaint is supported!");
+            LOG.log(POILogger.WARN, "Currently only SolidPaint is supported!");
+            return;
         }
         SolidPaint sp = (SolidPaint)color;
         Color c = DrawPaint.applyColorTransform(sp.getSolidColor());
@@ -173,12 +179,18 @@ public class XSLFTextRun implements TextRun {
     @Override
     public Double getFontSize(){
         double scale = 1;
-        CTTextNormalAutofit afit = getParentParagraph().getParentShape().getTextBodyPr().getNormAutofit();
-        if(afit != null) {
-            scale = (double)afit.getFontScale() / 100000;
+        final XSLFTextShape ps = getParentParagraph().getParentShape();
+        if (ps != null) {
+            final CTTextBodyProperties tbp = ps.getTextBodyPr();
+            if (tbp != null) {
+                CTTextNormalAutofit afit = tbp.getNormAutofit();
+                if (afit != null && afit.isSetFontScale()) {
+                    scale = afit.getFontScale() / 100000.;
+                }
+            }
         }
 
-        CharacterPropertyFetcher<Double> fetcher = new CharacterPropertyFetcher<Double>(_p.getIndentLevel()){
+        final CharacterPropertyFetcher<Double> fetcher = new CharacterPropertyFetcher<Double>(_p.getIndentLevel()){
             @Override
             public boolean fetch(CTTextCharacterProperties props){
                 if (props != null && props.isSetSz()) {