• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ServletContextResource类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: reloadProxyConfig

import org.springframework.web.context.support.ServletContextResource; //导入依赖的package包/类
/**
 * Reload proxy configuration reading {@link ProxyConfigImpl#locations}
 */
public void reloadProxyConfig() {
	if (locations != null) {
		for (Resource location : locations) {
			try {
				if (location.exists()) {
					trackLocation(location);
				} else {
					// Try to load from file system:
					String path = null;
					if (location instanceof ClassPathResource) {
						// This instance is running without web context
						path = ((ClassPathResource) location).getPath();
					} else if (location instanceof ServletContextResource) {
						// This instance is running in a web context
						path = ((ServletContextResource) location)
								.getPath();
					}
					if (path != null) {
						Resource alternative = new UrlResource("file:/"
								+ path);
						if (alternative.exists()) {
							trackLocation(alternative);
						}
					}
				}
			} catch (Exception e) {
				LOGGER.log(Level.SEVERE,
						"Error overriding the proxy configuration ", e);
			}
		}
	} else {
		LOGGER.log(Level.SEVERE,
				"Can't observe locations for proxy configuration");
	}
}
 
开发者ID:geosolutions-it,项目名称:OpenSDI-Manager2,代码行数:39,代码来源:ProxyConfigImpl.java


示例17: soyTemplateFilesResolver

import org.springframework.web.context.support.ServletContextResource; //导入依赖的package包/类
@Bean
public DefaultTemplateFilesResolver soyTemplateFilesResolver() throws Exception {
    final DefaultTemplateFilesResolver defaultTemplateFilesResolver = new DefaultTemplateFilesResolver();
    defaultTemplateFilesResolver.setHotReloadMode(hotReloadMode);
    defaultTemplateFilesResolver.setRecursive(recursive);
    defaultTemplateFilesResolver.setFilesExtension(fileExtension);
    defaultTemplateFilesResolver.setTemplatesLocation(new ServletContextResource(servletContext, templatesPath));

    return defaultTemplateFilesResolver;
}
 
开发者ID:matiwinnetou,项目名称:spring-soy-view,代码行数:11,代码来源:SpringSoyViewBaseConfig.java


示例18: getSitemap

import org.springframework.web.context.support.ServletContextResource; //导入依赖的package包/类
@RequestMapping(value = "/sitemap.xml", method = RequestMethod.GET, produces = "application/xml;charset=UTF-8")
@ResponseBody
public String getSitemap(HttpServletRequest request,Locale locale, Model model) throws IOException {
	ServletContextResource resource = new ServletContextResource(context, "/WEB-INF/spring/sitemap.xml");
	StringWriter writer = new StringWriter();
	IOUtils.copy(resource.getInputStream(), writer, "UTF-8");
	return writer.toString();
}
 
开发者ID:hansson,项目名称:rento,代码行数:9,代码来源:ApartmentController.java


示例19: getRobots

import org.springframework.web.context.support.ServletContextResource; //导入依赖的package包/类
@RequestMapping(value = "/robots.txt", method = RequestMethod.GET)
@ResponseBody
public String getRobots(HttpServletRequest request,Locale locale, Model model) throws IOException {
	ServletContextResource resource = new ServletContextResource(context, "/WEB-INF/spring/robots.txt");
	StringWriter writer = new StringWriter();
	IOUtils.copy(resource.getInputStream(), writer, "UTF-8");
	return writer.toString();
}
 
开发者ID:hansson,项目名称:rento,代码行数:9,代码来源:ApartmentController.java


示例20: setPath

import org.springframework.web.context.support.ServletContextResource; //导入依赖的package包/类
/**
 * Setter for file path.
 *
 * @param path  New path
 */
public void setPath(String path) {
	log.debug("Set path: {}", path);
	Resource rootFile = resources.getResource(path);
	try {
		// check for existence
		if (!rootFile.exists()) {
			log.debug("Persistence directory does not exist");
			if (rootFile instanceof ServletContextResource) {
				ServletContextResource servletResource = (ServletContextResource) rootFile;
				String contextPath = servletResource.getServletContext().getContextPath();
				log.debug("Persistence context path: {}", contextPath);
				if ("/".equals(contextPath)) {
					contextPath = "/root";
				}
				rootDir = String.format("%s/webapps%s/persistence", System.getProperty("red5.root"), contextPath);
				log.debug("Persistence directory path: {}", rootDir);
				File persistDir = new File(rootDir);
				if (!persistDir.mkdir()) {
					log.warn("Persistence directory creation failed");
				} else {
					log.debug("Persistence directory access - read: {} write: {}", persistDir.canRead(), persistDir.canWrite());
				}
				persistDir = null;
			}
		} else {
			rootDir = rootFile.getFile().getAbsolutePath();
		}
		log.debug("Root dir: {} path: {}", rootDir, path);
		this.path = path;
	} catch (IOException err) {
		log.error("I/O exception thrown when setting file path to {}", path, err);
		throw new RuntimeException(err);
	}
	storeThread = FilePersistenceThread.getInstance();
}
 
开发者ID:cwpenhale,项目名称:red5-mobileconsole,代码行数:41,代码来源:FilePersistence.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ApplicationAttemptReport类代码示例发布时间:2022-05-21
下一篇:
Java DualListModel类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap