Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
UserPreferences.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014-2020 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.core;
20 
21 import java.io.File;
22 import java.io.FileInputStream;
23 import java.io.IOException;
24 import java.nio.file.Paths;
25 import java.util.Arrays;
26 import java.util.List;
27 import java.util.Properties;
29 import java.util.prefs.BackingStoreException;
31 import java.util.prefs.PreferenceChangeListener;
32 import org.apache.commons.lang3.StringUtils;
33 import org.apache.commons.lang3.tuple.Triple;
34 import org.openide.util.Lookup;
35 import org.python.icu.util.TimeZone;
42 import org.sleuthkit.datamodel.CaseDbConnectionInfo;
43 import org.sleuthkit.datamodel.TskData.DbType;
44 
49 public final class UserPreferences {
50 
59  private static String getConfigPreferencePath(String identifier) {
60  return Paths.get(PlatformUtil.getUserConfigDirectory(), identifier + ".properties").toString();
61  }
62 
71  private static String getSharedPreferencePath(String identifier) {
72  return Paths.get(PlatformUtil.getModuleConfigDirectory(), identifier + ".properties").toString();
73  }
74 
75  private static final String VIEW_PREFERENCE_PATH = getSharedPreferencePath("ViewPreferences");
76  private static final String MACHINE_SPECIFIC_PREFERENCE_PATH = getConfigPreferencePath("MachineSpecificPreferences");
77  private static final String MODE_PREFERENCE_PATH = getConfigPreferencePath("ModePreferences");
78  private static final String EXTERNAL_SERVICE_PREFERENCE_PATH = getSharedPreferencePath("ExternalServicePreferences");
79 
80  private static final ConfigProperties viewPreferences = new ConfigProperties(VIEW_PREFERENCE_PATH);
81  private static final ConfigProperties machineSpecificPreferences = new ConfigProperties(MACHINE_SPECIFIC_PREFERENCE_PATH);
82  private static final ConfigProperties modePreferences = new ConfigProperties(MODE_PREFERENCE_PATH);
83  private static final ConfigProperties externalServicePreferences = new ConfigProperties(EXTERNAL_SERVICE_PREFERENCE_PATH);
84 
85  static {
86  // perform initial load to ensure disk preferences are loaded
87  try {
88  // make shared directory paths if they don't exist.
89  new File(PlatformUtil.getModuleConfigDirectory()).mkdirs();
90  viewPreferences.load();
91  machineSpecificPreferences.load();
92  modePreferences.load();
93  externalServicePreferences.load();
94  } catch (IOException ex) {
95  // can't log because logger requires UserPreferences.
96  // This shouldn't really be thrown unless their is a file access
97  // issue within the user config directory.
98  ex.printStackTrace();
99  }
100  }
101 
102  // view preferences
103  public static final String KEEP_PREFERRED_VIEWER = "KeepPreferredViewer"; // NON-NLS
104  public static final String HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE = "HideKnownFilesInDataSourcesTree"; //NON-NLS
105  public static final String HIDE_KNOWN_FILES_IN_VIEWS_TREE = "HideKnownFilesInViewsTree"; //NON-NLS
106  public static final String HIDE_SLACK_FILES_IN_DATA_SRCS_TREE = "HideSlackFilesInDataSourcesTree"; //NON-NLS
107  public static final String HIDE_SLACK_FILES_IN_VIEWS_TREE = "HideSlackFilesInViewsTree"; //NON-NLS
108  public static final String DISPLAY_TIMES_IN_LOCAL_TIME = "DisplayTimesInLocalTime"; //NON-NLS
109  public static final String TIME_ZONE_FOR_DISPLAYS = "TimeZoneForDisplays"; //NON-NLS
110  public static final String GROUP_ITEMS_IN_TREE_BY_DATASOURCE = "GroupItemsInTreeByDataSource"; //NON-NLS
111  public static final String SHOW_ONLY_CURRENT_USER_TAGS = "ShowOnlyCurrentUserTags";
112  public static final String HIDE_SCO_COLUMNS = "HideCentralRepoCommentsAndOccurrences"; //The key for this setting pre-dates the settings current functionality //NON-NLS
113  public static final String DISPLAY_TRANSLATED_NAMES = "DisplayTranslatedNames";
114  private static final boolean DISPLAY_TRANSLATED_NAMES_DEFAULT = true;
115  public static final String EXTERNAL_HEX_EDITOR_PATH = "ExternalHexEditorPath";
116  public static final String RESULTS_TABLE_PAGE_SIZE = "ResultsTablePageSize";
117 
118  // machine-specific settings
119  public static final String NUMBER_OF_FILE_INGEST_THREADS = "NumberOfFileIngestThreads"; //NON-NLS
120  public static final String PROCESS_TIME_OUT_ENABLED = "ProcessTimeOutEnabled"; //NON-NLS
121  public static final String PROCESS_TIME_OUT_HOURS = "ProcessTimeOutHours"; //NON-NLS
122  private static final int DEFAULT_PROCESS_TIMEOUT_HR = 60;
123  private static final String MAX_NUM_OF_LOG_FILE = "MaximumNumberOfLogFiles";
124  private static final int LOG_FILE_NUM_INT = 10;
125  public static final String SOLR_MAX_JVM_SIZE = "SolrMaxJVMSize";
126  private static final int DEFAULT_SOLR_HEAP_SIZE_MB_64BIT_PLATFORM = 2048;
127  private static final int DEFAULT_SOLR_HEAP_SIZE_MB_32BIT_PLATFORM = 512;
128  private static final String HEALTH_MONITOR_REPORT_PATH = "HealthMonitorReportPath";
129  private static final String TEMP_FOLDER = "Temp";
130  private static final String GEO_OSM_TILE_ZIP_PATH = "GeolocationOsmZipPath";
131  private static final String GEO_MBTILES_FILE_PATH = "GeolcoationMBTilesFilePath";
132 
133  // mode and enabled
134  public static final String SETTINGS_PROPERTIES = "AutoIngest";
135  private static final String MODE = "AutopsyMode"; // NON-NLS
136  private static final String APP_NAME = "AppName";
137 
138  // external services preferences
139  public static final String IS_MULTI_USER_MODE_ENABLED = "IsMultiUserModeEnabled"; //NON-NLS
140  private static final String GEO_TILE_OPTION = "GeolocationTileOption";
141  public static final String OCR_TRANSLATION_ENABLED = "OcrTranslationEnabled";
142  public static final String EXTERNAL_DATABASE_HOSTNAME_OR_IP = "ExternalDatabaseHostnameOrIp"; //NON-NLS
143  public static final String EXTERNAL_DATABASE_PORTNUMBER = "ExternalDatabasePortNumber"; //NON-NLS
144  public static final String EXTERNAL_DATABASE_NAME = "ExternalDatabaseName"; //NON-NLS
145  public static final String EXTERNAL_DATABASE_USER = "ExternalDatabaseUsername"; //NON-NLS
146  public static final String EXTERNAL_DATABASE_PASSWORD = "ExternalDatabasePassword"; //NON-NLS
147  public static final String EXTERNAL_DATABASE_TYPE = "ExternalDatabaseType"; //NON-NLS
148  private static final String SOLR8_SERVER_HOST = "Solr8ServerHost"; //NON-NLS
149  private static final String SOLR8_SERVER_PORT = "Solr8ServerPort"; //NON-NLS
150  private static final String SOLR4_SERVER_HOST = "IndexingServerHost"; //NON-NLS
151  private static final String SOLR4_SERVER_PORT = "IndexingServerPort"; //NON-NLS
152  private static final String ZK_SERVER_HOST = "ZookeeperServerHost"; //NON-NLS
153  private static final String ZK_SERVER_PORT = "ZookeeperServerPort"; //NON-NLS
154  private static final String MESSAGE_SERVICE_PASSWORD = "MessageServicePassword"; //NON-NLS
155  private static final String MESSAGE_SERVICE_USER = "MessageServiceUser"; //NON-NLS
156  private static final String MESSAGE_SERVICE_HOST = "MessageServiceHost"; //NON-NLS
157  private static final String MESSAGE_SERVICE_PORT = "MessageServicePort"; //NON-NLS
158  public static final String TEXT_TRANSLATOR_NAME = "TextTranslatorName";
159  private static final String DEFAULT_PORT_STRING = "61616";
160  private static final int DEFAULT_PORT_INT = 61616;
161  private static final String GEO_OSM_SERVER_ADDRESS = "GeolocationOsmServerAddress";
162 
163  // view preference keys used for moving from legacy files to new files
164  private static final List<String> VIEW_PREFERENCE_KEYS = Arrays.asList(
165  KEEP_PREFERRED_VIEWER,
166  HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE,
167  HIDE_KNOWN_FILES_IN_VIEWS_TREE,
168  HIDE_SLACK_FILES_IN_DATA_SRCS_TREE,
169  HIDE_SLACK_FILES_IN_VIEWS_TREE,
170  DISPLAY_TIMES_IN_LOCAL_TIME,
171  TIME_ZONE_FOR_DISPLAYS,
172  GROUP_ITEMS_IN_TREE_BY_DATASOURCE,
173  SHOW_ONLY_CURRENT_USER_TAGS,
174  HIDE_SCO_COLUMNS,
175  DISPLAY_TRANSLATED_NAMES,
176  EXTERNAL_HEX_EDITOR_PATH,
177  RESULTS_TABLE_PAGE_SIZE
178  );
179 
180  // machine preference keys used for moving from legacy files to new files
181  private static final List<String> MACHINE_PREFERENCE_KEYS = Arrays.asList(
182  NUMBER_OF_FILE_INGEST_THREADS,
183  PROCESS_TIME_OUT_ENABLED,
184  PROCESS_TIME_OUT_HOURS,
185  MAX_NUM_OF_LOG_FILE,
186  SOLR_MAX_JVM_SIZE,
187  HEALTH_MONITOR_REPORT_PATH,
188  TEMP_FOLDER,
189  GEO_OSM_TILE_ZIP_PATH,
190  GEO_MBTILES_FILE_PATH
191  );
192 
193  // mode preference keys used for moving from legacy files to new files
194  private static final List<String> MODE_PREFERENCE_KEYS = Arrays.asList(
195  SETTINGS_PROPERTIES,
196  MODE,
197  APP_NAME
198  );
199 
200  // external service preference keys used for moving from legacy files to new files
201  private static final List<String> EXTERNAL_SERVICE_KEYS = Arrays.asList(
202  IS_MULTI_USER_MODE_ENABLED,
203  GEO_TILE_OPTION,
204  OCR_TRANSLATION_ENABLED,
205  EXTERNAL_DATABASE_HOSTNAME_OR_IP,
206  EXTERNAL_DATABASE_PORTNUMBER,
207  EXTERNAL_DATABASE_NAME,
208  EXTERNAL_DATABASE_USER,
209  EXTERNAL_DATABASE_PASSWORD,
210  EXTERNAL_DATABASE_TYPE,
211  SOLR8_SERVER_HOST,
212  SOLR8_SERVER_PORT,
213  SOLR4_SERVER_HOST,
214  SOLR4_SERVER_PORT,
215  ZK_SERVER_HOST,
216  ZK_SERVER_PORT,
217  MESSAGE_SERVICE_PASSWORD,
218  MESSAGE_SERVICE_USER,
219  MESSAGE_SERVICE_HOST,
220  MESSAGE_SERVICE_PORT,
221  TEXT_TRANSLATOR_NAME,
222  GEO_OSM_SERVER_ADDRESS
223  );
224 
225  private static final String LEGACY_CONFIG_PATH = Paths.get(PlatformUtil.getUserConfigDirectory(), "Preferences", "org", "sleuthkit", "autopsy", "core.properties").toString();
226 
227  static void updateConfig() {
228  List<Triple<File, ConfigProperties, List<String>>> fileAndKeys = Arrays.asList(
229  Triple.of(new File(MODE_PREFERENCE_PATH), modePreferences, MODE_PREFERENCE_KEYS),
230  Triple.of(new File(MACHINE_SPECIFIC_PREFERENCE_PATH), machineSpecificPreferences, MACHINE_PREFERENCE_KEYS),
231  Triple.of(new File(VIEW_PREFERENCE_PATH), viewPreferences, VIEW_PREFERENCE_KEYS),
232  Triple.of(new File(EXTERNAL_SERVICE_PREFERENCE_PATH), externalServicePreferences, EXTERNAL_SERVICE_KEYS)
233  );
234 
235  boolean newSettingsExist = fileAndKeys.stream().anyMatch(triple -> triple.getLeft().exists());
236 
237  File oldSettingsFile = new File(LEGACY_CONFIG_PATH);
238  // copy old settings to new location.
239  if (oldSettingsFile.exists() && !newSettingsExist) {
240  try {
241  Properties allProperties = new Properties();
242  try (FileInputStream oldPropsStream = new FileInputStream(oldSettingsFile)) {
243  allProperties.load(oldPropsStream);
244  }
245 
246  for (Triple<File, ConfigProperties, List<String>> fileKeys : fileAndKeys) {
247  ConfigProperties newProperties = fileKeys.getMiddle();
248  for (String key : fileKeys.getRight()) {
249  String val = allProperties.getProperty(key);
250  if (val != null) {
251  newProperties.put(key, val);
252  }
253  }
254 
255  }
256  } catch (IOException ex) {
257  // can't log because logger requires UserPreferences.
258  // This shouldn't really be thrown unless their is a file access
259  // issue within the user config directory.
260  ex.printStackTrace();
261  }
262  }
263  }
264 
265  // Prevent instantiation.
266  private UserPreferences() {
267  }
268 
269  public enum SelectedMode {
271  AUTOINGEST
272  };
273 
279  public static SelectedMode getMode() {
280  if (ModuleSettings.settingExists(SETTINGS_PROPERTIES, MODE)) {
281  int ordinal = Integer.parseInt(ModuleSettings.getConfigSetting(SETTINGS_PROPERTIES, MODE));
282  return UserPreferences.SelectedMode.values()[ordinal];
283  }
285  }
286 
292  public static void setMode(SelectedMode mode) {
293  ModuleSettings.setConfigSetting(SETTINGS_PROPERTIES, MODE, Integer.toString(mode.ordinal()));
294  }
295 
302  public static void reloadFromStorage() throws BackingStoreException {
303  viewPreferences.sync();
304  machineSpecificPreferences.sync();
305  modePreferences.sync();
306  externalServicePreferences.sync();
307  }
308 
316  public static void saveToStorage() throws BackingStoreException {
317  viewPreferences.flush();
318  machineSpecificPreferences.flush();
319  modePreferences.flush();
320  externalServicePreferences.flush();
321  }
322 
323  public static void addChangeListener(PreferenceChangeListener listener) {
324  viewPreferences.addPreferenceChangeListener(listener);
325  machineSpecificPreferences.addPreferenceChangeListener(listener);
326  modePreferences.addPreferenceChangeListener(listener);
327  externalServicePreferences.addPreferenceChangeListener(listener);
328  }
329 
330  public static void removeChangeListener(PreferenceChangeListener listener) {
331  viewPreferences.removePreferenceChangeListener(listener);
332  machineSpecificPreferences.removePreferenceChangeListener(listener);
333  modePreferences.removePreferenceChangeListener(listener);
334  externalServicePreferences.removePreferenceChangeListener(listener);
335  }
336 
337  public static boolean keepPreferredContentViewer() {
338  return viewPreferences.getBoolean(KEEP_PREFERRED_VIEWER, false);
339  }
340 
341  public static void setKeepPreferredContentViewer(boolean value) {
342  viewPreferences.putBoolean(KEEP_PREFERRED_VIEWER, value);
343  }
344 
345  public static boolean hideKnownFilesInDataSourcesTree() {
346  return viewPreferences.getBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, false);
347  }
348 
349  public static void setHideKnownFilesInDataSourcesTree(boolean value) {
350  viewPreferences.putBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, value);
351  }
352 
353  public static boolean hideKnownFilesInViewsTree() {
354  return viewPreferences.getBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, true);
355  }
356 
357  public static void setHideKnownFilesInViewsTree(boolean value) {
358  viewPreferences.putBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, value);
359  }
360 
361  public static boolean hideSlackFilesInDataSourcesTree() {
362  return viewPreferences.getBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, true);
363  }
364 
365  public static void setHideSlackFilesInDataSourcesTree(boolean value) {
366  viewPreferences.putBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, value);
367  }
368 
369  public static boolean hideSlackFilesInViewsTree() {
370  return viewPreferences.getBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, true);
371  }
372 
373  public static void setHideSlackFilesInViewsTree(boolean value) {
374  viewPreferences.putBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, value);
375  }
376 
377  public static boolean displayTimesInLocalTime() {
378  return viewPreferences.getBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, true);
379  }
380 
381  public static void setDisplayTimesInLocalTime(boolean value) {
382  viewPreferences.putBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, value);
383  }
384 
385  public static String getTimeZoneForDisplays() {
386  return viewPreferences.get(TIME_ZONE_FOR_DISPLAYS, TimeZone.GMT_ZONE.getID());
387  }
388 
389  public static void setTimeZoneForDisplays(String timeZone) {
390  viewPreferences.put(TIME_ZONE_FOR_DISPLAYS, timeZone);
391  }
392 
393  public static int numberOfFileIngestThreads() {
394  return machineSpecificPreferences.getInt(NUMBER_OF_FILE_INGEST_THREADS, 2);
395  }
396 
397  public static void setNumberOfFileIngestThreads(int value) {
398  machineSpecificPreferences.putInt(NUMBER_OF_FILE_INGEST_THREADS, value);
399  }
400 
401  @Deprecated
402  public static boolean groupItemsInTreeByDatasource() {
403  return viewPreferences.getBoolean(GROUP_ITEMS_IN_TREE_BY_DATASOURCE, false);
404  }
405 
406  @Deprecated
407  public static void setGroupItemsInTreeByDatasource(boolean value) {
408  viewPreferences.putBoolean(GROUP_ITEMS_IN_TREE_BY_DATASOURCE, value);
409  }
410 
417  public static boolean showOnlyCurrentUserTags() {
418  return viewPreferences.getBoolean(SHOW_ONLY_CURRENT_USER_TAGS, false);
419  }
420 
427  public static void setShowOnlyCurrentUserTags(boolean value) {
428  viewPreferences.putBoolean(SHOW_ONLY_CURRENT_USER_TAGS, value);
429  }
430 
438  public static boolean getHideSCOColumns() {
439  return viewPreferences.getBoolean(HIDE_SCO_COLUMNS, false);
440  }
441 
449  public static void setHideSCOColumns(boolean value) {
450  viewPreferences.putBoolean(HIDE_SCO_COLUMNS, value);
451  }
452 
453  public static void setDisplayTranslatedFileNames(boolean value) {
454  viewPreferences.putBoolean(DISPLAY_TRANSLATED_NAMES, value);
455  }
456 
457  public static boolean displayTranslatedFileNames() {
458  return viewPreferences.getBoolean(DISPLAY_TRANSLATED_NAMES, DISPLAY_TRANSLATED_NAMES_DEFAULT);
459  }
460 
468  public static CaseDbConnectionInfo getDatabaseConnectionInfo() throws UserPreferencesException {
469  DbType dbType;
470  try {
471  dbType = DbType.valueOf(externalServicePreferences.get(EXTERNAL_DATABASE_TYPE, "POSTGRESQL")); //NON-NLS
472  } catch (Exception ex) {
473  dbType = DbType.SQLITE;
474  }
475  try {
476  return new CaseDbConnectionInfo(
477  externalServicePreferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP, ""),
478  externalServicePreferences.get(EXTERNAL_DATABASE_PORTNUMBER, "5432"),
479  externalServicePreferences.get(EXTERNAL_DATABASE_USER, ""),
480  TextConverter.convertHexTextToText(externalServicePreferences.get(EXTERNAL_DATABASE_PASSWORD, "")),
481  dbType);
482  } catch (TextConverterException ex) {
483  throw new UserPreferencesException("Failure converting password hex text to text.", ex); // NON-NLS
484  }
485  }
486 
495  public static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo) throws UserPreferencesException {
496  externalServicePreferences.put(EXTERNAL_DATABASE_HOSTNAME_OR_IP, connectionInfo.getHost());
497  externalServicePreferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort());
498  externalServicePreferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName());
499  try {
500  externalServicePreferences.put(EXTERNAL_DATABASE_PASSWORD, TextConverter.convertTextToHexText(connectionInfo.getPassword()));
501  } catch (TextConverterException ex) {
502  throw new UserPreferencesException("Failure converting text to password hext text", ex); // NON-NLS
503  }
504  externalServicePreferences.put(EXTERNAL_DATABASE_TYPE, connectionInfo.getDbType().toString());
505  }
506 
507  public static void setIsMultiUserModeEnabled(boolean enabled) {
508  externalServicePreferences.putBoolean(IS_MULTI_USER_MODE_ENABLED, enabled);
509  }
510 
511  public static boolean getIsMultiUserModeEnabled() {
512  return isMultiUserSupported() && externalServicePreferences.getBoolean(IS_MULTI_USER_MODE_ENABLED, false);
513  }
514 
515  private static Boolean multiUserSupported = null;
516 
525  public static boolean isMultiUserSupported() {
526  if (multiUserSupported == null) {
527  // looks for any SolrSearchService present in AutopsyService.
528  multiUserSupported = Lookup.getDefault().lookupAll(AutopsyService.class).stream()
529  .anyMatch(obj -> obj.getClass().getName().equalsIgnoreCase("org.sleuthkit.autopsy.keywordsearch.SolrSearchService"));
530  }
531 
532  return multiUserSupported;
533  }
534 
535  public static String getIndexingServerHost() {
536  return externalServicePreferences.get(SOLR8_SERVER_HOST, "");
537  }
538 
539  public static void setIndexingServerHost(String hostName) {
540  externalServicePreferences.put(SOLR8_SERVER_HOST, hostName);
541  }
542 
543  public static String getIndexingServerPort() {
544  return externalServicePreferences.get(SOLR8_SERVER_PORT, "8983");
545  }
546 
547  public static void setIndexingServerPort(int port) {
548  externalServicePreferences.putInt(SOLR8_SERVER_PORT, port);
549  }
550 
551  public static String getSolr4ServerHost() {
552  return externalServicePreferences.get(SOLR4_SERVER_HOST, "");
553  }
554 
555  public static void setSolr4ServerHost(String hostName) {
556  externalServicePreferences.put(SOLR4_SERVER_HOST, hostName);
557  }
558 
559  public static String getSolr4ServerPort() {
560  return externalServicePreferences.get(SOLR4_SERVER_PORT, "");
561  }
562 
563  public static void setSolr4ServerPort(String port) {
564  externalServicePreferences.put(SOLR4_SERVER_PORT, port);
565  }
566 
567  public static String getZkServerHost() {
568  return externalServicePreferences.get(ZK_SERVER_HOST, "");
569  }
570 
571  public static void setZkServerHost(String hostName) {
572  externalServicePreferences.put(ZK_SERVER_HOST, hostName);
573  }
574 
575  public static String getZkServerPort() {
576  return externalServicePreferences.get(ZK_SERVER_PORT, "9983");
577  }
578 
579  public static void setZkServerPort(String port) {
580  externalServicePreferences.put(ZK_SERVER_PORT, port);
581  }
582 
583  public static void setTextTranslatorName(String textTranslatorName) {
584  externalServicePreferences.put(TEXT_TRANSLATOR_NAME, textTranslatorName);
585  }
586 
587  public static String getTextTranslatorName() {
588  return externalServicePreferences.get(TEXT_TRANSLATOR_NAME, null);
589  }
590 
591  public static void setUseOcrInTranslation(boolean enableOcr) {
592  externalServicePreferences.putBoolean(OCR_TRANSLATION_ENABLED, enableOcr);
593  }
594 
595  public static boolean getUseOcrInTranslation() {
596  return externalServicePreferences.getBoolean(OCR_TRANSLATION_ENABLED, true);
597  }
598 
607  externalServicePreferences.put(MESSAGE_SERVICE_HOST, info.getHost());
608  externalServicePreferences.put(MESSAGE_SERVICE_PORT, Integer.toString(info.getPort()));
609  externalServicePreferences.put(MESSAGE_SERVICE_USER, info.getUserName());
610  try {
611  externalServicePreferences.put(MESSAGE_SERVICE_PASSWORD, TextConverter.convertTextToHexText(info.getPassword()));
612  } catch (TextConverterException ex) {
613  throw new UserPreferencesException("Failed to convert password text to hex text.", ex);
614  }
615  }
616 
625  int port;
626  try {
627  port = Integer.parseInt(externalServicePreferences.get(MESSAGE_SERVICE_PORT, DEFAULT_PORT_STRING));
628  } catch (NumberFormatException ex) {
629  // if there is an error parsing the port number, use the default port number
630  port = DEFAULT_PORT_INT;
631  }
632 
633  try {
634  return new MessageServiceConnectionInfo(
635  externalServicePreferences.get(MESSAGE_SERVICE_HOST, ""),
636  port,
637  externalServicePreferences.get(MESSAGE_SERVICE_USER, ""),
638  TextConverter.convertHexTextToText(externalServicePreferences.get(MESSAGE_SERVICE_PASSWORD, "")));
639  } catch (TextConverterException ex) {
640  throw new UserPreferencesException("Failed to convert password hex text to text.", ex);
641  }
642  }
643 
649  public static int getProcessTimeOutHrs() {
650  int timeOut = machineSpecificPreferences.getInt(PROCESS_TIME_OUT_HOURS, DEFAULT_PROCESS_TIMEOUT_HR);
651  if (timeOut < 0) {
652  timeOut = 0;
653  }
654  return timeOut;
655  }
656 
662  public static void setProcessTimeOutHrs(int value) {
663  if (value < 0) {
664  value = 0;
665  }
666  machineSpecificPreferences.putInt(PROCESS_TIME_OUT_HOURS, value);
667  }
668 
676  public static boolean getIsTimeOutEnabled() {
677  boolean enabled = machineSpecificPreferences.getBoolean(PROCESS_TIME_OUT_ENABLED, false);
678  return enabled;
679  }
680 
688  public static void setIsTimeOutEnabled(boolean enabled) {
689  machineSpecificPreferences.putBoolean(PROCESS_TIME_OUT_ENABLED, enabled);
690  }
691 
697  public static String getAppName() {
698  return modePreferences.get(APP_NAME, Version.getName());
699  }
700 
706  public static void setAppName(String name) {
707  modePreferences.put(APP_NAME, name);
708  }
709 
715  public static int getLogFileCount() {
716  return machineSpecificPreferences.getInt(MAX_NUM_OF_LOG_FILE, LOG_FILE_NUM_INT);
717  }
718 
724  public static int getDefaultLogFileCount() {
725  return LOG_FILE_NUM_INT;
726  }
727 
733  public static void setLogFileCount(int count) {
734  machineSpecificPreferences.putInt(MAX_NUM_OF_LOG_FILE, count);
735  }
736 
744  public static int getMaxSolrVMSize() {
745  if (PlatformUtil.is64BitJVM()) {
746  return machineSpecificPreferences.getInt(SOLR_MAX_JVM_SIZE, DEFAULT_SOLR_HEAP_SIZE_MB_64BIT_PLATFORM);
747  } else {
748  return machineSpecificPreferences.getInt(SOLR_MAX_JVM_SIZE, DEFAULT_SOLR_HEAP_SIZE_MB_32BIT_PLATFORM);
749  }
750  }
751 
757  public static void setMaxSolrVMSize(int maxSize) {
758  machineSpecificPreferences.putInt(SOLR_MAX_JVM_SIZE, maxSize);
759  }
760 
766  public static int getResultsTablePageSize() {
767  return viewPreferences.getInt(RESULTS_TABLE_PAGE_SIZE, 10_000);
768  }
769 
775  public static void setResultsTablePageSize(int pageSize) {
776  viewPreferences.putInt(RESULTS_TABLE_PAGE_SIZE, pageSize);
777  }
778 
784  public static void setExternalHexEditorPath(String executablePath) {
785  viewPreferences.put(EXTERNAL_HEX_EDITOR_PATH, executablePath);
786  }
787 
794  public static String getExternalHexEditorPath() {
795  return viewPreferences.get(EXTERNAL_HEX_EDITOR_PATH, Paths.get("C:", "Program Files", "HxD", "HxD.exe").toString());
796  }
797 
803  public static void setGeolocationTileOption(int option) {
804  externalServicePreferences.putInt(GEO_TILE_OPTION, option);
805  }
806 
813  public static int getGeolocationtTileOption() {
814  return externalServicePreferences.getInt(GEO_TILE_OPTION, 0);
815  }
816 
822  public static void setGeolocationOsmZipPath(String absolutePath) {
823  machineSpecificPreferences.put(GEO_OSM_TILE_ZIP_PATH, absolutePath);
824  }
825 
832  public static String getGeolocationOsmZipPath() {
833  return machineSpecificPreferences.get(GEO_OSM_TILE_ZIP_PATH, "");
834  }
835 
842  public static void setGeolocationOsmServerAddress(String address) {
843  externalServicePreferences.put(GEO_OSM_SERVER_ADDRESS, address);
844  }
845 
851  public static String getGeolocationOsmServerAddress() {
852  return externalServicePreferences.get(GEO_OSM_SERVER_ADDRESS, "");
853  }
854 
860  public static void setGeolocationMBTilesFilePath(String absolutePath) {
861  machineSpecificPreferences.put(GEO_MBTILES_FILE_PATH, absolutePath);
862  }
863 
869  public static String getGeolocationMBTilesFilePath() {
870  return machineSpecificPreferences.get(GEO_MBTILES_FILE_PATH, "");
871  }
872 
876  private static File getSystemTempDirFile() {
877  return Paths.get(System.getProperty("java.io.tmpdir"), getAppName(), TEMP_FOLDER).toFile();
878  }
879 
886  public static String getAppTempDirectory() {
887  // NOTE: If this code changes, Case.getTempDirectory() should likely be checked
888  // as well. See JIRA 7505 for more information.
889  File appTempDir = null;
891  case CUSTOM:
892  String customDirectory = UserMachinePreferences.getCustomTempDirectory();
893  appTempDir = (StringUtils.isBlank(customDirectory))
894  ? null
895  : Paths.get(customDirectory, getAppName(), TEMP_FOLDER).toFile();
896  break;
897  case SYSTEM:
898  default:
899  // at this level, if the case directory is specified for a temp
900  // directory, return the system temp directory instead.
901  appTempDir = getSystemTempDirFile();
902  break;
903  }
904 
905  appTempDir = appTempDir == null ? getSystemTempDirFile() : appTempDir;
906 
907  if (!appTempDir.exists()) {
908  appTempDir.mkdirs();
909  }
910 
911  return appTempDir.getAbsolutePath();
912  }
913 
919  public static void setHealthMonitorReportPath(String reportPath) {
920  machineSpecificPreferences.put(HEALTH_MONITOR_REPORT_PATH, reportPath);
921  }
922 
929  public static String getHealthMonitorReportPath() {
930  return machineSpecificPreferences.get(HEALTH_MONITOR_REPORT_PATH, "");
931  }
932 }
static void setZkServerHost(String hostName)
static synchronized String getConfigSetting(String moduleName, String settingName)
static void setGroupItemsInTreeByDatasource(boolean value)
static final ConfigProperties externalServicePreferences
static final ConfigProperties viewPreferences
static void setKeepPreferredContentViewer(boolean value)
static final List< String > EXTERNAL_SERVICE_KEYS
static void setDisplayTimesInLocalTime(boolean value)
static void setMode(SelectedMode mode)
static final ConfigProperties modePreferences
static void setUseOcrInTranslation(boolean enableOcr)
static void setHideSlackFilesInViewsTree(boolean value)
static void setHealthMonitorReportPath(String reportPath)
static final ConfigProperties machineSpecificPreferences
static CaseDbConnectionInfo getDatabaseConnectionInfo()
static void setHideSCOColumns(boolean value)
static void setIsTimeOutEnabled(boolean enabled)
static final List< String > MODE_PREFERENCE_KEYS
static void setResultsTablePageSize(int pageSize)
static void setIsMultiUserModeEnabled(boolean enabled)
static void removeChangeListener(PreferenceChangeListener listener)
static final List< String > VIEW_PREFERENCE_KEYS
static void setMessageServiceConnectionInfo(MessageServiceConnectionInfo info)
static synchronized boolean settingExists(String moduleName, String settingName)
static void setHideKnownFilesInViewsTree(boolean value)
static void setTextTranslatorName(String textTranslatorName)
static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo)
static void setTimeZoneForDisplays(String timeZone)
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
static void setIndexingServerHost(String hostName)
static void setDisplayTranslatedFileNames(boolean value)
static void setHideSlackFilesInDataSourcesTree(boolean value)
static void setHideKnownFilesInDataSourcesTree(boolean value)
static void setGeolocationOsmZipPath(String absolutePath)
static String getSharedPreferencePath(String identifier)
static void setExternalHexEditorPath(String executablePath)
static void addChangeListener(PreferenceChangeListener listener)
static final List< String > MACHINE_PREFERENCE_KEYS
static void setGeolocationMBTilesFilePath(String absolutePath)
static void setSolr4ServerHost(String hostName)
static void setShowOnlyCurrentUserTags(boolean value)
static String convertTextToHexText(String property)
static void setGeolocationOsmServerAddress(String address)
static String getConfigPreferencePath(String identifier)
static MessageServiceConnectionInfo getMessageServiceConnectionInfo()
static String convertHexTextToText(String property)

Copyright © 2012-2022 Basis Technology. Generated on: Wed Sep 28 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.