poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1829453 [3/3] - in /poi: site/src/documentation/content/xdocs/ trunk/src/java/org/apache/poi/sl/draw/ trunk/src/java/org/apache/poi/sl/extractor/ trunk/src/java/org/apache/poi/sl/usermodel/ trunk/src/ooxml/java/org/apache/poi/xslf/extracto...
Date Wed, 18 Apr 2018 15:02:03 GMT
Added: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapePlaceholderDetails.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapePlaceholderDetails.java?rev=1829453&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapePlaceholderDetails.java
(added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapePlaceholderDetails.java
Wed Apr 18 15:02:02 2018
@@ -0,0 +1,240 @@
+/* ====================================================================
+   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.hslf.usermodel;
+
+import org.apache.poi.ddf.EscherProperties;
+import org.apache.poi.ddf.EscherSpRecord;
+import org.apache.poi.hslf.exceptions.HSLFException;
+import org.apache.poi.hslf.record.HSLFEscherClientDataRecord;
+import org.apache.poi.hslf.record.OEPlaceholderAtom;
+import org.apache.poi.hslf.record.Record;
+import org.apache.poi.hslf.record.RoundTripHFPlaceholder12;
+import org.apache.poi.sl.usermodel.MasterSheet;
+import org.apache.poi.sl.usermodel.Placeholder;
+
+/**
+ * Extended placeholder details for HSLF shapes
+ *
+ * @since POI 4.0.0
+ */
+public class HSLFShapePlaceholderDetails extends HSLFPlaceholderDetails {
+    private enum PlaceholderContainer {
+        slide, master, notes, notesMaster
+    }
+
+    private final PlaceholderContainer source;
+    final HSLFSimpleShape shape;
+    private OEPlaceholderAtom oePlaceholderAtom;
+    private RoundTripHFPlaceholder12 roundTripHFPlaceholder12;
+
+
+    HSLFShapePlaceholderDetails(final HSLFSimpleShape shape) {
+        super(shape.getSheet(), null);
+
+        this.shape = shape;
+
+        final HSLFSheet sheet = shape.getSheet();
+        if (sheet instanceof HSLFSlideMaster) {
+            source = PlaceholderContainer.master;
+        } else if (sheet instanceof HSLFNotes) {
+            source = PlaceholderContainer.notes;
+        } else if (sheet instanceof MasterSheet) {
+            // notes master aren't yet supported ...
+            source = PlaceholderContainer.notesMaster;
+        } else {
+            source = PlaceholderContainer.slide;
+        }
+    }
+
+    public Placeholder getPlaceholder() {
+        updatePlaceholderAtom(false);
+        final int phId;
+        if (oePlaceholderAtom != null) {
+            phId = oePlaceholderAtom.getPlaceholderId();
+        } else if (roundTripHFPlaceholder12 != null) {
+            phId = roundTripHFPlaceholder12.getPlaceholderId();
+        } else {
+            return null;
+        }
+
+        switch (source) {
+        case slide:
+            return Placeholder.lookupNativeSlide(phId);
+        default:
+        case master:
+            return Placeholder.lookupNativeSlideMaster(phId);
+        case notes:
+            return Placeholder.lookupNativeNotes(phId);
+        case notesMaster:
+            return Placeholder.lookupNativeNotesMaster(phId);
+        }
+    }
+
+    public void setPlaceholder(final Placeholder placeholder) {
+        final EscherSpRecord spRecord = shape.getEscherChild(EscherSpRecord.RECORD_ID);
+        int flags = spRecord.getFlags();
+        if (placeholder == null) {
+            flags ^= EscherSpRecord.FLAG_HAVEMASTER;
+        } else {
+            flags |= EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HAVEMASTER;
+        }
+        spRecord.setFlags(flags);
+
+        // Placeholders can't be grouped
+        shape.setEscherProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, (placeholder
== null ? -1 : 262144));
+
+        if (placeholder == null) {
+            removePlaceholder();
+            return;
+        }
+
+        // init client data
+        updatePlaceholderAtom(true);
+
+        final byte phId = getPlaceholderId(placeholder);
+        oePlaceholderAtom.setPlaceholderId(phId);
+        roundTripHFPlaceholder12.setPlaceholderId(phId);
+    }
+
+    public PlaceholderSize getSize() {
+        final Placeholder ph = getPlaceholder();
+        if (ph == null) {
+            return null;
+        }
+
+        final int size = (oePlaceholderAtom != null) 
+            ? oePlaceholderAtom.getPlaceholderSize()
+            : OEPlaceholderAtom.PLACEHOLDER_HALFSIZE;
+        
+        switch (size) {
+        case OEPlaceholderAtom.PLACEHOLDER_FULLSIZE:
+            return PlaceholderSize.full;
+        default:
+        case OEPlaceholderAtom.PLACEHOLDER_HALFSIZE:
+            return PlaceholderSize.half;
+        case OEPlaceholderAtom.PLACEHOLDER_QUARTSIZE:
+            return PlaceholderSize.quarter;
+        }
+    }
+
+    public void setSize(final PlaceholderSize size) {
+        final Placeholder ph = getPlaceholder();
+        if (ph == null || size == null) {
+            return;
+        }
+        updatePlaceholderAtom(true);
+        
+        final byte ph_size;
+        switch (size) {
+        case full:
+            ph_size = OEPlaceholderAtom.PLACEHOLDER_FULLSIZE;
+            break;
+        default:
+        case half:
+            ph_size = OEPlaceholderAtom.PLACEHOLDER_HALFSIZE;
+            break;
+        case quarter:
+            ph_size = OEPlaceholderAtom.PLACEHOLDER_QUARTSIZE;
+            break;
+        }
+        oePlaceholderAtom.setPlaceholderSize(ph_size);
+    }
+
+    private byte getPlaceholderId(final Placeholder placeholder) {
+        /*
+         * Extract from MSDN:
+         *
+         * There is a special case when the placeholder does not have a position in the layout.
+         * This occurs when the user has moved the placeholder from its original position.
+         * In this case the placeholder ID is -1.
+         */
+        final byte phId;
+        switch (source) {
+            default:
+            case slide:
+                phId = (byte)placeholder.nativeSlideId;
+                break;
+            case master:
+                phId = (byte)placeholder.nativeSlideMasterId;
+                break;
+            case notes:
+                phId = (byte)placeholder.nativeNotesId;
+                break;
+            case notesMaster:
+                phId = (byte)placeholder.nativeNotesMasterId;
+                break;
+        }
+
+        if (phId == -2) {
+            throw new HSLFException("Placeholder "+placeholder.name()+" not supported for
this sheet type ("+shape.getSheet().getClass()+")");
+        }
+
+        return phId;
+    }
+
+    private void removePlaceholder() {
+        final HSLFEscherClientDataRecord clientData = shape.getClientData(false);
+        if (clientData != null) {
+            clientData.removeChild(OEPlaceholderAtom.class);
+            clientData.removeChild(RoundTripHFPlaceholder12.class);
+            // remove client data if the placeholder was the only child to be carried
+            if (clientData.getChildRecords().isEmpty()) {
+                shape.getSpContainer().removeChildRecord(clientData);
+            }
+        }
+        oePlaceholderAtom = null;
+        roundTripHFPlaceholder12 = null;
+    }
+
+    private void updatePlaceholderAtom(final boolean create) {
+        final HSLFEscherClientDataRecord clientData = shape.getClientData(create);
+        if (clientData == null) {
+            oePlaceholderAtom = null;
+            roundTripHFPlaceholder12 = null;
+            if (!create) {
+                return;
+            }
+            throw new HSLFException("Placeholder aren't allowed for shape type: " + shape.getClass().getSimpleName());
+        }
+
+        for (Record r : clientData.getHSLFChildRecords()) {
+            if (r instanceof OEPlaceholderAtom) {
+                oePlaceholderAtom = (OEPlaceholderAtom)r;
+            } else if (r instanceof RoundTripHFPlaceholder12) {
+                //special case for files saved in Office 2007
+                roundTripHFPlaceholder12 = (RoundTripHFPlaceholder12)r;
+            }
+        }
+
+        if (!create) {
+            return;
+        }
+
+        if (oePlaceholderAtom == null) {
+            oePlaceholderAtom = new OEPlaceholderAtom();
+            oePlaceholderAtom.setPlaceholderSize((byte)OEPlaceholderAtom.PLACEHOLDER_FULLSIZE);
+            // TODO: placement id only "SHOULD" be unique ... check other placeholders on
sheet for unique id
+            oePlaceholderAtom.setPlacementId(-1);
+            clientData.addChild(oePlaceholderAtom);
+        }
+        if (roundTripHFPlaceholder12 == null) {
+            roundTripHFPlaceholder12 = new RoundTripHFPlaceholder12();
+            clientData.addChild(roundTripHFPlaceholder12);
+        }
+    }
+}

Propchange: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapePlaceholderDetails.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSheet.java?rev=1829453&r1=1829452&r2=1829453&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSheet.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSheet.java Wed Apr 18 15:02:02
2018
@@ -28,8 +28,10 @@ import org.apache.poi.ddf.EscherDgRecord
 import org.apache.poi.ddf.EscherDggRecord;
 import org.apache.poi.ddf.EscherRecord;
 import org.apache.poi.hslf.exceptions.HSLFException;
+import org.apache.poi.hslf.model.HeadersFooters;
 import org.apache.poi.hslf.record.CString;
 import org.apache.poi.hslf.record.ColorSchemeAtom;
+import org.apache.poi.hslf.record.HeadersFootersContainer;
 import org.apache.poi.hslf.record.PPDrawing;
 import org.apache.poi.hslf.record.RecordContainer;
 import org.apache.poi.hslf.record.RecordTypes;
@@ -453,4 +455,20 @@ public abstract class HSLFSheet implemen
         addShape(s);
         return s;
     }
