Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
BingTranslatorSettings.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 2019 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.texttranslation.translators;
20 
21 import org.apache.commons.lang3.StringUtils;
23 
27 public final class BingTranslatorSettings {
28 
29  private static final String AUTHENTICATION_KEY = "Credentials";
30  private static final String BING_TRANSLATE_NAME = "BingTranslate";
31  private static final String DEFAULT_AUTHENTICATION = "";
32  private static final String DEFAULT_TARGET_LANGUAGE = "en";
33  private static final String TARGET_LANGUAGE_CODE_KEY = "TargetLanguageCode";
34  private String authenticationKey;
35  private String targetLanguageCode;
36 
41  loadSettings();
42  }
43 
50  String getAuthenticationKey() {
51  return authenticationKey;
52  }
53 
60  void setAuthenticationKey(String authKey) {
61  authenticationKey = authKey;
62  }
63 
67  void loadSettings() {
68  if (!ModuleSettings.configExists(BING_TRANSLATE_NAME)) {
69  ModuleSettings.makeConfigFile(BING_TRANSLATE_NAME);
70  }
71  if (ModuleSettings.settingExists(BING_TRANSLATE_NAME, AUTHENTICATION_KEY)) {
72  authenticationKey = ModuleSettings.getConfigSetting(BING_TRANSLATE_NAME, AUTHENTICATION_KEY);
73  }
74  if (authenticationKey == null || StringUtils.isBlank(authenticationKey)) {
75  authenticationKey = DEFAULT_AUTHENTICATION;
76  }
77  if (ModuleSettings.settingExists(BING_TRANSLATE_NAME, TARGET_LANGUAGE_CODE_KEY)) {
78  targetLanguageCode = ModuleSettings.getConfigSetting(BING_TRANSLATE_NAME, TARGET_LANGUAGE_CODE_KEY);
79  }
80  if (targetLanguageCode == null || StringUtils.isBlank(targetLanguageCode)) {
81  targetLanguageCode = DEFAULT_TARGET_LANGUAGE;
82  }
83  }
84 
90  String getTargetLanguageCode() {
91  return targetLanguageCode;
92  }
93 
100  void setTargetLanguageCode(String code) {
101  if (StringUtils.isBlank(code)) {
102  targetLanguageCode = DEFAULT_TARGET_LANGUAGE;
103  } else {
104  targetLanguageCode = code;
105  }
106  }
107 
111  void saveSettings() {
112  ModuleSettings.setConfigSetting(BING_TRANSLATE_NAME, AUTHENTICATION_KEY, authenticationKey);
113  ModuleSettings.setConfigSetting(BING_TRANSLATE_NAME, TARGET_LANGUAGE_CODE_KEY, targetLanguageCode);
114  }
115 }
static synchronized String getConfigSetting(String moduleName, String settingName)
static synchronized boolean makeConfigFile(String moduleName)
static synchronized boolean settingExists(String moduleName, String settingName)
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
static synchronized boolean configExists(String moduleName)

Copyright © 2012-2022 Basis Technology. Generated on: Mon Apr 17 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.