Example usage for javax.servlet ServletContext getAttribute

List of usage examples for javax.servlet ServletContext getAttribute

Introduction

In this page you can find the example usage for javax.servlet ServletContext getAttribute.

Prototype

public Object getAttribute(String name);

Source Link

Document

Returns the servlet container attribute with the given name, or null if there is no attribute by that name.

Usage

From source file:org.entando.entando.plugins.jpcomponentinstaller.aps.system.services.installer.DefaultComponentInstaller.java

private ApplicationContext getStoredContext(String contextDisplayName) {
    ServletContext servletContext = ((ConfigurableWebApplicationContext) _applicationContext)
            .getServletContext();//from  ww w. j a v  a  2 s  .c  o m
    List<ClassPathXmlApplicationContext> ctxList = (List<ClassPathXmlApplicationContext>) servletContext
            .getAttribute("pluginsContextsList");
    for (ClassPathXmlApplicationContext ctx : ctxList) {
        if (contextDisplayName.equals(ctx.getDisplayName())) {
            return ctx;
        }
    }
    return null;
}

From source file:org.apache.pluto.driver.services.container.EventProviderImpl.java

private List<String> getAllPortletsRegisteredForEvent(Event event, DriverConfiguration driverConfig,
        ServletContext containerServletContext) {
    Set<String> resultSet = new HashSet<String>();
    List<String> resultList = new ArrayList<String>();
    QName eventName = event.getQName();
    Collection<PortletWindowConfig> portlets = getAllPortlets(driverConfig);
    if (portletRegistry == null) {
        portletRegistry = ((PortletContainer) containerServletContext
                .getAttribute(AttributeKeys.PORTLET_CONTAINER)).getOptionalContainerServices()
                        .getPortletRegistryService();
    }/* w  ww  .  j  ava  2 s  .co m*/

    for (PortletWindowConfig portlet : portlets) {
        String contextPath = portlet.getContextPath();
        String applicationName = contextPath;
        if (applicationName.length() > 0) {
            applicationName = applicationName.substring(1);
        }
        PortletApplicationDefinition portletAppDD = null;
        try {
            portletAppDD = portletRegistry.getPortletApplication(applicationName);
            List<? extends PortletDefinition> portletDDs = portletAppDD.getPortlets();
            List<QName> aliases = getAllAliases(eventName, portletAppDD);
            for (PortletDefinition portletDD : portletDDs) {
                List<? extends EventDefinitionReference> processingEvents = portletDD
                        .getSupportedProcessingEvents();
                if (isEventSupported(processingEvents, eventName, portletAppDD.getDefaultNamespace())) {
                    if (portletDD.getPortletName().equals(portlet.getPortletName())) {
                        resultSet.add(portlet.getId());
                    }
                } else {

                    if (processingEvents != null) {
                        for (EventDefinitionReference ref : processingEvents) {
                            QName name = ref.getQualifiedName(portletAppDD.getDefaultNamespace());
                            if (name == null) {
                                continue;
                            }
                            // add also grouped portlets, that ends with "."
                            if (name.toString().endsWith(".")
                                    && eventName.toString().startsWith(name.toString())
                                    && portletDD.getPortletName().equals(portlet.getPortletName())) {
                                resultSet.add(portlet.getId());
                            }
                            // also look for alias names:
                            if (aliases != null) {
                                for (QName alias : aliases) {
                                    if (alias.toString().equals(name.toString())
                                            && portletDD.getPortletName().equals(portlet.getPortletName())) {
                                        resultSet.add(portlet.getId());
                                    }
                                }
                            }
                            // also look for default namespaced events
                            if (name.getNamespaceURI() == null || name.getNamespaceURI().equals("")) {
                                String defaultNamespace = portletAppDD.getDefaultNamespace();
                                QName qname = new QName(defaultNamespace, name.getLocalPart());
                                if (eventName.toString().equals(qname.toString())
                                        && portletDD.getPortletName().equals(portlet.getPortletName())) {
                                    resultSet.add(portlet.getId());
                                }
                            }
                        }
                    }
                }
            }
        } catch (PortletContainerException e) {
            LOG.warn(e);
        }
    }

    // make list
    for (String name : resultSet) {
        resultList.add(name);
    }
    return resultList;
}

From source file:org.apache.ofbiz.base.util.UtilHttp.java

/**
 * Create a map from a ServletContext object
 * @return The resulting Map//w w  w. j a  v a 2s  .  c om
 */
public static Map<String, Object> getServletContextMap(HttpServletRequest request,
        Set<? extends String> namesToSkip) {
    Map<String, Object> servletCtxMap = new HashMap<String, Object>();

    // look at all servlet context attributes
    ServletContext servletContext = (ServletContext) request.getAttribute("servletContext");
    Enumeration<String> applicationAttrNames = UtilGenerics.cast(servletContext.getAttributeNames());
    while (applicationAttrNames.hasMoreElements()) {
        String attrName = applicationAttrNames.nextElement();
        if (namesToSkip != null && namesToSkip.contains(attrName))
            continue;

        Object attrValue = servletContext.getAttribute(attrName);
        servletCtxMap.put(attrName, attrValue);
    }

    if (Debug.verboseOn()) {
        Debug.logVerbose("Made ServletContext Attribute Map with [" + servletCtxMap.size() + "] Entries",
                module);
        Debug.logVerbose("ServletContext Attribute Map Entries: " + System.getProperty("line.separator")
                + UtilMisc.printMap(servletCtxMap), module);
    }

    return servletCtxMap;
}

From source file:com.concursive.connect.web.modules.login.auth.session.SessionValidator.java

/**
 * Follow the current session validation schema and determine if there is a
 * valid session for the user. If there is a valid session, return the
 * <code>User</code> associated with that session, otherwise, return
 * <i>null</i>./*  w ww  .j a v a  2  s .  c  om*/
 *
 * @param request -
 *                The servlet request as provided by the
 *                <code>ControllerServlet</code>.
 * @return A valid <code>User</code> upon successful validation.<br>
 *         <code>Null</code> upon validation failure
 */
public User validateSession(ServletContext context, HttpServletRequest request, HttpServletResponse response) {
    User thisUser = (User) request.getSession(false).getAttribute(Constants.SESSION_USER);
    LOG.debug("Has user session: " + (thisUser != null));
    if (thisUser == null || !thisUser.isLoggedIn()) {
        LOG.debug("Checking for cookie...");
        // Check cookie for session info and generate a logged in user
        String guid = CookieUtils.getCookieValue(request, Constants.COOKIE_USER_GUID);
        if (guid == null) {
            LOG.debug("No cookie found.");
            return (thisUser == null ? null : thisUser);
        }
        LOG.debug("Cookie found with guid: " + guid);
        // Retrieve prefs to see if user with guid exists
        ApplicationPrefs prefs = (ApplicationPrefs) context.getAttribute(Constants.APPLICATION_PREFS);
        // Connection info
        ConnectionElement ce = new ConnectionElement();
        ce.setDriver(prefs.get("SITE.DRIVER"));
        ce.setUrl(prefs.get("SITE.URL"));
        ce.setUsername(prefs.get("SITE.USER"));
        ce.setPassword(prefs.get("SITE.PASSWORD"));
        ConnectionPool sqlDriver = (ConnectionPool) context.getAttribute(Constants.CONNECTION_POOL);
        Connection db = null;
        try {
            db = sqlDriver.getConnection(ce);
            // Load the user record from the guid
            thisUser = UserUtils.loadUserFromGuid(db, guid);
            if (thisUser != null) {
                // Track the login
                thisUser.updateLogin(db, request, prefs, null);
                thisUser.setBrowserType(request.getHeader("USER-AGENT"));
                // Apply defaults
                UserUtils.createLoggedInUser(thisUser, db, prefs, context);
                // Extend the cookie
                Cookie userCookie = new Cookie(Constants.COOKIE_USER_GUID, UserUtils.generateGuid(thisUser));
                userCookie.setPath("/");
                // 14 day cookie
                userCookie.setMaxAge(14 * 24 * 60 * 60);
                response.addCookie(userCookie);
            }
        } catch (Exception e) {
            thisUser = null;
            e.printStackTrace();
        } finally {
            if (db != null) {
                sqlDriver.free(db);
            }
        }
        // Add to session
        request.getSession().setAttribute(Constants.SESSION_USER, thisUser);
        request.getSession().setAttribute(Constants.SESSION_CONNECTION_ELEMENT, ce);
    }
    return thisUser;
}

From source file:org.fao.geonet.OgpAppHandler.java

private void fillCaches(final ServiceContext context) {
    final Format formatService = context.getBean(Format.class); // this will initialize the formatter

    Thread fillCaches = new Thread(new Runnable() {
        @Override/* w  ww.j a  va  2 s .  c  om*/
        public void run() {
            final ServletContext servletContext = context.getServlet().getServletContext();
            context.setAsThreadLocal();
            ApplicationContextHolder.set(_applicationContext);
            GeonetWro4jFilter filter = (GeonetWro4jFilter) servletContext
                    .getAttribute(GeonetWro4jFilter.GEONET_WRO4J_FILTER_KEY);

            @SuppressWarnings("unchecked")
            List<String> wro4jUrls = _applicationContext.getBean("wro4jUrlsToInitialize", List.class);

            for (String wro4jUrl : wro4jUrls) {
                Log.info(Geonet.GEONETWORK, "Initializing the WRO4J group: " + wro4jUrl + " cache");
                final MockHttpServletRequest servletRequest = new MockHttpServletRequest(servletContext, "GET",
                        "/static/" + wro4jUrl);
                final MockHttpServletResponse response = new MockHttpServletResponse();
                try {
                    filter.doFilter(servletRequest, response, new MockFilterChain());
                } catch (Throwable t) {
                    Log.info(Geonet.GEONETWORK,
                            "Error while initializing the WRO4J group: " + wro4jUrl + " cache", t);
                }
            }

            final Page<Metadata> metadatas = _applicationContext.getBean(MetadataRepository.class)
                    .findAll(new PageRequest(0, 1));
            if (metadatas.getNumberOfElements() > 0) {
                Integer mdId = metadatas.getContent().get(0).getId();
                context.getUserSession().loginAs(
                        new User().setName("admin").setProfile(Profile.Administrator).setUsername("admin"));
                @SuppressWarnings("unchecked")
                List<String> formattersToInitialize = _applicationContext.getBean("formattersToInitialize",
                        List.class);

                for (String formatterName : formattersToInitialize) {
                    Log.info(Geonet.GEONETWORK, "Initializing the Formatter with id: " + formatterName);
                    final MockHttpServletRequest servletRequest = new MockHttpServletRequest(servletContext);
                    final MockHttpServletResponse response = new MockHttpServletResponse();
                    try {
                        formatService.exec("eng", FormatType.html.toString(), mdId.toString(), null,
                                formatterName, Boolean.TRUE.toString(), false, FormatterWidth._100,
                                new ServletWebRequest(servletRequest, response));
                    } catch (Throwable t) {
                        Log.info(Geonet.GEONETWORK,
                                "Error while initializing the Formatter with id: " + formatterName, t);
                    }
                }
            }
        }
    });
    fillCaches.setDaemon(true);
    fillCaches.setName("Fill Caches Thread");
    fillCaches.setPriority(Thread.MIN_PRIORITY);
    fillCaches.start();
}

From source file:com.tremolosecurity.proxy.auth.PasswordReset.java

