Author: mickw
Date: 2006-04-04 15:09:06 +0200 (Tue, 04 Apr 2006)
New Revision: 2703
Modified:
trunk/pom.xml
trunk/src/java/no/schibstedsok/front/searchportal/analyzer/AnalysisRuleFactory.java
trunk/src/java/no/schibstedsok/front/searchportal/configuration/loader/PropertiesContext.java
trunk/src/java/no/schibstedsok/front/searchportal/configuration/loader/PropertiesLoader.java
trunk/src/java/no/schibstedsok/front/searchportal/configuration/loader/UrlResourceLoader.java
trunk/src/java/no/schibstedsok/front/searchportal/i18n/TextMessages.java
trunk/src/java/no/schibstedsok/front/searchportal/query/token/RegExpEvaluatorFactory.java
trunk/src/java/no/schibstedsok/front/searchportal/site/Site.java
Log:
inheritable property files (through the fallback process).
LocalEntityResolver to avoid URL requests to fetch sesam dtds.
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2006-04-04 12:48:18 UTC (rev 2702)
+++ trunk/pom.xml 2006-04-04 13:09:06 UTC (rev 2703)
@@ -114,10 +114,9 @@
</includes>
</resource>
<resource>
- <directory>src/data</directory>
+ <directory>src/webapp/dtds</directory>
<includes>
- <include>*.csv</include>
- <include>*.txt</include>
+ <include>*.dtd</include>
</includes>
</resource>
</resources>
Modified:
trunk/src/java/no/schibstedsok/front/searchportal/analyzer/AnalysisRuleFactory.java
===================================================================
---
trunk/src/java/no/schibstedsok/front/searchportal/analyzer/AnalysisRuleFactory.java
2006-04-04 12:48:18 UTC (rev 2702)
+++
trunk/src/java/no/schibstedsok/front/searchportal/analyzer/AnalysisRuleFactory.java
2006-04-04 13:09:06 UTC (rev 2703)
@@ -11,6 +11,7 @@
import javax.xml.parsers.DocumentBuilderFactory;
import no.schibstedsok.common.ioc.BaseContext;
import no.schibstedsok.front.searchportal.configuration.loader.DocumentLoader;
+import
no.schibstedsok.front.searchportal.configuration.loader.LocalEntityResolver;
import no.schibstedsok.front.searchportal.query.token.TokenPredicate;
import no.schibstedsok.front.searchportal.util.SearchConstants;
import org.apache.commons.collections.Predicate;
@@ -87,7 +88,9 @@
context = cxt;
final DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
factory.setValidating(false);
- loader =
context.newDocumentLoader(SearchConstants.ANALYSIS_RULES_XMLFILE,
factory.newDocumentBuilder());
+ final DocumentBuilder builder = factory.newDocumentBuilder();
+ builder.setEntityResolver(new LocalEntityResolver());
+ loader =
context.newDocumentLoader(SearchConstants.ANALYSIS_RULES_XMLFILE, builder);
INSTANCES.put(context.getSite(), this);
}
Modified:
trunk/src/java/no/schibstedsok/front/searchportal/configuration/loader/PropertiesContext.java
===================================================================
---
trunk/src/java/no/schibstedsok/front/searchportal/configuration/loader/PropertiesContext.java
2006-04-04 12:48:18 UTC (rev 2702)
+++
trunk/src/java/no/schibstedsok/front/searchportal/configuration/loader/PropertiesContext.java
2006-04-04 13:09:06 UTC (rev 2703)
@@ -15,6 +15,8 @@
*/
public interface PropertiesContext extends BaseContext {
/** Create a new PropertiesLoader for the given resource name/path and
load it into the given properties.
+ * Will not overwrite existing properties.
+ *
* @param resource the resource name/path.
* @param properties the properties to hold the individual properties
loaded.
* @return the new PropertiesLoader to use.
Modified:
trunk/src/java/no/schibstedsok/front/searchportal/configuration/loader/PropertiesLoader.java
===================================================================
---
trunk/src/java/no/schibstedsok/front/searchportal/configuration/loader/PropertiesLoader.java
2006-04-04 12:48:18 UTC (rev 2702)
+++
trunk/src/java/no/schibstedsok/front/searchportal/configuration/loader/PropertiesLoader.java
2006-04-04 13:09:06 UTC (rev 2703)
@@ -19,6 +19,8 @@
*/
public interface PropertiesLoader extends ResourceLoader {
/** initialise this resource loader with the resource name/path and the
resource it will go into.
+ * existing properties will not be overwritten.
+ *
[EMAIL PROTECTED] resource the name/path of the resource.
[EMAIL PROTECTED] properties the properties that will be used to hold the
individual properties.
**/
Modified:
trunk/src/java/no/schibstedsok/front/searchportal/configuration/loader/UrlResourceLoader.java
===================================================================
---
trunk/src/java/no/schibstedsok/front/searchportal/configuration/loader/UrlResourceLoader.java
2006-04-04 12:48:18 UTC (rev 2702)
+++
trunk/src/java/no/schibstedsok/front/searchportal/configuration/loader/UrlResourceLoader.java
2006-04-04 13:09:06 UTC (rev 2703)
@@ -156,13 +156,20 @@
/** [EMAIL PROTECTED]
*/
public void run() {
- if (!loadResource(getResource())) {
- LOG.warn(WARN_USING_FALLBACK + getResource());
- if (!loadResource(getFallbackResource())) {
- LOG.fatal(FATAL_RESOURCE_NOT_LOADED);
+ if( props != null ){
+ // Properties inherent through the fallback process. Keys are
*not* overridden.
+ loadResource(getResource());
+ loadResource(getFallbackResource());
+
+ }else{
+ // Default behavour: only load first found resource
+ if (!loadResource(getResource())) {
+ LOG.warn(WARN_USING_FALLBACK + getResource());
+ if (!loadResource(getFallbackResource())) {
+ LOG.fatal(FATAL_RESOURCE_NOT_LOADED);
+ }
}
}
-
}
private boolean loadResource(final String resource) {
@@ -178,7 +185,17 @@
if (props != null) {
- props.load(urlConn.getInputStream());
+ // only add properties that don't already exist!
+ // allows us to inherent back through the fallback process.
+ final Properties newProps = new Properties();
+ newProps.load(urlConn.getInputStream());
+ for(Object p : newProps.keySet()){
+
+ if( !props.containsKey(p) ){
+ final String prop = (String)p;
+ props.setProperty(prop,
newProps.getProperty(prop));
+ }
+ }
}
if (xstream != null) {
xstreamResult = xstream.fromXML(new
InputStreamReader(urlConn.getInputStream()));
Modified:
trunk/src/java/no/schibstedsok/front/searchportal/i18n/TextMessages.java
===================================================================
--- trunk/src/java/no/schibstedsok/front/searchportal/i18n/TextMessages.java
2006-04-04 12:48:18 UTC (rev 2702)
+++ trunk/src/java/no/schibstedsok/front/searchportal/i18n/TextMessages.java
2006-04-04 13:09:06 UTC (rev 2703)
@@ -45,6 +45,7 @@
/** Find the correct instance handling this Site.
**/
public static TextMessages valueOf(final Context cxt) {
+
final Site site = cxt.getSite();
TextMessages instance = INSTANCES.get(site);
if (instance == null) {
@@ -77,38 +78,41 @@
private final Properties keys = new Properties();
private TextMessages(final Context cxt) {
+
context = cxt;
- if (!loadKeys(cxt.getSite().getLocale())) {
-
LOG.info(cxt.getSite()+INFO_USING_DEFAULT_LOCALE+Locale.getDefault());
- loadKeys(Locale.getDefault());
- }
+ // import browser-applicable text messages
+ loadKeys(cxt.getSite().getLocale());
+
+ // import servers-default text messages [does not override existing
values]
+ LOG.info(cxt.getSite()+INFO_USING_DEFAULT_LOCALE+Locale.getDefault());
+ loadKeys(Locale.getDefault());
INSTANCES.put(cxt.getSite(),this);
}
- private boolean loadKeys(final Locale l) {
-
LOG.debug(DEBUG_LOADING_WITH_LOCALE+l.getLanguage()+"_"+l.getCountry()+"_"+l.getVariant());
- if (!loadKeysFallback(l)) {
- // ignore variant
-
LOG.debug(DEBUG_LOADING_WITH_LOCALE+l.getLanguage()+"_"+l.getCountry());
- if (!loadKeysFallback(new Locale(l.getLanguage(),
l.getCountry()))) {
- // ignore country
- LOG.debug(DEBUG_LOADING_WITH_LOCALE+l.getLanguage());
- if (!loadKeysFallback(new Locale(l.getLanguage()))) {
- return false;
- }
- }
- }
- return true;
+ private void loadKeys(final Locale l) {
+
+ // import the variant-specific text messages [does not override
existing values]
+ LOG.debug(DEBUG_LOADING_WITH_LOCALE + l.getLanguage() + "_" +
l.getCountry() + "_" + l.getVariant());
+ performLoadKeys(l);
+
+ // import the country-specific text messages [does not override
existing values]
+ LOG.debug(DEBUG_LOADING_WITH_LOCALE + l.getLanguage() + "_" +
l.getCountry());
+ performLoadKeys(new Locale(l.getLanguage(), l.getCountry()));
+
+ // import the language-specifix text messages [does not override
existing values]
+ LOG.debug(DEBUG_LOADING_WITH_LOCALE + l.getLanguage());
+ performLoadKeys(new Locale(l.getLanguage()));
+
}
- private boolean loadKeysFallback(final Locale locale) {
+ private void performLoadKeys(final Locale locale) {
+
final PropertiesLoader loader
- =
context.newPropertiesLoader(MESSAGE_RESOURCE+"_"+locale.toString()+".properties",
keys);
+ = context.newPropertiesLoader(MESSAGE_RESOURCE + "_" +
locale.toString() + ".properties", keys);
loader.abut();
loader.getProperties();
- return keys.size() > 0;
}
public String getMessage(final String key) {
Modified:
trunk/src/java/no/schibstedsok/front/searchportal/query/token/RegExpEvaluatorFactory.java
===================================================================
---
trunk/src/java/no/schibstedsok/front/searchportal/query/token/RegExpEvaluatorFactory.java
2006-04-04 12:48:18 UTC (rev 2702)
+++
trunk/src/java/no/schibstedsok/front/searchportal/query/token/RegExpEvaluatorFactory.java
2006-04-04 13:09:06 UTC (rev 2703)
@@ -6,6 +6,7 @@
import javax.xml.parsers.ParserConfigurationException;
import no.schibstedsok.common.ioc.BaseContext;
import no.schibstedsok.front.searchportal.configuration.loader.DocumentLoader;
+import
no.schibstedsok.front.searchportal.configuration.loader.LocalEntityResolver;
import no.schibstedsok.front.searchportal.configuration.loader.ResourceContext;
import no.schibstedsok.front.searchportal.site.Site;
import no.schibstedsok.front.searchportal.site.SiteContext;
@@ -77,7 +78,9 @@
context = cxt;
final DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
factory.setValidating(false);
- loader =
context.newDocumentLoader(SearchConstants.REGEXP_EVALUATOR_XMLFILE,
factory.newDocumentBuilder());
+ final DocumentBuilder builder = factory.newDocumentBuilder();
+ builder.setEntityResolver(new LocalEntityResolver());
+ loader =
context.newDocumentLoader(SearchConstants.REGEXP_EVALUATOR_XMLFILE, builder);
INSTANCES.put(context.getSite(), this);
}
Modified: trunk/src/java/no/schibstedsok/front/searchportal/site/Site.java
===================================================================
--- trunk/src/java/no/schibstedsok/front/searchportal/site/Site.java
2006-04-04 12:48:18 UTC (rev 2702)
+++ trunk/src/java/no/schibstedsok/front/searchportal/site/Site.java
2006-04-04 13:09:06 UTC (rev 2703)
@@ -167,7 +167,7 @@
final Properties props = new Properties();
try {
- props.load(Site.class.getResourceAsStream("/" +
SearchConstants.CONFIGURATION_FILE));
+ props.load(Site.class.getResourceAsStream('/' +
SearchConstants.CONFIGURATION_FILE));
} catch (IOException ex) {
LOG.fatal(FATAL_CANT_FIND_DEFAULT_SITE, ex);
}
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits