当前位置: 首页>>代码示例>>Java>>正文


Java ServletContextResource类代码示例

本文整理汇总了Java中org.springframework.web.context.support.ServletContextResource的典型用法代码示例。如果您正苦于以下问题:Java ServletContextResource类的具体用法?Java ServletContextResource怎么用?Java ServletContextResource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ServletContextResource类属于org.springframework.web.context.support包,在下文中一共展示了ServletContextResource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFileTimestamp

import org.springframework.web.context.support.ServletContextResource; //导入依赖的package包/类
/**
 * Return the file timestamp for the given resource.
 * @param resourceUrl the URL of the resource
 * @return the file timestamp in milliseconds, or -1 if not determinable
 */
protected long getFileTimestamp(String resourceUrl) {
	ServletContextResource resource = new ServletContextResource(getServletContext(), resourceUrl);
	try {
		long lastModifiedTime = resource.lastModified();
		if (logger.isDebugEnabled()) {
			logger.debug("Last-modified timestamp of " + resource + " is " + lastModifiedTime);
		}
		return lastModifiedTime;
	}
	catch (IOException ex) {
		logger.warn("Couldn't retrieve last-modified timestamp of [" + resource +
				"] - using ResourceServlet startup time");
		return -1;
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:ResourceServlet.java

示例2: viewResourceLoader

import org.springframework.web.context.support.ServletContextResource; //导入依赖的package包/类
@Bean
public CompositeResourceLoader viewResourceLoader() {
	CompositeResourceLoader compositeResourceLoader = new CompositeResourceLoader();
	compositeResourceLoader.addResourceLoader(new StartsWithMatcher(VIEW_PREFIX_CLASSPATH).withoutPrefix(),
			new ClasspathResourceLoader("/views"));
	try {
		compositeResourceLoader.addResourceLoader(new StartsWithMatcher(VIEW_PREFIX_TEMPLATE),
				new WebAppResourceLoader(new ServletContextResource(servletContext, templateLocation).getFile().getAbsolutePath()));

		compositeResourceLoader.addResourceLoader(new StartsWithMatcher("/WEB-INF").withPrefix(),
				new WebAppResourceLoader(servletContext.getRealPath(".")));
	} catch (IOException e) {
		e.printStackTrace();
	}
	return compositeResourceLoader;
}
 
开发者ID:xiangxik,项目名称:java-platform,代码行数:17,代码来源:ViewConfiguration.java

示例3: createVelocityContext

import org.springframework.web.context.support.ServletContextResource; //导入依赖的package包/类
@Override
protected Context createVelocityContext(Map<String, Object> model,
		HttpServletRequest request, HttpServletResponse response)
		throws Exception {
	ViewToolContext velocityContext = new ViewToolContext(getVelocityEngine(), request, response, getServletContext());
	velocityContext.putAll(model);
	if(getToolboxConfigLocation() != null ||getToolboxConfigResource() != null){
		XmlFactoryConfiguration cfg = new XmlFactoryConfiguration();
		URL cfgUrl;
		if(getToolboxConfigLocation() != null){
			cfgUrl = new ServletContextResource(getServletContext(), getToolboxConfigLocation()).getURL();
			cfg.read(cfgUrl);
		}else if(getToolboxConfigResource() != null){
			cfgUrl = getToolboxConfigResource().getURL();
			cfg.read(cfgUrl);
			ToolboxFactory factory = cfg.createFactory();
			
			velocityContext.addToolbox(factory.createToolbox(Scope.APPLICATION));
			velocityContext.addToolbox(factory.createToolbox(Scope.REQUEST));
			velocityContext.addToolbox(factory.createToolbox(Scope.SESSION));
		}
	}
	return velocityContext;
}
 
开发者ID:ivaneye,项目名称:java-template-simple,代码行数:25,代码来源:VelocityToolboxView.java

示例4: enumerateResourcesFromWebapp

import org.springframework.web.context.support.ServletContextResource; //导入依赖的package包/类
private List<Resource> enumerateResourcesFromWebapp(final String line,
		final String suffix) throws IOException {
	if (line.endsWith("/")) {
		ServletContextResourcePatternResolver resourceResolver = new ServletContextResourcePatternResolver(
				this.servletContext);
		String location = line + "**/*" + suffix;
		Resource[] resources = resourceResolver.getResources(location);
		return Arrays.asList(resources);
	}

	if (line.endsWith(suffix)) {
		return Collections.singletonList(new ServletContextResource(
				this.servletContext, line));
	}

	return Collections.emptyList();
}
 
开发者ID:khun777,项目名称:edsutil,代码行数:18,代码来源:WebResourceProcessor.java

示例5: configureParameters

import org.springframework.web.context.support.ServletContextResource; //导入依赖的package包/类
/**
 * Prepare client call
 * Uses username/password if set in the bean definition. Otherwise, use the given credentials
 * Also prepares the securityConfigResource.
 */
private void configureParameters(UsernamePasswordCredential credential) {
  if (this._sConfigResource == null){
    this._sConfigResource = new ServletContextResource(servletContext, this.configFilePath);
  }
  if (StringUtils.isNotBlank(this._wsUsername)) {
    // got username/pw from bean definition
    this._username = this._wsUsername;
    this._password = this._wsPass;
  } else {
    // get username/pw from credentials.
    this._username = credential.getUsername();
    this._password = credential.getPassword();
  }
  // ensure that username is lowercase
  if (this._username != null) {
    this._username = this._username.trim().toLowerCase();
  }
}
 
开发者ID:robertoschwald,项目名称:jasig-cas-examples-robertoschwald,代码行数:24,代码来源:ExampleWsClient.java

示例6: init

import org.springframework.web.context.support.ServletContextResource; //导入依赖的package包/类
@Override
public void init(ServletConfig config) throws ServletException {
	try {
		String isSyncGtsAuto = config.getInitParameter("start-auto-syncgts");
		log.debug("isSyncGtsAuto "+isSyncGtsAuto);			
		if (isSyncGtsAuto.equals("true")) {
			ServletContextResource contextResource=new ServletContextResource(config.getServletContext(), "/WEB-INF/sync-description.xml");
			InputStream inputStream = contextResource.getInputStream();
			final InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
			SyncDescription description = (SyncDescription) Utils.deserializeObject(inputStreamReader,SyncDescription.class);
			inputStreamReader.close();
			SyncGTS.getInstance().syncAndResyncInBackground(description, false);
		}
   	} catch (Exception e) {
   		log.error("Unable to Start Sync GTS Service." + FaultUtil.printFaultToString(e));
		throw new ServletException(e);
	}
	super.init(config);
}
 
开发者ID:NCIP,项目名称:cagrid-core,代码行数:20,代码来源:StartSyncGTSServlet.java

示例7: getContextPath

import org.springframework.web.context.support.ServletContextResource; //导入依赖的package包/类
/**
 * Returns the context path.
 * 
 * @param rootFile
 * @return context path
 */
private String getContextPath(Resource rootFile) {
    String contextPath = null;
    if (rootFile instanceof ServletContextResource) {
        ServletContextResource servletResource = (ServletContextResource) rootFile;
        contextPath = servletResource.getServletContext().getContextPath();
        if ("/".equals(contextPath)) {
            contextPath = "/root";
        }
    } else if (resources instanceof IScope) {
        contextPath = ((IScope) resources).getContextPath();
        if (contextPath == null) {
            contextPath = "/root";
        }
    }
    log.debug("Persistence context path: {}", contextPath);
    return contextPath;
}
 
开发者ID:Red5,项目名称:red5-server,代码行数:24,代码来源:FilePersistence.java

示例8: initRootDir

import org.springframework.web.context.support.ServletContextResource; //导入依赖的package包/类
/**
 * Initializes the root directory and creates it if it doesn't already exist.
 * 
 * @param rootFile
 * @param contextPath
 * @throws IOException
 */
private void initRootDir(Resource rootFile, String contextPath) throws IOException {
    if (rootFile instanceof ServletContextResource) {
        rootDir = String.format("%s/webapps%s", System.getProperty("red5.root"), contextPath);
    } else if (resources instanceof IScope) {
        rootDir = String.format("%s%s", resources.getResource("/").getFile().getAbsolutePath(), contextPath);
    }
    log.debug("Persistence directory path: {}", rootDir);
    File persistDir = new File(rootDir, path);
    if (!persistDir.exists()) {
        if (!persistDir.mkdirs()) {
            log.warn("Persistence directory creation failed");
        } else {
            log.debug("Persistence directory access - read: {} write: {}", persistDir.canRead(), persistDir.canWrite());
        }
    } else {
        log.debug("Persistence directory access - read: {} write: {}", persistDir.canRead(), persistDir.canWrite());
    }
    persistDir = null;
}
 
开发者ID:Red5,项目名称:red5-server,代码行数:27,代码来源:FilePersistence.java

示例9: createBroker

import org.springframework.web.context.support.ServletContextResource; //导入依赖的package包/类
/**
 * Factory method to create a new ActiveMQ Broker
 */
protected BrokerService createBroker(ServletContext context) {
    String brokerURI = context.getInitParameter(INIT_PARAM_BROKER_URI);
    if (brokerURI == null) {
        brokerURI = "activemq.xml";
    }
    context.log("Loading ActiveMQ Broker configuration from: " + brokerURI);
    Resource resource = new ServletContextResource(context, brokerURI);
    BrokerFactoryBean factory = new BrokerFactoryBean(resource);
    try {
        factory.afterPropertiesSet();
    } catch (Exception e) {
        context.log("Failed to create broker: " + e, e);
    }
    return factory.getBroker();
}
 
开发者ID:xuzhikethinker,项目名称:t4f-data,代码行数:19,代码来源:ActiveMQContextListener.java

示例10: load

import org.springframework.web.context.support.ServletContextResource; //导入依赖的package包/类
@Override
public String load(final String path) throws Exception {
    final org.springframework.core.io.Resource resource = new ServletContextResource(servletContext, path);
    try {
        byte[] content = FileCopyUtils.copyToByteArray(resource.getInputStream());
        return DigestUtils.md5DigestAsHex(content);
    } catch (IOException ex) {
        LOG.error("Could not calculate MD5 for resource: {}", path);
        return runtimeEnvironmentUtil.getRevision();
    }
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:12,代码来源:FrontendController.java

示例11: checkServletContextResource

import org.springframework.web.context.support.ServletContextResource; //导入依赖的package包/类
@Test
public void checkServletContextResource() throws Exception {
	Resource classpathLocation = new ClassPathResource("test/", PathResourceResolver.class);
	MockServletContext context = new MockServletContext();

	ServletContextResource servletContextLocation = new ServletContextResource(context, "/webjars/");
	ServletContextResource resource = new ServletContextResource(context, "/webjars/webjar-foo/1.0/foo.js");

	assertFalse(this.resolver.checkResource(resource, classpathLocation));
	assertTrue(this.resolver.checkResource(resource, servletContextLocation));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:12,代码来源:PathResourceResolverTests.java

示例12: getResourceByPath

import org.springframework.web.context.support.ServletContextResource; //导入依赖的package包/类
@Override
protected Resource getResourceByPath(String path) {
	if (getServletContext() == null) {
		return new ClassPathContextResource(path, getClassLoader());
	}
	return new ServletContextResource(getServletContext(), path);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:8,代码来源:EmbeddedWebApplicationContext.java

示例13: tryToCheckJspResource

import org.springframework.web.context.support.ServletContextResource; //导入依赖的package包/类
protected boolean tryToCheckJspResource(HttpServletRequest request, String viewName){
	ServletContext sc = request.getServletContext();
	String jsp = getPrefix() + viewName + getSuffix();
	ServletContextResource scr = new ServletContextResource(sc, jsp);
	if(scr.exists()){
		return true;
	}
	String path = sc.getRealPath(jsp);
	if(StringUtils.isBlank(path)){
		return false;
	}
	File jspFile = new File(path);
	return jspFile.exists();
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:15,代码来源:JspResourceViewResolver.java

示例14: initToolManager

import org.springframework.web.context.support.ServletContextResource; //导入依赖的package包/类
@PostConstruct
private void initToolManager() throws IllegalStateException, IOException {
	LOGGER.debug("Configuring toolbox from {}", getToolboxConfigLocation());
	velocityToolManager = new ViewToolManager(getServletContext(), false, true);
	velocityToolManager.setVelocityEngine(getVelocityEngine());
	FileFactoryConfiguration factoryConfig = new XmlFactoryConfiguration(false);
	factoryConfig.read(new ServletContextResource(getServletContext(), getToolboxConfigLocation()).getURL());
	velocityToolManager.configure(factoryConfig);
}
 
开发者ID:The4thLaw,项目名称:demyo,代码行数:10,代码来源:Velocity2ToolboxView.java

示例15: buildDir

import org.springframework.web.context.support.ServletContextResource; //导入依赖的package包/类
/**
 * 建構目錄
 * 
 * @param defaultDir
 * @param resource
 */
protected static void buildDir(String defaultDir, Resource resource, String assignDir) {
	try {
		// 當沒使用spring注入時,或指定目錄
		if (resource == null || assignDir != null) {
			File dir = new File(assignDir != null ? assignDir : defaultDir);
			FileHelper.md(dir);
		}
		// 使用spring注入時
		else {
			// web
			// /WEB-INF/xml
			// /custom/output
			if (resource instanceof ServletContextResource) {
				ServletContextResource recource = (ServletContextResource) resource;
				// 1./cms/WEB-INF/xml
				// 2./cms/custom/output
				FileHelper.md(recource.getFile().getAbsolutePath());
			}
			// file:xml
			// xml
			// custom/output
			else {
				URL url = resource.getURL();
				if (url != null) {
					FileHelper.md(url.getFile());
				}
			}
		}
	} catch (Exception ex) {
		ex.printStackTrace();
	}
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:39,代码来源:ConfigHelper2.java


注:本文中的org.springframework.web.context.support.ServletContextResource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。