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.

XSLFNotes.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
  17. import java.io.IOException;
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. import org.apache.poi.ooxml.POIXMLDocumentPart;
  21. import org.apache.poi.openxml4j.opc.PackagePart;
  22. import org.apache.poi.sl.usermodel.Notes;
  23. import org.apache.poi.util.Beta;
  24. import org.apache.xmlbeans.XmlException;
  25. import org.openxmlformats.schemas.presentationml.x2006.main.CTCommonSlideData;
  26. import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide;
  27. import org.openxmlformats.schemas.presentationml.x2006.main.NotesDocument;
  28. @Beta
  29. public final class XSLFNotes extends XSLFSheet
  30. implements Notes<XSLFShape,XSLFTextParagraph> {
  31. private CTNotesSlide _notes;
  32. /**
  33. * Create a new notes
  34. */
  35. XSLFNotes() {
  36. _notes = prototype();
  37. }
  38. /**
  39. * Construct a SpreadsheetML notes from a package part
  40. *
  41. * @param part the package part holding the notes data,
  42. * the content type must be <code>application/vnd.openxmlformats-officedocument.notes+xml</code>
  43. *
  44. * @since POI 3.14-Beta1
  45. */
  46. XSLFNotes(PackagePart part) throws IOException, XmlException {
  47. super(part);
  48. NotesDocument doc =
  49. NotesDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS);
  50. _notes = doc.getNotes();
  51. }
  52. private static CTNotesSlide prototype(){
  53. CTNotesSlide ctNotes = CTNotesSlide.Factory.newInstance();
  54. CTCommonSlideData cSld = ctNotes.addNewCSld();
  55. cSld.addNewSpTree();
  56. return ctNotes;
  57. }
  58. @Override
  59. public CTNotesSlide getXmlObject() {
  60. return _notes;
  61. }
  62. @Override
  63. protected String getRootElementName(){
  64. return "notes";
  65. }
  66. @Override
  67. public XSLFTheme getTheme(){
  68. final XSLFNotesMaster m = getMasterSheet();
  69. return (m != null) ? m.getTheme() : null;
  70. }
  71. @Override
  72. public XSLFNotesMaster getMasterSheet() {
  73. for (POIXMLDocumentPart p : getRelations()) {
  74. if (p instanceof XSLFNotesMaster){
  75. return (XSLFNotesMaster)p;
  76. }
  77. }
  78. return null;
  79. }
  80. @Override
  81. public List<List<XSLFTextParagraph>> getTextParagraphs() {
  82. List<List<XSLFTextParagraph>> tp = new ArrayList<>();
  83. for (XSLFShape sh : super.getShapes()) {
  84. if (sh instanceof XSLFTextShape) {
  85. XSLFTextShape txt = (XSLFTextShape)sh;
  86. tp.add(txt.getTextParagraphs());
  87. }
  88. }
  89. return tp;
  90. }
  91. @Override
  92. String mapSchemeColor(String schemeColor) {
  93. return mapSchemeColor(_notes.getClrMapOvr(), schemeColor);
  94. }
  95. }