unfinished release guide. It would be nice to have a html version.
[poi.git] / src / scratchpad / ooxml-src / org / apache / poi / hslf / HSLFXML.java
blob568cb80aa05e2c242f343549cf03744325ab462f
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
9 http://www.apache.org/licenses/LICENSE-2.0
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 package org.apache.poi.hslf;
19 import java.io.IOException;
21 import org.apache.poi.hxf.HXFDocument;
22 import org.apache.xmlbeans.XmlException;
23 import org.openxml4j.exceptions.InvalidFormatException;
24 import org.openxml4j.exceptions.OpenXML4JException;
25 import org.openxml4j.opc.Package;
26 import org.openxml4j.opc.PackagePart;
27 import org.openxml4j.opc.PackageRelationshipCollection;
28 import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide;
29 import org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation;
30 import org.openxmlformats.schemas.presentationml.x2006.main.CTSlide;
31 import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdList;
32 import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
33 import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMaster;
34 import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdList;
35 import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
36 import org.openxmlformats.schemas.presentationml.x2006.main.NotesDocument;
37 import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument;
38 import org.openxmlformats.schemas.presentationml.x2006.main.SldDocument;
39 import org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument;
41 /**
42 * Experimental class to do low level processing
43 * of pptx files.
45 * If you are using these low level classes, then you
46 * will almost certainly need to refer to the OOXML
47 * specifications from
48 * http://www.ecma-international.org/publications/standards/Ecma-376.htm
50 * WARNING - APIs expected to change rapidly
52 public class HSLFXML extends HXFDocument {
53 public static final String MAIN_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml";
54 public static final String NOTES_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml";
55 public static final String SLIDE_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.slide+xml";
56 public static final String SLIDE_LAYOUT_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout";
57 public static final String NOTES_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide";
59 private PresentationDocument presentationDoc;
61 public HSLFXML(Package container) throws OpenXML4JException, IOException, XmlException {
62 super(container, MAIN_CONTENT_TYPE);
64 presentationDoc =
65 PresentationDocument.Factory.parse(basePart.getInputStream());
68 /**
69 * Returns the low level presentation base object
71 public CTPresentation getPresentation() {
72 return presentationDoc.getPresentation();
75 /**
76 * Returns the references from the presentation to its
77 * slides.
78 * You'll need these to figure out the slide ordering,
79 * and to get at the actual slides themselves
81 public CTSlideIdList getSlideReferences() {
82 return getPresentation().getSldIdLst();
84 /**
85 * Returns the references from the presentation to its
86 * slide masters.
87 * You'll need these to get at the actual slide
88 * masters themselves
90 public CTSlideMasterIdList getSlideMasterReferences() {
91 return getPresentation().getSldMasterIdLst();
94 /**
95 * Returns the low level slide master object from
96 * the supplied slide master reference
98 public CTSlideMaster getSlideMaster(CTSlideMasterIdListEntry master) throws IOException, XmlException {
99 PackagePart masterPart =
100 getRelatedPackagePart(master.getId2());
101 SldMasterDocument masterDoc =
102 SldMasterDocument.Factory.parse(masterPart.getInputStream());
103 return masterDoc.getSldMaster();
107 * Returns the low level slide object from
108 * the supplied slide reference
110 public CTSlide getSlide(CTSlideIdListEntry slide) throws IOException, XmlException {
111 PackagePart slidePart =
112 getRelatedPackagePart(slide.getId2());
113 SldDocument slideDoc =
114 SldDocument.Factory.parse(slidePart.getInputStream());
115 return slideDoc.getSld();
119 * Returns the low level notes object for the given
120 * slide, as found from the supplied slide reference
122 public CTNotesSlide getNotes(CTSlideIdListEntry slide) throws IOException, XmlException {
123 PackagePart slidePart =
124 getRelatedPackagePart(slide.getId2());
126 PackageRelationshipCollection notes;
127 try {
128 notes = slidePart.getRelationshipsByType(NOTES_RELATION_TYPE);
129 } catch(InvalidFormatException e) {
130 throw new IllegalStateException(e);
133 if(notes.size() == 0) {
134 // No notes for this slide
135 return null;
137 if(notes.size() > 1) {
138 throw new IllegalStateException("Expecting 0 or 1 notes for a slide, but found " + notes.size());
141 PackagePart notesPart =
142 getPackagePart(notes.getRelationship(0));
143 NotesDocument notesDoc =
144 NotesDocument.Factory.parse(notesPart.getInputStream());
146 return notesDoc.getNotes();