Author: nick Date: Thu Dec 14 03:50:54 2006 New Revision: 487182 URL: http://svn.apache.org/viewvc?view=rev&rev=487182 Log: Try to work with files that don't have a master SlideListWithText, but go straight into a Slides one. Throw a better exception on slides with a mixed first SlideListWithText (see bug 41176 for more details)
Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java?view=diff&rev=487182&r1=487181&r2=487182 ============================================================================== --- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java (original) +++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java Thu Dec 14 03:50:54 2006 @@ -304,22 +304,58 @@ // we have to go and find their matching records // We always use the latest versions of these records, and use the // SlideAtom/NotesAtom to match them with the StyleAtomSet + // + // Some crazy documents don't have a master SlideListWithText, their + // first one is the slide containing one, which makes things fun... SlideListWithText masterSLWT = _documentRecord.getMasterSlideListWithText(); SlideListWithText slidesSLWT = _documentRecord.getSlideSlideListWithText(); SlideListWithText notesSLWT = _documentRecord.getNotesSlideListWithText(); - //find master slides + // Find master slides + // Need to ensure they're really master slides, and we're not dealing + // with a crazy document that doesn't have any master slides SlideAtomsSet[] masterSets = new SlideAtomsSet[0]; org.apache.poi.hslf.record.MainMaster[] masterRecords = null; if (masterSLWT != null){ - masterSets = masterSLWT.getSlideAtomsSets(); - masterRecords = new org.apache.poi.hslf.record.MainMaster[masterSets.length]; - for(int i=0; i<masterRecords.length; i++) { - masterRecords[i] = (org.apache.poi.hslf.record.MainMaster)getCoreRecordForSAS(masterSets[i]); - } + + // Are they Slides, Master Slides, or some broken mix? + int slideCount = 0; + int masterCount = 0; + for(int i=0; i<masterSets.length; i++) { + Record r = getCoreRecordForSAS(masterSets[i]); + if(r instanceof org.apache.poi.hslf.record.Slide) { + slideCount++; + } else if(r instanceof org.apache.poi.hslf.record.MainMaster) { + masterCount++; + } else { + throw new CorruptPowerPointFileException("The PowerPoint file had a broken first SlideListWithTexts. This should only contain either MainMasters, or Slides, but it contained a record of type " + r.getRecordType()); + } + } + + if(slideCount > 0 && masterCount == 0) { + // Actually the Slide SlideListWithTexts + notesSLWT = slidesSLWT; + slidesSLWT = masterSLWT; + masterSLWT = null; + } else if(masterCount >= 0 && slideCount == 0) { + // Is a normal, proper Masters SlideListWithTexts + masterRecords = new org.apache.poi.hslf.record.MainMaster[masterSets.length]; + + // Grab the Main Master records + for(int i=0; i<masterRecords.length; i++) { + masterRecords[i] = (org.apache.poi.hslf.record.MainMaster)getCoreRecordForSAS(masterSets[i]); + } + } else { + // Contains both Slides and Main Masters, is corrupt + throw new CorruptPowerPointFileException("The PowerPoint file had a broken first SlideListWithTexts. This should only contain either MainMasters, or Slides, but it contained a mix of both (" + slideCount + " slides and " + masterCount + " masters)"); + } } + + + // Having sorted out the masters, that leaves the notes and slides + // Start by finding the notes records to go with the entries in // notesSLWT --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] Mailing List: http://jakarta.apache.org/site/mail2.html#poi The Apache Jakarta POI Project: http://jakarta.apache.org/poi/