+    
+    /**
+     * Header / Footer settings for this slide.
+     *
+     * @return Header / Footer settings for this slide
+     */
+    public HeadersFooters getHeadersFooters() {
+        return new HeadersFooters(this, HeadersFootersContainer.SlideHeadersFootersContainer);
+    }
+
+
+    @Override
+    public HSLFPlaceholderDetails getPlaceholderDetails(Placeholder placeholder) {
+        final HSLFSimpleShape ph = getPlaceholder(placeholder);
+        return (ph == null) ? null : new HSLFShapePlaceholderDetails(ph);
+    }
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java?rev=1829453&r1=1829452&r2=1829453&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java Wed Apr
18 15:02:02 2018
@@ -18,7 +18,6 @@
 package org.apache.poi.hslf.usermodel;
 
 import java.awt.Color;
-import java.util.List;
 
 import org.apache.poi.ddf.AbstractEscherOptRecord;
 import org.apache.poi.ddf.EscherChildAnchorRecord;
@@ -31,10 +30,6 @@ import org.apache.poi.ddf.EscherRecord;
 import org.apache.poi.ddf.EscherSimpleProperty;
 import org.apache.poi.ddf.EscherSpRecord;
 import org.apache.poi.hslf.exceptions.HSLFException;
-import org.apache.poi.hslf.record.HSLFEscherClientDataRecord;
-import org.apache.poi.hslf.record.OEPlaceholderAtom;
-import org.apache.poi.hslf.record.Record;
-import org.apache.poi.hslf.record.RoundTripHFPlaceholder12;
 import org.apache.poi.sl.draw.DrawPaint;
 import org.apache.poi.sl.draw.geom.CustomGeometry;
 import org.apache.poi.sl.draw.geom.Guide;
