KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > widget > screen > ModelScreenWidget


1 /*
2  * $Id: ModelScreenWidget.java 7045 2006-03-22 08:46:16Z jonesde $
3  *
4  * Copyright (c) 2004-2005 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */

24 package org.ofbiz.widget.screen;
25
26 import java.io.IOException JavaDoc;
27 import java.io.Serializable JavaDoc;
28 import java.io.Writer JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.LinkedList JavaDoc;
33 import java.util.List JavaDoc;
34 import java.util.Map JavaDoc;
35
36 import javax.servlet.http.HttpServletRequest JavaDoc;
37 import javax.servlet.http.HttpServletResponse JavaDoc;
38 import javax.xml.parsers.ParserConfigurationException JavaDoc;
39
40 import org.ofbiz.base.util.Debug;
41 import org.ofbiz.base.util.GeneralException;
42 import org.ofbiz.base.util.UtilFormatOut;
43 import org.ofbiz.base.util.UtilValidate;
44 import org.ofbiz.base.util.UtilXml;
45 import org.ofbiz.base.util.UtilMisc;
46 import org.ofbiz.base.util.collections.MapStack;
47 import org.ofbiz.base.util.string.FlexibleStringExpander;
48 import org.ofbiz.widget.form.FormFactory;
49 import org.ofbiz.widget.form.FormStringRenderer;
50 import org.ofbiz.widget.form.ModelForm;
51 import org.ofbiz.widget.html.HtmlFormRenderer;
52 import org.ofbiz.widget.html.HtmlMenuRenderer;
53 import org.ofbiz.widget.html.HtmlTreeRenderer;
54 import org.ofbiz.widget.menu.MenuFactory;
55 import org.ofbiz.widget.menu.MenuStringRenderer;
56 import org.ofbiz.widget.menu.ModelMenu;
57 import org.ofbiz.widget.tree.ModelTree;
58 import org.ofbiz.widget.tree.TreeFactory;
59 import org.ofbiz.widget.tree.TreeStringRenderer;
60 import org.ofbiz.entity.GenericDelegator;
61 import org.ofbiz.entity.GenericValue;
62 import org.ofbiz.entity.GenericEntityException;
63 import org.w3c.dom.Element JavaDoc;
64 import org.xml.sax.SAXException JavaDoc;
65
66 /**
67  * Widget Library - Screen model class
68  *
69  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
70  * @version $Rev: 7045 $
71  * @since 3.1
72  */

