1 13 package com.tonbeller.wcf.form; 14 15 import java.net.MalformedURLException ; 16 import java.net.URL ; 17 import java.util.Locale ; 18 import java.util.MissingResourceException ; 19 20 import javax.servlet.jsp.JspException ; 21 22 import org.apache.log4j.Logger; 23 import org.w3c.dom.Document ; 24 25 import com.tonbeller.wcf.component.Component; 26 import com.tonbeller.wcf.component.ComponentTag; 27 import com.tonbeller.wcf.controller.RequestContext; 28 import com.tonbeller.wcf.utils.ResourceLocator; 29 import com.tonbeller.wcf.utils.XmlUtils; 30 import com.tonbeller.wcf.wizard.WizardComponent; 31 import com.tonbeller.wcf.wizard.WizardComponentTag; 32 33 38 public class FormComponentTag extends ComponentTag { 39 40 String xmlUri; 41 String model; 42 boolean bookmarkable = false; 43 boolean finishButton = true; 44 String bundle; 45 46 private static Logger logger = Logger.getLogger(FormComponentTag.class); 47 48 51 public Component createComponent(RequestContext context) throws JspException { 52 try { 53 54 Document doc = parseDocument(context, getXmlUri()); 55 56 Object bean = null; 58 if (model != null) 59 bean = context.getModelReference(model); 60 61 FormComponent fc = createFormComponent(context, id, doc, bean); 63 fc.setBookmarkable(bookmarkable); 64 fc.setFinishButton(finishButton); 65 66 registerWithWizard(fc); 67 return fc; 68 69 } catch (MalformedURLException e) { 70 logger.error(null, e); 71 throw new JspException (e); 72 } 73 } 74 75 78 private void registerWithWizard(FormComponent fc) { 79 WizardComponentTag wt = (WizardComponentTag) findAncestorWithClass(this, 80 WizardComponentTag.class); 81 if (wt == null) 82 return; 83 WizardComponent wc = (WizardComponent) wt.getComponent(); 84 wc.addPage(fc); 85 } 86 87 protected FormComponent createFormComponent(RequestContext context, String id, Document doc, 88 Object bean) { 89 return new FormComponent(id, null, doc, bean); 90 } 91 92 protected Document parseDocument(RequestContext context, String xmlUri) 93 throws MalformedURLException , MissingResourceException { 94 95 Locale loc = context.getLocale(); URL url = ResourceLocator.getResource(context.getServletContext(), loc, xmlUri); 97 98 Document document = XmlUtils.parse(url); 99 FormDocument.replaceI18n(context, document, getBundle()); 101 102 return document; 103 } 104 105 public String getXmlUri() { 106 return xmlUri; 107 } 108 109 public void setXmlUri(String xmlUri) { 110 this.xmlUri = xmlUri; 111 } 112 113 public String getModel() { 114 return model; 115 } 116 117 public void setModel(String model) { 118 this.model = model; 119 } 120 121 public void setBookmarkable(boolean b) { 122 bookmarkable = b; 123 } 124 125 public void setBundle(String bundle) { 126 this.bundle = bundle; 127 } 128 129 public boolean isFinishButton() { 130 return finishButton; 131 } 132 133 public void setFinishButton(boolean finishButton) { 134 this.finishButton = finishButton; 135 } 136 137 public String getBundle() { 138 return bundle; 139 } 140 141 } 142 | Popular Tags |