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

Copyright © 2012-2018 Basis Technology. Generated on: Fri Mar 22 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.