View | Details | Raw Unified | Return to bug 59302
Collapse All | Expand All

(-)src/scratchpad/src/org/apache/poi/hslf/record/DocInfoListContainer.java (+84 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.hslf.record;
19
20
import java.io.IOException;
21
import java.io.OutputStream;
22
23
import org.apache.poi.util.LittleEndian;
24
25
/**
26
 * A container record that specifies information about the document and document display settings.
27
 */
28
public final class DocInfoListContainer extends RecordContainer {
29
	private byte[] _header;
30
	private static long _type = RecordTypes.List.typeID;
31
32
	// Links to our more interesting children
33
34
	/**
35
	 * Set things up, and find our more interesting children
36
	 */
37
	protected DocInfoListContainer(byte[] source, int start, int len) {
38
		// Grab the header
39
		_header = new byte[8];
40
		System.arraycopy(source,start,_header,0,8);
41
42
		// Find our children
43
		_children = Record.findChildRecords(source,start+8,len-8);
44
		findInterestingChildren();
45
	}
46
47
	/**
48
	 * Go through our child records, picking out the ones that are
49
	 *  interesting, and saving those for use by the easy helper
50
	 *  methods.
51
	 */
52
	private void findInterestingChildren() {
53
54
	}
55
56
	/**
57
	 * Create a new DocInfoListContainer, with blank fields - not yet supported
58
	 */
59
	private DocInfoListContainer() {
60
		_header = new byte[8];
61
		_children = new Record[0];
62
63
		// Setup our header block
64
		_header[0] = 0x0f; // We are a container record
65
		LittleEndian.putShort(_header, 2, (short)_type);
66
67
		// Setup our child records
68
		findInterestingChildren();
69
	}
70
71
	/**
72
	 * We are of type 0x7D0
73
	 */
74
	public long getRecordType() { return _type; }
75
76
	/**
77
	 * Write the contents of the record back, so it can be written
78
	 *  to disk
79
	 */
80
	public void writeOut(OutputStream out) throws IOException {
81
		writeOut(_header[0],_header[1],_type,_children,out);
82
	}
83
84
}
(-)src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjStg.java (+9 lines)
Lines 144-149 Link Here
144
    }
144
    }
145
145
146
    /**
146
    /**
147
     * Gets the record instance from the header
148
     *
149
     * @return record instance
150
     */
151
    public int getRecordInstance() {
152
        return (LittleEndian.getUShort(_header, 0) >>> 4);
153
    }
154
    
155
    /**
147
     * Write the contents of the record back, so it can be written
156
     * Write the contents of the record back, so it can be written
148
     * to disk.
157
     * to disk.
149
     *
158
     *
(-)src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java (-3 / +3 lines)
Lines 47-54 Link Here
47
    ViewInfo(1020,null),
47
    ViewInfo(1020,null),
48
    ViewInfoAtom(1021,null),
48
    ViewInfoAtom(1021,null),
49
    SlideViewInfoAtom(1022,null),
49
    SlideViewInfoAtom(1022,null),
50
    VBAInfo(1023,null),
50
    VBAInfo(1023,VBAInfoContainer.class),
51
    VBAInfoAtom(1024,null),
51
    VBAInfoAtom(1024,VBAInfoAtom.class),
52
    SSDocInfoAtom(1025,null),
52
    SSDocInfoAtom(1025,null),
53
    Summary(1026,null),
53
    Summary(1026,null),
54
    DocRoutingSlip(1030,null),
54
    DocRoutingSlip(1030,null),
Lines 63-69 Link Here
63
    NamedShowSlides(1042,null),
63
    NamedShowSlides(1042,null),
64
    SheetProperties(1044,null),
64
    SheetProperties(1044,null),
65
    RoundTripCustomTableStyles12Atom(1064,null),
65
    RoundTripCustomTableStyles12Atom(1064,null),
66
    List(2000,null),
66
    List(2000,DocInfoListContainer.class),
67
    FontCollection(2005,FontCollection.class),
67
    FontCollection(2005,FontCollection.class),
68
    BookmarkCollection(2019,null),
68
    BookmarkCollection(2019,null),
69
    SoundCollection(2020,SoundCollection.class),
69
    SoundCollection(2020,SoundCollection.class),
(-)src/scratchpad/src/org/apache/poi/hslf/record/VBAInfoAtom.java (+117 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.hslf.record;
19
20
import java.io.IOException;
21
import java.io.OutputStream;
22
23
import org.apache.poi.util.LittleEndian;
24
25
/**
26
 * An atom record that specifies a reference to the VBA project storage.
27
 */