@@ -42,7 +37,6 @@ import org.apache.poi.sl.draw.geom.Prese
 import org.apache.poi.sl.usermodel.LineDecoration;
 import org.apache.poi.sl.usermodel.LineDecoration.DecorationShape;
 import org.apache.poi.sl.usermodel.LineDecoration.DecorationSize;
-import org.apache.poi.sl.usermodel.MasterSheet;
 import org.apache.poi.sl.usermodel.PaintStyle;
 import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
 import org.apache.poi.sl.usermodel.Placeholder;
@@ -541,144 +535,19 @@ public abstract class HSLFSimpleShape ex
     }
 
     @Override
+    public HSLFShapePlaceholderDetails getPlaceholderDetails() {
+        return new HSLFShapePlaceholderDetails(this);
+    }
+    
+    
+    @Override
     public Placeholder getPlaceholder() {
-        List<? extends Record> clRecords = getClientRecords();
-        if (clRecords == null) {
-            return null;
-        }
-        int phSource;
-        HSLFSheet sheet = getSheet();
-        if (sheet instanceof HSLFSlideMaster) {
-            phSource = 1;
-        } else if (sheet instanceof HSLFNotes) {
-            phSource = 2;
-        } else if (sheet instanceof MasterSheet) {
-            // notes master aren't yet supported ...
-            phSource = 3;
-        } else {
-            phSource = 0;
-        }
-        
-        for (Record r : clRecords) {
-            int phId;
-            if (r instanceof OEPlaceholderAtom) {
-                phId = ((OEPlaceholderAtom)r).getPlaceholderId();
-            } else if (r instanceof RoundTripHFPlaceholder12) {
-                //special case for files saved in Office 2007
-                phId = ((RoundTripHFPlaceholder12)r).getPlaceholderId();
-            } else {
-                continue;
-            }
-
-            switch (phSource) {
-            case 0:
-                return Placeholder.lookupNativeSlide(phId);
-            default:
-            case 1:
-                return Placeholder.lookupNativeSlideMaster(phId);
-            case 2:
-                return Placeholder.lookupNativeNotes(phId);
-            case 3:
-                return Placeholder.lookupNativeNotesMaster(phId);
-            }
-        }
-
-        return null;
+        return getPlaceholderDetails().getPlaceholder();
     }
 
     @Override
     public void setPlaceholder(Placeholder placeholder) {
-        EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
-        int flags = spRecord.getFlags();
-        if (placeholder == null) {
-            flags ^= EscherSpRecord.FLAG_HAVEMASTER;
-        } else {
-            flags |= EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HAVEMASTER;
-        }
-        spRecord.setFlags(flags);
-
-        // Placeholders can't be grouped
-        setEscherProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, (placeholder
== null ? -1 : 262144));
-
-        HSLFEscherClientDataRecord clientData = getClientData(false);
-        if (placeholder == null) {
-            if (clientData != null) {
-                clientData.removeChild(OEPlaceholderAtom.class);
-                clientData.removeChild(RoundTripHFPlaceholder12.class);
-                // remove client data if the placeholder was the only child to be carried
-                if (clientData.getChildRecords().isEmpty()) {
-                    getSpContainer().removeChildRecord(clientData);
-                }
-            }
-            return;
-        }
-
-        if (clientData == null) {
-            clientData = getClientData(true);
-        }
-
-        // OEPlaceholderAtom tells powerpoint that this shape is a placeholder
-        OEPlaceholderAtom oep = null;
-        RoundTripHFPlaceholder12 rtp = null;
-        for (Record r : clientData.getHSLFChildRecords()) {
-            if (r instanceof OEPlaceholderAtom) {
-                oep = (OEPlaceholderAtom)r;
-                break;
-            }
-            if (r instanceof RoundTripHFPlaceholder12) {
-                rtp = (RoundTripHFPlaceholder12)r;
-                break;
-            }
-        }
-
-        /**
-         * Extract from MSDN:
-         *
-         * There is a special case when the placeholder does not have a position in the layout.
-         * This occurs when the user has moved the placeholder from its original position.
-         * In this case the placeholder ID is -1.
-         */
-        byte phId;
-        HSLFSheet sheet = getSheet();
-        // TODO: implement/switch NotesMaster
-        if (sheet instanceof HSLFSlideMaster) {
-            phId = (byte)placeholder.nativeSlideMasterId;
-        } else if (sheet instanceof HSLFNotes) {
-            phId = (byte)placeholder.nativeNotesId;
-        } else {
-            phId = (byte)placeholder.nativeSlideId;
-        }
-
-        if (phId == -2) {
-            throw new HSLFException("Placeholder "+placeholder.name()+" not supported for
this sheet type ("+sheet.getClass()+")");
-        }
-
-        switch (placeholder) {
-            case HEADER:
-            case FOOTER:
-                if (rtp == null) {
-                    rtp = new RoundTripHFPlaceholder12();
-                    rtp.setPlaceholderId(phId);
-                    clientData.addChild(rtp);
-                }
-                if (oep != null) {
-                    clientData.removeChild(OEPlaceholderAtom.class);
-                }
-                break;
-            default:
-                if (rtp != null) {
-                    clientData.removeChild(RoundTripHFPlaceholder12.class);
-                }
-                if (oep == null) {
-                    oep = new OEPlaceholderAtom();
-                    oep.setPlaceholderSize((byte)OEPlaceholderAtom.PLACEHOLDER_FULLSIZE);
-                    // TODO: placement id only "SHOULD" be unique ... check other placeholders
on sheet for unique id
-                    oep.setPlacementId(-1);
-                    oep.setPlaceholderId(phId);
-                    clientData.addChild(oep);
-                }
-                break;
-        }
+        getPlaceholderDetails().setPlaceholder(placeholder);
     }
 
 
