Author: ssmiweve
Date: 2008-04-15 13:42:19 +0200 (Tue, 15 Apr 2008)
New Revision: 6440
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-15 11:14:46 UTC (rev 6439)
+++ branches/2.16/site-spi/src/main/java/no/sesat/search/site/Site.java
2008-04-15 11:42:19 UTC (rev 6440)
@@ -49,7 +49,10 @@
* While a SiteContext is a context required to use a Site.
**/
public interface Context extends BaseContext{
- /** Get the name of the parent site. **/
+ /** Get the name of the parent site.
+ * @param siteContext that can provide the current site the code is
within.
+ * @return the name of the parent site.
+ */
String getParentSiteName(SiteContext siteContext);
}
@@ -105,16 +108,16 @@
uniqueName = null;
parent = null;
}
-
+
/** Creates a new instance of Site.
* A null Context will result in a parentSiteName == siteName
*/
private Site(final Context cxt, final String theSiteName, final Locale
theLocale) {
-
-
+
+
try{
INSTANCES_LOCK.writeLock().lock();
-
+
LOG.info("Site(cxt, " + theSiteName + ", " + theLocale + ')');
assert null != theSiteName;
assert null != theLocale;
@@ -136,18 +139,37 @@
}
};
-
final String parentSiteName = null != cxt ?
cxt.getParentSiteName(siteContext) : siteName;
-
- parent = null == parentSiteName ||
ensureTrailingSlash(parentSiteName).equals(siteName)
- ? constructingDefault ? null : DEFAULT
- : Site.valueOf(cxt, parentSiteName, theLocale);
+ final String tsParentNameNoPort = null != parentSiteName
+ ? ensureTrailingSlash(parentSiteName.replaceAll(":.*$",
""))
+ : null;
+
+ LOG.error(siteName + " parent is " + parentSiteName);
+
+ if(constructingDefault){
+ parent = null;
+
+ }else{
+ LOG.error("Default-check-> " + DEFAULT.getName() + " ?= "
+ + (null != parentSiteName ?
ensureTrailingSlash(parentSiteName) : "null"));
+
+ 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());
+
+ parent = invalidParent
+ ? DEFAULT
+ : Site.valueOf(cxt, parentSiteName, theLocale);
+ }
+
assert null != parent || constructingDefault : "Parent must exist
for all Sites except the DEFAULT";
-
+
// register in global pool.
INSTANCES.put(uniqueName, this);
-
+
}finally{
INSTANCES_LOCK.writeLock().unlock();
}
@@ -155,8 +177,8 @@
/** the parent to this site.
- * returns null if we are the DEFAULT site.
- **/
+ * @return site null if we are the DEFAULT site.
+ */
public Site getParent(){
return parent;
}
@@ -211,7 +233,7 @@
*/
@Override
public boolean equals(final Object obj) {
-
+
return obj instanceof Site
? uniqueName.equals(((Site)obj).uniqueName)
: super.equals(obj);
@@ -243,11 +265,11 @@
try{
INSTANCES_LOCK.readLock().lock();
site = INSTANCES.get(getUniqueName(realSiteName,locale));
-
+
}finally{
INSTANCES_LOCK.readLock().unlock();
}
-
+
// construct a new instance
if (null == site && null != cxt) {
site = new Site(cxt, realSiteName, locale);
@@ -259,29 +281,29 @@
final Properties props = new Properties();
final InputStream is = Site.class.getResourceAsStream('/' +
CORE_CONF_FILE);
-
+
try {
if(null != is){
props.load(is);
is.close();
}
-
+
} catch (IOException ex) {
- LOG.fatal(FATAL_CANT_FIND_DEFAULT_SITE, ex);
+ LOG.fatal(FATAL_CANT_FIND_DEFAULT_SITE, ex);
}
-
+
final String defaultSiteName = props.getProperty(DEFAULT_SITE_KEY,
System.getProperty(DEFAULT_SITE_KEY));
LOG.info("defaultSiteName: " + defaultSiteName);
-
- final String defaultSiteLocaleName
+
+ final String defaultSiteLocaleName
= props.getProperty(DEFAULT_SITE_LOCALE_KEY,
System.getProperty(DEFAULT_SITE_LOCALE_KEY));
LOG.info("defaultSiteLocaleName: " + defaultSiteLocaleName);
-
- final String defaultSitePort
+
+ final String defaultSitePort
= props.getProperty(DEFAULT_SERVER_PORT_KEY,
System.getProperty(DEFAULT_SERVER_PORT_KEY));
LOG.info("defaultSitePort: " + defaultSitePort);
-
-
+
+
SERVER_PORT = Integer.parseInt(defaultSitePort);
constructingDefault = true;
@@ -303,14 +325,20 @@
/** the server's actual port. **/
public static final int SERVER_PORT;
- /** TODO comment me. **/
+ /** Get a uniqueName given a pair of siteName and locale.
+ * Used internally and before construction of any new Site.
+ *
+ * @param siteName
+ * @param locale
+ * @return
+ */
public static String getUniqueName(final String siteName, final Locale
locale) {
-
+
return siteName + '[' + locale.getDisplayName() + ']';
}
private static String ensureTrailingSlash(final String theSiteName) {
-
+
return theSiteName.endsWith("/")
? theSiteName
: theSiteName + '/';
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits