Autopsy  4.14.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;
30 
41 
42  private static volatile StartupWindowProvider instance;
43  private static final Logger logger = Logger.getLogger(StartupWindowProvider.class.getName());
45 
47  if (instance == null) {
48  synchronized (StartupWindowProvider.class) {
49  if (instance == null) {
50  instance = new StartupWindowProvider();
51  instance.init();
52  }
53  }
54  }
55 
56  return instance;
57  }
58 
59  private void init() {
60  if (startupWindowToUse == null) {
61  // first check whether we are running from command line
63  // Autopsy is running from command line
64  logger.log(Level.INFO, "Running from command line"); //NON-NLS
65  startupWindowToUse = new CommandLineStartupWindow();
66  // kick off command line processing
68  return;
69  }
70 
71  //discover the registered windows
72  Collection<? extends StartupWindowInterface> startupWindows
73  = Lookup.getDefault().lookupAll(StartupWindowInterface.class);
74 
75  int windowsCount = startupWindows.size();
76  if (windowsCount == 1) {
77  startupWindowToUse = startupWindows.iterator().next();
78  logger.log(Level.INFO, "Will use the default startup window: " + startupWindowToUse.toString()); //NON-NLS
79  } else if (windowsCount == 2) {
80  //pick the non default one
81  Iterator<? extends StartupWindowInterface> it = startupWindows.iterator();
82  while (it.hasNext()) {
83  StartupWindowInterface window = it.next();
84  if (!org.sleuthkit.autopsy.casemodule.StartupWindow.class.isInstance(window)) {
85  startupWindowToUse = window;
86  logger.log(Level.INFO, "Will use the custom startup window: " + startupWindowToUse.toString()); //NON-NLS
87  break;
88  }
89  }
90  } else {
91  // select first non-Autopsy start up window
92  Iterator<? extends StartupWindowInterface> it = startupWindows.iterator();
93  while (it.hasNext()) {
94  StartupWindowInterface window = it.next();
95  if (!window.getClass().getCanonicalName().startsWith("org.sleuthkit.autopsy")) {
96  startupWindowToUse = window;
97  logger.log(Level.INFO, "Will use the custom startup window: " + startupWindowToUse.toString()); //NON-NLS
98  break;
99  }
100  }
101  }
102 
103  if (startupWindowToUse == null) {
104  logger.log(Level.SEVERE, "Unexpected error, no startup window chosen, using the default"); //NON-NLS
105  startupWindowToUse = new org.sleuthkit.autopsy.casemodule.StartupWindow();
106  }
107  }
108  }
109 
118  private boolean isRunningFromCommandLine() {
119 
120  // first look up all OptionProcessors and see if running from command line option is set
121  Collection<? extends OptionProcessor> optionProcessors = Lookup.getDefault().lookupAll(OptionProcessor.class);
122  Iterator<? extends OptionProcessor> optionsIterator = optionProcessors.iterator();
123  while (optionsIterator.hasNext()) {
124  // find CommandLineOptionProcessor
125  OptionProcessor processor = optionsIterator.next();
126  if ((processor instanceof CommandLineOptionProcessor)) {
127  // check if we are running from command line
128  return ((CommandLineOptionProcessor) processor).isRunFromCommandLine();
129  }
130  }
131  return false;
132  }
133 
134  @Override
135  public void open() {
136  if (startupWindowToUse != null) {
137  startupWindowToUse.open();
138  }
139  }
140 
141  @Override
142  public void close() {
143  if (startupWindowToUse != null) {
144  startupWindowToUse.close();
145  }
146  }
147 
154  return startupWindowToUse;
155  }
156 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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