List of usage examples for javax.servlet ServletContextEvent getServletContext
public ServletContext getServletContext()
From source file:org.musicrecital.webapp.listener.UserCounterListener.java
/** * Initialize the context//w w w .j a v a2 s .com * * @param sce the event */ public synchronized void contextInitialized(ServletContextEvent sce) { servletContext = sce.getServletContext(); servletContext.setAttribute((COUNT_KEY), Integer.toString(counter)); }
From source file:org.parancoe.web.PopulateInitialDataContextListener.java
@Override public void contextInitialized(ServletContextEvent evt) { ctx = (ApplicationContext) evt.getServletContext() .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); Set<Class> fixtureClasses = new LinkedHashSet<Class>(getFixtureClasses()); if (fixtureClasses.isEmpty()) { log.info("Skipping initial data population (no models)"); return;/*from ww w .j a va 2s . c om*/ } Map<Class, List> fixtures = YamlFixtureHelper.loadFixturesFromResource("initialData/", fixtureClasses); log.info("Populating initial data for models..."); SessionFactory sessionFactory = (SessionFactory) ctx.getBean("sessionFactory"); Session session = sessionFactory.openSession(); session.beginTransaction(); //Attach transaction to thread TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session)); TransactionSynchronizationManager.initSynchronization(); try { for (Class clazz : fixtures.keySet()) { List modelFixtures = fixtures.get(clazz); if (modelFixtures.isEmpty()) { log.warn("No data for {}, did you created the fixture file?", YamlFixtureHelper.getModelName(clazz)); continue; } populateTableForModel(clazz, modelFixtures); } fixtures.clear(); log.info("Populating initial data for models done!"); session.getTransaction().commit(); if (session.isOpen()) { session.close(); } } catch (Exception e) { log.error("Error while populating initial data for models {}", e.getMessage(), e); log.debug("Rolling back the populating database transaction"); session.getTransaction().rollback(); } finally { try { if (session.isOpen()) { session.close(); } } catch (Exception e) { /*do nothing*/ } TransactionSynchronizationManager.unbindResource(sessionFactory); TransactionSynchronizationManager.clearSynchronization(); } }
From source file:edu.cornell.mannlib.vitro.webapp.servlet.setup.ContentModelSetup.java
@Override public void contextInitialized(ServletContextEvent sce) { ServletContext ctx = sce.getServletContext(); StartupStatus ss = StartupStatus.getBean(ctx); long begin = System.currentTimeMillis(); setUpJenaDataSource(ctx);//from w w w .j a v a2 s. c om ss.info(this, secondsSince(begin) + " seconds to set up models and DAO factories"); }
From source file:edu.northwestern.bioinformatics.studycalendar.web.LegacyUserProvisioningRecordExporter.java
public void contextInitialized(ServletContextEvent sce) { servletContext = sce.getServletContext(); if (!isExporterEnabled() || !isDataPresent()) { return;/*from w ww . jav a2 s . c o m*/ } String targetPath = exportRecords(); wipeTables(); log.info("Welcome to PSC 2.8.1+. Your old user provisioning data has been exported to {}.", targetPath); }
From source file:org.opennms.web.osgi.FrameworkStartupContextListener.java
@Override public void contextDestroyed(ServletContextEvent event) { try {/* w ww . j a v a2 s . c om*/ m_service.destroy(); // Clean up the old Karaf temp directory FileUtils.deleteDirectory(new File(event.getServletContext().getRealPath("/") + File.separator + "WEB-INF" + File.separator + "karaf" + File.separator + "data")); } catch (Exception e) { LogUtils.errorf(this, e, "Could not start up OSGi container: %s", e.getMessage()); } }
From source file:org.apache.chemistry.opencmis.server.impl.CmisRepositoryContextListener.java
public void contextInitialized(ServletContextEvent sce) { // get config file name or use default String configFilename = sce.getServletContext().getInitParameter(CONFIG_INIT_PARAM); if (configFilename == null) { configFilename = CONFIG_FILENAME; }/*from ww w . ja v a 2 s . c o m*/ // create services factory CmisServiceFactory factory = createServiceFactory(configFilename); // set the services factory into the servlet context sce.getServletContext().setAttribute(SERVICES_FACTORY, factory); }
From source file:org.ppwcode.vernacular.value_III.web.RegisterPropertyEditors.java
/** * Register this library in the {@link PropertyEditorManager} * {@link PropertyEditor} lookup path.//w w w . jav a 2 s . co m */ public void contextInitialized(final ServletContextEvent event) { assert preArgumentNotNull(event, "event"); assert pre(event.getServletContext() != null, "event.getServletContext() != null"); String initParameterValue = event.getServletContext().getInitParameter(INIT_PARAMETER_NAME); if (empty(initParameterValue) && LOG.isDebugEnabled()) { LOG.debug("no init parameter \"" + INIT_PARAMETER_NAME + "\" found; no package names added to PropertyEditorManager property editor search path"); } else { LOG.debug("found init parameter \"" + INIT_PARAMETER_NAME + "\": " + initParameterValue); String[] split = initParameterValue.split(SPLIT_PATTERN); for (int i = 0; i < split.length; i++) { String pn = split[i]; pn = pn.trim(); if (!empty(pn)) { LOG.debug("adding package name \"" + pn + "\" to PropertyEditorManager property editor search path"); registerPropertyEditorPackage(pn); } } if (LOG.isDebugEnabled()) { LOG.debug("PropertyEditorManager property editor search path: " + PropertyEditorManager.getEditorSearchPath()); } } }
From source file:org.rhq.enterprise.gui.startup.Configurator.java
/** * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent) */// www . java 2 s . c o m public void contextInitialized(ServletContextEvent sce) { ServletContext ctx = sce.getServletContext(); loadConfig(ctx); loadPreferences(ctx); loadTablePreferences(ctx); loadBuildVersion(ctx); loadJavaLoggingConfiguration(); }
From source file:edu.cornell.mannlib.vitro.webapp.servlet.setup.RunSparqlConstructs.java
public void contextInitialized(ServletContextEvent sce) { try {/*from w ww. j ava 2s . c o m*/ ServletContext ctx = sce.getServletContext(); WebappDaoFactory wadf = ModelAccess.on(ctx).getWebappDaoFactory(); String namespace = (wadf != null && wadf.getDefaultNamespace() != null) ? wadf.getDefaultNamespace() : DEFAULT_DEFAULT_NAMESPACE; OntModel baseOntModel = ModelAccess.on(ctx).getOntModel(FULL_ASSERTIONS); Model anonModel = ModelFactory.createDefaultModel(); Model namedModel = ModelFactory.createDefaultModel(); Set<String> resourcePaths = ctx.getResourcePaths(SPARQL_DIR); for (String path : resourcePaths) { log.debug("Attempting to execute SPARQL at " + path); File file = new File(ctx.getRealPath(path)); try { BufferedReader reader = new BufferedReader(new FileReader(file)); StringBuffer fileContents = new StringBuffer(); String ln; try { while ((ln = reader.readLine()) != null) { fileContents.append(ln).append('\n'); } try { Query q = QueryFactory.create(fileContents.toString(), Syntax.syntaxARQ); QueryExecution qe = QueryExecutionFactory.create(q, baseOntModel); qe.execConstruct(anonModel); } catch (Exception e) { String queryErrMsg = "Unable to execute query at " + path + " :"; log.error(queryErrMsg); System.out.println(queryErrMsg); e.printStackTrace(); } } catch (IOException ioe) { log.error("IO Exception reading " + path + " :"); ioe.printStackTrace(); } } catch (FileNotFoundException fnfe) { log.info(path + " not found. Skipping."); } } namedModel.add(anonModel); for (Iterator<Resource> i = anonModel.listSubjects(); i.hasNext();) { Resource s = i.next(); if (s.isAnon()) { int randomInt = -1; while (randomInt < 0 || baseOntModel.getIndividual(namespace + LOCAL_NAME_PREPEND + randomInt) != null) { randomInt = random.nextInt(Integer.MAX_VALUE); } Resource t = namedModel.createResource(s.getId()); ResourceUtils.renameResource(t, namespace + LOCAL_NAME_PREPEND + randomInt); } } baseOntModel.addSubModel(namedModel); String msg = "Attaching " + namedModel.size() + " statements as a result of SPARQL CONSTRUCTS"; log.info(msg); System.out.println(msg); } catch (Throwable t) { System.out.println("Throwable in listener " + this.getClass().getName()); t.printStackTrace(); log.error(t); } }
From source file:nl.b3p.viewer.components.ComponentRegistryInitializer.java
public void contextInitialized(ServletContextEvent sce) { servletContext = sce.getServletContext(); ComponentRegistryInitializer.registry = new ComponentRegistry(); /* checkout the configuration */ /* this parameter takes precedence over the path param */ crossContextName = servletContext.getInitParameter(PARAM_CROSS_CONTEXT); componentPath = servletContext.getInitParameter(PARAM_PATH); if (componentPath == null) { /* try the deprecated parameter name */ componentPath = servletContext.getInitParameter(PARAM_PATH_OLD); }//from w w w. jav a 2 s . c om if (componentPath == null) { /* use the default - because the cross context param takes precedence * this is never null, but the default at least */ componentPath = DEFAULT_COMPONENT_PATH; } ServletContext pathContext = servletContext; if (crossContextName != null) { log.info("Looking at cross context \"" + crossContextName + "\" for component paths..."); ServletContext crossContext = servletContext.getContext(crossContextName); if (crossContext != null) { pathContext = crossContext; } } registry.setComponentPaths(pathContext, componentPath.split(",")); tryComponentLoading(); }