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 2018/05/31 20:13:08 UTC

[tika] 02/06: merge conflicts

This is an automated email from the ASF dual-hosted git repository.

tallison pushed a commit to branch branch_1x
in repository https://gitbox.apache.org/repos/asf/tika.git

commit 0e1f4e77e63ba1d72714af305e39ee9a208f622a
Author: tballison <ta...@mitre.org>
AuthorDate: Tue May 29 14:10:06 2018 -0400

    merge conflicts
---
 .../main/java/org/apache/tika/fork/ForkClient.java | 143 ++++++++++++++++-----
 .../main/java/org/apache/tika/fork/ForkParser.java |  63 ++++++++-
 .../main/java/org/apache/tika/fork/ForkServer.java |  91 +++++++++++--
 .../{parser => fork}/ParserFactoryFactory.java     |   7 +-
 .../tika/parser/AutoDetectParserFactory.java       |  63 +++++++++
 .../java/org/apache/tika/parser/ParserFactory.java |   3 +-
 .../tika/fork/UpperCasingContentHandler.java       |  23 ++++
 .../org/apache/tika/parser/mock/MockParser.java    |   2 +-
 .../org/apache/tika/parser/mock/VowelParser.java   |  60 +++++++++
 .../tika/config/TIKA-2653-vowel-parser-ae.xml      |  26 ++++
 .../tika/config/TIKA-2653-vowel-parser-iou.xml     |  26 ++++
 11 files changed, 460 insertions(+), 47 deletions(-)

diff --git a/tika-core/src/main/java/org/apache/tika/fork/ForkClient.java b/tika-core/src/main/java/org/apache/tika/fork/ForkClient.java
index 0dffd08..f48adfb 100644
--- a/tika-core/src/main/java/org/apache/tika/fork/ForkClient.java
+++ b/tika-core/src/main/java/org/apache/tika/fork/ForkClient.java
@@ -25,6 +25,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.NotSerializableException;
+import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.jar.JarEntry;
@@ -35,6 +36,7 @@ import org.apache.tika.exception.TikaException;
 import org.apache.tika.io.IOUtils;
 import org.apache.tika.sax.AbstractRecursiveParserWrapperHandler;
 import org.apache.tika.sax.RecursiveParserWrapperHandler;
+import org.apache.tika.utils.ProcessUtils;
 import org.xml.sax.ContentHandler;
 
 class ForkClient {
@@ -53,6 +55,107 @@ class ForkClient {
 
     private final InputStream error;
 
+    public ForkClient(Path tikaDir, ParserFactoryFactory parserFactoryFactory, List<String> java, long serverPulseMillis) throws IOException, TikaException {
+        jar = null;
+        loader = null;
+        boolean ok = false;
+        ProcessBuilder builder = new ProcessBuilder();
+        List<String> command = new ArrayList<>();
+        command.addAll(java);
+        command.add("-cp");
+        String dirString = tikaDir.toAbsolutePath().toString();
+        if (!dirString.endsWith("/")) {
+            dirString += "/*";
+        } else {
+            dirString += "/";
+        }
+        dirString = ProcessUtils.escapeCommandLine(dirString);
+        command.add(dirString);
+        command.add("org.apache.tika.fork.ForkServer");
+        command.add(Long.toString(serverPulseMillis));
+        builder.command(command);
+        builder.redirectError(ProcessBuilder.Redirect.INHERIT);
+        try {
+            this.process = builder.start();
+
+            this.output = new DataOutputStream(process.getOutputStream());
+            this.input = new DataInputStream(process.getInputStream());
+            this.error = process.getErrorStream();
+
+            waitForStartBeacon();
+            output.writeByte(ForkServer.INIT_PARSER_FACTORY_FACTORY);
+            output.flush();
+            sendObject(parserFactoryFactory, resources);
+
+            waitForStartBeacon();
+
+            ok = true;
+        } catch (Throwable t) {
+            t.printStackTrace();
+            throw t;
+        } finally {
+            if (!ok) {
+                close();
+            }
+        }
+    }
+
+    /**
+     *
+     * @param tikaDir directory containing jars from which to start the child server and load the Parser
+     * @param parserFactoryFactory factory to send to child process to build parser upon arrival
+     * @param classLoader class loader to use for non-parser resource (content-handler, etc.)
+     * @param java java commandline to use for the commandline server
+     * @param serverPulseMillis how often to check if the server has been active
+     * @throws IOException
+     * @throws TikaException
+     */
+    public ForkClient(Path tikaDir, ParserFactoryFactory parserFactoryFactory, ClassLoader classLoader,
+                      List<String> java, long serverPulseMillis) throws IOException, TikaException {
+        jar = null;
+        loader = null;
+        boolean ok = false;
+        ProcessBuilder builder = new ProcessBuilder();
+        List<String> command = new ArrayList<>();
+        command.addAll(java);
+        command.add("-cp");
+        String dirString = tikaDir.toAbsolutePath().toString();
+        if (!dirString.endsWith("/")) {
+            dirString += "/*";
+        } else {
+            dirString += "/";
+        }
+        dirString = ProcessUtils.escapeCommandLine(dirString);
+        command.add(dirString);
+        command.add("org.apache.tika.fork.ForkServer");
+        command.add(Long.toString(serverPulseMillis));
+        builder.command(command);
+        builder.redirectError(ProcessBuilder.Redirect.INHERIT);
+        try {
+            this.process = builder.start();
+
+            this.output = new DataOutputStream(process.getOutputStream());
+            this.input = new DataInputStream(process.getInputStream());
+            this.error = process.getErrorStream();
+
+            waitForStartBeacon();
+            output.writeByte(ForkServer.INIT_PARSER_FACTORY_FACTORY_LOADER);
+            output.flush();
+            sendObject(parserFactoryFactory, resources);
+            sendObject(classLoader, resources);
+            waitForStartBeacon();
+            ok = true;
+        } catch (Throwable t) {
+            t.printStackTrace();
+            throw t;
+        } finally {
+            if (!ok) {
+                close();
+            }
+        }
+    }
+
+
     public ForkClient(ClassLoader loader, Object object, List<String> java, long serverPulseMillis)
             throws IOException, TikaException {
         boolean ok = false;
@@ -66,8 +169,8 @@ class ForkClient {
             command.add("-jar");
             command.add(jar.getPath());
             command.add(Long.toString(serverPulseMillis));
-            builder.command(command);
             builder.redirectError(ProcessBuilder.Redirect.INHERIT);
+            builder.command(command);
             this.process = builder.start();
 
             this.output = new DataOutputStream(process.getOutputStream());
@@ -75,9 +178,11 @@ class ForkClient {
             this.error = process.getErrorStream();
 
             waitForStartBeacon();
-
+            output.writeByte(ForkServer.INIT_LOADER_PARSER);
+            output.flush();
             sendObject(loader, resources);
             sendObject(object, resources);
+            waitForStartBeacon();
 
             ok = true;
         } finally {
@@ -89,11 +194,15 @@ class ForkClient {
 
     private void waitForStartBeacon() throws IOException {
         while (true) {
-            consumeErrorStream();
             int type = input.read();
             if ((byte) type == ForkServer.READY) {
-                consumeErrorStream();
                 return;
+            } else if ((byte)type == ForkServer.FAILED_TO_START) {
+                throw new IOException("Server had a catastrophic initialization failure");
+            } else if (type == -1) {
+                throw new IOException("EOF while waiting for start beacon");
+            } else {
+                throw new IOException("Unexpected byte while waiting for start beacon: "+type);
             }
         }
     }
@@ -103,10 +212,8 @@ class ForkClient {
             output.writeByte(ForkServer.PING);
             output.flush();
             while (true) {
-                consumeErrorStream();
                 int type = input.read();
                 if (type == ForkServer.PING) {
-                    consumeErrorStream();
                     return true;
                 } else {
                     return false;
@@ -198,10 +305,8 @@ class ForkClient {
             throws IOException {
         output.flush();
         while (true) {
-            consumeErrorStream();
             int type = input.read();
             if (type == -1) {
-                consumeErrorStream();
                 throw new IOException(
                         "Lost connection to a forked server process");
             } else if (type == ForkServer.RESOURCE) {
@@ -223,26 +328,6 @@ class ForkClient {
     }
 
     /**
-     * Consumes all pending bytes from the standard error stream of the
-     * forked server process, and prints them out to the standard error
-     * stream of this process. This method should be called always before
-     * expecting some output from the server, to prevent the server from
-     * blocking due to a filled up pipe buffer of the error stream.
-     *
-     * @throws IOException if the error stream could not be read
-     */
-    private void consumeErrorStream() throws IOException {
-        int n;
-        while ((n = error.available()) > 0) {
-            byte[] b = new byte[n];
-            n = error.read(b);
-            if (n > 0) {
-                System.err.write(b, 0, n);
-            }
-        }
-    }
-
-    /**
      * Creates a temporary jar file that can be used to bootstrap the forked
      * server process. Remember to remove the file when no longer used.
      *
@@ -283,7 +368,7 @@ class ForkClient {
                     MemoryURLConnection.class,
                     MemoryURLStreamHandler.class,
                     MemoryURLStreamHandlerFactory.class,
-                    MemoryURLStreamRecord.class
+                    MemoryURLStreamRecord.class, TikaException.class
             };
             ClassLoader loader = ForkServer.class.getClassLoader();
             for (Class<?> klass : bootstrap) {
diff --git a/tika-core/src/main/java/org/apache/tika/fork/ForkParser.java b/tika-core/src/main/java/org/apache/tika/fork/ForkParser.java
index 94e8d35..d95a63d 100644
--- a/tika-core/src/main/java/org/apache/tika/fork/ForkParser.java
+++ b/tika-core/src/main/java/org/apache/tika/fork/ForkParser.java
@@ -18,6 +18,7 @@ package org.apache.tika.fork;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -33,7 +34,8 @@ import org.apache.tika.parser.AbstractParser;
 import org.apache.tika.parser.AutoDetectParser;
 import org.apache.tika.parser.ParseContext;
 import org.apache.tika.parser.Parser;
-import org.apache.tika.sax.AbstractRecursiveParserWrapperHandler;
+import org.apache.tika.parser.ParserFactory;
+import org.apache.tika.parser.ParserFactoryFactory;
 import org.apache.tika.sax.TeeContentHandler;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
@@ -43,10 +45,15 @@ public class ForkParser extends AbstractParser {
     /** Serial version UID */
     private static final long serialVersionUID = -4962742892274663950L;
 
+    //these are used by the legacy usage
     private final ClassLoader loader;
-
     private final Parser parser;
 
+    //these are used when the server builds a parser via a directory
+    //of jars, not via legacy bootstrap etc.
+    private final Path tikaBin;
+    private final ParserFactoryFactory parserFactoryFactory;
+
     /** Java command line */
     private List<String> java = Arrays.asList("java", "-Xmx32m");
 
@@ -60,6 +67,36 @@ public class ForkParser extends AbstractParser {
     private long serverPulseMillis = 5000;
 
     /**
+     * If you have a directory with, say, tike-app.jar and you want the child process/server to build a parser
+     * and run it from that -- so that you can keep all of those dependencies out of your client code, use
+     * this initializer.
+     *
+     * @param tikaBin directory containing the tika-app.jar or similar -- full jar including tika-core and all
+     *                desired parsers and dependencies
+     * @param factoryFactory
+     */
+    public ForkParser(Path tikaBin, ParserFactoryFactory factoryFactory) {
+        loader = null;
+        parser = null;
+        this.tikaBin = tikaBin;
+        this.parserFactoryFactory = factoryFactory;
+    }
+
+    /**
+     * <b>EXPERT</b>
+     * @param tikaBin directory containing the tika-app.jar or similar -- full jar including tika-core and all
+     *                desired parsers and dependencies
+     * @param parserFactoryFactory -- the factory to use to generate the parser factory in the child process/server
+     * @param classLoader to use for all classes besides the parser in the child process/server
+     */
+    public ForkParser(Path tikaBin, ParserFactoryFactory parserFactoryFactory, ClassLoader classLoader) {
+        parser = null;
+        loader = classLoader;
+        this.tikaBin = tikaBin;
+        this.parserFactoryFactory = parserFactoryFactory;
+    }
+
+    /**
      * @param loader The ClassLoader to use 
      * @param parser the parser to delegate to. This one cannot be another ForkParser
      */
@@ -67,6 +104,8 @@ public class ForkParser extends AbstractParser {
         if (parser instanceof ForkParser) {
             throw new IllegalArgumentException("The underlying parser of a ForkParser should not be a ForkParser, but a specific implementation.");
         }
+        this.tikaBin = null;
+        this.parserFactoryFactory = null;
         this.loader = loader;
         this.parser = parser;
     }
@@ -126,7 +165,8 @@ public class ForkParser extends AbstractParser {
 
     /**
      * Sets the command used to start the forked server process.
-     * The arguments "-jar" and "/path/to/bootstrap.jar" are
+     * The arguments "-jar" and "/path/to/bootstrap.jar"
+     * or "-cp" and "/path/to/tika_bin" are
      * appended to the given command when starting the process.
      * The default setting is {"java", "-Xmx32m"}.
      * <p/>
@@ -256,7 +296,7 @@ public class ForkParser extends AbstractParser {
 
             // Create a new process if there's room in the pool
             if (client == null && currentlyInUse < poolSize) {
-                client = new ForkClient(loader, parser, java, serverPulseMillis);
+                client = newClient();
             }
 
             // Ping the process, and get rid of it if it's inactive
@@ -279,6 +319,21 @@ public class ForkParser extends AbstractParser {
         }
     }
 
+    private ForkClient newClient() throws IOException, TikaException {
+
+        if (loader == null && parser == null && tikaBin != null && parserFactoryFactory != null) {
+            return new ForkClient(tikaBin, parserFactoryFactory, java, serverPulseMillis);
+        } else if (loader != null && parser != null && tikaBin == null && parserFactoryFactory == null) {
+           return new ForkClient(loader, parser, java, serverPulseMillis);
+        } else if (loader != null && parser == null && tikaBin != null && parserFactoryFactory != null) {
+            return new ForkClient(tikaBin, parserFactoryFactory, loader, java, serverPulseMillis);
+        } else {
+            //TODO: make this more useful
+            throw new IllegalStateException("Unexpected combination of state items");
+        }
+
+    }
+
     private synchronized void releaseClient(ForkClient client, boolean alive) {
         currentlyInUse--;
         if (currentlyInUse + pool.size() < poolSize && alive) {
diff --git a/tika-core/src/main/java/org/apache/tika/fork/ForkServer.java b/tika-core/src/main/java/org/apache/tika/fork/ForkServer.java
index 845113b..30690b9 100644
--- a/tika-core/src/main/java/org/apache/tika/fork/ForkServer.java
+++ b/tika-core/src/main/java/org/apache/tika/fork/ForkServer.java
@@ -16,6 +16,10 @@
  */
 package org.apache.tika.fork;
 
+import org.apache.tika.exception.TikaException;
+import org.apache.tika.parser.ParserFactory;
+import org.xml.sax.SAXException;
+
 import java.io.ByteArrayInputStream;
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
@@ -31,6 +35,8 @@ import java.util.zip.CheckedOutputStream;
 import java.util.zip.Checksum;
 
 import org.apache.tika.exception.TikaException;
+import org.apache.tika.parser.ParserFactory;
+import org.apache.tika.parser.ParserFactoryFactory;
 
 class ForkServer implements Runnable, Checksum {
 
@@ -46,6 +52,12 @@ class ForkServer implements Runnable, Checksum {
 
     public static final byte READY = 4;
 
+    public static final byte FAILED_TO_START = 5;
+
+    public static final byte INIT_PARSER_FACTORY_FACTORY = 6;
+    public static final byte INIT_LOADER_PARSER = 7;
+    public static final byte INIT_PARSER_FACTORY_FACTORY_LOADER = 8;
+
     //milliseconds to sleep before checking to see if there has been any reading/writing
     //If no reading or writing in this time, shutdown the server.
     private long serverPulseMillis = 5000;
@@ -84,6 +96,11 @@ class ForkServer implements Runnable, Checksum {
 
     private volatile boolean active = true;
 
+    //can't be class Parser because then you'd
+    //have to include that in bootstrap jar (legacy mode)
+    private Object parser;
+    private ClassLoader classLoader;
+
     /**
      * Sets up a forked server instance using the given stdin/out
      * communication channel.
@@ -114,14 +131,20 @@ class ForkServer implements Runnable, Checksum {
 
     public void processRequests() {
         try {
-            output.writeByte(READY);
-            output.flush();
-
-            ClassLoader loader = (ClassLoader) readObject(
-                    ForkServer.class.getClassLoader());
-            Thread.currentThread().setContextClassLoader(loader);
-
-            Object object = readObject(loader);
+            initializeParserAndLoader();
+        } catch (Throwable t) {
+            t.printStackTrace();
+            System.err.flush();
+            try {
+                output.writeByte(FAILED_TO_START);
+                output.flush();
+            } catch (IOException e) {
+                e.printStackTrace();
+                System.err.flush();
+            }
+            return;
+        }
+        try {
             while (true) {
                 int request = input.read();
                 if (request == -1) {
@@ -129,7 +152,7 @@ class ForkServer implements Runnable, Checksum {
                 } else if (request == PING) {
                     output.writeByte(PING);
                 } else if (request == CALL) {
-                    call(loader, object);
+                    call(classLoader, parser);
                 } else {
                     throw new IllegalStateException("Unexpected request");
                 }
@@ -141,6 +164,55 @@ class ForkServer implements Runnable, Checksum {
         System.err.flush();
     }
 
+    private void initializeParserAndLoader() throws IOException, ClassNotFoundException,
+            TikaException, SAXException {
+        output.writeByte(READY);
+        output.flush();
+
+        int configIndex = input.read();
+        if (configIndex == -1) {
+            throw new TikaException("eof! pipe closed?!");
+        }
+
+        Object firstObject = readObject(
+                ForkServer.class.getClassLoader());
+        switch (configIndex) {
+            case INIT_PARSER_FACTORY_FACTORY:
+                if (firstObject instanceof ParserFactoryFactory) {
+                    //the user has submitted a parser factory, but no class loader
+                    classLoader = ForkServer.class.getClassLoader();
+                    ParserFactory parserFactory = ((ParserFactoryFactory) firstObject).build();
+                    parser = parserFactory.build();
+                } else {
+                    throw new IllegalArgumentException("Expecting only one object of class ParserFactoryFactory");
+                }
+                break;
+            case INIT_LOADER_PARSER:
+                if (firstObject instanceof ClassLoader) {
+                    classLoader = (ClassLoader) firstObject;
+                    Thread.currentThread().setContextClassLoader(classLoader);
+                    //parser from parent process
+                    parser = readObject(classLoader);
+                } else {
+                    throw new IllegalArgumentException("Expecting ClassLoader followed by a Parser");
+                }
+                break;
+            case INIT_PARSER_FACTORY_FACTORY_LOADER:
+                if (firstObject instanceof ParserFactoryFactory) {
+                    //the user has submitted a parser factory and a class loader
+                    ParserFactory parserFactory = ((ParserFactoryFactory) firstObject).build();
+                    parser = parserFactory.build();
+                    classLoader = (ClassLoader) readObject(ForkServer.class.getClassLoader());
+                    Thread.currentThread().setContextClassLoader(classLoader);
+                } else {
+                    throw new IllegalStateException("Expecing ParserFactoryFactory followed by a class loader");
+                }
+                break;
+        }
+        output.writeByte(READY);
+        output.flush();
+    }
+
     private void call(ClassLoader loader, Object object) throws Exception {
         Method method = getMethod(object, input.readUTF());
         Object[] args =
@@ -186,7 +258,6 @@ class ForkServer implements Runnable, Checksum {
      * is expected to be preceded by a size integer, that is used for reading
      * the entire serialization into a memory before deserializing it.
      *
-     * @param input input stream from which the serialized object is read
      * @param loader class loader to be used for loading referenced classes
      * @throws IOException if the object could not be deserialized
      * @throws ClassNotFoundException if a referenced class is not found
diff --git a/tika-core/src/main/java/org/apache/tika/parser/ParserFactoryFactory.java b/tika-core/src/main/java/org/apache/tika/fork/ParserFactoryFactory.java
similarity index 96%
rename from tika-core/src/main/java/org/apache/tika/parser/ParserFactoryFactory.java
rename to tika-core/src/main/java/org/apache/tika/fork/ParserFactoryFactory.java
index e44ba80..f40d3ed 100644
--- a/tika-core/src/main/java/org/apache/tika/parser/ParserFactoryFactory.java
+++ b/tika-core/src/main/java/org/apache/tika/fork/ParserFactoryFactory.java
@@ -1,5 +1,3 @@
-package org.apache.tika.parser;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -17,7 +15,12 @@ package org.apache.tika.parser;
  * limitations under the License.
  */
 
+package org.apache.tika.fork;
+
+
+
 import org.apache.tika.exception.TikaException;
+import org.apache.tika.parser.ParserFactory;
 
 import java.io.Serializable;
 import java.lang.reflect.Constructor;
diff --git a/tika-core/src/main/java/org/apache/tika/parser/AutoDetectParserFactory.java b/tika-core/src/main/java/org/apache/tika/parser/AutoDetectParserFactory.java
new file mode 100644
index 0000000..d00f59d
--- /dev/null
+++ b/tika-core/src/main/java/org/apache/tika/parser/AutoDetectParserFactory.java
@@ -0,0 +1,63 @@
+/*
+ * 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;
+
+import org.apache.tika.config.TikaConfig;
+import org.apache.tika.exception.TikaException;
+import org.xml.sax.SAXException;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Map;
+
+/**
+ * Factory for an AutoDetectParser
+ */
+public class AutoDetectParserFactory extends ParserFactory {
+
+    /**
+     * Path to a tika-config file.  This must be a literal
+     * file or findable on the classpath.
+     */
+    public static final String TIKA_CONFIG_PATH = "tika_config_path";
+
+    public AutoDetectParserFactory(Map<String, String> args) {
+        super(args);
+    }
+
+    @Override
+    public Parser build() throws IOException, SAXException, TikaException {
+        String tikaConfigPath = args.remove(TIKA_CONFIG_PATH);
+        TikaConfig tikaConfig = null;
+        if (tikaConfigPath != null) {
+            if (Files.isReadable(Paths.get(tikaConfigPath))) {
+                tikaConfig = new TikaConfig(Paths.get(tikaConfigPath));
+            } else if (this.getClass().getResource(tikaConfigPath) != null) {
+                try (InputStream is = this.getClass().getResourceAsStream(tikaConfigPath)) {
+                    tikaConfig = new TikaConfig(is);
+                }
+            }
+        }
+        if (tikaConfig == null) {
+            tikaConfig = TikaConfig.getDefaultConfig();
+        }
+        return new AutoDetectParser(tikaConfig);
+    }
+}
diff --git a/tika-core/src/main/java/org/apache/tika/parser/ParserFactory.java b/tika-core/src/main/java/org/apache/tika/parser/ParserFactory.java
index c8a92e7..ab61785 100644
--- a/tika-core/src/main/java/org/apache/tika/parser/ParserFactory.java
+++ b/tika-core/src/main/java/org/apache/tika/parser/ParserFactory.java
@@ -19,6 +19,7 @@ package org.apache.tika.parser;
 
 
 import org.apache.tika.exception.TikaException;
+import org.xml.sax.SAXException;
 
 import java.io.IOException;
 import java.util.Map;
@@ -31,6 +32,6 @@ public abstract class ParserFactory {
         this.args = args;
     }
 
-    public abstract Parser build() throws IOException, TikaException;
+    public abstract Parser build() throws IOException, SAXException, TikaException;
 
 }
diff --git a/tika-core/src/test/java/org/apache/tika/fork/UpperCasingContentHandler.java b/tika-core/src/test/java/org/apache/tika/fork/UpperCasingContentHandler.java
new file mode 100644
index 0000000..035288a
--- /dev/null
+++ b/tika-core/src/test/java/org/apache/tika/fork/UpperCasingContentHandler.java
@@ -0,0 +1,23 @@
+package org.apache.tika.fork;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import java.util.Locale;
+
+public class UpperCasingContentHandler extends DefaultHandler {
+    StringBuilder sb = new StringBuilder();
+
+    @Override
+    public void characters(char[] ch, int start, int length)
+            throws SAXException {
+        String chars = new String(ch, start, length);
+        sb.append(chars.toUpperCase(Locale.US));
+    }
+
+    @Override
+    public String toString() {
+        return sb.toString();
+    }
+
+}
diff --git a/tika-core/src/test/java/org/apache/tika/parser/mock/MockParser.java b/tika-core/src/test/java/org/apache/tika/parser/mock/MockParser.java
index 510ca69..f162502 100644
--- a/tika-core/src/test/java/org/apache/tika/parser/mock/MockParser.java
+++ b/tika-core/src/test/java/org/apache/tika/parser/mock/MockParser.java
@@ -256,7 +256,7 @@ public class MockParser extends AbstractParser {
         }
     }
 
-    private void write(Node action, XHTMLContentHandler xhtml) throws SAXException {
+    protected void write(Node action, XHTMLContentHandler xhtml) throws SAXException {
         NamedNodeMap attrs = action.getAttributes();
         Node eNode = attrs.getNamedItem("element");
         String elementType = "p";
diff --git a/tika-core/src/test/java/org/apache/tika/parser/mock/VowelParser.java b/tika-core/src/test/java/org/apache/tika/parser/mock/VowelParser.java
new file mode 100644
index 0000000..f3ef4a0
--- /dev/null
+++ b/tika-core/src/test/java/org/apache/tika/parser/mock/VowelParser.java
@@ -0,0 +1,60 @@
+/*
+ * 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.mock;
+
+
+
+
+import org.apache.tika.config.Field;
+import org.apache.tika.sax.XHTMLContentHandler;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * only parses vowels as specified in "vowel" field.
+ */
+public class VowelParser extends MockParser {
+
+    private static final long serialVersionUID = 1L;
+
+    @Field
+    private String vowel = "aeiou";
+
+    protected void write(Node action, XHTMLContentHandler xhtml) throws SAXException {
+        NamedNodeMap attrs = action.getAttributes();
+        Node eNode = attrs.getNamedItem("element");
+        String elementType = "p";
+        if (eNode != null) {
+            elementType = eNode.getTextContent();
+        }
+        String text = action.getTextContent();
+        StringBuilder sb = new StringBuilder();
+        Matcher m = Pattern.compile("(?i)(["+vowel+"])").matcher(text);
+        while (m.find()) {
+            sb.append(m.group(1));
+        }
+        xhtml.startElement(elementType);
+        xhtml.characters(sb.toString());
+        xhtml.endElement(elementType);
+    }
+
+}
diff --git a/tika-core/src/test/resources/org/apache/tika/config/TIKA-2653-vowel-parser-ae.xml b/tika-core/src/test/resources/org/apache/tika/config/TIKA-2653-vowel-parser-ae.xml
new file mode 100644
index 0000000..c0da793
--- /dev/null
+++ b/tika-core/src/test/resources/org/apache/tika/config/TIKA-2653-vowel-parser-ae.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<properties>
+  <parsers>
+    <parser class="org.apache.tika.parser.mock.VowelParser">
+      <params>
+        <param name="vowel" type="string">ae</param>
+      </params>
+    </parser>
+  </parsers>
+</properties>
diff --git a/tika-core/src/test/resources/org/apache/tika/config/TIKA-2653-vowel-parser-iou.xml b/tika-core/src/test/resources/org/apache/tika/config/TIKA-2653-vowel-parser-iou.xml
new file mode 100644
index 0000000..c04849b
--- /dev/null
+++ b/tika-core/src/test/resources/org/apache/tika/config/TIKA-2653-vowel-parser-iou.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<properties>
+  <parsers>
+    <parser class="org.apache.tika.parser.mock.VowelParser">
+      <params>
+        <param name="vowel" type="string">iou</param>
+      </params>
+    </parser>
+  </parsers>
+</properties>

-- 
To stop receiving notification emails like this one, please contact
tallison@apache.org.