You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2016/06/29 11:11:27 UTC
[21/39] tika git commit: Convert new lines from windows to unix
http://git-wip-us.apache.org/repos/asf/tika/blob/c7a6bcac/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/opc/OPCDetector.java
----------------------------------------------------------------------
diff --git a/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/opc/OPCDetector.java b/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/opc/OPCDetector.java
index cc17459..a8fe200 100644
--- a/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/opc/OPCDetector.java
+++ b/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/opc/OPCDetector.java
@@ -1,155 +1,155 @@
-/*
- * 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.tika.parser.opc;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Locale;
-import java.util.regex.Pattern;
-
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.apache.poi.openxml4j.opc.OPCPackage;
-import org.apache.poi.openxml4j.opc.PackageAccess;
-import org.apache.poi.openxml4j.opc.PackagePart;
-import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
-import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
-import org.apache.tika.detect.Detector;
-import org.apache.tika.io.TemporaryResources;
-import org.apache.tika.io.TikaInputStream;
-import org.apache.tika.metadata.Metadata;
-import org.apache.tika.mime.MediaType;
-
-/**
- * Detector that detects OPC Packages
- *
- */
-public class OPCDetector implements Detector {
-
- /**
- *
- */
- private static final long serialVersionUID = -3569622763024617244L;
-
- private static final Pattern MACRO_TEMPLATE_PATTERN = Pattern.compile("macroenabledtemplate$", Pattern.CASE_INSENSITIVE);
-
- // TODO Remove this constant once we upgrade to POI 3.12 beta 2, then use PackageRelationshipTypes
- private static final String VISIO_DOCUMENT =
- "http://schemas.microsoft.com/visio/2010/relationships/document";
-
- // TODO Remove this constant once we upgrade to POI 3.12 beta 2, then use PackageRelationshipTypes
- private static final String STRICT_CORE_DOCUMENT =
- "http://purl.oclc.org/ooxml/officeDocument/relationships/officeDocument";
-
- @Override
- public MediaType detect(InputStream input, Metadata metadata) throws IOException {
- TemporaryResources tmp = new TemporaryResources();
- try {
- TikaInputStream stream = TikaInputStream.get(input, tmp);
- // Use POI to open and investigate it for us
- OPCPackage pkg = OPCPackage.open(stream.getFile().getPath(), PackageAccess.READ);
- stream.setOpenContainer(pkg);
-
- // Is at an OOXML format?
- MediaType type = detectOfficeOpenXML(pkg);
- if (type != null) return type;
-
- // Is it XPS format?
- type = detectXPSOPC(pkg);
- if (type != null) return type;
-
- // Is it an AutoCAD format?
- type = detectAutoCADOPC(pkg);
-
- return type;
- } catch (InvalidFormatException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }finally {
- tmp.close();
- }
- return null;
- }
-
- /**
- * Detects the type of an OfficeOpenXML (OOXML) file from
- * opened Package
- */
- public static MediaType detectOfficeOpenXML(OPCPackage pkg) {
- // Check for the normal Office core document
- PackageRelationshipCollection core =
- pkg.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT);
- // Otherwise check for some other Office core document types
- if (core.size() == 0) {
- core = pkg.getRelationshipsByType(STRICT_CORE_DOCUMENT);
- }
- if (core.size() == 0) {
- core = pkg.getRelationshipsByType(VISIO_DOCUMENT);
- }
-
- // If we didn't find a single core document of any type, skip detection
- if (core.size() != 1) {
- // Invalid OOXML Package received
- return null;
- }
-
- // Get the type of the core document part
- PackagePart corePart = pkg.getPart(core.getRelationship(0));
- String coreType = corePart.getContentType();
-
- // Turn that into the type of the overall document
- String docType = coreType.substring(0, coreType.lastIndexOf('.'));
-
- // The Macro Enabled formats are a little special
- if(docType.toLowerCase(Locale.ROOT).endsWith("macroenabled")) {
- docType = docType.toLowerCase(Locale.ROOT) + ".12";
- }
-
- if(docType.toLowerCase(Locale.ROOT).endsWith("macroenabledtemplate")) {
- docType = MACRO_TEMPLATE_PATTERN.matcher(docType).replaceAll("macroenabled.12");
- }
-
- // Build the MediaType object and return
- return MediaType.parse(docType);
- }
- /**
- * Detects Open XML Paper Specification (XPS)
- */
- private static MediaType detectXPSOPC(OPCPackage pkg) {
- PackageRelationshipCollection xps =
- pkg.getRelationshipsByType("http://schemas.microsoft.com/xps/2005/06/fixedrepresentation");
- if (xps.size() == 1) {
- return MediaType.application("vnd.ms-xpsdocument");
- } else {
- // Non-XPS Package received
- return null;
- }
- }
- /**
- * Detects AutoCAD formats that live in OPC packaging
- */
- private static MediaType detectAutoCADOPC(OPCPackage pkg) {
- PackageRelationshipCollection dwfxSeq =
- pkg.getRelationshipsByType("http://schemas.autodesk.com/dwfx/2007/relationships/documentsequence");
- if (dwfxSeq.size() == 1) {
- return MediaType.parse("model/vnd.dwfx+xps");
- } else {
- // Non-AutoCAD Package received
- return null;
- }
- }
-
-}
+/*
+ * 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.tika.parser.opc;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Locale;
+import java.util.regex.Pattern;
+
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.openxml4j.opc.PackageAccess;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
+import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
+import org.apache.tika.detect.Detector;
+import org.apache.tika.io.TemporaryResources;
+import org.apache.tika.io.TikaInputStream;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.mime.MediaType;
+
+/**
+ * Detector that detects OPC Packages
+ *
+ */
+public class OPCDetector implements Detector {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -3569622763024617244L;
+
+ private static final Pattern MACRO_TEMPLATE_PATTERN = Pattern.compile("macroenabledtemplate$", Pattern.CASE_INSENSITIVE);
+
+ // TODO Remove this constant once we upgrade to POI 3.12 beta 2, then use PackageRelationshipTypes
+ private static final String VISIO_DOCUMENT =
+ "http://schemas.microsoft.com/visio/2010/relationships/document";
+
+ // TODO Remove this constant once we upgrade to POI 3.12 beta 2, then use PackageRelationshipTypes
+ private static final String STRICT_CORE_DOCUMENT =
+ "http://purl.oclc.org/ooxml/officeDocument/relationships/officeDocument";
+
+ @Override
+ public MediaType detect(InputStream input, Metadata metadata) throws IOException {
+ TemporaryResources tmp = new TemporaryResources();
+ try {
+ TikaInputStream stream = TikaInputStream.get(input, tmp);
+ // Use POI to open and investigate it for us
+ OPCPackage pkg = OPCPackage.open(stream.getFile().getPath(), PackageAccess.READ);
+ stream.setOpenContainer(pkg);
+
+ // Is at an OOXML format?
+ MediaType type = detectOfficeOpenXML(pkg);
+ if (type != null) return type;
+
+ // Is it XPS format?
+ type = detectXPSOPC(pkg);
+ if (type != null) return type;
+
+ // Is it an AutoCAD format?
+ type = detectAutoCADOPC(pkg);
+
+ return type;
+ } catch (InvalidFormatException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }finally {
+ tmp.close();
+ }
+ return null;
+ }
+
+ /**
+ * Detects the type of an OfficeOpenXML (OOXML) file from
+ * opened Package
+ */
+ public static MediaType detectOfficeOpenXML(OPCPackage pkg) {
+ // Check for the normal Office core document
+ PackageRelationshipCollection core =
+ pkg.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT);
+ // Otherwise check for some other Office core document types
+ if (core.size() == 0) {
+ core = pkg.getRelationshipsByType(STRICT_CORE_DOCUMENT);
+ }
+ if (core.size() == 0) {
+ core = pkg.getRelationshipsByType(VISIO_DOCUMENT);
+ }
+
+ // If we didn't find a single core document of any type, skip detection
+ if (core.size() != 1) {
+ // Invalid OOXML Package received
+ return null;
+ }
+
+ // Get the type of the core document part
+ PackagePart corePart = pkg.getPart(core.getRelationship(0));
+ String coreType = corePart.getContentType();
+
+ // Turn that into the type of the overall document
+ String docType = coreType.substring(0, coreType.lastIndexOf('.'));
+
+ // The Macro Enabled formats are a little special
+ if(docType.toLowerCase(Locale.ROOT).endsWith("macroenabled")) {
+ docType = docType.toLowerCase(Locale.ROOT) + ".12";
+ }
+
+ if(docType.toLowerCase(Locale.ROOT).endsWith("macroenabledtemplate")) {
+ docType = MACRO_TEMPLATE_PATTERN.matcher(docType).replaceAll("macroenabled.12");
+ }
+
+ // Build the MediaType object and return
+ return MediaType.parse(docType);
+ }
+ /**
+ * Detects Open XML Paper Specification (XPS)
+ */
+ private static MediaType detectXPSOPC(OPCPackage pkg) {
+ PackageRelationshipCollection xps =
+ pkg.getRelationshipsByType("http://schemas.microsoft.com/xps/2005/06/fixedrepresentation");
+ if (xps.size() == 1) {
+ return MediaType.application("vnd.ms-xpsdocument");
+ } else {
+ // Non-XPS Package received
+ return null;
+ }
+ }
+ /**
+ * Detects AutoCAD formats that live in OPC packaging
+ */
+ private static MediaType detectAutoCADOPC(OPCPackage pkg) {
+ PackageRelationshipCollection dwfxSeq =
+ pkg.getRelationshipsByType("http://schemas.autodesk.com/dwfx/2007/relationships/documentsequence");
+ if (dwfxSeq.size() == 1) {
+ return MediaType.parse("model/vnd.dwfx+xps");
+ } else {
+ // Non-AutoCAD Package received
+ return null;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tika/blob/c7a6bcac/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/opendocument/OpenOfficeParser.java
----------------------------------------------------------------------
diff --git a/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/opendocument/OpenOfficeParser.java b/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/opendocument/OpenOfficeParser.java
index e5beb4b..90f2d2e 100644
--- a/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/opendocument/OpenOfficeParser.java
+++ b/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/opendocument/OpenOfficeParser.java
@@ -1,28 +1,28 @@
-/*
- * 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.tika.parser.opendocument;
-
-import org.apache.tika.parser.odf.OpenDocumentParser;
-
-/**
- * OpenOffice parser
- *
- * @deprecated Use the {@link OpenDocumentParser} class instead.
- * This class will be removed in Apache Tika 1.0.
- */
-public class OpenOfficeParser extends OpenDocumentParser {
-}
+/*
+ * 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.tika.parser.opendocument;
+
+import org.apache.tika.parser.odf.OpenDocumentParser;
+
+/**
+ * OpenOffice parser
+ *
+ * @deprecated Use the {@link OpenDocumentParser} class instead.
+ * This class will be removed in Apache Tika 1.0.
+ */
+public class OpenOfficeParser extends OpenDocumentParser {
+}
http://git-wip-us.apache.org/repos/asf/tika/blob/c7a6bcac/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/rtf/GroupState.java
----------------------------------------------------------------------
diff --git a/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/rtf/GroupState.java b/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/rtf/GroupState.java
index eba9d8c..4a9a1d1 100644
--- a/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/rtf/GroupState.java
+++ b/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/rtf/GroupState.java
@@ -1,67 +1,67 @@
-/*
- * 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.tika.parser.rtf;
-
-import java.nio.charset.Charset;
-
-/* Holds all state associated with current RTF group, ie {
- * ... }. */
-
-class GroupState {
- public int depth;
- public boolean bold;
- public boolean italic;
- // True if we are skipping all text in current group,
- // eg if group leads with a \*:
- public boolean ignore;
- // Default is 1 if no uc control has been seen yet:
- public int ucSkip = 1;
- public int list;
- public int listLevel;
- public Charset fontCharset;
- //in objdata
- public boolean objdata;
- //depth in pict, 1 = at pict level
- public int pictDepth;
- //in picprop key/value pair
- public boolean sp;
- //in picprop's name
- public boolean sn;
- //in picprop's value
- public boolean sv;
- //in embedded object or not
- public boolean object;
-
- // Create default (root) GroupState
- public GroupState() {
- }
-
- // Create new GroupState, inheriting all properties from current one, adding 1 to the depth
- public GroupState(GroupState other) {
- bold = other.bold;
- italic = other.italic;
- ignore = other.ignore;
- ucSkip = other.ucSkip;
- list = other.list;
- listLevel = other.listLevel;
- fontCharset = other.fontCharset;
- depth = 1 + other.depth;
- pictDepth = other.pictDepth > 0 ? other.pictDepth + 1 : 0;
- //do not inherit object, sn, sv or sp
-
- }
-}
+/*
+ * 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.tika.parser.rtf;
+
+import java.nio.charset.Charset;
+
+/* Holds all state associated with current RTF group, ie {
+ * ... }. */
+
+class GroupState {
+ public int depth;
+ public boolean bold;
+ public boolean italic;
+ // True if we are skipping all text in current group,
+ // eg if group leads with a \*:
+ public boolean ignore;
+ // Default is 1 if no uc control has been seen yet:
+ public int ucSkip = 1;
+ public int list;
+ public int listLevel;
+ public Charset fontCharset;
+ //in objdata
+ public boolean objdata;
+ //depth in pict, 1 = at pict level
+ public int pictDepth;
+ //in picprop key/value pair
+ public boolean sp;
+ //in picprop's name
+ public boolean sn;
+ //in picprop's value
+ public boolean sv;
+ //in embedded object or not
+ public boolean object;
+
+ // Create default (root) GroupState
+ public GroupState() {
+ }
+
+ // Create new GroupState, inheriting all properties from current one, adding 1 to the depth
+ public GroupState(GroupState other) {
+ bold = other.bold;
+ italic = other.italic;
+ ignore = other.ignore;
+ ucSkip = other.ucSkip;
+ list = other.list;
+ listLevel = other.listLevel;
+ fontCharset = other.fontCharset;
+ depth = 1 + other.depth;
+ pictDepth = other.pictDepth > 0 ? other.pictDepth + 1 : 0;
+ //do not inherit object, sn, sv or sp
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/tika/blob/c7a6bcac/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/rtf/ListDescriptor.java
----------------------------------------------------------------------
diff --git a/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/rtf/ListDescriptor.java b/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/rtf/ListDescriptor.java
index 1931232..e7142bd 100644
--- a/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/rtf/ListDescriptor.java
+++ b/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/rtf/ListDescriptor.java
@@ -1,35 +1,35 @@
-/*
- * 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.tika.parser.rtf;
-
-/**
- * Contains the information for a single list in the list or list override tables.
- */
-public class ListDescriptor {
- public final static int NUMBER_TYPE_BULLET = 23;
-
- public int id;
- // We record this but don't make use if it today:
- public int templateID;
- // We record this but don't make use if it today:
- public boolean isStyle;
- public int[] numberType = new int[9];
-
- public boolean isUnordered(int level) {
- return numberType[level] == NUMBER_TYPE_BULLET;
- }
-}
+/*
+ * 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.tika.parser.rtf;
+
+/**
+ * Contains the information for a single list in the list or list override tables.
+ */
+public class ListDescriptor {
+ public final static int NUMBER_TYPE_BULLET = 23;
+
+ public int id;
+ // We record this but don't make use if it today:
+ public int templateID;
+ // We record this but don't make use if it today:
+ public boolean isStyle;
+ public int[] numberType = new int[9];
+
+ public boolean isUnordered(int level) {
+ return numberType[level] == NUMBER_TYPE_BULLET;
+ }
+}
http://git-wip-us.apache.org/repos/asf/tika/blob/c7a6bcac/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/rtf/RTFParser.java
----------------------------------------------------------------------
diff --git a/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/rtf/RTFParser.java b/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/rtf/RTFParser.java
index ccd7e7f..d2c448b 100644
--- a/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/rtf/RTFParser.java
+++ b/tika-parser-modules/tika-parser-office-module/src/main/java/org/apache/tika/parser/rtf/RTFParser.java
@@ -1,93 +1,93 @@
-/*
- * 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.tika.parser.rtf;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collections;
-import java.util.Set;
-
-import org.apache.commons.io.input.TaggedInputStream;
-import org.apache.tika.exception.TikaException;
-import org.apache.tika.metadata.Metadata;
-import org.apache.tika.mime.MediaType;
-import org.apache.tika.parser.AbstractParser;
-import org.apache.tika.parser.ParseContext;
-import org.apache.tika.sax.XHTMLContentHandler;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-
-/**
- * RTF parser
- */
-public class RTFParser extends AbstractParser {
-
- /**
- * Serial version UID
- */
- private static final long serialVersionUID = -4165069489372320313L;
-
- private static final Set<MediaType> SUPPORTED_TYPES =
- Collections.singleton(MediaType.application("rtf"));
- /**
- * maximum number of bytes per embedded object/pict (default: 20MB)
- */
- private static int EMB_OBJ_MAX_BYTES = 20 * 1024 * 1024; //20MB
-
- /**
- * See {@link #setMaxBytesForEmbeddedObject(int)}.
- *
- * @return maximum number of bytes allowed for an embedded object.
- */
- public static int getMaxBytesForEmbeddedObject() {
- return EMB_OBJ_MAX_BYTES;
- }
-
- /**
- * Bytes for embedded objects are currently cached in memory.
- * If something goes wrong during the parsing of an embedded object,
- * it is possible that a read length may be crazily too long
- * and cause a heap crash.
- *
- * @param max maximum number of bytes to allow for embedded objects. If
- * the embedded object has more than this number of bytes, skip it.
- */
- public static void setMaxBytesForEmbeddedObject(int max) {
- EMB_OBJ_MAX_BYTES = max;
- }
-
- public Set<MediaType> getSupportedTypes(ParseContext context) {
- return SUPPORTED_TYPES;
- }
-
- public void parse(
- InputStream stream, ContentHandler handler,
- Metadata metadata, ParseContext context)
- throws IOException, SAXException, TikaException {
- metadata.set(Metadata.CONTENT_TYPE, "application/rtf");
- TaggedInputStream tagged = new TaggedInputStream(stream);
- try {
- XHTMLContentHandler xhtmlHandler = new XHTMLContentHandler(handler, metadata);
- RTFEmbObjHandler embObjHandler = new RTFEmbObjHandler(xhtmlHandler, metadata, context);
- final TextExtractor ert = new TextExtractor(xhtmlHandler, metadata, embObjHandler);
- ert.extract(stream);
- } catch (IOException e) {
- tagged.throwIfCauseOf(e);
- throw new TikaException("Error parsing an RTF document", e);
- }
- }
-}
+/*
+ * 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.tika.parser.rtf;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.Set;
+
+import org.apache.commons.io.input.TaggedInputStream;
+import org.apache.tika.exception.TikaException;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.mime.MediaType;
+import org.apache.tika.parser.AbstractParser;
+import org.apache.tika.parser.ParseContext;
+import org.apache.tika.sax.XHTMLContentHandler;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+/**
+ * RTF parser
+ */
+public class RTFParser extends AbstractParser {
+
+ /**
+ * Serial version UID
+ */
+ private static final long serialVersionUID = -4165069489372320313L;
+
+ private static final Set<MediaType> SUPPORTED_TYPES =
+ Collections.singleton(MediaType.application("rtf"));
+ /**
+ * maximum number of bytes per embedded object/pict (default: 20MB)
+ */
+ private static int EMB_OBJ_MAX_BYTES = 20 * 1024 * 1024; //20MB
+
+ /**
+ * See {@link #setMaxBytesForEmbeddedObject(int)}.
+ *
+ * @return maximum number of bytes allowed for an embedded object.
+ */
+ public static int getMaxBytesForEmbeddedObject() {
+ return EMB_OBJ_MAX_BYTES;
+ }
+
+ /**
+ * Bytes for embedded objects are currently cached in memory.
+ * If something goes wrong during the parsing of an embedded object,
+ * it is possible that a read length may be crazily too long
+ * and cause a heap crash.
+ *
+ * @param max maximum number of bytes to allow for embedded objects. If
+ * the embedded object has more than this number of bytes, skip it.
+ */
+ public static void setMaxBytesForEmbeddedObject(int max) {
+ EMB_OBJ_MAX_BYTES = max;
+ }
+
+ public Set<MediaType> getSupportedTypes(ParseContext context) {
+ return SUPPORTED_TYPES;
+ }
+
+ public void parse(
+ InputStream stream, ContentHandler handler,
+ Metadata metadata, ParseContext context)
+ throws IOException, SAXException, TikaException {
+ metadata.set(Metadata.CONTENT_TYPE, "application/rtf");
+ TaggedInputStream tagged = new TaggedInputStream(stream);
+ try {
+ XHTMLContentHandler xhtmlHandler = new XHTMLContentHandler(handler, metadata);
+ RTFEmbObjHandler embObjHandler = new RTFEmbObjHandler(xhtmlHandler, metadata, context);
+ final TextExtractor ert = new TextExtractor(xhtmlHandler, metadata, embObjHandler);
+ ert.extract(stream);
+ } catch (IOException e) {
+ tagged.throwIfCauseOf(e);
+ throw new TikaException("Error parsing an RTF document", e);
+ }
+ }
+}