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.

POIXMLTypeLoader.java 3.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.ooxml;
  16. import java.util.Collections;
  17. import java.util.HashMap;
  18. import java.util.Map;
  19. import org.apache.poi.openxml4j.opc.PackageNamespaces;
  20. import org.apache.poi.xssf.usermodel.XSSFRelation;
  21. import org.apache.xmlbeans.XmlOptions;
  22. public class POIXMLTypeLoader {
  23. // TODO: Do these have a good home like o.a.p.openxml4j.opc.PackageNamespaces and PackageRelationshipTypes?
  24. // These constants should be common to all of POI and easy to use by other applications such as Tika
  25. private static final String MS_OFFICE_URN = "urn:schemas-microsoft-com:office:office";
  26. private static final String MS_EXCEL_URN = "urn:schemas-microsoft-com:office:excel";
  27. private static final String MS_WORD_URN = "urn:schemas-microsoft-com:office:word";
  28. private static final String MS_VML_URN = "urn:schemas-microsoft-com:vml";
  29. public static final XmlOptions DEFAULT_XML_OPTIONS;
  30. static {
  31. DEFAULT_XML_OPTIONS = new XmlOptions();
  32. DEFAULT_XML_OPTIONS.setSaveOuter();
  33. DEFAULT_XML_OPTIONS.setUseDefaultNamespace();
  34. DEFAULT_XML_OPTIONS.setSaveAggressiveNamespaces();
  35. DEFAULT_XML_OPTIONS.setCharacterEncoding("UTF-8");
  36. DEFAULT_XML_OPTIONS.setDisallowDocTypeDeclaration(true);
  37. DEFAULT_XML_OPTIONS.setEntityExpansionLimit(1);
  38. // JAXP is used for parsing
  39. // so only user code using XmlObject/XmlToken.Factory.parse
  40. // directly can bypass the entity check, which is probably unlikely (... and not within our responsibility :))
  41. // DEFAULT_XML_OPTIONS.setLoadEntityBytesLimit(4096);
  42. // POI is not thread-safe - so we can switch to unsynchronized xmlbeans mode - see #61350
  43. // Update: disabled again for now as it caused strange NPEs and other problems
  44. // when reading properties in separate workbooks in multiple threads
  45. // DEFAULT_XML_OPTIONS.setUnsynchronized();
  46. Map<String, String> map = new HashMap<>();
  47. map.put(XSSFRelation.NS_DRAWINGML, "a");
  48. map.put("http://schemas.openxmlformats.org/drawingml/2006/chart", "c");
  49. map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp");
  50. map.put(PackageNamespaces.MARKUP_COMPATIBILITY, "ve");
  51. map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m");
  52. map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
  53. map.put("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes", "vt");
  54. map.put(XSSFRelation.NS_PRESENTATIONML, "p");
  55. map.put(XSSFRelation.NS_WORDPROCESSINGML, "w");
  56. map.put("http://schemas.microsoft.com/office/word/2006/wordml", "wne");
  57. map.put(MS_OFFICE_URN, "o");
  58. map.put(MS_EXCEL_URN, "x");
  59. map.put(MS_WORD_URN, "w10");
  60. map.put(MS_VML_URN, "v");
  61. map.put("http://schemas.microsoft.com/office/drawing/2012/chart", "c15");
  62. DEFAULT_XML_OPTIONS.setSaveSuggestedPrefixes(Collections.unmodifiableMap(map));
  63. }
  64. }