Author: ssmiweve
Date: 2008-04-16 11:07:07 +0200 (Wed, 16 Apr 2008)
New Revision: 6464
Modified:
branches/2.16/site-spi/src/main/java/no/sesat/search/site/Site.java
Log:
SEARCH-4613 - generic.sesam.no configuration files are loaded through apache
Modified: branches/2.16/site-spi/src/main/java/no/sesat/search/site/Site.java
===================================================================
--- branches/2.16/site-spi/src/main/java/no/sesat/search/site/Site.java
2008-04-16 07:33:59 UTC (rev 6463)
+++ branches/2.16/site-spi/src/main/java/no/sesat/search/site/Site.java
2008-04-16 09:07:07 UTC (rev 6464)
@@ -33,8 +33,13 @@
import no.schibstedsok.commons.ioc.BaseContext;
import org.apache.log4j.Logger;
-/** A Site object idenetifies an unique SiteSearch implementation.
- * This bean holds nothing more than the name of the virtual host used to
access this SiteSearch.
+/** A Site object identifies a Skin + Locale pairing.
+ *
+ * This bean holds nothing more than the name of the virtual host (siteName)
and locale used to access this Skin.
+ *
+ * It is used as a key to obtain the correct factory instances in the
application.
+ * There is usually only one Skin per siteName and it is left up to the skin
to handle different locales.
+ * .
* <b>Immutable</b>.
*
* Does a little bit of niggling wiggling to load the DEFAULT site. See static
constructor.
@@ -44,7 +49,13 @@
*/
public final class Site implements Serializable {
- /** Not to be confused with the SiteContext.
+ /** During construction of any site we must know who the parent site is
going to be.
+ * It will likely be also constructed since leaf sites are those first
requested.
+ *
+ * The base level sites, locale variants of the DEFAULT site, are expected
to have a null parent.
+ * These DEFAULT sites can just pass in a null context instead of
constructing a context that returns a null parent.
+ *
+ * Not to be confused with the SiteContext.
* This is a Context required for constructing a Site.
* While a SiteContext is a context required to use a Site.
**/
@@ -87,7 +98,7 @@
*/
private final String cxtName;
/**
- * Holds value of property _locale.
+ * Holds value of property locale.
*/
private Locale locale;
/**
@@ -125,9 +136,7 @@
// siteName must finish with a '\'
siteName = ensureTrailingSlash(theSiteName);
- cxtName = siteName.indexOf(':') >= 0
- ? siteName.substring(0, siteName.indexOf(':')) + '/' // don't
include the port in the cxtName.
- : siteName;
+ cxtName = ensureTrailingSlash(siteName.replaceAll(":.*$", "")); //
don't include the port in the cxtName.
locale = theLocale;
uniqueName = getUniqueName(siteName, locale);
@@ -139,26 +148,32 @@
}
};
- final String parentSiteName = null != cxt ?
cxt.getParentSiteName(siteContext) : siteName;
+ final String parentSiteName;
+ if(null != cxt){
+ parentSiteName = null != cxt.getParentSiteName(siteContext)
+ ?
ensureTrailingSlash(cxt.getParentSiteName(siteContext))
+ : null;
+ }else{
+ parentSiteName = siteName;
+ }
final String tsParentNameNoPort = null != parentSiteName
? ensureTrailingSlash(parentSiteName.replaceAll(":.*$",
""))
: null;
- LOG.error(siteName + " parent is " + parentSiteName);
+ LOG.debug(siteName + " parent is " + parentSiteName);
if(constructingDefault){
parent = null;
}else{
- LOG.error("Default-check-> " + DEFAULT.getName() + " ?= "
- + (null != parentSiteName ?
ensureTrailingSlash(parentSiteName) : "null"));
+ LOG.debug("Default-check-> " + DEFAULT.getName() + " ?= " +
parentSiteName);
final boolean invalidParent = null == parentSiteName
// also avoid any incest
|| siteName.equals(tsParentNameNoPort)
// and detect ahead the link to the grandfather of all
"generic.sesam"
- ||
ensureTrailingSlash(parentSiteName).equals(DEFAULT.getName());
+ || DEFAULT.getName().equals(parentSiteName);
parent = invalidParent
? DEFAULT
@@ -168,6 +183,7 @@
assert null != parent || constructingDefault : "Parent must exist
for all Sites except the DEFAULT";
// register in global pool.
+ LOG.debug("INSTANCES.put(" + uniqueName + ", this)");
INSTANCES.put(uniqueName, this);
}finally{
@@ -222,15 +238,11 @@
return locale;
}
- /** [EMAIL PROTECTED]
- */
@Override
public String toString(){
return uniqueName;
}
- /** [EMAIL PROTECTED]
- */
@Override
public boolean equals(final Object obj) {
@@ -239,8 +251,6 @@
: super.equals(obj);
}
- /** [EMAIL PROTECTED]
- */
@Override
public int hashCode() {
return uniqueName.hashCode();
@@ -249,6 +259,9 @@
/** Get the instance for the given siteName.
* The port number will be changed if the server has explicitly assigned
one port number to use.
* A "www." prefix will be automatically ignored.
+ *
+ * TODO refactor to instanceOf(..). it is an instance returned not a
primitive.
+ *
* @param cxt the cxt to use during creation. null will prevent
constructing a new site.
* @param siteName the virtual host name.
* @param locale the locale desired
@@ -262,9 +275,11 @@
final String realSiteName =
ensureTrailingSlash(siteName.replaceAll("www.", ""));
// Look for existing instances
+ final String uniqueName = getUniqueName(realSiteName,locale);
try{
INSTANCES_LOCK.readLock().lock();
- site = INSTANCES.get(getUniqueName(realSiteName,locale));
+ LOG.debug("INSTANCES.get(" + uniqueName + ")");
+ site = INSTANCES.get(uniqueName);
}finally{
INSTANCES_LOCK.readLock().unlock();
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits