IndiscriminateSiteIdentifier -> SiteIdentifiers.DEFAULT
Also added SiteIdentifiers.single().
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
//
|
||||
// samskivert library - useful routines for java programs
|
||||
// Copyright (C) 2001-2012 Michael Bayne, et al.
|
||||
// http://github.com/samskivert/samskivert/blob/master/COPYING
|
||||
|
||||
package com.samskivert.servlet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* Used by default and for systems that have no need to discriminate between different sites in
|
||||
* their web applications.
|
||||
*/
|
||||
public class IndiscriminateSiteIdentifier implements SiteIdentifier
|
||||
{
|
||||
/**
|
||||
* Always returns {@link #DEFAULT_SITE_ID} regardless of the information in the request.
|
||||
*/
|
||||
public int identifySite (HttpServletRequest req)
|
||||
{
|
||||
return DEFAULT_SITE_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Always returns {@link #DEFAULT_SITE_STRING} regardless of the value of the supplied
|
||||
* identifer.
|
||||
*/
|
||||
public String getSiteString (int siteId)
|
||||
{
|
||||
return DEFAULT_SITE_STRING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Always returns {@link #DEFAULT_SITE_ID} regardless of the value of the supplied string.
|
||||
*/
|
||||
public int getSiteId (String siteString)
|
||||
{
|
||||
return DEFAULT_SITE_ID;
|
||||
}
|
||||
|
||||
// documented inherited from interface
|
||||
public Iterator<Site> enumerateSites ()
|
||||
{
|
||||
return _sites.iterator();
|
||||
}
|
||||
|
||||
protected static ArrayList<Site> _sites = new ArrayList<Site>();
|
||||
static {
|
||||
_sites.add(new Site(DEFAULT_SITE_ID, DEFAULT_SITE_STRING));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// samskivert library - useful routines for java programs
|
||||
// Copyright (C) 2001-2012 Michael Bayne, et al.
|
||||
// http://github.com/samskivert/samskivert/blob/master/COPYING
|
||||
|
||||
package com.samskivert.servlet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* {@link SiteIdentifier} utility methods.
|
||||
*/
|
||||
public class SiteIdentifiers
|
||||
{
|
||||
/** A site identifier that always returns the default site. */
|
||||
public static final SiteIdentifier DEFAULT = single(
|
||||
SiteIdentifier.DEFAULT_SITE_ID, SiteIdentifier.DEFAULT_SITE_STRING);
|
||||
|
||||
/** Returns a site identifier that returns the specified site always. */
|
||||
public static SiteIdentifier single (final int siteId, final String siteString) {
|
||||
return new SiteIdentifier() {
|
||||
@Override public int identifySite (HttpServletRequest req) {
|
||||
return siteId;
|
||||
}
|
||||
@Override public String getSiteString (int siteId) {
|
||||
return siteString;
|
||||
}
|
||||
@Override public int getSiteId (String siteString) {
|
||||
return siteId;
|
||||
}
|
||||
@Override public Iterator<Site> enumerateSites () {
|
||||
List<Site> sites = new ArrayList<Site>();
|
||||
sites.add(new Site(siteId, siteString));
|
||||
return sites.iterator();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -15,10 +15,10 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
|
||||
import com.samskivert.servlet.HttpErrorException;
|
||||
import com.samskivert.servlet.IndiscriminateSiteIdentifier;
|
||||
import com.samskivert.servlet.MessageManager;
|
||||
import com.samskivert.servlet.RedirectException;
|
||||
import com.samskivert.servlet.SiteIdentifier;
|
||||
import com.samskivert.servlet.SiteIdentifiers;
|
||||
import com.samskivert.servlet.SiteResourceLoader;
|
||||
import com.samskivert.servlet.util.ExceptionMap;
|
||||
import com.samskivert.servlet.util.FriendlyException;
|
||||
@@ -249,13 +249,13 @@ public class Application
|
||||
|
||||
/**
|
||||
* Called to instantiate the site identifier that we'd like to use in this application. This
|
||||
* will be an instance of {@link IndiscriminateSiteIdentifier} unless the derived application
|
||||
* class overrides this method and creates something more to its liking. This will be called
|
||||
* after the application's {@link #init} method has been called.
|
||||
* will be {@link SiteIdentifiers#DEFAULT}} unless the derived application class overrides this
|
||||
* method and creates something more to its liking. This will be called after the application's
|
||||
* {@link #init} method has been called.
|
||||
*/
|
||||
protected SiteIdentifier createSiteIdentifier (ServletContext ctx)
|
||||
{
|
||||
return new IndiscriminateSiteIdentifier();
|
||||
return SiteIdentifiers.DEFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user