/*
 * Copyright 2015 Corpuslinguistic working group Humboldt University Berlin.
 *
 * Licensed 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
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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 annis.gui.servlets;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
import java.util.Properties;

import javax.servlet.ServletException;

import org.aeonbits.owner.ConfigFactory;

import com.vaadin.server.ServiceException;
import com.vaadin.server.SessionInitEvent;
import com.vaadin.server.SessionInitListener;
import com.vaadin.server.VaadinService;
import com.vaadin.server.VaadinServlet;
import com.vaadin.server.VaadinSession;

import annis.gui.requesthandler.ShortenerRequestHandler;
import annis.libgui.AnnisBaseUI;
import annis.libgui.Helper;
import annis.libgui.UIConfig;

/**
 *
 * @author Thomas Krause {@literal <krauseto@hu-berlin.de>}
 */
public class AnnisServlet extends VaadinServlet {
    
    protected void loadApplicationProperties(String configFile, VaadinSession session) {
        List<File> locations = AnnisBaseUI.getAllConfigLocations(configFile);

        // load properties in the right order
        for (File f : locations) {
            loadPropertyFile(f, session);
        }
    }

    private void loadPropertyFile(File f, VaadinSession session) {
        if (f.canRead() && f.isFile()) {
            try (FileInputStream fis = new FileInputStream(f)) {
                Properties p = new Properties();
                p.load(fis);

                // copy all properties to the session
                for (String name : p.stringPropertyNames()) {
                    session.setAttribute(name, p.getProperty(name));
                }

            } catch (IOException ex) {

            }
        }
    }

    @Override
    protected void servletInitialized() throws ServletException {
        super.servletInitialized();

        getService().addSessionInitListener(new SessionInitListener() {

            @Override
            public void sessionInit(SessionInitEvent event) throws ServiceException {
                VaadinSession session = event.getSession();
                event.getSession().addRequestHandler(new ShortenerRequestHandler());
            }
        });
    }

}

@@ -1413,843 +1413,8 @@
    %0A
-    protected void loadApplicationProperties(String configFile, VaadinSession session) %7B%0A        List%3CFile%3E locations = AnnisBaseUI.getAllConfigLocations(configFile);%0A%0A        // load properties in the right order%0A        for (File f : locations) %7B%0A            loadPropertyFile(f, session);%0A        %7D%0A    %7D%0A%0A    private void loadPropertyFile(File f, VaadinSession session) %7B%0A        if (f.canRead() && f.isFile()) %7B%0A            try (FileInputStream fis = new FileInputStream(f)) %7B%0A                Properties p = new Properties();%0A                p.load(fis);%0A%0A                // copy all properties to the session%0A                for (String name : p.stringPropertyNames()) %7B%0A                    session.setAttribute(name, p.getProperty(name));%0A                %7D%0A%0A            %7D catch (IOException ex) %7B%0A%0A            %7D%0A        %7D%0A    %7D%0A%0A
     

Remove unused functions