Hi,

I am developing an intranet site for my company using Cocoon 2.1.5.1
with Portal block (not portal-fw).  The emphasis is on minimal
development time so Cocoon is ideal, apart from:

I need to serve up from Cocoon images and documents that live elsewhere
on a Windows (SMB) network.  The DirectoryGenerator does exactly what I
want it to except it does not appear to support
"\\servername\share\path\filename" syntax for specifying the source dir.
Java is perfectly happy with this syntax, but in Cocoon, at line 274 of
org.apache.cocoon.generation.DirectoryGenerator, the
MutableEnvironmentFacade associated with the generator (this.resovler)
resolves the file URI to a local path relative to the site directory
(X:/tomcat/webapps/cocoon/servername/share/ etc).

I have tried 101 ways of specifying the address in the config file
"file:///", "//servername" etc. etc. but got nowhere.  The only way I
could get it to work would be to modify the code for DirectoryGenerator
such that it would attempt to use the src string directly as a file if
and only if the URI failed.  Look for XXXXXX in the code below.

Is there a more elegant way of doing this?

NOTES:
1) Drive maps are ugly and run into serious Windows permissions issues
when running Tomcat as a service
2) The Tomcat server's location is less of a given than the location of
the documents and images (at least until it proves it's worth ;-)),
hence the need to handle this cleanly.

I apologise if I have missed something obvious but I am fairly new to
Cocoon. I have spent more time on this one issue than the rest of the
time to build the portal (2 days). Any help or advice would be much
appreciated. 

Many thanks,
Matt.

Matt Innes, UTB Consulting
[EMAIL PROTECTED]@utbconsulting.com
+44 7795 300 735


public class DirectoryGenerarator {

        .
        .
        .

    public void generate() throws SAXException, ProcessingException {
        String directory = super.source;
        Source inputSource = null;
        try {
            inputSource = this.resolver.resolveURI(directory);
            String systemId = inputSource.getURI();
            if (!systemId.startsWith(FILE)) {
                throw new ResourceNotFoundException(systemId + " does
not denote a directory");
            }
            // This relies on systemId being of the form "file://..."
            File directoryFile = new File(new URL(systemId).getFile());
            if (!directoryFile.isDirectory()) {
                        // XXXXXXXXXXXX THIS ASSIGNMENT AND FOLLOWING IF
STATEMENT IS NEW, PREVIOUSLY IT JUST THREW THE EXCEPTION XXXXXXXXXXXXX

                        directoryFile = new File(directory);
                
                if  (directoryFile.isDirectory() == false){
                    throw new ResourceNotFoundException(directory + " is
not a directory.");
                }
            }

            this.contentHandler.startDocument();
            this.contentHandler.startPrefixMapping(PREFIX, URI);

            Stack ancestors = getAncestors(directoryFile);
            addAncestorPath(directoryFile, ancestors);

            this.contentHandler.endPrefixMapping(PREFIX);
            this.contentHandler.endDocument();
        } catch (SourceException se) {
            throw SourceUtil.handle(se);
        } catch (IOException ioe) {
            throw new ResourceNotFoundException("Could not read
directory " + directory, ioe);
        } finally {
            this.resolver.release(inputSource);
        }
    }
}

Reply via email to