@Override
public void init(ServletContext ctx, HashMap<String, Attribute> init) {
    this.cfgMgr = (ConfigManager) ctx.getAttribute(ProxyConstants.TREMOLO_CONFIG);

    this.enabled = Boolean.parseBoolean(init.get("enabled").getValues().get(0));

    if (this.enabled) {

        this.msgQ = new ArrayDeque<SmtpMessage>();

        StopableThread st = new SendMessageThread(this);
        Thread t = new Thread(st);
        t.start();//from   w w  w . ja  va2  s  . com
        this.cfgMgr.addThread(st);

        String driver = init.get("driver").getValues().get(0);
        logger.info("Driver : '" + driver + "'");

        String url = init.get("url").getValues().get(0);
        ;
        logger.info("URL : " + url);
        String user = init.get("user").getValues().get(0);
        ;
        logger.info("User : " + user);
        String pwd = init.get("password").getValues().get(0);
        ;
        logger.info("Password : **********");

        int maxCons = Integer.parseInt(init.get("maxCons").getValues().get(0));
        logger.info("Max Cons : " + maxCons);
        int maxIdleCons = Integer.parseInt(init.get("maxIdleCons").getValues().get(0));
        logger.info("maxIdleCons : " + maxIdleCons);

        String dialect = init.get("dialect").getValues().get(0);
        logger.info("Hibernate Dialect : '" + dialect + "'");

        String validationQuery = init.get("validationQuery").getValues().get(0);
        logger.info("Validation Query : '" + validationQuery + "'");

        this.initializeHibernate(driver, user, pwd, url, dialect, maxCons, maxIdleCons, validationQuery);

        this.passwordResetURL = init.get("passwordResetURI").getValues().get(0);
        this.minValidKey = Integer.parseInt(init.get("minValidKey").getValues().get(0));

        StopableThread tokenClean = new TokenCleanup(this.sessionFactory, this.minValidKey);
        t = new Thread(tokenClean);

        this.cfgMgr.addThread(tokenClean);
        t.start();

        this.smtpServer = init.get("smtpHost").getValues().get(0);
        logger.info("SMTP Server : '" + this.smtpServer + "'");
        this.smtpPort = Integer.parseInt(init.get("smtpPort").getValues().get(0));
        logger.info("SMTP Port : '" + this.smtpPort + "'");
        this.smtpUser = init.get("smtpUser").getValues().get(0);
        logger.info("SMTP User : '" + this.smtpUser + "'");
        this.smtpPassword = init.get("smtpPassword").getValues().get(0);
        logger.info("SMTP Password : '************'");
        this.smtpSubject = init.get("smtpSubject").getValues().get(0);
        logger.info("SMTP Subject : '" + this.smtpSubject + "'");
        this.smtpMsg = init.get("smtpMsg").getValues().get(0);

        this.smtpFrom = init.get("smtpFrom").getValues().get(0);
        logger.info("SMTP From : '" + this.smtpFrom + "'");
        this.smtpTLS = Boolean.parseBoolean(init.get("smtpTLS").getValues().get(0));
        logger.info("SMTP TLS : '" + this.smtpTLS + "'");
        if (init.get("smtpSocksHost") != null && init.get("smtpSocksHost").getValues().size() > 0
                && !init.get("smtpSocksHost").getValues().get(0).isEmpty()) {
            logger.info("SMTP SOCKS : 'true'");
            this.useSocks = true;
            this.socksHost = init.get("smtpSocksHost").getValues().get(0);
            logger.info("SMTP SOCKS Host : '" + this.socksHost + "'");
            this.socksPort = Integer.parseInt(init.get("smtpSocksPort").getValues().get(0));
            logger.info("SMTP SOCKS Port : '" + this.socksPort + "'");
        } else {
            logger.info("SMTP SOCKS : 'false'");
            this.useSocks = false;
        }

        if (init.get("smtpLocalhost") != null && init.get("smtpLocalhost").getValues().size() > 0) {
            this.smtpLocalhost = init.get("smtpLocalhost").getValues().get(0);
            logger.info("SMTP Localhost : '" + this.smtpLocalhost + "'");
        } else {
            this.smtpLocalhost = null;
        }

    }

}

