Autopsy  4.21.0
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.time.ZoneId;
26 import java.util.Arrays;
27 import java.util.List;
28 import java.util.Properties;
30 import java.util.prefs.BackingStoreException;
32 import java.util.prefs.PreferenceChangeListener;
33 import org.apache.commons.lang3.StringUtils;
34 import org.apache.commons.lang3.tuple.Triple;
35 import org.openide.util.Lookup;
36 import org.python.icu.util.TimeZone;
43 import org.sleuthkit.datamodel.CaseDbConnectionInfo;
44 import org.sleuthkit.datamodel.TskData.DbType;
45 
50 public final class UserPreferences {
51 
60  private static String getConfigPreferencePath(String identifier) {
61  return Paths.get(PlatformUtil.getUserConfigDirectory(), identifier + ".properties").toString();
62  }
63 
72  private static String getSharedPreferencePath(String identifier) {
73  return Paths.get(PlatformUtil.getModuleConfigDirectory(), identifier + ".properties").toString();
74  }
75 
76  private static final String VIEW_PREFERENCE_PATH = getSharedPreferencePath("ViewPreferences");
77  private static final String MACHINE_SPECIFIC_PREFERENCE_PATH = getConfigPreferencePath("MachineSpecificPreferences");
78  private static final String MODE_PREFERENCE_PATH = getConfigPreferencePath("ModePreferences");
79  private static final String EXTERNAL_SERVICE_PREFERENCE_PATH = getSharedPreferencePath("ExternalServicePreferences");
80 
81  private static final ConfigProperties viewPreferences = new ConfigProperties(VIEW_PREFERENCE_PATH);
82  private static final ConfigProperties machineSpecificPreferences = new ConfigProperties(MACHINE_SPECIFIC_PREFERENCE_PATH);
83  private static final ConfigProperties modePreferences = new ConfigProperties(MODE_PREFERENCE_PATH);
84  private static final ConfigProperties externalServicePreferences = new ConfigProperties(EXTERNAL_SERVICE_PREFERENCE_PATH);
85 
86  static {
87  // perform initial load to ensure disk preferences are loaded
88  try {
89  // make shared directory paths if they don't exist.
90  new File(PlatformUtil.getModuleConfigDirectory()).mkdirs();
91  viewPreferences.load();
92  machineSpecificPreferences.load();
93  modePreferences.load();
94  externalServicePreferences.load();
95  } catch (IOException ex) {
96  // can't log because logger requires UserPreferences.
97  // This shouldn't really be thrown unless their is a file access
98  // issue within the user config directory.
99  ex.printStackTrace();
100  }
101  }
102 
103  // view preferences
104  public static final String KEEP_PREFERRED_VIEWER = "KeepPreferredViewer"; // NON-NLS
105  public static final String HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE = "HideKnownFilesInDataSourcesTree"; //NON-NLS
106  public static final String HIDE_KNOWN_FILES_IN_VIEWS_TREE = "HideKnownFilesInViewsTree"; //NON-NLS
107  public static final String HIDE_SLACK_FILES_IN_DATA_SRCS_TREE = "HideSlackFilesInDataSourcesTree"; //NON-NLS
108  public static final String HIDE_SLACK_FILES_IN_VIEWS_TREE = "HideSlackFilesInViewsTree"; //NON-NLS
109  public static final String DISPLAY_TIMES_IN_LOCAL_TIME = "DisplayTimesInLocalTime"; //NON-NLS
110  public static final String TIME_ZONE_FOR_DISPLAYS = "TimeZoneForDisplays"; //NON-NLS
111  public static final String GROUP_ITEMS_IN_TREE_BY_DATASOURCE = "GroupItemsInTreeByDataSource"; //NON-NLS
112  public static final String SHOW_ONLY_CURRENT_USER_TAGS = "ShowOnlyCurrentUserTags";
113  public static final String HIDE_SCO_COLUMNS = "HideCentralRepoCommentsAndOccurrences"; //The key for this setting pre-dates the settings current functionality //NON-NLS
114  public static final String DISPLAY_TRANSLATED_NAMES = "DisplayTranslatedNames";
115  private static final boolean DISPLAY_TRANSLATED_NAMES_DEFAULT = true;
116  public static final String EXTERNAL_HEX_EDITOR_PATH = "ExternalHexEditorPath";
117  public static final String RESULTS_TABLE_PAGE_SIZE = "ResultsTablePageSize";
118 
119  // machine-specific settings
120  public static final String NUMBER_OF_FILE_INGEST_THREADS = "NumberOfFileIngestThreads"; //NON-NLS
121  public static final String PROCESS_TIME_OUT_ENABLED = "ProcessTimeOutEnabled"; //NON-NLS
122  public static final String PROCESS_TIME_OUT_HOURS = "ProcessTimeOutHours"; //NON-NLS
123  private static final int DEFAULT_PROCESS_TIMEOUT_HR = 60;
124  private static final String MAX_NUM_OF_LOG_FILE = "MaximumNumberOfLogFiles";
125  private static final int LOG_FILE_NUM_INT = 10;
126  public static final String SOLR_MAX_JVM_SIZE = "SolrMaxJVMSize";
127  private static final int DEFAULT_SOLR_HEAP_SIZE_MB_64BIT_PLATFORM = 2048;
128  private static final int DEFAULT_SOLR_HEAP_SIZE_MB_32BIT_PLATFORM = 512;
129  private static final String HEALTH_MONITOR_REPORT_PATH = "HealthMonitorReportPath";
130  private static final String TEMP_FOLDER = "Temp";
131  private static final String GEO_OSM_TILE_ZIP_PATH = "GeolocationOsmZipPath";
132  private static final String GEO_MBTILES_FILE_PATH = "GeolcoationMBTilesFilePath";
133 
134  // mode and enabled
135  public static final String SETTINGS_PROPERTIES = "AutoIngest";
136  private static final String MODE = "AutopsyMode"; // NON-NLS
137  private static final String APP_NAME = "AppName";
138 
139  // external services preferences
140  public static final String IS_MULTI_USER_MODE_ENABLED = "IsMultiUserModeEnabled"; //NON-NLS
141  private static final String GEO_TILE_OPTION = "GeolocationTileOption";
142  public static final String OCR_TRANSLATION_ENABLED = "OcrTranslationEnabled";
143  public static final String EXTERNAL_DATABASE_HOSTNAME_OR_IP = "ExternalDatabaseHostnameOrIp"; //NON-NLS
144  public static final String EXTERNAL_DATABASE_PORTNUMBER = "ExternalDatabasePortNumber"; //NON-NLS
145  public static final String EXTERNAL_DATABASE_NAME = "ExternalDatabaseName"; //NON-NLS
146  public static final String EXTERNAL_DATABASE_USER = "ExternalDatabaseUsername"; //NON-NLS
147  public static final String EXTERNAL_DATABASE_PASSWORD = "ExternalDatabasePassword"; //NON-NLS
148  public static final String EXTERNAL_DATABASE_TYPE = "ExternalDatabaseType"; //NON-NLS
149  private static final String SOLR8_SERVER_HOST = "Solr8ServerHost"; //NON-NLS
150  private static final String SOLR8_SERVER_PORT = "Solr8ServerPort"; //NON-NLS
151  private static final String SOLR4_SERVER_HOST = "IndexingServerHost"; //NON-NLS
152  private static final String SOLR4_SERVER_PORT = "IndexingServerPort"; //NON-NLS
153  private static final String ZK_SERVER_HOST = "ZookeeperServerHost"; //NON-NLS
154  private static final String ZK_SERVER_PORT = "ZookeeperServerPort"; //NON-NLS
155  private static final String MESSAGE_SERVICE_PASSWORD = "MessageServicePassword"; //NON-NLS
156  private static final String MESSAGE_SERVICE_USER = "MessageServiceUser"; //NON-NLS
157  private static final String MESSAGE_SERVICE_HOST = "MessageServiceHost"; //NON-NLS
158  private static final String MESSAGE_SERVICE_PORT = "MessageServicePort"; //NON-NLS
159  public static final String TEXT_TRANSLATOR_NAME = "TextTranslatorName";
160  private static final String DEFAULT_PORT_STRING = "61616";
161  private static final int DEFAULT_PORT_INT = 61616;
162  private static final String GEO_OSM_SERVER_ADDRESS = "GeolocationOsmServerAddress";
163 
164  // view preference keys used for moving from legacy files to new files
165  private static final List<String> VIEW_PREFERENCE_KEYS = Arrays.asList(
166  KEEP_PREFERRED_VIEWER,
167  HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE,
168  HIDE_KNOWN_FILES_IN_VIEWS_TREE,
169  HIDE_SLACK_FILES_IN_DATA_SRCS_TREE,
170  HIDE_SLACK_FILES_IN_VIEWS_TREE,
171  DISPLAY_TIMES_IN_LOCAL_TIME,
172  TIME_ZONE_FOR_DISPLAYS,
173  GROUP_ITEMS_IN_TREE_BY_DATASOURCE,
174  SHOW_ONLY_CURRENT_USER_TAGS,
175  HIDE_SCO_COLUMNS,
176  DISPLAY_TRANSLATED_NAMES,
177  EXTERNAL_HEX_EDITOR_PATH,
178  RESULTS_TABLE_PAGE_SIZE
179  );
180 
181  // machine preference keys used for moving from legacy files to new files
182  private static final List<String> MACHINE_PREFERENCE_KEYS = Arrays.asList(
183  NUMBER_OF_FILE_INGEST_THREADS,
184  PROCESS_TIME_OUT_ENABLED,
185  PROCESS_TIME_OUT_HOURS,
186  MAX_NUM_OF_LOG_FILE,
187  SOLR_MAX_JVM_SIZE,
188  HEALTH_MONITOR_REPORT_PATH,
189  TEMP_FOLDER,
190  GEO_OSM_TILE_ZIP_PATH,
191  GEO_MBTILES_FILE_PATH
192  );
193 
194  // mode preference keys used for moving from legacy files to new files
195  private static final List<String> MODE_PREFERENCE_KEYS = Arrays.asList(
196  SETTINGS_PROPERTIES,
197  MODE,
198  APP_NAME
199  );
200 
201  // external service preference keys used for moving from legacy files to new files
202  private static final List<String> EXTERNAL_SERVICE_KEYS = Arrays.asList(
203  IS_MULTI_USER_MODE_ENABLED,
204  GEO_TILE_OPTION,
205  OCR_TRANSLATION_ENABLED,
206  EXTERNAL_DATABASE_HOSTNAME_OR_IP,
207  EXTERNAL_DATABASE_PORTNUMBER,
208  EXTERNAL_DATABASE_NAME,
209  EXTERNAL_DATABASE_USER,
210  EXTERNAL_DATABASE_PASSWORD,
211  EXTERNAL_DATABASE_TYPE,
212  SOLR8_SERVER_HOST,
213  SOLR8_SERVER_PORT,
214  SOLR4_SERVER_HOST,
215  SOLR4_SERVER_PORT,
216  ZK_SERVER_HOST,
217  ZK_SERVER_PORT,
218  MESSAGE_SERVICE_PASSWORD,
219  MESSAGE_SERVICE_USER,
220  MESSAGE_SERVICE_HOST,
221  MESSAGE_SERVICE_PORT,
222  TEXT_TRANSLATOR_NAME,
223  GEO_OSM_SERVER_ADDRESS
224  );
225 
226  private static final String LEGACY_CONFIG_PATH = Paths.get(PlatformUtil.getUserConfigDirectory(), "Preferences", "org", "sleuthkit", "autopsy", "core.properties").toString();
227 
228  static void updateConfig() {
229  List<Triple<File, ConfigProperties, List<String>>> fileAndKeys = Arrays.asList(
230  Triple.of(new File(MODE_PREFERENCE_PATH), modePreferences, MODE_PREFERENCE_KEYS),
231  Triple.of(new File(MACHINE_SPECIFIC_PREFERENCE_PATH), machineSpecificPreferences, MACHINE_PREFERENCE_KEYS),
232  Triple.of(new File(VIEW_PREFERENCE_PATH), viewPreferences, VIEW_PREFERENCE_KEYS),
233  Triple.of(new File(EXTERNAL_SERVICE_PREFERENCE_PATH), externalServicePreferences, EXTERNAL_SERVICE_KEYS)
234  );
235 
236  boolean newSettingsExist = fileAndKeys.stream().anyMatch(triple -> triple.getLeft().exists());
237 
238  File oldSettingsFile = new File(LEGACY_CONFIG_PATH);
239  // copy old settings to new location.
240  if (oldSettingsFile.exists() && !newSettingsExist) {
241  try {
242  Properties allProperties = new Properties();
243  try (FileInputStream oldPropsStream = new FileInputStream(oldSettingsFile)) {
244  allProperties.load(oldPropsStream);
245  }
246 
247  for (Triple<File, ConfigProperties, List<String>> fileKeys : fileAndKeys) {
248  ConfigProperties newProperties = fileKeys.getMiddle();
249  for (String key : fileKeys.getRight()) {
250  String val = allProperties.getProperty(key);
251  if (val != null) {
252  newProperties.put(key, val);
253  }
254  }
255 
256  }
257  } catch (IOException ex) {
258  // can't log because logger requires UserPreferences.
259  // This shouldn't really be thrown unless their is a file access
260  // issue within the user config directory.
261  ex.printStackTrace();
262  }
263  }
264  }
265 
266  // Prevent instantiation.
267  private UserPreferences() {
268  }
269 
270  public enum SelectedMode {
272  AUTOINGEST
273  };
274 
280  public static SelectedMode getMode() {
281  if (ModuleSettings.settingExists(SETTINGS_PROPERTIES, MODE)) {
282  int ordinal = Integer.parseInt(ModuleSettings.getConfigSetting(SETTINGS_PROPERTIES, MODE));
283  return UserPreferences.SelectedMode.values()[ordinal];
284  }
286  }
287 
293  public static void setMode(SelectedMode mode) {
294  ModuleSettings.setConfigSetting(SETTINGS_PROPERTIES, MODE, Integer.toString(mode.ordinal()));
295  }
296 
303  public static void reloadFromStorage() throws BackingStoreException {
304  viewPreferences.sync();
305  machineSpecificPreferences.sync();
306  modePreferences.sync();
307  externalServicePreferences.sync();
308  }
309 
317  public static void saveToStorage() throws BackingStoreException {
318  viewPreferences.flush();
319  machineSpecificPreferences.flush();
320  modePreferences.flush();
321  externalServicePreferences.flush();
322  }
323 
324  public static void addChangeListener(PreferenceChangeListener listener) {
325  viewPreferences.addPreferenceChangeListener(listener);
326  machineSpecificPreferences.addPreferenceChangeListener(listener);
327  modePreferences.addPreferenceChangeListener(listener);
328  externalServicePreferences.addPreferenceChangeListener(listener);
329  }
330 
331  public static void removeChangeListener(PreferenceChangeListener listener) {
332  viewPreferences.removePreferenceChangeListener(listener);
333  machineSpecificPreferences.removePreferenceChangeListener(listener);
334  modePreferences.removePreferenceChangeListener(listener);
335  externalServicePreferences.removePreferenceChangeListener(listener);
336  }
337 
338  public static boolean keepPreferredContentViewer() {
339  return viewPreferences.getBoolean(KEEP_PREFERRED_VIEWER, false);
340  }
341 
342  public static void setKeepPreferredContentViewer(boolean value) {
343  viewPreferences.putBoolean(KEEP_PREFERRED_VIEWER, value);
344  }
345 
346  public static boolean hideKnownFilesInDataSourcesTree() {
347  return viewPreferences.getBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, false);
348  }
349 
350  public static void setHideKnownFilesInDataSourcesTree(boolean value) {
351  viewPreferences.putBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, value);
352  }
353 
354  public static boolean hideKnownFilesInViewsTree() {
355  return viewPreferences.getBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, true);
356  }
357 
358  public static void setHideKnownFilesInViewsTree(boolean value) {
359  viewPreferences.putBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, value);
360  }
361 
362  public static boolean hideSlackFilesInDataSourcesTree() {
363  return viewPreferences.getBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, true);
364  }
365 
366  public static void setHideSlackFilesInDataSourcesTree(boolean value) {
367  viewPreferences.putBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, value);
368  }
369 
370  public static boolean hideSlackFilesInViewsTree() {
371  return viewPreferences.getBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, true);
372  }
373 
374  public static void setHideSlackFilesInViewsTree(boolean value) {
375  viewPreferences.putBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, value);
376  }
377 
378  public static boolean displayTimesInLocalTime() {
379  return viewPreferences.getBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, true);
380  }
381 
382  public static void setDisplayTimesInLocalTime(boolean value) {
383  viewPreferences.putBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, value);
384  }
385 
386  public static String getTimeZoneForDisplays() {
387  return viewPreferences.get(TIME_ZONE_FOR_DISPLAYS, TimeZone.GMT_ZONE.getID());
388  }
389 
398  public static String getInferredUserTimeZone() {
399  String timeZonePref = viewPreferences.get(TIME_ZONE_FOR_DISPLAYS, null);
400  if (StringUtils.isBlank(timeZonePref)) {
401  ZoneId systemZoneId = ZoneId.systemDefault();
402  if (systemZoneId != null) {
403  timeZonePref = systemZoneId.getId();
404  }
405  }
406 
407  if (StringUtils.isBlank(timeZonePref)) {
408  timeZonePref = TimeZone.GMT_ZONE.getID();
409  }
410 
411  return timeZonePref;
412  }
413 
414  public static void setTimeZoneForDisplays(String timeZone) {
415  viewPreferences.put(TIME_ZONE_FOR_DISPLAYS, timeZone);
416  }
417 
418  public static int numberOfFileIngestThreads() {
419  return machineSpecificPreferences.getInt(NUMBER_OF_FILE_INGEST_THREADS, 2);
420  }
421 
422  public static void setNumberOfFileIngestThreads(int value) {
423  machineSpecificPreferences.putInt(NUMBER_OF_FILE_INGEST_THREADS, value);
424  }
425 
426  @Deprecated
427  public static boolean groupItemsInTreeByDatasource() {
428  return viewPreferences.getBoolean(GROUP_ITEMS_IN_TREE_BY_DATASOURCE, false);
429  }
430 
431  @Deprecated
432  public static void setGroupItemsInTreeByDatasource(boolean value) {
433  viewPreferences.putBoolean(GROUP_ITEMS_IN_TREE_BY_DATASOURCE, value);
434  }
435 
442  public static boolean showOnlyCurrentUserTags() {
443  return viewPreferences.getBoolean(SHOW_ONLY_CURRENT_USER_TAGS, false);
444  }
445 
452  public static void setShowOnlyCurrentUserTags(boolean value) {
453  viewPreferences.putBoolean(SHOW_ONLY_CURRENT_USER_TAGS, value);
454  }
455 
463  public static boolean getHideSCOColumns() {
464  return viewPreferences.getBoolean(HIDE_SCO_COLUMNS, false);
465  }
466 
474  public static void setHideSCOColumns(boolean value) {
475  viewPreferences.putBoolean(HIDE_SCO_COLUMNS, value);
476  }
477 
478  public static void setDisplayTranslatedFileNames(boolean value) {
479  viewPreferences.putBoolean(DISPLAY_TRANSLATED_NAMES, value);
480  }
481 
482  public static boolean displayTranslatedFileNames() {
483  return viewPreferences.getBoolean(DISPLAY_TRANSLATED_NAMES, DISPLAY_TRANSLATED_NAMES_DEFAULT);
484  }
485 
493  public static CaseDbConnectionInfo getDatabaseConnectionInfo() throws UserPreferencesException {
494  DbType dbType;
495  try {
496  dbType = DbType.valueOf(externalServicePreferences.get(EXTERNAL_DATABASE_TYPE, "POSTGRESQL")); //NON-NLS
497  } catch (Exception ex) {
498  dbType = DbType.SQLITE;
499  }
500  try {
501  return new CaseDbConnectionInfo(
502  externalServicePreferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP, ""),
503  externalServicePreferences.get(EXTERNAL_DATABASE_PORTNUMBER, "5432"),
504  externalServicePreferences.get(EXTERNAL_DATABASE_USER, ""),
505  TextConverter.convertHexTextToText(externalServicePreferences.get(EXTERNAL_DATABASE_PASSWORD, "")),
506  dbType);
507  } catch (TextConverterException ex) {
508  throw new UserPreferencesException("Failure converting password hex text to text.", ex); // NON-NLS
509  }
510  }
511 
520  public static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo) throws UserPreferencesException {
521  externalServicePreferences.put(EXTERNAL_DATABASE_HOSTNAME_OR_IP, connectionInfo.getHost());
522  externalServicePreferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort());
523  externalServicePreferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName());
524  try {
525  externalServicePreferences.put(EXTERNAL_DATABASE_PASSWORD, TextConverter.convertTextToHexText(connectionInfo.getPassword()));
526  } catch (TextConverterException ex) {
527  throw new UserPreferencesException("Failure converting text to password hext text", ex); // NON-NLS
528  }
529  externalServicePreferences.put(EXTERNAL_DATABASE_TYPE, connectionInfo.getDbType().toString());
530  }
531 
532  public static void setIsMultiUserModeEnabled(boolean enabled) {
533  externalServicePreferences.putBoolean(IS_MULTI_USER_MODE_ENABLED, enabled);
534  }
535 
536  public static boolean getIsMultiUserModeEnabled() {
537  return isMultiUserSupported() && externalServicePreferences.getBoolean(IS_MULTI_USER_MODE_ENABLED, false);
538  }
539 
540  private static Boolean multiUserSupported = null;
541 
550  public static boolean isMultiUserSupported() {
551  if (multiUserSupported == null) {
552  // looks for any SolrSearchService present in AutopsyService.
553  multiUserSupported = Lookup.getDefault().lookupAll(AutopsyService.class).stream()
554  .anyMatch(obj -> obj.getClass().getName().equalsIgnoreCase("org.sleuthkit.autopsy.keywordsearch.SolrSearchService"));
555  }
556 
557  return multiUserSupported;
558  }
559 
560  public static String getIndexingServerHost() {
561  return externalServicePreferences.get(SOLR8_SERVER_HOST, "");
562  }
563 
564  public static void setIndexingServerHost(String hostName) {
565  externalServicePreferences.put(SOLR8_SERVER_HOST, hostName);
566  }
567 
568  public static String getIndexingServerPort() {
569  return externalServicePreferences.get(SOLR8_SERVER_PORT, "8983");
570  }
571 
572  public static void setIndexingServerPort(int port) {
573  externalServicePreferences.putInt(SOLR8_SERVER_PORT, port);
574  }
575 
576  public static String getSolr4ServerHost() {
577  return externalServicePreferences.get(SOLR4_SERVER_HOST, "");
578  }
579 
580  public static void setSolr4ServerHost(String hostName) {
581  externalServicePreferences.put(SOLR4_SERVER_HOST, hostName);
582  }
583 
584  public static String getSolr4ServerPort() {
585  return externalServicePreferences.get(SOLR4_SERVER_PORT, "");
586  }
587 
588  public static void setSolr4ServerPort(String port) {
589  externalServicePreferences.put(SOLR4_SERVER_PORT, port);
590  }
591 
592  public static String getZkServerHost() {
593  return externalServicePreferences.get(ZK_SERVER_HOST, "");
594  }
595 
596  public static void setZkServerHost(String hostName) {
597  externalServicePreferences.put(ZK_SERVER_HOST, hostName);
598  }
599 
600  public static String getZkServerPort() {
601  return externalServicePreferences.get(ZK_SERVER_PORT, "9983");
602  }
603 
604  public static void setZkServerPort(String port) {
605  externalServicePreferences.put(ZK_SERVER_PORT, port);
606  }
607 
608  public static void setTextTranslatorName(String textTranslatorName) {
609  externalServicePreferences.put(TEXT_TRANSLATOR_NAME, textTranslatorName);
610  }
611 
612  public static String getTextTranslatorName() {
613  return externalServicePreferences.get(TEXT_TRANSLATOR_NAME, null);
614  }
615 
616  public static void setUseOcrInTranslation(boolean enableOcr) {
617  externalServicePreferences.putBoolean(OCR_TRANSLATION_ENABLED, enableOcr);
618  }
619 
620  public static boolean getUseOcrInTranslation() {
621  return externalServicePreferences.getBoolean(OCR_TRANSLATION_ENABLED, true);
622  }
623 
632  externalServicePreferences.put(MESSAGE_SERVICE_HOST, info.getHost());
633  externalServicePreferences.put(MESSAGE_SERVICE_PORT, Integer.toString(info.getPort()));
634  externalServicePreferences.put(MESSAGE_SERVICE_USER, info.getUserName());
635  try {
636  externalServicePreferences.put(MESSAGE_SERVICE_PASSWORD, TextConverter.convertTextToHexText(info.getPassword()));
637  } catch (TextConverterException ex) {
638  throw new UserPreferencesException("Failed to convert password text to hex text.", ex);
639  }
640  }
641 
650  int port;
651  try {
652  port = Integer.parseInt(externalServicePreferences.get(MESSAGE_SERVICE_PORT, DEFAULT_PORT_STRING));
653  } catch (NumberFormatException ex) {
654  // if there is an error parsing the port number, use the default port number
655  port = DEFAULT_PORT_INT;
656  }
657 
658  try {
659  return new MessageServiceConnectionInfo(
660  externalServicePreferences.get(MESSAGE_SERVICE_HOST, ""),
661  port,
662  externalServicePreferences.get(MESSAGE_SERVICE_USER, ""),
663  TextConverter.convertHexTextToText(externalServicePreferences.get(MESSAGE_SERVICE_PASSWORD, "")));
664  } catch (TextConverterException ex) {
665  throw new UserPreferencesException("Failed to convert password hex text to text.", ex);
666  }
667  }
668 
674  public static int getProcessTimeOutHrs() {
675  int timeOut = machineSpecificPreferences.getInt(PROCESS_TIME_OUT_HOURS, DEFAULT_PROCESS_TIMEOUT_HR);
676  if (timeOut < 0) {
677  timeOut = 0;
678  }
679  return timeOut;
680  }
681 
687  public static void setProcessTimeOutHrs(int value) {
688  if (value < 0) {
689  value = 0;
690  }
691  machineSpecificPreferences.putInt(PROCESS_TIME_OUT_HOURS, value);
692  }
693 
701  public static boolean getIsTimeOutEnabled() {
702  boolean enabled = machineSpecificPreferences.getBoolean(PROCESS_TIME_OUT_ENABLED, false);
703  return enabled;
704  }
705 
713  public static void setIsTimeOutEnabled(boolean enabled) {
714  machineSpecificPreferences.putBoolean(PROCESS_TIME_OUT_ENABLED, enabled);
715  }
716 
722  public static String getAppName() {
723  return modePreferences.get(APP_NAME, Version.getName());
724  }
725 
731  public static void setAppName(String name) {
732  modePreferences.put(APP_NAME, name);
733  }
734 
740  public static int getLogFileCount() {
741  return machineSpecificPreferences.getInt(MAX_NUM_OF_LOG_FILE, LOG_FILE_NUM_INT);
742  }
743 
749  public static int getDefaultLogFileCount() {
750  return LOG_FILE_NUM_INT;
751  }
752 
758  public static void setLogFileCount(int count) {
759  machineSpecificPreferences.putInt(MAX_NUM_OF_LOG_FILE, count);
760  }
761 
769  public static int getMaxSolrVMSize() {
770  if (PlatformUtil.is64BitJVM()) {
771  return machineSpecificPreferences.getInt(SOLR_MAX_JVM_SIZE, DEFAULT_SOLR_HEAP_SIZE_MB_64BIT_PLATFORM);
772  } else {
773  return machineSpecificPreferences.getInt(SOLR_MAX_JVM_SIZE, DEFAULT_SOLR_HEAP_SIZE_MB_32BIT_PLATFORM);
774  }
775  }
776 
782  public static void setMaxSolrVMSize(int maxSize) {
783  machineSpecificPreferences.putInt(SOLR_MAX_JVM_SIZE, maxSize);
784  }
785 
791  public static int getResultsTablePageSize() {
792  return viewPreferences.getInt(RESULTS_TABLE_PAGE_SIZE, 10_000);
793  }
794 
800  public static void setResultsTablePageSize(int pageSize) {
801  viewPreferences.putInt(RESULTS_TABLE_PAGE_SIZE, pageSize);
802  }
803 
809  public static void setExternalHexEditorPath(String executablePath) {
810  viewPreferences.put(EXTERNAL_HEX_EDITOR_PATH, executablePath);
811  }
812 
819  public static String getExternalHexEditorPath() {
820  return viewPreferences.get(EXTERNAL_HEX_EDITOR_PATH, Paths.get("C:", "Program Files", "HxD", "HxD.exe").toString());
821  }
822 
828  public static void setGeolocationTileOption(int option) {
829  externalServicePreferences.putInt(GEO_TILE_OPTION, option);
830  }
831 
838  public static int getGeolocationtTileOption() {
839  return externalServicePreferences.getInt(GEO_TILE_OPTION, 0);
840  }
841 
847  public static void setGeolocationOsmZipPath(String absolutePath) {
848  machineSpecificPreferences.put(GEO_OSM_TILE_ZIP_PATH, absolutePath);
849  }
850 
857  public static String getGeolocationOsmZipPath() {
858  return machineSpecificPreferences.get(GEO_OSM_TILE_ZIP_PATH, "");
859  }
860 
867  public static void setGeolocationOsmServerAddress(String address) {
868  externalServicePreferences.put(GEO_OSM_SERVER_ADDRESS, address);
869  }
870 
876  public static String getGeolocationOsmServerAddress() {
877  return externalServicePreferences.get(GEO_OSM_SERVER_ADDRESS, "");
878  }
879 
885  public static void setGeolocationMBTilesFilePath(String absolutePath) {
886  machineSpecificPreferences.put(GEO_MBTILES_FILE_PATH, absolutePath);
887  }
888 
894  public static String getGeolocationMBTilesFilePath() {
895  return machineSpecificPreferences.get(GEO_MBTILES_FILE_PATH, "");
896  }
897 
901  private static File getSystemTempDirFile() {
902  return Paths.get(System.getProperty("java.io.tmpdir"), getAppName(), TEMP_FOLDER).toFile();
903  }
904 
911  public static String getAppTempDirectory() {
912  // NOTE: If this code changes, Case.getTempDirectory() should likely be checked
913  // as well. See JIRA 7505 for more information.
914  File appTempDir = null;
916  case CUSTOM:
917  String customDirectory = UserMachinePreferences.getCustomTempDirectory();
918  appTempDir = (StringUtils.isBlank(customDirectory))
919  ? null
920  : Paths.get(customDirectory, getAppName(), TEMP_FOLDER).toFile();
921  break;
922  case SYSTEM:
923  default:
924  // at this level, if the case directory is specified for a temp
925  // directory, return the system temp directory instead.
926  appTempDir = getSystemTempDirFile();
927  break;
928  }
929 
930  appTempDir = appTempDir == null ? getSystemTempDirFile() : appTempDir;
931 
932  if (!appTempDir.exists()) {
933  appTempDir.mkdirs();
934  }
935 
936  return appTempDir.getAbsolutePath();
937  }
938 
944  public static void setHealthMonitorReportPath(String reportPath) {
945  machineSpecificPreferences.put(HEALTH_MONITOR_REPORT_PATH, reportPath);
946  }
947 
954  public static String getHealthMonitorReportPath() {
955  return machineSpecificPreferences.get(HEALTH_MONITOR_REPORT_PATH, "");
956  }
957 }
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: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.