Autopsy  4.15.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ReportBranding.java
Go to the documentation of this file.
1  /*
2  *
3  * Autopsy Forensic Browser
4  *
5  * Copyright 2013-2014 Basis Technology Corp.
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.report;
20 
22 import java.io.File;
23 import java.io.IOException;
24 import java.util.logging.Level;
26 import org.openide.util.NbBundle;
29 
37 public final class ReportBranding implements ReportBrandingProviderI {
38 
39  //property names
40  public static final String AGENCY_LOGO_PATH_PROP = "AgencyLogoPath"; //NON-NLS
41  private static final String REPORT_TITLE_PROP = "ReportTitle"; //NON-NLS
42  private static final String REPORT_FOOTER_PROP = "ReportFooter"; //NON-NLS
43  //default settings
44  private static final String DEFAULT_GENERATOR_LOGO = "/org/sleuthkit/autopsy/report/images/default_generator_logo.png"; //NON-NLS
45  private static final String DEFAULT_REPORT_TITLE = NbBundle
46  .getMessage(ReportBranding.class, "ReportBranding.defaultReportTitle.text");
47  private static final String DEFAULT_REPORT_FOOTER = NbBundle
48  .getMessage(ReportBranding.class, "ReportBranding.defaultReportFooter.text");
49  private String reportsBrandingDir; //dir with extracted reports branding resources
50  public static final String MODULE_NAME = ReportBranding.class.getSimpleName();
51  private static final Logger logger = Logger.getLogger(ReportBranding.class.getName());
52 
53  // this is static so that it can be set by another object
54  // before the report is actually made. Entire class should
55  // probably become singleton. Is set to null until setPath
56  // is called to specify something other than default.
57  private static String generatorLogoPath = null;
58 
59  private String defaultGeneratorLogoPath;
60 
61  public ReportBranding() {
62 
63  //initialize with extracting of resource files if needed, ensure 1 writer at a time
64  synchronized (ReportBranding.class) {
65 
66  reportsBrandingDir = PlatformUtil.getUserConfigDirectory() + File.separator + ReportGenerator.getReportsDirectory() + File.separator
67  + "branding"; //NON-NLS
68  File brandingDir = new File(reportsBrandingDir);
69  if (!brandingDir.exists()) {
70  if (!brandingDir.mkdirs()) {
71  logger.log(Level.SEVERE, "Error creating report branding dir for the case, will use defaults"); //NON-NLS
72  //TODO use defaults
73  }
74  }
78  }
79  }
80 
81  public String getReportsBrandingDir() {
82  return reportsBrandingDir;
83  }
84 
88  private void extractDefaultGeneratorLogo() {
89  try {
90  PlatformUtil.extractResourceToUserConfigDir(getClass(), DEFAULT_GENERATOR_LOGO, true);
91  } catch (IOException ex) {
92  logger.log(Level.SEVERE, "Error extracting report branding resource for generator logo ", ex); //NON-NLS
93  }
94  defaultGeneratorLogoPath = PlatformUtil.getUserConfigDirectory() + File.separator + DEFAULT_GENERATOR_LOGO;
95  }
96 
97  @Override
98  public String getGeneratorLogoPath() {
99  // if no one called to change the path, use default
100  if (generatorLogoPath == null) {
101  generatorLogoPath = defaultGeneratorLogoPath;
102  }
103 
104  return generatorLogoPath;
105  }
106 
107  @Override
108  public void setGeneratorLogoPath(String path) {
109  generatorLogoPath = path;
110  }
111 
112  @Override
113  public String getAgencyLogoPath() {
114  String curPath = null;
115 
116  /*
117  * The agency logo code uses these properties to persist changes in the
118  * logo (within the same process). This is different from the generator
119  * logo that uses a static variable.
120  */
121  curPath = ModuleSettings.getConfigSetting(MODULE_NAME, AGENCY_LOGO_PATH_PROP);
122  //if has been set, validate it's correct, if not set, return null
123  if (curPath != null && new File(curPath).canRead() == false) {
124  //use default
125  logger.log(Level.INFO, "Custom report branding for agency logo is not valid: " + curPath); //NON-NLS
126  curPath = null;
127  }
128 
129  return curPath;
130  }
131 
132  @Override
133  public void setAgencyLogoPath(String path) {
134  // Use properties to persist the logo to use.
135  // Should use static variable instead
136  ModuleSettings.setConfigSetting(MODULE_NAME, AGENCY_LOGO_PATH_PROP, path);
137  }
138 
139  @Override
140  public String getReportTitle() {
141  String curTitle = null;
142 
143  curTitle = ModuleSettings.getConfigSetting(MODULE_NAME, REPORT_TITLE_PROP);
144  if (curTitle == null || curTitle.isEmpty()) {
145  //use default
146  logger.log(Level.INFO, "Using default report branding for report title"); //NON-NLS
147  curTitle = DEFAULT_REPORT_TITLE;
148  ModuleSettings.setConfigSetting(MODULE_NAME, REPORT_TITLE_PROP, curTitle);
149  }
150 
151  return curTitle;
152  }
153 
154  @Override
155  public void setReportTitle(String title) {
156  ModuleSettings.setConfigSetting(MODULE_NAME, REPORT_TITLE_PROP, title);
157  }
158 
159  @Override
160  public String getReportFooter() {
161  String curFooter = null;
162 
163  curFooter = ModuleSettings.getConfigSetting(MODULE_NAME, REPORT_FOOTER_PROP);
164  if (curFooter == null) {
165  //use default
166  logger.log(Level.INFO, "Using default report branding for report footer"); //NON-NLS
167  curFooter = DEFAULT_REPORT_FOOTER;
168  ModuleSettings.setConfigSetting(MODULE_NAME, REPORT_FOOTER_PROP, curFooter);
169  }
170 
171  return curFooter;
172  }
173 
174  @Override
175  public void setReportFooter(String footer) {
176  ModuleSettings.setConfigSetting(MODULE_NAME, REPORT_FOOTER_PROP, footer);
177  }
178 }
static synchronized String getConfigSetting(String moduleName, String settingName)
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
static< T > boolean extractResourceToUserConfigDir(final Class< T > resourceClass, final String resourceFileName, boolean overWrite)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2020 Basis Technology. Generated on: Mon Jul 6 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.