You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ni...@apache.org on 2016/02/25 19:20:17 UTC
[2/4] tika git commit: TIKA-1870 JavaDoc and Test coverage for
RichTextContentHandler that lived in tika-server
TIKA-1870 JavaDoc and Test coverage for RichTextContentHandler that lived in tika-server
Project: http://git-wip-us.apache.org/repos/asf/tika/repo
Commit: http://git-wip-us.apache.org/repos/asf/tika/commit/3b7922db
Tree: http://git-wip-us.apache.org/repos/asf/tika/tree/3b7922db
Diff: http://git-wip-us.apache.org/repos/asf/tika/diff/3b7922db
Branch: refs/heads/master
Commit: 3b7922db1a2e72181e1a00168d2aee33bfe1d4a3
Parents: 0bd05ce
Author: John Patrick <nh...@gmail.com>
Authored: Wed Feb 24 15:47:53 2016 +0000
Committer: John Patrick <nh...@gmail.com>
Committed: Wed Feb 24 15:47:53 2016 +0000
----------------------------------------------------------------------
.../apache/tika/sax/RichTextContentHandler.java | 12 ++++
.../tika/sax/RichTextContentHandlerTest.java | 75 ++++++++++++++++++++
2 files changed, 87 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tika/blob/3b7922db/tika-core/src/main/java/org/apache/tika/sax/RichTextContentHandler.java
----------------------------------------------------------------------
diff --git a/tika-core/src/main/java/org/apache/tika/sax/RichTextContentHandler.java b/tika-core/src/main/java/org/apache/tika/sax/RichTextContentHandler.java
index 7ab7835..8fcc4d5 100644
--- a/tika-core/src/main/java/org/apache/tika/sax/RichTextContentHandler.java
+++ b/tika-core/src/main/java/org/apache/tika/sax/RichTextContentHandler.java
@@ -22,7 +22,19 @@ import java.io.Writer;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
+/**
+ * Content handler for Rich Text, it will extract XHTML <img/>
+ * tag <alt/> attribute and XHTML <a/> tag <name/>
+ * attribute into the output.
+ */
public class RichTextContentHandler extends WriteOutContentHandler {
+
+ /**
+ * Creates a content handler that writes XHTML body character events to
+ * the given writer.
+ *
+ * @param writer writer
+ */
public RichTextContentHandler(Writer writer) {
super(writer);
}
http://git-wip-us.apache.org/repos/asf/tika/blob/3b7922db/tika-core/src/test/java/org/apache/tika/sax/RichTextContentHandlerTest.java
----------------------------------------------------------------------
diff --git a/tika-core/src/test/java/org/apache/tika/sax/RichTextContentHandlerTest.java b/tika-core/src/test/java/org/apache/tika/sax/RichTextContentHandlerTest.java
new file mode 100644
index 0000000..257ea38
--- /dev/null
+++ b/tika-core/src/test/java/org/apache/tika/sax/RichTextContentHandlerTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.sax;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStreamWriter;
+import java.nio.charset.Charset;
+
+import org.apache.tika.metadata.Metadata;
+import org.junit.Test;
+import org.xml.sax.helpers.AttributesImpl;
+
+/**
+ * Test cases for the {@link RichTextContentHandler} class.
+ */
+public class RichTextContentHandlerTest {
+
+ /**
+ * Test to check img tags are detected and rich text version used.
+ */
+ @Test
+ public void aTagTest() throws Exception {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+
+ XHTMLContentHandler xhtml = new XHTMLContentHandler(
+ new RichTextContentHandler(
+ new OutputStreamWriter(buffer, Charset.defaultCharset())),
+ new Metadata());
+ xhtml.startDocument();
+ AttributesImpl attributes = new AttributesImpl();
+ attributes.addAttribute("", "", "name", "", "value");
+ xhtml.startElement("a", attributes);
+ xhtml.endDocument();
+
+ assertEquals("\n\n\n\n[bookmark: value]", buffer.toString(UTF_8.name()));
+ }
+
+ /**
+ * Test to check a tags are detected and rich text version used.
+ */
+ @Test
+ public void imgTagTest() throws Exception {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+
+ XHTMLContentHandler xhtml = new XHTMLContentHandler(
+ new RichTextContentHandler(
+ new OutputStreamWriter(buffer, Charset.defaultCharset())),
+ new Metadata());
+ xhtml.startDocument();
+ AttributesImpl attributes = new AttributesImpl();
+ attributes.addAttribute("", "", "alt", "", "value");
+ xhtml.startElement("img", attributes);
+ xhtml.endDocument();
+
+ assertEquals("\n\n\n\n[image: value]", buffer.toString(UTF_8.name()));
+ }
+
+}