Then I guess you guys will not like to read what I'm writing now
(I'm the crooked mind perverting Cocoon concepts...:)).
You can accomplish what you are asking for by means of
SAX programming. The concept is this:
generate(originalXML)---->XMLReaderTransformer---->Transformer1-->...--->Ser
ialize
At the end of this message you can find the source for XMLReaderTransformer,
which works as a generator, but in the form of a transformer.
This XMLReaderTransformer ignores the input and spits out SAX
events out of the parsed XML file whose path is supplied
by means of an "src" attribute.
You can modify the XMLReaderTransformer to intercept
from the "originalXML" document the element that contains
that path you are looking for. Once you find it, resolve it to
an InputSource and then pass this InputSource to the
SourceUtil.parse() method.
Like I said, you need to play with SAX to make it work.
Again, I know this is not recommended but just for the heck of it...
But it's possible.
jlerm
----- Original Message -----
From: "Geoff Howard" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, September 04, 2003 9:58 PM
Subject: Re: Use the value of an XML attribute as sitemap parameter
> Javier Ramos wrote:
> > Hello,
> >
> > I would like to be able to extract from an XML document
> > transformed several times in a pipeline the name of one of its elements,
> > and use it to create the src attribute of the next transformer in the
> > pipeline.
> >
> > Anyone thinks this is possible, and how?
>
> No, it is impossible on purpose because situations like you describe can
> lead to applications which are very difficult to maintain. By the time
> generation begins, the complete pipeline must be set up, meaning all src
> attributes must be fixed. The src can only be affected by sitemap
> components executed before pipeline setup (matchers, selectors, input
> modules, actions and flow).
>
> Perhaps you can describe a simplified version of your use case and
> someone can give pointers on how to best achieve this within Cocoon.
>
> Geoff
>
package org.apache.cocoon.transformation;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.SourceResolver;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.XMLReaderFactory;
import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
import org.xml.sax.helpers.AttributesImpl;
import org.apache.cocoon.caching.CacheableProcessingComponent;
import org.apache.cocoon.components.source.SourceUtil;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceException;
import org.apache.excalibur.source.SourceValidity;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.Composable;
import java.io.StringReader;
import java.io.IOException;
import java.util.Map;
public class XMLReaderTransformer
extends AbstractTransformer
implements CacheableProcessingComponent, Composable, Disposable {
/** The input source */
protected Source inputSource;
protected SourceResolver resolver;
/**
* Recycle this component.
* All instance variables are set to <code>null</code>.
*/
public void recycle() {
if ( null != this.inputSource ) {
resolver.release( this.inputSource );
this.inputSource = null;
this.resolver = null;
}
super.recycle();
}
/** The component manager instance */
protected ComponentManager manager = null;
/**
* Set the current <code>ComponentManager</code> instance used by this
* <code>Composable</code>.
*/
public void compose(ComponentManager manager) throws ComponentException
{
this.manager = manager;
}
/**
* Release all resources.
*/
public void dispose() {
this.manager = null;
}
/** BEGIN SitemapComponent methods **/
public void setup(SourceResolver resolver,
Map objectModel,
String source,
Parameters parameters)
throws ProcessingException, SAXException, IOException {
//super.setup(resolver, objectModel, source, parameters);
this.resolver = resolver;
try {
this.inputSource = resolver.resolveURI(source);
} catch (SourceException se) {
throw SourceUtil.handle("XMLReaderTransformer.setup(): Error
during resolving of '" + source + "'.", se);
}
}
/**
* Generate the unique key.
* This key must be unique inside the space of this component.
*
* @return The generated key hashes the src
*/
public java.io.Serializable getKey() {
return this.inputSource.getURI();
}
/**
* Generate the validity object.
*
* @return The generated validity object or <code>null</code> if the
* component is currently not cacheable.
*/
public SourceValidity getValidity() {
return this.inputSource.getValidity();
}
/** BEGIN SAX ContentHandler handlers **/
public void startElement(String uri, String name, String raw, Attributes
attributes)
throws SAXException {
}
public void endElement(String uri,String name,String raw)
throws SAXException {
}
public void characters(char c[], int start, int len)
throws SAXException {
}
public void processingInstruction(String target, String data)
throws SAXException {
}
public void startEntity(String name)
throws SAXException {
}
public void endEntity(String name)
throws SAXException {
}
public void startCDATA()
throws SAXException {
}
public void endCDATA()
throws SAXException {
}
public void comment(char ch[], int start, int len)
throws SAXException {
}
public void startDocument()
throws SAXException {
/*
try {
super.xmlConsumer.startDocument();
}
catch (Exception e) {
System.out.println("XMLReaderTransformer.startDocument failed: " +
e.getMessage());
}
*/
try {
SourceUtil.parse( this.manager, this.inputSource, super.xmlConsumer);
} catch (IOException e) {
System.out.println("XMLReaderTransformer.endDocument():
SourceUtil.parse() failed: " + e.getMessage());
throw new SAXException (e);
}
catch (SAXException e2) {
System.out.println("XMLReaderTransformer.endDocument():
SourceUtil.parse() failed: " + e2.getMessage());
throw e2;
}
catch (ProcessingException e3) {
System.out.println("XMLReaderTransformer.endDocument():
SourceUtil.parse() failed: " + e3.getMessage());
throw new SAXException (e3);
}
/*
try {
}
catch (Exception e) {
System.out.println("XMLReaderTransformer.startDocument(): parsing the
file failed: " + e2.getMessage());
}
*/
}
public void endDocument()
throws SAXException {
/*
try {
super.xmlConsumer.endDocument();
}
catch (Exception e) {
System.out.println("XMLReaderTransformer.endDocument failed: " +
e.getMessage());
}
*/
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]