/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.fs.hdfsoverhttp;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.servlet.ServletContext;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import org.apache.hadoop.fs.Path;

public class SysConfig {

    private final static Logger log = LogManager.getLogger(HdfsTool.class);
	
    private static Properties props;
	private static String CONF_FILE = "hdfs-over-http.conf";
	static String ROOT_DIR;
	static String HDFS_URI;
	static String INDEX_HTML;
	public static String README_FILE;
	public static String HEADER_FILE;
	public static boolean hasReadme;
	public static boolean hasHeader;
    
	/**
	 * get parameter from the config file
	 * @param context
	 */
    static public void init(ServletContext context){
		if(props == null){
			try{
				props = getProps(context);
	    		ROOT_DIR = String.trim(props.getProperty("root-dir","/"));
	    		if(ROOT_DIR.endsWith(Path.SEPARATOR)){
	    			ROOT_DIR = ROOT_DIR.substring(0,ROOT_DIR.length() - 1);
	    		}
	    		
	    		HDFS_URI = String.trim(props.getProperty("hdfs-uri"));
	    		
	    		INDEX_HTML = String.trim(props.getProperty("DirectoryIndex","index.html"));
	    		
	    		README_FILE = String.trim(props.getProperty("ReadmeName"));
	    		if(README_FILE != null)hasReadme = true;
	    		HEADER_FILE = String.trim(props.getProperty("HeaderName",""));
	    		if(HEADER_FILE != null)hasHeader = true;

			}catch(IOException e){
				log.error(CONF_FILE + " doesn't exist",e);
			}
		}
    }
    
    /**
     * load configure file
     * @param context
     * @return object of property
     * @throws IOException
     */
	static private Properties getProps(ServletContext context) throws IOException{
		Properties props = new Properties();
		InputStream inputStream=context.getResourceAsStream("/WEB-INF/conf/" + CONF_FILE);
		props.load(inputStream);
		return props;
    }
	
}

@@ -1667,28 +1667,16 @@
 T_DIR = 
-String.trim(
 props.ge
@@ -1700,16 +1700,22 @@
 ir%22,%22/%22)
+.trim(
 );%0A%09    
@@ -1854,28 +1854,16 @@
 S_URI = 
-String.trim(
 props.ge
@@ -1883,16 +1883,22 @@
 fs-uri%22)
+.trim(
 );%0A%09    
@@ -1920,28 +1920,16 @@
 _HTML = 
-String.trim(
 props.ge
@@ -1968,16 +1968,22 @@
 x.html%22)
+.trim(
 );%0A%09    
@@ -2002,36 +2002,24 @@
 ADME_FILE = 
-String.trim(
 props.getPro
@@ -2037,16 +2037,22 @@
 meName%22)
+.trim(
 );%0A%09    
@@ -2119,20 +2119,8 @@
 E = 
-String.trim(
 prop
@@ -2149,16 +2149,22 @@
 ame%22,%22%22)
+.trim(
 );%0A%09    

trim the space character of system config value