From source file:org.exoplatform.frameworks.jcr.command.web.GenericWebAppContext.java

public GenericWebAppContext(ServletContext servletContext, HttpServletRequest request,
        HttpServletResponse response, SessionProvider sessionProvider, ManageableRepository repository) {

    initialize(servletContext, request, response);

    this.sessionProvider = sessionProvider;
    this.repository = repository;

    // log.info("WEb context ---------------");
    // initialize context with all props
    Enumeration en = servletContext.getInitParameterNames();
    while (en.hasMoreElements()) {
        String name = (String) en.nextElement();
        put(name, servletContext.getInitParameter(name));
        LOG.debug("ServletContext init param: " + name + "=" + servletContext.getInitParameter(name));
    }/*w  w  w  .j ava  2 s .  co  m*/

    en = servletContext.getAttributeNames();
    while (en.hasMoreElements()) {
        String name = (String) en.nextElement();
        put(name, servletContext.getAttribute(name));
        LOG.debug("ServletContext: " + name + "=" + servletContext.getAttribute(name));
    }

    HttpSession session = request.getSession(false);
    if (session != null) {
        en = session.getAttributeNames();
        while (en.hasMoreElements()) {
            String name = (String) en.nextElement();
            put(name, session.getAttribute(name));
            LOG.debug("Session: " + name + "=" + session.getAttribute(name));
        }
    }

    en = request.getAttributeNames();
    while (en.hasMoreElements()) {
        String name = (String) en.nextElement();
        put(name, request.getAttribute(name));
    }

    en = request.getParameterNames();
    while (en.hasMoreElements()) {
        String name = (String) en.nextElement();
        put(name, request.getParameter(name));
        LOG.debug("Request: " + name + "=" + request.getParameter(name));
    }
}

From source file:org.entando.entando.plugins.jpcomponentinstaller.aps.system.services.installer.DefaultComponentInstaller.java

private ApplicationContext loadContext(String[] configLocations, URLClassLoader cl, String contextDisplayName,
        Properties properties) throws Exception {
    ServletContext servletContext = ((ConfigurableWebApplicationContext) this._applicationContext)
            .getServletContext();/*from   w  ww. j a  v a  2  s.  c  om*/
    //if plugin's classes have been loaded we can go on
    List<ClassPathXmlApplicationContext> ctxList = (List<ClassPathXmlApplicationContext>) servletContext
            .getAttribute("pluginsContextsList");
    if (ctxList == null) {
        ctxList = new ArrayList<ClassPathXmlApplicationContext>();
        servletContext.setAttribute("pluginsContextsList", ctxList);
    }
    ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
    ClassPathXmlApplicationContext newContext = null;
    try {
        //create a new spring context with the classloader and the paths defined as parameter in pluginsInstallerContext.xml.
        //The new context is given the default webapplication context as its parent  
        Thread.currentThread().setContextClassLoader(cl);
        newContext = new ClassPathXmlApplicationContext();
        //ClassPathXmlApplicationContext newContext = new ClassPathXmlApplicationContext(configLocations, applicationContext);    
        PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
        configurer.setProperties(properties);
        newContext.addBeanFactoryPostProcessor(configurer);
        newContext.setClassLoader(cl);
        newContext.setParent(this._applicationContext);
        String[] configLocs = new String[] { "classpath:spring/restServerConfig.xml",
                "classpath:spring/baseSystemConfig.xml" };
        newContext.setConfigLocations(configLocs);
        newContext.refresh();
        BaseConfigManager baseConfigManager = (BaseConfigManager) ((ConfigurableWebApplicationContext) this._applicationContext)
                .getBean("BaseConfigManager");
        baseConfigManager.init();
        newContext.setConfigLocations(configLocations);
        newContext.refresh();
        newContext.setDisplayName(contextDisplayName);
        ClassPathXmlApplicationContext currentCtx = (ClassPathXmlApplicationContext) this
                .getStoredContext(contextDisplayName);
        if (currentCtx != null) {
            currentCtx.close();
            ctxList.remove(currentCtx);
        }
        ctxList.add(newContext);

    } catch (Exception e) {
        _logger.error("Unexpected error loading application context: " + e.getMessage());
        e.printStackTrace();
        throw e;
    } finally {
        Thread.currentThread().setContextClassLoader(currentClassLoader);
    }
    return newContext;
}

From source file:com.redsqirl.auth.UserInfoBean.java

/**
 * Method that will clean up the session objects once the user has finished with it.
 *//*from   w ww .java 2  s .com*/
public void invalidateSession() {
    try {
        if (userName != null && checkPassword) {
            FacesContext fCtx = FacesContext.getCurrentInstance();
            ServletContext sc = (ServletContext) fCtx.getExternalContext().getContext();
            Map<String, HttpSession> sessionLoginMap = (Map<String, HttpSession>) sc
                    .getAttribute("sessionLoginMap");
            invalidateSession(sessionLoginMap.get(userName));
        }
        checkPassword = false;

    } catch (Exception e) {
        logger.error(e, e);
    }
}

From source file:com.rapid.server.RapidServletContextListener.java

public static int loadApplications(ServletContext servletContext) throws JAXBException, JSONException,
        InstantiationException, IllegalAccessException, ClassNotFoundException, IllegalArgumentException,
        SecurityException, InvocationTargetException, NoSuchMethodException, IOException,
        ParserConfigurationException, SAXException, TransformerFactoryConfigurationError, TransformerException,
        RapidLoadingException, XPathExpressionException {

    // get any existing applications
    Applications applications = (Applications) servletContext.getAttribute("applications");

    // check we got some
    if (applications != null) {
        // loop the application ids
        for (String appId : applications.getIds()) {
            // loop the versions
            for (String version : applications.getVersions(appId).keySet()) {
                // get the version
                Application application = applications.get(appId, version);
                // close it
                application.close(servletContext);
            }/*from   ww  w  .  j  a va2s .  c  o m*/
        }
    }

    // make a new set of applications
    applications = new Applications();

    File applicationFolderRoot = new File(servletContext.getRealPath("/WEB-INF/applications/"));

    for (File applicationFolder : applicationFolderRoot.listFiles()) {

        if (applicationFolder.isDirectory()) {

            // get the list of files in this folder - should be all version folders
            File[] applicationFolders = applicationFolder.listFiles();

            // assume we didn't need to version
            boolean versionCreated = false;

            // if we got some
            if (applicationFolders != null) {

                try {

                    // look for an application file in the root of the application folder
                    File applicationFile = new File(applicationFolder.getAbsoluteFile() + "/application.xml");

                    // set a version for this app (just in case it doesn't have one)
                    String version = "1";

                    // if it exists here, it's in the wrong (non-versioned) place!
                    if (applicationFile.exists()) {

                        // create a file for the new version folder
                        File versionFolder = new File(applicationFolder + "/" + version);
                        // keep appending the version if the folder already exists
                        while (versionFolder.exists()) {
                            // append .1 to the version 1, 1.1, 1.1.1, etc
                            version += ".1";
                            versionFolder = new File(applicationFolder + "/" + version);
                        }

                        // make the dir
                        versionFolder.mkdir();
                        _logger.info(versionFolder + " created");
                        // copy in all files and pages folder
                        for (File file : applicationFolders) {
                            // copy all files and the pages folder
                            if (!file.isDirectory() || (file.isDirectory() && "pages".equals(file.getName()))) {
                                // make a desintation file
                                File destFile = new File(versionFolder + "/" + file.getName());
                                // this is not a version folder itself, copy it to the new version folder
                                Files.copyFolder(file, destFile);
                                // delete the file or folder
                                Files.deleteRecurring(file);
                                // log
                                _logger.info(file + " moved to " + destFile);
                            }

                        }
                        // record that we created a version
                        versionCreated = true;

                    } // application.xml non-versioned check

                    try {

                        // get the version folders
                        File[] versionFolders = applicationFolder.listFiles();
                        // get a marshaller
                        Marshaller marshaller = RapidHttpServlet.getMarshaller();

                        // loop them
                        for (File versionFolder : versionFolders) {
                            // check is folder
                            if (versionFolder.isDirectory()) {
                                // look for an application file in the version folder
                                applicationFile = new File(versionFolder + "/application.xml");
                                // if it exists
                                if (applicationFile.exists()) {

                                    // placeholder for the application we're going to version up or just load
                                    Application application = null;

                                    // if we had to create a version for it
                                    if (versionCreated) {

                                        // load without resources
                                        application = Application.load(servletContext, applicationFile, false);

                                        // set the new version
                                        application.setVersion(version);

                                        // re-initialise it without resources (for the security adapter)
                                        application.initialise(servletContext, false);

                                        // marshal the updated application object to it's file
                                        FileOutputStream fos = new FileOutputStream(applicationFile);
                                        marshaller.marshal(application, fos);
                                        fos.close();

                                        // get a dir for the pages
                                        File pageDir = new File(versionFolder + "/pages");
                                        // check it exists
                                        if (pageDir.exists()) {
                                            // loop the pages files
                                            for (File pageFile : pageDir.listFiles()) {
                                                // read the contents of the file
                                                String pageContent = Strings.getString(pageFile);
                                                // replace all old file references
                                                pageContent = pageContent
                                                        .replace("/" + application.getId() + "/",
                                                                "/" + application.getId() + "/"
                                                                        + application.getVersion() + "/")
                                                        .replace("~?a=" + application.getId() + "&amp;",
                                                                "~?a=" + application.getId() + "&amp;"
                                                                        + application.getVersion() + "&amp;");
                                                // create a file writer
                                                FileWriter fs = new FileWriter(pageFile);
                                                // save the changes
                                                fs.write(pageContent);
                                                // close the writer
                                                fs.close();
                                                _logger.info(pageFile + " updated with new references");
                                            }
                                        }
                                        // make a dir for it's web resources
                                        File webDir = new File(application.getWebFolder(servletContext));
                                        webDir.mkdir();
                                        _logger.info(webDir + " created");
                                        // loop all the files in the parent
                                        for (File file : webDir.getParentFile().listFiles()) {
                                            // check not dir
                                            if (!file.isDirectory()) {
                                                // create a destination file for the new location
                                                File destFile = new File(webDir + "/" + file.getName());
                                                // copy it to the new destination
                                                Files.copyFile(file, destFile);
                                                // delete the file or folder
                                                file.delete();
                                                _logger.info(file + " moved to " + destFile);
                                            }

                                        }

                                    }

                                    // (re)load the application
                                    application = Application.load(servletContext, applicationFile);

                                    // put it in our collection
                                    applications.put(application);

                                }

                            } // folder check

                        } // version folder loop      

                    } catch (Exception ex) {

                        // log the exception
                        _logger.error(ex);

                    } // version load catch

                } catch (Exception ex) {

                    // log it
                    _logger.error("Error creating version folder for app " + applicationFolder, ex);

                } // version folder creation catch               

            } // application folders check

        } // application folder check

    } // application folder loop

    // store them in the context
    servletContext.setAttribute("applications", applications);

    _logger.info(applications.size() + " applications loaded");

    return applications.size();

}