Autopsy  4.6.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.openide.util.Lookup;
26 
37 
38  private static volatile StartupWindowProvider instance;
39  private static final Logger logger = Logger.getLogger(StartupWindowProvider.class.getName());
41 
43  if (instance == null) {
44  synchronized (StartupWindowProvider.class) {
45  if (instance == null) {
46  instance = new StartupWindowProvider();
47  instance.init();
48  }
49  }
50  }
51 
52  return instance;
53  }
54 
55  private void init() {
56  if (startupWindowToUse == null) {
57  //discover the registered windows
58  Collection<? extends StartupWindowInterface> startupWindows
59  = Lookup.getDefault().lookupAll(StartupWindowInterface.class);
60 
61  int windowsCount = startupWindows.size();
62  if (windowsCount == 1) {
63  startupWindowToUse = startupWindows.iterator().next();
64  logger.log(Level.INFO, "Will use the default startup window: " + startupWindowToUse.toString()); //NON-NLS
65  } else if (windowsCount == 2) {
66  //pick the non default one
67  Iterator<? extends StartupWindowInterface> it = startupWindows.iterator();
68  while (it.hasNext()) {
69  StartupWindowInterface window = it.next();
70  if (!org.sleuthkit.autopsy.casemodule.StartupWindow.class.isInstance(window)) {
71  startupWindowToUse = window;
72  logger.log(Level.INFO, "Will use the custom startup window: " + startupWindowToUse.toString()); //NON-NLS
73  break;
74  }
75  }
76  } else {
77  // select first non-Autopsy start up window
78  Iterator<? extends StartupWindowInterface> it = startupWindows.iterator();
79  while (it.hasNext()) {
80  StartupWindowInterface window = it.next();
81  if (!window.getClass().getCanonicalName().startsWith("org.sleuthkit.autopsy")) {
82  startupWindowToUse = window;
83  logger.log(Level.INFO, "Will use the custom startup window: " + startupWindowToUse.toString()); //NON-NLS
84  break;
85  }
86  }
87  }
88 
89  if (startupWindowToUse == null) {
90  logger.log(Level.SEVERE, "Unexpected error, no startup window chosen, using the default"); //NON-NLS
91  startupWindowToUse = new org.sleuthkit.autopsy.casemodule.StartupWindow();
92  }
93  }
94  }
95 
96  @Override
97  public void open() {
98  if (startupWindowToUse != null) {
99  startupWindowToUse.open();
100  }
101  }
102 
103  @Override
104  public void close() {
105  if (startupWindowToUse != null) {
106  startupWindowToUse.close();
107  }
108  }
109 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.