28
public final class VBAInfoAtom extends RecordAtom {
29
    private static final long _type = RecordTypes.VBAInfoAtom.typeID;
30
    
31
    /**
32
     * Record header.
33
     */
34
    private byte[] _header;
35
36
    /**
37
     * Record data.
38
     */
39
    private long persistIdRef;
40
    private boolean hasMacros;
41
    private long version;
42
43
    /**
44
     * Constructs an empty atom - not yet supported 
45
     */
46
    private VBAInfoAtom() {
47
        _header = new byte[8];
48
        // TODO: fix me
49
        LittleEndian.putUInt(_header, 0, _type);
50
        persistIdRef = 0;
51
        hasMacros = true;
52
        version = 2;
53
    }
54
    
55
    /**
56
     * Constructs the vba atom record from its source data.
57
     *
58
     * @param source the source data as a byte array.
59
     * @param start the start offset into the byte array.
60
     * @param len the length of the slice in the byte array.
61
     */
62
    public VBAInfoAtom(byte[] source, int start, int len) {
63
        // Get the header.
64
        _header = new byte[8];
65
        System.arraycopy(source,start,_header,0,8);
66
67
        // Get the record data.
68
        persistIdRef = LittleEndian.getUInt(source, start+8);
69
        hasMacros = (LittleEndian.getUInt(source, start+16) == 1);
70
        version = LittleEndian.getUInt(source, start+24);
71
    }
72
    /**
73
     * Gets the record type.
74
     * @return the record type.
75
     */
76
    public long getRecordType() { return _type; }
77
78
    /**
79
     * Write the contents of the record back, so it can be written
80
     * to disk
81
     *
82
     * @param out the output stream to write to.
83
     * @throws java.io.IOException if an error occurs.
84
     */
85
    public void writeOut(OutputStream out) throws IOException {
86
        out.write(_header);
87
        LittleEndian.putUInt(persistIdRef, out);
88
        LittleEndian.putUInt(hasMacros ? 1 : 0, out);
89
        LittleEndian.putUInt(version, out);
90
    }
91
92
    public long getPersistIdRef() {
93
        return persistIdRef;
94
    }
95
96
    public void setPersistIdRef(long persistIdRef) {
97
        this.persistIdRef = persistIdRef;
98
    }
99
100
    public boolean isHasMacros() {
101
        return hasMacros;
102
    }
103
104
    public void setHasMacros(boolean hasMacros) {
105
        this.hasMacros = hasMacros;
106
    }
107
108
    public long getVersion() {
109
        return version;
110
    }
111
112
    public void setVersion(long version) {
113
        this.version = version;
114
    }
115
116
    
117
}
(-)src/scratchpad/src/org/apache/poi/hslf/record/VBAInfoContainer.java (+84 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.hslf.record;
19
20
import java.io.IOException;
21
import java.io.OutputStream;
22
23
import org.apache.poi.util.LittleEndian;
24
25
/**
26
 * A container record that specifies VBA information for the document.
27
 */
28
public final class VBAInfoContainer extends RecordContainer {
29
	private byte[] _header;
30
	private static long _type = RecordTypes.VBAInfo.typeID;
31
32
	// Links to our more interesting children
33
34
	/**
35
	 * Set things up, and find our more interesting children
36
	 */
37
	protected VBAInfoContainer(byte[] source, int start, int len) {
38
		// Grab the header
39
		_header = new byte[8];
40
		System.arraycopy(source,start,_header,0,8);
41
42
		// Find our children
43
		_children = Record.findChildRecords(source,start+8,len-8);
44
		findInterestingChildren();
45
	}
46
47
	/**
48
	 * Go through our child records, picking out the ones that are
49
	 *  interesting, and saving those for use by the easy helper
50
	 *  methods.
51
	 */
52
	private void findInterestingChildren() {
53
54
	}
55
56
	/**
57
	 * Create a new VBAInfoContainer, with blank fields - not yet supported
58
	 */
59
	private VBAInfoContainer() {
60
		_header = new byte[8];
61
		_children = new Record[0];
62
63
		// Setup our header block
64
		_header[0] = 0x0f; // We are a container record
65
		LittleEndian.putShort(_header, 2, (short)_type);
66
67
		// Setup our child records
68
		findInterestingChildren();
69
	}
70
71
	/**
72
	 * We are of type 0x3FF
73
	 */
74
	public long getRecordType() { return _type; }
75
76
	/**
77
	 * Write the contents of the record back, so it can be written
78
	 *  to disk
79
	 */
80
	public void writeOut(OutputStream out) throws IOException {
81
		writeOut(_header[0],_header[1],_type,_children,out);
82
	}
83
84
}
(-)src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java (+35 lines)
Lines 29-36 Link Here
29
import java.awt.geom.Path2D;
29
import java.awt.geom.Path2D;
30
import java.awt.geom.Rectangle2D;
30
import java.awt.geom.Rectangle2D;
31
import java.awt.image.BufferedImage;
31
import java.awt.image.BufferedImage;
32
import java.io.ByteArrayInputStream;
32
import java.io.File;
33
import java.io.File;
33
import java.io.IOException;
34
import java.io.IOException;
35
import java.io.InputStream;
34
import java.io.OutputStream;
36
import java.io.OutputStream;
35
import java.io.PrintStream;
37
import java.io.PrintStream;
36
import java.text.AttributedCharacterIterator;
38
import java.text.AttributedCharacterIterator;
Lines 51-62 Link Here
51
import org.apache.poi.hslf.exceptions.OldPowerPointFormatException;
53
import org.apache.poi.hslf.exceptions.OldPowerPointFormatException;
52
import org.apache.poi.hslf.extractor.PowerPointExtractor;
54
import org.apache.poi.hslf.extractor.PowerPointExtractor;
53
import org.apache.poi.hslf.model.HeadersFooters;
55
import org.apache.poi.hslf.model.HeadersFooters;
56
import org.apache.poi.hslf.record.DocInfoListContainer;
54
import org.apache.poi.hslf.record.Document;
57
import org.apache.poi.hslf.record.Document;
58
import org.apache.poi.hslf.record.ExOleObjStg;
55
import org.apache.poi.hslf.record.Record;
59
import org.apache.poi.hslf.record.Record;
60
import org.apache.poi.hslf.record.RecordTypes;
56
import org.apache.poi.hslf.record.SlideListWithText;
61
import org.apache.poi.hslf.record.SlideListWithText;
57
import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
62
import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
58
import org.apache.poi.hslf.record.TextHeaderAtom;
63
import org.apache.poi.hslf.record.TextHeaderAtom;
64
import org.apache.poi.hslf.record.VBAInfoAtom;
65
import org.apache.poi.hslf.record.VBAInfoContainer;
59
import org.apache.poi.hssf.usermodel.DummyGraphics2d;
66
import org.apache.poi.hssf.usermodel.DummyGraphics2d;
67
import org.apache.poi.poifs.macros.VBAMacroReader;
60
import org.apache.poi.sl.draw.DrawFactory;
68
import org.apache.poi.sl.draw.DrawFactory;
61
import org.apache.poi.sl.draw.DrawPaint;
69
import org.apache.poi.sl.draw.DrawPaint;
62
import org.apache.poi.sl.draw.DrawTextParagraph;
70
import org.apache.poi.sl.draw.DrawTextParagraph;
Lines 72-77 Link Here
72
import org.apache.poi.sl.usermodel.TextParagraph;
80
import org.apache.poi.sl.usermodel.TextParagraph;
73
import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
81
import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
74
import org.apache.poi.sl.usermodel.TextRun;
82
import org.apache.poi.sl.usermodel.TextRun;
83
import org.apache.poi.util.IOUtils;
75
import org.apache.poi.util.LittleEndian;
84
import org.apache.poi.util.LittleEndian;
76
import org.apache.poi.util.StringUtil;
85
import org.apache.poi.util.StringUtil;
77
import org.apache.poi.util.Units;
86
import org.apache.poi.util.Units;
Lines 948-951 Link Here
948
        
957
        
949
        ppt2.close();
958
        ppt2.close();
950
    }
