Changeset 32327 for main


Ignore:
Timestamp:
2018-08-07T14:35:03+12:00 (6 years ago)
Author:
kjdon
Message:

changed the way we read in servlet init params - now loop through them all so that we can add any new ones into config_params. then they will eventually make their way to xslt params for the transformation - now can add new ones without having to modify java code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryServlet.java

    r31185 r32327  
    123123        //System.setProperty("java.util.prefs.PreferencesFactory", "org.greenstone.gsdl3.util.DisabledPreferencesFactory");
    124124
    125         library_name = config.getInitParameter(GSConstants.LIBRARY_NAME);
    126         String interface_name = config.getInitParameter(GSConstants.INTERFACE_NAME);
    127 
    128         String useXslt = (String) config.getInitParameter(GSConstants.USE_CLIENT_SIDE_XSLT);
    129         supports_client_xslt = useXslt != null && useXslt.equals("true");
    130 
    131         this.default_lang = config.getInitParameter(GSConstants.DEFAULT_LANG);
    132         String sess_expire = config.getInitParameter(GSXML.SESSION_EXPIRATION);
    133 
    134         if (sess_expire != null && !sess_expire.equals(""))
    135         {
    136             this.session_expiration = Integer.parseInt(sess_expire);
    137         }
    138 
    139         if (library_name == null || interface_name == null)
    140         {
    141             // must have this
    142             System.err.println("initialisation parameters not all set!");
    143             System.err.println(" you must have libraryname and interfacename");
    144             System.exit(1);
    145         }
    146 
    147         String site_name = config.getInitParameter(GSConstants.SITE_NAME);
     125        // Look through all the init params
     126        // these are the ones we are expecting
     127        String interface_name = null;
     128        String useXslt = null;
     129        String sess_expire = null;
     130        String site_name = null;
     131        String recept_name = null;
     132
     133        // may have these instead of site_name
    148134        String remote_site_name = null;
    149135        String remote_site_type = null;
    150136        String remote_site_address = null;
    151137
    152         if (site_name == null)
    153         {
    154             // no site, try for communicator
    155             remote_site_name = config.getInitParameter("remote_site_name");
    156             remote_site_type = config.getInitParameter("remote_site_type");
    157             remote_site_address = config.getInitParameter("remote_site_address");
    158             if (remote_site_name == null || remote_site_type == null || remote_site_address == null)
    159             {
    160                 System.err.println("initialisation paramters not all set!");
    161                 System.err.println("if site_name is not set, then you must have remote_site_name, remote_site_type and remote_site_address set");
    162                 System.exit(1);
    163             }
    164         }
    165 
     138        // the stored config params
     139        HashMap<String, Object> config_params = new HashMap<String, Object>();
     140        Enumeration<String> params = config.getInitParameterNames();
     141        while (params.hasMoreElements()) {
     142          String name = params.nextElement();
     143          String value = config.getInitParameter(name);
     144          switch(name) {
     145          case GSConstants.LIBRARY_NAME: library_name = value;
     146            break;
     147          case GSConstants.INTERFACE_NAME: interface_name = value;
     148            break;
     149          case GSConstants.USE_CLIENT_SIDE_XSLT: useXslt = value;
     150            break;
     151          case GSConstants.DEFAULT_LANG: this.default_lang = value;
     152            break;
     153          case GSXML.SESSION_EXPIRATION: sess_expire = value;
     154            break;
     155          case GSConstants.SITE_NAME: site_name = value;
     156            break;
     157          case GSConstants.REMOTE_SITE_NAME: remote_site_name = value;
     158            break;
     159          case GSConstants.REMOTE_SITE_TYPE: remote_site_type = value;
     160            break;
     161          case GSConstants.REMOTE_SITE_ADDRESS: remote_site_address = value;
     162            break;
     163          case GSConstants.RECEPTIONIST_CLASS: recept_name = value;
     164            break;
     165            // default - just add to config params
     166          default: config_params.put(name, value);
     167            break;
     168          }
     169        }
     170
     171        if (library_name == null || interface_name == null) {
     172         
     173          // must have these
     174          System.err.println("initialisation parameters not all set!");
     175          System.err.println(" you must have libraryname and interfacename");
     176          System.exit(1);
     177        }
     178
     179        // If we don't have a site, then we must be using a Communicator, and all the remote params must be set
     180        if (site_name == null && (remote_site_name == null || remote_site_type == null || remote_site_address == null)) {
     181         
     182          System.err.println("initialisation paramters not all set!");
     183          System.err.println("if site_name is not set, then you must have remote_site_name, remote_site_type and remote_site_address set");
     184          System.exit(1);
     185        }
     186       
     187        supports_client_xslt = useXslt != null && useXslt.equals("true");
     188        if (sess_expire != null && !sess_expire.equals(""))
     189        {
     190            this.session_expiration = Integer.parseInt(sess_expire);
     191        }
    166192        if (this.default_lang == null)
    167193        {
     
    169195            this.default_lang = DEFAULT_LANG;
    170196        }
    171 
    172         HashMap<String, Object> config_params = new HashMap<String, Object>();
    173197
    174198        config_params.put(GSConstants.LIBRARY_NAME, library_name);
     
    180204            config_params.put(GSConstants.SITE_NAME, site_name);
    181205        }
    182         //this.converter = new XMLConverter();
    183         //this.doc = XMLConverter.newDOM();
    184206
    185207        // the receptionist -the servlet will talk to this
    186         String recept_name = (String) config.getInitParameter("receptionist_class");
    187208        if (recept_name == null)
    188209        {
     
    204225        this.recept.setConfigParams(config_params);
    205226
    206         // the receptionist uses a MessageRouter or Communicator to send its requests to. We either create a MessageRouter here for the designated site (if site_name set), or we create a Communicator for a remote site. The is given to teh Receptionist, and the servlet never talks to it again.directly.
     227        // the receptionist uses a MessageRouter or Communicator to send its requests to. We either create a MessageRouter here for the designated site (if site_name set), or we create a Communicator for a remote site. The is given to the Receptionist, and the servlet never talks to it again directly.
    207228        if (site_name != null)
    208229        {
     
    287308        //Allow the message router and the document to be accessed from anywhere in this servlet context
    288309        this.getServletContext().setAttribute("GSRouter", this.recept.getMessageRouter());
    289         //this.getServletContext().setAttribute("GSDocument", this.doc);
    290310    }
    291311
Note: See TracChangeset for help on using the changeset viewer.