Spring Framework Resource - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework Resource class.

This code example shows how to use the following methods:getFilename, lastModified
	private final long lastModified;
 
 
	public TransformedResource(Resource original, byte[] transformedContent) {
		super(transformedContent);
		this.filename = original.getFilename();
		try { 
			this.lastModified = original.lastModified();
		} 
		catch (IOException e) {
			// should never happen 
			throw new IllegalArgumentException(e);
		} 
	} 
 
 
	@Override 
	public String getFilename() {
		return this.filename;
	} 
7
CodeRank
This code example shows how to use the following methods:createRelative, getFilename
		private final Resource gzipped; 
 
 
		public GzippedResource(Resource original) throws IOException { 
			this.original = original; 
			this.gzipped = original.createRelative(original.getFilename() + ".gz"); 
		} 
 
 
		public InputStream getInputStream() throws IOException { 
			return this.gzipped.getInputStream(); 
		} 
 
		public boolean exists() { 
			return this.gzipped.exists(); 
		} 
 
		public boolean isReadable() { 
			return this.gzipped.isReadable(); 
		} 
6
CodeRank
This code example shows how to use the following methods:exists, getInputStream
		return true; 
	} 
 
	/** 
	 * Renders the Excel view, given the specified model. 
	 */ 
	@Override 
	protected final void renderMergedOutputModel( 
			Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { 
 
		// Set the content type and get the output stream. 
		response.setContentType(getContentType()); 
		OutputStream out = response.getOutputStream(); 
 
		WritableWorkbook workbook; 
		if (this.url != null) { 
			Workbook template = getTemplateSource(this.url, request); 
			workbook = Workbook.createWorkbook(out, template); 
		} 
		else { 

6
CodeRank
This code example shows how to use the following methods:exists, getInputStream
 
		// Create the Excel document from the source. 
		if (logger.isDebugEnabled()) { 
			logger.debug("Loading Excel workbook from " + inputFile); 
		} 
		POIFSFileSystem fs = new POIFSFileSystem(inputFile.getInputStream()); 
		return new HSSFWorkbook(fs); 
	} 
 
	/** 
	 * Subclasses must implement this method to create an Excel HSSFWorkbook document, 
	 * given the model. 
	 * @param model the model Map 
	 * @param workbook the Excel workbook to complete 
	 * @param request in case we need locale etc. Shouldn't look at attributes. 
	 * @param response in case we need to set cookies. Shouldn't write to it. 
	 */ 
	protected abstract void buildExcelDocument( 
			Map<String, Object> model, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) 
			throws Exception; 
6
CodeRank
This code example shows how to use the following methods:getInputStream
			if (resourcePath != null) {
				if (logger.isTraceEnabled()) {
					logger.trace("Trying to locate XML entity [" + systemId + "] as resource [" + resourcePath + "]");
				} 
				Resource resource = this.resourceLoader.getResource(resourcePath);
				source = new InputSource(resource.getInputStream());
				source.setPublicId(publicId);
				source.setSystemId(systemId);
				if (logger.isDebugEnabled()) {
					logger.debug("Found XML entity [" + systemId + "]: " + resource);
				} 
			} 
		} 
		return source;
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:getFilename
			} 
			return FileTypeMap.getDefaultFileTypeMap(); 
		} 
 
		public static MediaType getMediaType(Resource resource) {
			if (resource.getFilename() == null) {
				return null; 
			} 
			String mediaType = fileTypeMap.getContentType(resource.getFilename());
			return (StringUtils.hasText(mediaType) ? MediaType.parseMediaType(mediaType) : null);
		} 
	} 
 
} 
5
CodeRank
This code example shows how to use the following methods:getFile
 * @author John A. Lewis 
 * @since 2.0 
 * @see javax.portlet.PortletContext#getResourceAsStream 
 * @see javax.portlet.PortletContext#getRealPath 
 */ 
public class PortletContextResource extends AbstractFileResolvingResource implements ContextResource {
 
	private final PortletContext portletContext;
 
	private final String path;
 
 
	/** 
	 * Create a new PortletContextResource. 
	 * <p>The Portlet spec requires that resource paths start with a slash, 
	 * even if many containers accept paths without leading slash too. 
	 * Consequently, the given path will be prepended with a slash if it 
	 * doesn't already start with one. 
	 * @param portletContext the PortletContext to load from 
	 * @param path the path of the resource 
5
CodeRank
This code example shows how to use the following methods:getFile
 * @since 28.12.2003 
 * @see javax.servlet.ServletContext#getResourceAsStream 
 * @see javax.servlet.ServletContext#getResource 
 * @see javax.servlet.ServletContext#getRealPath 
 */ 
public class ServletContextResource extends AbstractFileResolvingResource implements ContextResource { 
 
	private final ServletContext servletContext; 
 
	private final String path; 
 
 
	/** 
	 * Create a new ServletContextResource. 
	 * <p>The Servlet spec requires that resource paths start with a slash, 
	 * even if many containers accept paths without leading slash too. 
	 * Consequently, the given path will be prepended with a slash if it 
	 * doesn't already start with one. 
	 * @param servletContext the ServletContext to load from 
	 * @param path the path of the resource 
5
CodeRank
This code example shows how to use the following methods:getInputStream
	@Override 
	public InputStream getResourceAsStream(String path) {
		Resource resource = this.resourceLoader.getResource(getResourceLocation(path));
		try { 
			return resource.getInputStream();
		} 
		catch (IOException ex) {
			logger.info("Couldn't open InputStream for " + resource, ex);
			return null; 
		} 
	} 
 
	@Override 
	public int getMajorVersion() { 
		return 2; 
	} 
 
	@Override 
	public int getMinorVersion() { 
		return 0; 
5
CodeRank
This code example shows how to use the following methods:getURI, getInputStream
		else if (source instanceof InputStream) { 
			return new StreamSource((InputStream) source); 
		} 
		else if (source instanceof Resource) { 
			Resource resource = (Resource) source; 
			return new StreamSource(resource.getInputStream(), resource.getURI().toASCIIString()); 
		} 
		else { 
			throw new IllegalArgumentException("Value '" + source + "' cannot be converted to XSLT Source"); 
		} 
	} 
 
	/** 
	 * Configure the supplied {@link Transformer} instance. 
	 * <p>The default implementation copies parameters from the model into the 
	 * Transformer's {@link Transformer#setParameter parameter set}. 
	 * This implementation also copies the {@link #setOutputProperties output properties} 
	 * into the {@link Transformer} {@link Transformer#setOutputProperty output properties}. 
	 * Indentation properties are set as well. 
	 * @param model merged output Map (never {@code null}) 
5
CodeRank
See Code Examples for Spring Framework Resource Methods: