gt:         catch (FileNotFoundException e) {
context: /*
   * Copyright (c) 2015 Memorial Sloan-Kettering Cancer Center.
   *
   * This library is distributed in the hope that it will be useful, but WITHOUT
   * ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
   * FOR A PARTICULAR PURPOSE. The software and documentation provided hereunder
   * is on an "as is" basis, and Memorial Sloan-Kettering Cancer Center has no
   * obligations to provide maintenance, support, updates, enhancements or
   * modifications. In no event shall Memorial Sloan-Kettering Cancer Center be
   * liable to any party for direct, indirect, special, incidental or
   * consequential damages, including lost profits, arising out of the use of this
   * software and its documentation, even if Memorial Sloan-Kettering Cancer
   * Center has been advised of the possibility of such damage.
   */
  
  /*
   * This file is part of cBioPortal.
   *
   * cBioPortal is free software: you can redistribute it and/or modify
   * it under the terms of the GNU Affero General Public License as
   * published by the Free Software Foundation, either version 3 of the
   * License.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU Affero General Public License for more details.
   *
   * You should have received a copy of the GNU Affero General Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  
  package org.mskcc.cbio.portal.util;
  
  import org.mskcc.cbio.portal.servlet.QueryBuilder;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.springframework.security.core.Authentication;
  import org.springframework.security.core.context.SecurityContextHolder;
  
  import java.io.*;
  import java.net.HttpURLConnection;
  import java.util.*;
  import java.net.URL;
  
  
  /**
   * Utility class for getting / setting global properties.
   */
  public class GlobalProperties {
  
      public static final String HOME_DIR = "PORTAL_HOME";
      private static final String propertiesFilename = "portal.properties";
  
      public static final String PATHWAY_COMMONS_URL = "pathway_commons.url";
      public static final String UCSC_CANCER_GENOMICS_URL = "ucsc_cancer_genomics.url";
  	public static final String SEGFILE_URL = "segfile.url";
  	public static final String OPENSSL_BINARY = "openssl.binary";
  	public static final String SIGNATURE_KEY = "signature.key";
  	public static final String ENCRYPTION_KEY = "encryption.key";
  	public static final String BROAD_BAM_URL = "broad.bam.url";
  	public static final String BROAD_BAM_CHECKING_URL = "broad.bam.checking.url";
  	public static final String IGV_BAM_LINKING = "igv.bam.linking";
  	public static final String IGV_BAM_LINKING_STUDIES = "igv.bam.linking.studies";
      public static final String AUTHENTICATE = "authenticate";
      public static final String AUTHORIZATION = "authorization";
      public static final String FILTER_GROUPS_BY_APPNAME = "filter_groups_by_appname";
      public static final String INCLUDE_NETWORKS = "include_networks";
      public static final String GOOGLE_ANALYTICS_PROFILE_ID = "google_analytics_profile_id";
      public static final String GENOMESPACE = "genomespace";
  
      public static final String APP_NAME = "app.name";
      public static final String DEFAULT_APP_NAME = "public_portal";
      
      public static final String APP_VERSION = "app.version";
      public static final String SKIN_TITLE = "skin.title";
      public static final String DEFAULT_SKIN_TITLE = "cBioPortal for Cancer Genomics";
      public static final String SKIN_BLURB = "skin.blurb";
      // blurb default
      public static final String DEFAULT_SKIN_BLURB = "The cBioPortal for Cancer Genomics provides " +
              "<b>visualization</b>, <b>analysis</b> and <b>download</b> of large-scale cancer genomics data sets. " +
              "<p>Please adhere to <u><a href=\"http://cancergenome.nih.gov/abouttcga/policies/publicationguidelines\"> " +
              "the TCGA publication guidelines</a></u> when using TCGA data in your publications.</p> " +
              "<p><b>Please cite</b> <a href=\"http://www.ncbi.nlm.nih.gov/pubmed/23550210\">Gao " +
              "et al. <i>Sci. Signal.</i> 2013</a> &amp;  " +
              "<a href=\"http://cancerdiscovery.aacrjournals.org/content/2/5/401.abstract\">" +
              "Cerami et al. <i>Cancer Discov.</i> 2012</a> when publishing results based on cBioPortal.</p>\n";
      public static final String SKIN_TAG_LINE_IMAGE = "skin.tag_line_image";
      public static final String DEFAULT_SKIN_TAG_LINE_IMAGE = "images/tag_line.png";
      public static final String SKIN_EMAIL_CONTACT = "skin.email_contact";
      public static final String DEFAULT_EMAIL_CONTACT = "cbioportal at googlegroups dot com";
      public static final String SKIN_SHOW_NEWS_TAB = "skin.show_news_tab";
      public static final String SKIN_SHOW_DATA_TAB = "skin.show_data_tab";
      public static final String SKIN_RIGHT_NAV_SHOW_DATA_SETS = "skin.right_nav.show_data_sets";
      public static final String SKIN_RIGHT_NAV_SHOW_EXAMPLES = "skin.right_nav.show_examples";
      public static final String SKIN_RIGHT_NAV_SHOW_TESTIMONIALS = "skin.right_nav.show_testimonials";
      public static final String SKIN_AUTHORIZATION_MESSAGE = "skin.authorization_message";
      public static final String DEFAULT_AUTHORIZATION_MESSAGE = "Access to this portal is only available to authorized users.";
      public static final String SKIN_EXAMPLE_STUDY_QUERIES = "skin.example_study_queries";
      public static final String DEFAULT_SKIN_EXAMPLE_STUDY_QUERIES =
              "tcga\n" +
              "tcga -provisional\n" +
              "tcga -moratorium\n" +
              "tcga OR icgc\n" +
              "-\"cell line\"\n" +
              "prostate mskcc\n" +
              "esophageal OR stomach\n" +
              "serous\n" +
              "breast";
      public static final String SKIN_DATASETS_HEADER = "skin.data_sets_header";
      public static final String DEFAULT_SKIN_DATASETS_HEADER = "The portal currently contains data from the following " +
              "cancer genomics studies.  The table below lists the number of available samples per data type and tumor.";
      public static final String SKIN_DATASETS_FOOTER = "skin.data_sets_footer";
      public static final String DEFAULT_SKIN_DATASETS_FOOTER = "Data sets of TCGA studies were downloaded from Broad " +
              "Firehose (http://gdac.broadinstitute.org) and updated monthly. In some studies, data sets were from the " +
              "TCGA working groups directly.";
  
      public static final String PATIENT_VIEW_PLACEHOLDER = "patient_view_placeholder";
      public static final String PATIENT_VIEW_GENOMIC_OVERVIEW_CNA_CUTOFF = "patient_view_genomic_overview_cna_cutoff";
      public static final double[] DEFAULT_GENOMIC_OVERVIEW_CNA_CUTOFF = new double[]{0.2,1.5};
      public static final String PATIENT_VIEW_DIGITAL_SLIDE_IFRAME_URL = "digitalslidearchive.iframe.url";
      public static final String PATIENT_VIEW_DIGITAL_SLIDE_META_URL = "digitalslidearchive.meta.url";
      public static final String PATIENT_VIEW_TCGA_PATH_REPORT_URL = "tcga_path_report.url";
      public static final String ONCOKB_URL = "oncokb.url";
  
      public static final String SESSION_SERVICE_URL = "session.service.url";
  
      // properties for showing the right logo in the header_bar and default logo
      public static final String SKIN_RIGHT_LOGO = "skin.right_logo";
      public static final String DEFAULT_SKIN_RIGHT_LOGO = "images/mskcc_logo_3d_grey.jpg";
  
      // properties for hiding/showing tabs in the header navigation bar
      public static final String SKIN_SHOW_WEB_API_TAB = "skin.show_web_api_tab";
      public static final String SKIN_SHOW_R_MATLAB_TAB = "skin.show_r_matlab_tab";
      public static final String SKIN_SHOW_TUTORIALS_TAB = "skin.show_tutorials_tab";
      public static final String SKIN_SHOW_FAQS_TAB = "skin.show_faqs_tab";
      public static final String SKIN_SHOW_TOOLS_TAB = "skin.show_tools_tab";
      public static final String SKIN_SHOW_ABOUT_TAB = "skin.show_about_tab";
      public static final String SKIN_SHOW_VISUALIZE_YOUR_DATA_TAB = "skin.show_visualize_your_data_tab";
  
      // property for setting the news blurb in the right column
      public static final String SKIN_RIGHT_NAV_WHATS_NEW_BLURB = "skin.right_nav.whats_new_blurb";
      public static final String DEFAULT_SKIN_WHATS_NEW_BLURB = 
              "<form action=\"http://groups.google.com/group/cbioportal-news/boxsubscribe\"> &nbsp;&nbsp;&nbsp;&nbsp;" +
              "<b>Sign up for low-volume email news alerts:</b></br> &nbsp;&nbsp;&nbsp;&nbsp;<input type=\"text\" " +
              "name=\"email\" title=\"Subscribe to mailing list\"> <input type=\"submit\" name=\"sub\" value=\"Subscribe\"> " +
              "</form> &nbsp;&nbsp;&nbsp;&nbsp;<b>Or follow us <a href=\"http://www.twitter.com/cbioportal\">" +
              "<i>@cbioportal</i></a> on Twitter</b>\n";
  
      // footer
      public static final String SKIN_FOOTER = "skin.footer";
      public static final String DEFAULT_SKIN_FOOTER = " | <a href=\"http://www.mskcc.org/mskcc/html/44.cfm\">MSKCC</a>" +
              " | <a href=\"http://cancergenome.nih.gov/\">TCGA</a>";
  
      // login contact
      public static final String SKIN_LOGIN_CONTACT_HTML = "skin.login.contact_html";
      public static final String DEFAULT_SKIN_LOGIN_CONTACT_HTML = "If you think you have received this message in " +
              "error, please contact us at <a style=\"color:#FF0000\" href=\"mailto:cbioportal-access@cbio.mskcc.org\">" +
              "cbioportal-access@cbio.mskcc.org</a>";
  
      // properties for hiding/showing tabs in the patient view
      public static final String SKIN_PATIENT_VIEW_SHOW_DRUGS_TAB="skin.patient_view.show_drugs_tab";
  
      // property for setting the saml registration html
      public static final String SKIN_LOGIN_SAML_REGISTRATION_HTML = "skin.login.saml.registration_html";
      public static final String DEFAULT_SKIN_LOGIN_SAML_REGISTRATION_HTML = "Sign in with MSK";
  
      // property for the saml entityid
      public static final String SAML_IDP_METADATA_ENTITYID="saml.idp.metadata.entityid";
  
      // property for the custom header tabs
      public static final String SKIN_CUSTOM_HEADER_TABS="skin.custom_header_tabs";
  
      // properties for the FAQ, about us, news and examples
      public static final String SKIN_BASEURL="skin.documentation.baseurl";
      public static final String DEFAULT_SKIN_BASEURL="https://raw.githubusercontent.com/cBioPortal/cbioportal/master/docs/";
      public static final String SKIN_DOCUMENTATION_MARKDOWN="skin.documentation.markdown";
  
      public static final String SKIN_FAQ="skin.documentation.faq";
      public static final String DEFAULT_SKIN_FAQ="FAQ.md";
      public static final String SKIN_ABOUT="skin.documentation.about";
      public static final String DEFAULT_SKIN_ABOUT="About-Us.md";
      public static final String SKIN_NEWS="skin.documentation.news";
      public static final String DEFAULT_SKIN_NEWS="News.md";
  
      public static final String SKIN_EXAMPLES_RIGHT_COLUMN="skin.examples_right_column";
      public static final String DEFAULT_SKIN_EXAMPLES_RIGHT_COLUMN="../../../content/examples.html";
      
      public static final String ALWAYS_SHOW_STUDY_GROUP="always_show_study_group";
  
      // property for text shown at the right side of the Select Patient/Case set, which
      // links to the study view
      public static final String SKIN_STUDY_VIEW_LINK_TEXT="skin.study_view.link_text";
      public static final String DEFAULT_SKIN_STUDY_VIEW_LINK_TEXT="To build your own case set, try out our enhanced " +
              "Study View.";
  
      public static final String MYCANCERGENOME_SHOW = "mycancergenome.show";
      public static final String ONCOKB_GENE_STATUS = "oncokb.geneStatus";
      public static final String SHOW_HOTSPOT = "show.hotspot";
      
      public static final String RECACHE_STUDY_AFTER_UPDATE = "recache_study_after_update";
      
      public static final String DB_VERSION = "db.version";
      
      public static final String DARWIN_AUTH_URL = "darwin.auth_url";
      public static final String DARWIN_RESPONSE_URL = "darwin.response_url";
      public static final String DARWIN_AUTHORITY = "darwin.authority";
      public static final String CIS_USER = "cis.user";
      public static final String DISABLED_TABS = "disabled_tabs";
      
      public static final String PRIORITY_STUDIES = "priority_studies";
      
      private static Log LOG = LogFactory.getLog(GlobalProperties.class);
      private static Properties properties = initializeProperties();
  
      private static Properties initializeProperties()
      {
          return loadProperties(getResourceStream());
      }
  
      private static InputStream getResourceStream()
      {
          String resourceFilename = null;
          InputStream resourceFIS = null;
  
          try {
              String home = System.getenv(HOME_DIR);
              if (home != null) {
                   resourceFilename =
                      home + File.separator + GlobalProperties.propertiesFilename;
                  if (LOG.isInfoEnabled()) {
                      LOG.info("Attempting to read properties file: " + resourceFilename);
                  }
                  resourceFIS = new FileInputStream(resourceFilename);
                  if (LOG.isInfoEnabled()) {
                      LOG.info("Successfully read properties file");
                  }
              }
          }
  