From: Yegor Kozlov Date: Sat, 10 Sep 2011 10:50:05 +0000 (+0000) Subject: initial support for table styles in XSLF X-Git-Tag: REL_3_8_BETA5~180 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9c108f4fee473a7fb2b76af0492f332f0849f62c;p=poi.git initial support for table styles in XSLF git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1167491 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java index 6682420486..2491f68a78 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java @@ -64,9 +64,10 @@ public class XMLSlideShow extends POIXMLDocument { private CTPresentation _presentation; private List _slides; private Map _masters; + private List _pictures; + private XSLFTableStyles _tableStyles; private XSLFNotesMaster _notesMaster; private XSLFCommentAuthors _commentAuthors; - protected List _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; + } + } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java index 0d691e44dd..a1d1b51100 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java @@ -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 cls) { super(type, rel, defaultName, cls); diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableStyle.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableStyle.java new file mode 100644 index 0000000000..31840314b9 --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableStyle.java @@ -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(); + } +} \ No newline at end of file diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableStyles.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableStyles.java new file mode 100644 index 0000000000..154f25e06a --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableStyles.java @@ -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{ + private CTTableStyleList _tblStyleLst; + private List _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(_tblStyleLst.sizeOfTblStyleArray()); + for(CTTableStyle c : _tblStyleLst.getTblStyleList()){ + _styles.add(new XSLFTableStyle(c)); + } + } + + public CTTableStyleList getXmlObject(){ + return _tblStyleLst; + } + + public Iterator iterator(){ + return _styles.iterator(); + } + + public List getStyles(){ + return Collections.unmodifiableList(_styles); + } +} \ No newline at end of file diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTableStyles.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTableStyles.java new file mode 100644 index 0000000000..73b488b248 --- /dev/null +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTableStyles.java @@ -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()); + } +} \ No newline at end of file