KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > generation > WoodyGenerator


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.woody.generation;
17
18 import java.io.IOException JavaDoc;
19 import java.util.Locale JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import org.apache.avalon.framework.parameters.Parameters;
23 import org.apache.cocoon.ProcessingException;
24 import org.apache.cocoon.environment.SourceResolver;
25 import org.apache.cocoon.generation.AbstractGenerator;
26 import org.apache.cocoon.woody.Constants;
27 import org.apache.cocoon.woody.formmodel.Form;
28 import org.apache.cocoon.woody.transformation.WoodyPipelineConfig;
29 import org.xml.sax.Attributes JavaDoc;
30 import org.xml.sax.SAXException JavaDoc;
31
32 /**
33  * A generator that streams an XML representation of a Woody {@link Form}. This will
34  * recursively contain the XML for all widgets on the form. This can then be styled
35  * using an XSLT.
36  *
37  * <p>An alternative approach that requires less (or even none) XSLT work is offered by
38  * the {@link org.apache.cocoon.woody.transformation.WoodyTemplateTransformer WoodyTemplateTransformer}.
39  *
40  * <p>The Form whose XML should be produced should reside either
41  * <ol><li> In a request attribute, whose name should be provided to this
42  * generator as a sitemap parameter called "attribute-name".</li>
43  * <li> Or else at its default-location in the flow context-object.</li>
44  * </ol>
45  *
46  * @version $Id: WoodyGenerator.java 30932 2004-07-29 17:35:38Z vgritsenko $
47  */

48 public class WoodyGenerator extends AbstractGenerator {
49     
50     protected WoodyPipelineConfig config;
51     private static final String JavaDoc FORM_GENERATED_EL = "form-generated";
52
53     public void setup(SourceResolver resolver, Map JavaDoc objectModel, String JavaDoc src, Parameters par)
54             throws ProcessingException, SAXException JavaDoc, IOException JavaDoc {
55         super.setup(resolver, objectModel, src, par);
56         
57         this.config = WoodyPipelineConfig.createConfig(objectModel, parameters);
58     }
59
60     public void recycle() {
61         super.recycle();
62         this.config = null;
63     }
64
65     public void generate() throws IOException JavaDoc, SAXException JavaDoc, ProcessingException {
66         contentHandler.startDocument();
67         contentHandler.startPrefixMapping(Constants.WI_PREFIX, Constants.WI_NS);
68         Attributes JavaDoc formAtts = this.config.getFormAttributes();
69         
70         contentHandler.startElement(Constants.WI_NS, FORM_GENERATED_EL, Constants.WI_PREFIX_COLON +FORM_GENERATED_EL, formAtts);
71         Form form = config.findForm();
72         form.generateSaxFragment(contentHandler, Locale.US);
73         contentHandler.endElement(Constants.WI_NS, FORM_GENERATED_EL, Constants.WI_PREFIX_COLON +FORM_GENERATED_EL);
74         
75         contentHandler.endPrefixMapping(Constants.WI_PREFIX);
76         contentHandler.endDocument();
77     }
78 }
79
Popular Tags