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
407ec57e37
commit
a972aa482a
@ -16,33 +16,7 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import org.apache.poi.POIXMLDocument;
|
import java.awt.Dimension;
|
||||||
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.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@ -53,6 +27,30 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Pattern;
|
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.
|
* High level representation of a ooxml slideshow.
|
||||||
* This is the first object most users will construct whether
|
* This is the first object most users will construct whether
|
||||||
@ -61,12 +59,12 @@ import java.util.regex.Pattern;
|
|||||||
*/
|
*/
|
||||||
@Beta
|
@Beta
|
||||||
public class XMLSlideShow extends POIXMLDocument {
|
public class XMLSlideShow extends POIXMLDocument {
|
||||||
|
|
||||||
private static POILogger _logger = POILogFactory.getLogger(XMLSlideShow.class);
|
private static POILogger _logger = POILogFactory.getLogger(XMLSlideShow.class);
|
||||||
|
|
||||||
private CTPresentation _presentation;
|
private CTPresentation _presentation;
|
||||||
private List<XSLFSlide> _slides;
|
private List<XSLFSlide> _slides;
|
||||||
private Map<String, XSLFSlideMaster> _masters;
|
private Map<String, XSLFSlideMaster> _masters;
|
||||||
|
private XSLFNotesMaster _notesMaster;
|
||||||
protected List<XSLFPictureData> _pictures;
|
protected List<XSLFPictureData> _pictures;
|
||||||
|
|
||||||
public XMLSlideShow() {
|
public XMLSlideShow() {
|
||||||
@ -125,6 +123,8 @@ public class XMLSlideShow extends POIXMLDocument {
|
|||||||
} else if (p instanceof XSLFSlideMaster) {
|
} else if (p instanceof XSLFSlideMaster) {
|
||||||
XSLFSlideMaster master = (XSLFSlideMaster)p;
|
XSLFSlideMaster master = (XSLFSlideMaster)p;
|
||||||
_masters.put(p.getPackageRelationship().getId(), master);
|
_masters.put(p.getPackageRelationship().getId(), master);
|
||||||
|
} else if (p instanceof XSLFNotesMaster) {
|
||||||
|
_notesMaster = (XSLFNotesMaster)p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,6 +219,10 @@ public class XMLSlideShow extends POIXMLDocument {
|
|||||||
return slide;
|
return slide;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public XSLFNotesMaster getNotesMaster() {
|
||||||
|
return _notesMaster;
|
||||||
|
}
|
||||||
|
|
||||||
public XSLFSlideMaster[] getSlideMasters() {
|
public XSLFSlideMaster[] getSlideMasters() {
|
||||||
return _masters.values().toArray(new XSLFSlideMaster[_masters.size()]);
|
return _masters.values().toArray(new XSLFSlideMaster[_masters.size()]);
|
||||||
}
|
}
|
||||||
|
78
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java
Normal file
78
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java
Normal file
@ -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(
|
public static final XSLFRelation NOTES = new XSLFRelation(
|
||||||
"application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml",
|
"application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide",
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide",
|
||||||
null, null
|
"/ppt/notesSlides/notesSlide#.xml",
|
||||||
|
XSLFNotes.class
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final XSLFRelation SLIDE = new XSLFRelation(
|
public static final XSLFRelation SLIDE = new XSLFRelation(
|
||||||
|
@ -16,14 +16,12 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.poi.POIXMLDocumentPart;
|
import org.apache.poi.POIXMLDocumentPart;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
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.Beta;
|
||||||
import org.apache.poi.util.IOUtils;
|
|
||||||
import org.apache.xmlbeans.XmlException;
|
import org.apache.xmlbeans.XmlException;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTGroupShapeProperties;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTGroupShapeProperties;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D;
|
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.CTGroupShapeNonVisual;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlide;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlide;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.SldDocument;
|
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
|
@Beta
|
||||||
public final class XSLFSlide extends XSLFSheet {
|
public final class XSLFSlide extends XSLFSheet {
|
||||||
private final CTSlide _slide;
|
private final CTSlide _slide;
|
||||||
private XSLFSlideLayout _layout;
|
private XSLFSlideLayout _layout;
|
||||||
|
private XSLFNotes _notes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new slide
|
* Create a new slide
|
||||||
@ -54,6 +46,7 @@ public final class XSLFSlide extends XSLFSheet {
|
|||||||
XSLFSlide() {
|
XSLFSlide() {
|
||||||
super();
|
super();
|
||||||
_slide = prototype();
|
_slide = prototype();
|
||||||
|
setCommonSlideData(_slide.getCSld());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -132,6 +125,22 @@ public final class XSLFSlide extends XSLFSheet {
|
|||||||
return _layout;
|
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){
|
public void setFollowMasterBackground(boolean value){
|
||||||
_slide.setShowMasterSp(value);
|
_slide.setShowMasterSp(value);
|
||||||
}
|
}
|
||||||
|
@ -83,12 +83,11 @@ public class TestXMLSlideShow extends TestCase {
|
|||||||
|
|
||||||
// Now get those objects
|
// Now get those objects
|
||||||
assertNotNull(xml.getSlides()[0]);
|
assertNotNull(xml.getSlides()[0]);
|
||||||
assertNotNull(xml.getSlides()[0]);
|
assertNotNull(xml.getSlides()[1]);
|
||||||
|
|
||||||
// And check they have notes as expected
|
// And check they have notes as expected
|
||||||
// TODO
|
assertNotNull(xml.getSlides()[0].getNotes());
|
||||||
// assertNotNull(xml.getNotes(slides[0]));
|
assertNotNull(xml.getSlides()[1].getNotes());
|
||||||
// assertNotNull(xml.getNotes(slides[1]));
|
|
||||||
|
|
||||||
// Next up look for the slide master
|
// Next up look for the slide master
|
||||||
CTSlideMasterIdListEntry[] masters = new CTSlideMasterIdListEntry[
|
CTSlideMasterIdListEntry[] masters = new CTSlideMasterIdListEntry[
|
||||||
@ -103,7 +102,8 @@ public class TestXMLSlideShow extends TestCase {
|
|||||||
CTNotesMasterIdListEntry notesMaster =
|
CTNotesMasterIdListEntry notesMaster =
|
||||||
xml.getCTPresentation().getNotesMasterIdLst().getNotesMasterId();
|
xml.getCTPresentation().getNotesMasterIdLst().getNotesMasterId();
|
||||||
assertNotNull(notesMaster);
|
assertNotNull(notesMaster);
|
||||||
// TODO Get the wrapper
|
|
||||||
|
assertNotNull(xml.getNotesMaster());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMetadataBasics() throws Exception {
|
public void testMetadataBasics() throws Exception {
|
||||||
|
Loading…
Reference in New Issue
Block a user