KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infohazard > maverick > transform > DocumentTransformFactory


1 /*
2  * $Id: DocumentTransformFactory.java,v 1.4 2003/10/27 11:00:49 thusted Exp $
3  * $Source: /cvsroot/mav/maverick/src/java/org/infohazard/maverick/transform/DocumentTransformFactory.java,v $
4  */

5
6 package org.infohazard.maverick.transform;
7
8 import org.infohazard.maverick.flow.*;
9 import org.infohazard.maverick.util.XML;
10 import javax.servlet.*;
11 import org.jdom.Element;
12
13
14 /**
15  * <p>Factory for creating transformation pipelines based on executing
16  * successive documents which are aware of servlet attribute collections.
17  * The output of the preceeding step is
18  * stored as a String in the request attributes, available to be
19  * included anywhere in the successive document.</p>
20  *
21  * <p>This factory has certain options which can be defined when
22  * declaring the factory. The defaults are shown here:</p>
23  *
24  * <pre>
25  * &lt;transform-factory type="document" provider="org.infohazard.maverick.transform.DocumentTransformFactory"&gt;
26  * &lt;default-bean-name value="wrapped"/&gt;
27  * &lt;/transform-factory&gt;
28  * </pre>
29  *
30  * <ul>
31  * <li>
32  * <b>default-bean-name</b> - If no "bean" attribute is specified
33  * for individual transformations, this is the name which will be
34  * used for placing the wrapped content in the request attributes.
35  * </li>
36  * </ul>
37  *
38  * <p>The options for an individual transform are like this:</p>
39  *
40  * <pre>
41  * &lt;transform type="document" path="blah.jsp" bean="wrapped"/&gt;
42  * </pre>
43  */

44 public class DocumentTransformFactory implements TransformFactory
45 {
46     /**
47      * If not specified on the factory, the default name for wrapped beans.
48      */

49     protected static final String JavaDoc DEFAULT_DEFAULT_WRAPPED_NAME = "wrapped";
50
51     /**
52      * For the factory configuration
53      */

54     protected static final String JavaDoc ATTR_DEFAULT_WRAPPED_NAME = "default-bean-name";
55
56
57     /**
58      * For transform nodes
59      */

60     protected static final String JavaDoc ATTR_PATH = "path";
61     protected static final String JavaDoc ATTR_BEAN = "bean";
62
63
64     /**
65      * Unless overriden on path nodes, the bean name to use for wrapping
66      * content from previous stages.
67      */

68     protected String JavaDoc defaultWrappedName = DEFAULT_DEFAULT_WRAPPED_NAME;
69
70     /**
71      */

72     public void init(Element factoryNode, ServletConfig servletCfg) throws ConfigException
73     {
74         if (factoryNode != null)
75         {
76             // Figure out the default content type for successful transforms
77
String JavaDoc wrappedNameStr = XML.getValue(factoryNode, ATTR_DEFAULT_WRAPPED_NAME);
78             if (wrappedNameStr != null)
79                 this.defaultWrappedName = wrappedNameStr;
80         }
81     }
82
83     /**
84      */

85     public Transform createTransform(Element transformNode) throws ConfigException
86     {
87         String JavaDoc path = XML.getValue(transformNode, ATTR_PATH);
88         if (path == null)
89             throw new ConfigException("Document transform node must have a \""
90                                         + ATTR_PATH + "\" attribute: "
91                                         + XML.toString(transformNode));
92         
93         String JavaDoc wrappedName = XML.getValue(transformNode, ATTR_BEAN);
94         if (wrappedName == null)
95             wrappedName = this.defaultWrappedName;
96
97         return new DocumentTransform(path, wrappedName);
98     }
99 }
Popular Tags