001: package com.xoetrope.builder.w3c.xforms;
002:
003: import java.io.Reader;
004: import java.util.Enumeration;
005: import java.util.Hashtable;
006: import java.util.Vector;
007:
008: import java.awt.Component;
009: import java.awt.Container;
010:
011: import net.xoetrope.builder.XuiBuilder;
012: import net.xoetrope.debug.DebugLogger;
013: import net.xoetrope.xml.XmlElement;
014: import net.xoetrope.xml.XmlSource;
015: import net.xoetrope.xui.XPage;
016: import net.xoetrope.xui.PageSupport;
017: import net.xoetrope.xui.XRadioButtonGroup;
018: import net.xoetrope.xui.build.BuildProperties;
019: import net.xoetrope.xui.data.XModel;
020: import net.xoetrope.swing.XPanel;
021: import net.xoetrope.swing.XComboBox;
022: import net.xoetrope.swing.XEdit;
023: import net.xoetrope.swing.XPassword;
024: import net.xoetrope.swing.XTextArea;
025: import java.awt.GridLayout;
026: import com.xoetrope.swing.XSlider;
027: import net.xoetrope.swing.XButton;
028: import net.xoetrope.xui.XProject;
029:
030: /**
031: * An experimental build for W3C XForms XML format
032: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
033: * the GNU Public License (GPL), please see license.txt for more details. If
034: * you make commercial use of this software you must purchase a commercial
035: * license from Xoetrope.</p>
036: * <p> $Revision: 1.8 $</p>
037: */
038: public class XFormsBuilder extends XuiBuilder {
039: public static final String XFORMS_XMLNS = "http://www.w3.org/2002/xforms";
040: public static final String XHTML_XMLNS = "http://www.w3.org/1999/xhtml";
041: public static final String XEVENTS_XMLNS = "http://www.w3.org/2001/xml-events";
042:
043: public static final int SELECT = 0;
044: public static final int SELECT1 = 1;
045: public static final int INPUT = 2;
046: public static final int SECRET = 3;
047: public static final int TEXTAREA = 4;
048: public static final int MODEL = 5;
049: public static final int GROUP = 6;
050: public static final int RANGE = 7;
051: public static final int UPLOAD = 8;
052: public static final int TRIGGER = 9;
053: public static final int SUBMIT = 10;
054:
055: private static Hashtable formTags = null;
056:
057: protected String packageName;
058:
059: protected String selectStyle = XPage.RADIO;
060:
061: public XFormsBuilder(XProject project) {
062: super (project);
063: setupFormTags();
064: }
065:
066: /**
067: * Read an XML description of the page and construct a new XPage. An instance
068: * of the class specified by the class attribute is constructed or else an
069: * instance of XPage if no class attribute is specified. The new page is
070: * populated but is not yet added to its parent.
071: * <br>
072: * The startup file parameter 'DefaultClass' is used to obtain a default for
073: * each page's class if a class parameter is not specified in the page's XML
074: * <br>
075: * The startup file parameter 'Validations' is used to obtain a default for
076: * each page's set of validation rules
077: *
078: * @param reader a input stream from which to read the page
079: * @param pageName the name of the page
080: * @param include the page to be loaded is being included in another page
081: * @return the page
082: */
083: public PageSupport readPage(Reader reader, String pageName,
084: boolean include) {
085: XmlElement model = XmlSource.read(reader);
086: setupPage(model, pageName, include);
087: setupModel(pageName);
088:
089: String namespace = model.getNamespace();
090:
091: if ((namespace == null)
092: || namespace.toLowerCase().equals(XHTML_XMLNS))
093: readHtml(model);
094: else if (namespace.toLowerCase().equals(XFORMS_XMLNS))
095: readForm(model);
096: else if (namespace.toLowerCase().equals(XEVENTS_XMLNS))
097: readEvents(model);
098:
099: page.doLayout();
100: return page;
101: }
102:
103: /**
104: * Read a form element
105: * @param model the XML
106: * @return true if the children require further processing
107: */
108: protected void readForm(XmlElement model) {
109: String typeName = model.getName();
110:
111: Object obj = formTags.get(typeName);
112: if (obj != null) {
113: int tagId = ((Integer) obj).intValue();
114:
115: try {
116: switch (tagId) {
117: case SELECT:
118: readSelect(model);
119: break;
120: case SELECT1:
121: readSelect1(model);
122: break;
123: case INPUT:
124: readInput(model);
125: break;
126: case SECRET:
127: readSecret(model);
128: break;
129: case TEXTAREA:
130: readTextArea(model);
131: break;
132: case MODEL:
133: readModel(model);
134: break;
135: case GROUP:
136: readGroup(model);
137: break;
138: case RANGE:
139: readRange(model);
140: break;
141: case UPLOAD:
142: readUpload(model);
143: break;
144: case TRIGGER:
145: readTrigger(model);
146: break;
147: case SUBMIT:
148: readSubmit(model);
149: break;
150: }
151: } catch (Exception e) {
152: e.printStackTrace();
153: }
154: } else
155: addComponent(typeName, model);
156: }
157:
158: /**
159: * Read html elements
160: * @param model the XHTML
161: * @return true if the children require further processing
162: */
163: protected boolean readHtml(XmlElement model) {
164: Vector componentNodes = model.getChildren();
165: int numNodes = componentNodes.size();
166: for (int i = 0; i < numNodes; i++) {
167: XmlElement childNode = (XmlElement) componentNodes
168: .elementAt(i);
169: if (childNode != null) {
170: if (childNode.getNamespace().equals(XFORMS_XMLNS)
171: || childNode.getNamespace().equals(
172: XEVENTS_XMLNS)) {
173: readForm(childNode);
174: return true;
175: }
176: }
177:
178: readHtml(childNode);
179: }
180:
181: return true;
182: }
183:
184: /**
185: * Read html elements
186: * @param model the XHTML
187: * @return true if the children require further processing
188: */
189: protected boolean readEvents(XmlElement model) {
190: Vector componentNodes = model.getChildren();
191: int numNodes = componentNodes.size();
192: for (int i = 0; i < numNodes; i++) {
193: XmlElement childNode = (XmlElement) componentNodes
194: .elementAt(i);
195: if ((childNode != null)
196: && (childNode.getNamespace().equals(XFORMS_XMLNS)))
197: readForm(childNode);
198: else
199: readHtml(childNode);
200: }
201:
202: return true;
203: }
204:
205: /**
206: * Read a select node
207: * @param selectNode the xml representing the select item
208: */
209: protected void readSelect(XmlElement selectNode) {
210: Component parent = (Component) componentFactory
211: .getParentComponent();
212:
213: XmlElement childNode = selectNode.getFirstChildNamed("label");
214: if (childNode != null)
215: selectStyle = XPage.COMBO;
216:
217: if (selectStyle.equals(XPage.COMBO)) {
218: XPanel panel = (XPanel) addComponent("panel", selectNode);
219: componentFactory.setParentComponent(panel);
220:
221: if (childNode != null)
222: addComponent("label", childNode);
223:
224: childNode = selectNode.getFirstChildNamed("choices");
225: if (childNode != null) {
226: XComboBox combo = (XComboBox) addComponent("combo",
227: childNode);
228: Vector itemNodes = childNode.getChildren();
229: int numItems = itemNodes.size();
230: for (int i = 0; i < numItems; i++) {
231: XmlElement item = (XmlElement) itemNodes
232: .elementAt(i);
233: if ((item != null)
234: && (item.getName().equals("item"))) {
235: combo.addItem(item.getFirstChildNamed("label")
236: .getContent());
237: }
238: }
239: }
240:
241: childNode = selectNode.getFirstChildNamed("itemset");
242: if (childNode != null) {
243: XmlElement labelNode = childNode
244: .getFirstChildNamed("label");
245: XComboBox combo = (XComboBox) addComponent("combo",
246: childNode);
247: XModel item = readItemset(childNode);
248: // Vector itemNodes = readItemset( childNode );
249: // int numItems = itemNodes.size();
250: // for ( int i = 0; i < numItems; i++ ) {
251: // XModel item = ( XModel )itemNodes.elementAt( i );
252: if (item != null) {
253: combo.addItem(item.getValueAsString(labelNode
254: .getAttribute("ref")));
255: }
256: // }
257: }
258: }
259: }
260:
261: protected XModel readItemset(XmlElement itemsetNode) {
262: String model = "XForms/" + itemsetNode.getAttribute("model");
263: String nodeSet = itemsetNode.getAttribute("nodeset");
264: if (nodeSet.charAt(0) == '/')
265: nodeSet = nodeSet.substring(1);
266:
267: XModel modelNode = (XModel) currentProject.getModel()
268: .get(model);
269: return (XModel) modelNode.get(nodeSet);
270: }
271:
272: protected XModel readItem(XmlElement itemsetNode) {
273: String model = "XForms/" + itemsetNode.getAttribute("model");
274: String nodeSet = itemsetNode.getAttribute("ref");
275: if (nodeSet.charAt(0) == '/')
276: nodeSet = nodeSet.substring(1);
277:
278: XModel modelNode = (XModel) currentProject.getModel()
279: .get(model);
280: return (XModel) modelNode.get(nodeSet);
281: }
282:
283: /**
284: * Read a select1 node
285: * @param selectNode the xml representing the select item
286: */
287: protected void readSelect1(XmlElement selectNode) {
288: Component parent = (Component) componentFactory
289: .getParentComponent();
290:
291: XmlElement childNode = selectNode.getFirstChildNamed("label");
292:
293: XPanel panel = (XPanel) addComponent("panel", selectNode);
294: panel.setName(selectNode.getAttribute("ref"));
295: componentFactory.setParentComponent(panel);
296:
297: if (childNode != null)
298: addComponent("label", childNode);
299:
300: Vector itemNodes = selectNode.getChildren();
301: int numItems = itemNodes.size();
302: for (int i = 0; i < numItems; i++) {
303: XmlElement item = (XmlElement) itemNodes.elementAt(i);
304: if ((item != null) && (item.getName().equals("item"))) {
305: addComponent("radio", item.getFirstChildNamed("label"));
306: }
307: }
308:
309: // Reset the parent component to its state prior to this call
310: componentFactory.setParentComponent(parent);
311: }
312:
313: protected void readModel(XmlElement modelNode) {
314: String modelId = modelNode.getAttribute("id");
315: XModel xformsModel = (XModel) currentProject.getModel().get(
316: modelId == null ? "XForms" : "XForms" + "/" + modelId);
317:
318: XmlElement instanceNode = modelNode
319: .getFirstChildNamed("xf:instance");
320: if (instanceNode == null)
321: instanceNode = modelNode.getFirstChildNamed("instance");
322: if (instanceNode == null)
323: instanceNode = modelNode;
324: if (instanceNode != null) {
325: Vector itemNodes = instanceNode.getChildren();
326: int numItems = itemNodes.size();
327: for (int i = 0; i < numItems; i++) {
328: XmlElement childNode = (XmlElement) itemNodes
329: .elementAt(i);
330: XModel model = (XModel) xformsModel.get(childNode
331: .getName());
332: model.setTagName(childNode.getName());
333: Enumeration enumeration = childNode
334: .enumerateAttributeNames();
335: model.setNumAttributes(2 + childNode
336: .getAttributeCount());
337: int j = 2;
338: while (enumeration.hasMoreElements()) {
339: String attribName = (String) enumeration
340: .nextElement();
341: model.setAttribValue(j++, attribName, childNode
342: .getAttribute(attribName));
343: }
344:
345: readModelChildren(model, childNode);
346: }
347: }
348: }
349:
350: protected void readModelChildren(XModel parentModel,
351: XmlElement parentNode) {
352: Vector itemNodes = parentNode.getChildren();
353: int numItems = itemNodes.size();
354: for (int i = 0; i < numItems; i++) {
355: XmlElement childNode = (XmlElement) itemNodes.elementAt(i);
356: XModel childModel = (XModel) parentModel.get(childNode
357: .getName());
358: parentModel
359: .set(childNode.getName(), childNode.getContent());
360: readModelChildren(childModel, childNode);
361: }
362: }
363:
364: protected void readGroup(XmlElement modelNode) {
365: Component parent = (Component) componentFactory
366: .getParentComponent();
367: XPanel panel = (XPanel) addComponent("panel", modelNode);
368: componentFactory.setParentComponent(panel);
369: panel.setLayout(new GridLayout(0, 1));
370:
371: Vector componentNodes = modelNode.getChildren();
372: int numNodes = componentNodes.size();
373: for (int i = 0; i < numNodes; i++) {
374: XmlElement childNode = (XmlElement) componentNodes
375: .elementAt(i);
376: if (childNode != null)
377: readForm(childNode);
378: }
379:
380: // Reset the parent component to its state prior to this call
381: componentFactory.setParentComponent(parent);
382: }
383:
384: protected void readInput(XmlElement inputNode) {
385: Component parent = (Component) componentFactory
386: .getParentComponent();
387: XPanel panel = (XPanel) addComponent("panel", inputNode);
388: componentFactory.setParentComponent(panel);
389:
390: XmlElement childNode = inputNode.getFirstChildNamed("label");
391: if (childNode != null)
392: addComponent("label", childNode);
393:
394: XEdit edit = (XEdit) addComponent("edit", inputNode);
395:
396: childNode = inputNode.getFirstChildNamed("help");
397: if (childNode != null)
398: edit.setToolTipText(childNode.getContent());
399:
400: // Reset the parent component to its state prior to this call
401: componentFactory.setParentComponent(parent);
402: }
403:
404: protected void readRange(XmlElement rangeNode) {
405: Component parent = (Component) componentFactory
406: .getParentComponent();
407: XPanel panel = (XPanel) addComponent("panel", rangeNode);
408: componentFactory.setParentComponent(panel);
409:
410: XmlElement childNode = rangeNode.getFirstChildNamed("label");
411: if (childNode != null)
412: addComponent("label", childNode);
413:
414: XSlider slider = (XSlider) addComponent("slider", rangeNode);
415: if (rangeNode.getAttribute("model") != null) {
416: XModel item = readItem(rangeNode);
417: }
418:
419: String attrib = rangeNode.getAttribute("step");
420: if (attrib != null)
421: slider.setIncrement(Integer.parseInt(attrib));
422:
423: attrib = rangeNode.getAttribute("start");
424: if (attrib != null)
425: slider.setMinimum(Integer.parseInt(attrib));
426:
427: attrib = rangeNode.getAttribute("end");
428: if (attrib != null)
429: slider.setMaximum(Integer.parseInt(attrib));
430:
431: childNode = rangeNode.getFirstChildNamed("help");
432: if (childNode != null)
433: slider.setToolTipText(childNode.getContent());
434:
435: // Reset the parent component to its state prior to this call
436: componentFactory.setParentComponent(parent);
437: }
438:
439: protected void readUpload(XmlElement uploadNode) {
440: Component parent = (Component) componentFactory
441: .getParentComponent();
442: XPanel panel = (XPanel) addComponent("panel", uploadNode);
443: componentFactory.setParentComponent(panel);
444:
445: XmlElement childNode = uploadNode.getFirstChildNamed("label");
446: if (childNode != null)
447: addComponent("label", childNode);
448:
449: XEdit edit = (XEdit) addComponent("edit", uploadNode);
450: XButton button = (XButton) addComponent("button", uploadNode);
451: button.setText("...");
452:
453: childNode = uploadNode.getFirstChildNamed("help");
454: if (childNode != null)
455: edit.setToolTipText(childNode.getContent());
456:
457: // Reset the parent component to its state prior to this call
458: componentFactory.setParentComponent(parent);
459: }
460:
461: protected void readSecret(XmlElement inputNode) {
462: Component parent = (Component) componentFactory
463: .getParentComponent();
464: XPanel panel = (XPanel) addComponent("panel", inputNode);
465: componentFactory.setParentComponent(panel);
466:
467: XmlElement childNode = inputNode.getFirstChildNamed("label");
468: if (childNode != null)
469: addComponent("label", childNode);
470:
471: XPassword edit = (XPassword) addComponent("password", inputNode);
472:
473: childNode = inputNode.getFirstChildNamed("help");
474: if (childNode != null)
475: edit.setToolTipText(childNode.getContent());
476:
477: // Reset the parent component to its state prior to this call
478: componentFactory.setParentComponent(parent);
479: }
480:
481: protected void readTextArea(XmlElement inputNode) {
482: Component parent = (Component) componentFactory
483: .getParentComponent();
484:
485: XPanel panel = (XPanel) addComponent("panel", inputNode);
486: componentFactory.setParentComponent(panel);
487:
488: XmlElement childNode = inputNode.getFirstChildNamed("label");
489: if (childNode != null)
490: addComponent("label", childNode);
491:
492: XTextArea edit = (XTextArea) addComponent("textarea", inputNode);
493:
494: childNode = inputNode.getFirstChildNamed("help");
495: if (childNode != null)
496: edit.setToolTipText(childNode.getContent());
497:
498: // Reset the parent component to its state prior to this call
499: componentFactory.setParentComponent(parent);
500: }
501:
502: protected void readTrigger(XmlElement triggerNode) {
503: Vector actionNodes = triggerNode.getChildren("action");
504: int numActions = actionNodes.size();
505: if (numActions > 0) {
506: for (int i = 0; i < numActions; i++) {
507: XmlElement actionNode = (XmlElement) actionNodes
508: .elementAt(i);
509: String eventStr = actionNode.getAttribute("ev:event");
510: String handlerStr = actionNode
511: .getAttribute("ev:handler");
512: addActions(actionNode, eventStr, handlerStr);
513: }
514: } else {
515: String eventStr = triggerNode.getAttribute("ev:event");
516: String handlerStr = triggerNode.getAttribute("ev:handler");
517: addActions(triggerNode, eventStr, handlerStr);
518: }
519: }
520:
521: protected void readSubmit(XmlElement submitNode) {
522: Component parent = (Component) componentFactory
523: .getParentComponent();
524:
525: XPanel panel = (XPanel) addComponent("panel", submitNode);
526: componentFactory.setParentComponent(panel);
527:
528: XmlElement childNode = submitNode.getFirstChildNamed("label");
529: if (childNode != null)
530: addComponent("label", childNode);
531:
532: XButton button = (XButton) addComponent("button", submitNode);
533: button.setText("Submit");
534: String submissionStr = submitNode.getAttribute("submission");
535:
536: String model = "XForms/submission/@id=" + submissionStr;
537: XModel submissionNode = (XModel) currentProject.getModel().get(
538: model);
539: String action = submissionNode
540: .getAttribValueAsString(submissionNode
541: .getAttribute("action"));
542: String ref = submissionNode
543: .getAttribValueAsString(submissionNode
544: .getAttribute("ref"));
545: String method = submissionNode
546: .getAttribValueAsString(submissionNode
547: .getAttribute("method"));
548: String separator = submissionNode
549: .getAttribValueAsString(submissionNode
550: .getAttribute("separator"));
551: String encoding = submissionNode
552: .getAttribValueAsString(submissionNode
553: .getAttribute("encoding"));
554: String replace = submissionNode
555: .getAttribValueAsString(submissionNode
556: .getAttribute("replace"));
557: String indent = submissionNode
558: .getAttribValueAsString(submissionNode
559: .getAttribute("indent"));
560: String version = submissionNode
561: .getAttribValueAsString(submissionNode
562: .getAttribute("version"));
563: String omit_xml_declaration = submissionNode
564: .getAttribValueAsString(submissionNode
565: .getAttribute("omit-xml-declaration"));
566: String standalone = submissionNode
567: .getAttribValueAsString(submissionNode
568: .getAttribute("standalone"));
569: String cdata_section_elements = submissionNode
570: .getAttribValueAsString(submissionNode
571: .getAttribute("cdata-section-elements"));
572:
573: childNode = submitNode.getFirstChildNamed("help");
574: if (childNode != null)
575: button.setToolTipText(childNode.getContent());
576:
577: // Reset the parent component to its state prior to this call
578: componentFactory.setParentComponent(parent);
579: }
580:
581: protected void addActions(XmlElement actionNode, String event,
582: String handler) {
583: Vector actionNodes = actionNode.getChildren();
584: int numActions = actionNodes.size();
585: for (int i = 0; i < numActions; i++) {
586: XmlElement methodNode = (XmlElement) actionNodes
587: .elementAt(i);
588: String method = methodNode.getName();
589: String controlStr = methodNode.getAttribute("control");
590: Object targetComp = page;
591: if (controlStr != null)
592: targetComp = page.findComponent(controlStr);
593:
594: String eventType = getEventType(event);
595: if (eventType != null)
596: addHandler(page, targetComp, eventType, method);
597:
598: String eventStr = methodNode.getAttribute("ev:event");
599: if (eventStr != null) {
600: eventType = getEventType(eventStr);
601: if (eventType != null)
602: addHandler(page, targetComp, eventType, method);
603: }
604: }
605: }
606:
607: /**
608: * Adds an individual component element to the page (this method may be called
609: * recursively for nested elements). Several methods will be attempted until a
610: * component is successfully created. Firstly the built-in component types are
611: * checked, then any additional registered component constructors. The types
612: * can be specified by type ID, type name or class name.
613: * @param childName the name of the child element
614: * @param childNode the XML element containing the component specification.
615: * @return the new component
616: */
617: protected Component addComponent(String childName,
618: XmlElement childNode) {
619: String nameStr = null, contentStr, styleStr;
620:
621: Component comp = null;
622: try {
623: nameStr = contentStr = styleStr = null;
624: Hashtable componentAttributes = new Hashtable(); // Local copy of the component attributes
625: Enumeration attribNamesEnum = childNode
626: .enumerateAttributeNames();
627: while (attribNamesEnum.hasMoreElements()) {
628: String attribName = (String) attribNamesEnum
629: .nextElement();
630: String attribValue = (String) childNode
631: .getAttribute(attribName);
632: if (attribName.compareTo("ref") == 0)
633: nameStr = attribValue;
634: else if (attribName.compareTo("content") == 0) {
635: contentStr = (String) rootPage
636: .evaluateAttribute(attribValue);
637: componentAttributes.put(attribName, contentStr);
638: } else if (attribName.compareTo("class") == 0)
639: styleStr = childNode.getName() + "/" + attribValue;
640: else {
641: // Save a copy of the attributes in the page for post creation usage
642: ((XPage) rootPage).setAttribute(attribName,
643: nameStr, attribValue);
644:
645: // Save a local copy for use during the construction process
646: componentAttributes.put(attribName, attribValue);
647: }
648: }
649:
650: contentStr = childNode.getContent();
651:
652: // Load with a name like 'Button'
653: try {
654: comp = (Component) componentFactory.addComponent(
655: getComponentRenderType(childName), 0, 0, -1,
656: -1, contentStr, styleStr);
657: } catch (Exception e) {
658: comp = null;
659: }
660:
661: if (comp == null)
662: return null;
663:
664: // Set the component name
665: comp.setName(nameStr);
666:
667: // Special handling for radio buttons
668: // For the first rb create a group
669: // For subsequent rbs add them to the group
670: // If another type of component is found reset the groups
671: if (comp instanceof XRadioButtonGroup) {
672: XRadioButtonGroup rb = ((XRadioButtonGroup) comp);
673: if (checkBoxGroup == null) {
674: // The radio button may already have a group
675: if (rb.getRadioButtonGroup() == null)
676: checkBoxGroup = rb.createGroup();
677: else
678: checkBoxGroup = rb.getRadioButtonGroup();
679: } else
680: rb.setRadioButtonGroup(checkBoxGroup);
681: } else
682: checkBoxGroup = null;
683:
684: // Setup any extra attributes specified in the XML
685: setComponentAttributes(childName, comp, componentAttributes);
686: } catch (Exception e) {
687: if (BuildProperties.DEBUG)
688: DebugLogger
689: .logError("While adding the component element: "
690: + nameStr);
691: e.printStackTrace();
692: }
693:
694: return comp;
695: }
696:
697: protected void setupPage(XmlElement model, String pageName,
698: boolean include) {
699: String className = model.getAttribute("class");
700: if (className == null) {
701: // Try to get a default startup class name if none has been specified in the XML
702: try {
703: className = currentProject
704: .getStartupParam("DefaultClass");
705: } catch (Exception ex) {
706: }
707: if (className == null)
708: className = "net.xoetrope.xui.XPage";
709: }
710:
711: if (!include) {
712: if ((className.indexOf('.') <= 0)
713: && (packageName.length() > 1))
714: className = packageName + className;
715: try {
716: page = loadClass(className);
717: } catch (Exception e) {
718: if (BuildProperties.DEBUG)
719: DebugLogger
720: .trace("Unable to load the named class: "
721: + className);
722: page = new XPage();
723: }
724: setPageName(pageName);
725:
726: componentFactory.setParentComponent((Container) page);
727: String styleName = model.getAttribute("style");
728: if (styleName != null)
729: componentFactory.applyStyle(page, styleName);
730: }
731: String layoutStyle = model.getAttribute("layoutStyle");
732: if (layoutStyle == null)
733: layoutStyle = "BoxLayout";
734: Hashtable ht = new Hashtable();
735: ht.put("isHorz", "1");
736: componentFactory.addLayout(null, layoutHelper
737: .getLayoutType("box"), ht);
738:
739: int width = 0, height = 0;
740: Enumeration attribNamesEnum = model.enumerateAttributeNames();
741: while (attribNamesEnum.hasMoreElements()) {
742: String attribName = (String) attribNamesEnum.nextElement();
743: String attribValue = (String) model
744: .getAttribute(attribName);
745: page.setAttribute(attribName, null, page
746: .evaluateAttribute(attribValue));
747: if (attribName.compareTo("resource") == 0) {
748: String resName;
749: if ((attribValue != null) && (attribValue.length() > 0))
750: resName = page.evaluatePath(attribValue);
751: else
752: resName = currentProject
753: .getStartupParam("Language");
754: componentFactory.setResourceBundle(resName);
755: page.getComponentFactory().setResourceBundle(resName);
756: }
757: }
758:
759: rootPage = (XPage) page;
760: }
761:
762: protected void setupModel(String pageName) {
763: try {
764: int pos = pageName.lastIndexOf('-');
765: if (pos > 0) {
766: String modelName = pageName.substring(0, pos + 1)
767: + "model.xml";
768: Reader reader = currentProject
769: .getBufferedReader(modelName);
770: XmlElement model = XmlSource.read(reader);
771: if (model.getName().indexOf("model") >= 0)
772: readModel(model);
773: else {
774: Vector children = model.getChildren();
775: int numChildren = children.size();
776: for (int i = 0; i < numChildren; i++)
777: readModel((XmlElement) children.elementAt(i));
778: }
779: }
780: } catch (Exception ex) {
781: if (BuildProperties.DEBUG)
782: DebugLogger
783: .logWarning("Unable to read the XForms model file for page:"
784: + pageName);
785: }
786: }
787:
788: protected String getComponentRenderType(String childType) {
789: if (childType.equals("choices")) {
790: if (selectStyle == XPage.COMBO)
791: return "combo";
792: }
793: return childType;
794: }
795:
796: protected String getEventType(String event) {
797: if (event == null)
798: return null;
799:
800: if (event.equals("xforms-focus"))
801: return "FocusHandler";
802: else if (event.equals("submit"))
803: return "ActionHandler";
804:
805: return null;
806: }
807:
808: protected void setupFormTags() {
809: if (formTags == null) {
810: formTags = new Hashtable();
811: formTags.put("select", new Integer(SELECT));
812: formTags.put("select1", new Integer(SELECT1));
813: formTags.put("input", new Integer(INPUT));
814: formTags.put("secret", new Integer(SECRET));
815: formTags.put("textarea", new Integer(TEXTAREA));
816: formTags.put("model", new Integer(MODEL));
817: formTags.put("group", new Integer(GROUP));
818: formTags.put("range", new Integer(RANGE));
819: formTags.put("upload", new Integer(UPLOAD));
820: formTags.put("trigger", new Integer(TRIGGER));
821: formTags.put("submit", new Integer(SUBMIT));
822: }
823: }
824:
825: /**
826: * Get the page loader type - a unique name identifying the loader
827: * @return "xforms"
828: */
829: public String getType() {
830: return "xforms";
831: }
832: }
|