initial support for table styles in XSLF

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1167491 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2011-09-10 10:50:05 +00:00
parent 41f656b6c8
commit 76b20bf253
5 changed files with 167 additions and 1 deletions

View File

@ -64,9 +64,10 @@ public class XMLSlideShow extends POIXMLDocument {
private CTPresentation _presentation;
private List<XSLFSlide> _slides;
private Map<String, XSLFSlideMaster> _masters;
private List<XSLFPictureData> _pictures;
private XSLFTableStyles _tableStyles;
private XSLFNotesMaster _notesMaster;
private XSLFCommentAuthors _commentAuthors;
protected List<XSLFPictureData> _pictures;
public XMLSlideShow() {
this(empty());
@ -124,6 +125,8 @@ public class XMLSlideShow extends POIXMLDocument {
} else if (p instanceof XSLFSlideMaster) {
XSLFSlideMaster master = (XSLFSlideMaster)p;
_masters.put(p.getPackageRelationship().getId(), master);
}else if (p instanceof XSLFTableStyles){
_tableStyles = (XSLFTableStyles)p;
} else if (p instanceof XSLFNotesMaster) {
_notesMaster = (XSLFNotesMaster)p;
} else if (p instanceof XSLFCommentAuthors) {
@ -335,4 +338,8 @@ public class XMLSlideShow extends POIXMLDocument {
return imageNumber - 1;
}
public XSLFTableStyles getTableStyles(){
return _tableStyles;
}
}

View File

@ -190,6 +190,13 @@ public class XSLFRelation extends POIXMLRelation {
null
);
public static final XSLFRelation TABLE_STYLES = new XSLFRelation(
"application/vnd.openxmlformats-officedocument.presentationml.tableStyles+xml",
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableStyles",
"/ppt/tableStyles.xml",
XSLFTableStyles.class
);
private XSLFRelation(String type, String rel, String defaultName, Class<? extends POIXMLDocumentPart> cls) {
super(type, rel, defaultName, cls);

View File

@ -0,0 +1,47 @@
/*
* ====================================================================
* 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 org.openxmlformats.schemas.drawingml.x2006.main.CTTableStyle;
/**
* Represents a table in a .pptx presentation
*
* @author Yegor Kozlov
*/
public class XSLFTableStyle {
private CTTableStyle _tblStyle;
/*package*/ XSLFTableStyle(CTTableStyle style){
_tblStyle = style;
}
public CTTableStyle getXmlObject(){
return _tblStyle;
}
public String getStyleName(){
return _tblStyle.getStyleName();
}
public String getStyleId(){
return _tblStyle.getStyleId();
}
}

View File

@ -0,0 +1,63 @@
/* ====================================================================
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 org.apache.poi.POIXMLDocumentPart;
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.drawingml.x2006.main.CTTableStyle;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableStyleList;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
@Beta
public class XSLFTableStyles extends POIXMLDocumentPart implements Iterable<XSLFTableStyle>{
private CTTableStyleList _tblStyleLst;
private List<XSLFTableStyle> _styles;
public XSLFTableStyles(){
super();
}
public XSLFTableStyles(PackagePart part, PackageRelationship rel) throws IOException, XmlException {
super(part, rel);
_tblStyleLst = CTTableStyleList.Factory.parse(getPackagePart().getInputStream());
_styles = new ArrayList<XSLFTableStyle>(_tblStyleLst.sizeOfTblStyleArray());
for(CTTableStyle c : _tblStyleLst.getTblStyleList()){
_styles.add(new XSLFTableStyle(c));
}
}
public CTTableStyleList getXmlObject(){
return _tblStyleLst;
}
public Iterator<XSLFTableStyle> iterator(){
return _styles.iterator();
}
public List<XSLFTableStyle> getStyles(){
return Collections.unmodifiableList(_styles);
}
}

View File

@ -0,0 +1,42 @@
/* ====================================================================
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 junit.framework.TestCase;
import java.awt.*;
import java.awt.geom.Ellipse2D;
import java.awt.geom.GeneralPath;
import java.util.*;
import java.util.List;
import org.apache.poi.xslf.XSLFTestDataSamples;
import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
/**
* @author Yegor Kozlov
*/
public class TestXSLFTableStyles extends TestCase {
public void testRead(){
XMLSlideShow ppt = new XMLSlideShow();
XSLFTableStyles tblStyles = ppt.getTableStyles();
assertNotNull(tblStyles);
assertEquals(10, tblStyles.getStyles().size());
}
}