Author: mickw
Date: 2006-05-03 22:32:21 +0200 (Wed, 03 May 2006)
New Revision: 2853
Modified:
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SearchModeFactory.java
trunk/src/java/no/schibstedsok/front/searchportal/servlet/SearchServlet.java
trunk/src/java/no/schibstedsok/front/searchportal/view/config/SearchTabFactory.java
trunk/src/test/java/no/schibstedsok/front/searchportal/command/WebSearchCommandTest.java
trunk/src/test/java/no/schibstedsok/front/searchportal/configuration/SearchModeFactoryTest.java
Log:
SEARCH-263 infopages, and config/tabs/modes reloading.
Modified:
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SearchModeFactory.java
===================================================================
---
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SearchModeFactory.java
2006-05-03 17:33:53 UTC (rev 2852)
+++
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SearchModeFactory.java
2006-05-03 20:32:21 UTC (rev 2853)
@@ -126,7 +126,17 @@
}
return instance;
}
+
+ public static boolean remove(final Site site){
+ try{
+ INSTANCES_LOCK.writeLock().lock();
+ return null != INSTANCES.remove(site);
+ }finally{
+ INSTANCES_LOCK.writeLock().unlock();
+ }
+ }
+
// Constructors --------------------------------------------------
/** Creates a new instance of ModeFactoryImpl */
Modified:
trunk/src/java/no/schibstedsok/front/searchportal/servlet/SearchServlet.java
===================================================================
---
trunk/src/java/no/schibstedsok/front/searchportal/servlet/SearchServlet.java
2006-05-03 17:33:53 UTC (rev 2852)
+++
trunk/src/java/no/schibstedsok/front/searchportal/servlet/SearchServlet.java
2006-05-03 20:32:21 UTC (rev 2853)
@@ -41,7 +41,11 @@
private static final long serialVersionUID = 3068140845772756438L;
private static final Logger LOG = Logger.getLogger(SearchServlet.class);
- private static final String WARN_TABS_CLEANED = " status on cleaning tabs
for ";
+ private static final String ERR_MISSING_TAB = "No existing implementation
for tab ";
+ private static final String ERR_MISSING_MODE = "No existing implementation
for mode ";
+ private static final String WARN_TABS_CLEANED = " status on cleaning site
for ";
+ private static final String WARN_CONFIG_CLEANED = " status on cleaning
configuration for ";
+ private static final String WARN_MODES_CLEANED = " status on cleaning
modes for ";
//private SearchTabs tabs;
@@ -54,29 +58,18 @@
/** [EMAIL PROTECTED]
*/
protected void doGet(
- final HttpServletRequest httpServletRequest,
- final HttpServletResponse httpServletResponse)
+ final HttpServletRequest request,
+ final HttpServletResponse response)
throws ServletException, IOException {
- if (httpServletRequest.getParameter("q") == null) {
- String redir = httpServletRequest.getContextPath();
- if (redir == null) { redir = "/"; }
- if (!redir.endsWith("/")) {
- LOG.debug("doGet: Adding / to " + redir);
-
- redir += "/";
- }
-
- LOG.info("doGet(): Empty Query String redirect=" + redir);
-
- httpServletResponse.sendRedirect(redir);
+ if ( isEmptyQuery(request, response) ) {
return;
}
if (LOG.isDebugEnabled()) {
LOG.debug("ENTR: doGet()");
- LOG.debug("Character encoding =" +
httpServletRequest.getCharacterEncoding());
+ LOG.debug("Character encoding =" +
request.getCharacterEncoding());
}
StopWatch stopWatch = null;
@@ -85,28 +78,14 @@
stopWatch.start();
}
- final Site site = (Site)
httpServletRequest.getAttribute(Site.NAME_KEY);
- final boolean forceReload =
"tabs".equals(httpServletRequest.getParameter("reload"));
+ final Site site = (Site) request.getAttribute(Site.NAME_KEY);
+
+ performReloads(site, request.getParameter("reload"));
- if(forceReload){
- final boolean cleaned = SiteConfiguration.remove(site);
- LOG.warn(cleaned + WARN_TABS_CLEANED + site);
- }
- //final SearchTabs tabs =
SiteConfiguration.valueOf(site).getSearchTabs();
+ updateContentType(site, response);
+ String searchTabKey = request.getParameter("c");
- // TODO. Any better way to do this. Sitemesh?
- if (site.getName().startsWith("mobil")) {
- httpServletResponse.setContentType("text/xml; charset=utf-8");
- } else {
- httpServletResponse.setContentType("text/html; charset=utf-8");
- }
-
- httpServletResponse.setCharacterEncoding("UTF-8"); // correct encoding
-
-
- String searchTabKey = httpServletRequest.getParameter("c");
-
if (searchTabKey == null) {
searchTabKey = "d";
}
@@ -128,12 +107,21 @@
final SearchTab searchTab = SearchTabFactory.getTabFactory(
ContextWrapper.wrap(SearchTabFactory.Context.class,
genericCxt))
.getTabByKey(searchTabKey);
+
+ if( searchTab == null ){
+ LOG.error(ERR_MISSING_TAB + searchTabKey);
+ throw new UnsupportedOperationException(ERR_MISSING_TAB +
searchTabKey);
+ }
+
final SearchMode mode = SearchModeFactory.getModeFactory(
ContextWrapper.wrap(SearchModeFactory.Context.class,
genericCxt))
.getMode(searchTab.getMode());
+
+ if( mode == null ){
+ LOG.error(ERR_MISSING_MODE + searchTab.getMode());
+ throw new UnsupportedOperationException(ERR_MISSING_MODE +
searchTab.getMode());
+ }
- //final SearchMode mode = tabs.getSearchMode(searchTabKey);
-
final RunningQuery.Context rqCxt = ContextWrapper.wrap(// <editor-fold
defaultstate="collapsed" desc=" rqCxt ">
RunningQuery.Context.class,
new BaseContext() {
@@ -148,27 +136,27 @@
);//</editor-fold>
final RunningQuery query = QueryFactory.getInstance()
- .createQuery(rqCxt, httpServletRequest, httpServletResponse);
+ .createQuery(rqCxt, request, response);
- httpServletRequest.setAttribute("locale", query.getLocale());
- httpServletRequest.setAttribute("query", query);
- httpServletRequest.setAttribute("site", site);
- httpServletRequest.setAttribute("text",
+ request.setAttribute("locale", query.getLocale());
+ request.setAttribute("query", query);
+ request.setAttribute("site", site);
+ request.setAttribute("text",
TextMessages.valueOf(ContextWrapper.wrap(TextMessages.Context.class,
genericCxt)));
- if (httpServletRequest.getParameter("offset") != null
- && !"".equals(httpServletRequest.getParameter("offset"))) {
+ if (request.getParameter("offset") != null
+ && !"".equals(request.getParameter("offset"))) {
-
query.setOffset(Integer.parseInt(httpServletRequest.getParameter("offset")));
+ query.setOffset(Integer.parseInt(request.getParameter("offset")));
}
- if (httpServletRequest.getParameter("q") != null) {
- httpServletRequest.setAttribute("q",
- QueryStringHelper.safeGetParameter(httpServletRequest, "q"));
+ if (request.getParameter("q") != null) {
+ request.setAttribute("q",
+ QueryStringHelper.safeGetParameter(request, "q"));
}
- httpServletRequest.setAttribute("tab", searchTab);
- httpServletRequest.setAttribute("c", searchTabKey);
+ request.setAttribute("tab", searchTab);
+ request.setAttribute("c", searchTabKey);
try {
query.run();
@@ -181,5 +169,61 @@
LOG.info("doGet(): Search took " + stopWatch + " " +
query.getQueryString());
}
}
+
+ private void performReloads(
+ final Site site,
+ final String reload){
+
+ if( "all".equalsIgnoreCase(reload) ){
+ final boolean cleaned = SiteConfiguration.remove(site);
+ LOG.warn(cleaned + WARN_CONFIG_CLEANED + site);
+ }
+ if( "all".equalsIgnoreCase(reload) || "tabs".equalsIgnoreCase(reload)
){
+ final boolean cleaned = SearchTabFactory.remove(site);
+ LOG.warn(cleaned + WARN_TABS_CLEANED + site);
+ }
+ if( "all".equalsIgnoreCase(reload) || "modes".equalsIgnoreCase(reload)
){
+ final boolean cleaned = SearchModeFactory.remove(site);
+ LOG.warn(cleaned + WARN_MODES_CLEANED + site);
+ }
+ }
+
+ private boolean isEmptyQuery(
+ final HttpServletRequest request,
+ final HttpServletResponse response ) throws IOException{
+
+ if (request.getParameter("q") == null) {
+
+ String redir = request.getContextPath();
+ if (redir == null) {
+ redir = "/";
+ }
+ if (!redir.endsWith("/")) {
+ LOG.debug("doGet: Adding / to " + redir);
+ redir += "/";
+ }
+
+ LOG.info("doGet(): Empty Query String redirect=" + redir);
+
+ response.sendRedirect(redir);
+ return true;
+ }
+ return false;
+ }
+
+ private void updateContentType(
+ final Site site,
+ final HttpServletResponse response ){
+
+ // TODO. Any better way to do this. Sitemesh?
+ if (site.getName().startsWith("mobil")) {
+ response.setContentType("text/xml; charset=utf-8");
+ } else {
+ response.setContentType("text/html; charset=utf-8");
+ }
+
+ response.setCharacterEncoding("UTF-8"); // correct encoding
+ }
+
}
Modified:
trunk/src/java/no/schibstedsok/front/searchportal/view/config/SearchTabFactory.java
===================================================================
---
trunk/src/java/no/schibstedsok/front/searchportal/view/config/SearchTabFactory.java
2006-05-03 17:33:53 UTC (rev 2852)
+++
trunk/src/java/no/schibstedsok/front/searchportal/view/config/SearchTabFactory.java
2006-05-03 20:32:21 UTC (rev 2853)
@@ -83,7 +83,16 @@
return instance;
}
+ public static boolean remove(final Site site){
+ try{
+ INSTANCES_LOCK.writeLock().lock();
+ return null != INSTANCES.remove(site);
+ }finally{
+ INSTANCES_LOCK.writeLock().unlock();
+ }
+ }
+
// Constructors --------------------------------------------------
/** Creates a new instance of ViewFactory */
Modified:
trunk/src/test/java/no/schibstedsok/front/searchportal/command/WebSearchCommandTest.java
===================================================================
---
trunk/src/test/java/no/schibstedsok/front/searchportal/command/WebSearchCommandTest.java
2006-05-03 17:33:53 UTC (rev 2852)
+++
trunk/src/test/java/no/schibstedsok/front/searchportal/command/WebSearchCommandTest.java
2006-05-03 20:32:21 UTC (rev 2853)
@@ -147,7 +147,7 @@
public SearchMode getSearchMode() {
return SearchModeFactory.getModeFactory(
ContextWrapper.wrap(SearchModeFactory.Context.class,
this))
- .getMode("magic");
+ .getMode("norsk-magic");
}
public SearchTab getSearchTab(){
return SearchTabFactory.getTabFactory(
Modified:
trunk/src/test/java/no/schibstedsok/front/searchportal/configuration/SearchModeFactoryTest.java
===================================================================
---
trunk/src/test/java/no/schibstedsok/front/searchportal/configuration/SearchModeFactoryTest.java
2006-05-03 17:33:53 UTC (rev 2852)
+++
trunk/src/test/java/no/schibstedsok/front/searchportal/configuration/SearchModeFactoryTest.java
2006-05-03 20:32:21 UTC (rev 2853)
@@ -68,7 +68,7 @@
public void testGetMode() {
LOG.trace("testGetMode");
- final String id = "magic";
+ final String id = "norsk-magic";
final SearchModeFactory instance = getModeFactory();
final SearchMode result = instance.getMode(id);
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits