Project

General

Profile

« Previous | Next » 

Revision 3099

Added by Matt Jones over 17 years ago

Updated MetaCatServlet so that it supports a web-based interface for configuring its own properties the first time it is run (determined by the property "configured" being set to false). Which properties are exposed in the web interface is determined by the list of properties in the 'metacat.properties.metadata' file. This file is managed by the new OptionsMetadata class in the utilities module, and provides information that allows metacat to build a human-readable configuration page for the properties. Still need to finish filling out the information in metacat.properties.metadata for the rest of the properties that we want to be editable. This autoconfiguration process is the first step towards building a turnkey installer for metacat.

Note: you need to remove the lib/utilities.jar file from your metacat workspace, update the utilities module, and then rebuild metacat clean in order to pickup the changes introduced here.

View differences:

lib/metacat.properties.metadata
1
# user,Database Username,Database,1,Name of database user to own all tables
2
# password,Database Password,Database,2,Password for database user
3
# administrators,Administrators,Access Configuration,1,List of administrators for this installation in LDAP DN syntax (colon separated)
4
# moderators,Moderators,Access Configuration,2,List of moderators for this installation in LDAP DN syntax (colon separated)
0 5

  
lib/configure.jsp
1
<%@ page    language="java" import="java.util.Enumeration" %>
1
<%@ page    language="java" import="java.util.Enumeration,java.util.Iterator,java.util.Set,java.util.Map,edu.ucsb.nceas.utilities.OptionsMetadata" %>
2 2
<% 
3 3
/**
4 4
 *  '$RCSfile$'
......
77 77
<br clear="right"/>
78 78

  
79 79
<form method="POST" action="<%= request.getContextPath() %>/metacat">
80

  
81
<p class="section">All properties (unsorted, need to fix)</p>
82

  
83 80
<% 
84
   Enumeration optionsList = (Enumeration)request.getAttribute("optionslist");
85
   while (optionsList.hasMoreElements()) {
86
       String name = (String)optionsList.nextElement();
87
       if (!name.equals("configured")) {
81
    OptionsMetadata metadata = (OptionsMetadata)request.getAttribute("metadata");
82
	if (metadata != null) {
83
        Set groups = metadata.getGroups();
84
        Iterator iter = groups.iterator();
85
   		while (iter.hasNext()) {
86
       		String groupName = (String)iter.next();
88 87
%>
89
        <label for="<%= name %>"><%= name %></label>
90
	    <input id="<%= name %>" name="<%= name %>" 
91
	           value="<%= request.getAttribute(name) %>"
92
	           <% if (name.equals("password")) { %>
93
	           type="password"
94
	           <% } else { %>
95
	           type="text" 
96
	           <% } %>
97
	           /><br/>
88
			<p class="section"><%= groupName  %></p>
98 89
<%
99
       }
100
   }
90
			Map keys = metadata.getKeysInGroup(groupName);
91
			Iterator optionsList = keys.values().iterator();
92
			while (optionsList.hasNext()) {
93
    			String name = (String)optionsList.next();
94
    			if (!name.equals("configured")) {
101 95
%>
96
     				<label for="<%= name %>" title="<%= metadata.getOptionDescription(name) %>"><%= metadata.getOptionLabel(name) %></label>
97
	    			<input id="<%= name %>" name="<%= name %>" 
98
	           			value="<%= request.getAttribute(name) %>"
99
	           			<% if (name.equals("password")) { %>
100
	           				type="password"
101
	           			<% } else { %>
102
	           				type="text" 
103
	           			<% } %>
104
	           			alt="<%= metadata.getOptionDescription(name) %>"
105
	           			/><br/>
106
<%
107
    			}
108
			}
109
   		}
110
   	}
111
%>
102 112

  
103
<input type="hidden" name="action" value="configure"/>
104
<p><input type="submit" value="Save"/></p>
113
			<input type="hidden" name="action" value="configure"/>
114
			<p><input type="submit" value="Save"/></p>
105 115

  
106 116
</form>
107 117

  
src/edu/ucsb/nceas/metacat/MetaCatServlet.java
1 1
/**
2 2
 *  '$RCSfile$'
3 3
 *    Purpose: A Class that implements a metadata catalog as a java Servlet
4
 *  Copyright: 2000 Regents of the University of California and the
4
 *  Copyright: 2006 Regents of the University of California and the
5 5
 *             National Center for Ecological Analysis and Synthesis
6 6
 *    Authors: Matt Jones, Dan Higgins, Jivka Bojilova, Chad Berkley, Matthew Perry
7 7
 *
......
29 29
import java.io.BufferedInputStream;
30 30
import java.io.File;
31 31
import java.io.FileInputStream;
32
import java.io.FileNotFoundException;
33
import java.io.FileReader;
32 34
import java.io.IOException;
33 35
import java.io.PrintWriter;
36
import java.io.Reader;
34 37
import java.io.StringReader;
35 38
import java.net.MalformedURLException;
36 39
import java.net.URL;
......
45 48
import java.util.Hashtable;
46 49
import java.util.Iterator;
47 50
import java.util.Properties;
51
import java.util.Set;
48 52
import java.util.Timer;
49 53
import java.util.Vector;
50 54
import java.util.zip.ZipEntry;
......
69 73
import com.oreilly.servlet.multipart.Part;
70 74

  
71 75
import edu.ucsb.nceas.utilities.Options;
76
import edu.ucsb.nceas.utilities.OptionsMetadata;
72 77
import edu.ucsb.nceas.metacat.spatial.SpatialHarvester;
73 78
import edu.ucsb.nceas.metacat.spatial.SpatialQuery;
74 79

  
......
149 154
            // Initialize the properties file for our options
150 155
            String dirPath = context.getRealPath(CONFIG_DIR);
151 156
            File propertyFile = new File(dirPath, CONFIG_NAME);
152

  
157
            
153 158
            String LOG_CONFIG_NAME = dirPath + "/log4j.properties";
154 159
            PropertyConfigurator.configureAndWatch(LOG_CONFIG_NAME);
155 160
            
......
3243 3248
            // The servlet configuration parameters have not been set, so
3244 3249
            // redirect to a web form for configuring metacat
3245 3250
            
3246
            // Add attributes to the request for all configuration options so
3247
            // that the configuration form can display the names and values of
3248
            // all configuration options.
3249
            // TODO: Still need to determine a way to get some metadata about 
3250
            // each attribute to the form jsp, such as a description and 
3251
            // possibly a label and widget type to use and possibly a 
3252
            // controlled values list
3251
            // Load the properties metadata file to determine which properties
3252
            // need to be configured, and include this metadata object in
3253
            // the request so that the JSP page can use the metadata in 
3254
            // constructing the editing form
3255
            String dirPath = this.getServletContext().getRealPath(CONFIG_DIR);
3256
            File metadataFile = new File(dirPath, CONFIG_NAME+".metadata");
3257
            OptionsMetadata metadata = null;
3258
            
3259
            try {
3260
                Reader reader = new FileReader(metadataFile);
3261
                metadata = new OptionsMetadata(reader);
3262
                reader.close();
3263
                request.setAttribute("metadata", metadata);
3264
            } catch (IOException e) {
3265
                Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
3266
                logMetacat.error("Error reading properties metadata: " +
3267
                        e.getMessage());
3268
            }
3269
            
3270
            // Also add the list of options and their values to the request
3253 3271
            Enumeration properties = options.propertyNames();
3254 3272
            while (properties.hasMoreElements()) {
3255 3273
                String name = (String)properties.nextElement();
......
3258 3276
            properties = options.propertyNames();
3259 3277
            request.setAttribute("optionslist", properties);
3260 3278
            
3261
            // Forward the request
3279
            // Forward the request to the JSP page
3262 3280
            forwardRequest(request, response, 
3263 3281
                    MetaCatUtil.getOption("configurationPage"));
3264 3282
        } else {
3265 3283
            // The configuration form is being submitted and needs to be
3266 3284
            // processed, setting the properties in the configuration file
3267
            // then restarting metacat
3285
            // then restart metacat
3268 3286
            
3269 3287
            // TODO: Should first validate that the options provided are 
3270 3288
            // legitimate, and possibly even test them (for example, use
......
3325 3343
            try {
3326 3344
                PrintWriter out = response.getWriter();
3327 3345
                out.println("Error while forwarding to: " + destination);
3346
                e1.printStackTrace(out);
3328 3347
                out.close();
3329 3348
            } catch (IOException e) {
3330 3349
                Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
build.xml
1026 1026
             tofile="${build.war}/web.xml" />
1027 1027
       <copy file="lib/metacat.properties" todir="${war.webinf}"
1028 1028
             filtering="yes" />
1029
   	   <copy file="lib/metacat.properties.metadata" todir="${war.webinf}"
1030
   	             filtering="no" />
1029 1031
       <copy todir="${war.webinf}" filtering="yes">
1030 1032
	   	  <fileset dir="lib">
1031 1033
           <include name="skin.configs/**"/>
......
1045 1047
         <fileset dir="lib">
1046 1048
           <exclude name="*.jar"/>
1047 1049
           <exclude name="*.properties"/>
1050
         	<exclude name="*.metadata"/>
1048 1051
           <exclude name="web.xml"/>
1049 1052
           <exclude name="**/*.jpg"/>
1050 1053
           <exclude name="**/*.png"/>

Also available in: Unified diff