Spring Framework AbstractFileResolvingResource - 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 AbstractFileResolvingResource class.

This code example shows how to use the following methods:lastModified
	 * 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; 
		} 
	} 
 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getFile
	@Override 
	public File getFile() throws IOException {
		URL url = getURL();
		if (ResourceUtils.isFileURL(url)) {
			// Proceed with file system resolution... 
			return super.getFile(); 
		} 
		else { 
			String realPath = PortletUtils.getRealPath(this.portletContext, this.path);
			return new File(realPath);
		} 
	} 
 
	@Override 
	public Resource createRelative(String relativePath) {
		String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
		return new PortletContextResource(this.portletContext, pathToUse);
	} 
 
	@Override 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getFile
	 
	@Override 
	@Before 
	public void setUp() throws Exception {
		 
		ClassPathResource cpr = new ClassPathResource("FileURIHandlerFactoryTest-context.xml", getClass());
		File f = cpr.getFile();
		fileURI = f.toURI();
	} 
 
	@Test
	public void testResolveFSHandler() throws Exception {
		 
		FileURIHandler handler = fileURIHandlerFactory.getHandler(fileURI);
		 
		assertNotNull(handler);
		assertTrue(handler instanceof FilesystemFileURIHandler);
	} 
	 
	@Test
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getFile
        contentComparator.init();
         
        ClassPathResource file0Resource = new ClassPathResource("filesys/ContentComparatorTest0.mpp");
        assertNotNull("unable to find test resource filesys/ContentComparatorTest0.mpp", file0Resource);
         
        ClassPathResource file1Resource = new ClassPathResource("filesys/ContentComparatorTest1.mpp");
        assertNotNull("unable to find test resource filesys/ContentComparatorTest1.mpp", file1Resource);
         
        ClassPathResource file2Resource = new ClassPathResource("filesys/ContentComparatorTest2.mpp");
        assertNotNull("unable to find test resource filesys/ContentComparatorTest2.mpp", file1Resource);
          
        File textFile = TempFileProvider.createTempFile("testCIFSContentComparator","txt");
        FileOutputStream os1 = new FileOutputStream(textFile);
        os1.write("The quick brown fox".getBytes("UTF-8"));
        os1.close();
 
        /** 
         * Compare same project file with itself  
         */ 
        { 

5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getFile
	@Override 
	public File getFile() throws IOException { 
		URL url = this.servletContext.getResource(this.path); 
		if (url != null && ResourceUtils.isFileURL(url)) { 
			// Proceed with file system resolution... 
			return super.getFile(); 
		} 
		else { 
			String realPath = WebUtils.getRealPath(this.servletContext, this.path); 
			return new File(realPath); 
		} 
	} 
 
	/** 
	 * This implementation creates a ServletContextResource, applying the given path 
	 * relative to the path of the underlying file of this resource descriptor. 
	 * @see org.springframework.util.StringUtils#applyRelativePath(String, String) 
	 */ 
	@Override 
	public Resource createRelative(String relativePath) { 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getInputStream, exists
        } 
 
        @Override 
        public boolean exists() 
        { 
            if (!super.exists()) 
            { 
                // Check whether InputStream of the resource really cannot be retrieved - as the UrlResource 
                // can return "false" from exists() if the resource is inside a JAR or JBoss VFS system file. 
                InputStream stream = null;
                try 
                { 
                    stream = super.getInputStream();
                    return stream != null;
                } 
                catch (IOException e)
                { 
                    // We can't get the InputStream of current resource due to incorrect URL or other issue 
                    return false; 
                } 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getFile
 */ 
public class PluginXmlValidatorTest { 
 
    @Test
    public void testValidate() throws Exception {
        ClassPathResource testPlugin = new ClassPathResource("/hq-plugin.xml");
        File testPluginFile = testPlugin.getFile();
        //Point to the hq-plugin folder under src control to resolve shared XML 
        File pluginDir = new File(testPluginFile.getParentFile().getParentFile().getParentFile().getParent() + "/hq-plugin");
        PluginXmlValidator validator = new PluginXmlValidator(pluginDir.getAbsolutePath());
        validator.validatePluginXML(testPluginFile.getAbsolutePath());
    } 
     
    @Test(expected=PluginException.class)
    public void testValidateInvalidSharedXmlLocation() throws Exception {
        ClassPathResource testPlugin = new ClassPathResource("/hq-plugin.xml");
        File testPluginFile = testPlugin.getFile();
        File pluginDir = new File("fake");
        PluginXmlValidator validator = new PluginXmlValidator(pluginDir.getAbsolutePath());
        validator.validatePluginXML(testPluginFile.getAbsolutePath());
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getFile
     * 
     * @return the simple-spring-app WAR file 
     * @throws IOException 
     */ 
    public static File simpleSpringApp() throws IOException {
		ClassPathResource cpr = new ClassPathResource("simple-spring-app.war");
		File file = cpr.getFile();
        assertTrue("Expected test app at " + file.getCanonicalPath(), file.exists());
        return file;
    } 
 
    /** 
     * Returns a bad spring application that will cause crashes. 
     * 
     * @return the bad-spring-app WAR file 
     * @throws IOException 
     */ 
    public static File badSpringApp() throws IOException {
		ClassPathResource cpr = new ClassPathResource("bad-spring-app.war");
		File file = cpr.getFile();
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getFile
        return getDataSetFromClasspathFile(filename,"/dataSets/");
    } 
 
    public IDataSet getDataSetFromClasspathFile(String filename, String directory)
    throws IOException, DataSetException {
        ClassPathResource resource = new ClassPathResource(directory + filename);
        File file = resource.getFile();
        if (file == null) {
            throw new FileNotFoundException("Couldn't find file:" + filename);
        } 
        FlatXmlDataSetBuilder fb = new FlatXmlDataSetBuilder();
        fb.setColumnSensing(true);
        fb.setDtdMetadata(false);
        return fb.build(file);
    } 
 
    public IDataSet getDataSetFromFile(String filename)
    throws IOException, DataSetException {
        File file = new File(filename);
        FlatXmlDataSetBuilder fb = new FlatXmlDataSetBuilder();
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getFile
    private String resourceListingFromDeclaration(String swaggerGroup, String apiDeclaration) throws IOException {
        return fileContents(swaggerGroup, "apiDeclarations/" + apiDeclaration + ".json");
    } 
 
    private String fileContents(String swaggerGroup, String fileName) throws IOException {
        ClassPathResource classPathResource = new ClassPathResource(swaggerGroup + "/" + fileName);
        File file = classPathResource.getFile();
        return FileUtils.readFileToString(file);
    } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Spring Framework AbstractFileResolvingResource Methods: