ServerPropertiesBase.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.generic_project.utils;

  21. import java.util.Properties;

  22. import org.openspcoop2.generic_project.exception.ServiceException;
  23. import org.openspcoop2.utils.Utilities;

  24. /**
  25.  * ServerProperties
  26.  *
  27.  * @author Poli Andrea (apoli@link.it)
  28.  * @author $Author$
  29.  * @version $Rev$, $Date$
  30.  */
  31. public class ServerPropertiesBase {


  32.        
  33.     // ------- Instance -------------
  34.    
  35.     private LoaderProperties loader = null;
  36.    
  37.     public ServerPropertiesBase(String filePropertiesName) throws ServiceException{
  38.         this.loader = new LoaderProperties(filePropertiesName);
  39.     }
  40.     public ServerPropertiesBase(Properties properties) throws ServiceException{
  41.         this.loader = new LoaderProperties(properties);
  42.     }
  43.    
  44.     public String getProperty(String name,boolean required) throws ServiceException{
  45.         String tmp = this.loader.getProperties().getProperty(name);
  46.         if(tmp==null){
  47.             if(required){
  48.                 throw new ServiceException("Property ["+name+"] not found");
  49.             }else{
  50.                 return null;
  51.             }
  52.         }
  53.         else{
  54.             return tmp.trim();
  55.         }
  56.     }
  57.    
  58.     public Properties readProperties(String prefix) throws ServiceException{
  59.         try{
  60.             return Utilities.readProperties(prefix, this.loader.getProperties());
  61.         }catch(Exception e){
  62.             throw new ServiceException(e.getMessage(),e);
  63.         }
  64.     }
  65.    
  66.     public boolean getBooleanProperty(String name,boolean required) throws ServiceException{
  67.         String p = this.getProperty(name, required);
  68.         if("true".equalsIgnoreCase(p)){
  69.             return  true;
  70.         }
  71.         else{
  72.             return false;
  73.         }
  74.     }
  75.    
  76. }