You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ma...@apache.org on 2012/03/23 09:49:22 UTC

svn commit: r1304232 - in /tika/trunk/tika-server/src/main/java/org/apache/tika/server: RichTextContentHandler.java TikaResource.java

Author: maxcom
Date: Fri Mar 23 08:49:22 2012
New Revision: 1304232

URL: http://svn.apache.org/viewvc?rev=1304232&view=rev
Log:
TikaResource: extract anonymous class

Added:
    tika/trunk/tika-server/src/main/java/org/apache/tika/server/RichTextContentHandler.java
Modified:
    tika/trunk/tika-server/src/main/java/org/apache/tika/server/TikaResource.java

Added: tika/trunk/tika-server/src/main/java/org/apache/tika/server/RichTextContentHandler.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-server/src/main/java/org/apache/tika/server/RichTextContentHandler.java?rev=1304232&view=auto
==============================================================================
--- tika/trunk/tika-server/src/main/java/org/apache/tika/server/RichTextContentHandler.java (added)
+++ tika/trunk/tika-server/src/main/java/org/apache/tika/server/RichTextContentHandler.java Fri Mar 23 08:49:22 2012
@@ -0,0 +1,47 @@
+/*
+ * 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.server;
+
+import org.apache.tika.sax.WriteOutContentHandler;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+import java.io.Writer;
+
+class RichTextContentHandler extends WriteOutContentHandler {
+  public RichTextContentHandler(Writer writer) {
+    super(writer);
+  }
+
+  @Override
+  public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+    super.startElement(uri, localName, qName, attributes);
+
+    if ("img".equals(localName) && attributes.getValue("alt")!=null) {
+      String nfo = "[image: "+attributes.getValue("alt")+ ']';
+
+      characters(nfo.toCharArray(), 0, nfo.length());
+    }
+
+    if ("a".equals(localName) && attributes.getValue("name")!=null) {
+      String nfo = "[bookmark: "+attributes.getValue("name")+ ']';
+
+      characters(nfo.toCharArray(), 0, nfo.length());
+    }
+  }
+}

Modified: tika/trunk/tika-server/src/main/java/org/apache/tika/server/TikaResource.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-server/src/main/java/org/apache/tika/server/TikaResource.java?rev=1304232&r1=1304231&r2=1304232&view=diff
==============================================================================
--- tika/trunk/tika-server/src/main/java/org/apache/tika/server/TikaResource.java (original)
+++ tika/trunk/tika-server/src/main/java/org/apache/tika/server/TikaResource.java Fri Mar 23 08:49:22 2012
@@ -33,8 +33,6 @@ import org.apache.tika.parser.ParseConte
 import org.apache.tika.parser.Parser;
 import org.apache.tika.parser.html.HtmlParser;
 import org.apache.tika.sax.BodyContentHandler;
-import org.apache.tika.sax.WriteOutContentHandler;
-import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 
@@ -130,24 +128,7 @@ public class TikaResource {
       public void write(OutputStream outputStream) throws IOException, WebApplicationException {
         Writer writer = new OutputStreamWriter(outputStream, "UTF-8");
 
-        BodyContentHandler body = new BodyContentHandler(new WriteOutContentHandler(writer) {
-          @Override
-          public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
-            super.startElement(uri, localName, qName, attributes);
-
-            if ("img".equals(localName) && attributes.getValue("alt")!=null) {
-              String nfo = "[image: "+attributes.getValue("alt")+ ']';
-
-              characters(nfo.toCharArray(), 0, nfo.length());
-            }
-
-            if ("a".equals(localName) && attributes.getValue("name")!=null) {
-              String nfo = "[bookmark: "+attributes.getValue("name")+ ']';
-
-              characters(nfo.toCharArray(), 0, nfo.length());
-            }
-          }
-        });
+        BodyContentHandler body = new BodyContentHandler(new RichTextContentHandler(writer));
 
         TikaInputStream tis = TikaInputStream.get(is);