mirror of https://github.com/apache/lucene.git
SOLR-1525 allow DIH to refer to core properties
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@881724 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
752faad70b
commit
47bff0322c
|
@ -80,7 +80,9 @@ public class DocBuilder {
|
|||
|
||||
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));
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.solr.handler.dataimport;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Collections;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
|
@ -41,7 +42,14 @@ public class VariableResolverImpl extends VariableResolver {
|
|||
|
||||
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 @@ public class VariableResolverImpl extends VariableResolver {
|
|||
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) {
|
||||
|
|
|
@ -42,6 +42,21 @@ public class TestVariableResolver {
|
|||
Assert.assertEquals("WORLD", vri.resolve("hello.world"));
|
||||
}
|
||||
|
||||
@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();
|
||||
|
|
Loading…
Reference in New Issue