You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by th...@apache.org on 2015/04/13 10:46:36 UTC

svn commit: r1673138 - in /tika/trunk/tika-parsers/src: main/java/org/apache/tika/parser/odf/OpenDocumentContentParser.java test/java/org/apache/tika/parser/odf/OpenDocumentParserTest.java test/resources/test-documents/testODT-TIKA-6000.odt

Author: thaichat04
Date: Mon Apr 13 08:46:36 2015
New Revision: 1673138

URL: http://svn.apache.org/r1673138
Log:
TIKA-6000 - Fixing NPE when having style in footnote

Added:
    tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/odf/OpenDocumentParserTest.java   (with props)
    tika/trunk/tika-parsers/src/test/resources/test-documents/testODT-TIKA-6000.odt   (with props)
Modified:
    tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/odf/OpenDocumentContentParser.java

Modified: tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/odf/OpenDocumentContentParser.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/odf/OpenDocumentContentParser.java?rev=1673138&r1=1673137&r2=1673138&view=diff
==============================================================================
--- tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/odf/OpenDocumentContentParser.java (original)
+++ tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/odf/OpenDocumentContentParser.java Mon Apr 13 08:46:36 2015
@@ -169,6 +169,9 @@ public class OpenDocumentContentParser e
 		    }
 
             TextStyle style = textStyleMap.get(name);
+            if (style == null) {
+              return;
+            }
 
             // End tags that refer to no longer valid styles
             if (!style.underlined && lastTextStyle != null && lastTextStyle.underlined) {
@@ -224,7 +227,7 @@ public class OpenDocumentContentParser e
 		        String namespaceURI, String localName, String qName,
 		        Attributes attrs) throws SAXException {
 		    // keep track of current node type. If it is a text node,
-		    // a bit at the current depth ist set in textNodeStack.
+		    // a bit at the current depth its set in textNodeStack.
 		    // characters() checks the top bit to determine, if the
 		    // actual node is a text node to print out nodeDepth contains
 		    // the depth of the current node and also marks top of stack.

Added: tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/odf/OpenDocumentParserTest.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/odf/OpenDocumentParserTest.java?rev=1673138&view=auto
==============================================================================
--- tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/odf/OpenDocumentParserTest.java (added)
+++ tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/odf/OpenDocumentParserTest.java Mon Apr 13 08:46:36 2015
@@ -0,0 +1,56 @@
+/*
+ * 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.odf;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.InputStream;
+
+import org.apache.tika.TikaTest;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.parser.ParseContext;
+import org.apache.tika.parser.Parser;
+import org.apache.tika.sax.BodyContentHandler;
+import org.junit.Test;
+import org.xml.sax.ContentHandler;
+
+
+public class OpenDocumentParserTest extends TikaTest {
+  
+  @Test
+  public void can_parse_odt_file_with_styles_tika_6000() throws Exception {
+      Parser parser = new OpenDocumentParser();
+      InputStream input = ODFParserTest.class.getResourceAsStream("/test-documents/testODT-TIKA-6000.odt");
+      try {
+         Metadata metadata = new Metadata();
+         ContentHandler handler = new BodyContentHandler();
+         parser.parse(input, handler, metadata, new ParseContext());
+
+         assertEquals("application/vnd.oasis.opendocument.text", metadata.get(Metadata.CONTENT_TYPE));
+
+         String content = handler.toString();
+         
+         assertContains("Utilisation de ce document", content);
+         assertContains("Copyright and License", content);
+         assertContains("Changer la langue", content);
+         assertContains("La page d’accueil permet de faire une recherche simple", content);                
+      } finally {
+         input.close();
+      }
+  }
+
+}

Propchange: tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/odf/OpenDocumentParserTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tika/trunk/tika-parsers/src/test/resources/test-documents/testODT-TIKA-6000.odt
URL: http://svn.apache.org/viewvc/tika/trunk/tika-parsers/src/test/resources/test-documents/testODT-TIKA-6000.odt?rev=1673138&view=auto
==============================================================================
Binary file - no diff available.

Propchange: tika/trunk/tika-parsers/src/test/resources/test-documents/testODT-TIKA-6000.odt
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream