Added a TikaConfigException, params getter

Project: http://git-wip-us.apache.org/repos/asf/tika/repo
Commit: http://git-wip-us.apache.org/repos/asf/tika/commit/64db9614
Tree: http://git-wip-us.apache.org/repos/asf/tika/tree/64db9614
Diff: http://git-wip-us.apache.org/repos/asf/tika/diff/64db9614

Branch: refs/heads/master
Commit: 64db9614cfaa3e873a9dc9efc6d201d887f6a4c5
Parents: ae51417
Author: Thamme Gowda <[email protected]>
Authored: Sat Mar 12 06:43:44 2016 -0800
Committer: Thamme Gowda <[email protected]>
Committed: Sat Mar 12 06:43:44 2016 -0800

----------------------------------------------------------------------
 .../java/org/apache/tika/base/Configurable.java | 32 ++++++++++++++--
 .../tika/exception/TikaConfigException.java     | 39 ++++++++++++++++++++
 .../org/apache/tika/parser/AbstractParser.java  | 15 +++++++-
 3 files changed, 81 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tika/blob/64db9614/tika-core/src/main/java/org/apache/tika/base/Configurable.java
----------------------------------------------------------------------
diff --git a/tika-core/src/main/java/org/apache/tika/base/Configurable.java 
b/tika-core/src/main/java/org/apache/tika/base/Configurable.java
index 8ae1b30..6f1c405 100644
--- a/tika-core/src/main/java/org/apache/tika/base/Configurable.java
+++ b/tika-core/src/main/java/org/apache/tika/base/Configurable.java
@@ -1,8 +1,26 @@
+/*
+ * 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.base;
 
-import org.apache.tika.exception.TikaException;
+import org.apache.tika.exception.TikaConfigException;
 import org.apache.tika.parser.ParseContext;
 
+import java.util.Map;
+
 /**
  * Defines contract for configurable services
  * @since Apache Tika 1.13
@@ -10,10 +28,16 @@ import org.apache.tika.parser.ParseContext;
 public interface Configurable {
 
     /**
-     * Confure an instance with Tika Context
+     * Configure an instance with Tika Context
      * @param context configuration instance in the form of context
-     * @throws TikaException when an instance fails to work at the given 
context
+     * @throws TikaConfigException when an instance fails to work at the given 
context
      * @since Apache Tika 1.13
      */
-    void configure(ParseContext context) throws TikaException;
+    void configure(ParseContext context) throws TikaConfigException;
+
+    /**
+     * Gets parameters of this configurable instance
+     * @return parameters in the form  of a map of key value pairs
+     */
+    Map<String, String> getParams();
 }

http://git-wip-us.apache.org/repos/asf/tika/blob/64db9614/tika-core/src/main/java/org/apache/tika/exception/TikaConfigException.java
----------------------------------------------------------------------
diff --git 
a/tika-core/src/main/java/org/apache/tika/exception/TikaConfigException.java 
b/tika-core/src/main/java/org/apache/tika/exception/TikaConfigException.java
new file mode 100644
index 0000000..1c01fb6
--- /dev/null
+++ b/tika-core/src/main/java/org/apache/tika/exception/TikaConfigException.java
@@ -0,0 +1,39 @@
+/*
+ * 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.exception;
+
+/**
+ * Tika Config Exception is an exception to occur when there is an error
+ * in Tika config file and/or one or more of the parsers failed to initialize
+ * from that erroneous config.
+ *
+ * @since Apache Tika 1.13
+ */
+public class TikaConfigException extends TikaException {
+
+    /**
+     * Creates an instance of exception
+     * @param msg message
+     */
+    public TikaConfigException(String msg) {
+        super(msg);
+    }
+
+    public TikaConfigException(String msg, Throwable cause) {
+        super(msg, cause);
+    }
+}

http://git-wip-us.apache.org/repos/asf/tika/blob/64db9614/tika-core/src/main/java/org/apache/tika/parser/AbstractParser.java
----------------------------------------------------------------------
diff --git a/tika-core/src/main/java/org/apache/tika/parser/AbstractParser.java 
b/tika-core/src/main/java/org/apache/tika/parser/AbstractParser.java
index 10f731e..72c8bbd 100644
--- a/tika-core/src/main/java/org/apache/tika/parser/AbstractParser.java
+++ b/tika-core/src/main/java/org/apache/tika/parser/AbstractParser.java
@@ -18,8 +18,10 @@ package org.apache.tika.parser;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Map;
 import java.util.Properties;
 
+import org.apache.tika.exception.TikaConfigException;
 import org.apache.tika.exception.TikaException;
 import org.apache.tika.metadata.Metadata;
 import org.xml.sax.ContentHandler;
@@ -66,7 +68,18 @@ public abstract class AbstractParser implements 
ConfigurableParser {
      * @since Apache Tika 1.13
      */
     @Override
-    public void configure(ParseContext context) throws TikaException {
+    public void configure(ParseContext context) throws TikaConfigException {
         this.context = context;
     }
+
+
+    /**
+     * Gets Parameters of this configurable instance
+     * @return a map of key value pairs
+     */
+    @Override
+    public Map<String, String> getParams() {
+        return this.context.getParams();
+    }
 }
+

Reply via email to