Package com.alibaba.citrus.service.resource

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


    public Resource doFilter(ResourceMatchResult filterMatchResult, Set<ResourceLoadingOption> options,
                             ResourceFilterChain chain) throws ResourceNotFoundException {
        String resourceName = filterMatchResult.getResourceName();
        String xsltName = filterMatchResult.substitute(xslt);
        Resource xsltRes;

        try {
            xsltRes = resourceLoadingService.getResource(xsltName);
        } catch (ResourceNotFoundException e) {
            xsltRes = null;
        }

        if (xsltRes == null && failIfNotFound) {
            throw new ResourceNotFoundException("Could not find XSLT file for " + this + ", resourceName="
                    + filterMatchResult.getResourceName());
        }

        Resource resource = chain.doFilter(filterMatchResult, options);

        resource = transformDocument(resource, resourceName, xsltRes, xsltName);

        if (getSaveToDir() != null) {
            resource = saveToDir(resource, resourceName);
View Full Code Here


        } catch (IOException e) {
            log.warn("Could not save to file: " + fileToSave.getAbsolutePath(), e);
            return resource;
        }

        Resource transformed = new FileResource(fileToSave);

        if (log.isDebugEnabled()) {
            log.debug("Transformed resource is saved to " + fileToSave.getAbsolutePath());
        }
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

            loader.init(getResourceLoadingService());
        }
    }

    public Resource getResource(ResourceLoaderContext context, Set<ResourceLoadingOption> options) {
        Resource firstResult = null;

        // �������е�loader��
        // * ���ص�һ�����ڵ�resource
        // * ����resource�����ڣ��򷵻ص�һ���ǿյ�resource��
        //   ���磬file-loader��option=FOR_CREATEʱ�����ܷ���һ�������ڣ����ɱ�������resource��
        for (ResourceLoader loader : loaders) {
            Resource resource = loader.getResource(context, options);

            if (resource != null) {
                if (resource.exists()) {
                    return resource;
                }

                if (firstResult == null) {
                    firstResult = 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

        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

        // (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

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.