CommonLibrary(util/rest-client) code upload.
[vfc/nfvo/wfengine.git] / CommonLibrary / common-util / src / main / java / org / openo / baseservice / util / impl / SystemEnvVariablesDefImpl.java
1 /*
2  * Copyright (c) 2016, Huawei Technologies Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.openo.baseservice.util.impl;
17
18 import org.openo.baseservice.util.inf.SystemEnvVariables;
19
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 import java.io.File;
24 import java.io.IOException;
25
26 /**
27  * System environment variable helper implementation.<br/>
28  * <p>
29  * </p>
30  * 
31  * @author
32  * @version SDNO 0.5 24-Jun-2016
33  */
34 public class SystemEnvVariablesDefImpl extends SystemEnvVariables {
35
36     private static final Logger LOG = LoggerFactory.getLogger(SystemEnvVariablesDefImpl.class);
37
38     @Override
39     public String getAppRoot() {
40         String appRoot = null;
41         appRoot = System.getProperty("catalina.base");
42         if(appRoot != null) {
43             appRoot = getCanonicalPath(appRoot);
44         }
45         return appRoot;
46     }
47
48     /**
49      * Gets the canonical path<br/>
50      * 
51      * @param inPath input path
52      * @return the canonical path.
53      * @since SDNO 0.5
54      */
55     private String getCanonicalPath(final String inPath) {
56         String path = null;
57         try {
58             if(inPath != null) {
59                 final File file = new File(inPath);
60                 path = file.getCanonicalPath();
61             }
62         } catch(final IOException e) {
63             LOG.error("file.getCanonicalPath() IOException:", e);
64         }
65         return path;
66     }
67
68 }