cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [1/2] git commit: CXF-5549: Introduce Tika Search Visitor. Added ParamConverterProvider and DefaultParamConverterProvider implementation
Date Fri, 04 Jul 2014 14:46:52 GMT
Repository: cxf
Updated Branches:
  refs/heads/master fb690c029 -> c5752fd7e


CXF-5549: Introduce Tika Search Visitor. Added ParamConverterProvider and DefaultParamConverterProvider
implementation


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/3a373f17
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/3a373f17
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/3a373f17

Branch: refs/heads/master
Commit: 3a373f172876808b6b14795a6c576db6fdec5cf4
Parents: 2f4bd49
Author: reta <drreta@gmail.com>
Authored: Fri Jul 4 10:46:32 2014 -0400
Committer: reta <drreta@gmail.com>
Committed: Fri Jul 4 10:46:32 2014 -0400

----------------------------------------------------------------------
 .../ext/search/tika/LuceneDocumentMetadata.java | 14 +++++
 .../search/tika/TikaLuceneContentExtractor.java | 54 ++++++++++++++++----
 .../visitor/AbstractSearchConditionVisitor.java | 11 ++++
 3 files changed, 69 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/3a373f17/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/tika/LuceneDocumentMetadata.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/tika/LuceneDocumentMetadata.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/tika/LuceneDocumentMetadata.java
