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.

XDGFDocument.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.xdgf.usermodel;
  16. import java.util.HashMap;
  17. import java.util.Map;
  18. import org.apache.poi.POIXMLException;
  19. import org.apache.poi.util.Internal;
  20. import com.microsoft.schemas.office.visio.x2012.main.DocumentSettingsType;
  21. import com.microsoft.schemas.office.visio.x2012.main.StyleSheetType;
  22. import com.microsoft.schemas.office.visio.x2012.main.VisioDocumentType;
  23. /**
  24. * Represents the root document: /visio/document.xml
  25. *
  26. * You're probably actually looking for {@link XmlVisioDocument}, this
  27. * only contains metadata about the root document in the OOXML package.
  28. */
  29. public class XDGFDocument {
  30. protected VisioDocumentType _document;
  31. Map<Long, XDGFStyleSheet> _styleSheets = new HashMap<Long, XDGFStyleSheet>();
  32. // defaults
  33. long _defaultFillStyle = 0;
  34. long _defaultGuideStyle = 0;
  35. long _defaultLineStyle = 0;
  36. long _defaultTextStyle = 0;
  37. public XDGFDocument(VisioDocumentType document) {
  38. _document = document;
  39. if (!_document.isSetDocumentSettings())
  40. throw new POIXMLException("Document settings not found");
  41. DocumentSettingsType docSettings = _document.getDocumentSettings();
  42. if (docSettings.isSetDefaultFillStyle())
  43. _defaultFillStyle = docSettings.getDefaultFillStyle();
  44. if (docSettings.isSetDefaultGuideStyle())
  45. _defaultGuideStyle = docSettings.getDefaultGuideStyle();
  46. if (docSettings.isSetDefaultLineStyle())
  47. _defaultLineStyle = docSettings.getDefaultLineStyle();
  48. if (docSettings.isSetDefaultTextStyle())
  49. _defaultTextStyle = docSettings.getDefaultTextStyle();
  50. if (_document.isSetStyleSheets()) {
  51. for (StyleSheetType styleSheet: _document.getStyleSheets().getStyleSheetArray()) {
  52. _styleSheets.put(styleSheet.getID(), new XDGFStyleSheet(styleSheet, this));
  53. }
  54. }
  55. }
  56. @Internal
  57. public VisioDocumentType getXmlObject() {
  58. return _document;
  59. }
  60. public XDGFStyleSheet getStyleById(long id) {
  61. return _styleSheets.get(id);
  62. }
  63. public XDGFStyleSheet getDefaultFillStyle() {
  64. XDGFStyleSheet style = getStyleById(_defaultFillStyle);
  65. if (style == null)
  66. throw new POIXMLException("No default fill style found!");
  67. return style;
  68. }
  69. public XDGFStyleSheet getDefaultGuideStyle() {
  70. XDGFStyleSheet style = getStyleById(_defaultGuideStyle);
  71. if (style == null)
  72. throw new POIXMLException("No default guide style found!");
  73. return style;
  74. }
  75. public XDGFStyleSheet getDefaultLineStyle() {
  76. XDGFStyleSheet style = getStyleById(_defaultLineStyle);
  77. if (style == null)
  78. throw new POIXMLException("No default line style found!");
  79. return style;
  80. }
  81. public XDGFStyleSheet getDefaultTextStyle() {
  82. XDGFStyleSheet style = getStyleById(_defaultTextStyle);
  83. if (style == null)
  84. throw new POIXMLException("No default text style found!");
  85. return style;
  86. }
  87. }