mirror of https://github.com/apache/poi.git
Basic XSLF support for slide notes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1165105 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4b125e7ccd
commit
a727217e9e
|
@ -16,33 +16,7 @@
|
|||
==================================================================== */
|
||||
package org.apache.poi.xslf.usermodel;
|
||||
|
||||
import org.apache.poi.POIXMLDocument;
|
||||
import org.apache.poi.POIXMLDocumentPart;
|
||||
import org.apache.poi.POIXMLException;
|
||||
import org.apache.poi.xslf.XSLFSlideShow;
|
||||
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||
import org.apache.poi.openxml4j.opc.PackagePartName;
|
||||
import org.apache.poi.openxml4j.opc.TargetMode;
|
||||
import org.apache.poi.sl.usermodel.Slide;
|
||||
import org.apache.poi.sl.usermodel.SlideShow;
|
||||
import org.apache.poi.util.Beta;
|
||||
import org.apache.poi.util.Internal;
|
||||
import org.apache.poi.util.POILogFactory;
|
||||
import org.apache.poi.util.POILogger;
|
||||
import org.apache.poi.util.PackageHelper;
|
||||
import org.apache.poi.util.Units;
|
||||
import org.apache.xmlbeans.XmlException;
|
||||
import org.apache.xmlbeans.XmlOptions;
|
||||
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdList;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideSize;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.Dimension;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
@ -53,6 +27,30 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.poi.POIXMLDocument;
|
||||
import org.apache.poi.POIXMLDocumentPart;
|
||||
import org.apache.poi.POIXMLException;
|
||||
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||
import org.apache.poi.openxml4j.opc.PackagePartName;
|
||||
import org.apache.poi.openxml4j.opc.TargetMode;
|
||||
import org.apache.poi.util.Beta;
|
||||
import org.apache.poi.util.Internal;
|
||||
import org.apache.poi.util.POILogFactory;
|
||||
import org.apache.poi.util.POILogger;
|
||||
import org.apache.poi.util.PackageHelper;
|
||||
import org.apache.poi.util.Units;
|
||||
import org.apache.poi.xslf.XSLFSlideShow;
|
||||
import org.apache.xmlbeans.XmlException;
|
||||
import org.apache.xmlbeans.XmlOptions;
|
||||
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdList;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideSize;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument;
|
||||
|
||||
/**
|
||||
* High level representation of a ooxml slideshow.
|
||||
* This is the first object most users will construct whether
|
||||
|
@ -61,12 +59,12 @@ import java.util.regex.Pattern;
|
|||
*/
|
||||
@Beta
|
||||
public class XMLSlideShow extends POIXMLDocument {
|
||||
|
||||
private static POILogger _logger = POILogFactory.getLogger(XMLSlideShow.class);
|
||||
|
||||
private CTPresentation _presentation;
|
||||
private List<XSLFSlide> _slides;
|
||||
private Map<String, XSLFSlideMaster> _masters;
|
||||
private XSLFNotesMaster _notesMaster;
|
||||
protected List<XSLFPictureData> _pictures;
|
||||
|
||||
public XMLSlideShow() {
|
||||
|
@ -122,9 +120,11 @@ public class XMLSlideShow extends POIXMLDocument {
|
|||
for (POIXMLDocumentPart p : getRelations()) {
|
||||
if (p instanceof XSLFSlide) {
|
||||
shIdMap.put(p.getPackageRelationship().getId(), (XSLFSlide) p);
|
||||
} else if (p instanceof XSLFSlideMaster){
|
||||
} else if (p instanceof XSLFSlideMaster) {
|
||||
XSLFSlideMaster master = (XSLFSlideMaster)p;
|
||||
_masters.put(p.getPackageRelationship().getId(), master);
|
||||
} else if (p instanceof XSLFNotesMaster) {
|
||||
_notesMaster = (XSLFNotesMaster)p;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,6 +218,10 @@ public class XMLSlideShow extends POIXMLDocument {
|
|||
_slides.add(slide);
|
||||
return slide;
|
||||
}
|
||||
|
||||
public XSLFNotesMaster getNotesMaster() {
|
||||
return _notesMaster;
|
||||
}
|
||||
|
||||
public XSLFSlideMaster[] getSlideMasters() {
|
||||
return _masters.values().toArray(new XSLFSlideMaster[_masters.size()]);
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
package org.apache.poi.xslf.usermodel;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
||||
import org.apache.poi.util.Beta;
|
||||
import org.apache.xmlbeans.XmlException;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTCommonSlideData;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.NotesDocument;
|
||||
|
||||
@Beta
|
||||
public final class XSLFNotes extends XSLFSheet {
|
||||
private CTNotesSlide _notes;
|
||||
|
||||
/**
|
||||
* Create a new slide
|
||||
*/
|
||||
XSLFNotes() {
|
||||
super();
|
||||
_notes = prototype();
|
||||
setCommonSlideData(_notes.getCSld());
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a SpreadsheetML drawing from a package part
|
||||
*
|
||||
* @param part the package part holding the drawing data,
|
||||
* the content type must be <code>application/vnd.openxmlformats-officedocument.drawing+xml</code>
|
||||
* @param rel the package relationship holding this drawing,
|
||||
* the relationship type must be http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing
|
||||
*/
|
||||
XSLFNotes(PackagePart part, PackageRelationship rel) throws IOException, XmlException {
|
||||
super(part, rel);
|
||||
|
||||
NotesDocument doc =
|
||||
NotesDocument.Factory.parse(getPackagePart().getInputStream());
|
||||
_notes = doc.getNotes();
|
||||
setCommonSlideData(_notes.getCSld());
|
||||
}
|
||||
|
||||
|
||||
private static CTNotesSlide prototype(){
|
||||
CTNotesSlide ctNotes = CTNotesSlide.Factory.newInstance();
|
||||
CTCommonSlideData cSld = ctNotes.addNewCSld();
|
||||
|
||||
// TODO What else is needed for a mininum notes?
|
||||
|
||||
return ctNotes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CTNotesSlide getXmlObject() {
|
||||
return _notes;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRootElementName(){
|
||||
return "notes";
|
||||
}
|
||||
}
|
|
@ -73,7 +73,8 @@ public class XSLFRelation extends POIXMLRelation {
|
|||
public static final XSLFRelation NOTES = new XSLFRelation(
|
||||
"application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide",
|
||||
null, null
|
||||
"/ppt/notesSlides/notesSlide#.xml",
|
||||
XSLFNotes.class
|
||||
);
|
||||
|
||||
public static final XSLFRelation SLIDE = new XSLFRelation(
|
||||
|
|
|
@ -16,14 +16,12 @@
|
|||
==================================================================== */
|
||||
package org.apache.poi.xslf.usermodel;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.poi.POIXMLDocumentPart;
|
||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
||||
import org.apache.poi.openxml4j.opc.PackagePartName;
|
||||
import org.apache.poi.openxml4j.opc.TargetMode;
|
||||
import org.apache.poi.sl.usermodel.Slide;
|
||||
import org.apache.poi.util.Beta;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.apache.xmlbeans.XmlException;
|
||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTGroupShapeProperties;
|
||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D;
|
||||
|
@ -35,18 +33,12 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape;
|
|||
import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShapeNonVisual;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlide;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.SldDocument;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideLayoutIdListEntry;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Beta
|
||||
public final class XSLFSlide extends XSLFSheet {
|
||||
private final CTSlide _slide;
|
||||
private XSLFSlideLayout _layout;
|
||||
private final CTSlide _slide;
|
||||
private XSLFSlideLayout _layout;
|
||||
private XSLFNotes _notes;
|
||||
|
||||
/**
|
||||
* Create a new slide
|
||||
|
@ -54,6 +46,7 @@ public final class XSLFSlide extends XSLFSheet {
|
|||
XSLFSlide() {
|
||||
super();
|
||||
_slide = prototype();
|
||||
setCommonSlideData(_slide.getCSld());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -131,6 +124,22 @@ public final class XSLFSlide extends XSLFSheet {
|
|||
}
|
||||
return _layout;
|
||||
}
|
||||
|
||||
public XSLFNotes getNotes() {
|
||||
if(_notes == null) {
|
||||
for (POIXMLDocumentPart p : getRelations()) {
|
||||
if (p instanceof XSLFNotes){
|
||||
_notes = (XSLFNotes)p;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(_notes == null) {
|
||||
// This slide lacks notes
|
||||
// Not al have them, sorry...
|
||||
return null;
|
||||
}
|
||||
return _notes;
|
||||
}
|
||||
|
||||
public void setFollowMasterBackground(boolean value){
|
||||
_slide.setShowMasterSp(value);
|
||||
|
|
|
@ -83,12 +83,11 @@ public class TestXMLSlideShow extends TestCase {
|
|||
|
||||
// Now get those objects
|
||||
assertNotNull(xml.getSlides()[0]);
|
||||
assertNotNull(xml.getSlides()[0]);
|
||||
assertNotNull(xml.getSlides()[1]);
|
||||
|
||||
// And check they have notes as expected
|
||||
// TODO
|
||||
// assertNotNull(xml.getNotes(slides[0]));
|
||||
// assertNotNull(xml.getNotes(slides[1]));
|
||||
assertNotNull(xml.getSlides()[0].getNotes());
|
||||
assertNotNull(xml.getSlides()[1].getNotes());
|
||||
|
||||
// Next up look for the slide master
|
||||
CTSlideMasterIdListEntry[] masters = new CTSlideMasterIdListEntry[
|
||||
|
@ -103,8 +102,9 @@ public class TestXMLSlideShow extends TestCase {
|
|||
CTNotesMasterIdListEntry notesMaster =
|
||||
xml.getCTPresentation().getNotesMasterIdLst().getNotesMasterId();
|
||||
assertNotNull(notesMaster);
|
||||
// TODO Get the wrapper
|
||||
}
|
||||
|
||||
assertNotNull(xml.getNotesMaster());
|
||||
}
|
||||
|
||||
public void testMetadataBasics() throws Exception {
|
||||
XMLSlideShow xml = new XMLSlideShow(pack);
|
||||
|
|
Loading…
Reference in New Issue