01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: 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.dev;
19:
20: import org.apache.poi.hslf.*;
21: import org.apache.poi.hslf.record.*;
22:
23: /**
24: * Uses record level code to locate PPDrawing entries.
25: * Having found them, it sees if they have DDF Textbox records, and if so,
26: * searches those for text. Prints out any text it finds
27: */
28: public class PPDrawingTextListing {
29: public static void main(String[] args) throws Exception {
30: if (args.length < 1) {
31: System.err.println("Need to give a filename");
32: System.exit(1);
33: }
34:
35: HSLFSlideShow ss = new HSLFSlideShow(args[0]);
36:
37: // Find PPDrawings at any second level position
38: Record[] records = ss.getRecords();
39: for (int i = 0; i < records.length; i++) {
40: Record[] children = records[i].getChildRecords();
41: if (children != null && children.length != 0) {
42: for (int j = 0; j < children.length; j++) {
43: if (children[j] instanceof PPDrawing) {
44: System.out.println("Found PPDrawing at " + j
45: + " in top level record " + i + " ("
46: + records[i].getRecordType() + ")");
47:
48: // Look for EscherTextboxWrapper's
49: PPDrawing ppd = (PPDrawing) children[j];
50: EscherTextboxWrapper[] wrappers = ppd
51: .getTextboxWrappers();
52: System.out.println(" Has " + wrappers.length
53: + " textbox wrappers within");
54:
55: // Loop over the wrappers, showing what they contain
56: for (int k = 0; k < wrappers.length; k++) {
57: EscherTextboxWrapper tbw = wrappers[k];
58: System.out.println(" " + k + " has "
59: + tbw.getChildRecords().length
60: + " PPT atoms within");
61:
62: // Loop over the records, printing the text
63: Record[] pptatoms = tbw.getChildRecords();
64: for (int l = 0; l < pptatoms.length; l++) {
65: String text = null;
66: if (pptatoms[l] instanceof TextBytesAtom) {
67: TextBytesAtom tba = (TextBytesAtom) pptatoms[l];
68: text = tba.getText();
69: }
70: if (pptatoms[l] instanceof TextCharsAtom) {
71: TextCharsAtom tca = (TextCharsAtom) pptatoms[l];
72: text = tca.getText();
73: }
74:
75: if (text != null) {
76: text = text.replace('\r', '\n');
77: System.out.println(" ''"
78: + text + "''");
79: }
80: }
81: }
82: }
83: }
84: }
85: }
86: }
87: }
|