Project

General

Profile

« Previous | Next » 

Revision 4124

Added by daigle about 16 years ago

Create PropertyService using log directory instead of servlet context.

View differences:

src/edu/ucsb/nceas/metacat/advancedsearch/AdvancedSearchServlet.java
38 38

  
39 39
import edu.ucsb.nceas.metacat.client.*;
40 40
import edu.ucsb.nceas.metacat.service.PropertyService;
41
import edu.ucsb.nceas.utilities.Options;
41
import edu.ucsb.nceas.metacat.service.ServiceException;
42 42
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
43 43

  
44 44
/** 
......
115 115
	public void init(ServletConfig config) throws ServletException {
116 116
		ServletContext context = null;
117 117
		String dirPath;
118
		Options options = null;
119 118

  
120 119
		super.init(config);
121 120
		context = config.getServletContext();
122 121
		dirPath = context.getRealPath(CONFIG_DIR);
123
		File propertyFile = new File(dirPath, CONFIG_NAME);
124 122

  
125 123
		try {
126
			options = Options.initialize(propertyFile);
124
			PropertyService.getInstance(dirPath);
127 125
			this.contextString = PropertyService.getProperty("application.context");
128
		} catch (IOException e) {
129
			System.err.println("Error in loading options: " + e.getMessage());
126
		} catch (ServiceException se) {
127
			System.err.println("Error in loading properties: " + se.getMessage());
130 128
		} catch (PropertyNotFoundException pnfe) {
131 129
			System.err.println("couldn't read property during initialization: " 
132 130
					+ pnfe.getMessage());
src/edu/ucsb/nceas/metacat/advancedsearch/BrowseServlet.java
38 38

  
39 39
import edu.ucsb.nceas.metacat.client.*;
40 40
import edu.ucsb.nceas.metacat.service.PropertyService;
41
import edu.ucsb.nceas.metacat.service.ServiceException;
41 42
import edu.ucsb.nceas.metacat.util.SystemUtil;
42
import edu.ucsb.nceas.utilities.Options;
43 43
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
44 44

  
45 45
/** 
......
117 117
	public void init(ServletConfig config) throws ServletException {
118 118
		ServletContext context = null;
119 119
		String dirPath;
120
		Options options = null;
121 120

  
122 121
		super.init(config);
123 122
		context = config.getServletContext();
124 123
		dirPath = context.getRealPath(CONFIG_DIR);
125
		File propertyFile = new File(dirPath, CONFIG_NAME);
126 124

  
127 125
		try {
128
			options = Options.initialize(propertyFile);
126
			PropertyService.getInstance(dirPath);
129 127
			this.contextString = PropertyService.getProperty("application.context");
130
		} catch (IOException e) {
131
			System.err.println("Error in loading options: " + e.getMessage());
128
		} catch (ServiceException se) {
129
			System.err.println("Error in loading properties: " + se.getMessage());
132 130
		} catch (PropertyNotFoundException pnfe) {
133 131
			System.err.println("couldn't read property during initialization: "
134 132
					+ pnfe.getMessage());
src/edu/ucsb/nceas/metacat/advancedsearch/SearchServlet.java
37 37

  
38 38
import edu.ucsb.nceas.metacat.client.*;
39 39
import edu.ucsb.nceas.metacat.service.PropertyService;
40
import edu.ucsb.nceas.metacat.service.ServiceException;
40 41
import edu.ucsb.nceas.metacat.util.SystemUtil;
41
import edu.ucsb.nceas.utilities.Options;
42 42
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
43 43

  
44 44
/** 
......
118 118
	public void init(ServletConfig config) throws ServletException {
119 119
		ServletContext context = null;
120 120
		String dirPath;
121
		Options options = null;
122 121

  
123 122
		super.init(config);
124 123
		context = config.getServletContext();
125 124
		dirPath = context.getRealPath(CONFIG_DIR);
126
		File propertyFile = new File(dirPath, CONFIG_NAME);
127 125

  
128 126
		try {
129
			options = Options.initialize(propertyFile);
127
			PropertyService.getInstance(dirPath);
130 128
			this.contextString = PropertyService.getProperty("application.context");
131
		} catch (IOException e) {
132
			System.err.println("Error in loading options: " + e.getMessage());
129
		} catch (ServiceException se) {
130
			System.err.println("Error in loading properties: " + se.getMessage());
133 131
		} catch (PropertyNotFoundException pnfe) {
134 132
			System.err.println("couldn't read property during initialization: "
135 133
					+ pnfe.getMessage());
src/edu/ucsb/nceas/metacat/advancedsearch/LoginServlet.java
38 38

  
39 39
import edu.ucsb.nceas.metacat.client.*;
40 40
import edu.ucsb.nceas.metacat.service.PropertyService;
41
import edu.ucsb.nceas.metacat.service.ServiceException;
41 42
import edu.ucsb.nceas.metacat.util.SystemUtil;
42
import edu.ucsb.nceas.utilities.Options;
43 43
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
44 44

  
45 45
/** 
......
131 131
	public void init(ServletConfig config) throws ServletException {
132 132
		ServletContext context = null;
133 133
		String dirPath;
134
		Options options = null;
135 134

  
136 135
		super.init(config);
137 136
		context = config.getServletContext();
138 137
		dirPath = context.getRealPath(CONFIG_DIR);
139
		File propertyFile = new File(dirPath, CONFIG_NAME);
140 138

  
141 139
		try {
142
			options = Options.initialize(propertyFile);
140
			PropertyService.getInstance(dirPath);
143 141
			this.contextString = PropertyService.getProperty("application.context");
144
		} catch (IOException e) {
145
			System.err.println("Error in loading options: " + e.getMessage());
142
		} catch (ServiceException se) {
143
			System.err.println("Error in loading properties: " + se.getMessage());
146 144
		} catch (PropertyNotFoundException pnfe) {
147 145
			System.err.println("couldn't read property during initialization: "
148 146
					+ pnfe.getMessage());
src/edu/ucsb/nceas/metacat/MetaCatServlet.java
162 162
            
163 163
            ServletContext context = config.getServletContext();
164 164
             
165
            // Initialize the properties file for our options
165
            // Initialize the properties file
166 166
            String dirPath = context.getRealPath(CONFIG_DIR);
167 167
            
168 168
            String LOG_CONFIG_NAME = dirPath + "/log4j.properties";
169 169
            PropertyConfigurator.configureAndWatch(LOG_CONFIG_NAME);
170 170
            
171
            PropertyService propertyService = PropertyService.getInstance(context);
171
            PropertyService propertyService = PropertyService.getInstance(dirPath);
172 172
            logMetacat.debug("PropertyService singleton created " + propertyService);
173 173
            
174 174
            SkinPropertyService skinPropertyService = SkinPropertyService.getInstance(context);
......
237 237
                    skinOption.load(fis);
238 238
                    fis.close();
239 239
                } catch (IOException ioe) {
240
                    logMetacat.error("Error in loading options for skin " + "skinName" +" : "
240
                    logMetacat.error("Error in loading properties for skin " + "skinName" +" : "
241 241
                            + ioe.getMessage());
242 242
                }
243 243
                MetaCatUtil.addSkinConfig(skinName, skinOption);
......
3641 3641
        return newAccNum;
3642 3642
    }
3643 3643
    
3644
//    /**
3645
//     * Handle configuration of the servlet the first time that Metacat starts
3646
//     * by collecting necessary configuration information from the administrator.
3647
//     *
3648
//     * @param request the http request information
3649
//     * @param response the http response to be sent back to the client
3650
//     */
3651
//    private void configureMetacat(HttpServletRequest request,
3652
//            HttpServletResponse response) {
3653
//        Options options = (Options)Options.getInstance();
3654
//        String action = request.getParameter("action");
3655
//        if (action == null || !action.equals("configure")) {
3656
//            // The servlet configuration parameters have not been set, so
3657
//            // redirect to a web form for configuring metacat
3658
//            
3659
//            // Load the properties metadata file to determine which properties
3660
//            // need to be configured, and include this metadata object in
3661
//            // the request so that the JSP page can use the metadata in
3662
//            // constructing the editing form
3663
//            String dirPath = this.getServletContext().getRealPath(CONFIG_DIR);
3664
//            File metadataFile = new File(dirPath, CONFIG_NAME+".metadata");
3665
//            OptionsMetadata metadata = null;
3666
//            
3667
//            try {
3668
//                Reader reader = new FileReader(metadataFile);
3669
//                metadata = new OptionsMetadata(reader);
3670
//                reader.close();
3671
//                request.setAttribute("metadata", metadata);
3672
//            } catch (IOException e) {
3673
//                Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
3674
//                logMetacat.error("Error reading properties metadata: " +
3675
//                        e.getMessage());
3676
//            }
3677
//            
3678
//            // Also add the list of options and their values to the request
3679
//            Enumeration properties = options.propertyNames();
3680
//            while (properties.hasMoreElements()) {
3681
//                String name = (String)properties.nextElement();
3682
//                request.setAttribute( name, MetaCatUtil.getOption(name));
3683
//            }
3684
//            properties = options.propertyNames();
3685
//            request.setAttribute("optionslist", properties);
3686
//            
3687
//            // Forward the request to the JSP page
3688
//            forwardRequest(request, response,
3689
//                    MetaCatUtil.getOption("configurationPage"));
3690
//        } else {
3691
//            // The configuration form is being submitted and needs to be
3692
//            // processed, setting the properties in the configuration file
3693
//            // then restart metacat
3694
//            
3695
//            // TODO: Should first validate that the options provided are
3696
//            // legitimate, and possibly even test them (for example, use
3697
//            // the database connection info to connect to the database)
3698
//            
3699
//            // For each property, check if it is changed and save it
3700
//            Enumeration properties = options.propertyNames();
3701
//            while (properties.hasMoreElements()) {
3702
//                String name = (String)properties.nextElement();
3703
//                checkAndSetOption(request, name);
3704
//            }
3705
//            
3706
//            // Now that the options have been set, change the 'configured'
3707
//            // option to 'true' so that normal metacat requests will go through
3708
//            MetaCatUtil.setOption("configured", "true");
3709
//            
3710
//            // Reload the servlet so that the database connections are loaded
3711
//            // In the absence of being able to do this programatically, then
3712
//            // redirect to a response page with instructions to restart
3713
//            forwardRequest(request, response,
3714
//                    MetaCatUtil.getOption("configurationSuccessPage"));
3715
//        }
3716
//    }
3717
    
