// Path: src/main/java/com/raibledesigns/webapp/listener/StartupListener.java
// public class StartupListener implements ServletContextListener {
//     private static final Log log = LogFactory.getLog(StartupListener.class);
// 
//     /**
//      * {@inheritDoc}
//      */
//     @SuppressWarnings("unchecked")
//     public void contextInitialized(ServletContextEvent event) {
//         log.debug("Initializing context...");
// 
//         ServletContext context = event.getServletContext();
// 
//         // Orion starts Servlets before Listeners, so check if the config
//         // object already exists
//         Map<String, Object> config = (HashMap<String, Object>) context.getAttribute(Constants.CONFIG);
// 
//         if (config == null) {
//             config = new HashMap<>();
//         }
// 
//         ApplicationContext ctx =
//                 WebApplicationContextUtils.getRequiredWebApplicationContext(context);
// 
//         PasswordEncoder passwordEncoder = null;
//         try {
//             ProviderManager provider = (ProviderManager) ctx.getBean("org.springframework.security.authentication.ProviderManager#0");
//             for (Object o : provider.getProviders()) {
//                 AuthenticationProvider p = (AuthenticationProvider) o;
//                 if (p instanceof RememberMeAuthenticationProvider) {
//                     config.put("rememberMeEnabled", Boolean.TRUE);
//                 } else if (ctx.getBean("passwordEncoder") != null) {
//                     passwordEncoder = (PasswordEncoder) ctx.getBean("passwordEncoder");
//                 }
//             }
//         } catch (NoSuchBeanDefinitionException n) {
//             log.debug("authenticationManager bean not found, assuming test and ignoring...");
//             // ignore, should only happen when testing
//         }
// 
//         context.setAttribute(Constants.CONFIG, config);
// 
//         // output the retrieved values for the Init and Context Parameters
//         if (log.isDebugEnabled()) {
//             log.debug("Remember Me Enabled? " + config.get("rememberMeEnabled"));
//             if (passwordEncoder != null) {
//                 log.debug("Password Encoder: " + passwordEncoder.getClass().getSimpleName());
//             }
//             log.debug("Populating drop-downs...");
//         }
// 
//         setupContext(context);
// 
//         // Determine version number for CSS and JS Assets
//         String appVersion = null;
//         try {
//             InputStream is = context.getResourceAsStream("/META-INF/MANIFEST.MF");
//             if (is == null) {
//                 log.warn("META-INF/MANIFEST.MF not found.");
//             } else {
//                 Manifest mf = new Manifest();
//                 mf.read(is);
//                 Attributes atts = mf.getMainAttributes();
//                 appVersion = atts.getValue("Implementation-Version");
//             }
//         } catch (IOException e) {
//             log.error("I/O Exception reading manifest: " + e.getMessage());
//         }
// 
//         // If there was a build number defined in the war, then use it for
//         // the cache buster. Otherwise, assume we are in development mode
//         // and use a random cache buster so developers don't have to clear
//         // their browser cache.
//         if (appVersion == null || appVersion.contains("SNAPSHOT")) {
//             appVersion = "" + new Random().nextInt(100000);
//         }
// 
//         log.info("Application version set to: " + appVersion);
//         context.setAttribute(Constants.ASSETS_VERSION, appVersion);
//     }
// 
//     /**
//      * This method uses the LookupManager to lookup available roles from the data layer.
//      *
//      * @param context The servlet context
//      */
//     public static void setupContext(ServletContext context) {
//         ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
//         LookupManager mgr = (LookupManager) ctx.getBean("lookupManager");
// 
//         // get list of possible roles
//         context.setAttribute(Constants.AVAILABLE_ROLES, mgr.getAllRoles());
//         log.debug("Drop-down initialization complete [OK]");
// 
//         // Any manager extending GenericManager will do:
//         GenericManager manager = (GenericManager) ctx.getBean("userManager");
//         doReindexing(manager);
//         log.debug("Full text search reindexing complete [OK]");
//     }
// 
//     private static void doReindexing(GenericManager manager) {
//         manager.reindexAll(false);
//     }
// 
//     /**
//      * Shutdown servlet context (currently a no-op method).
//      *
//      * @param servletContextEvent The servlet context event
//      */
//     public void contextDestroyed(ServletContextEvent servletContextEvent) {
//         //LogFactory.release(Thread.currentThread().getContextClassLoader());
//         //Commented out the above call to avoid warning when SLF4J in classpath.
//         //WARN: The method class org.apache.commons.logging.impl.SLF4JLogFactory#release() was invoked.
//         //WARN: Please see http://www.slf4j.org/codes.html for an explanation.
//     }
// }


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.raibledesigns.webapp.listener.StartupListener;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
package com.raibledesigns.webapp.controller;




/**
 * This class is used to reload the drop-downs initialized in the
 * StartupListener.
 *
 * <p>
 * <a href="ReloadController.java.html"><i>View Source</i></a>
 * </p>
 *
 * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
 */
@Controller
@RequestMapping("/admin/reload*")
public class ReloadController {
    private transient final Log log = LogFactory.getLog(ReloadController.class);

    @RequestMapping(method = RequestMethod.GET)
    @SuppressWarnings("unchecked")
    public ModelAndView handleRequest(HttpServletRequest request,
                                      HttpServletResponse response)
    throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("Entering 'execute' method");
        }

