I replied to the list earlier that I have written a lightweight Transformer that does exactly what
you want. But you make an even more lightweight one allowing only copying of files.
Extend the AbstractTransformer, add the following:
public void startElement(String namespaceURI, String localName,
String qName, Attributes attributes)
throws SAXException {
// If we encounter a file element in our namespace, invoke a copy
// on the src attribute
if (COPY_FILES_NS.equals(namespaceURI) && FILE_ELEMENT.equals(localName)) {
copy(attributes.getValue(SRC_ATTRIBUTE),
attributes.getValue(TARGET_ATTRIBUTE));
}
else {
super.startElement(namespaceURI, localName, qName, attributes);
}
}
public void endElement(String namespaceURI, String localName, String qName)
throws SAXException {
if (COPY_FILES_NS.equals(namespaceURI) && FILE_ELEMENT.equals(localName)) {
; // Do nothing here since we want to remove this element.
} else {
super.endElement(namespaceURI, localName, qName);
}
}
And add a copy function that does the actual copying, just using plain Java...
Cheers...
Lars Huttar wrote:
Hi all,
I have the following problem.
We have a CASE-like Cocoon application that generates a bunch of code
and writes it to a destination folder. It also copies some boilerplate
files. It does the file copying by (1) generating a set of xincludes,
which are run through the XInclude transformer, and (2) writing result
to disk using SourceWritingTransformer. (This is done together with a
set of cincludes, so that we can generate both static and dynamic code
in one pipeline.)
However, this method seems inefficient as a way of copying large files
that need no pipeline processing. Why parse them into SAX and then
serialize them back out again? Yes, I'm using <source:write
serializer="text">, but they still have to go through SAX.
Also, if I try to peek at the intermediate output, between the XInclude
transformer that brings in a file and the SourceWritingTransformer that
writes it, I get errors from binary files:
"XML Parsing Error: reference to invalid character number" or "An
invalid character was found in text content." And no wonder. (In
Firefox, this error prevents me from seeing much of the intermediate
XML. In IE, I get an error popup, but I can still look over the XML.
Sure I could use IE for this case, but the less I have to remember to
switch browsers the better. And my boss would appreciate a cleaner
solution than that.)
One alternative that has been suggested is to use Ant. However, Ant can
be a configuration headache, especially since recent Cocoon has its own
version of Ant and the library versions can conflict with any other
version that may be on the system, if I recall right. Moreover, it just
makes the deployment of our application messier if the user has to
install Cocoon from source in order to include Ant so they can use our
app. But this is a possibility nevertheless.
Looking for ways to write files on cocoon.apache.org and the wiki, I
found that I could use the "/cocoon.processPipelineTo/ method from
flowscript, to save the result of a pipeline to a file"
(http://wiki.apache.org/cocoon/SavingFilesToFileSystem).
But the result is the same: static file contents have to get parsed into
the XML pipeline unnecessarily; and if I tried to look at the
intermediate XML before the writing occurs, I'd get browser errors.
I suppose another possibility would be to extend the
SourceWritingTransformer to be able to copy files without having their
contents in the pipeline. I've never extended a component before, but
maybe this is the time to get my feet wet. Seems like this would be
useful to other folks.
Thanks for any suggestions,
Lars
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
[EMAIL PROTECTED]
IT-consultant at Daidalos BV, Zoetermeer (NL)
http://www.daidalos.nl/
tel:+31-(0)79-3316961
fax:+31-(0)79-3316464
GPG: 1024D/12DEBB50
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]