diff --git a/src/ooxml/java/org/apache/poi/POIXMLDocument.java b/src/ooxml/java/org/apache/poi/POIXMLDocument.java index 6f8a7e37d..a9cceb525 100644 --- a/src/ooxml/java/org/apache/poi/POIXMLDocument.java +++ b/src/ooxml/java/org/apache/poi/POIXMLDocument.java @@ -80,4 +80,37 @@ public abstract class POIXMLDocument { } return part; } + + /** + * Checks that the supplied InputStream (which MUST + * support mark and reset, or be a PushbackInputStream) + * has a OOXML (zip) header at the start of it. + * If your InputStream does not support mark / reset, + * then wrap it in a PushBackInputStream, then be + * sure to always use that, and not the original! + * @param inp An InputStream which supports either mark/reset, or is a PushbackInputStream + */ + public static boolean hasOOXMLHeader(InputStream inp) throws IOException { + // We want to peek at the first 4 bytes + inp.mark(4); + + byte[] header = new byte[4]; + IOUtils.readFully(inp, header); + + // Wind back those 4 bytes + if(inp instanceof PushbackInputStream) { + PushbackInputStream pin = (PushbackInputStream)inp; + pin.unread(header); + } else { + inp.reset(); + } + + // Did it match the ooxml zip signature? + return ( + header[0] == POIFSConstants.OOXML_FILE_HEADER[0] && + header[1] == POIFSConstants.OOXML_FILE_HEADER[1] && + header[2] == POIFSConstants.OOXML_FILE_HEADER[2] && + header[3] == POIFSConstants.OOXML_FILE_HEADER[3] + ); + } } diff --git a/src/scratchpad/ooxml-src/org/apache/poi/POIXMLTextExtractor.java b/src/ooxml/java/org/apache/poi/POIXMLTextExtractor.java similarity index 100% rename from src/scratchpad/ooxml-src/org/apache/poi/POIXMLTextExtractor.java rename to src/ooxml/java/org/apache/poi/POIXMLTextExtractor.java diff --git a/src/scratchpad/ooxml-src/org/apache/poi/hxf/dev/HXFLister.java b/src/ooxml/java/org/apache/poi/dev/OOXMLLister.java similarity index 94% rename from src/scratchpad/ooxml-src/org/apache/poi/hxf/dev/HXFLister.java rename to src/ooxml/java/org/apache/poi/dev/OOXMLLister.java index 032b74b6f..7084b38f3 100644 --- a/src/scratchpad/ooxml-src/org/apache/poi/hxf/dev/HXFLister.java +++ b/src/ooxml/java/org/apache/poi/dev/OOXMLLister.java @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ -package org.apache.poi.hxf.dev; +package org.apache.poi.dev; import java.io.File; import java.io.IOException; @@ -29,18 +29,18 @@ import org.openxml4j.opc.PackageRelationship; import org.openxml4j.opc.PackageRelationshipCollection; /** - * Prints out the contents of a HXF (ooxml) container. + * Prints out the contents of a OOXML container. * Useful for seeing what parts are defined, and how * they're all related to each other. */ -public class HXFLister { +public class OOXMLLister { private Package container; private PrintStream disp; - public HXFLister(Package container) { + public OOXMLLister(Package container) { this(container, System.out); } - public HXFLister(Package container, PrintStream disp) { + public OOXMLLister(Package container, PrintStream disp) { this.container = container; this.disp = disp; } @@ -121,7 +121,7 @@ public class HXFLister { System.exit(2); } - HXFLister lister = new HXFLister( + OOXMLLister lister = new OOXMLLister( Package.open(f.toString(), PackageAccess.READ) ); diff --git a/src/scratchpad/ooxml-src/org/apache/poi/hslf/HSLFXML.java b/src/ooxml/java/org/apache/poi/hslf/HSLFXML.java similarity index 100% rename from src/scratchpad/ooxml-src/org/apache/poi/hslf/HSLFXML.java rename to src/ooxml/java/org/apache/poi/hslf/HSLFXML.java diff --git a/src/scratchpad/ooxml-src/org/apache/poi/hslf/extractor/HXFPowerPointExtractor.java b/src/ooxml/java/org/apache/poi/hslf/extractor/HXFPowerPointExtractor.java similarity index 100% rename from src/scratchpad/ooxml-src/org/apache/poi/hslf/extractor/HXFPowerPointExtractor.java rename to src/ooxml/java/org/apache/poi/hslf/extractor/HXFPowerPointExtractor.java diff --git a/src/scratchpad/ooxml-src/org/apache/poi/hslf/usermodel/HSLFXMLSlideShow.java b/src/ooxml/java/org/apache/poi/hslf/usermodel/HSLFXMLSlideShow.java similarity index 100% rename from src/scratchpad/ooxml-src/org/apache/poi/hslf/usermodel/HSLFXMLSlideShow.java rename to src/ooxml/java/org/apache/poi/hslf/usermodel/HSLFXMLSlideShow.java diff --git a/src/scratchpad/ooxml-src/org/apache/poi/hwpf/HWPFXML.java b/src/ooxml/java/org/apache/poi/hwpf/HWPFXML.java similarity index 100% rename from src/scratchpad/ooxml-src/org/apache/poi/hwpf/HWPFXML.java rename to src/ooxml/java/org/apache/poi/hwpf/HWPFXML.java diff --git a/src/scratchpad/ooxml-src/org/apache/poi/hwpf/extractor/HXFWordExtractor.java b/src/ooxml/java/org/apache/poi/hwpf/extractor/HXFWordExtractor.java similarity index 100% rename from src/scratchpad/ooxml-src/org/apache/poi/hwpf/extractor/HXFWordExtractor.java rename to src/ooxml/java/org/apache/poi/hwpf/extractor/HXFWordExtractor.java diff --git a/src/scratchpad/ooxml-src/org/apache/poi/hwpf/usermodel/HWPFXMLDocument.java b/src/ooxml/java/org/apache/poi/hwpf/usermodel/HWPFXMLDocument.java similarity index 100% rename from src/scratchpad/ooxml-src/org/apache/poi/hwpf/usermodel/HWPFXMLDocument.java rename to src/ooxml/java/org/apache/poi/hwpf/usermodel/HWPFXMLDocument.java diff --git a/src/scratchpad/ooxml-testcases/org/apache/poi/hslf/TestHSLFXML.java b/src/ooxml/testcases/org/apache/poi/hslf/TestHSLFXML.java similarity index 100% rename from src/scratchpad/ooxml-testcases/org/apache/poi/hslf/TestHSLFXML.java rename to src/ooxml/testcases/org/apache/poi/hslf/TestHSLFXML.java diff --git a/src/scratchpad/ooxml-testcases/org/apache/poi/hslf/extractor/TestHXFPowerPointExtractor.java b/src/ooxml/testcases/org/apache/poi/hslf/extractor/TestHXFPowerPointExtractor.java similarity index 100% rename from src/scratchpad/ooxml-testcases/org/apache/poi/hslf/extractor/TestHXFPowerPointExtractor.java rename to src/ooxml/testcases/org/apache/poi/hslf/extractor/TestHXFPowerPointExtractor.java diff --git a/src/scratchpad/ooxml-testcases/org/apache/poi/hwpf/TestHWPFXML.java b/src/ooxml/testcases/org/apache/poi/hwpf/TestHWPFXML.java similarity index 100% rename from src/scratchpad/ooxml-testcases/org/apache/poi/hwpf/TestHWPFXML.java rename to src/ooxml/testcases/org/apache/poi/hwpf/TestHWPFXML.java diff --git a/src/scratchpad/ooxml-testcases/org/apache/poi/hwpf/extractor/TestHXFWordExtractor.java b/src/ooxml/testcases/org/apache/poi/hwpf/extractor/TestHXFWordExtractor.java similarity index 100% rename from src/scratchpad/ooxml-testcases/org/apache/poi/hwpf/extractor/TestHXFWordExtractor.java rename to src/ooxml/testcases/org/apache/poi/hwpf/extractor/TestHXFWordExtractor.java diff --git a/src/scratchpad/ooxml-src/org/apache/poi/POIXMLDocument.java b/src/scratchpad/ooxml-src/org/apache/poi/POIXMLDocument.java deleted file mode 100644 index 86b0d557b..000000000 --- a/src/scratchpad/ooxml-src/org/apache/poi/POIXMLDocument.java +++ /dev/null @@ -1,45 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ -package org.apache.poi; - -import org.apache.poi.hxf.HXFDocument; - -/** - * Parent class of all UserModel POI XML (ooxml) - * implementations. - * Provides a similar function to {@link POIDocument}, - * for the XML based classes. - */ -public abstract class POIXMLDocument { - private HXFDocument document; - - /** - * Creates a new POI XML Document, wrapping up - * the underlying raw HXFDocument - */ - protected POIXMLDocument(HXFDocument document) { - this.document = document; - } - - /** - * Returns the underlying HXFDocument, typically - * used for unit testing - */ - public HXFDocument _getHXFDocument() { - return document; - } -}