List of usage examples for org.springframework.web.util WebUtils getTempDir
public static File getTempDir(ServletContext servletContext)
From source file:net.mojodna.sprout.support.SpringBodyTagSupport.java
/** * Return the temporary directory for the current web application, * as provided by the servlet container. * @return the File representing the temporary directory *//*from w ww. j av a 2s. c o m*/ protected final File getTempDir() { return WebUtils.getTempDir(getServletContext()); }
From source file:org.jasig.portlet.blackboardvcportlet.service.impl.SessionServiceImpl.java
@Override public void setServletContext(ServletContext servletContext) { this.tempDir = WebUtils.getTempDir(servletContext); }
From source file:com.ms.commons.summer.web.multipart.CommonsMultipartEngancedResolver.java
public void setServletContext(ServletContext servletContext) { if (!isUploadTempDirSpecified()) { getFileItemFactory().setRepository(WebUtils.getTempDir(servletContext)); } }
From source file:com.bstek.dorado.web.loader.DoradoLoader.java
public synchronized void preload(ServletContext servletContext, boolean processOriginContextConfigLocation) throws Exception { if (preloaded) { throw new IllegalStateException("Dorado base configurations already loaded."); }// w w w . jav a 2s . co m preloaded = true; // ? ConsoleUtils.outputLoadingInfo("Initializing " + DoradoAbout.getProductTitle() + " engine..."); ConsoleUtils.outputLoadingInfo("[Vendor: " + DoradoAbout.getVendor() + "]"); ConfigureStore configureStore = Configure.getStore(); doradoHome = System.getenv("DORADO_HOME"); // ?DoradoHome String intParam; intParam = servletContext.getInitParameter("doradoHome"); if (intParam != null) { doradoHome = intParam; } if (doradoHome == null) { doradoHome = DEFAULT_DORADO_HOME; } configureStore.set(HOME_PROPERTY, doradoHome); ConsoleUtils.outputLoadingInfo("[Home: " + StringUtils.defaultString(doradoHome, "<not assigned>") + "]"); // ResourceLoader ResourceLoader resourceLoader = new ServletContextResourceLoader(servletContext) { @Override public Resource getResource(String resourceLocation) { if (resourceLocation != null && resourceLocation.startsWith(HOME_LOCATION_PREFIX)) { resourceLocation = ResourceUtils.concatPath(doradoHome, resourceLocation.substring(HOME_LOCATION_PREFIX_LEN)); } return super.getResource(resourceLocation); } }; String runMode = null; if (StringUtils.isNotEmpty(doradoHome)) { String configureLocation = HOME_LOCATION_PREFIX + "configure.properties"; loadConfigureProperties(configureStore, resourceLoader, configureLocation, false); } runMode = configureStore.getString("core.runMode"); if (StringUtils.isNotEmpty(runMode)) { loadConfigureProperties(configureStore, resourceLoader, CORE_PROPERTIES_LOCATION_PREFIX + "configure-" + runMode + ".properties", true); if (StringUtils.isNotEmpty(doradoHome)) { loadConfigureProperties(configureStore, resourceLoader, HOME_LOCATION_PREFIX + "configure-" + runMode + ".properties", true); } } ConsoleUtils.outputConfigureItem("core.runMode"); ConsoleUtils.outputConfigureItem("core.addonLoadMode"); File tempDir; String tempDirPath = configureStore.getString("core.tempDir"); if (StringUtils.isNotBlank(tempDirPath)) { tempDir = new File(tempDirPath); } else { tempDir = new File(WebUtils.getTempDir(servletContext), ".dorado"); } boolean supportsTempFile = configureStore.getBoolean("core.supportsTempFile"); TempFileUtils.setSupportsTempFile(supportsTempFile); if (supportsTempFile) { if ((tempDir.exists() && tempDir.isDirectory()) || tempDir.mkdir()) { TempFileUtils.setTempDir(tempDir); } ConsoleUtils.outputLoadingInfo("[TempDir: " + TempFileUtils.getTempDir().getPath() + "]"); } else { ConsoleUtils.outputLoadingInfo("Temp file is forbidden."); } // File storeDir; String storeDirSettring = configureStore.getString("core.storeDir"); if (StringUtils.isNotEmpty(storeDirSettring)) { storeDir = new File(storeDirSettring); File testFile = new File(storeDir, ".test"); if (!testFile.mkdirs()) { throw new IllegalStateException( "Store directory [" + storeDir.getAbsolutePath() + "] is not writable in actually."); } testFile.delete(); } else { storeDir = new File(tempDir, "dorado-store"); configureStore.set("core.storeDir", storeDir.getAbsolutePath()); } ConsoleUtils.outputConfigureItem("core.storeDir"); // gothrough packages String addonLoadMode = Configure.getString("core.addonLoadMode"); String[] enabledAddons = StringUtils.split(Configure.getString("core.enabledAddons"), ",; \n\r"); String[] disabledAddon = StringUtils.split(Configure.getString("core.disabledAddon"), ",; \n\r"); Collection<PackageInfo> packageInfos = PackageManager.getPackageInfoMap().values(); int addonNumber = 0; for (PackageInfo packageInfo : packageInfos) { String packageName = packageInfo.getName(); if (packageName.equals("dorado-core")) { continue; } if (addonNumber > 9999) { packageInfo.setEnabled(false); } else if (StringUtils.isEmpty(addonLoadMode) || "positive".equals(addonLoadMode)) { packageInfo.setEnabled(!ArrayUtils.contains(disabledAddon, packageName)); } else { // addonLoadMode == negative packageInfo.setEnabled(ArrayUtils.contains(enabledAddons, packageName)); } if (packageInfo.isEnabled()) { addonNumber++; } } // print packages int i = 0; for (PackageInfo packageInfo : packageInfos) { ConsoleUtils.outputLoadingInfo( StringUtils.rightPad(String.valueOf(++i) + '.', 4) + "Package [" + packageInfo.getName() + " - " + StringUtils.defaultIfBlank(packageInfo.getVersion(), "<Unknown Version>") + "] found." + ((packageInfo.isEnabled() ? "" : " #DISABLED# "))); } // load packages for (PackageInfo packageInfo : packageInfos) { if (!packageInfo.isEnabled()) { pushLocations(contextLocations, packageInfo.getComponentLocations()); continue; } PackageListener packageListener = packageInfo.getListener(); if (packageListener != null) { packageListener.beforeLoadPackage(packageInfo, resourceLoader); } PackageConfigurer packageConfigurer = packageInfo.getConfigurer(); if (StringUtils.isNotEmpty(packageInfo.getPropertiesLocations())) { for (String location : org.springframework.util.StringUtils.tokenizeToStringArray( packageInfo.getPropertiesLocations(), ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS)) { loadConfigureProperties(configureStore, resourceLoader, location, false); } } String[] locations; if (packageConfigurer != null) { locations = packageConfigurer.getPropertiesConfigLocations(resourceLoader); if (locations != null) { for (String location : locations) { loadConfigureProperties(configureStore, resourceLoader, location, false); } } } // ?Spring? pushLocations(contextLocations, packageInfo.getContextLocations()); if (packageConfigurer != null) { locations = packageConfigurer.getContextConfigLocations(resourceLoader); if (locations != null) { for (String location : locations) { pushLocation(contextLocations, location); } } } pushLocations(servletContextLocations, packageInfo.getServletContextLocations()); if (packageConfigurer != null) { locations = packageConfigurer.getServletContextConfigLocations(resourceLoader); if (locations != null) { for (String location : locations) { pushLocation(servletContextLocations, location); } } } packageInfo.setLoaded(true); } // ?dorado-homepropertiesaddon if (StringUtils.isNotEmpty(doradoHome)) { String configureLocation = HOME_LOCATION_PREFIX + "configure.properties"; loadConfigureProperties(configureStore, resourceLoader, configureLocation, true); if (StringUtils.isNotEmpty(runMode)) { loadConfigureProperties(configureStore, resourceLoader, CORE_PROPERTIES_LOCATION_PREFIX + "configure-" + runMode + ".properties", true); loadConfigureProperties(configureStore, resourceLoader, HOME_LOCATION_PREFIX + "configure-" + runMode + ".properties", true); } } Resource resource; // context if (processOriginContextConfigLocation) { intParam = servletContext.getInitParameter(CONTEXT_CONFIG_LOCATION); if (intParam != null) { pushLocations(contextLocations, intParam); } } resource = resourceLoader.getResource(HOME_CONTEXT_XML); if (resource.exists()) { pushLocations(contextLocations, HOME_CONTEXT_XML); } if (StringUtils.isNotEmpty(runMode)) { String extHomeContext = HOME_CONTEXT_PREFIX + '-' + runMode + CONTEXT_FILE_EXT; resource = resourceLoader.getResource(extHomeContext); if (resource.exists()) { pushLocations(contextLocations, extHomeContext); } } // servlet-context intParam = servletContext.getInitParameter(SERVLET_CONTEXT_CONFIG_LOCATION); if (intParam != null) { pushLocations(servletContextLocations, intParam); } resource = resourceLoader.getResource(HOME_SERVLET_CONTEXT_XML); if (resource.exists()) { pushLocations(servletContextLocations, HOME_SERVLET_CONTEXT_XML); } if (StringUtils.isNotEmpty(runMode)) { String extHomeContext = HOME_SERVLET_CONTEXT_PREFIX + '-' + runMode + CONTEXT_FILE_EXT; resource = resourceLoader.getResource(extHomeContext); if (resource.exists()) { pushLocations(servletContextLocations, extHomeContext); } } ConsoleUtils.outputConfigureItem(RESOURCE_LOADER_PROPERTY); ConsoleUtils.outputConfigureItem(BYTE_CODE_PROVIDER_PROPERTY); String contextLocationsFromProperties = configureStore.getString(CONTEXT_CONFIG_PROPERTY); if (contextLocationsFromProperties != null) { pushLocations(contextLocations, contextLocationsFromProperties); } configureStore.set(CONTEXT_CONFIG_PROPERTY, StringUtils.join(getRealResourcesPath(contextLocations), ';')); ConsoleUtils.outputConfigureItem(CONTEXT_CONFIG_PROPERTY); String serlvetContextLocationsFromProperties = configureStore.getString(SERVLET_CONTEXT_CONFIG_PROPERTY); if (serlvetContextLocationsFromProperties != null) { pushLocations(servletContextLocations, serlvetContextLocationsFromProperties); } configureStore.set(SERVLET_CONTEXT_CONFIG_PROPERTY, StringUtils.join(getRealResourcesPath(servletContextLocations), ';')); ConsoleUtils.outputConfigureItem(SERVLET_CONTEXT_CONFIG_PROPERTY); // ?WebContext DoradoContext context = DoradoContext.init(servletContext, false); Context.setFailSafeContext(context); }
From source file:org.springframework.web.multipart.commons.CommonsMultipartResolver.java
@Override public void setServletContext(ServletContext servletContext) { if (!isUploadTempDirSpecified()) { getFileItemFactory().setRepository(WebUtils.getTempDir(servletContext)); }//w w w . ja va 2s. c o m }
From source file:org.springframework.web.multipart.cos.CosMultipartResolver.java
/** * Constructor for standalone usage. Determines the servlet container's * temporary directory via the given ServletContext. * @param servletContext the ServletContext to use */// ww w . jav a 2 s . c o m public CosMultipartResolver(ServletContext servletContext) { this.uploadTempDir = WebUtils.getTempDir(servletContext); }
From source file:org.springframework.web.multipart.cos.CosMultipartResolver.java
public void setServletContext(ServletContext servletContext) { if (this.uploadTempDir == null) { this.uploadTempDir = WebUtils.getTempDir(servletContext); }/*from w w w .ja v a 2 s. c om*/ }
From source file:ubic.gemma.web.util.upload.CommonsMultipartMonitoredResolver.java
@Override public void setServletContext(ServletContext servletContext) { if (this.uploadTempDir == null) { this.uploadTempDir = WebUtils.getTempDir(servletContext); }/*from w ww.j av a2 s.c o m*/ }