Autopsy  4.16.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;
31 
42 
43  private static volatile StartupWindowProvider instance;
44  private static final Logger logger = Logger.getLogger(StartupWindowProvider.class.getName());
46 
48  if (instance == null) {
49  synchronized (StartupWindowProvider.class) {
50  if (instance == null) {
51  instance = new StartupWindowProvider();
52  instance.init();
53  }
54  }
55  }
56 
57  return instance;
58  }
59 
60  private void init() {
61  if (startupWindowToUse == null) {
62  // first check whether we are running from command line
64 
65  String defaultArg = getDefaultArgument();
66  if(defaultArg != null) {
67  new CommandLineOpenCaseManager(defaultArg).start();
68  return;
69  } else {
70  // Autopsy is running from command line
71  logger.log(Level.INFO, "Running from command line"); //NON-NLS
72  startupWindowToUse = new CommandLineStartupWindow();
73  // kick off command line processing
75  return;
76  }
77  }
78 
79  //discover the registered windows
80  Collection<? extends StartupWindowInterface> startupWindows
81  = Lookup.getDefault().lookupAll(StartupWindowInterface.class);
82 
83  int windowsCount = startupWindows.size();
84  if (windowsCount == 1) {
85  startupWindowToUse = startupWindows.iterator().next();
86  logger.log(Level.INFO, "Will use the default startup window: " + startupWindowToUse.toString()); //NON-NLS
87  } else if (windowsCount == 2) {
88  //pick the non default one
89  Iterator<? extends StartupWindowInterface> it = startupWindows.iterator();
90  while (it.hasNext()) {
91  StartupWindowInterface window = it.next();
92  if (!org.sleuthkit.autopsy.casemodule.StartupWindow.class.isInstance(window)) {
93  startupWindowToUse = window;
94  logger.log(Level.INFO, "Will use the custom startup window: " + startupWindowToUse.toString()); //NON-NLS
95  break;
96  }
97  }
98  } else {
99  // select first non-Autopsy start up window
100  Iterator<? extends StartupWindowInterface> it = startupWindows.iterator();
101  while (it.hasNext()) {
102  StartupWindowInterface window = it.next();
103  if (!window.getClass().getCanonicalName().startsWith("org.sleuthkit.autopsy")) {
104  startupWindowToUse = window;
105  logger.log(Level.INFO, "Will use the custom startup window: " + startupWindowToUse.toString()); //NON-NLS
106  break;
107  }
108  }
109  }
110 
111  if (startupWindowToUse == null) {
112  logger.log(Level.SEVERE, "Unexpected error, no startup window chosen, using the default"); //NON-NLS
113  startupWindowToUse = new org.sleuthkit.autopsy.casemodule.StartupWindow();
114  }
115  }
116  }
117 
126  private boolean isRunningFromCommandLine() {
127 
128  CommandLineOptionProcessor processor = Lookup.getDefault().lookup(CommandLineOptionProcessor.class);
129  if(processor != null) {
130  return processor.isRunFromCommandLine();
131  }
132  return false;
133  }
134 
140  private String getDefaultArgument() {
141  CommandLineOptionProcessor processor = Lookup.getDefault().lookup(CommandLineOptionProcessor.class);
142  if(processor != null) {
143  return processor.getDefaultArgument();
144  }
145  return null;
146  }
147 
148  @Override
149  public void open() {
150  if (startupWindowToUse != null) {
151  startupWindowToUse.open();
152  }
153  }
154 
155  @Override
156  public void close() {
157  if (startupWindowToUse != null) {
158  startupWindowToUse.close();
159  }
160  }
161 
168  return startupWindowToUse;
169  }
170 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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