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.

XSSFPivotCache.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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.xssf.usermodel;
  16. import org.apache.poi.ooxml.POIXMLDocumentPart;
  17. import org.apache.poi.openxml4j.opc.PackagePart;
  18. import org.apache.poi.util.Beta;
  19. import org.apache.xmlbeans.XmlException;
  20. import org.apache.xmlbeans.XmlOptions;
  21. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCache;
  22. import java.io.IOException;
  23. import java.io.InputStream;
  24. import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
  25. public class XSSFPivotCache extends POIXMLDocumentPart {
  26. private CTPivotCache ctPivotCache;
  27. @Beta
  28. public XSSFPivotCache(){
  29. super();
  30. ctPivotCache = CTPivotCache.Factory.newInstance();
  31. }
  32. @Beta
  33. public XSSFPivotCache(CTPivotCache ctPivotCache) {
  34. super();
  35. this.ctPivotCache = ctPivotCache;
  36. }
  37. /**
  38. * Creates n XSSFPivotCache representing the given package part and relationship.
  39. * Should only be called when reading in an existing file.
  40. *
  41. * @param part - The package part that holds xml data representing this pivot cache definition.
  42. *
  43. * @since POI 3.14-Beta1
  44. */
  45. @Beta
  46. protected XSSFPivotCache(PackagePart part) throws IOException {
  47. super(part);
  48. try (InputStream stream = part.getInputStream()) {
  49. readFrom(stream);
  50. }
  51. }
  52. @Beta
  53. protected void readFrom(InputStream is) throws IOException {
  54. try {
  55. XmlOptions options = new XmlOptions(DEFAULT_XML_OPTIONS);
  56. //Removing root element
  57. options.setLoadReplaceDocumentElement(null);
  58. ctPivotCache = CTPivotCache.Factory.parse(is, options);
  59. } catch (XmlException e) {
  60. throw new IOException(e.getLocalizedMessage());
  61. }
  62. }
  63. @Beta
  64. public CTPivotCache getCTPivotCache() {
  65. return ctPivotCache;
  66. }
  67. }