Autopsy  3.1
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  private 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  private 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  return generatorLogoPath;
103  }
104 
105  @Override
106  public void setGeneratorLogoPath(String path) {
107  generatorLogoPath = path;
108  }
109 
110  @Override
111  public String getAgencyLogoPath() {
112  String curPath = null;
113 
114  /* The agency logo code uses these properties to persist changes
115  * in the logo (within the same process).
116  * This is different from the generator logo that uses a static variable.
117  */
118  curPath = ModuleSettings.getConfigSetting(MODULE_NAME, AGENCY_LOGO_PATH_PROP);
119  //if has been set, validate it's correct, if not set, return null
120  if (curPath != null && new File(curPath).canRead() == false) {
121  //use default
122  logger.log(Level.INFO, "Custom report branding for agency logo is not valid: " + curPath); //NON-NLS
123  curPath = null;
124  }
125 
126  return curPath;
127  }
128 
129  @Override
130  public void setAgencyLogoPath(String path) {
131  // Use properties to persist the logo to use.
132  // Should use static variable instead
133  ModuleSettings.setConfigSetting(MODULE_NAME, AGENCY_LOGO_PATH_PROP, path);
134  }
135 
136  @Override
137  public String getReportTitle() {
138  String curTitle = null;
139 
140  curTitle = ModuleSettings.getConfigSetting(MODULE_NAME, REPORT_TITLE_PROP);
141  if (curTitle == null || curTitle.isEmpty()) {
142  //use default
143  logger.log(Level.INFO, "Using default report branding for report title"); //NON-NLS
144  curTitle = DEFAULT_REPORT_TITLE;
145  ModuleSettings.setConfigSetting(MODULE_NAME, REPORT_TITLE_PROP, curTitle);
146  }
147 
148  return curTitle;
149  }
150 
151  @Override
152  public void setReportTitle(String title) {
153  ModuleSettings.setConfigSetting(MODULE_NAME, REPORT_TITLE_PROP, title);
154  }
155 
156  @Override
157  public String getReportFooter() {
158  String curFooter = null;
159 
160  curFooter = ModuleSettings.getConfigSetting(MODULE_NAME, REPORT_FOOTER_PROP);
161  if (curFooter == null) {
162  //use default
163  logger.log(Level.INFO, "Using default report branding for report footer"); //NON-NLS
164  curFooter = DEFAULT_REPORT_FOOTER;
165  ModuleSettings.setConfigSetting(MODULE_NAME, REPORT_FOOTER_PROP, curFooter);
166  }
167 
168  return curFooter;
169  }
170 
171  @Override
172  public void setReportFooter(String footer) {
173  ModuleSettings.setConfigSetting(MODULE_NAME, REPORT_FOOTER_PROP, footer);
174  }
175 }
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)
static Logger getLogger(String name)
Definition: Logger.java:131

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