001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hslf.dev;
019:
020: import org.apache.poi.hslf.HSLFSlideShow;
021: import org.apache.poi.hslf.record.Document;
022: import org.apache.poi.hslf.record.Record;
023: import org.apache.poi.hslf.record.RecordTypes;
024: import org.apache.poi.hslf.record.SlideListWithText;
025:
026: /**
027: * Uses record level code to Documents.
028: * Having found them, it sees if they have any SlideListWithTexts,
029: * and reports how many, and what sorts of things they contain
030: */
031: public class SLWTListing {
032: public static void main(String[] args) throws Exception {
033: if (args.length < 1) {
034: System.err.println("Need to give a filename");
035: System.exit(1);
036: }
037:
038: HSLFSlideShow ss = new HSLFSlideShow(args[0]);
039:
040: // Find the documents, and then their SLWT
041: Record[] records = ss.getRecords();
042: for (int i = 0; i < records.length; i++) {
043: if (records[i] instanceof Document) {
044: Document doc = (Document) records[i];
045: SlideListWithText[] slwts = doc.getSlideListWithTexts();
046:
047: System.out.println("Document at " + i + " had "
048: + slwts.length + " SlideListWithTexts");
049: if (slwts.length == 0) {
050: System.err
051: .println("** Warning: Should have had at least 1! **");
052: }
053: if (slwts.length > 3) {
054: System.err
055: .println("** Warning: Shouldn't have more than 3!");
056: }
057:
058: // Check the SLWTs contain what we'd expect
059: for (int j = 0; j < slwts.length; j++) {
060: SlideListWithText slwt = slwts[j];
061: Record[] children = slwt.getChildRecords();
062:
063: System.out.println(" - SLWT at " + j + " had "
064: + children.length + " children:");
065:
066: // Should only have SlideAtomSets if the second one
067: int numSAS = slwt.getSlideAtomsSets().length;
068: if (j == 1) {
069: if (numSAS == 0) {
070: System.err
071: .println(" ** 2nd SLWT didn't have any SlideAtomSets!");
072: } else {
073: System.out.println(" - Contains " + numSAS
074: + " SlideAtomSets");
075: }
076: } else {
077: if (numSAS > 0) {
078: System.err.println(" ** SLWT " + j
079: + " had " + numSAS
080: + " SlideAtomSets! (expected 0)");
081: }
082: }
083:
084: // Report the first 5 children, to give a flavour
085: int upTo = 5;
086: if (children.length < 5) {
087: upTo = children.length;
088: }
089: for (int k = 0; k < upTo; k++) {
090: Record r = children[k];
091: int typeID = (int) r.getRecordType();
092: String typeName = RecordTypes
093: .recordName(typeID);
094: System.out.println(" - " + typeID + " ("
095: + typeName + ")");
096: }
097: }
098: }
099: }
100: }
101: }
|