@@ -727,4 +596,10 @@ public abstract class HSLFSimpleShape ex
     protected void setHyperlink(HSLFHyperlink link) {
         _hyperlink = link;
     }
+    
+    @Override
+    public boolean isPlaceholder() {
+        // currently we only identify TextShapes as placeholders
+        return false;
+    }
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java?rev=1829453&r1=1829452&r2=1829453&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java Wed Apr 18 15:02:02
2018
@@ -26,12 +26,12 @@ 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;
 import org.apache.poi.hslf.record.Comment2000;
 import org.apache.poi.hslf.record.EscherTextboxWrapper;
 import org.apache.poi.hslf.record.HeadersFootersContainer;
+import org.apache.poi.hslf.record.Record;
 import org.apache.poi.hslf.record.RecordContainer;
 import org.apache.poi.hslf.record.RecordTypes;
 import org.apache.poi.hslf.record.SSSlideInfoAtom;
@@ -87,8 +87,6 @@ public final class HSLFSlide extends HSL
 	        if (_paragraphs.isEmpty()) {
 	            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
@@ -366,8 +364,9 @@ public final class HSLFSlide extends HSL
      */
      @Override
     public HSLFBackground getBackground() {
-        if(getFollowMasterBackground()) {
-            return getMasterSheet().getBackground();
+        if (getFollowMasterBackground()) {
+            final HSLFMasterSheet ms = getMasterSheet();
+            return (ms == null) ? null : ms.getBackground();
         }
         return super.getBackground();
     }
@@ -377,63 +376,44 @@ public final class HSLFSlide extends HSL
      */
     @Override
     public ColorSchemeAtom getColorScheme() {
-        if(getFollowMasterScheme()){
-            return getMasterSheet().getColorScheme();
+        if (getFollowMasterScheme()) {
+            final HSLFMasterSheet ms = getMasterSheet();
+            return (ms == null) ? null : ms.getColorScheme();
         }
         return super.getColorScheme();
     }
 
+    private static RecordContainer selectContainer(final RecordContainer root, final int
index, final RecordTypes... path) {
+        if (root == null || index >= path.length) {
+            return root;
+        }
+        final RecordContainer newRoot = (RecordContainer) root.findFirstOfType(path[index].typeID);
+        return selectContainer(newRoot, index+1, path);
+    }
+
     /**
      * Get the comment(s) for this slide.
      * Note - for now, only works on PPT 2000 and
      *  PPT 2003 files. Doesn't work for PPT 97
      *  ones, as they do their comments oddly.
      */
-    public Comment[] getComments() {
+    public List<HSLFComment> getComments() {
+        final List<HSLFComment> comments = new ArrayList<>();
     	// If there are any, they're in
     	//  ProgTags -> ProgBinaryTag -> BinaryTagData
-    	RecordContainer progTags = (RecordContainer)
-    			getSheetContainer().findFirstOfType(
-    						RecordTypes.ProgTags.typeID
-    	);
-    	if(progTags != null) {
-    		RecordContainer progBinaryTag = (RecordContainer)
-    			progTags.findFirstOfType(
-    					RecordTypes.ProgBinaryTag.typeID
-    		);
-    		if(progBinaryTag != null) {
-    			RecordContainer binaryTags = (RecordContainer)
-    				progBinaryTag.findFirstOfType(
-    						RecordTypes.BinaryTagData.typeID
-    			);
-    			if(binaryTags != null) {
-    				// This is where they'll be
-    				int count = 0;
-    				for(int i=0; i<binaryTags.getChildRecords().length; i++) {
-    					if(binaryTags.getChildRecords()[i] instanceof Comment2000) {
-    						count++;
-    					}
-    				}
-
-    				// Now build
-    				Comment[] comments = new Comment[count];
-    				count = 0;
-    				for(int i=0; i<binaryTags.getChildRecords().length; i++) {
-    					if(binaryTags.getChildRecords()[i] instanceof Comment2000) {
-    						comments[i] = new Comment(
-    								(Comment2000)binaryTags.getChildRecords()[i]
-    						);
-    						count++;
-    					}
-    				}
-
-    				return comments;
-    			}
-    		}
-    	}
+        final RecordContainer binaryTags =
+                selectContainer(getSheetContainer(), 0,
+                        RecordTypes.ProgTags, RecordTypes.ProgBinaryTag, RecordTypes.BinaryTagData);
+
+        if (binaryTags != null) {
+            for (final Record record : binaryTags.getChildRecords()) {
+                if (record instanceof Comment2000) {
+                    comments.add(new HSLFComment((Comment2000)record));
+                }
+            }
+        }
 
-    	// None found
-    	return new Comment[0];
+    	return comments;
     }
 
     /**
@@ -478,9 +458,7 @@ public final class HSLFSlide extends HSL
 	public boolean isHidden() {
 		SSSlideInfoAtom slideInfo =
 			(SSSlideInfoAtom)getSlideRecord().findFirstOfType(RecordTypes.SSSlideInfoAtom.typeID);
-		return (slideInfo == null)
-			? false
-			: slideInfo.getEffectTransitionFlagByBit(SSSlideInfoAtom.HIDDEN_BIT);
+		return (slideInfo != null) && slideInfo.getEffectTransitionFlagByBit(SSSlideInfoAtom.HIDDEN_BIT);
 	}
 
     @Override
@@ -505,25 +483,22 @@ public final class HSLFSlide extends HSL
     }
 
     @Override
-    public boolean getDisplayPlaceholder(Placeholder placeholder) {
-        HeadersFooters hf = getHeadersFooters();
-        SlideLayoutType slt =  getSlideRecord().getSlideAtom().getSSlideLayoutAtom().getGeometryType();
-        boolean isTitle =
+    public boolean getDisplayPlaceholder(final Placeholder placeholder) {
+        final HeadersFooters hf = getHeadersFooters();
+        final SlideLayoutType slt = getSlideRecord().getSlideAtom().getSSlideLayoutAtom().getGeometryType();
+        final boolean isTitle =
             (slt == SlideLayoutType.TITLE_SLIDE || slt == SlideLayoutType.TITLE_ONLY || slt
== SlideLayoutType.MASTER_TITLE);
-        if (hf != null) {
-            switch (placeholder) {
-            case DATETIME:
-                return hf.isDateTimeVisible() && !isTitle;
-            case SLIDE_NUMBER:
-                return hf.isSlideNumberVisible() && !isTitle;
-            case HEADER:
-                return hf.isHeaderVisible() && !isTitle;
-            case FOOTER:
-                return hf.isFooterVisible() && !isTitle;
-            default:
-                break;    
-            }
+        switch (placeholder) {
+        case DATETIME:
+            return hf.isDateTimeVisible() && !isTitle;
+        case SLIDE_NUMBER:
+            return hf.isSlideNumberVisible() && !isTitle;
+        case HEADER:
+            return hf.isHeaderVisible() && !isTitle;
+        case FOOTER:
+            return hf.isFooterVisible() && !isTitle;
+        default:
+            return false;
         }
-        return false;
     }
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java?rev=1829453&r1=1829452&r2=1829453&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java Wed Apr
18 15:02:02 2018
@@ -38,6 +38,7 @@ import org.apache.poi.ddf.EscherContaine
 import org.apache.poi.ddf.EscherOptRecord;
 import org.apache.poi.hpsf.ClassID;
 import org.apache.poi.hpsf.ClassIDPredefined;
+import org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor;
 import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
 import org.apache.poi.hslf.exceptions.HSLFException;
 import org.apache.poi.hslf.model.HeadersFooters;
@@ -1047,6 +1048,11 @@ public final class HSLFSlideShow impleme
 		return objectId;
 	}
 
+	@Override
+    public HPSFPropertiesExtractor getMetadataTextExtractor() {
+        return new HPSFPropertiesExtractor(getSlideShowImpl());
+    }
+	
 	protected int addToObjListAtom(RecordContainer exObj) {
 		ExObjList lst = getDocumentRecord().getExObjList(true);
 		ExObjListAtom objAtom = lst.getExObjListAtom();

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java?rev=1829453&r1=1829452&r2=1829453&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java Wed Apr
18 15:02:02 2018
@@ -272,7 +272,7 @@ implements TextShape<HSLFShape,HSLFTextP
         }
 
         final String text = ((tba != null) ? tba.getText() : tca.getText());
-        
+
         StyleTextPropAtom sta = (StyleTextPropAtom)_txtbox.findFirstOfType(StyleTextPropAtom._type);
         TextPropCollection paraStyle = null, charStyle = null;
         if (sta == null) {
@@ -305,7 +305,7 @@ implements TextShape<HSLFShape,HSLFTextP
             htp.setParagraphStyle(paraStyle);
             htp.setParentShape(this);
             _paragraphs.add(htp);
-    
+
             HSLFTextRun htr = new HSLFTextRun(htp);
             htr.setCharacterStyle(charStyle);
             htr.setText(text);
@@ -317,7 +317,7 @@ implements TextShape<HSLFShape,HSLFTextP
     public Rectangle2D resizeToFitText() {
         return resizeToFitText(null);
     }
-    
+
     @Override
     public Rectangle2D resizeToFitText(Graphics2D graphics) {
         Rectangle2D anchor = getAnchor();
@@ -649,7 +649,7 @@ implements TextShape<HSLFShape,HSLFTextP
             } else {
                 _paragraphs = pList;
             }
-        
+
             if (_paragraphs.isEmpty()) {
                 LOG.log(POILogger.WARN, "TextRecord didn't contained any text lines");
             }
@@ -701,18 +701,13 @@ implements TextShape<HSLFShape,HSLFTextP
 
     @Override
     public boolean isPlaceholder() {
-        OEPlaceholderAtom oep = getPlaceholderAtom();
-        if (oep != null) {
-            return true;
-        }
-
-        //special case for files saved in Office 2007
-        RoundTripHFPlaceholder12 hldr = getHFPlaceholderAtom();
-        if (hldr != null) {
-            return true;
-        }
-
-        return false;
+        return
+            ((getPlaceholderAtom() != null) ||
+            //special case for files saved in Office 2007
+            (getHFPlaceholderAtom() != null)) &&
+            // check for metro shape of complex placeholder
+            (!new HSLFMetroShape<HSLFShape>(this).hasMetroBlob())
+        ;
     }
 
 
@@ -738,7 +733,7 @@ implements TextShape<HSLFShape,HSLFTextP
     public double getTextHeight() {
         return getTextHeight(null);
     }
-    
+
     @Override
     public double getTextHeight(Graphics2D graphics) {
         DrawFactory drawFact = DrawFactory.getInstance(graphics);

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java?rev=1829453&r1=1829452&r2=1829453&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java Wed
Apr 18 15:02:02 2018
@@ -33,9 +33,9 @@ import java.io.InputStream;
 import java.util.List;
 
 import org.apache.poi.POIDataSamples;
+import org.apache.poi.hslf.usermodel.HSLFObjectShape;
 import org.apache.poi.hslf.usermodel.HSLFSlideShow;
 import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
-import org.apache.poi.hslf.usermodel.HSLFObjectShape;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hwpf.HWPFDocument;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
@@ -89,12 +89,12 @@ public final class TestExtractor {
     public void testReadSheetText() throws IOException {
         // Basic 2 page example
         PowerPointExtractor ppe = openExtractor("basic_test_ppt_file.ppt");
-        ensureTwoStringsTheSame(expectText, ppe.getText());
+        assertEquals(expectText, ppe.getText());
         ppe.close();
 
         // 1 page example with text boxes
         PowerPointExtractor ppe2 = openExtractor("with_textbox.ppt");
-        ensureTwoStringsTheSame(expectText2, ppe2.getText());
+        assertEquals(expectText2, ppe2.getText());
         ppe2.close();
     }
 
@@ -103,15 +103,15 @@ public final class TestExtractor {
         // Basic 2 page example
         PowerPointExtractor ppe = openExtractor("basic_test_ppt_file.ppt");
         String notesText = ppe.getNotes();
-        String expText = "These are the notes for page 1\nThese are the notes on page two,
again lacking formatting\n";
-        ensureTwoStringsTheSame(expText, notesText);
+        String expText = "\nThese are the notes for page 1\n\nThese are the notes on page
two, again lacking formatting\n";
+        assertEquals(expText, notesText);
         ppe.close();
 
         // Other one doesn't have notes
         PowerPointExtractor ppe2 = openExtractor("with_textbox.ppt");
         notesText = ppe2.getNotes();
         expText = "";
-        ensureTwoStringsTheSame(expText, notesText);
+        assertEquals(expText, notesText);
         ppe2.close();
     }
 
@@ -122,8 +122,8 @@ public final class TestExtractor {
                 "This is the title on page 2\nThis is page two\nIt has several blocks of
text\nNone of them have formatting\n"
         };
         String[] ntText = new String[]{
-                "These are the notes for page 1\n",
-                "These are the notes on page two, again lacking formatting\n"
+                "\nThese are the notes for page 1\n",
+                "\nThese are the notes on page two, again lacking formatting\n"
         };
 
         PowerPointExtractor ppe = openExtractor("basic_test_ppt_file.ppt");
@@ -137,7 +137,7 @@ public final class TestExtractor {
 
         ppe.setSlidesByDefault(true);
         ppe.setNotesByDefault(true);
-        assertEquals(slText[0] + slText[1] + "\n" + ntText[0] + ntText[1], ppe.getText());
+        assertEquals(slText[0] + ntText[0] + slText[1] + ntText[1], ppe.getText());
         ppe.close();
     }
 
@@ -166,16 +166,6 @@ public final class TestExtractor {
         ppe.close();
     }
 
-    private void ensureTwoStringsTheSame(String exp, String act) {
-        assertEquals(exp.length(), act.length());
-        char[] expC = exp.toCharArray();
-        char[] actC = act.toCharArray();
-        for (int i = 0; i < expC.length; i++) {
-            assertEquals("Char " + i, expC[i], actC[i]);
-        }
-        assertEquals(exp, act);
-    }
-
     @Test
     public void testExtractFromEmbeded() throws IOException {
         InputStream is = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("excel_with_embeded.xls");
@@ -454,4 +444,38 @@ public final class TestExtractor {
         assertContains(text, "Prague");
         ppe.close();
     }
+
+    @Test
+    public void testExtractGroupedShapeText() throws Exception {
+        try (final PowerPointExtractor ppe = openExtractor("bug62092.ppt")) {
+            final String text = ppe.getText();
+
+            //this tests that we're ignoring text shapes at depth=0
+            //i.e. POI has already included them in the slide's getTextParagraphs()
+            assertContains(text, "Text box1");
+            assertEquals(1, countMatches(text,"Text box1"));
+
+
+            //the WordArt and text box count tests will fail
+            //if this content is available via getTextParagraphs() of the slide in POI
+            //i.e. when POI is fixed, these tests will fail, and
+            //we'll have to remove the workaround in HSLFExtractor's extractGroupText(...)
+            assertEquals(1, countMatches(text,"WordArt1"));
+            assertEquals(1, countMatches(text,"WordArt2"));
+            assertEquals(1, countMatches(text,"Ungrouped text box"));//should only be 1
+            assertContains(text, "Text box2");
+            assertContains(text, "Text box3");
+            assertContains(text, "Text box4");
+            assertContains(text, "Text box5");
+
+            //see below -- need to extract hyperlinks
+            assertContains(text, "tika");
+            assertContains(text, "MyTitle");
+
+        }
+    }
+
+    private static int countMatches(final String base, final String find) {
+        return base.split(find).length-1;
+    }
 }

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordTypes.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordTypes.java?rev=1829453&r1=1829452&r2=1829453&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordTypes.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordTypes.java Wed
Apr 18 15:02:02 2018
@@ -18,10 +18,10 @@
 package org.apache.poi.hslf.record;
 
 
-import static org.junit.Assert.assertEquals;
-
 import org.junit.Test;
 
+import static org.junit.Assert.assertEquals;
+
 /**
  * Tests that RecordTypes returns the right records and classes when asked
  */
@@ -42,20 +42,15 @@ public final class TestRecordTypes {
 
     @Test
 	public void testPPTClassLookups() {
-		assertEquals(Slide.class, RecordTypes.Slide.handlingClass);
-		assertEquals(TextCharsAtom.class, RecordTypes.TextCharsAtom.handlingClass);
-		assertEquals(TextBytesAtom.class, RecordTypes.TextBytesAtom.handlingClass);
-		assertEquals(SlideListWithText.class, RecordTypes.SlideListWithText.handlingClass);
-
 		// If this record is ever implemented, change to one that isn't!
 		// This is checking the "unhandled default" stuff works
-		assertEquals(UnknownRecordPlaceholder.class, RecordTypes.forTypeID(-10).handlingClass);
+		assertEquals(RecordTypes.UnknownRecordPlaceholder, RecordTypes.forTypeID(-10));
 	}
 
     @Test
     public void testEscherClassLookups() {
 		// Should all come back with null, as DDF handles them
-		assertEquals(null, RecordTypes.EscherDggContainer.handlingClass);
-		assertEquals(null, RecordTypes.EscherBStoreContainer.handlingClass);
+		assertEquals(null, RecordTypes.EscherDggContainer.recordConstructor);
+		assertEquals(null, RecordTypes.EscherBStoreContainer.recordConstructor);
 	}
 }

Added: poi/trunk/test-data/slideshow/bug62092.ppt
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/slideshow/bug62092.ppt?rev=1829453&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/slideshow/bug62092.ppt
------------------------------------------------------------------------------
    svn:mime-type = application/vnd.ms-powerpoint



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message