Autopsy  4.17.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
StartupWindowProvider.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-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.casemodule;
20 
21 import java.util.Collection;
22 import java.util.Iterator;
23 import java.util.logging.Level;
24 import org.netbeans.spi.sendopts.OptionProcessor;
25 import org.openide.util.Lookup;
26 import org.openide.util.NbBundle;
35 
46 
47  private static volatile StartupWindowProvider instance;
48  private static final Logger logger = Logger.getLogger(StartupWindowProvider.class.getName());
50 
52  if (instance == null) {
53  synchronized (StartupWindowProvider.class) {
54  if (instance == null) {
55  instance = new StartupWindowProvider();
56  instance.init();
57  }
58  }
59  }
60 
61  return instance;
62  }
63 
64  private void init() {
65  if (startupWindowToUse == null) {
66  // first check whether we are running from command line
68 
69  String defaultArg = getDefaultArgument();
70  if(defaultArg != null) {
71  new CommandLineOpenCaseManager(defaultArg).start();
72  return;
73  } else {
74  // Autopsy is running from command line
75  logger.log(Level.INFO, "Running from command line"); //NON-NLS
76  startupWindowToUse = new CommandLineStartupWindow();
77  // kick off command line processing
79  return;
80  }
81  }
82 
84  checkSolr();
85  }
86 
87  //discover the registered windows
88  Collection<? extends StartupWindowInterface> startupWindows
89  = Lookup.getDefault().lookupAll(StartupWindowInterface.class);
90 
91  int windowsCount = startupWindows.size();
92  if (windowsCount == 1) {
93  startupWindowToUse = startupWindows.iterator().next();
94  logger.log(Level.INFO, "Will use the default startup window: " + startupWindowToUse.toString()); //NON-NLS
95  } else if (windowsCount == 2) {
96  //pick the non default one
97  Iterator<? extends StartupWindowInterface> it = startupWindows.iterator();
98  while (it.hasNext()) {
99  StartupWindowInterface window = it.next();
100  if (!org.sleuthkit.autopsy.casemodule.StartupWindow.class.isInstance(window)) {
101  startupWindowToUse = window;
102  logger.log(Level.INFO, "Will use the custom startup window: " + startupWindowToUse.toString()); //NON-NLS
103  break;
104  }
105  }
106  } else {
107  // select first non-Autopsy start up window
108  Iterator<? extends StartupWindowInterface> it = startupWindows.iterator();
109  while (it.hasNext()) {
110  StartupWindowInterface window = it.next();
111  if (!window.getClass().getCanonicalName().startsWith("org.sleuthkit.autopsy")) {
112  startupWindowToUse = window;
113  logger.log(Level.INFO, "Will use the custom startup window: " + startupWindowToUse.toString()); //NON-NLS
114  break;
115  }
116  }
117  }
118 
119  if (startupWindowToUse == null) {
120  logger.log(Level.SEVERE, "Unexpected error, no startup window chosen, using the default"); //NON-NLS
121  startupWindowToUse = new org.sleuthkit.autopsy.casemodule.StartupWindow();
122  }
123  }
124  }
125 
126  private void checkSolr() {
127 
128  // if Multi-User settings are enabled and Solr8 server is not configured,
129  // display an error message and a dialog
131  // Solr 8 host name is not configured. This could be the first time user
132  // runs Autopsy with Solr 8. Display a message.
133  MessageNotifyUtil.Notify.error(NbBundle.getMessage(CueBannerPanel.class, "SolrNotConfiguredDialog.title"),
134  NbBundle.getMessage(SolrNotConfiguredDialog.class, "SolrNotConfiguredDialog.EmptyKeywordSearchHostName"));
135 
136  SolrNotConfiguredDialog dialog = new SolrNotConfiguredDialog();
137  dialog.setVisible(true);
138  }
139  }
140 
149  private boolean isRunningFromCommandLine() {
150 
151  CommandLineOptionProcessor processor = Lookup.getDefault().lookup(CommandLineOptionProcessor.class);
152  if(processor != null) {
153  return processor.isRunFromCommandLine();
154  }
155  return false;
156  }
157 
163  private String getDefaultArgument() {
164  CommandLineOptionProcessor processor = Lookup.getDefault().lookup(CommandLineOptionProcessor.class);
165  if(processor != null) {
166  return processor.getDefaultArgument();
167  }
168  return null;
169  }
170 
171  @Override
172  public void open() {
173  if (startupWindowToUse != null) {
174  startupWindowToUse.open();
175  }
176  }
177 
178  @Override
179  public void close() {
180  if (startupWindowToUse != null) {
181  startupWindowToUse.close();
182  }
183  }
184 
191  return startupWindowToUse;
192  }
193 }
static void error(String title, String message)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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