Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
GoogleTranslatorSettings.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 com.google.cloud.translate.TranslateOptions;
22 import org.apache.commons.lang3.StringUtils;
24 
28 public final class GoogleTranslatorSettings {
29 
30  private static final String DEFAULT_TARGET_LANGUAGE = TranslateOptions.getDefaultInstance().getTargetLanguage();
31  private static final String CREDENTIAL_PATH_KEY = "CredentialPath";
32  private static final String TARGET_LANGUAGE_CODE_KEY = "TargetLanguageCode";
33  private static final String GOOGLE_TRANSLATE_NAME = "GoogleTranslate";
34  private static final String DEFAULT_CREDENTIAL_PATH = "";
35  private String targetLanguageCode;
36  private String credentialPath;
37 
42  loadSettings();
43  }
44 
50  String getTargetLanguageCode() {
51  return targetLanguageCode;
52  }
53 
59  String getCredentialPath() {
60  return credentialPath;
61  }
62 
68  void setCredentialPath(String path) {
69  credentialPath = path;
70  }
71 
78  void setTargetLanguageCode(String code) {
79  if (StringUtils.isBlank(code)) {
80  targetLanguageCode = DEFAULT_TARGET_LANGUAGE;
81  } else {
82  targetLanguageCode = code;
83  }
84  }
85 
89  void loadSettings() {
90  if (!ModuleSettings.configExists(GOOGLE_TRANSLATE_NAME)) {
91  ModuleSettings.makeConfigFile(GOOGLE_TRANSLATE_NAME);
92  }
93  if (ModuleSettings.settingExists(GOOGLE_TRANSLATE_NAME, TARGET_LANGUAGE_CODE_KEY)) {
94  targetLanguageCode = ModuleSettings.getConfigSetting(GOOGLE_TRANSLATE_NAME, TARGET_LANGUAGE_CODE_KEY);
95  }
96  if (targetLanguageCode == null || StringUtils.isBlank(targetLanguageCode)) {
97  targetLanguageCode = DEFAULT_TARGET_LANGUAGE;
98  }
99  if (ModuleSettings.settingExists(GOOGLE_TRANSLATE_NAME, CREDENTIAL_PATH_KEY)) {
100  credentialPath = ModuleSettings.getConfigSetting(GOOGLE_TRANSLATE_NAME, CREDENTIAL_PATH_KEY);
101  }
102  if (credentialPath == null) {
103  credentialPath = DEFAULT_CREDENTIAL_PATH;
104  }
105  }
106 
110  void saveSettings() {
111  ModuleSettings.setConfigSetting(GOOGLE_TRANSLATE_NAME, TARGET_LANGUAGE_CODE_KEY, targetLanguageCode);
112  ModuleSettings.setConfigSetting(GOOGLE_TRANSLATE_NAME, CREDENTIAL_PATH_KEY, credentialPath);
113  }
114 }

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