73 public abstract class ModelScreenWidget implements Serializable JavaDoc {
74     public static final String JavaDoc module = ModelScreenWidget.class.getName();
75
76     protected ModelScreen modelScreen;
77     
78     public ModelScreenWidget(ModelScreen modelScreen, Element JavaDoc widgetElement) {
79         this.modelScreen = modelScreen;
80         if (Debug.verboseOn()) Debug.logVerbose("Reading Screen sub-widget with name: " + widgetElement.getNodeName(), module);
81     }
82     
83     public abstract void renderWidgetString(Writer JavaDoc writer, Map JavaDoc context, ScreenStringRenderer screenStringRenderer) throws GeneralException;
84
85     public abstract String JavaDoc rawString();
86     
87     public static List JavaDoc readSubWidgets(ModelScreen modelScreen, List JavaDoc subElementList) {
88         List JavaDoc subWidgets = new LinkedList JavaDoc();
89         
90         Iterator JavaDoc subElementIter = subElementList.iterator();
91         while (subElementIter.hasNext()) {
92             Element JavaDoc subElement = (Element JavaDoc) subElementIter.next();
93
94             if ("section".equals(subElement.getNodeName())) {
95                 subWidgets.add(new Section(modelScreen, subElement));
96             } else if ("container".equals(subElement.getNodeName())) {
97                 subWidgets.add(new Container(modelScreen, subElement));
98             } else if ("include-screen".equals(subElement.getNodeName())) {
99                 subWidgets.add(new IncludeScreen(modelScreen, subElement));
100             } else if ("decorator-screen".equals(subElement.getNodeName())) {
101                 subWidgets.add(new DecoratorScreen(modelScreen, subElement));
102             } else if ("decorator-section-include".equals(subElement.getNodeName())) {
103                 subWidgets.add(new DecoratorSectionInclude(modelScreen, subElement));
104             } else if ("label".equals(subElement.getNodeName())) {
105                 subWidgets.add(new Label(modelScreen, subElement));
106             } else if ("include-form".equals(subElement.getNodeName())) {
107                 subWidgets.add(new Form(modelScreen, subElement));
108             } else if ("include-menu".equals(subElement.getNodeName())) {
109                 subWidgets.add(new Menu(modelScreen, subElement));
110             } else if ("include-tree".equals(subElement.getNodeName())) {
111                 subWidgets.add(new Tree(modelScreen, subElement));
112             } else if ("content".equals(subElement.getNodeName())) {
113                 subWidgets.add(new Content(modelScreen, subElement));
114             } else if ("sub-content".equals(subElement.getNodeName())) {
115                 subWidgets.add(new SubContent(modelScreen, subElement));
116             } else if ("platform-specific".equals(subElement.getNodeName())) {
117                 subWidgets.add(new PlatformSpecific(modelScreen, subElement));
118             } else if ("link".equals(subElement.getNodeName())) {
119                 subWidgets.add(new Link(modelScreen, subElement));
120             } else if ("image".equals(subElement.getNodeName())) {
121                 subWidgets.add(new Image(modelScreen, subElement));
122             } else if ("iterate-section".equals(subElement.getNodeName())) {
123                 subWidgets.add(new IterateSectionWidget(modelScreen, subElement));
124             } else {
125                 throw new IllegalArgumentException JavaDoc("Found invalid screen widget element with name: " + subElement.getNodeName());
126             }
127         }
128         
129         return subWidgets;
130     }
131     
132     public static void renderSubWidgetsString(List JavaDoc subWidgets, Writer JavaDoc writer, Map JavaDoc context, ScreenStringRenderer screenStringRenderer) throws GeneralException {
133         if (subWidgets == null) {
134             return;
135         }
136         Iterator JavaDoc subWidgetIter = subWidgets.iterator();
137         while (subWidgetIter.hasNext()) {
138             ModelScreenWidget subWidget = (ModelScreenWidget) subWidgetIter.next();
139             if (Debug.verboseOn()) Debug.logVerbose("Rendering screen " + subWidget.modelScreen.name + " widget " + subWidget.getClass().getName(), module);
140
141             Map JavaDoc parameters = (Map JavaDoc) context.get("parameters");
142             boolean insertWidgetBoundaryComments = "true".equals(parameters==null?null:parameters.get("widgetVerbose"));
143             StringBuffer JavaDoc widgetDescription = null;
144             if (insertWidgetBoundaryComments) {
145                 widgetDescription = new StringBuffer JavaDoc();
146                 widgetDescription.append("Widget [screen:");
147                 widgetDescription.append(subWidget.modelScreen.name);
148                 widgetDescription.append("] ");
149                 widgetDescription.append(subWidget.rawString());
150                 
151                 try {
152                     writer.write("<!-- === BEGIN ");
153                     writer.write(widgetDescription.toString());
154                     writer.write(" -->\n");
155                 } catch (IOException JavaDoc e) {
156                     throw new GeneralException("Error adding verbose sub-widget HTML/XML comments:", e);
157                 }
158             }
159             
160             // render the sub-widget itself
161
subWidget.renderWidgetString(writer, context, screenStringRenderer);
162             
163             if (insertWidgetBoundaryComments) {
164                 try {
165                     writer.write("\n<!-- === END ");
166                     writer.write(widgetDescription.toString());
167                     writer.write(" -->\n");
168                 } catch (IOException JavaDoc e) {
169                     throw new GeneralException("Error adding verbose sub-widget HTML/XML comments:", e);
170                 }
171             }
172         }
173     }
174
175     public static class SectionsRenderer {
176         protected Map JavaDoc sectionMap;
177         protected ScreenStringRenderer screenStringRenderer;
178         protected Map JavaDoc context;
179         protected Writer JavaDoc writer;
180         
181         public SectionsRenderer(Map JavaDoc sectionMap, Map JavaDoc context, Writer JavaDoc writer, ScreenStringRenderer screenStringRenderer) {
182             this.sectionMap = sectionMap;
183             this.context = context;
184             this.writer = writer;
185             this.screenStringRenderer = screenStringRenderer;
186         }
187
188         /** This is a lot like the ScreenRenderer class and returns an empty String so it can be used more easily with FreeMarker */
189         public String JavaDoc render(String JavaDoc sectionName) throws GeneralException {
190             ModelScreenWidget section = (ModelScreenWidget) this.sectionMap.get(sectionName);
191             // if no section by that name, write nothing
192
if (section != null) {
193                 section.renderWidgetString(this.writer, this.context, this.screenStringRenderer);
194             }
195             return "";
196         }
197     }
198
199     public static class Section extends ModelScreenWidget {
200         protected String JavaDoc name;
201         protected ModelScreenCondition condition;
202         protected List JavaDoc actions;
203         protected List JavaDoc subWidgets;
204         protected List JavaDoc failWidgets;
205         
206         public Section(ModelScreen modelScreen, Element JavaDoc sectionElement) {
207             super(modelScreen, sectionElement);
208             this.name = sectionElement.getAttribute("name");
209
210             // read condition under the "condition" element
211
Element JavaDoc conditionElement = UtilXml.firstChildElement(sectionElement, "condition");
212             if (conditionElement != null) {
213                 this.condition = new ModelScreenCondition(modelScreen, conditionElement);
214             }
215
216             // read all actions under the "actions" element
217
Element JavaDoc actionsElement = UtilXml.firstChildElement(sectionElement, "actions");
218             if (actionsElement != null) {
219                 this.actions = ModelScreenAction.readSubActions(modelScreen, actionsElement);
220             }
221             
222             // read sub-widgets
223
Element JavaDoc widgetsElement = UtilXml.firstChildElement(sectionElement, "widgets");
224             List JavaDoc subElementList = UtilXml.childElementList(widgetsElement);
225             this.subWidgets = ModelScreenWidget.readSubWidgets(this.modelScreen, subElementList);
226
227             // read fail-widgets
228
Element JavaDoc failWidgetsElement = UtilXml.firstChildElement(sectionElement, "fail-widgets");
229             if (failWidgetsElement != null) {
230                 List JavaDoc failElementList = UtilXml.childElementList(failWidgetsElement);
231                 this.failWidgets = ModelScreenWidget.readSubWidgets(this.modelScreen, failElementList);
232             }
233         }
234
235         public void renderWidgetString(Writer JavaDoc writer, Map JavaDoc context, ScreenStringRenderer screenStringRenderer) throws GeneralException {
236             // check the condition, if there is one
237
boolean condTrue = true;
238             if (this.condition != null) {
239                 if (!this.condition.eval(context)) {
240                     condTrue = false;
241                 }
242             }
243             
244             // if condition does not exist or evals to true run actions and render widgets, otherwise render fail-widgets
245
if (condTrue) {
246                 // run the actions only if true
247
ModelScreenAction.runSubActions(this.actions, context);
248                 
249                 try {
250                     // section by definition do not themselves do anything, so this method will generally do nothing, but we'll call it anyway
251
screenStringRenderer.renderSectionBegin(writer, context, this);
252                     
253                     // render sub-widgets
254
renderSubWidgetsString(this.subWidgets, writer, context, screenStringRenderer);
255
256                     screenStringRenderer.renderSectionEnd(writer, context, this);
257                 } catch (IOException JavaDoc e) {
258                     String JavaDoc errMsg = "Error rendering widgets section [" + this.getName() + "] in screen named [" + this.modelScreen.getName() + "]: " + e.toString();
259                     Debug.logError(e, errMsg, module);
260                     throw new RuntimeException JavaDoc(errMsg);
261                 }
262             } else {
263                 try {
264                     // section by definition do not themselves do anything, so this method will generally do nothing, but we'll call it anyway
265
screenStringRenderer.renderSectionBegin(writer, context, this);
266                     
267                     // render sub-widgets
268
renderSubWidgetsString(this.failWidgets, writer, context, screenStringRenderer);
269
270                     screenStringRenderer.renderSectionEnd(writer, context, this);
271                 } catch (IOException JavaDoc e) {
272                     String JavaDoc errMsg = "Error rendering fail-widgets section [" + this.getName() + "] in screen named [" + this.modelScreen.getName() + "]: " + e.toString();
273                     Debug.logError(e, errMsg, module);
274                     throw new RuntimeException JavaDoc(errMsg);
275                 }
276             }
277             
278         }
279         
280         public String JavaDoc getName() {
281             return name;
282         }
283
284         public String JavaDoc rawString() {
285             return "<section" + (UtilValidate.isNotEmpty(this.name)?" name=\"" + this.name + "\"":"") + ">";
286         }
287     }
288
289     public static class Container extends ModelScreenWidget {
290         protected FlexibleStringExpander idExdr;
291         protected FlexibleStringExpander styleExdr;
292         protected List JavaDoc subWidgets;
293         
294         public Container(ModelScreen modelScreen, Element JavaDoc containerElement) {
295             super(modelScreen, containerElement);
296             this.idExdr = new FlexibleStringExpander(containerElement.getAttribute("id"));
297             this.styleExdr = new FlexibleStringExpander(containerElement.getAttribute("style"));
298             
299             // read sub-widgets
300
List JavaDoc subElementList = UtilXml.childElementList(containerElement);
301             this.subWidgets = ModelScreenWidget.readSubWidgets(this.modelScreen, subElementList);
302             return;
303         }
304
305         public void renderWidgetString(Writer JavaDoc writer, Map JavaDoc context, ScreenStringRenderer screenStringRenderer) throws GeneralException {
306             try {
307                 screenStringRenderer.renderContainerBegin(writer, context, this);
308                 
309                 // render sub-widgets
310
renderSubWidgetsString(this.subWidgets, writer, context, screenStringRenderer);
311
312                 screenStringRenderer.renderContainerEnd(writer, context, this);
313             } catch (IOException JavaDoc e) {
314                 String JavaDoc errMsg = "Error rendering container in screen named [" + this.modelScreen.getName() + "]: " + e.toString();
315                 Debug.logError(e, errMsg, module);
316                 throw new RuntimeException JavaDoc(errMsg);
317             }
318         }
319         
320         public String JavaDoc getId(Map JavaDoc context) {
321             return this.idExdr.expandString(context);
322         }
323         
324         public String JavaDoc getStyle(Map JavaDoc context) {
325             return this.styleExdr.expandString(context);
326         }
327
328         public String JavaDoc rawString() {
329             return "<container id=\"" + this.idExdr.getOriginal() + "\" style=\"" + this.styleExdr.getOriginal() + "\">";
330         }
331     }
332
333     public static class IncludeScreen extends ModelScreenWidget {
334         protected FlexibleStringExpander nameExdr;
335         protected FlexibleStringExpander locationExdr;
336         protected FlexibleStringExpander shareScopeExdr;
337         
338         public IncludeScreen(ModelScreen modelScreen, Element JavaDoc includeScreenElement) {
339             super(modelScreen, includeScreenElement);
340             this.nameExdr = new FlexibleStringExpander(includeScreenElement.getAttribute("name"));
341             this.locationExdr = new FlexibleStringExpander(includeScreenElement.getAttribute("location"));
342             this.shareScopeExdr = new FlexibleStringExpander(includeScreenElement.getAttribute("share-scope"));
343         }
344
345         public void renderWidgetString(Writer JavaDoc writer, Map JavaDoc context, ScreenStringRenderer screenStringRenderer) throws GeneralException {
346             // if we are not sharing the scope, protect it using the MapStack
347
boolean protectScope = !shareScope(context);
348             if (protectScope) {
349                 if (!(context instanceof MapStack)) {
350                     context = MapStack.create(context);
351                 }
352                 
353                 ((MapStack) context).push();
354                 
355                 // build the widgetpath
356
List JavaDoc widgetTrail = (List JavaDoc) context.get("_WIDGETTRAIL_");
357                 if (widgetTrail == null) {
358                     widgetTrail = new ArrayList JavaDoc();
359                 }
360                 
361                 String JavaDoc thisName = nameExdr.expandString(context);
362                 widgetTrail.add(thisName);
363                 context.put("_WIDGETTRAIL_", widgetTrail);
364             }
365             
366             // dont need the renderer here, will just pass this on down to another screen call; screenStringRenderer.renderContainerBegin(writer, context, this);
367
String JavaDoc name = this.getName(context);
368             String JavaDoc location = this.getLocation(context);
369             
370             if (UtilValidate.isEmpty(name)) {
371                 if (Debug.infoOn()) Debug.logInfo("In the include-screen tag the screen name was empty, ignoring include; in screen [" + this.modelScreen.getName() + "]", module);
372                 return;
373             }
374             
375             // check to see if the name is a composite name separated by a #, if so split it up and get it by the full loc#name
376
if (ScreenFactory.isCombinedName(name)) {
377                 String JavaDoc combinedName = name;
378                 location = ScreenFactory.getResourceNameFromCombined(combinedName);
379                 name = ScreenFactory.getScreenNameFromCombined(combinedName);
380             }
381             
382             ModelScreen modelScreen = null;
383             if (UtilValidate.isNotEmpty(location)) {
384                 try {
385                     modelScreen = ScreenFactory.getScreenFromLocation(location, name);
386                 } catch (IOException JavaDoc e) {
387                     String JavaDoc errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString();
388                     Debug.logError(e, errMsg, module);
389                     throw new RuntimeException JavaDoc(errMsg);
390                 } catch (SAXException JavaDoc e) {
391                     String JavaDoc errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString();
392                     Debug.logError(e, errMsg, module);
393                     throw new RuntimeException JavaDoc(errMsg);
394                 } catch (ParserConfigurationException JavaDoc e) {
395                     String JavaDoc errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString();
396                     Debug.logError(e, errMsg, module);
397                     throw new RuntimeException JavaDoc(errMsg);
398                 }
399             } else {
400                 modelScreen = (ModelScreen) this.modelScreen.modelScreenMap.get(name);
401                 if (modelScreen == null) {
402                     throw new IllegalArgumentException JavaDoc("Could not find screen with name [" + name + "] in the same file as the screen with name [" + this.modelScreen.getName() + "]");
403                 }
404             }
405             modelScreen.renderScreenString(writer, context, screenStringRenderer);
406
407             if (protectScope) {
408                 ((MapStack) context).pop();
409             }
410         }
411         
412         public String JavaDoc getName(Map JavaDoc context) {
413             return this.nameExdr.expandString(context);
414         }
415         
416         public String JavaDoc getLocation(Map JavaDoc context) {
417             return this.locationExdr.expandString(context);
418         }
419         
420         public boolean shareScope(Map JavaDoc context) {
421             String JavaDoc shareScopeString = this.shareScopeExdr.expandString(context);
422             // defaults to false, so anything but true is false
423
return "true".equals(shareScopeString);
424         }
425
426         public String JavaDoc rawString() {
427             return "<include-screen name=\"" + this.nameExdr.getOriginal() + "\" location=\"" + this.locationExdr.getOriginal() + "\" share-scope=\"" + this.shareScopeExdr.getOriginal() + "\"/>";
428         }
429     }
430
431     public static class DecoratorScreen extends ModelScreenWidget {
432         protected FlexibleStringExpander nameExdr;
433         protected FlexibleStringExpander locationExdr;
434         protected Map JavaDoc sectionMap = new HashMap JavaDoc();
435         
436         public DecoratorScreen(ModelScreen modelScreen, Element JavaDoc decoratorScreenElement) {
437             super(modelScreen, decoratorScreenElement);
438             this.nameExdr = new FlexibleStringExpander(decoratorScreenElement.getAttribute("name"));
439             this.locationExdr = new FlexibleStringExpander(decoratorScreenElement.getAttribute("location"));
440             
441             List JavaDoc decoratorSectionElementList = UtilXml.childElementList(decoratorScreenElement, "decorator-section");
442             Iterator JavaDoc decoratorSectionElementIter = decoratorSectionElementList.iterator();
443             while (decoratorSectionElementIter.hasNext()) {
444                 Element JavaDoc decoratorSectionElement = (Element JavaDoc) decoratorSectionElementIter.next();
445                 String JavaDoc name = decoratorSectionElement.getAttribute("name");
446                 this.sectionMap.put(name, new DecoratorSection(modelScreen, decoratorSectionElement));
447             }
448         }
449
450         public void renderWidgetString(Writer JavaDoc writer, Map JavaDoc context, ScreenStringRenderer screenStringRenderer) throws GeneralException {
451             // isolate the scope
452
if (!(context instanceof MapStack)) {
453                 context = MapStack.create(context);
454             }
455             
456             MapStack contextMs = (MapStack) context;
457
458             // create a standAloneStack, basically a "save point" for this SectionsRenderer, and make a new "screens" object just for it so it is isolated and doesn't follow the stack down
459
MapStack standAloneStack = contextMs.standAloneChildStack();
460             standAloneStack.put("screens", new ScreenRenderer(writer, contextMs, screenStringRenderer));
461             SectionsRenderer sections = new SectionsRenderer(this.sectionMap, standAloneStack, writer, screenStringRenderer);
462             
463             // put the sectionMap in the context, make sure it is in the sub-scope, ie after calling push on the MapStack
464
contextMs.push();
465             context.put("sections", sections);
466             
467             String JavaDoc name = this.getName(context);
468             String JavaDoc location = this.getLocation(context);
469             
470             // check to see if the name is a composite name separated by a #, if so split it up and get it by the full loc#name
471
if (ScreenFactory.isCombinedName(name)) {
472                 String JavaDoc combinedName = name;
473                 location = ScreenFactory.getResourceNameFromCombined(combinedName);
474                 name = ScreenFactory.getScreenNameFromCombined(combinedName);
475             }
476             
477             ModelScreen modelScreen = null;
478             if (UtilValidate.isNotEmpty(location)) {
479                 try {
480                     modelScreen = ScreenFactory.getScreenFromLocation(location, name);
481                 } catch (IOException JavaDoc e) {
482                     String JavaDoc errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString();
483                     Debug.logError(e, errMsg, module);
484                     throw new RuntimeException JavaDoc(errMsg);
485                 } catch (SAXException JavaDoc e) {
486                     String JavaDoc errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString();
487                     Debug.logError(e, errMsg, module);
488                     throw new RuntimeException JavaDoc(errMsg);
489                 } catch (ParserConfigurationException JavaDoc e) {
490                     String JavaDoc errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString();
491                     Debug.logError(e, errMsg, module);
492                     throw new RuntimeException JavaDoc(errMsg);
493                 }
494             } else {
495                 modelScreen = (ModelScreen) this.modelScreen.modelScreenMap.get(name);
496                 if (modelScreen == null) {
497                     throw new IllegalArgumentException JavaDoc("Could not find screen with name [" + name + "] in the same file as the screen with name [" + this.modelScreen.getName() + "]");
498                 }
499             }
500             modelScreen.renderScreenString(writer, context, screenStringRenderer);
501
502             contextMs.pop();
503         }
504
505         public String JavaDoc getName(Map JavaDoc context) {
506             return this.nameExdr.expandString(context);
507         }
508         
509         public String JavaDoc getLocation(Map JavaDoc context) {
510             return this.locationExdr.expandString(context);
511         }
512
513         public String JavaDoc rawString() {
514             return "<decorator-screen name=\"" + this.nameExdr.getOriginal() + "\" location=\"" + this.locationExdr.getOriginal() + "\"/>";
515         }
516     }
517
518     public static class DecoratorSection extends ModelScreenWidget {
519         protected String JavaDoc name;
520         protected List JavaDoc subWidgets;
521         
522         public DecoratorSection(ModelScreen modelScreen, Element JavaDoc decoratorSectionElement) {
523             super(modelScreen, decoratorSectionElement);
524             this.name = decoratorSectionElement.getAttribute("name");
525             // read sub-widgets
526
List JavaDoc subElementList = UtilXml.childElementList(decoratorSectionElement);
527             this.subWidgets = ModelScreenWidget.readSubWidgets(this.modelScreen, subElementList);
528         }
529
530         public void renderWidgetString(Writer JavaDoc writer, Map JavaDoc context, ScreenStringRenderer screenStringRenderer) throws GeneralException {
531             // render sub-widgets
532
renderSubWidgetsString(this.subWidgets, writer, context, screenStringRenderer);
533         }
534
535         public String JavaDoc rawString() {
536             return "<decorator-section name=\"" + this.name + "\">";
537         }
538     }
539     
540     public static class DecoratorSectionInclude extends ModelScreenWidget {
541         protected String JavaDoc name;
542         
543         public DecoratorSectionInclude(ModelScreen modelScreen, Element JavaDoc decoratorSectionElement) {
544             super(modelScreen, decoratorSectionElement);
545             this.name = decoratorSectionElement.getAttribute("name");
546         }
547
548         public void renderWidgetString(Writer JavaDoc writer, Map JavaDoc context, ScreenStringRenderer screenStringRenderer) throws GeneralException {
549             SectionsRenderer sections = (SectionsRenderer) context.get("sections");
550             // for now if sections is null, just log a warning; may be permissible to make the screen for flexible
551
if (sections == null) {
552                 Debug.logWarning("In decorator-section-include could not find sections object in the context, not rendering section with name [" + this.name + "]", module);
553             } else {
554                 sections.render(this.name);
555             }
556         }
557
558         public String JavaDoc rawString() {
559             return "<decorator-section-include name=\"" + this.name + "\">";
560         }
561     }
562     
563     public static class Label extends ModelScreenWidget {
564         protected FlexibleStringExpander textExdr;
565         
566         protected FlexibleStringExpander idExdr;
567         protected FlexibleStringExpander styleExdr;
568         
569         public Label(ModelScreen modelScreen, Element JavaDoc labelElement) {
570             super(modelScreen, labelElement);
571
572             // put the text attribute first, then the pcdata under the element, if both are there of course
573
String JavaDoc textAttr = UtilFormatOut.checkNull(labelElement.getAttribute("text"));
574             String JavaDoc pcdata = UtilFormatOut.checkNull(UtilXml.elementValue(labelElement));
575             this.textExdr = new FlexibleStringExpander(textAttr + pcdata);
576
577             this.idExdr = new FlexibleStringExpander(labelElement.getAttribute("id"));
578             this.styleExdr = new FlexibleStringExpander(labelElement.getAttribute("style"));
579         }
580
581         public void renderWidgetString(Writer JavaDoc writer, Map JavaDoc context, ScreenStringRenderer screenStringRenderer) {
582             try {
583                 screenStringRenderer.renderLabel(writer, context, this);
584             } catch (IOException JavaDoc e) {
585                 String JavaDoc errMsg = "Error rendering label in screen named [" + this.modelScreen.getName() + "]: " + e.toString();
586                 Debug.logError(e, errMsg, module);
587                 throw new RuntimeException JavaDoc(errMsg);
588             }
589         }
590         
591         public String JavaDoc getText(Map JavaDoc context) {
592             return this.textExdr.expandString(context);
593         }
594         
595         public String JavaDoc getId(Map JavaDoc context) {
596             return this.idExdr.expandString(context);
597         }
598         
599         public String JavaDoc getStyle(Map JavaDoc context) {
600             return this.styleExdr.expandString(context);
601         }
602         
603         public String JavaDoc rawString() {
604             return "<label id=\"" + this.idExdr.getOriginal() + "\" style=\"" + this.styleExdr.getOriginal() + "\" text=\"" + this.textExdr.getOriginal() + "\"/>";
605         }
606     }
607
608     public static class Form extends ModelScreenWidget {
609         protected FlexibleStringExpander nameExdr;
610         protected FlexibleStringExpander locationExdr;
611         protected FlexibleStringExpander shareScopeExdr;
612         
613         public Form(ModelScreen modelScreen, Element JavaDoc formElement) {
614             super(modelScreen, formElement);
615
616             this.nameExdr = new FlexibleStringExpander(formElement.getAttribute("name"));
617             this.locationExdr = new FlexibleStringExpander(formElement.getAttribute("location"));
618             this.shareScopeExdr = new FlexibleStringExpander(formElement.getAttribute("share-scope"));
619         }
620
621         public void renderWidgetString(Writer JavaDoc writer, Map JavaDoc context, ScreenStringRenderer screenStringRenderer) {
622             boolean protectScope = !shareScope(context);
623             if (protectScope) {
624                 if (!(context instanceof MapStack)) {
625                     context = MapStack.create(context);
626                 }
627                 ((MapStack) context).push();
628             }
629             
630             String JavaDoc name = this.getName(context);
631             String JavaDoc location = this.getLocation(context);
632             ModelForm modelForm = null;
633             try {
634                 modelForm = FormFactory.getFormFromLocation(this.getLocation(context), this.getName(context), this.modelScreen.getDelegator(context), this.modelScreen.getDispatcher(context));
635             } catch (IOException JavaDoc e) {
636                 String JavaDoc errMsg = "Error rendering included form named [" + name + "] at location [" + location + "]: " + e.toString();
637                 Debug.logError(e, errMsg, module);
638                 throw new RuntimeException JavaDoc(errMsg);
639             } catch (SAXException JavaDoc e) {
640                 String JavaDoc errMsg = "Error rendering included form named [" + name + "] at location [" + location + "]: " + e.toString();
641                 Debug.logError(e, errMsg, module);
642                 throw new RuntimeException JavaDoc(errMsg);
643             } catch (ParserConfigurationException JavaDoc e) {
644                 String JavaDoc errMsg = "Error rendering included form named [" + name + "] at location [" + location + "]: " + e.toString();
645                 Debug.logError(e, errMsg, module);
646                 throw new RuntimeException JavaDoc(errMsg);
647             }
648             
649             // try finding the formStringRenderer by name in the context in case one was prepared and put there
650
FormStringRenderer formStringRenderer = (FormStringRenderer) context.get("formStringRenderer");
651             // if there was no formStringRenderer put in place, now try finding the request/response in the context and creating a new one
652
if (formStringRenderer == null) {
653                 HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) context.get("request");
654                 HttpServletResponse JavaDoc response = (HttpServletResponse JavaDoc) context.get("response");
655                 if (request != null && response != null) {
656                     formStringRenderer = new HtmlFormRenderer(request, response);
657                 }
658             }
659             // still null, throw an error
660
if (formStringRenderer == null) {
661                 throw new IllegalArgumentException JavaDoc("Could not find a formStringRenderer in the context, and could not find HTTP request/response objects need to create one.");
662             }
663             
664             //Debug.logInfo("before renderFormString, context:" + context, module);
665
StringBuffer JavaDoc renderBuffer = new StringBuffer JavaDoc();
666             modelForm.renderFormString(renderBuffer, context, formStringRenderer);
667             try {
668                 writer.write(renderBuffer.toString());
669             } catch (IOException JavaDoc e) {
670                 String JavaDoc errMsg = "Error rendering included form named [" + name + "] at location [" + location + "]: " + e.toString();
671                 Debug.logError(e, errMsg, module);
672                 throw new RuntimeException JavaDoc(errMsg);
673             }
674
675             if (protectScope) {
676                 ((MapStack) context).pop();
677             }
678         }
679         
680         public String JavaDoc getName(Map JavaDoc context) {
681             return this.nameExdr.expandString(context);
682         }
683         
684         public String JavaDoc getLocation(Map JavaDoc context) {
685             return this.locationExdr.expandString(context);
686         }
687         
688         public boolean shareScope(Map JavaDoc context) {
689             String JavaDoc shareScopeString = this.shareScopeExdr.expandString(context);
690             // defaults to false, so anything but true is false
691
return "true".equals(shareScopeString);
692         }
693
694         public String JavaDoc rawString() {
695             return "<include-form name=\"" + this.nameExdr.getOriginal() + "\" location=\"" + this.locationExdr.getOriginal() + "\" share-scope=\"" + this.shareScopeExdr.getOriginal() + "\"/>";
696         }
697     }
698
699     public static class Tree extends ModelScreenWidget {
700         protected FlexibleStringExpander nameExdr;
701         protected FlexibleStringExpander locationExdr;
702         protected FlexibleStringExpander shareScopeExdr;
703         
704         public Tree(ModelScreen modelScreen, Element JavaDoc treeElement) {
705             super(modelScreen, treeElement);
706
707             this.nameExdr = new FlexibleStringExpander(treeElement.getAttribute("name"));
708             this.locationExdr = new FlexibleStringExpander(treeElement.getAttribute("location"));
709             this.shareScopeExdr = new FlexibleStringExpander(treeElement.getAttribute("share-scope"));
710         }
711
712         public void renderWidgetString(Writer JavaDoc writer, Map JavaDoc context, ScreenStringRenderer screenStringRenderer) throws GeneralException {
713             boolean protectScope = !shareScope(context);
714             if (protectScope) {
715                 if (!(context instanceof MapStack)) {
716                     context = MapStack.create(context);
717                 }
718                 ((MapStack) context).push();
719             }
720             
721             String JavaDoc name = this.getName(context);
722             String JavaDoc location = this.getLocation(context);
723             ModelTree modelTree = null;
724             try {
725                 modelTree = TreeFactory.getTreeFromLocation(this.getLocation(context), this.getName(context), this.modelScreen.getDelegator(context), this.modelScreen.getDispatcher(context));
726             } catch (IOException JavaDoc e) {
727                 String JavaDoc errMsg = "Error rendering included tree named [" + name + "] at location [" + location + "]: " + e.toString();
728                 Debug.logError(e, errMsg, module);
729                 throw new RuntimeException JavaDoc(errMsg);
730             } catch (SAXException JavaDoc e) {
731                 String JavaDoc errMsg = "Error rendering included tree named [" + name + "] at location [" + location + "]: " + e.toString();
732                 Debug.logError(e, errMsg, module);
733                 throw new RuntimeException JavaDoc(errMsg);
734             } catch (ParserConfigurationException JavaDoc e) {
735                 String JavaDoc errMsg = "Error rendering included tree named [" + name + "] at location [" + location + "]: " + e.toString();
736                 Debug.logError(e, errMsg, module);
737                 throw new RuntimeException JavaDoc(errMsg);
738             }
739             
740             // try finding the treeStringRenderer by name in the context in case one was prepared and put there
741
TreeStringRenderer treeStringRenderer = (TreeStringRenderer) context.get("treeStringRenderer");
742             // if there was no treeStringRenderer put in place, now try finding the request/response in the context and creating a new one
743
if (treeStringRenderer == null) {
744                 treeStringRenderer = new HtmlTreeRenderer();
745                 /*
746                 String renderClassStyle = modelTree.getRenderStyle();
747                 if (UtilValidate.isNotEmpty(renderClassStyle) && renderClassStyle.equals("simple"))
748                     treeStringRenderer = new HtmlTreeRenderer();
749                 else
750                     treeStringRenderer = new HtmlTreeExpandCollapseRenderer();
751                 */

752             }
753             // still null, throw an error
754
if (treeStringRenderer == null) {
755                 throw new IllegalArgumentException JavaDoc("Could not find a treeStringRenderer in the context, and could not find HTTP request/response objects need to create one.");
756             }
757             
758             StringBuffer JavaDoc renderBuffer = new StringBuffer JavaDoc();
759             modelTree.renderTreeString(renderBuffer, context, treeStringRenderer);
760             try {
761                 writer.write(renderBuffer.toString());
762             } catch (IOException JavaDoc e) {
763                 String JavaDoc errMsg = "Error rendering included tree named [" + name + "] at location [" + location + "]: " + e.toString();
764                 Debug.logError(e, errMsg, module);
765                 throw new RuntimeException JavaDoc(errMsg);
766             }
767
768             if (protectScope) {
769                 ((MapStack) context).pop();
770             }
771         }
772         
773         public String JavaDoc getName(Map JavaDoc context) {
774             return this.nameExdr.expandString(context);
775         }
776         
777         public String JavaDoc getLocation(Map JavaDoc context) {
778             return this.locationExdr.expandString(context);
779         }
780         
781         public boolean shareScope(Map JavaDoc context) {
782             String JavaDoc shareScopeString = this.shareScopeExdr.expandString(context);
783             // defaults to false, so anything but true is false
784
return "true".equals(shareScopeString);
785         }
786
787         public String JavaDoc rawString() {
788             return "<include-tree name=\"" + this.nameExdr.getOriginal() + "\" location=\"" + this.locationExdr.getOriginal() + "\" share-scope=\"" + this.shareScopeExdr.getOriginal() + "\"/>";
789         }
790     }
791
792     public static class PlatformSpecific extends ModelScreenWidget {
793         protected ModelScreenWidget subWidget;
794         
795         public PlatformSpecific(ModelScreen modelScreen, Element JavaDoc platformSpecificElement) {
796             super(modelScreen, platformSpecificElement);
797             Element JavaDoc childElement = UtilXml.firstChildElement(platformSpecificElement);
798             if ("html".equals(childElement.getNodeName())) {
799                 subWidget = new HtmlWidget(modelScreen, childElement);
800             } else {
801                 throw new IllegalArgumentException JavaDoc("Tag not supported under the platform-specific tag with name: " + childElement.getNodeName());
802             }
803         }
804
805         public void renderWidgetString(Writer JavaDoc writer, Map JavaDoc context, ScreenStringRenderer screenStringRenderer) throws GeneralException {
806             subWidget.renderWidgetString(writer, context, screenStringRenderer);
807         }
808
809         public String JavaDoc rawString() {
810             return "<platform-specific>" + (this.subWidget==null?"":this.subWidget.rawString());
811         }
812     }
813
814     public static class Content extends ModelScreenWidget {
815         
816         protected FlexibleStringExpander contentId;
817         protected FlexibleStringExpander editRequest;
818         protected FlexibleStringExpander editContainerStyle;
819         protected FlexibleStringExpander enableEditName;
820         protected boolean xmlEscape = false;
821         protected FlexibleStringExpander dataResourceId;
822         protected String JavaDoc width;
823         protected String JavaDoc height;
824         protected String JavaDoc border;
825         
826         public Content(ModelScreen modelScreen, Element JavaDoc subContentElement) {
827             super(modelScreen, subContentElement);
828
829             // put the text attribute first, then the pcdata under the element, if both are there of course
830
this.contentId = new FlexibleStringExpander(subContentElement.getAttribute("content-id"));
831             this.dataResourceId = new FlexibleStringExpander(subContentElement.getAttribute("dataresource-id"));
832             this.editRequest = new FlexibleStringExpander(subContentElement.getAttribute("edit-request"));
833             this.editContainerStyle = new FlexibleStringExpander(subContentElement.getAttribute("edit-container-style"));
834             this.enableEditName = new FlexibleStringExpander(subContentElement.getAttribute("enable-edit-name"));
835             this.xmlEscape = "true".equals(subContentElement.getAttribute("xml-escape"));
836             this.width = subContentElement.getAttribute("width");
837             if (UtilValidate.isEmpty(this.width)) this.width="60%";
838             this.height = subContentElement.getAttribute("height");
839             if (UtilValidate.isEmpty(this.height)) this.width="400px";
840             this.border = subContentElement.getAttribute("border");
841             return;
842         }
843
844         public void renderWidgetString(Writer JavaDoc writer, Map JavaDoc context, ScreenStringRenderer screenStringRenderer) {
845             try {
846                 // pushing the contentId on the context as "contentId" is done
847
// because many times there will be embedded "subcontent" elements
848
// that use the syntax: <subcontent content-id="${contentId}"...
849
// and this is a step to make sure that it is there.
850
GenericDelegator delegator = (GenericDelegator) context.get("delegator");
851                 GenericValue content = null;
852                 String JavaDoc expandedDataResourceId = getDataResourceId(context);
853                 if (UtilValidate.isEmpty(expandedDataResourceId)) {
854                     String JavaDoc expandedContentId = getContentId(context);
855                     if (!(context instanceof MapStack)) {
856                         context = MapStack.create(context);
857                     }
858                     
859                     // This is an important step to make sure that the current contentId is in the context
860
// as templates that contain "subcontent" elements will expect to find the master
861
// contentId in the context as "contentId".
862
((MapStack) context).push();
863                     context.put("contentId", expandedContentId);
864                     
865                     if (UtilValidate.isNotEmpty(expandedContentId)) {
866                         content = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", expandedContentId));
867                     }
868                     expandedDataResourceId = content.getString("dataResourceId");
869                 }
870                 GenericValue dataResource = null;
871                 if (UtilValidate.isNotEmpty(expandedDataResourceId)) {
872                     dataResource = delegator.findByPrimaryKeyCache("DataResource", UtilMisc.toMap("dataResourceId", expandedDataResourceId));
873                 }
874                 
875                 String JavaDoc mimeTypeId = null;
876                 if (dataResource != null) {
877                     mimeTypeId = dataResource.getString("mimeTypeId");
878                 }
879                 
880                 if (UtilValidate.isNotEmpty(mimeTypeId)
881                         && ((mimeTypeId.indexOf("application") >= 0) || (mimeTypeId.indexOf("image")) >= 0) ) {
882                     screenStringRenderer.renderContentFrame(writer, context, this);
883                 } else {
884                     screenStringRenderer.renderContentBegin(writer, context, this);
885                     screenStringRenderer.renderContentBody(writer, context, this);
886                     screenStringRenderer.renderContentEnd(writer, context, this);
887                 }
888                 ((MapStack) context).pop();
889             } catch (IOException JavaDoc e) {
890                 String JavaDoc errMsg = "Error rendering content with contentId [" + getContentId(context) + "]: " + e.toString();
891                 Debug.logError(e, errMsg, module);
892                 throw new RuntimeException JavaDoc(errMsg);
893             } catch (GenericEntityException e) {
894                 String JavaDoc errMsg = "Error obtaining content with contentId [" + getContentId(context) + "]: " + e.toString();
895                 Debug.logError(e, errMsg, module);
896                 throw new RuntimeException JavaDoc(errMsg);
897             }
898
899         }
900         
901         public String JavaDoc getContentId(Map JavaDoc context) {
902             return this.contentId.expandString(context);
903         }
904         
905         public String JavaDoc getDataResourceId(Map JavaDoc context) {
906             return this.dataResourceId.expandString(context);
907         }
908         
909         public String JavaDoc getEditRequest(Map JavaDoc context) {
910             return this.editRequest.expandString(context);
911         }
912         
913         public String JavaDoc getEditContainerStyle(Map JavaDoc context) {
914             return this.editContainerStyle.expandString(context);
915         }
916         
917         public String JavaDoc getEnableEditName(Map JavaDoc context) {
918             return this.enableEditName.expandString(context);
919         }
920         
921         public boolean xmlEscape() {
922             return this.xmlEscape;
923         }
924         
925         public String JavaDoc rawString() {
926             // may want to expand this a bit more
927
return "<content content-id=\"" + this.contentId.getOriginal() + "\" xml-escape=\"" + this.xmlEscape + "\"/>";
928         }
929         
930         public String JavaDoc getWidth() {
931             return this.width;
932         }
933         
934         public String JavaDoc getHeight() {
935             return this.height;
936         }
937         
938         public String JavaDoc getBorder() {
939             return this.border;
940         }
941     }
942
943     public static class SubContent extends ModelScreenWidget {
944         protected FlexibleStringExpander contentId;
945         protected FlexibleStringExpander assocName;
946         protected FlexibleStringExpander editRequest;
947         protected FlexibleStringExpander editContainerStyle;
948         protected FlexibleStringExpander enableEditName;
949         protected boolean xmlEscape = false;
950         
951         public SubContent(ModelScreen modelScreen, Element JavaDoc subContentElement) {
952             super(modelScreen, subContentElement);
953
954             // put the text attribute first, then the pcdata under the element, if both are there of course
955
this.contentId = new FlexibleStringExpander(UtilFormatOut.checkNull(subContentElement.getAttribute("content-id")));
956             this.assocName = new FlexibleStringExpander(UtilFormatOut.checkNull(subContentElement.getAttribute("assoc-name")));
957             this.editRequest = new FlexibleStringExpander(UtilFormatOut.checkNull(subContentElement.getAttribute("edit-request")));
958             this.editContainerStyle = new FlexibleStringExpander(subContentElement.getAttribute("edit-container-style"));
959             this.enableEditName = new FlexibleStringExpander(subContentElement.getAttribute("enable-edit-name"));
960             this.xmlEscape = "true".equals(subContentElement.getAttribute("xml-escape"));
961
962         }
963
964         public void renderWidgetString(Writer JavaDoc writer, Map JavaDoc context, ScreenStringRenderer screenStringRenderer) {
965             try {
966                 screenStringRenderer.renderSubContentBegin(writer, context, this);
967                 screenStringRenderer.renderSubContentBody(writer, context, this);
968                 screenStringRenderer.renderSubContentEnd(writer, context, this);
969             } catch (IOException JavaDoc e) {
970                 String JavaDoc errMsg = "Error rendering subContent with contentId [" + getContentId(context) + "]: " + e.toString();
971                 Debug.logError(e, errMsg, module);
972                 throw new RuntimeException JavaDoc(errMsg);
973             }
974         }
975         
976         public String JavaDoc getContentId(Map JavaDoc context) {
977             return this.contentId.expandString(context);
978         }
979         
980         public String JavaDoc getAssocName(Map JavaDoc context) {
981             return this.assocName.expandString(context);
982         }
983         
984         public String JavaDoc getEditRequest(Map JavaDoc context) {
985             return this.editRequest.expandString(context);
986         }
987         
988         public String JavaDoc getEditContainerStyle(Map JavaDoc context) {
989             return this.editContainerStyle.expandString(context);
990         }
991         
992         public String JavaDoc getEnableEditName(Map JavaDoc context) {
993             return this.enableEditName.expandString(context);
994         }
995         
996         public boolean xmlEscape() {
997             return this.xmlEscape;
998         }
999
1000        public String JavaDoc rawString() {
1001            // may want to expand this a bit more
1002
return "<sub-content content-id=\"" + this.contentId.getOriginal() + "\" assoc-name=\"" + this.assocName.getOriginal() + "\" xml-escape=\"" + this.xmlEscape + "\"/>";
1003        }
1004    }
1005
1006    public static class Menu extends ModelScreenWidget {
1007        protected FlexibleStringExpander nameExdr;
1008        protected FlexibleStringExpander locationExdr;
1009        
1010        public Menu(ModelScreen modelScreen, Element JavaDoc menuElement) {
1011            super(modelScreen, menuElement);
1012
1013            this.nameExdr = new FlexibleStringExpander(menuElement.getAttribute("name"));
1014            this.locationExdr = new FlexibleStringExpander(menuElement.getAttribute("location"));
1015        }
1016
1017        public void renderWidgetString(Writer JavaDoc writer, Map JavaDoc context, ScreenStringRenderer screenStringRenderer) {
1018            String JavaDoc name = this.getName(context);
1019            String JavaDoc location = this.getLocation(context);
1020            ModelMenu modelMenu = null;
1021            try {
1022                modelMenu = MenuFactory.getMenuFromLocation(this.getLocation(context), this.getName(context), this.modelScreen.getDelegator(context), this.modelScreen.getDispatcher(context));
1023            } catch (IOException JavaDoc e) {
1024                String JavaDoc errMsg = "Error rendering included menu named [" + name + "] at location [" + location + "]: " + e.toString();
1025                Debug.logError(e, errMsg, module);
1026                throw new RuntimeException JavaDoc(errMsg);
1027            } catch (SAXException JavaDoc e) {
1028                String JavaDoc errMsg = "Error rendering included menu named [" + name + "] at location [" + location + "]: " + e.toString();
1029                Debug.logError(e, errMsg, module);
1030                throw new RuntimeException JavaDoc(errMsg);
1031            } catch (ParserConfigurationException JavaDoc e) {
1032                String JavaDoc errMsg = "Error rendering included menu named [" + name + "] at location [" + location + "]: " + e.toString();
1033                Debug.logError(e, errMsg, module);
1034                throw new RuntimeException JavaDoc(errMsg);
1035            }
1036            
1037            // try finding the menuStringRenderer by name in the context in case one was prepared and put there
1038
MenuStringRenderer menuStringRenderer = (MenuStringRenderer) context.get("menuStringRenderer");
1039            // if there was no menuStringRenderer put in place, now try finding the request/response in the context and creating a new one
1040
if (menuStringRenderer == null) {
1041                HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) context.get("request");
1042                HttpServletResponse JavaDoc response = (HttpServletResponse JavaDoc) context.get("response");
1043                if (request != null && response != null) {
1044                    menuStringRenderer = new HtmlMenuRenderer(request, response);
1045                }
1046            }
1047            // still null, throw an error
1048
if (menuStringRenderer == null) {
1049                throw new IllegalArgumentException JavaDoc("Could not find a menuStringRenderer in the context, and could not find HTTP request/response objects need to create one.");
1050            }
1051            
1052            StringBuffer JavaDoc renderBuffer = new StringBuffer JavaDoc();
1053            modelMenu.renderMenuString(renderBuffer, context, menuStringRenderer);
1054            try {
1055                writer.write(renderBuffer.toString());
1056            } catch (IOException JavaDoc e) {
1057                String JavaDoc errMsg = "Error rendering included menu named [" + name + "] at location [" + location + "]: " + e.toString();
1058                Debug.logError(e, errMsg, module);
1059                throw new RuntimeException JavaDoc(errMsg);
1060            }
1061        }
1062        
1063        public String JavaDoc getName(Map JavaDoc context) {
1064            return this.nameExdr.expandString(context);
1065        }
1066        
1067        public String JavaDoc getLocation(Map JavaDoc context) {
1068            return this.locationExdr.expandString(context);
1069        }
1070
1071        public String JavaDoc rawString() {
1072            return "<include-menu name=\"" + this.nameExdr.getOriginal() + "\" location=\"" + this.locationExdr.getOriginal() + "\"/>";
1073        }
1074    }
1075    
1076    public static class Link extends ModelScreenWidget {
1077        protected FlexibleStringExpander textExdr;
1078        protected FlexibleStringExpander idExdr;
1079        protected FlexibleStringExpander styleExdr;
1080        protected FlexibleStringExpander targetExdr;
1081        protected FlexibleStringExpander targetWindowExdr;
1082        protected FlexibleStringExpander prefixExdr;
1083        protected FlexibleStringExpander nameExdr;
1084        protected Image image;
1085        protected String JavaDoc urlMode = "intra-app";
1086        protected boolean fullPath = false;
1087        protected boolean secure = false;
1088        protected boolean encode = false;
1089        
1090
1091        public Link(ModelScreen modelScreen, Element JavaDoc linkElement) {
1092            super(modelScreen, linkElement);
1093
1094            setText(linkElement.getAttribute("text"));
1095            setId(linkElement.getAttribute("id"));
1096            setStyle(linkElement.getAttribute("style"));
1097            setName(linkElement.getAttribute("name"));
1098            setTarget(linkElement.getAttribute("target"));
1099            setTargetWindow(linkElement.getAttribute("target-window"));
1100            setPrefix(linkElement.getAttribute("prefix"));
1101            setUrlMode(linkElement.getAttribute("url-mode"));
1102            setFullPath(linkElement.getAttribute("full-path"));
1103            setSecure(linkElement.getAttribute("secure"));
1104            setEncode(linkElement.getAttribute("encode"));
1105            Element JavaDoc imageElement = UtilXml.firstChildElement(linkElement, "image");
1106            if (imageElement != null) {
1107                this.image = new Image(modelScreen, imageElement);
1108            }
1109
1110        }
1111
1112        public void renderWidgetString(Writer JavaDoc writer, Map JavaDoc context, ScreenStringRenderer screenStringRenderer) {
1113            try {
1114                screenStringRenderer.renderLink(writer, context, this);
1115            } catch (IOException JavaDoc e) {
1116                String JavaDoc errMsg = "Error rendering link with id [" + getId(context) + "]: " + e.toString();
1117                Debug.logError(e, errMsg, module);
1118                throw new RuntimeException JavaDoc(errMsg);
1119            }
1120        }
1121        
1122        public String JavaDoc getText(Map JavaDoc context) {
1123            return this.textExdr.expandString(context);
1124        }
1125        
1126        public String JavaDoc getId(Map JavaDoc context) {
1127            return this.idExdr.expandString(context);
1128        }
1129        
1130        public String JavaDoc getStyle(Map JavaDoc context) {
1131            return this.styleExdr.expandString(context);
1132        }
1133        
1134        public String JavaDoc getTarget(Map JavaDoc context) {
1135            return this.targetExdr.expandString(context);
1136        }
1137        
1138        public String JavaDoc getName(Map JavaDoc context) {
1139            return this.nameExdr.expandString(context);
1140        }
1141        
1142        public String JavaDoc getTargetWindow(Map JavaDoc context) {
1143            return this.targetWindowExdr.expandString(context);
1144        }
1145        
1146        public String JavaDoc getUrlMode() {
1147            return this.urlMode;
1148        }
1149        
1150        public String JavaDoc getPrefix(Map JavaDoc context) {
1151            return this.prefixExdr.expandString(context);
1152        }
1153        
1154        public boolean getFullPath() {
1155            return this.fullPath;
1156        }
1157        
1158        public boolean getSecure() {
1159            return this.secure;
1160        }
1161        
1162        public boolean getEncode() {
1163            return this.encode;
1164        }
1165        
1166        public Image getImage() {
1167            return this.image;
1168        }
1169
1170        public void setText(String JavaDoc val) {
1171            String JavaDoc textAttr = UtilFormatOut.checkNull(val);
1172            this.textExdr = new FlexibleStringExpander(textAttr);
1173        }
1174        public void setId(String JavaDoc val) {
1175            this.idExdr = new FlexibleStringExpander(val);
1176        }
1177        public void setStyle(String JavaDoc val) {
1178            this.styleExdr = new FlexibleStringExpander(val);
1179        }
1180        public void setTarget(String JavaDoc val) {
1181            this.targetExdr = new FlexibleStringExpander(val);
1182        }
1183        public void setName(String JavaDoc val) {
1184            this.nameExdr = new FlexibleStringExpander(val);
1185        }
1186        public void setTargetWindow(String JavaDoc val) {
1187            this.targetWindowExdr = new FlexibleStringExpander(val);
1188        }
1189        public void setPrefix(String JavaDoc val) {
1190            this.prefixExdr = new FlexibleStringExpander(val);
1191        }
1192        public void setUrlMode(String JavaDoc val) {
1193            if (UtilValidate.isNotEmpty(val))
1194                this.urlMode = val;
1195        }
1196        public void setFullPath(String JavaDoc val) {
1197            String JavaDoc sFullPath = val;
1198            if (sFullPath != null && sFullPath.equalsIgnoreCase("true"))
1199                this.fullPath = true;
1200            else
1201                this.fullPath = false;
1202        }
1203
1204        public void setSecure(String JavaDoc val) {
1205            String JavaDoc sSecure = val;
1206            if (sSecure != null && sSecure.equalsIgnoreCase("true"))
1207                this.secure = true;
1208            else
1209                this.secure = false;
1210        }
1211
1212        public void setEncode(String JavaDoc val) {
1213            String JavaDoc sEncode = val;
1214            if (sEncode != null && sEncode.equalsIgnoreCase("true"))
1215                this.encode = true;
1216            else
1217                this.encode = false;
1218        }
1219        public void setImage(Image img) {
1220            this.image = img;
1221        }
1222
1223        public String JavaDoc rawString() {
1224            // may want to add more to this
1225
return "<link id=\"" + this.idExdr.getOriginal() + "\" style=\"" + this.styleExdr.getOriginal() + "\" text=\"" + this.textExdr.getOriginal() + "\" target=\"" + this.targetExdr.getOriginal() + "\" name=\"" + this.nameExdr.getOriginal() + "\" url-mode=\"" + this.urlMode + "\"/>";
1226        }
1227    }
1228
1229    public static class Image extends ModelScreenWidget {
1230        protected FlexibleStringExpander srcExdr;
1231        protected FlexibleStringExpander idExdr;
1232        protected FlexibleStringExpander styleExdr;
1233        protected FlexibleStringExpander widthExdr;
1234        protected FlexibleStringExpander heightExdr;
1235        protected FlexibleStringExpander borderExdr;
1236        protected String JavaDoc urlMode = "content";
1237
1238        public Image(ModelScreen modelScreen, Element JavaDoc imageElement) {
1239            super(modelScreen, imageElement);
1240
1241            setSrc(imageElement.getAttribute("src"));
1242            setId(imageElement.getAttribute("id"));
1243            setStyle(imageElement.getAttribute("style"));
1244            setWidth(imageElement.getAttribute("width"));
1245            setHeight(imageElement.getAttribute("height"));
1246            setBorder(UtilFormatOut.checkEmpty(imageElement.getAttribute("border"), "0"));
1247            setUrlMode(UtilFormatOut.checkEmpty(imageElement.getAttribute("url-mode"), "content"));
1248        }
1249
1250        public void renderWidgetString(Writer JavaDoc writer, Map JavaDoc context, ScreenStringRenderer screenStringRenderer) {
1251            try {
1252                screenStringRenderer.renderImage(writer, context, this);
1253            } catch (IOException JavaDoc e) {
1254                String JavaDoc errMsg = "Error rendering image with id [" + getId(context) + "]: " + e.toString();
1255                Debug.logError(e, errMsg, module);
1256                throw new RuntimeException JavaDoc(errMsg);
1257            }
1258        }
1259        
1260        public String JavaDoc getSrc(Map JavaDoc context) {
1261            return this.srcExdr.expandString(context);
1262        }
1263        
1264        public String JavaDoc getId(Map JavaDoc context) {
1265            return this.idExdr.expandString(context);
1266        }
1267        
1268        public String JavaDoc getStyle(Map JavaDoc context) {
1269            return this.styleExdr.expandString(context);
1270        }
1271
1272        public String JavaDoc getWidth(Map JavaDoc context) {
1273            return this.widthExdr.expandString(context);
1274        }
1275
1276        public String JavaDoc getHeight(Map JavaDoc context) {
1277            return this.heightExdr.expandString(context);
1278        }
1279
1280        public String JavaDoc getBorder(Map JavaDoc context) {
1281            return this.borderExdr.expandString(context);
1282        }
1283        
1284        public String JavaDoc getUrlMode() {
1285            return this.urlMode;
1286        }
1287        
1288        public void setSrc(String JavaDoc val) {
1289            String JavaDoc textAttr = UtilFormatOut.checkNull(val);
1290            this.srcExdr = new FlexibleStringExpander(textAttr);
1291        }
1292        public void setId(String JavaDoc val) {
1293            this.idExdr = new FlexibleStringExpander(val);
1294        }
1295        public void setStyle(String JavaDoc val) {
1296            this.styleExdr = new FlexibleStringExpander(val);
1297        }
1298        public void setWidth(String JavaDoc val) {
1299            this.widthExdr = new FlexibleStringExpander(val);
1300        }
1301        public void setHeight(String JavaDoc val) {
1302            this.heightExdr = new FlexibleStringExpander(val);
1303        }
1304        public void setBorder(String JavaDoc val) {
1305            this.borderExdr = new FlexibleStringExpander(val);
1306        }
1307        public void setUrlMode(String JavaDoc val) {
1308            if (UtilValidate.isEmpty(val)) {
1309                this.urlMode = "content";
1310            } else {
1311                this.urlMode = val;
1312            }
1313        }
1314
1315        public String JavaDoc rawString() {
1316            // may want to add more to this
1317
return "<image id=\"" + this.idExdr.getOriginal() + "\" style=\"" + this.styleExdr.getOriginal() + "\" SRC=\"" + this.srcExdr.getOriginal() + "\" url-mode=\"" + this.urlMode + "\"/>";
1318        }
1319    }
1320}
1321
1322
Popular Tags