index 3223823..dcb8f5a 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/tika/LuceneDocumentMetadata.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/tika/LuceneDocumentMetadata.java
@@ -21,9 +21,14 @@ package org.apache.cxf.jaxrs.ext.search.tika;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
+import javax.ws.rs.ext.ParamConverterProvider;
+
+import org.apache.cxf.jaxrs.ext.search.DefaultParamConverterProvider;
+
 public class LuceneDocumentMetadata {
     private final Map< String, Class< ? > > fieldTypes;
     private final String contentFieldName;
+    private ParamConverterProvider converterProvider = new DefaultParamConverterProvider();
     
     public LuceneDocumentMetadata() {
         this("contents");
@@ -44,6 +49,11 @@ public class LuceneDocumentMetadata {
         return this;
     }
     
+    public LuceneDocumentMetadata withFieldTypeConverter(final ParamConverterProvider provider)
{
+        this.converterProvider = provider;
+        return this;
+    }
+    
     public String getContentFieldName() {
         return contentFieldName;
     }
@@ -55,4 +65,8 @@ public class LuceneDocumentMetadata {
     public Map<String, Class<?>> getFieldTypes() {
         return fieldTypes;
     }    
+    
+    public ParamConverterProvider getFieldTypeConverter() {
+        return converterProvider;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/3a373f17/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/tika/TikaLuceneContentExtractor.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/tika/TikaLuceneContentExtractor.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/tika/TikaLuceneContentExtractor.java
index f182db2..0f78791 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/tika/TikaLuceneContentExtractor.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/tika/TikaLuceneContentExtractor.java
@@ -19,13 +19,14 @@
 package org.apache.cxf.jaxrs.ext.search.tika;
 
 import java.io.InputStream;
+import java.lang.annotation.Annotation;
 import java.util.Date;
 import java.util.List;
 
-import org.apache.cxf.jaxrs.ext.search.SearchUtils;
+import javax.ws.rs.ext.ParamConverter;
+import javax.ws.rs.ext.ParamConverterProvider;
+
 import org.apache.cxf.jaxrs.ext.search.tika.TikaContentExtractor.TikaContent;
-import org.apache.lucene.document.DateTools;
-import org.apache.lucene.document.DateTools.Resolution;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.DoubleField;
 import org.apache.lucene.document.Field;
@@ -197,28 +198,61 @@ public class TikaLuceneContentExtractor {
         return new TextField(documentMetadata.getContentFieldName(), content, Store.YES);
     }
     
+    @SuppressWarnings("unchecked")
+    private static< T > T getValue(final Class< T > type, final ParamConverterProvider
provider, 
+            final String value) {
+        
+        if (String.class.isAssignableFrom(type)) {
+            return (T)value;
+        }
+        
+        if (provider != null) {        
+            final ParamConverter< T > converter = provider.getConverter(type, null,
new Annotation[0]);
+            if (converter != null) {
+                return converter.fromString(value);
+            }
+        }
+               
+        throw new IllegalArgumentException(String.format(
+                "Unable to convert string '%s' to instance of class '%s': no appropriate
converter provided",
+                value, type.getName()));        
+    }
+    
+    private static< T > String getString(final Class< T > type, final ParamConverterProvider
provider, 
+            final T value) {
+        
+        if (provider != null) {        
+            final ParamConverter< T > converter = provider.getConverter(type, null,
new Annotation[0]);
+            if (converter != null) {
+                return converter.toString(value);
+            }
+        }
+               
+        return value == null ? null : value.toString();         
+    }
+    
     private static Field getField(final LuceneDocumentMetadata documentMetadata, 
                                   final String name, final String value) { 
         final Class< ? > type = documentMetadata.getFieldType(name);
+        final ParamConverterProvider provider = documentMetadata.getFieldTypeConverter();
         
         if (type != null) {
             if (Number.class.isAssignableFrom(type)) {
                 if (Double.class.isAssignableFrom(type)) {
-                    return new DoubleField(name, Double.valueOf(value), Store.YES);
+                    return new DoubleField(name, getValue(Double.class, provider, value),
Store.YES);
                 } else if (Float.class.isAssignableFrom(type)) {
-                    return new FloatField(name, Float.valueOf(value), Store.YES);
+                    return new FloatField(name, getValue(Float.class, provider, value), Store.YES);
                 } else if (Long.class.isAssignableFrom(type)) {
-                    return new LongField(name, Long.valueOf(value), Store.YES);
+                    return new LongField(name, getValue(Long.class, provider, value), Store.YES);
                 } else if (Integer.class.isAssignableFrom(type) || Byte.class.isAssignableFrom(type))
{
-                    return new IntField(name, Integer.valueOf(value), Store.YES);
+                    return new IntField(name, getValue(Integer.class, provider, value), Store.YES);
                 }
             } else if (Date.class.isAssignableFrom(type)) {
-                final Date date = SearchUtils.dateFromStringWithDefaultFormats(value);  
             
+                final Date date = getValue(Date.class, provider, value);                
                 Field field = null;
                 
                 if (date != null) {
-                    field = new StringField(name, DateTools.dateToString(date, Resolution.MILLISECOND),

-                        Store.YES);
+                    field = new StringField(name, getString(Date.class, provider, date),
Store.YES);
                 } else {
                     field = new StringField(name, value, Store.YES); 
                 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/3a373f17/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java
index 574a7f4..98259bd 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java
@@ -25,6 +25,8 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
+import javax.ws.rs.ext.ParamConverterProvider;
+
 import org.apache.cxf.jaxrs.ext.search.PrimitiveStatement;
 import org.apache.cxf.jaxrs.ext.search.SearchConditionVisitor;
 import org.apache.cxf.jaxrs.ext.search.collections.CollectionCheckInfo;
@@ -37,6 +39,7 @@ public abstract class AbstractSearchConditionVisitor <T, E> implements
SearchCon
     private Map<String, String> fieldMap;
     private Map<String, Class<?>> primitiveFieldTypeMap;
     private PropertyValidator<Object> validator;
+    private ParamConverterProvider converterProvider;
     private boolean wildcardStringMatch;
     
     protected AbstractSearchConditionVisitor(Map<String, String> fieldMap) {
@@ -178,4 +181,12 @@ public abstract class AbstractSearchConditionVisitor <T, E> implements
SearchCon
     public void setWildcardStringMatch(boolean wildcardStringMatch) {
         this.wildcardStringMatch = wildcardStringMatch;
     }
+    
+    public void setFieldTypeConverter(final ParamConverterProvider provider) {
+        this.converterProvider = provider;
+    }
+    
+    public ParamConverterProvider getFieldTypeConverter() {
+        return converterProvider;
+    }
 }


Mime
View raw message