Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements. See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership. The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
 package org.apache.marmotta.splash.startup;
 import static org.apache.marmotta.splash.common.MarmottaStartupHelper.checkServerName;
 import static org.apache.marmotta.splash.common.MarmottaStartupHelper.getServerPort;
 import static org.apache.marmotta.splash.common.MarmottaStartupHelper.getStartupProperties;
 import static org.apache.marmotta.splash.common.MarmottaStartupHelper.listHostAddresses;
 import static org.apache.marmotta.splash.common.MarmottaStartupHelper.storeStartupProperties;
 import java.util.List;
 import java.util.Map;
Add file description here!

Author: Sebastian Schaffert

 public class StartupListener implements LifecycleListener {
     protected static Log log = LogFactory.getLog(StartupListener.class);
     public StartupListener() {

React on the AFTER_START_EVENT of Tomcat and startup the browser to point to the Marmotta installation. Depending on the state of the Marmotta installation, the following actions are carried out:
  • in case the Marmotta is started for the first time, show a dialog box with options to select which IP-address to use for configuring the Marmotta; the IP address will be stored in a separate properties file in MARMOTTA_HOME
  • in case the Marmotta has already been configured but the IP address that was used is no longer existing on the server, show a warning dialog (this can happen e.g. for laptops with dynamically changing network configurations)
  • otherwise, open a browser using the network address that was used previously

event LifecycleEvent that has occurred
     public void lifecycleEvent(LifecycleEvent event) {
         if(event.getType().equals(.)) {
             if(!GraphicsEnvironment.isHeadless()) {
                 String serverName = null;
                 int serverPort = 0;
                 // open browser window
                 if (Desktop.isDesktopSupported()) {
                     Properties startupProperties = getStartupProperties();
                     if(startupProperties.getProperty("") != null && startupProperties.getProperty("startup.port") != null) {
                         serverName = startupProperties.getProperty("");
                         serverPort = Integer.parseInt(startupProperties.getProperty("startup.port"));
                         if(!checkServerName(serverName) || serverPort != getServerPort()) {
                                     "Configured server name not found",
                                     "The host name ("+serverName+") that has been used to configure this \n" +
                                     "installation is no longer available on this server. The system \n" +
                                     "might behave unexpectedly. Please consider using a localhost configuration \n" +
                                     "for systems with dynamic IP addresses!");
                    } else {
                        // show a dialog listing all available addresses of this server and allowing the user to
                        // chose
                        List<Optionchoices = new ArrayList<>();
                        Map<String,List<InetAddress>> addressList = listHostAddresses();
                        List<StringhostNames = new ArrayList<String>(addressList.keySet());
                        int loopback = -1;
                        for (int i = 0; i < hostNames.size(); i++) {
                            String hostName = hostNames.get(i);
                            List<InetAddressaddresses = addressList.get(hostName);
                            String label = hostName + " \n(";
                            for(Iterator<InetAddressit = addresses.iterator(); it.hasNext(); ) {
                                label +=;
                                if(it.hasNext()) {
                                    label +=", ";
                            label += ")";
                            String text;
                            if(addresses.get(0).isLoopbackAddress()) {
                                text = "Local IP-Address. Recommended for Laptop use or Demonstration purposes";
                                loopback = loopback<0?i:loopback;
                            } else {
                                text = "Public IP-Address. Recommended for Workstation or Server use";
                            choices.add(new Option(labeltext));
                        int choice ="Select Server Address",
                                "Select host address to use for configuring the\nApache Marmotta Platform.",
                                WordUtils.wrap("For demonstration purposes or laptop installations it is recommended to select \""+(loopback<0?"localhost":hostNames.get(loopback))+"\" below. For server and workstation installations, please select a public IP address.", 60), 
                        if (choice < 0) {
                            .error("No Server Address selected, server will shut down.");
                            throw new IllegalArgumentException("No Server Addess was selected");
                        serverName = hostNames.get(choice);
                        serverPort = getServerPort();
                    final Desktop desktop = Desktop.getDesktop();
                    if(desktop.isSupported(..) && serverName != null && serverPort > 0) {
                        try {
                            URI uri = new URI("http",null,serverName,serverPort,"/",null,null);
                        } catch (Exception e1) {
                            ..println("could not open browser window, message was: "+e1.getMessage());
New to GrepCode? Check out our FAQ X