You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2015/12/31 23:10:18 UTC
svn commit: r1722476 [2/2] - in /poi: site/src/documentation/content/xdocs/
trunk/src/examples/src/org/apache/poi/hslf/examples/
trunk/src/examples/src/org/apache/poi/xslf/usermodel/
trunk/src/java/org/apache/poi/ddf/ trunk/src/java/org/apache/poi/sl/d...
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java?rev=1722476&r1=1722475&r2=1722476&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java Thu Dec 31 22:10:17 2015
@@ -17,8 +17,8 @@
package org.apache.poi.hslf.record;
-import java.lang.reflect.Field;
import java.util.HashMap;
+import java.util.Map;
/**
* List of all known record types in a PowerPoint document, and the
@@ -26,191 +26,209 @@ import java.util.HashMap;
* There are two categories of records:
* <li> PowerPoint records: 0 <= info <= 10002 (will carry class info)
* <li> Escher records: info >= 0xF000 (handled by DDF, so no class info)
- *
- * @author Yegor Kozlov
- * @author Nick Burch
*/
-public final class RecordTypes {
- public static final HashMap<Integer,String> typeToName;
- public static final HashMap<Integer,Class<? extends Record>> typeToClass;
-
- public static final Type Unknown = new Type(0,null);
- public static final Type Document = new Type(1000,Document.class);
- public static final Type DocumentAtom = new Type(1001,DocumentAtom.class);
- public static final Type EndDocument = new Type(1002,null);
- public static final Type Slide = new Type(1006,Slide.class);
- public static final Type SlideAtom = new Type(1007,SlideAtom.class);
- public static final Type Notes = new Type(1008,Notes.class);
- public static final Type NotesAtom = new Type(1009,NotesAtom.class);
- public static final Type Environment = new Type(1010,Environment.class);
- public static final Type SlidePersistAtom = new Type(1011,SlidePersistAtom.class);
- public static final Type SSlideLayoutAtom = new Type(1015,null);
- public static final Type MainMaster = new Type(1016,MainMaster.class);
- public static final Type SSSlideInfoAtom = new Type(1017,SSSlideInfoAtom.class);
- public static final Type SlideViewInfo = new Type(1018,null);
- public static final Type GuideAtom = new Type(1019,null);
- public static final Type ViewInfo = new Type(1020,null);
- public static final Type ViewInfoAtom = new Type(1021,null);
- public static final Type SlideViewInfoAtom = new Type(1022,null);
- public static final Type VBAInfo = new Type(1023,null);
- public static final Type VBAInfoAtom = new Type(1024,null);
- public static final Type SSDocInfoAtom = new Type(1025,null);
- public static final Type Summary = new Type(1026,null);
- public static final Type DocRoutingSlip = new Type(1030,null);
- public static final Type OutlineViewInfo = new Type(1031,null);
- public static final Type SorterViewInfo = new Type(1032,null);
- public static final Type ExObjList = new Type(1033,ExObjList.class);
- public static final Type ExObjListAtom = new Type(1034,ExObjListAtom.class);
- public static final Type PPDrawingGroup = new Type(1035,PPDrawingGroup.class);
- public static final Type PPDrawing = new Type(1036,PPDrawing.class);
- public static final Type NamedShows = new Type(1040,null);
- public static final Type NamedShow = new Type(1041,null);
- public static final Type NamedShowSlides = new Type(1042,null);
- public static final Type SheetProperties = new Type(1044,null);
- public static final Type RoundTripCustomTableStyles12Atom = new Type(1064,null);
- public static final Type List = new Type(2000,null);
- public static final Type FontCollection = new Type(2005,FontCollection.class);
- public static final Type BookmarkCollection = new Type(2019,null);
- public static final Type SoundCollection = new Type(2020,SoundCollection.class);
- public static final Type SoundCollAtom = new Type(2021,null);
- public static final Type Sound = new Type(2022,Sound.class);
- public static final Type SoundData = new Type(2023,SoundData.class);
- public static final Type BookmarkSeedAtom = new Type(2025,null);
- public static final Type ColorSchemeAtom = new Type(2032,ColorSchemeAtom.class);
- public static final Type ExObjRefAtom = new Type(3009,null);
- public static final Type OEShapeAtom = new Type(3009,OEShapeAtom.class);
- public static final Type OEPlaceholderAtom = new Type(3011,OEPlaceholderAtom.class);
- public static final Type GPopublicintAtom = new Type(3024,null);
- public static final Type GRatioAtom = new Type(3031,null);
- public static final Type OutlineTextRefAtom = new Type(3998,OutlineTextRefAtom.class);
- public static final Type TextHeaderAtom = new Type(3999,TextHeaderAtom.class);
- public static final Type TextCharsAtom = new Type(4000,TextCharsAtom.class);
- public static final Type StyleTextPropAtom = new Type(4001, StyleTextPropAtom.class);//0x0fa1 RT_StyleTextPropAtom
- public static final Type MasterTextPropAtom = new Type(4002, MasterTextPropAtom.class);
- public static final Type TxMasterStyleAtom = new Type(4003,TxMasterStyleAtom.class);
- public static final Type TxCFStyleAtom = new Type(4004,null);
- public static final Type TxPFStyleAtom = new Type(4005,null);
- public static final Type TextRulerAtom = new Type(4006,TextRulerAtom.class);
- public static final Type TextBookmarkAtom = new Type(4007,null);
- public static final Type TextBytesAtom = new Type(4008,TextBytesAtom.class);
- public static final Type TxSIStyleAtom = new Type(4009,null);
- public static final Type TextSpecInfoAtom = new Type(4010, TextSpecInfoAtom.class);
- public static final Type DefaultRulerAtom = new Type(4011,null);
- public static final Type StyleTextProp9Atom = new Type(4012, StyleTextProp9Atom.class); //0x0FAC RT_StyleTextProp9Atom
- public static final Type FontEntityAtom = new Type(4023,FontEntityAtom.class);
- public static final Type FontEmbeddedData = new Type(4024,null);
- public static final Type CString = new Type(4026,CString.class);
- public static final Type MetaFile = new Type(4033,null);
- public static final Type ExOleObjAtom = new Type(4035,ExOleObjAtom.class);
- public static final Type SrKinsoku = new Type(4040,null);
- public static final Type HandOut = new Type(4041,DummyPositionSensitiveRecordWithChildren.class);
- public static final Type ExEmbed = new Type(4044,ExEmbed.class);
- public static final Type ExEmbedAtom = new Type(4045,ExEmbedAtom.class);
- public static final Type ExLink = new Type(4046,null);
- public static final Type BookmarkEntityAtom = new Type(4048,null);
- public static final Type ExLinkAtom = new Type(4049,null);
- public static final Type SrKinsokuAtom = new Type(4050,null);
- public static final Type ExHyperlinkAtom = new Type(4051,ExHyperlinkAtom.class);
- public static final Type ExHyperlink = new Type(4055,ExHyperlink.class);
- public static final Type SlideNumberMCAtom = new Type(4056,null);
- public static final Type HeadersFooters = new Type(4057,HeadersFootersContainer.class);
- public static final Type HeadersFootersAtom = new Type(4058,HeadersFootersAtom.class);
- public static final Type TxInteractiveInfoAtom = new Type(4063,TxInteractiveInfoAtom.class);
- public static final Type CharFormatAtom = new Type(4066,null);
- public static final Type ParaFormatAtom = new Type(4067,null);
- public static final Type RecolorInfoAtom = new Type(4071,null);
- public static final Type ExQuickTimeMovie = new Type(4074,null);
- public static final Type ExQuickTimeMovieData = new Type(4075,null);
- public static final Type ExControl = new Type(4078,ExControl.class);
- public static final Type SlideListWithText = new Type(4080,SlideListWithText.class);
- public static final Type InteractiveInfo = new Type(4082,InteractiveInfo.class);
- public static final Type InteractiveInfoAtom = new Type(4083,InteractiveInfoAtom.class);
- public static final Type UserEditAtom = new Type(4085,UserEditAtom.class);
- public static final Type CurrentUserAtom = new Type(4086,null);
- public static final Type DateTimeMCAtom = new Type(4087,null);
- public static final Type GenericDateMCAtom = new Type(4088,null);
- public static final Type FooterMCAtom = new Type(4090,null);
- public static final Type ExControlAtom = new Type(4091,ExControlAtom.class);
- public static final Type ExMediaAtom = new Type(4100,ExMediaAtom.class);
- public static final Type ExVideoContainer = new Type(4101,ExVideoContainer.class);
- public static final Type ExAviMovie = new Type(4102,ExAviMovie.class);
- public static final Type ExMCIMovie = new Type(4103,ExMCIMovie.class);
- public static final Type ExMIDIAudio = new Type(4109,null);
- public static final Type ExCDAudio = new Type(4110,null);
- public static final Type ExWAVAudioEmbedded = new Type(4111,null);
- public static final Type ExWAVAudioLink = new Type(4112,null);
- public static final Type ExOleObjStg = new Type(4113,ExOleObjStg.class);
- public static final Type ExCDAudioAtom = new Type(4114,null);
- public static final Type ExWAVAudioEmbeddedAtom = new Type(4115,null);
- public static final Type AnimationInfo = new Type(4116,AnimationInfo.class);
- public static final Type AnimationInfoAtom = new Type(4081,AnimationInfoAtom.class);
- public static final Type RTFDateTimeMCAtom = new Type(4117,null);
- public static final Type ProgTags = new Type(5000,DummyPositionSensitiveRecordWithChildren.class);
- public static final Type ProgStringTag = new Type(5001,null);
- public static final Type ProgBinaryTag = new Type(5002,DummyPositionSensitiveRecordWithChildren.class);
- public static final Type BinaryTagData = new Type(5003, BinaryTagDataBlob.class);//0x138b RT_BinaryTagDataBlob
- public static final Type PrpublicintOptions = new Type(6000,null);
- public static final Type PersistPtrFullBlock = new Type(6001,PersistPtrHolder.class);
- public static final Type PersistPtrIncrementalBlock = new Type(6002,PersistPtrHolder.class);
- public static final Type GScalingAtom = new Type(10001,null);
- public static final Type GRColorAtom = new Type(10002,null);
+public enum RecordTypes {
+ Unknown(0,null),
+ UnknownRecordPlaceholder(-1, UnknownRecordPlaceholder.class),
+ Document(1000,Document.class),
+ DocumentAtom(1001,DocumentAtom.class),
+ EndDocument(1002,null),
+ Slide(1006,Slide.class),
+ SlideAtom(1007,SlideAtom.class),
+ Notes(1008,Notes.class),
+ NotesAtom(1009,NotesAtom.class),
+ Environment(1010,Environment.class),
+ SlidePersistAtom(1011,SlidePersistAtom.class),
+ SSlideLayoutAtom(1015,null),
+ MainMaster(1016,MainMaster.class),
+ SSSlideInfoAtom(1017,SSSlideInfoAtom.class),
+ SlideViewInfo(1018,null),
+ GuideAtom(1019,null),
+ ViewInfo(1020,null),
+ ViewInfoAtom(1021,null),
+ SlideViewInfoAtom(1022,null),
+ VBAInfo(1023,null),
+ VBAInfoAtom(1024,null),
+ SSDocInfoAtom(1025,null),
+ Summary(1026,null),
+ DocRoutingSlip(1030,null),
+ OutlineViewInfo(1031,null),
+ SorterViewInfo(1032,null),
+ ExObjList(1033,ExObjList.class),
+ ExObjListAtom(1034,ExObjListAtom.class),
+ PPDrawingGroup(1035,PPDrawingGroup.class),
+ PPDrawing(1036,PPDrawing.class),
+ NamedShows(1040,null),
+ NamedShow(1041,null),
+ NamedShowSlides(1042,null),
+ SheetProperties(1044,null),
+ RoundTripCustomTableStyles12Atom(1064,null),
+ List(2000,null),
+ FontCollection(2005,FontCollection.class),
+ BookmarkCollection(2019,null),
+ SoundCollection(2020,SoundCollection.class),
+ SoundCollAtom(2021,null),
+ Sound(2022,Sound.class),
+ SoundData(2023,SoundData.class),
+ BookmarkSeedAtom(2025,null),
+ ColorSchemeAtom(2032,ColorSchemeAtom.class),
+ ExObjRefAtom(3009,ExObjRefAtom.class),
+ OEPlaceholderAtom(3011,OEPlaceholderAtom.class),
+ GPopublicintAtom(3024,null),
+ GRatioAtom(3031,null),
+ OutlineTextRefAtom(3998,OutlineTextRefAtom.class),
+ TextHeaderAtom(3999,TextHeaderAtom.class),
+ TextCharsAtom(4000,TextCharsAtom.class),
+ StyleTextPropAtom(4001, StyleTextPropAtom.class),//0x0fa1 RT_StyleTextPropAtom
+ MasterTextPropAtom(4002, MasterTextPropAtom.class),
+ TxMasterStyleAtom(4003,TxMasterStyleAtom.class),
+ TxCFStyleAtom(4004,null),
+ TxPFStyleAtom(4005,null),
+ TextRulerAtom(4006,TextRulerAtom.class),
+ TextBookmarkAtom(4007,null),
+ TextBytesAtom(4008,TextBytesAtom.class),
+ TxSIStyleAtom(4009,null),
+ TextSpecInfoAtom(4010, TextSpecInfoAtom.class),
+ DefaultRulerAtom(4011,null),
+ StyleTextProp9Atom(4012, StyleTextProp9Atom.class), //0x0FAC RT_StyleTextProp9Atom
+ FontEntityAtom(4023,FontEntityAtom.class),
+ FontEmbeddedData(4024,null),
+ CString(4026,CString.class),
+ MetaFile(4033,null),
+ ExOleObjAtom(4035,ExOleObjAtom.class),
+ SrKinsoku(4040,null),
+ HandOut(4041,DummyPositionSensitiveRecordWithChildren.class),
+ ExEmbed(4044,ExEmbed.class),
+ ExEmbedAtom(4045,ExEmbedAtom.class),
+ ExLink(4046,null),
+ BookmarkEntityAtom(4048,null),
+ ExLinkAtom(4049,null),
+ SrKinsokuAtom(4050,null),
+ ExHyperlinkAtom(4051,ExHyperlinkAtom.class),
+ ExHyperlink(4055,ExHyperlink.class),
+ SlideNumberMCAtom(4056,null),
+ HeadersFooters(4057,HeadersFootersContainer.class),
+ HeadersFootersAtom(4058,HeadersFootersAtom.class),
+ TxInteractiveInfoAtom(4063,TxInteractiveInfoAtom.class),
+ CharFormatAtom(4066,null),
+ ParaFormatAtom(4067,null),
+ RecolorInfoAtom(4071,null),
+ ExQuickTimeMovie(4074,null),
+ ExQuickTimeMovieData(4075,null),
+ ExControl(4078,ExControl.class),
+ SlideListWithText(4080,SlideListWithText.class),
+ InteractiveInfo(4082,InteractiveInfo.class),
+ InteractiveInfoAtom(4083,InteractiveInfoAtom.class),
+ UserEditAtom(4085,UserEditAtom.class),
+ CurrentUserAtom(4086,null),
+ DateTimeMCAtom(4087,null),
+ GenericDateMCAtom(4088,null),
+ FooterMCAtom(4090,null),
+ ExControlAtom(4091,ExControlAtom.class),
+ ExMediaAtom(4100,ExMediaAtom.class),
+ ExVideoContainer(4101,ExVideoContainer.class),
+ ExAviMovie(4102,ExAviMovie.class),
+ ExMCIMovie(4103,ExMCIMovie.class),
+ ExMIDIAudio(4109,null),
+ ExCDAudio(4110,null),
+ ExWAVAudioEmbedded(4111,null),
+ ExWAVAudioLink(4112,null),
+ ExOleObjStg(4113,ExOleObjStg.class),
+ ExCDAudioAtom(4114,null),
+ ExWAVAudioEmbeddedAtom(4115,null),
+ AnimationInfo(4116,AnimationInfo.class),
+ AnimationInfoAtom(4081,AnimationInfoAtom.class),
+ RTFDateTimeMCAtom(4117,null),
+ ProgTags(5000,DummyPositionSensitiveRecordWithChildren.class),
+ ProgStringTag(5001,null),
+ ProgBinaryTag(5002,DummyPositionSensitiveRecordWithChildren.class),
+ BinaryTagData(5003, BinaryTagDataBlob.class),//0x138b RT_BinaryTagDataBlob
+ PrpublicintOptions(6000,null),
+ PersistPtrFullBlock(6001,PersistPtrHolder.class),
+ PersistPtrIncrementalBlock(6002,PersistPtrHolder.class),
+ GScalingAtom(10001,null),
+ GRColorAtom(10002,null),
// Records ~12000 seem to be related to the Comments used in PPT 2000/XP
// (Comments in PPT97 are normal Escher text boxes)
- public static final Type Comment2000 = new Type(12000,Comment2000.class);
- public static final Type Comment2000Atom = new Type(12001,Comment2000Atom.class);
- public static final Type Comment2000Summary = new Type(12004,null);
- public static final Type Comment2000SummaryAtom = new Type(12005,null);
+ Comment2000(12000,Comment2000.class),
+ Comment2000Atom(12001,Comment2000Atom.class),
+ Comment2000Summary(12004,null),
+ Comment2000SummaryAtom(12005,null),
// Records ~12050 seem to be related to Document Encryption
- public static final Type DocumentEncryptionAtom = new Type(12052,DocumentEncryptionAtom.class);
+ DocumentEncryptionAtom(12052,DocumentEncryptionAtom.class),
+
+ OriginalMainMasterId(1052,null),
+ CompositeMasterId(1052,null),
+ RoundTripContentMasterInfo12(1054,null),
+ RoundTripShapeId12(1055,null),
+ RoundTripHFPlaceholder12(1056,RoundTripHFPlaceholder12.class),
+ RoundTripContentMasterId(1058,null),
+ RoundTripOArtTextStyles12(1059,null),
+ RoundTripShapeCheckSumForCustomLayouts12(1062,null),
+ RoundTripNotesMasterTextStyles12(1063,null),
+ RoundTripCustomTableStyles12(1064,null),
+
+ // records greater then 0xF000 belong to with Microsoft Office Drawing format also known as Escher
+ EscherDggContainer(0xF000,null),
+ EscherDgg(0xf006,null),
+ EscherCLSID(0xf016,null),
+ EscherOPT(0xf00b,null),
+ EscherBStoreContainer(0xf001,null),
+ EscherBSE(0xf007,null),
+ EscherBlip_START(0xf018,null),
+ EscherBlip_END(0xf117,null),
+ EscherDgContainer(0xf002,null),
+ EscherDg(0xf008,null),
+ EscherRegroupItems(0xf118,null),
+ EscherColorScheme(0xf120,null),
+ EscherSpgrContainer(0xf003,null),
+ EscherSpContainer(0xf004,null),
+ EscherSpgr(0xf009,null),
+ EscherSp(0xf00a,null),
+ EscherTextbox(0xf00c,null),
+ EscherClientTextbox(0xf00d,null),
+ EscherAnchor(0xf00e,null),
+ EscherChildAnchor(0xf00f,null),
+ EscherClientAnchor(0xf010,null),
+ EscherClientData(0xf011,null),
+ EscherSolverContainer(0xf005,null),
+ EscherConnectorRule(0xf012,null),
+ EscherAlignRule(0xf013,null),
+ EscherArcRule(0xf014,null),
+ EscherClientRule(0xf015,null),
+ EscherCalloutRule(0xf017,null),
+ EscherSelection(0xf119,null),
+ EscherColorMRU(0xf11a,null),
+ EscherDeletedPspl(0xf11d,null),
+ EscherSplitMenuColors(0xf11e,null),
+ EscherOleObject(0xf11f,null),
+ EscherUserDefined(0xf122,null);
+
+ private static final Map<Short,RecordTypes> LOOKUP;
+
+ static {
+ LOOKUP = new HashMap<Short,RecordTypes>();
+ for(RecordTypes s : values()) {
+ LOOKUP.put(s.typeID, s);
+ }
+ }
+
+ public final short typeID;
+ public final Class<? extends Record> handlingClass;
+
+ private RecordTypes(int typeID, Class<? extends Record> handlingClass) {
+ this.typeID = (short)typeID;
+ this.handlingClass = handlingClass;
+ }
+
+ public static RecordTypes forTypeID(int typeID) {
+ RecordTypes rt = LOOKUP.get((short)typeID);
+ return (rt != null) ? rt : UnknownRecordPlaceholder;
+ }
+
- public static final Type OriginalMainMasterId = new Type(1052,null);
- public static final Type CompositeMasterId = new Type(1052,null);
- public static final Type RoundTripContentMasterInfo12 = new Type(1054,null);
- public static final Type RoundTripShapeId12 = new Type(1055,null);
- public static final Type RoundTripHFPlaceholder12 = new Type(1056,RoundTripHFPlaceholder12.class);
- public static final Type RoundTripContentMasterId = new Type(1058,null);
- public static final Type RoundTripOArtTextStyles12 = new Type(1059,null);
- public static final Type RoundTripShapeCheckSumForCustomLayouts12 = new Type(1062,null);
- public static final Type RoundTripNotesMasterTextStyles12 = new Type(1063,null);
- public static final Type RoundTripCustomTableStyles12 = new Type(1064,null);
-
- //records greater then 0xF000 belong to with Microsoft Office Drawing format also known as Escher
- public static final int EscherDggContainer = 0xf000;
- public static final int EscherDgg = 0xf006;
- public static final int EscherCLSID = 0xf016;
- public static final int EscherOPT = 0xf00b;
- public static final int EscherBStoreContainer = 0xf001;
- public static final int EscherBSE = 0xf007;
- public static final int EscherBlip_START = 0xf018;
- public static final int EscherBlip_END = 0xf117;
- public static final int EscherDgContainer = 0xf002;
- public static final int EscherDg = 0xf008;
- public static final int EscherRegroupItems = 0xf118;
- public static final int EscherColorScheme = 0xf120;
- public static final int EscherSpgrContainer = 0xf003;
- public static final int EscherSpContainer = 0xf004;
- public static final int EscherSpgr = 0xf009;
- public static final int EscherSp = 0xf00a;
- public static final int EscherTextbox = 0xf00c;
- public static final int EscherClientTextbox = 0xf00d;
- public static final int EscherAnchor = 0xf00e;
- public static final int EscherChildAnchor = 0xf00f;
- public static final int EscherClientAnchor = 0xf010;
- public static final int EscherClientData = 0xf011;
- public static final int EscherSolverContainer = 0xf005;
- public static final int EscherConnectorRule = 0xf012;
- public static final int EscherAlignRule = 0xf013;
- public static final int EscherArcRule = 0xf014;
- public static final int EscherClientRule = 0xf015;
- public static final int EscherCalloutRule = 0xf017;
- public static final int EscherSelection = 0xf119;
- public static final int EscherColorMRU = 0xf11a;
- public static final int EscherDeletedPspl = 0xf11d;
- public static final int EscherSplitMenuColors = 0xf11e;
- public static final int EscherOleObject = 0xf11f;
- public static final int EscherUserDefined = 0xf122;
/**
* Returns name of the record by its type
@@ -218,10 +236,10 @@ public final class RecordTypes {
* @param type section of the record header
* @return name of the record
*/
- public static String recordName(int type) {
- String name = typeToName.get(Integer.valueOf(type));
- return (name == null) ? ("Unknown" + type) : name;
- }
+// public static String recordName(int type) {
+// String name = typeToName.get(Integer.valueOf(type));
+// return (name == null) ? ("Unknown" + type) : name;
+// }
/**
* Returns the class handling a record by its type.
@@ -232,38 +250,38 @@ public final class RecordTypes {
* @param type section of the record header
* @return class to handle the record, or null if an unknown (eg Escher) record
*/
- public static Class<? extends Record> recordHandlingClass(int type) {
- Class<? extends Record> c = typeToClass.get(Integer.valueOf(type));
- return c;
- }
-
- static {
- typeToName = new HashMap<Integer,String>();
- typeToClass = new HashMap<Integer,Class<? extends Record>>();
- try {
- Field[] f = RecordTypes.class.getFields();
- for (int i = 0; i < f.length; i++){
- Object val = f[i].get(null);
-
- // Escher record, only store ID -> Name
- if (val instanceof Integer) {
- typeToName.put((Integer)val, f[i].getName());
- }
- // PowerPoint record, store ID -> Name and ID -> Class
- if (val instanceof Type) {
- Type t = (Type)val;
- Class<? extends Record> c = t.handlingClass;
- Integer id = Integer.valueOf(t.typeID);
- if(c == null) { c = UnknownRecordPlaceholder.class; }
-
- typeToName.put(id, f[i].getName());
- typeToClass.put(id, c);
- }
- }
- } catch (IllegalAccessException e){
- throw new RuntimeException("Failed to initialize records types");
- }
- }
+// public static Class<? extends Record> recordHandlingClass(int type) {
+// Class<? extends Record> c = typeToClass.get(Integer.valueOf(type));
+// return c;
+// }
+//
+// static {
+// typeToName = new HashMap<Integer,String>();
+// typeToClass = new HashMap<Integer,Class<? extends Record>>();
+// try {
+// Field[] f = RecordTypes.class.getFields();
+// for (int i = 0; i < f.length; i++){
+// Object val = f[i].get(null);
+//
+// // Escher record, only store ID -> Name
+// if (val instanceof Integer) {
+// typeToName.put((Integer)val, f[i].getName());
+// }
+// // PowerPoint record, store ID -> Name and ID -> Class
+// if (val instanceof Type) {
+// Type t = (Type)val;
+// Class<? extends Record> c = t.handlingClass;
+// Integer id = Integer.valueOf(t.typeID);
+// if(c == null) { c = UnknownRecordPlaceholder.class; }
+//
+// typeToName.put(id, f[i].getName());
+// typeToClass.put(id, c);
+// }
+// }
+// } catch (IllegalAccessException e){
+// throw new RuntimeException("Failed to initialize records types");
+// }
+// }
/**
@@ -271,12 +289,12 @@ public final class RecordTypes {
* Contains both the type, and the handling class (if any), and
* offers methods to get either back out.
*/
- public static class Type {
- public final int typeID;
- public final Class<? extends Record> handlingClass;
- public Type(int typeID, Class<? extends Record> handlingClass) {
- this.typeID = typeID;
- this.handlingClass = handlingClass;
- }
- }
+// public static class Type {
+// public final int typeID;
+// public final Class<? extends Record> handlingClass;
+// public Type(int typeID, Class<? extends Record> handlingClass) {
+// this.typeID = typeID;
+// this.handlingClass = handlingClass;
+// }
+// }
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/RoundTripHFPlaceholder12.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/RoundTripHFPlaceholder12.java?rev=1722476&r1=1722475&r2=1722476&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/RoundTripHFPlaceholder12.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/RoundTripHFPlaceholder12.java Thu Dec 31 22:10:17 2015
@@ -20,6 +20,8 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
+import org.apache.poi.util.LittleEndian;
+
/**
* An atom record that specifies that a shape is a header or footer placeholder shape
*
@@ -41,6 +43,17 @@ public final class RoundTripHFPlaceholde
private byte _placeholderId;
/**
+ * Create a new instance of <code>RoundTripHFPlaceholder12</code>
+ */
+ public RoundTripHFPlaceholder12(){
+ _header = new byte[8];
+ LittleEndian.putUShort(_header, 0, 0);
+ LittleEndian.putUShort(_header, 2, (int)getRecordType());
+ LittleEndian.putInt(_header, 4, 8);
+ _placeholderId = 0;
+ }
+
+ /**
* Constructs the comment atom record from its source data.
*
* @param source the source data as a byte array.
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java?rev=1722476&r1=1722475&r2=1722476&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java Thu Dec 31 22:10:17 2015
@@ -171,7 +171,7 @@ public final class TxMasterStyleAtom ext
/**
* Updates the rawdata from the modified paragraph/character styles
*
- * @since 3.14-beta1
+ * @since POI 3.14-beta1
*/
public void updateStyles() {
int type = getTextType();
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFHyperlink.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFHyperlink.java?rev=1722476&r1=1722475&r2=1722476&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFHyperlink.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFHyperlink.java Thu Dec 31 22:10:17 2015
@@ -17,10 +17,18 @@
package org.apache.poi.hslf.usermodel;
-import java.util.*;
-
-import org.apache.poi.ddf.*;
-import org.apache.poi.hslf.record.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.ListIterator;
+
+import org.apache.poi.hslf.record.ExHyperlink;
+import org.apache.poi.hslf.record.ExObjList;
+import org.apache.poi.hslf.record.HSLFEscherClientDataRecord;
+import org.apache.poi.hslf.record.InteractiveInfo;
+import org.apache.poi.hslf.record.InteractiveInfoAtom;
+import org.apache.poi.hslf.record.Record;
+import org.apache.poi.hslf.record.TxInteractiveInfoAtom;
/**
* Represents a hyperlink in a PowerPoint document
@@ -156,6 +164,7 @@ public final class HSLFHyperlink {
* @param paragraphs List of <code>TextParagraph</code> to lookup hyperlinks
* @return found hyperlinks
*/
+ @SuppressWarnings("resource")
public static List<HSLFHyperlink> find(List<HSLFTextParagraph> paragraphs){
List<HSLFHyperlink> lst = new ArrayList<HSLFHyperlink>();
if (paragraphs == null || paragraphs.isEmpty()) return lst;
@@ -165,10 +174,10 @@ public final class HSLFHyperlink {
HSLFSlideShow ppt = firstPara.getSheet().getSlideShow();
//document-level container which stores info about all links in a presentation
ExObjList exobj = ppt.getDocumentRecord().getExObjList();
- if (exobj == null) return lst;
-
- Record[] records = firstPara.getRecords();
- find(records, exobj, lst);
+ if (exobj != null) {
+ Record[] records = firstPara.getRecords();
+ find(Arrays.asList(records), exobj, lst);
+ }
return lst;
}
@@ -179,39 +188,38 @@ public final class HSLFHyperlink {
* @param shape <code>Shape</code> to lookup hyperlink in
* @return found hyperlink or <code>null</code>
*/
+ @SuppressWarnings("resource")
public static HSLFHyperlink find(HSLFShape shape){
- List<HSLFHyperlink> lst = new ArrayList<HSLFHyperlink>();
HSLFSlideShow ppt = shape.getSheet().getSlideShow();
//document-level container which stores info about all links in a presentation
ExObjList exobj = ppt.getDocumentRecord().getExObjList();
- if (exobj == null) {
- return null;
- }
+ HSLFEscherClientDataRecord cldata = shape.getClientData(false);
- EscherContainerRecord spContainer = shape.getSpContainer();
- for (Iterator<EscherRecord> it = spContainer.getChildIterator(); it.hasNext(); ) {
- EscherRecord obj = it.next();
- if (obj.getRecordId() == EscherClientDataRecord.RECORD_ID){
- byte[] data = obj.serialize();
- Record[] records = Record.findChildRecords(data, 8, data.length-8);
- find(records, exobj, lst);
- }
+ if (exobj != null && cldata != null) {
+ List<HSLFHyperlink> lst = new ArrayList<HSLFHyperlink>();
+ find(cldata.getHSLFChildRecords(), exobj, lst);
+ return lst.isEmpty() ? null : (HSLFHyperlink)lst.get(0);
}
- return lst.size() == 1 ? (HSLFHyperlink)lst.get(0) : null;
+ return null;
}
- private static void find(Record[] records, ExObjList exobj, List<HSLFHyperlink> out){
- if (records == null) return;
- for (int i = 0; i < records.length; i++) {
- //see if we have InteractiveInfo in the textrun's records
- if(!(records[i] instanceof InteractiveInfo)) continue;
-
- InteractiveInfo hldr = (InteractiveInfo)records[i];
+ private static void find(List<? extends Record> records, ExObjList exobj, List<HSLFHyperlink> out){
+ ListIterator<? extends Record> iter = records.listIterator();
+ while (iter.hasNext()) {
+ Record r = iter.next();
+ // see if we have InteractiveInfo in the textrun's records
+ if (!(r instanceof InteractiveInfo)) {
+ continue;
+ }
+
+ InteractiveInfo hldr = (InteractiveInfo)r;
InteractiveInfoAtom info = hldr.getInteractiveInfoAtom();
int id = info.getHyperlinkID();
ExHyperlink linkRecord = exobj.get(id);
- if (linkRecord == null) continue;
+ if (linkRecord == null) {
+ continue;
+ }
HSLFHyperlink link = new HSLFHyperlink();
link.title = linkRecord.getLinkTitle();
@@ -219,8 +227,13 @@ public final class HSLFHyperlink {
link.type = info.getAction();
out.add(link);
- if (i+1 < records.length && records[i+1] instanceof TxInteractiveInfoAtom){
- TxInteractiveInfoAtom txinfo = (TxInteractiveInfoAtom)records[++i];
+ if (iter.hasNext()) {
+ r = iter.next();
+ if (!(r instanceof TxInteractiveInfoAtom)) {
+ iter.previous();
+ continue;
+ }
+ TxInteractiveInfoAtom txinfo = (TxInteractiveInfoAtom)r;
link.startIndex = txinfo.getStartIndex();
link.endIndex = txinfo.getEndIndex();
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPlaceholder.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPlaceholder.java?rev=1722476&r1=1722475&r2=1722476&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPlaceholder.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPlaceholder.java Thu Dec 31 22:10:17 2015
@@ -18,7 +18,7 @@
package org.apache.poi.hslf.usermodel;
import org.apache.poi.ddf.EscherContainerRecord;
-import org.apache.poi.sl.usermodel.SimpleShape.Placeholder;
+import org.apache.poi.sl.usermodel.Placeholder;
import org.apache.poi.sl.usermodel.ShapeContainer;
/**
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java?rev=1722476&r1=1722475&r2=1722476&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java Thu Dec 31 22:10:17 2015
@@ -21,6 +21,7 @@ import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.util.Iterator;
+import java.util.List;
import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherChildAnchorRecord;
@@ -33,7 +34,10 @@ import org.apache.poi.ddf.EscherProperty
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherSimpleProperty;
import org.apache.poi.ddf.EscherSpRecord;
+import org.apache.poi.ddf.EscherTextboxRecord;
import org.apache.poi.hslf.record.ColorSchemeAtom;
+import org.apache.poi.hslf.record.HSLFEscherClientDataRecord;
+import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.RecordTypes;
import org.apache.poi.sl.usermodel.FillStyle;
import org.apache.poi.sl.usermodel.Shape;
@@ -217,19 +221,32 @@ public abstract class HSLFShape implemen
public static <T extends EscherRecord> T getEscherChild(EscherContainerRecord owner, int recordId){
return owner.getChildById((short)recordId);
}
+
+ /**
+ * @since POI 3.14-Beta2
+ */
+ public static <T extends EscherRecord> T getEscherChild(EscherContainerRecord owner, RecordTypes recordId){
+ return getEscherChild(owner, recordId.typeID);
+ }
public <T extends EscherRecord> T getEscherChild(int recordId){
return _escherContainer.getChildById((short)recordId);
}
/**
+ * @since POI 3.14-Beta2
+ */
+ public <T extends EscherRecord> T getEscherChild(RecordTypes recordId){
+ return getEscherChild(recordId.typeID);
+ }
+
+ /**
* Returns escher property by id.
*
* @return escher property or <code>null</code> if not found.
*/
public static <T extends EscherProperty> T getEscherProperty(AbstractEscherOptRecord opt, int propId){
- if (opt == null) return null;
- return opt.lookup(propId);
+ return (opt == null) ? null : opt.<T>lookup(propId);
}
/**
@@ -443,7 +460,7 @@ public abstract class HSLFShape implemen
}
public AbstractEscherOptRecord getEscherOptRecord() {
- AbstractEscherOptRecord opt = getEscherChild(EscherOptRecord.RECORD_ID);
+ AbstractEscherOptRecord opt = getEscherChild(RecordTypes.EscherOPT);
if (opt == null) {
opt = getEscherChild(RecordTypes.EscherUserDefined);
}
@@ -485,4 +502,48 @@ public abstract class HSLFShape implemen
public boolean isPlaceholder() {
return false;
}
+
+ /**
+ * Find a record in the underlying EscherClientDataRecord
+ *
+ * @param recordType type of the record to search
+ */
+ @SuppressWarnings("unchecked")
+ public <T extends Record> T getClientDataRecord(int recordType) {
+
+ List<? extends Record> records = getClientRecords();
+ if (records != null) for (Record r : records) {
+ if (r.getRecordType() == recordType){
+ return (T)r;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Search for EscherClientDataRecord, if found, convert its contents into an array of HSLF records
+ *
+ * @return an array of HSLF records contained in the shape's EscherClientDataRecord or <code>null</code>
+ */
+ protected List<? extends Record> getClientRecords() {
+ HSLFEscherClientDataRecord clientData = getClientData(false);
+ return (clientData == null) ? null : clientData.getHSLFChildRecords();
+ }
+
+ /**
+ * Create a new HSLF-specific EscherClientDataRecord
+ *
+ * @param create if true, create the missing record
+ * @return the client record or null if it was missing and create wasn't activated
+ */
+ protected HSLFEscherClientDataRecord getClientData(boolean create) {
+ HSLFEscherClientDataRecord clientData = getEscherChild(HSLFEscherClientDataRecord.RECORD_ID);
+ if (clientData == null && create) {
+ clientData = new HSLFEscherClientDataRecord();
+ clientData.setOptions((short)15);
+ clientData.setRecordId(HSLFEscherClientDataRecord.RECORD_ID);
+ getSpContainer().addChildBefore(clientData, EscherTextboxRecord.RECORD_ID);
+ }
+ return clientData;
+ }
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java?rev=1722476&r1=1722475&r2=1722476&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java Thu Dec 31 22:10:17 2015
@@ -17,12 +17,27 @@
package org.apache.poi.hslf.usermodel;
-import java.util.Iterator;
import java.util.List;
-import org.apache.poi.ddf.*;
-import org.apache.poi.hslf.model.*;
-import org.apache.poi.hslf.record.*;
+import org.apache.poi.ddf.AbstractEscherOptRecord;
+import org.apache.poi.ddf.EscherClientDataRecord;
+import org.apache.poi.ddf.EscherContainerRecord;
+import org.apache.poi.ddf.EscherOptRecord;
+import org.apache.poi.ddf.EscherProperties;
+import org.apache.poi.ddf.EscherProperty;
+import org.apache.poi.ddf.EscherPropertyFactory;
+import org.apache.poi.ddf.EscherRecord;
+import org.apache.poi.ddf.EscherSimpleProperty;
+import org.apache.poi.ddf.EscherSpRecord;
+import org.apache.poi.ddf.EscherTextboxRecord;
+import org.apache.poi.hslf.model.MovieShape;
+import org.apache.poi.hslf.model.OLEShape;
+import org.apache.poi.hslf.record.ExObjRefAtom;
+import org.apache.poi.hslf.record.HSLFEscherClientDataRecord;
+import org.apache.poi.hslf.record.InteractiveInfo;
+import org.apache.poi.hslf.record.InteractiveInfoAtom;
+import org.apache.poi.hslf.record.Record;
+import org.apache.poi.hslf.record.RecordTypes;
import org.apache.poi.sl.usermodel.ShapeContainer;
import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.util.POILogFactory;
@@ -50,7 +65,7 @@ public final class HSLFShapeFactory {
public static HSLFGroupShape createShapeGroup(EscherContainerRecord spContainer, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
boolean isTable = false;
EscherContainerRecord ecr = (EscherContainerRecord)spContainer.getChild(0);
- EscherRecord opt = HSLFShape.getEscherChild(ecr, (short)RecordTypes.EscherUserDefined);
+ EscherRecord opt = HSLFShape.getEscherChild(ecr, RecordTypes.EscherUserDefined);
if (opt != null) {
EscherPropertyFactory f = new EscherPropertyFactory();
@@ -120,12 +135,10 @@ public final class HSLFShapeFactory {
}
}
- OEShapeAtom oes = getClientDataRecord(spContainer, RecordTypes.OEShapeAtom.typeID);
- if (oes != null){
- return new OLEShape(spContainer, parent);
- }
-
- return new HSLFPictureShape(spContainer, parent);
+ ExObjRefAtom oes = getClientDataRecord(spContainer, RecordTypes.ExObjRefAtom.typeID);
+ return (oes != null)
+ ? new OLEShape(spContainer, parent)
+ : new HSLFPictureShape(spContainer, parent);
}
private static HSLFShape createNonPrimitive(EscherContainerRecord spContainer, ShapeContainer<HSLFShape,HSLFTextParagraph> parent) {
@@ -141,15 +154,10 @@ public final class HSLFShapeFactory {
@SuppressWarnings("unchecked")
protected static <T extends Record> T getClientDataRecord(EscherContainerRecord spContainer, int recordType) {
- for (Iterator<EscherRecord> it = spContainer.getChildIterator(); it.hasNext();) {
- EscherRecord obj = it.next();
- if (obj.getRecordId() == EscherClientDataRecord.RECORD_ID) {
- byte[] data = obj.serialize();
- for (Record r : Record.findChildRecords(data, 8, data.length - 8)) {
- if (r.getRecordType() == recordType) {
- return (T)r;
- }
- }
+ HSLFEscherClientDataRecord cldata = spContainer.getChildById(EscherClientDataRecord.RECORD_ID);
+ if (cldata != null) for (Record r : cldata.getHSLFChildRecords()) {
+ if (r.getRecordType() == recordType) {
+ return (T)r;
}
}
return null;
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=1722476&r1=1722475&r2=1722476&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 Thu Dec 31 22:10:17 2015
@@ -149,7 +149,7 @@ public abstract class HSLFSheet implemen
public List<HSLFShape> getShapes() {
PPDrawing ppdrawing = getPPDrawing();
- EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
+ EscherContainerRecord dg = ppdrawing.getDgContainer();
EscherContainerRecord spgr = null;
for (Iterator<EscherRecord> it = dg.getChildIterator(); it.hasNext();) {
@@ -187,7 +187,7 @@ public abstract class HSLFSheet implemen
public void addShape(HSLFShape shape) {
PPDrawing ppdrawing = getPPDrawing();
- EscherContainerRecord dgContainer = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
+ EscherContainerRecord dgContainer = ppdrawing.getDgContainer();
EscherContainerRecord spgr = (EscherContainerRecord) HSLFShape.getEscherChild(dgContainer, EscherContainerRecord.SPGR_CONTAINER);
spgr.addChildRecord(shape.getSpContainer());
@@ -244,16 +244,8 @@ public abstract class HSLFSheet implemen
public boolean removeShape(HSLFShape shape) {
PPDrawing ppdrawing = getPPDrawing();
- EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
- EscherContainerRecord spgr = null;
-
- for (Iterator<EscherRecord> it = dg.getChildIterator(); it.hasNext();) {
- EscherRecord rec = it.next();
- if (rec.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) {
- spgr = (EscherContainerRecord) rec;
- break;
- }
- }
+ EscherContainerRecord dg = ppdrawing.getDgContainer();
+ EscherContainerRecord spgr = dg.getChildById(EscherContainerRecord.SPGR_CONTAINER);
if(spgr == null) {
return false;
}
@@ -292,7 +284,7 @@ public abstract class HSLFSheet implemen
if (_background == null) {
PPDrawing ppdrawing = getPPDrawing();
- EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
+ EscherContainerRecord dg = ppdrawing.getDgContainer();
EscherContainerRecord spContainer = dg.getChildById(EscherContainerRecord.SP_CONTAINER);
_background = new HSLFBackground(spContainer, null);
_background.setSheet(this);
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=1722476&r1=1722475&r2=1722476&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 Thu Dec 31 22:10:17 2015
@@ -18,16 +18,40 @@
package org.apache.poi.hslf.usermodel;
import java.awt.Color;
-import java.io.ByteArrayOutputStream;
+import java.util.List;
-import org.apache.poi.ddf.*;
+import org.apache.poi.ddf.AbstractEscherOptRecord;
+import org.apache.poi.ddf.EscherChildAnchorRecord;
+import org.apache.poi.ddf.EscherClientAnchorRecord;
+import org.apache.poi.ddf.EscherContainerRecord;
+import org.apache.poi.ddf.EscherOptRecord;
+import org.apache.poi.ddf.EscherProperties;
+import org.apache.poi.ddf.EscherProperty;
+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.*;
+import org.apache.poi.hslf.record.HSLFEscherClientDataRecord;
+import org.apache.poi.hslf.record.InteractiveInfo;
+import org.apache.poi.hslf.record.InteractiveInfoAtom;
+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.*;
-import org.apache.poi.sl.usermodel.*;
-import org.apache.poi.sl.usermodel.LineDecoration.*;
+import org.apache.poi.sl.draw.geom.CustomGeometry;
+import org.apache.poi.sl.draw.geom.Guide;
+import org.apache.poi.sl.draw.geom.PresetGeometries;
+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.PaintStyle;
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
+import org.apache.poi.sl.usermodel.Placeholder;
+import org.apache.poi.sl.usermodel.Shadow;
+import org.apache.poi.sl.usermodel.ShapeContainer;
+import org.apache.poi.sl.usermodel.ShapeType;
+import org.apache.poi.sl.usermodel.SimpleShape;
+import org.apache.poi.sl.usermodel.StrokeStyle;
import org.apache.poi.sl.usermodel.StrokeStyle.LineCap;
import org.apache.poi.sl.usermodel.StrokeStyle.LineCompound;
import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
@@ -46,12 +70,6 @@ public abstract class HSLFSimpleShape ex
public final static double DEFAULT_LINE_WIDTH = 0.75;
/**
- * Records stored in EscherClientDataRecord
- */
- protected Record[] _clientRecords;
- protected EscherClientDataRecord _clientData;
-
- /**
* Create a SimpleShape object and initialize it from the supplied Record container.
*
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
@@ -82,9 +100,10 @@ public abstract class HSLFSimpleShape ex
opt.setRecordId(EscherOptRecord.RECORD_ID);
_escherContainer.addChildRecord(opt);
- EscherRecord anchor;
- if(isChild) anchor = new EscherChildAnchorRecord();
- else {
+ EscherRecord anchor;
+ if(isChild) {
+ anchor = new EscherChildAnchorRecord();
+ } else {
anchor = new EscherClientAnchorRecord();
//hack. internal variable EscherClientAnchorRecord.shortRecord can be
@@ -251,70 +270,11 @@ public abstract class HSLFSimpleShape ex
getFill().setForegroundColor(color);
}
- /**
- * Find a record in the underlying EscherClientDataRecord
- *
- * @param recordType type of the record to search
- */
- @SuppressWarnings("unchecked")
- protected <T extends Record> T getClientDataRecord(int recordType) {
-
- Record[] records = getClientRecords();
- if(records != null) for (int i = 0; i < records.length; i++) {
- if(records[i].getRecordType() == recordType){
- return (T)records[i];
- }
- }
- return null;
- }
-
- /**
- * Search for EscherClientDataRecord, if found, convert its contents into an array of HSLF records
- *
- * @return an array of HSLF records contained in the shape's EscherClientDataRecord or <code>null</code>
- */
- protected Record[] getClientRecords() {
- if(_clientData == null){
- EscherRecord r = getEscherChild(EscherClientDataRecord.RECORD_ID);
- //ddf can return EscherContainerRecord with recordId=EscherClientDataRecord.RECORD_ID
- //convert in to EscherClientDataRecord on the fly
- if(r != null && !(r instanceof EscherClientDataRecord)){
- byte[] data = r.serialize();
- r = new EscherClientDataRecord();
- r.fillFields(data, 0, new HSLFEscherRecordFactory());
- }
- _clientData = (EscherClientDataRecord)r;
- }
- if(_clientData != null && _clientRecords == null){
- byte[] data = _clientData.getRemainingData();
- _clientRecords = Record.findChildRecords(data, 0, data.length);
- }
- return _clientRecords;
- }
-
- protected void updateClientData() {
- if(_clientData != null && _clientRecords != null){
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- try {
- for (int i = 0; i < _clientRecords.length; i++) {
- _clientRecords[i].writeOut(out);
- }
- } catch(Exception e){
- throw new HSLFException(e);
- }
- _clientData.setRemainingData(out.toByteArray());
- }
- }
-
public void setHyperlink(HSLFHyperlink link){
if(link.getId() == -1){
throw new HSLFException("You must call SlideShow.addHyperlink(Hyperlink link) first");
}
- EscherClientDataRecord cldata = new EscherClientDataRecord();
- cldata.setOptions((short)0xF);
- getSpContainer().addChildRecord(cldata); // TODO - junit to prove getChildRecords().add is wrong
-
InteractiveInfo info = new InteractiveInfo();
InteractiveInfoAtom infoAtom = info.getInteractiveInfoAtom();
@@ -356,14 +316,8 @@ public abstract class HSLFSimpleShape ex
infoAtom.setHyperlinkID(link.getId());
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- try {
- info.writeOut(out);
- } catch(Exception e){
- throw new HSLFException(e);
- }
- cldata.setRemainingData(out.toByteArray());
-
+ HSLFEscherClientDataRecord cldata = getClientData(true);
+ cldata.addChild(infoAtom);
}
public Guide getAdjustValue(String name) {
@@ -560,99 +514,119 @@ public abstract class HSLFSimpleShape ex
}
};
}
-
- protected void setPlaceholder(Placeholder placeholder) {
- EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
+
+ @Override
+ public Placeholder getPlaceholder() {
+ List<? extends Record> clRecords = getClientRecords();
+ if (clRecords == null) {
+ return null;
+ }
+ for (Record r : clRecords) {
+ if (r instanceof OEPlaceholderAtom) {
+ OEPlaceholderAtom oep = (OEPlaceholderAtom)r;
+ return Placeholder.lookupNative(oep.getPlaceholderId());
+ } else if (r instanceof RoundTripHFPlaceholder12) {
+ RoundTripHFPlaceholder12 rtp = (RoundTripHFPlaceholder12)r;
+ return Placeholder.lookupNative(rtp.getPlaceholderId());
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public void setPlaceholder(Placeholder placeholder) {
+ EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
int flags = spRecord.getFlags();
- flags |= EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HAVEMASTER;
- spRecord.setFlags(flags);
-
- EscherClientDataRecord cldata = _escherContainer.getChildById(EscherClientDataRecord.RECORD_ID);
- if (cldata == null) {
- cldata = new EscherClientDataRecord();
- // append placeholder container before EscherTextboxRecord
- _escherContainer.addChildBefore(cldata, EscherTextboxRecord.RECORD_ID);
+ if (placeholder == null) {
+ flags ^= EscherSpRecord.FLAG_HAVEMASTER;
+ } else {
+ flags |= EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HAVEMASTER;
}
- cldata.setOptions((short)15);
-
- AbstractEscherOptRecord opt = getEscherOptRecord();
+ spRecord.setFlags(flags);
// Placeholders can't be grouped
- setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 262144);
+ 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 = new OEPlaceholderAtom();
+ 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;
+ }
+ }
/**
- * Extarct from MSDN:
+ * 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.
*/
- oep.setPlacementId(-1);
-
- boolean isMaster = (getSheet() instanceof HSLFSlideMaster);
- boolean isNotes = (getSheet() instanceof HSLFNotes);
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 TITLE:
- phId = (isMaster) ? OEPlaceholderAtom.MasterTitle : OEPlaceholderAtom.Title;
- break;
- case BODY:
- phId = (isMaster) ? OEPlaceholderAtom.MasterBody :
- ((isNotes) ? OEPlaceholderAtom.NotesBody : OEPlaceholderAtom.Body);
- break;
- case CENTERED_TITLE:
- phId = (isMaster) ? OEPlaceholderAtom.MasterCenteredTitle : OEPlaceholderAtom.CenteredTitle;
- break;
- case SUBTITLE:
- phId = (isMaster) ? OEPlaceholderAtom.MasterSubTitle : OEPlaceholderAtom.Subtitle;
- break;
- case DATETIME:
- phId = OEPlaceholderAtom.MasterDate;
- break;
- case SLIDE_NUMBER:
- phId = OEPlaceholderAtom.MasterSlideNumber;
- break;
- case FOOTER:
- phId = OEPlaceholderAtom.MasterFooter;
- break;
case HEADER:
- phId = OEPlaceholderAtom.MasterHeader;
- break;
- case DGM:
- case CHART:
- phId = OEPlaceholderAtom.Graph;
- break;
- case TABLE:
- phId = OEPlaceholderAtom.Table;
- break;
- case PICTURE:
- case CLIP_ART:
- phId = OEPlaceholderAtom.ClipArt;
- break;
- case MEDIA:
- phId = OEPlaceholderAtom.MediaClip;
- break;
- case SLIDE_IMAGE:
- phId = (isMaster) ? OEPlaceholderAtom.MasterNotesSlideImage : OEPlaceholderAtom.NotesSlideImage;
+ case FOOTER:
+ if (rtp == null) {
+ rtp = new RoundTripHFPlaceholder12();
+ rtp.setPlaceholderId(phId);
+ clientData.addChild(rtp);
+ }
+ if (oep != null) {
+ clientData.removeChild(OEPlaceholderAtom.class);
+ }
break;
default:
- case CONTENT:
- phId = OEPlaceholderAtom.Object;
+ 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;
}
- oep.setPlaceholderId(phId);
-
- //convert hslf into ddf record
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- try {
- oep.writeOut(out);
- } catch(Exception e){
- throw new HSLFException(e);
- }
- cldata.setRemainingData(out.toByteArray());
}
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=1722476&r1=1722475&r2=1722476&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 Thu Dec 31 22:10:17 2015
@@ -42,8 +42,8 @@ import org.apache.poi.hslf.record.TextHe
import org.apache.poi.sl.draw.DrawFactory;
import org.apache.poi.sl.draw.Drawable;
import org.apache.poi.sl.usermodel.Notes;
+import org.apache.poi.sl.usermodel.Placeholder;
import org.apache.poi.sl.usermodel.ShapeType;
-import org.apache.poi.sl.usermodel.SimpleShape.Placeholder;
import org.apache.poi.sl.usermodel.Slide;
/**
@@ -163,7 +163,7 @@ public final class HSLFSlide extends HSL
public void onCreate(){
//initialize drawing group id
EscherDggRecord dgg = getSlideShow().getDocumentRecord().getPPDrawingGroup().getEscherDggRecord();
- EscherContainerRecord dgContainer = (EscherContainerRecord)getSheetContainer().getPPDrawing().getEscherRecords()[0];
+ EscherContainerRecord dgContainer = getSheetContainer().getPPDrawing().getDgContainer();
EscherDgRecord dg = (EscherDgRecord) HSLFShape.getEscherChild(dgContainer, EscherDgRecord.RECORD_ID);
int dgId = dgg.getMaxDrawingGroupId() + 1;
dg.setOptions((short)(dgId << 4));
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=1722476&r1=1722475&r2=1722476&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 Thu Dec 31 22:10:17 2015
@@ -1162,8 +1162,8 @@ public final class HSLFSlideShow impleme
// For position dependent records, hold where they were and now are
// As we go along, update, and hand over, to any Position Dependent
// records we happen across
- Map<RecordTypes.Type,PositionDependentRecord> interestingRecords =
- new HashMap<RecordTypes.Type,PositionDependentRecord>();
+ Map<RecordTypes,PositionDependentRecord> interestingRecords =
+ new HashMap<RecordTypes,PositionDependentRecord>();
try {
_hslfSlideShow.updateAndWriteDependantRecords(null,interestingRecords);
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java?rev=1722476&r1=1722475&r2=1722476&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java Thu Dec 31 22:10:17 2015
@@ -474,7 +474,7 @@ public final class HSLFSlideShowImpl ext
* May be null, if not needed.
* @throws IOException
*/
- public void updateAndWriteDependantRecords(OutputStream os, Map<RecordTypes.Type,PositionDependentRecord> interestingRecords)
+ public void updateAndWriteDependantRecords(OutputStream os, Map<RecordTypes,PositionDependentRecord> interestingRecords)
throws IOException {
// For position dependent records, hold where they were and now are
// As we go along, update, and hand over, to any Position Dependent
@@ -502,7 +502,7 @@ public final class HSLFSlideShowImpl ext
// Grab interesting records as they come past
// this will only save the very last record of each type
- RecordTypes.Type saveme = null;
+ RecordTypes saveme = null;
int recordType = (int)record.getRecordType();
if (recordType == RecordTypes.PersistPtrIncrementalBlock.typeID) {
saveme = RecordTypes.PersistPtrIncrementalBlock;
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java?rev=1722476&r1=1722475&r2=1722476&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java Thu Dec 31 22:10:17 2015
@@ -95,14 +95,14 @@ implements HSLFShapeContainer, TableShap
EscherContainerRecord spCont = (EscherContainerRecord) getSpContainer().getChild(0);
AbstractEscherOptRecord opt = new EscherOptRecord();
- opt.setRecordId((short)RecordTypes.EscherUserDefined);
+ opt.setRecordId(RecordTypes.EscherUserDefined.typeID);
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__TABLEPROPERTIES, 1));
EscherArrayProperty p = new EscherArrayProperty((short)(0x4000 | EscherProperties.GROUPSHAPE__TABLEROWPROPERTIES), false, null);
p.setSizeOfElements(0x0004);
p.setNumberOfElementsInArray(numRows);
p.setNumberOfElementsInMemory(numRows);
opt.addEscherProperty(p);
- spCont.addChildBefore(opt, RecordTypes.EscherClientAnchor);
+ spCont.addChildBefore(opt, RecordTypes.EscherClientAnchor.typeID);
}
/**
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java?rev=1722476&r1=1722475&r2=1722476&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java Thu Dec 31 22:10:17 2015
@@ -157,7 +157,7 @@ public final class HSLFTextParagraph imp
*
* @param paragraphStyle the master style reference
*
- * @since 3.14-Beta1
+ * @since POI 3.14-Beta1
*/
@Internal
/* package */ void setMasterStyleReference(TextPropCollection paragraphStyle) {
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java?rev=1722476&r1=1722475&r2=1722476&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java Thu Dec 31 22:10:17 2015
@@ -76,7 +76,7 @@ public final class HSLFTextRun implement
*
* @param characterStyle the master style reference
*
- * @since 3.14-Beta1
+ * @since POI 3.14-Beta1
*/
@Internal
/* package */ void setMasterStyleReference(TextPropCollection characterStyle) {
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=1722476&r1=1722475&r2=1722476&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 Thu Dec 31 22:10:17 2015
@@ -45,6 +45,7 @@ import org.apache.poi.hslf.record.TxInte
import org.apache.poi.sl.draw.DrawFactory;
import org.apache.poi.sl.draw.DrawTextShape;
import org.apache.poi.sl.usermodel.Insets2D;
+import org.apache.poi.sl.usermodel.Placeholder;
import org.apache.poi.sl.usermodel.ShapeContainer;
import org.apache.poi.sl.usermodel.TextShape;
import org.apache.poi.sl.usermodel.VerticalAlignment;
@@ -603,15 +604,30 @@ implements TextShape<HSLFShape,HSLFTextP
}
/**
- * Return <code>OEPlaceholderAtom</code>, the atom that describes a placeholder.
+ * Return {@link OEPlaceholderAtom}, the atom that describes a placeholder.
*
- * @return <code>OEPlaceholderAtom</code> or <code>null</code> if not found
+ * @return {@link OEPlaceholderAtom} or {@code null} if not found
*/
public OEPlaceholderAtom getPlaceholderAtom(){
return getClientDataRecord(OEPlaceholderAtom.typeID);
}
/**
+ * Return {@link RoundTripHFPlaceholder12}, the atom that describes a header/footer placeholder.
+ * Compare the {@link RoundTripHFPlaceholder12#getPlaceholderId()} with
+ * {@link OEPlaceholderAtom#MasterHeader} or {@link OEPlaceholderAtom#MasterFooter}, to find out
+ * what kind of placeholder this is.
+ *
+ * @return {@link RoundTripHFPlaceholder12} or {@code null} if not found
+ *
+ * @since POI 3.14-Beta2
+ */
+ public RoundTripHFPlaceholder12 getHFPlaceholderAtom() {
+ // special case for files saved in Office 2007
+ return getClientDataRecord(RoundTripHFPlaceholder12.typeID);
+ }
+
+ /**
*
* Assigns a hyperlink to this text shape
*
@@ -644,7 +660,7 @@ implements TextShape<HSLFShape,HSLFTextP
if (oep != null) return true;
//special case for files saved in Office 2007
- RoundTripHFPlaceholder12 hldr = getClientDataRecord(RoundTripHFPlaceholder12.typeID);
+ RoundTripHFPlaceholder12 hldr = getHFPlaceholderAtom();
if (hldr != null) return true;
return false;
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java?rev=1722476&r1=1722475&r2=1722476&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java Thu Dec 31 22:10:17 2015
@@ -17,18 +17,22 @@
package org.apache.poi.hslf;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.FileNotFoundException;
-
-import junit.framework.TestCase;
+import java.io.IOException;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests that HSLFSlideShow writes the powerpoint bit of data back out
@@ -36,7 +40,7 @@ import org.apache.poi.poifs.filesystem.P
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public final class TestReWrite extends TestCase {
+public final class TestReWrite {
// HSLFSlideShow primed on the test data
private HSLFSlideShowImpl hssA;
private HSLFSlideShowImpl hssB;
@@ -46,7 +50,8 @@ public final class TestReWrite extends T
private POIFSFileSystem pfsB;
private POIFSFileSystem pfsC;
- public void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
@@ -60,10 +65,12 @@ public final class TestReWrite extends T
hssC = new HSLFSlideShowImpl(pfsC);
}
+ @Test
public void testWritesOutTheSame() throws Exception {
assertWritesOutTheSame(hssA, pfsA);
assertWritesOutTheSame(hssB, pfsB);
}
+
public void assertWritesOutTheSame(HSLFSlideShowImpl hss, POIFSFileSystem pfs) throws Exception {
// Write out to a byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -85,13 +92,15 @@ public final class TestReWrite extends T
byte[] _nData = new byte[nProps.getSize()];
pfs.createDocumentInputStream("PowerPoint Document").read(_oData);
npfs.createDocumentInputStream("PowerPoint Document").read(_nData);
- for(int i=0; i<_oData.length; i++) {
+ for(int i=0; i<_oData.length; i++) {
//System.out.println(i + "\t" + Integer.toHexString(i));
assertEquals(_oData[i], _nData[i]);
}
+ npfs.close();
}
- public void testWithMacroStreams() throws Exception {
+ @Test
+ public void testWithMacroStreams() throws IOException {
// Check that they're apparently the same
assertSlideShowWritesOutTheSame(hssC, pfsC);
@@ -101,28 +110,25 @@ public final class TestReWrite extends T
// Write out normally, will loose the macro stream
ByteArrayOutputStream baos = new ByteArrayOutputStream();
hssC.write(baos);
- POIFSFileSystem pfsNew = new POIFSFileSystem(
- new ByteArrayInputStream(baos.toByteArray()) );
-
- try {
- pfsNew.getRoot().getEntry("Macros");
- fail();
- } catch(FileNotFoundException e) {
- // Good, as expected
- }
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ POIFSFileSystem pfsNew = new POIFSFileSystem(bais);
+ assertFalse(pfsNew.getRoot().hasEntry("Macros"));
+ pfsNew.close();
// But if we write out with nodes preserved, will be there
- baos = new ByteArrayOutputStream();
+ baos.reset();
hssC.write(baos, true);
- pfsNew = new POIFSFileSystem(
- new ByteArrayInputStream(baos.toByteArray()) );
- assertNotNull( pfsNew.getRoot().getEntry("Macros") );
+ bais = new ByteArrayInputStream(baos.toByteArray());
+ pfsNew = new POIFSFileSystem(bais);
+ assertTrue( pfsNew.getRoot().hasEntry("Macros") );
+ pfsNew.close();
}
/**
* Ensure that simply opening a slideshow (usermodel) view of it
* doesn't change things
*/
+ @Test
public void testSlideShowWritesOutTheSame() throws Exception {
assertSlideShowWritesOutTheSame(hssA, pfsA);
@@ -130,9 +136,11 @@ public final class TestReWrite extends T
// We need to identify and fix that first
//assertSlideShowWritesOutTheSame(hssB, pfsB);
}
- public void assertSlideShowWritesOutTheSame(HSLFSlideShowImpl hss, POIFSFileSystem pfs) throws Exception {
+
+ public void assertSlideShowWritesOutTheSame(HSLFSlideShowImpl hss, POIFSFileSystem pfs) throws IOException {
// Create a slideshow covering it
- HSLFSlideShow ss = new HSLFSlideShow(hss);
+ @SuppressWarnings("resource")
+ HSLFSlideShow ss = new HSLFSlideShow(hss);
ss.getSlides();
ss.getNotes();
@@ -161,17 +169,23 @@ public final class TestReWrite extends T
System.out.println(i + "\t" + Integer.toHexString(i));
assertEquals(_oData[i], _nData[i]);
}
+ npfs.close();
}
- public void test48593() throws Exception {
- HSLFSlideShow slideShow = new HSLFSlideShow();
- slideShow.createSlide();
- slideShow = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
- slideShow.createSlide();
- slideShow = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
- slideShow.createSlide();
- slideShow = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
- slideShow.createSlide();
- slideShow = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
+ @Test
+ public void test48593() throws IOException {
+ HSLFSlideShow ppt1 = new HSLFSlideShow();
+ ppt1.createSlide();
+ HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
+ ppt2.createSlide();
+ HSLFSlideShow ppt3 = HSLFTestDataSamples.writeOutAndReadBack(ppt2);
+ ppt3.createSlide();
+ HSLFSlideShow ppt4 = HSLFTestDataSamples.writeOutAndReadBack(ppt3);
+ ppt4.createSlide();
+ HSLFTestDataSamples.writeOutAndReadBack(ppt4).close();
+ ppt4.close();
+ ppt3.close();
+ ppt2.close();
+ ppt1.close();
}
}
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=1722476&r1=1722475&r2=1722476&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 Thu Dec 31 22:10:17 2015
@@ -18,40 +18,44 @@
package org.apache.poi.hslf.record;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
/**
* Tests that RecordTypes returns the right records and classes when asked
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
-public final class TestRecordTypes extends TestCase {
+public final class TestRecordTypes {
+ @Test
public void testPPTNameLookups() {
- assertEquals("MainMaster", RecordTypes.recordName(1016));
- assertEquals("TextBytesAtom", RecordTypes.recordName(4008));
- assertEquals("VBAInfo", RecordTypes.recordName(1023));
+ assertEquals("MainMaster", RecordTypes.MainMaster.name());
+ assertEquals("TextBytesAtom", RecordTypes.TextBytesAtom.name());
+ assertEquals("VBAInfo", RecordTypes.VBAInfo.name());
}
+ @Test
public void testEscherNameLookups() {
- assertEquals("EscherDggContainer", RecordTypes.recordName(0xf000));
- assertEquals("EscherClientTextbox", RecordTypes.recordName(0xf00d));
- assertEquals("EscherSelection", RecordTypes.recordName(0xf119));
+ assertEquals("EscherDggContainer", RecordTypes.EscherDggContainer.name());
+ assertEquals("EscherClientTextbox", RecordTypes.EscherClientTextbox.name());
+ assertEquals("EscherSelection", RecordTypes.EscherSelection.name());
}
+ @Test
public void testPPTClassLookups() {
- assertEquals(Slide.class, RecordTypes.recordHandlingClass(1006));
- assertEquals(TextCharsAtom.class, RecordTypes.recordHandlingClass(4000));
- assertEquals(TextBytesAtom.class, RecordTypes.recordHandlingClass(4008));
- assertEquals(SlideListWithText.class, RecordTypes.recordHandlingClass(4080));
+ 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.recordHandlingClass(2019));
+ assertEquals(UnknownRecordPlaceholder.class, RecordTypes.forTypeID(-10).handlingClass);
}
- public void testEscherClassLookups() {
+ @Test
+ public void testEscherClassLookups() {
// Should all come back with null, as DDF handles them
- assertEquals(null, RecordTypes.recordHandlingClass(0xf000));
- assertEquals(null, RecordTypes.recordHandlingClass(0xf001));
+ assertEquals(null, RecordTypes.EscherDggContainer.handlingClass);
+ assertEquals(null, RecordTypes.EscherBStoreContainer.handlingClass);
}
}
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java?rev=1722476&r1=1722475&r2=1722476&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java Thu Dec 31 22:10:17 2015
@@ -20,6 +20,7 @@ package org.apache.poi.hslf.usermodel;
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 java.awt.Color;
@@ -42,7 +43,9 @@ import org.apache.poi.hslf.exceptions.Ol
import org.apache.poi.hslf.extractor.PowerPointExtractor;
import org.apache.poi.hslf.model.HeadersFooters;
import org.apache.poi.hslf.record.Document;
+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.hslf.record.SlideListWithText;
import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
import org.apache.poi.hslf.record.TextHeaderAtom;
@@ -50,6 +53,7 @@ import org.apache.poi.sl.draw.DrawPaint;
import org.apache.poi.sl.usermodel.PaintStyle;
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
import org.apache.poi.sl.usermodel.PictureData.PictureType;
+import org.apache.poi.sl.usermodel.Placeholder;
import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.sl.usermodel.SlideShowFactory;
@@ -777,6 +781,31 @@ public final class TestBugs {
ex.close();
}
+ @Test
+ public void bug58159() throws IOException {
+ File sample = HSLFTestDataSamples.getSampleFile("bug58159_headers-and-footers.ppt");
+ HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(sample);
+ HeadersFooters hf = ppt.getSlideHeadersFooters();
+ assertNull(hf.getHeaderText());
+ assertEquals("Slide footer", hf.getFooterText());
+ hf = ppt.getNotesHeadersFooters();
+ assertEquals("Notes header", hf.getHeaderText());
+ assertEquals("Notes footer", hf.getFooterText());
+ HSLFSlide sl = ppt.getSlides().get(0);
+ hf = sl.getHeadersFooters();
+ assertNull(hf.getHeaderText());
+ assertEquals("Slide footer", hf.getFooterText());
+ for (HSLFShape shape : sl.getShapes()) {
+ if (shape instanceof HSLFTextShape) {
+ HSLFTextShape ts = (HSLFTextShape)shape;
+ Placeholder ph = ts.getPlaceholder();
+ if (Placeholder.FOOTER == ph) {
+ assertEquals("Slide footer", ts.getText());
+ }
+ }
+ }
+ ppt.close();
+ }
private static HSLFSlideShow open(String fileName) throws IOException {
File sample = HSLFTestDataSamples.getSampleFile(fileName);
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNumberedList.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNumberedList.java?rev=1722476&r1=1722475&r2=1722476&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNumberedList.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNumberedList.java Thu Dec 31 22:10:17 2015
@@ -42,12 +42,11 @@ public final class TestNumberedList {
@Test
public void testNumberedList() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("numbers.ppt"));
- assertTrue("No Exceptions while reading file", true);
-
final List<HSLFSlide> slides = ppt.getSlides();
assertEquals(2, slides.size());
checkSlide0(slides.get(0));
checkSlide1(slides.get(1));
+ ppt.close();
}
private void checkSlide0(final HSLFSlide s) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org