1 16 package org.apache.cocoon.forms.generation; 17 18 import java.io.IOException ; 19 import java.util.Locale ; 20 import java.util.Map ; 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.forms.FormsConstants; 26 import org.apache.cocoon.forms.formmodel.Form; 27 import org.apache.cocoon.forms.transformation.FormsPipelineConfig; 28 import org.apache.cocoon.generation.AbstractGenerator; 29 import org.xml.sax.Attributes ; 30 import org.xml.sax.SAXException ; 31 32 48 public class FormsGenerator extends AbstractGenerator { 49 50 protected FormsPipelineConfig config; 51 private static final String FORM_GENERATED_EL = "form-generated"; 52 53 public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) 54 throws ProcessingException, SAXException , IOException { 55 super.setup(resolver, objectModel, src, par); 56 57 this.config = FormsPipelineConfig.createConfig(objectModel, parameters); 58 if (this.config.getFormMethod() == null) { 60 this.config.setFormMethod("POST"); 61 } 62 } 63 64 public void recycle() { 65 super.recycle(); 66 this.config = null; 67 } 68 69 public void generate() throws IOException , SAXException , ProcessingException { 70 contentHandler.startDocument(); 71 contentHandler.startPrefixMapping(FormsConstants.INSTANCE_PREFIX, FormsConstants.INSTANCE_NS); 72 Attributes formAtts = this.config.getFormAttributes(); 73 74 contentHandler.startElement(FormsConstants.INSTANCE_NS, FORM_GENERATED_EL, FormsConstants.INSTANCE_PREFIX_COLON +FORM_GENERATED_EL, formAtts); 75 Form form = config.findForm(); 76 form.generateSaxFragment(contentHandler, Locale.US); 77 contentHandler.endElement(FormsConstants.INSTANCE_NS, FORM_GENERATED_EL, FormsConstants.INSTANCE_PREFIX_COLON +FORM_GENERATED_EL); 78 79 contentHandler.endPrefixMapping(FormsConstants.INSTANCE_PREFIX); 80 contentHandler.endDocument(); 81 } 82 } 83 | Popular Tags |