lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From no...@apache.org
Subject svn commit: r881724 - in /lucene/solr/trunk/contrib/dataimporthandler/src: main/java/org/apache/solr/handler/dataimport/ test/java/org/apache/solr/handler/dataimport/
Date Wed, 18 Nov 2009 11:22:18 GMT
Author: noble
Date: Wed Nov 18 11:22:17 2009
New Revision: 881724

URL: http://svn.apache.org/viewvc?rev=881724&view=rev
Log:
SOLR-1525 allow DIH to refer to core properties

Modified:
    lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DocBuilder.java
    lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/VariableResolverImpl.java
    lucene/solr/trunk/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestVariableResolver.java

Modified: lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DocBuilder.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DocBuilder.java?rev=881724&r1=881723&r2=881724&view=diff
==============================================================================
--- lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DocBuilder.java
(original)
+++ lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DocBuilder.java
Wed Nov 18 11:22:17 2009
@@ -80,7 +80,9 @@
 
   public VariableResolverImpl getVariableResolver() {
     try {
-      VariableResolverImpl resolver = new VariableResolverImpl();
+      VariableResolverImpl resolver = null;
+      if(dataImporter != null && dataImporter.getCore() != null) resolver =  new
VariableResolverImpl(dataImporter.getCore().getResourceLoader().getCoreProperties());
+      else resolver = new VariableResolverImpl();
       Map<String, Object> indexerNamespace = new HashMap<String, Object>();
       if (persistedProperties.getProperty(LAST_INDEX_TIME) != null) {
         indexerNamespace.put(LAST_INDEX_TIME, persistedProperties.getProperty(LAST_INDEX_TIME));

Modified: lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/VariableResolverImpl.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/VariableResolverImpl.java?rev=881724&r1=881723&r2=881724&view=diff
==============================================================================
--- lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/VariableResolverImpl.java
(original)
+++ lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/VariableResolverImpl.java
Wed Nov 18 11:22:17 2009
@@ -18,6 +18,7 @@
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Collections;
 import java.util.regex.Pattern;
 
 /**
@@ -41,7 +42,14 @@
 
   private final TemplateString templateString = new TemplateString();
 
+  private final Map defaults ;
+
   public VariableResolverImpl() {
+    defaults = Collections.emptyMap();
+  }
+
+  public VariableResolverImpl(Map defaults) {
+    this.defaults = defaults;
   }
 
   /**
@@ -100,23 +108,30 @@
       for (int i = 0; i < parts.length; i++) {
         String thePart = parts[i];
         if (i == parts.length - 1) {
-          return namespace.get(thePart);
+          Object val = namespace.get(thePart);
+          return val == null ? getDefault(name): val ;
         }
         Object temp = namespace.get(thePart);
         if (temp == null) {
-          return namespace.get(mergeAll(parts, i));
+          Object val = namespace.get(mergeAll(parts, i));
+          return val == null ? getDefault(name): val ;
         } else {
           if (temp instanceof Map) {
             namespace = (Map) temp;
           } else {
-            return null;
+            return getDefault(name);
           }
         }
       }
     } finally {
-      CURRENT_VARIABLE_RESOLVER.set(null);
+      CURRENT_VARIABLE_RESOLVER.remove();
     }
-    return null;
+    return getDefault(name);
+  }
+
+  private Object getDefault(String name) {
+    Object val = defaults.get(name);
+    return val == null? System.getProperty(name) : val;
   }
 
   private String mergeAll(String[] parts, int i) {

Modified: lucene/solr/trunk/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestVariableResolver.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestVariableResolver.java?rev=881724&r1=881723&r2=881724&view=diff
==============================================================================
--- lucene/solr/trunk/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestVariableResolver.java
(original)
+++ lucene/solr/trunk/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestVariableResolver.java
Wed Nov 18 11:22:17 2009
@@ -43,6 +43,21 @@
   }
 
   @Test
+  public void testDefaults(){
+    System.out.println(System.setProperty(TestVariableResolver.class.getName(),"hello"));
+    System.out.println("s.gP()"+ System.getProperty(TestVariableResolver.class.getName()));

+
+    HashMap m = new HashMap();
+    m.put("hello","world");
+    VariableResolverImpl vri = new VariableResolverImpl(m);
+    Object val = vri.resolve(TestVariableResolver.class.getName());
+    System.out.println("val = " + val);
+    Assert.assertEquals("hello", val);
+    Assert.assertEquals("world",vri.resolve("hello"));
+
+  }
+
+  @Test
   public void testNestedNamespace() {
     VariableResolverImpl vri = new VariableResolverImpl();
     Map<String, Object> ns = new HashMap<String, Object>();



Mime
View raw message