Package com.alibaba.citrus.service.resource

Examples of com.alibaba.citrus.service.resource.Resource


        public void init(ResourceLoadingService resourceLoadingService) {
        }

        public Resource doFilter(ResourceMatchResult filterMatchResult, Set<ResourceLoadingOption> options,
                                 ResourceFilterChain chain) throws ResourceNotFoundException {
            final Resource resource = chain.doFilter(filterMatchResult, options);

            return new Resource() {
                public boolean exists() {
                    return resource.exists();
                }

                public File getFile() {
                    return null;
                }

                public InputStream getInputStream() throws IOException {
                    return resource.getInputStream();
                }

                public URL getURL() {
                    return null;
                }

                public long lastModified() {
                    return resource.lastModified();
                }
            };
        }
View Full Code Here


        public void init(ResourceLoadingService resourceLoadingService) {
        }

        public Resource doFilter(ResourceMatchResult filterMatchResult, Set<ResourceLoadingOption> options,
                                 ResourceFilterChain chain) throws ResourceNotFoundException {
            final Resource resource = chain.doFilter(filterMatchResult, options);

            return new Resource() {
                public boolean exists() {
                    return resource.exists();
                }

                public File getFile() {
                    return null;
                }

                public InputStream getInputStream() throws IOException {
                    return resource.getInputStream();
                }

                public URL getURL() {
                    return null;
                }

                public long lastModified() {
                    return resource.lastModified();
                }
            };
        }
View Full Code Here

        // (2) with FOR_CREATE option
        assertResourceLoader("/myapp/def.txt", "WEB-INF/aaa/ccc/def.txt", true, FOR_CREATE);

        // (3) without FOR_CREATE option
        Resource resource = loader.getResource(new MyContext("/myapp/ghi.txt"), null);
        Assert.assertNull(resource);

        // (4) with FOR_CREATE option
        resource = loader.getResource(new MyContext("/myapp/ghi.txt"), FOR_CREATE);
        Assert.assertNotNull(resource);
        assertTrue(!resource.exists());
    }
View Full Code Here

        assertResourceLoader(resourceName, fileName, exists, null);
    }

    protected void assertResourceLoader(String resourceName, String fileName, boolean exists,
                                        Set<ResourceLoadingOption> options) throws Exception {
        Resource resource = loader.getResource(new MyContext(resourceName), options);

        if (exists) {
            assertNotNull(resource);
            assertTrue(resource.exists());
            assertEquals(new File(srcdir, fileName).getAbsolutePath(), resource.getFile().getAbsolutePath());
        } else {
            assertNull(resource);
        }
    }
View Full Code Here

        assertSame(parentService, resourceLoadingService.getParent());
    }

    @Test
    public void inMemory() throws Exception {
        Resource resource = resourceLoadingService.getResource("/myfolder/test.xml");

        // 因为没设置saveTo,因此不可以取得URL和File。
        assertNull(resource.getURL());
        assertNull(resource.getFile());

        // 检查转换的结果, 读两遍仍应正常
        String output = normalizeString(StreamUtil.readText(resource.getInputStream(), "GB2312", true));

        output = normalizeString(StreamUtil.readText(resource.getInputStream(), "GB2312", true));

        System.out.println(output);

        String expected = normalizeString(StreamUtil.readText(
                resourceLoadingService.getResourceAsStream("/myfolder/test.result"), "GB2312", true));
View Full Code Here

        assertEquals(expected, output);
    }

    @Test
    public void saveToFile() throws Exception {
        Resource resource = resourceLoadingService.getResource("/myfolder/test2.xml");

        // 因为设置了saveToDir,因此可以取得URL和File。
        assertNotNull(resource.getURL());
        assertNotNull(resource.getFile());

        // 检查转换的结果
        String output = normalizeString(StreamUtil.readText(resource.getInputStream(), "GB2312", true));

        output = normalizeString(StreamUtil.readText(resource.getInputStream(), "GB2312", true));

        System.out.println(output);

        String expected = normalizeString(StreamUtil.readText(
                resourceLoadingService.getResourceAsStream("/myfolder/test.result"), "GB2312", true));
View Full Code Here

        assertResourceLoader(resourceName, fileName, exists, null);
    }

    protected void assertResourceLoader(String resourceName, String fileName, boolean exists,
                                        Set<ResourceLoadingOption> options) throws Exception {
        Resource resource = loader.getResource(new MyContext(resourceName), options);

        if (exists) {
            assertNotNull(resource);
            assertTrue(resource.exists());
            assertEquals(new File(srcdir, fileName).getAbsolutePath(), resource.getFile().getAbsolutePath());
        } else {
            assertNull(resource);
        }
    }
View Full Code Here

    /** 跟踪一个查找过过程。 */
    public ResourceTrace getTrace() throws ResourceNotFoundException {
        trace = createLinkedList();

        Resource resource = null;

        try {
            resource = doLoad(resourceName, options); // 越过filters
        } catch (ResourceNotFoundException e) {
            // ignore
View Full Code Here

        return getServletResource(getNewResourceName(context), context, options);
    }

    public String[] list(ResourceListerContext context, Set<ResourceLoadingOption> options) {
        String path = getNewResourceName(context);
        Resource resource = getServletResource(path, context, options);

        if (resource == null) {
            return null; // 目录不存在,则返回null
        }

        boolean isDirectory = resource.getURL().getPath().endsWith("/");

        if (!path.endsWith("/")) {
            path += "/";
        }
View Full Code Here

            } catch (MalformedURLException e) {
                // ignore
            }
        }

        Resource resource = null;

        if (resourceURL != null) {
            resource = new URLResource(resourceURL);
        }

        // 对于webapp资源,如果被找到,可以肯定资源存在,不需要再检查其存在性。
        // 然而在httpunit环境下,上述规则可能不被遵循。
        // 为了保险起见,同时检查一下文件的存在性。
        if (resource != null && resource.getFile() != null && !resource.getFile().exists()) {
            resource = null;
        }

        return resource;
    }
View Full Code Here

TOP

Related Classes of com.alibaba.citrus.service.resource.Resource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.