lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehatc...@apache.org
Subject svn commit: r792555 - in /lucene/solr/trunk/contrib/dataimporthandler: CHANGES.txt src/main/java/org/apache/solr/handler/dataimport/URLDataSource.java src/test/java/org/apache/solr/handler/dataimport/TestURLDataSource.java
Date Thu, 09 Jul 2009 13:46:45 GMT
Author: ehatcher
Date: Thu Jul  9 13:46:45 2009
New Revision: 792555

URL: http://svn.apache.org/viewvc?rev=792555&view=rev
Log:
SOLR-1265: Add variable resolving for URLDataSource properties like baseUrl

Added:
    lucene/solr/trunk/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestURLDataSource.java
Modified:
    lucene/solr/trunk/contrib/dataimporthandler/CHANGES.txt
    lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/URLDataSource.java

Modified: lucene/solr/trunk/contrib/dataimporthandler/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/dataimporthandler/CHANGES.txt?rev=792555&r1=792554&r2=792555&view=diff
==============================================================================
--- lucene/solr/trunk/contrib/dataimporthandler/CHANGES.txt (original)
+++ lucene/solr/trunk/contrib/dataimporthandler/CHANGES.txt Thu Jul  9 13:46:45 2009
@@ -246,6 +246,8 @@
 26.SOLR-1146: ConcurrentModificationException in DataImporter.getStatusMessages
               (Walter Ferrara, Noble Paul via shalin)
 
+             
+
 Documentation
 ----------------------
 
@@ -289,6 +291,8 @@
               Introduced a DocWrapper which takes care of maintaining document level session
variables.
               (Noble Paul, shalin)
 
+10.SOLR-1265: Add variable resolving for URLDataSource properties like baseUrl.  (Chris Eldredge
via ehatcher)
+
 ================== Release 1.3.0 20080915 ==================
 
 Status

Modified: lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/URLDataSource.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/URLDataSource.java?rev=792555&r1=792554&r2=792555&view=diff
==============================================================================
--- lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/URLDataSource.java
(original)
+++ lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/URLDataSource.java
Thu Jul  9 13:46:45 2009
@@ -49,15 +49,22 @@
 
   private int readTimeout = READ_TIMEOUT;
 
+  private Context context;
+
+  private Properties initProps;
+
   public URLDataSource() {
   }
 
   public void init(Context context, Properties initProps) {
-    baseUrl = initProps.getProperty(BASE_URL);
-    if (initProps.get(ENCODING) != null)
-      encoding = initProps.getProperty(ENCODING);
-    String cTimeout = initProps.getProperty(CONNECTION_TIMEOUT_FIELD_NAME);
-    String rTimeout = initProps.getProperty(READ_TIMEOUT_FIELD_NAME);
+    this.context = context;
+    this.initProps = initProps;
+    
+    baseUrl = getInitPropWithReplacements(BASE_URL);
+    if (getInitPropWithReplacements(ENCODING) != null)
+      encoding = getInitPropWithReplacements(ENCODING);
+    String cTimeout = getInitPropWithReplacements(CONNECTION_TIMEOUT_FIELD_NAME);
+    String rTimeout = getInitPropWithReplacements(READ_TIMEOUT_FIELD_NAME);
     if (cTimeout != null) {
       try {
         connectionTimeout = Integer.parseInt(cTimeout);
@@ -72,7 +79,6 @@
         LOG.warn("Invalid read timeout: " + rTimeout);
       }
     }
-
   }
 
   public Reader getData(String query) {
@@ -111,6 +117,18 @@
   public void close() {
   }
 
+  public String getBaseUrl() {
+    return baseUrl;
+  }
+
+  private String getInitPropWithReplacements(String propertyName) {
+    final String expr = initProps.getProperty(propertyName);
+    if (expr == null) {
+      return null;
+    }
+    return context.getVariableResolver().replaceTokens(expr);
+  }
+
   private static final Pattern URIMETHOD = Pattern.compile("\\w{3,}:/");
 
   private static final Pattern CHARSET_PATTERN = Pattern.compile(".*?charset=(.*)$", Pattern.CASE_INSENSITIVE);

Added: lucene/solr/trunk/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestURLDataSource.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestURLDataSource.java?rev=792555&view=auto
==============================================================================
--- lucene/solr/trunk/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestURLDataSource.java
(added)
+++ lucene/solr/trunk/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestURLDataSource.java
Thu Jul  9 13:46:45 2009
@@ -0,0 +1,47 @@
+/**
+ * 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.solr.handler.dataimport;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+public class TestURLDataSource {
+  private List<Map<String, String>> fields = new ArrayList<Map<String,
String>>();
+  private URLDataSource dataSource = new URLDataSource();
+  private VariableResolverImpl variableResolver = new VariableResolverImpl();
+  private Context context = AbstractDataImportHandlerTest.getContext(null, variableResolver,
+      dataSource, Context.FULL_DUMP, fields, null);
+  private Properties initProps = new Properties();
+  
+  @Test
+  public void substitutionsOnBaseUrl() throws Exception {
+    String url = "http://example.com/";
+    
+    variableResolver.addNamespace("dataimporter.request", Collections.<String,Object>singletonMap("baseurl",
url));
+    
+    initProps.setProperty(URLDataSource.BASE_URL, "${dataimporter.request.baseurl}");
+    dataSource.init(context, initProps);
+    Assert.assertEquals(url, dataSource.getBaseUrl());
+  }
+}



Mime
View raw message