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 SlideListWithText entries.
25: * Having found them, it sees if they have any text, and prints out
26: * what it finds.
27: */
28: public class SLWTTextListing {
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 the documents, and then their SLWT
38: Record[] records = ss.getRecords();
39: for (int i = 0; i < records.length; i++) {
40: if (records[i] instanceof Document) {
41: Record docRecord = records[i];
42: Record[] docChildren = docRecord.getChildRecords();
43: for (int j = 0; j < docChildren.length; j++) {
44: if (docChildren[j] instanceof SlideListWithText) {
45: System.out.println("Found SLWT at pos " + j
46: + " in the Document at " + i);
47: System.out
48: .println(" Has "
49: + docChildren[j]
50: .getChildRecords().length
51: + " children");
52:
53: // Grab the SlideAtomSet's, which contain
54: // a SlidePersistAtom and then a bunch of text
55: // + related records
56: SlideListWithText slwt = (SlideListWithText) docChildren[j];
57: SlideListWithText.SlideAtomsSet[] this Sets = slwt
58: .getSlideAtomsSets();
59: System.out.println(" Has " + this Sets.length
60: + " AtomSets in it");
61:
62: // Loop over the sets, showing what they contain
63: for (int k = 0; k < this Sets.length; k++) {
64: SlidePersistAtom spa = this Sets[k]
65: .getSlidePersistAtom();
66: System.out.println(" " + k
67: + " has slide id "
68: + spa.getSlideIdentifier());
69: System.out.println(" " + k
70: + " has ref id " + spa.getRefID());
71:
72: // Loop over the records, printing the text
73: Record[] slwtc = this Sets[k]
74: .getSlideRecords();
75: for (int l = 0; l < slwtc.length; l++) {
76: String text = null;
77: if (slwtc[l] instanceof TextBytesAtom) {
78: TextBytesAtom tba = (TextBytesAtom) slwtc[l];
79: text = tba.getText();
80: }
81: if (slwtc[l] instanceof TextCharsAtom) {
82: TextCharsAtom tca = (TextCharsAtom) slwtc[l];
83: text = tca.getText();
84: }
85:
86: if (text != null) {
87: text = text.replace('\r', '\n');
88: System.out.println(" ''"
89: + text + "''");
90: }
91: }
92: }
93: }
94: }
95: }
96: }
97: }
98: }
|