[
https://issues.apache.org/jira/browse/SOLR-8166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14962005#comment-14962005
]
ASF GitHub Bot commented on SOLR-8166:
--------------------------------------
Github user uschindler commented on a diff in the pull request:
https://github.com/apache/lucene-solr/pull/206#discussion_r42311748
--- Diff:
solr/contrib/extraction/src/java/org/apache/solr/handler/extraction/ParseContextConfig.java
---
@@ -0,0 +1,113 @@
+package org.apache.solr.handler.extraction;
+
+/*
+ * 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.
+ */
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.File;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tika.parser.ParseContext;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class ParseContextConfig {
+ private Map<Class, Object> entries = new HashMap<>();
+
+ public ParseContextConfig() {
+ }
+
+ public ParseContextConfig(Element element, ClassLoader loader) throws
Exception {
+ extract(element, loader);
+ }
+
+ public ParseContextConfig(Document document, ClassLoader loader) throws
Exception {
+ this(document.getDocumentElement(), loader);
+ }
+
+ public ParseContextConfig(String fileName, ClassLoader loader) throws
Exception {
+ this(getBuilder().parse(fileName), loader);
+ }
+
+ public ParseContextConfig(File file, ClassLoader loader) throws
Exception {
+ this(getBuilder().parse(file), loader);
+ }
+
+ private static DocumentBuilder getBuilder() throws Exception {
+ return DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ }
+
+ private void extract(Element element, ClassLoader loader) throws
Exception {
+ final NodeList xmlEntries = element.getElementsByTagName("entry");
+ for (int i = 0; i < xmlEntries.getLength(); i++) {
+ final NamedNodeMap xmlEntryAttributes =
xmlEntries.item(i).getAttributes();
+ final String className =
xmlEntryAttributes.getNamedItem("class").getNodeValue();
+ final String implementationName =
xmlEntryAttributes.getNamedItem("value").getNodeValue();
+
+ final NodeList xmlProperties =
((Element)xmlEntries.item(i)).getElementsByTagName("property");
+
+ final Class<?> interfaceClass = loader.loadClass(className);
+ final Class<?> implementationClass =
loader.loadClass(implementationName);
+ final Object instance = implementationClass.newInstance();
+
+ for (int j = 0; j < xmlProperties.getLength(); j++) {
+ final Node xmlProperty = xmlProperties.item(j);
+ final NamedNodeMap xmlPropertyAttributes =
xmlProperty.getAttributes();
+
+ final String propertyName =
xmlPropertyAttributes.getNamedItem("name").getNodeValue();
+ final String propertyValue =
xmlPropertyAttributes.getNamedItem("value").getNodeValue();
+
+ final Field declaredField =
interfaceClass.getDeclaredField(propertyName);
+ final Class<?> type = declaredField.getType();
+ final Method declaredMethod =
interfaceClass.getDeclaredMethod("set" + propertyName.substring(0,
1).toUpperCase() + propertyName.substring(1, propertyName.length()), type);
--- End diff --
This does not work in Turkey! :-) Don't use String#toUpper/LowerCase()
without giving a Locale (Locale.ROOT is needed here)
> Introduce possibility to configure ParseContext in
> ExtractingRequestHandler/ExtractingDocumentLoader
> ----------------------------------------------------------------------------------------------------
>
> Key: SOLR-8166
> URL: https://issues.apache.org/jira/browse/SOLR-8166
> Project: Solr
> Issue Type: Improvement
> Components: contrib - Solr Cell (Tika extraction)
> Affects Versions: 5.3
> Reporter: Andriy Binetsky
> Assignee: Uwe Schindler
>
> Actually there is no possibility to hand over some additional configuration
> by document extracting with ExtractingRequestHandler/ExtractingDocumentLoader.
> For example I need to put org.apache.tika.parser.pdf.PDFParserConfig with
> "extractInlineImages" set to true in ParseContext to trigger extraction/OCR
> recognizing of embedded images from pdf.
> It would be nice to have possibility to configure created ParseContext due
> xml-config file like TikaConfig does.
> I would suggest to have following:
> solrconfig.xml:
> <requestHandler name="/update/extract"
> class="org.apache.solr.handler.extraction.ExtractingRequestHandler">
> <str name="parseContext.config">parseContext.config</str>
> </requestHandler>
> parseContext.config:
> <entries>
> <entry class="org.apache.tika.parser.pdf.PDFParserConfig"
> value="org.apache.tika.parser.pdf.PDFParserConfig">
> <property name="extractInlineImages" value="true"/>
> </entry>
> </entries>
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]