You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XSLFSlideMaster.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.xslf.usermodel;
  16. import org.apache.poi.POIXMLDocumentPart;
  17. import org.apache.poi.openxml4j.opc.PackagePart;
  18. import org.apache.poi.openxml4j.opc.PackageRelationship;
  19. import org.apache.poi.sl.usermodel.MasterSheet;
  20. import org.apache.poi.util.Beta;
  21. import org.apache.xmlbeans.XmlException;
  22. import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMaster;
  23. import org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument;
  24. import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterTextStyles;
  25. import org.openxmlformats.schemas.drawingml.x2006.main.CTTextListStyle;
  26. import java.io.IOException;
  27. import java.util.HashMap;
  28. import java.util.Map;
  29. /**
  30. * Slide master object associated with this layout.
  31. * <p>
  32. * Within a slide master slide are contained all elements
  33. * that describe the objects and their corresponding formatting
  34. * for within a presentation slide.
  35. * </p>
  36. * <p>
  37. * Within a slide master slide are two main elements.
  38. * The cSld element specifies the common slide elements such as shapes and
  39. * their attached text bodies. Then the txStyles element specifies the
  40. * formatting for the text within each of these shapes. The other properties
  41. * within a slide master slide specify other properties for within a presentation slide
  42. * such as color information, headers and footers, as well as timing and
  43. * transition information for all corresponding presentation slides.
  44. * </p>
  45. *
  46. * @author Yegor Kozlov
  47. */
  48. @Beta
  49. public class XSLFSlideMaster extends XSLFSheet {
  50. private CTSlideMaster _slide;
  51. private Map<String, XSLFSlideLayout> _layouts;
  52. private XSLFTheme _theme;
  53. XSLFSlideMaster() {
  54. super();
  55. _slide = CTSlideMaster.Factory.newInstance();
  56. }
  57. protected XSLFSlideMaster(PackagePart part, PackageRelationship rel) throws IOException, XmlException {
  58. super(part, rel);
  59. SldMasterDocument doc =
  60. SldMasterDocument.Factory.parse(getPackagePart().getInputStream());
  61. _slide = doc.getSldMaster();
  62. setCommonSlideData(_slide.getCSld());
  63. }
  64. @Override
  65. public CTSlideMaster getXmlObject() {
  66. return _slide;
  67. }
  68. @Override
  69. protected String getRootElementName(){
  70. return "sldMaster";
  71. }
  72. public XSLFSlideLayout getLayout(String name){
  73. if(_layouts == null){
  74. _layouts = new HashMap<String, XSLFSlideLayout>();
  75. for (POIXMLDocumentPart p : getRelations()) {
  76. if (p instanceof XSLFSlideLayout){
  77. XSLFSlideLayout layout = (XSLFSlideLayout)p;
  78. _layouts.put(layout.getName().toLowerCase(), layout);
  79. }
  80. }
  81. }
  82. return _layouts.get(name);
  83. }
  84. public XSLFTheme getTheme(){
  85. if(_theme == null){
  86. for (POIXMLDocumentPart p : getRelations()) {
  87. if (p instanceof XSLFTheme){
  88. _theme = (XSLFTheme)p;
  89. break;
  90. }
  91. }
  92. }
  93. return _theme;
  94. }
  95. protected CTTextListStyle getTextProperties(Placeholder textType) {
  96. CTTextListStyle props;
  97. CTSlideMasterTextStyles txStyles = getXmlObject().getTxStyles();
  98. switch (textType){
  99. case TITLE:
  100. case CENTERED_TITLE:
  101. case SUBTITLE:
  102. props = txStyles.getTitleStyle();
  103. break;
  104. case BODY:
  105. props = txStyles.getBodyStyle();
  106. break;
  107. default:
  108. props = txStyles.getOtherStyle();
  109. break;
  110. }
  111. return props;
  112. }
  113. }