Skip to content

Commit c11e037

Browse files
committed
First steps in porting 4.x sax ooxml -> 3.x - checkpoint
1 parent 478049c commit c11e037

12 files changed

Lines changed: 1800 additions & 178 deletions

File tree

tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/parser/microsoft/ooxml/OOXMLExtractorFactory.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.InputStream;
2222
import java.nio.file.Files;
2323
import java.util.Locale;
24+
import java.util.Set;
2425

2526
import org.apache.poi.extractor.ExtractorFactory;
2627
import org.apache.poi.ooxml.POIXMLDocument;
@@ -182,6 +183,10 @@ public static void parse(InputStream stream, ContentHandler baseHandler, Metadat
182183
XSLFEventBasedPowerPointExtractor.class.getCanonicalName());
183184
} else if (poiExtractor instanceof XPSTextExtractor) {
184185
extractor = new XPSExtractorDecorator(context, poiExtractor);
186+
} else if (isVisioType(type)) {
187+
//SAX-based .vsdx extractor; the XDGF-based poiExtractor is used only for its
188+
//OPCPackage (VSDXExtractorDecorator reads the package directly)
189+
extractor = new VSDXExtractorDecorator(context, poiExtractor);
185190
} else if (document == null) {
186191
throw new TikaException(
187192
"Expecting UserModel based POI OOXML extractor with a document, but none" +
@@ -295,5 +300,17 @@ private static POIXMLTextExtractor tryXSLF(OPCPackage pkg, boolean eventBased)
295300
return null;
296301
}
297302

303+
private static final Set<String> VISIO_SUBTYPES = Set.of(
304+
"vnd.ms-visio.drawing",
305+
"vnd.ms-visio.drawing.macroenabled.12",
306+
"vnd.ms-visio.stencil",
307+
"vnd.ms-visio.stencil.macroenabled.12",
308+
"vnd.ms-visio.template",
309+
"vnd.ms-visio.template.macroenabled.12"
310+
);
311+
312+
private static boolean isVisioType(MediaType type) {
313+
return type != null && VISIO_SUBTYPES.contains(type.getSubtype());
314+
}
298315

299316
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.tika.parser.microsoft.ooxml;
18+
19+
/**
20+
* Sheet contents handler that uses {@link XSSFCommentsShim.CommentData}
21+
* instead of POI's XMLBeans-dependent {@code XSSFComment}.
22+
*/
23+
interface TikaSheetContentsHandler {
24+
25+
void startRow(int rowNum);
26+
27+
void endRow(int rowNum);
28+
29+
void cell(String cellRef, String formattedValue, XSSFCommentsShim.CommentData comment);
30+
31+
default void headerFooter(String text, boolean isHeader, String tagName) {
32+
}
33+
34+
default void endSheet() {
35+
}
36+
}

0 commit comments

Comments
 (0)