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

Copyright © 2012-2016 Basis Technology. Generated on: Tue Feb 20 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.