KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > state > cocoon > view > XslViewHelper


1 package org.sapia.soto.state.cocoon.view;
2
3 import org.sapia.soto.Env;
4 import org.sapia.soto.EnvAware;
5 import org.sapia.soto.util.URIResolverImpl;
6
7 import org.xml.sax.ContentHandler JavaDoc;
8
9 import java.io.IOException JavaDoc;
10
11 import java.util.ArrayList JavaDoc;
12 import java.util.List JavaDoc;
13 import java.util.Map JavaDoc;
14
15 import javax.xml.transform.TransformerConfigurationException JavaDoc;
16 import javax.xml.transform.TransformerException JavaDoc;
17 import javax.xml.transform.sax.SAXResult JavaDoc;
18 import javax.xml.transform.sax.SAXTransformerFactory JavaDoc;
19 import javax.xml.transform.sax.TransformerHandler JavaDoc;
20
21
22 /**
23  * Helper class that can be extended by <code>State</code> implementations
24  * that whish to provide XSL-based pipelining behavior. The class implements
25  * the getId() and setId() methods that are eventually required by all
26  * <code>state</code> implementations.
27  * <p>
28  * An instance of this class encapsulates <code>XslSource</code> instances that
29  * act together in a pipeline of SAX events.
30  *
31  * @deprecated replaced by the <code>StyleStep</code> class.
32  *
33  * @see org.sapia.soto.state.xml.StyleStep
34  * @see org.sapia.soto.state.cocoon.view.DomifyView
35  * @see org.sapia.soto.state.cocoon.view.JellyView
36  *
37  * @author Yanick Duchesne
38  * <dl>
39  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
40  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
41  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
42  * </dl>
43  */

44 public class XslViewHelper implements EnvAware {
45   protected List JavaDoc _sources = new ArrayList JavaDoc();
46   private SAXTransformerFactory JavaDoc _fac;
47
48   public XslViewHelper(SAXTransformerFactory JavaDoc fac) {
49     _fac = fac;
50   }
51
52   /**
53    * @see org.sapia.soto.EnvAware#setEnv(org.sapia.soto.Env)
54    */

55   public void setEnv(Env env) {
56     if (!(_fac.getURIResolver() instanceof URIResolverImpl)) {
57       _fac.setURIResolver(new URIResolverImpl(env, _fac.getURIResolver()));
58     }
59   }
60
61   /**
62    * @param src a <code>XslSource</code>.
63    */

64   protected void addSource(XslSource src) {
65     _sources.add(src);
66     src.setSaxTransformerFactory(_fac);
67   }
68
69   /**
70    * @param params the <code>Map</code> that contains the view parameters.
71    * @param handler the <code>ContentHandler</code> to which SAX events are to be
72    * ultimately pipelined.
73    *
74    * @return a <code>TransformInfo</code>.
75    * @throws TransformerConfigurationException
76    * @throws TransformerException
77    * @throws IOException
78    */

79   protected TransformInfo process(Map JavaDoc params, ContentHandler JavaDoc handler)
80     throws TransformerConfigurationException JavaDoc, TransformerException JavaDoc, IOException JavaDoc {
81     TransformerHandler JavaDoc[] handlers = new TransformerHandler JavaDoc[_sources.size()];
82     SAXResult JavaDoc first = null;
83     XslSource src;
84
85     if (_sources.size() == 1) {
86       src = (XslSource) _sources.get(0);
87       handlers[0] = src.getTransformerHandler(params);
88       handlers[0].setResult(first = new SAXResult JavaDoc(handler));
89     } else {
90       for (int i = 0; i < _sources.size(); i++) {
91         src = (XslSource) _sources.get(i);
92         handlers[i] = src.getTransformerHandler(params);
93
94         if (i > 0) {
95           if ((i - 1) == 0) {
96             handlers[i - 1].setResult(first = new SAXResult JavaDoc(handlers[i]));
97           } else {
98             handlers[i - 1].setResult(new SAXResult JavaDoc(handlers[i]));
99           }
100         }
101       }
102
103       handlers[handlers.length - 1].setResult(new SAXResult JavaDoc(handler));
104     }
105
106     return new TransformInfo(first, handlers[0]);
107   }
108 }
109
Popular Tags