959
    }
960
961
    @Test
962
    public void macrotest() throws IOException {
963
        HSLFSlideShow ppt = open("SimpleMacro.ppt");
964
        DocInfoListContainer list = (DocInfoListContainer)ppt.getDocumentRecord().findFirstOfType(RecordTypes.List.typeID);
965
        VBAInfoContainer vbaInfo = (VBAInfoContainer)list.findFirstOfType(RecordTypes.VBAInfo.typeID);
966
        VBAInfoAtom vbaAtom = (VBAInfoAtom)vbaInfo.findFirstOfType(RecordTypes.VBAInfoAtom.typeID);
967
        long persistId = vbaAtom.getPersistIdRef();
968
        byte data[] = null;
969
        
970
        for (HSLFObjectData obj : ppt.getEmbeddedObjects()) {
971
            ExOleObjStg exObj = obj.getExOleObjStg();
972
            if (exObj.getPersistId() == persistId) {
973
                // compression is handled by exoleobjstg
974
                InputStream rawData = exObj.getData();
975
                data = IOUtils.toByteArray(rawData);
976
                rawData.close();
977
                break;
978
            }
979
        };
980
        
981
        VBAMacroReader vbareader = new VBAMacroReader(new ByteArrayInputStream(data));
982
        Map<String,String> bla = vbareader.readMacros();
983
        ppt.close();
984
    }
985
951
}
986
}

Return to bug 59302