Package org.apache.excalibur.source.impl

Examples of org.apache.excalibur.source.impl.FileSource


    }

    protected void copyDirSource(Publication template, String publicationId,
            SourceResolver resolver, String publicationsUri, String source)
            throws MalformedURLException, IOException {
        FileSource directory = new FileSource(publicationsUri + "/" + template.getId() + "/"
                + source);
        Collection files = directory.getChildren();
        for (Iterator iter = files.iterator(); iter.hasNext();) {
            FileSource filesource = (FileSource) iter.next();
            if (filesource.isCollection()) {
                copyDirSource(template, publicationId, resolver, publicationsUri, source + "/"
                        + filesource.getName());
            } else {
                copySource(template, publicationId, resolver, publicationsUri, source + "/"
                        + filesource.getName());
            }
        }
    }
View Full Code Here


    public void testDirExistence() throws Exception
    {
        m_tempDir.mkdirs();
        long time = m_tempDir.lastModified();
        FileSource src = new FileSource("file", m_tempDir);
        assertTrue("Temp dir doesn't exist", src.exists());
        assertTrue("Temp dir is not traversable", src.isCollection());
        // Check it was created less than 1 secs ago
        assertEquals("Wrong creation date", time, src.getLastModified());

        assertTrue("Temp dir is not empty", src.getChildren().isEmpty());
    }
View Full Code Here

    public void testChildCreation() throws Exception
    {
        final String text = "Writing to a source";

        FileSource src = new FileSource("file", m_tempDir);

        FileSource child = (FileSource) src.getChild("child.txt");
        assertTrue("New file already exists", !child.exists());

        // Should not have a validity, since it doesn't exist
        assertNull("New file has a validity", child.getValidity());

        // Test the name
        assertEquals("Wrong name", "child.txt", child.getName());

        // Feed with some content
        fillSource(child, text);

        // And test it
        assertEquals(
            "Wrong length",
            text.length() + System.getProperty("line.separator").length(),
            child.getContentLength());
        assertEquals("Wrong content-type", "text/plain", child.getMimeType());
        assertTrue("New file is traversable", !child.isCollection());

        // Check that parent now has children
        Collection children = src.getChildren();
        assertEquals("Wrong number of children", 1, children.size());

        // And also that crawling up the hierarchy is OK
        Source parent = child.getParent();
        assertEquals("Wrong parent URI", src.getURI(), parent.getURI());

    }
View Full Code Here

    public void testMove() throws Exception
    {
        final String text = "Original text";

        FileSource src = new FileSource("file", m_tempDir);

        FileSource child = (FileSource) src.getChild("child.txt");
        assertTrue("New file already exists", !child.exists());

        fillSource(child, text);
        assertTrue("New file doesn't exist", child.exists());
        long length = child.getContentLength();

        FileSource child2 = (FileSource) src.getChild("child2.txt");
        assertTrue("Second file already exist", !child2.exists());

        SourceUtil.move(child, child2);
        assertTrue("First file still exists", !child.exists());
        assertTrue("Second file doesn't exist", child2.exists());
        assertEquals("Wrong length of second file", length, child2.getContentLength());
    }
View Full Code Here

    public void testCopy() throws Exception
    {
        final String text = "Original text";

        FileSource src = new FileSource("file", m_tempDir);

        FileSource child = (FileSource) src.getChild("child.txt");
        assertTrue("New file already exists", !child.exists());

        fillSource(child, text);
        assertTrue("New file doesn't exist", child.exists());
        long length = child.getContentLength();

        FileSource child2 = (FileSource) src.getChild("child2.txt");
        assertTrue("Second file already exist", !child2.exists());

        SourceUtil.copy(child, child2);

        assertTrue("First file doesn't exist", child.exists());
        assertTrue("Second file doesn't exist", child2.exists());
        assertEquals("Wrong length of second file", length, child2.getContentLength());

    }
View Full Code Here

    public void testDelete() throws Exception
    {
        final String text = "Original text";

        FileSource src = new FileSource("file", m_tempDir);

        FileSource child = (FileSource) src.getChild("child.txt");
        assertTrue("New file already exists", !child.exists());
        fillSource(child, text);
        assertTrue("New file doesn't exist", child.exists());

        child.delete();
        assertTrue("File still exists", !child.exists());
    }
View Full Code Here

        assertTrue("File still exists", !child.exists());
    }

    public void testConcurrentAccess() throws Exception
    {
        FileSource src = new FileSource("file", m_tempDir);

        FileSource child = (FileSource) src.getChild("child.txt");
        assertTrue("New file already exists", !child.exists());

        child.getOutputStream();

        try
        {
            // Get it a second time
            child.getOutputStream();
        }
        catch (ConcurrentModificationException cme)
        {
            return; // This is what is expected
        }
View Full Code Here

    }

    public void testAtomicUpdate() throws Exception
    {
        final String text = "Blah, blah";
        FileSource src = new FileSource("file", m_tempDir);

        FileSource child = (FileSource) src.getChild("child.txt");
        assertTrue("New file already exists", !child.exists());
        fillSource(child, text + " and blah!");

        long length = child.getContentLength();

        SourceValidity validity = child.getValidity();
        assertEquals("Validity is not valid", 1, validity.isValid());

        // Wait 2 seconds before updating the file
        Thread.sleep(2 * 1000L);

        // Now change its content
        PrintWriter pw = new PrintWriter(child.getOutputStream());
        pw.write(text);

        assertEquals("File length modified", length, child.getContentLength());

        pw.close();

        assertTrue("File length not modified", length != child.getContentLength());

        assertEquals("Validity is valid", -1, validity.isValid());
    }
View Full Code Here

    }

    protected void copyDirSource(Publication template, String publicationId,
            SourceResolver resolver, String publicationsUri, String source)
            throws MalformedURLException, IOException {
        FileSource directory = new FileSource(publicationsUri + "/" + template.getId() + "/"
                + source);
        Collection files = directory.getChildren();
        for (Iterator iter = files.iterator(); iter.hasNext();) {
            FileSource filesource = (FileSource) iter.next();
            if (filesource.isCollection()) {
                copyDirSource(template, publicationId, resolver, publicationsUri, source + "/"
                        + filesource.getName());
            } else {
                copySource(template, publicationId, resolver, publicationsUri, source + "/"
                        + filesource.getName());
            }
        }
    }
View Full Code Here

    }

    protected void copyDirSource(Publication template, String publicationId,
            SourceResolver resolver, String publicationsUri, String source)
            throws MalformedURLException, IOException {
        FileSource directory = new FileSource(publicationsUri + "/" + template.getId() + "/"
                + source);
        Collection files = directory.getChildren();
        for (Iterator iter = files.iterator(); iter.hasNext();) {
            FileSource filesource = (FileSource) iter.next();
            if (filesource.isCollection()) {
                copyDirSource(template, publicationId, resolver, publicationsUri, source + "/"
                        + filesource.getName());
            } else {
                copySource(template, publicationId, resolver, publicationsUri, source + "/"
                        + filesource.getName());
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.excalibur.source.impl.FileSource

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.