3718
//    /**
3719
//     * Take input from the user in an HTTP request about an option to be
3720
//     * changed and update the options property file with that new value
3721
//     * if it has changed from the value that was originally set.
3722
//     *
3723
//     * @param request that was generated by the user
3724
//     * @param response to send output back to the user
3725
//     * @param optionName the name of the option to be checked and set
3726
//     */
3727
//    private void checkAndSetOption(HttpServletRequest request,
3728
//            String optionName) {
3729
//        String value = MetaCatUtil.getOption(optionName);
3730
//        String newValue = request.getParameter(optionName);
3731
//        if (newValue != null && !newValue.equals(value)) {
3732
//            MetaCatUtil.setOption(optionName, newValue);
3733
//        }
3734
//    }
3735
    
3736 3644
    /**
3737 3645
     * Forward a request that was received by this servlet on to another
3738 3646
     * JSP page or servlet to continue handling the request.
src/edu/ucsb/nceas/metacat/service/PropertyService.java
62 62
	
63 63
	private static final String MAIN_CONFIG_NAME = "metacat.properties";
64 64
	private static final String ORG_CONFIG_NAME = "org.properties";
65
	private static final String CONFIG_DIR = "WEB-INF";
66 65
	
67 66
	private static String mainPropertiesFilePath = null;
68 67
	private static SortedProperties mainProperties = null;
......
86 85
	 * 
87 86
	 * @param servletContext the context we will use to get relative paths
88 87
	 */