// Path: src/main/java/com/raibledesigns/webapp/listener/StartupListener.java
// public class StartupListener implements ServletContextListener {
//     private static final Log log = LogFactory.getLog(StartupListener.class);
// 
//     /**
//      * {@inheritDoc}
//      */
//     @SuppressWarnings("unchecked")
//     public void contextInitialized(ServletContextEvent event) {
//         log.debug("Initializing context...");
// 
//         ServletContext context = event.getServletContext();
// 
//         // Orion starts Servlets before Listeners, so check if the config
//         // object already exists
//         Map<String, Object> config = (HashMap<String, Object>) context.getAttribute(Constants.CONFIG);
// 
//         if (config == null) {
//             config = new HashMap<>();
//         }
// 
//         ApplicationContext ctx =
//                 WebApplicationContextUtils.getRequiredWebApplicationContext(context);
// 
//         PasswordEncoder passwordEncoder = null;
//         try {
//             ProviderManager provider = (ProviderManager) ctx.getBean("org.springframework.security.authentication.ProviderManager#0");
//             for (Object o : provider.getProviders()) {
//                 AuthenticationProvider p = (AuthenticationProvider) o;
//                 if (p instanceof RememberMeAuthenticationProvider) {
//                     config.put("rememberMeEnabled", Boolean.TRUE);
//                 } else if (ctx.getBean("passwordEncoder") != null) {
//                     passwordEncoder = (PasswordEncoder) ctx.getBean("passwordEncoder");
//                 }
//             }
//         } catch (NoSuchBeanDefinitionException n) {
//             log.debug("authenticationManager bean not found, assuming test and ignoring...");
//             // ignore, should only happen when testing
//         }
// 
//         context.setAttribute(Constants.CONFIG, config);
// 
//         // output the retrieved values for the Init and Context Parameters
//         if (log.isDebugEnabled()) {
//             log.debug("Remember Me Enabled? " + config.get("rememberMeEnabled"));
//             if (passwordEncoder != null) {
//                 log.debug("Password Encoder: " + passwordEncoder.getClass().getSimpleName());
//             }
//             log.debug("Populating drop-downs...");
//         }
// 
//         setupContext(context);
// 
//         // Determine version number for CSS and JS Assets
//         String appVersion = null;
//         try {
//             InputStream is = context.getResourceAsStream("/META-INF/MANIFEST.MF");
//             if (is == null) {
//                 log.warn("META-INF/MANIFEST.MF not found.");
//             } else {
//                 Manifest mf = new Manifest();
//                 mf.read(is);
//                 Attributes atts = mf.getMainAttributes();
//                 appVersion = atts.getValue("Implementation-Version");
//             }
//         } catch (IOException e) {
//             log.error("I/O Exception reading manifest: " + e.getMessage());
//         }
// 
//         // If there was a build number defined in the war, then use it for
//         // the cache buster. Otherwise, assume we are in development mode
//         // and use a random cache buster so developers don't have to clear
//         // their browser cache.
//         if (appVersion == null || appVersion.contains("SNAPSHOT")) {
//             appVersion = "" + new Random().nextInt(100000);
//         }
// 
//         log.info("Application version set to: " + appVersion);
//         context.setAttribute(Constants.ASSETS_VERSION, appVersion);
//     }
// 
//     /**
//      * This method uses the LookupManager to lookup available roles from the data layer.
//      *
//      * @param context The servlet context
//      */
//     public static void setupContext(ServletContext context) {
//         ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
//         LookupManager mgr = (LookupManager) ctx.getBean("lookupManager");
// 
//         // get list of possible roles
//         context.setAttribute(Constants.AVAILABLE_ROLES, mgr.getAllRoles());
//         log.debug("Drop-down initialization complete [OK]");
// 
//         // Any manager extending GenericManager will do:
//         GenericManager manager = (GenericManager) ctx.getBean("userManager");
//         doReindexing(manager);
//         log.debug("Full text search reindexing complete [OK]");
//     }
// 
//     private static void doReindexing(GenericManager manager) {
//         manager.reindexAll(false);
//     }
// 
//     /**
//      * Shutdown servlet context (currently a no-op method).
//      *
//      * @param servletContextEvent The servlet context event
//      */
//     public void contextDestroyed(ServletContextEvent servletContextEvent) {
//         //LogFactory.release(Thread.currentThread().getContextClassLoader());
//         //Commented out the above call to avoid warning when SLF4J in classpath.
//         //WARN: The method class org.apache.commons.logging.impl.SLF4JLogFactory#release() was invoked.
//         //WARN: Please see http://www.slf4j.org/codes.html for an explanation.
//     }
// }


// Path: src/main/java/com/raibledesigns/webapp/controller/ReloadController.java
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.raibledesigns.webapp.listener.StartupListener;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

package com.raibledesigns.webapp.controller;




/**
 * This class is used to reload the drop-downs initialized in the
 * StartupListener.
 *
 * <p>
 * <a href="ReloadController.java.html"><i>View Source</i></a>
 * </p>
 *
 * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
 */
@Controller
@RequestMapping("/admin/reload*")
public class ReloadController {
    private transient final Log log = LogFactory.getLog(ReloadController.class);

    @RequestMapping(method = RequestMethod.GET)
    @SuppressWarnings("unchecked")
    public ModelAndView handleRequest(HttpServletRequest request,
                                      HttpServletResponse response)
    throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("Entering 'execute' method");
        }

        StartupListener.setupContext(request.getSession().getServletContext());