001package jmri.profile; 002 003import java.io.File; 004import java.util.ArrayList; 005import java.util.Arrays; 006import java.util.prefs.BackingStoreException; 007import jmri.util.prefs.JmriPreferencesProvider; 008import org.slf4j.Logger; 009import org.slf4j.LoggerFactory; 010 011public class ProfileProperties implements AuxiliaryProperties { 012 013 private final File path; 014 015 private final static Logger log = LoggerFactory.getLogger(ProfileProperties.class); 016 017 public ProfileProperties(Profile project) { 018 this.path = project.getPath(); 019 } 020 021 /** 022 * Package protected constructor used in 023 * {@link jmri.profile.Profile#Profile(java.io.File, boolean)}. 024 * 025 * @param path Path to a partially constructed Profile 026 */ 027 ProfileProperties(File path) { 028 this.path = path; 029 } 030 031 @Override 032 public String get(String key, boolean shared) { 033 return JmriPreferencesProvider.getPreferences(path, null, shared).node(Profile.PROFILE).get(key, null); 034 } 035 036 @Override 037 public Iterable<String> listKeys(boolean shared) { 038 try { 039 String[] keys = JmriPreferencesProvider.getPreferences(path, null, shared).node(Profile.PROFILE).keys(); 040 return new ArrayList<>(Arrays.asList(keys)); 041 } catch (BackingStoreException ex) { 042 log.error("Unable to read properties.", ex); 043 return new ArrayList<>(); 044 } 045 } 046 047 @Override 048 public void put(String key, String value, boolean shared) { 049 JmriPreferencesProvider.getPreferences(path, null, shared).node(Profile.PROFILE).put(key, value); 050 } 051 052}