89
	private PropertyService(ServletContext servletContext) throws ServiceException {
88
	private PropertyService(String configDir) throws ServiceException {
90 89
		try {
91
		initialize(servletContext);
90
			initialize(configDir);
92 91
		} catch (GeneralPropertyException gpe) {
93
			throw new ServiceException("Properties problem while initializing PropertyService: " + gpe.getMessage());
92
			throw new ServiceException("Properties problem while initializing " + 
93
					"PropertyService: " + gpe.getMessage());
94 94
		} catch (IOException ioe) {
95
			throw new ServiceException("I/O Problem while initializing PropertyService: " + ioe.getMessage());
95
			throw new ServiceException("I/O Problem while initializing " + 
96
					"PropertyService: " + ioe.getMessage());
96 97
		}
97 98
	}
98 99
	
......
102 103
	 * @param servletContext the context we will use to get relative paths
103 104
	 * @return the single instance of AuthAdmin
104 105
	 */
105
	public static PropertyService getInstance(ServletContext servletContext) throws ServiceException {
106
	public static PropertyService getInstance(String configDir) throws ServiceException {
106 107
		if (propertyService == null) {
107
			propertyService = new PropertyService(servletContext);
108
			propertyService = new PropertyService(configDir);
108 109
		}
109 110
		return propertyService;
110 111
	}
......
114 115
	 * 
115 116
	 * @param servletContext the context we will use to get relative paths
116 117
	 */
117
	public void initialize(ServletContext servletContext)
118
	public void initialize(String configDir)
118 119
			throws IOException, GeneralPropertyException {
119 120
		
120 121
		logMetacat.debug("Initializing PropertyService");
121 122

  
122 123
		// mainProperties will hold the primary configuration values for metacat.
123
		mainPropertiesFilePath = servletContext.getRealPath(CONFIG_DIR) + FileUtil.getFS() + MAIN_CONFIG_NAME;
124
		mainPropertiesFilePath = configDir + FileUtil.getFS() + MAIN_CONFIG_NAME;
124 125
		if (mainProperties == null) {
125 126
			mainProperties = new SortedProperties(mainPropertiesFilePath);
126 127
			mainProperties.load();
......
130 131
			// mainMetaData holds configuration information about main properties.
131 132
			// This is primarily used to display input fields on the configuration
132 133
			// page. The information is retrieved from an xml metadata file
133
			propertiesMetaDataFilePath = servletContext.getRealPath(CONFIG_DIR) + FileUtil.getFS() + MAIN_CONFIG_NAME + ".metadata.xml";
134
			propertiesMetaDataFilePath = configDir + FileUtil.getFS() + MAIN_CONFIG_NAME + ".metadata.xml";
134 135
			if (mainMetaData == null) {
135 136
				mainMetaData = new PropertiesMetaData(propertiesMetaDataFilePath);
136 137
			}
......
140 141
			// organization. This is primarily used to display input fields on 
141 142
			// the organization configuration page. The information is retrieved 
142 143
			// from an xml metadata file dedication just to organization properties.
143
			orgMetaDataFilePath = servletContext.getRealPath(CONFIG_DIR) + FileUtil.getFS() + ORG_CONFIG_NAME + ".metadata.xml";
144
			orgMetaDataFilePath = configDir + FileUtil.getFS() + ORG_CONFIG_NAME + ".metadata.xml";
144 145
			if (orgMetaData == null) {
145 146
				orgMetaData = new PropertiesMetaData(orgMetaDataFilePath);
146 147
			}
src/edu/ucsb/nceas/metacat/harvesterClient/MetUpload.java
24 24

  
25 25
package edu.ucsb.nceas.metacat.harvesterClient;
26 26

  
27
import edu.ucsb.nceas.utilities.Options;
28 27
import java.io.*;
29 28
import java.util.*;
30 29
import javax.servlet.ServletConfig;
......
192 191
		this.config = config;
193 192
		this.context = config.getServletContext();
194 193
		dirPath = context.getRealPath(CONFIG_DIR);
195
		File propertyFile = new File(dirPath, CONFIG_NAME);
196 194

  
197 195
		try {
198
			PropertyService.getInstance(this.context);
196
			PropertyService.getInstance(dirPath);
199 197
			metacatURL = SystemUtil.getServletURL();
200 198
		} catch (ServiceException se) {
201 199
			System.out.println("Service problem while initializing MetUpload: " + se.getMessage());
src/edu/ucsb/nceas/metacat/EML201DocumentCorrector.java
1 1
package edu.ucsb.nceas.metacat;
2 2

  
3
import java.io.File;
4 3
import java.sql.Statement;
5 4

  
6 5
import org.apache.log4j.Logger;
7 6

  
8
import edu.ucsb.nceas.utilities.Options;
7
import edu.ucsb.nceas.metacat.service.PropertyService;
9 8

  
10 9
/**
11 10
 * Before Metacat 1.8.1 release, Metacat uses the eml201 schema with the tag
......
124 123
     {
125 124
    	 
126 125
    	 //initialize options and connection pool
127
    	 Options.initialize(new File("build/metacat.properties"));
126
    	 PropertyService.getInstance("build/metacat.properties");
128 127
    	 DBConnectionPool connPool = DBConnectionPool.getInstance();
129
    	 
130
    	 
128
    	   	 
131 129
    	 // run the thread
132 130
    	 EML201DocumentCorrector correct = new EML201DocumentCorrector();
133 131
    	 //Thread thread = new Thread(correct);

Also available in: Unified diff