Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: joist/java/org/joist/search Search.java Search.properties

Project highlights: Architectural Overview

joist
Discussion topic

Back to topic list

CVS update: joist/java/org/joist/search Search.java Search.properties

Author stack
Full name Michael Stack
Date 2000-11-06 17:38:11 PST
Message User: stack
  Date: 00/11/06 17:38:11

  Added: java/org/joist/search Search.java Search.properties
  Log:
  Renamed SearchServlet as Search
  
  Revision Changes Path
  1.1 joist/java/org/joist​/search/Search.java
  
  Index: Search.java
  ====================​====================​====================​=======
  /* ====================​====================​====================​====
   * Copyright (c) 2000 Collab.Net. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions are
   * met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in the
   * documentation and/or other materials provided with the distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   * any, must include the following acknowlegement: "This product includes
   * software developed by Collab.Net (http://www.Collab.Net/)."
   * Alternately, this acknowlegement may appear in the software itself, if
   * and wherever such third-party acknowlegements normally appear.
   *
   * 4. The hosted project names must not be used to endorse or promote
   * products derived from this software without prior written
   * permission. For written permission, please contact info at collab dot net.
   *
   * 5. Products derived from this software may not use the "Tigris" name
   * nor may "Tigris" appear in their names without prior written
   * permission of Collab.Net.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
   * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
   * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
   * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
   * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * ====================​====================​====================​========
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of Collab.Net.
   */
  package org.joist.search;
   
   
  import java.sql.*;
  import org.webmacro.util.*;
  import org.webmacro.servlet.*;
  import org.joist.security.*;
  import org.joist.search.Query;
  import org.joist.search.SearchSwishe;
  import org.joist.search.SearchResult;
  import java.util.*;
  
   
  /** Simple search servlet.
  * <p>
  * Issues:
  * <ol>
  * <li>None</li>
  * </ol>
  * </p>
  * <p>
  * Test Cases:
  * <ol>
  * <li>What happens when form is empty and it's submitted?
  * <ol>
  * <li>Missing Fields message shows up saying Query is empty.</li>
  * </ol>
  * </li>
  * <li>What happens when form is partially completed? Does the missing fields messages display?
  * <ol>
  * <li>Doesn't apply.
  * </li>
  * </ol>
  * </li>
  * <li>On successful submission, does the content show up in the database?
  * <ol>
  * <li>Doesn't apply.</li>
  * </ol>
  * </li>
  * <li>On successful submission, are we taken to the next page, the project home page?
  * <ol>
  * <li>Yes -- only its same page but w/ search results filled out.</li>
  * </ol>
  * </li>
  * <li>Check the javadoc. How does it come out?
  * <ol>
  * <li>Looks good. I built the javadoc using:
  * <pre>/home/sta​ck/software/jdk1.3/b​in/javadoc -d javadoc -classpath /home/stack/cvsroot/​sandbox/site/lib/joi​st.jar:${CLASSPATH}​ -sourcepath . org.joist.search
  * </pre>
  * </li>
  * </ol>
  * </li>
  * </ol>
  *
  * @author <a href="mailto:stack@c​ollab.net">St.Ack​</a>
  * @version $Id: Search.java,v 1.1 2000/11/07 01:38:11 stack Exp $
  */
  public class Search
      extends org.joist.security.U​nsecureServlet
      implements SearchServletConstants
  {
      /** Class version string
      */
      public static final String versionID
          = "$Id: Search.java,v 1.1 2000/11/07 01:38:11 stack Exp $";
      
      
      /** Logging object.
      */
      private Log log
          = new Log( "search", "Simple Search" );
          
  
      /** Are we in debug state?
      */
      private static final boolean debug
          = true;
      
      
      /** Process search.
       * @param connection A connection to a JDBC database
       * @param context The WebContext partially populated by WMServlet
       * @return The template name
       * @exception HandlerException
       * @exception RedirectException
       */
      protected String processRequest( Connection connection,
                                          WebContext context )
          throws HandlerException, RedirectException
      {
          String templateName
              = super.processRequest( connection, context );
  
           
          List missingFields = new ArrayList( );
              
          try
          {
              String query
                  = processField( context,
                      QUERY_KEY,
                      "",
                      "Query",
                      missingFields );
                                  
              String resultsPerPage
                  = processField( context,
                      RESULTS_PER_PAGE_KEY,
                      "",
                      "Results per Page (Hidden Field)",
                      missingFields );
          
              String action
                  = ( String )context.get( ACTION_KEY );
              
              if( debug )
                  log.debug( "Action: " + action );
              
              
              label_action_test: if( ( action != null )
                                      && action.equals( SEARCH_ACTION ) )
              {
                  if( !isValidUserInput( missingFields ) )
                  {
                      if( debug )
                          log.debug( "INVALID INPUT: "
                                      + missingFields.toString( ) );
                      reportInvalidUserInput( context, missingFields );
                  }
                  else
                  {
                      String index = myProperties.getProperty( INDEX_PATH );
                      if(debug)
                          log.debug( index );
                          
                      Query objQuery
                          = new Query( query,
                              index,
                              Integer.parseInt( resultsPerPage ) );
                  
                      SearchSwishe swishe
                          = new SearchSwishe(
                              myProperties.getProperty( BINARY_PATH ),
                              myProperties.getProperty( DOC_ROOT ),
                              myProperties.getProperty( DOMAIN_KEY ),
                              myProperties.getProperty( HTTP_PORT_KEY ),
                              null /* Need to ask how to figure protocol */ );
                          
                      SearchResult searchresult
                          = swishe.search( objQuery );
                                      
                       if( debug )
                          log.debug( "Number Of Hits: "
                                      + Integer.toString( searchresult.getNumberOfHits( ) ) );
                                      
                      context.put( SEARCH_RESULT_KEY, searchresult );
                  }
              }
          } // label_action_test
          
          catch( Exception e )
          {
              log.exception( e );
              String message = e.getMessage( );
              if( debug )
                  log.debug( message );
              appendToMessage( context, message );
          }
          
          finally
          {
              if( debug )
                  log.debug( "done" );
          }
          
          return templateName;
      }
      
      
      /**
       * Retrieves HTML form and/or CGI query string data, both adding the data
       * to the context and returning it. If the form field contains no data,
       * the provided <code>descript​ion</code> is noted in the
       * <code>missingF​ields</code> list (if provided).
       * <p>
       * The name of this method is, unfortunately, ambiguous (because it does
       * so many things). It may not be a cohesive, but it sure is useful!
       * <p>Taken from org.tigris.helm.secu​rity.HelmServlet
       * </p>
       *
       * @param context The WebContext to add the param to.
       * @param key The name of the form field and context key.
       * @param defaultValue The default value to use if there is nothing in
       * the form.
       * @param description The description to put into the
       * <code>missingF​ields</code> list if the the form
       * field has no value (or <code>null</code>).
       * @param missingFields The list of missing fields (or <code>null</code>
       * if you do not care if the field is missing).
       * @return The form value retrieved.
       */
      protected String processField( WebContext context,
                                      String key,
                                      String defaultValue,
                                      String description,
                                      List missingFields)
      {
          String value = context.getForm(key);
          if ( value == null || value.length( ) <= 0 )
          {
              if (missingFields != null)
              {
                  missingFields.add(description);
              }
              value = defaultValue;
          }
          context.put(key, value);
          if( debug )
              log.debug( "Processing field: " + key + '=' + value );
          return value;
      }
  
  
      /**
       * Checks whether the user inputs are valid. Examines
       * <code>missingF​ields</code> and <code>validati​onErrors</code​> for listed
       * fields.
       * <p>Taken from org.tigris.helm.secu​rity.HelmServlet
       * </p>
       *
       * @param missingFields The missing fields.
       * @return The validity of the user input.
       */
      protected final boolean isValidUserInput( List missingFields )
      {
          return ( missingFields == null || missingFields.isEmpty() );
      }
  
  
      /**
       * Reports missing fields and data validation errors. Examines
       * <code>missingF​ields</code> and <code>validati​onErrors</code​> for listed
       * fields.
       *
       * <p>Taken from org.tigris.helm.secu​rity.HelmServlet
       * </p>
       * @param context The WebContext to report errors in.
       * @param missingFields The missing fields.
       */
      protected final void reportInvalidUserInput( WebContext context,
                                                   List missingFields )
      {
          if (missingFields != null && !missingFields.isEmpty())
          {
              appendToMessage(context, "Required information missing",
                              missingFields);
          }
      }
  }
  
  
  
  1.1 joist/java/org/joist​/search/Search.prope​rties
  
  Index: Search.properties
  ====================​====================​====================​=======
  # $Id: Search.properties,v 1.1 2000/11/07 01:38:11 stack Exp $
  #
  servletDirectory=org/joist
  servletTemplate=sear​ch/SearchPage.wm
  servletName=SearchServlet
  displayName=Search Page
  pageTitle=Search Page
  swisheBinary=/usr/bin/swish-e

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: joist/java/org/joist/search Search.java Search.properties stack Michael Stack 2000-11-06 17:38:11 PST
Messages per page: