001    /*
002     * file CcDemoProps.java
003     *
004     * Licensed Materials - Property of IBM
005     * Restricted Materials of IBM - you are allowed to copy, modify and 
006     * redistribute this file as part of any program that interfaces with 
007     * IBM Rational CM API.
008     *
009     * com.ibm.rational.stp.client.samples.cc.CcDemoProps
010     *
011     * (C) Copyright IBM Corporation 2008.  All Rights Reserved.
012     * Note to U.S. Government Users Restricted Rights:  Use, duplication or 
013     * disclosure restricted by GSA ADP  Schedule Contract with IBM Corp.
014     */
015    
016    package com.ibm.rational.stp.client.samples.cc;
017    
018    import java.io.File;
019    import java.io.FileInputStream;
020    import java.io.InputStream;
021    import java.util.Properties;
022    
023    public class CcDemoProps {
024    
025        /**
026         * The name of the default demo property file
027         */
028        private static final String PROPS_FILE = "cc_cmapi.props";
029        private static Properties m_props;
030        private final File m_propsFile;
031    
032        /**
033         * Construct instance using the default properties file $HOME/cc_cmapi.props
034         */
035        public CcDemoProps() throws Exception {
036            this(getDefaultPropsFile());
037        }
038    
039        /**
040         * Construct instance using the specified properties file.
041         */
042        public CcDemoProps(File propsFile) throws Exception {
043            InputStream propStream = new FileInputStream(propsFile);
044            m_props = new Properties();
045            m_props.load(propStream);
046            m_propsFile = propsFile;
047        }
048    
049        /**
050         * User's OS login name on the CM Server.
051         */
052        public String getLoginName() {
053            return getRequired("loginName");
054        }
055    
056        /**
057         * User's OS login domain on the CM Server.
058         * Typically required on Windows CM Server but not on Unix
059         */
060        public String getLoginDomain() {
061            return m_props.getProperty("loginDomain");
062        }
063    
064        /**
065         * User's OS login name and domain on the CM Server in the form
066         * <code>DOMAIN\loginname</code>.
067         */
068        public String getLoginNameAndDomain() {
069            String domain = getLoginDomain();
070            if (domain != null && domain.length() > 0) {
071                return domain + "\\" + getLoginName();
072            } else {
073                return getLoginName();
074            }
075        }
076    
077        /**
078         * CearCase domain password on the CM Server.
079         */
080        public String getPassword() {
081            return getRequired("password");
082        }
083    
084        /**
085         * URL of CM Server.
086         */
087        public String getCmServerUrl() {
088            return getRequired("serverUrl");
089        }
090    
091        /**
092         * VOB tag of the demo UCM project VOB.
093         */
094        public String getDemoUcmProjectVob() {
095            return getRequired("demoUcmProjectVob");
096        }
097    
098        /**
099         * Client-side temporary directory for creating temp web views, etc.
100         * E.g., "c:\temp", /var/tmp
101         */
102        public File getTempDir() {
103            return new File(getRequired("tempDir"));
104        }
105    
106        private String getRequired(String name) {
107            String value = m_props.getProperty(name);
108            if (value == null || value.length() == 0) {
109                throw new IllegalStateException("Missing required property '" + name
110                        + "' in property file: " + m_propsFile);
111            }
112            return m_props.getProperty(name);
113        }
114    
115        /**
116         * Get the default properties file.  By default, look in the current user's
117         * home directory for a file called "cc_cmapi.props".
118         */
119        private static File getDefaultPropsFile() throws Exception {
120            File propsFile = new File(System.getProperty("user.home"), PROPS_FILE);
121            if ( ! propsFile.exists()) {
122                throw new Exception("Missing property file: " + propsFile);
123            }
124            return propsFile;
125        }
126    }