KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > widget > menu > ModelMenuItem


1 /*
2  * $Id: ModelMenuItem.java 5470 2005-08-07 16:07:37Z jonesde $
3  *
4  * Copyright (c) 2003 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.menu;
25
26 import java.io.IOException JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.LinkedList JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Map JavaDoc;
32
33 import javax.xml.parsers.ParserConfigurationException JavaDoc;
34
35 import org.ofbiz.base.util.Debug;
36 import org.ofbiz.base.util.UtilFormatOut;
37 import org.ofbiz.base.util.UtilValidate;
38 import org.ofbiz.base.util.UtilXml;
39 import org.ofbiz.base.util.string.FlexibleStringExpander;
40 import org.ofbiz.entityext.permission.EntityPermissionChecker;
41 import org.w3c.dom.Element JavaDoc;
42 import org.xml.sax.SAXException JavaDoc;
43
44 /**
45  * Widget Library - Form model class
46  *
47  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
48  * @author <a HREF="mailto:byersa@automationgroups.com">Al Byers</a>
49  * @version $Rev: 5470 $
50  * @since 2.2
51  */

52 public class ModelMenuItem {
53
54     public static final String JavaDoc module = ModelMenuItem.class.getName();
55
56     protected ModelMenu modelMenu;
57
58     protected Map JavaDoc dataMap = new HashMap JavaDoc();
59     protected String JavaDoc name;
60     protected String JavaDoc entityName;
61     protected FlexibleStringExpander title;
62     protected FlexibleStringExpander tooltip;
63     protected String JavaDoc titleStyle;
64     protected String JavaDoc disabledTitleStyle;
65     protected String JavaDoc widgetStyle;
66     protected String JavaDoc tooltipStyle;
67     protected String JavaDoc selectedStyle;
68     protected Integer JavaDoc position = null;
69
70     protected FlexibleStringExpander associatedContentId;
71     protected String JavaDoc cellWidth;
72     protected Boolean JavaDoc hideIfSelected;
73     protected Boolean JavaDoc hasPermission;
74     protected String JavaDoc disableIfEmpty;
75     protected ModelMenu subMenu;
76     protected Link link;
77     
78     protected List JavaDoc menuItemList = new LinkedList JavaDoc();
79     protected Map JavaDoc menuItemMap = new HashMap JavaDoc();
80
81
82     public static String JavaDoc DEFAULT_TARGET_TYPE = "intra-app";
83     
84     protected EntityPermissionChecker permissionChecker;
85     protected ModelMenuItem parentMenuItem;
86     protected ModelMenuCondition condition;
87     protected boolean disabled = false;
88     protected List JavaDoc actions;
89     protected String JavaDoc align;
90     protected String JavaDoc alignStyle;
91     
92     // ===== CONSTRUCTORS =====
93
/** Default Constructor */
94     public ModelMenuItem(ModelMenu modelMenu) {
95         this.modelMenu = modelMenu;
96     }
97
98     /** XML Constructor */
99     public ModelMenuItem(Element JavaDoc fieldElement, ModelMenuItem modelMenuItem) {
100         parentMenuItem = modelMenuItem;
101         loadMenuItem(fieldElement, modelMenuItem.getModelMenu());
102     }
103     
104
105     public ModelMenuItem(Element JavaDoc fieldElement, ModelMenu modelMenu) {
106         loadMenuItem(fieldElement, modelMenu);
107     }
108     
109     public void loadMenuItem(Element JavaDoc fieldElement, ModelMenu modelMenu) {
110         this.modelMenu = modelMenu;
111         this.name = fieldElement.getAttribute("name");
112         this.entityName = fieldElement.getAttribute("entity-name");
113         this.setTitle(fieldElement.getAttribute("title"));
114         this.setTooltip(fieldElement.getAttribute("tooltip"));
115         this.titleStyle = fieldElement.getAttribute("title-style");
116         this.disabledTitleStyle = fieldElement.getAttribute("disabled-title-style");
117         this.widgetStyle = fieldElement.getAttribute("widget-style");
118         this.tooltipStyle = fieldElement.getAttribute("tooltip-style");
119         this.selectedStyle = fieldElement.getAttribute("selected-style");
120         this.setHideIfSelected(fieldElement.getAttribute("hide-if-selected"));
121         this.disableIfEmpty = fieldElement.getAttribute("disable-if-empty");
122         this.align = fieldElement.getAttribute("align");
123         this.alignStyle = fieldElement.getAttribute("align-style");
124
125         String JavaDoc positionStr = fieldElement.getAttribute("position");
126         try {
127             if (positionStr != null && positionStr.length() > 0) {
128                 position = Integer.valueOf(positionStr);
129             }
130         } catch (Exception JavaDoc e) {
131             Debug.logError(
132                 e,
133                 "Could not convert position attribute of the field element to an integer: [" + positionStr + "], using the default of the menu renderer",
134                 module);
135         }
136
137         this.setAssociatedContentId( fieldElement.getAttribute("associated-content-id"));
138         this.cellWidth = fieldElement.getAttribute("cell-width");
139
140         dataMap.put("name", this.name);
141         //dataMap.put("associatedContentId", this.associatedContentId);
142

143         Element JavaDoc subMenuElement = UtilXml.firstChildElement(fieldElement, "sub-menu");
144         if (subMenuElement != null) {
145             String JavaDoc subMenuLocation = subMenuElement.getAttribute("location");
146             String JavaDoc subMenuName = subMenuElement.getAttribute("name");
147             try {
148                 this.subMenu = MenuFactory.getMenuFromLocation(subMenuLocation, subMenuName, modelMenu.getDelegator(), modelMenu.getDispacher());
149             } catch (IOException JavaDoc e) {
150                 String JavaDoc errMsg = "Error getting subMenu in menu named [" + this.modelMenu.getName() + "]: " + e.toString();
151                 Debug.logError(e, errMsg, module);
152                 throw new RuntimeException JavaDoc(errMsg);
153             } catch (SAXException JavaDoc e2) {
154                 String JavaDoc errMsg = "Error getting subMenu in menu named [" + this.modelMenu.getName() + "]: " + e2.toString();
155                 Debug.logError(e2, errMsg, module);
156                 throw new RuntimeException JavaDoc(errMsg);
157             } catch (ParserConfigurationException JavaDoc e3) {
158                 String JavaDoc errMsg = "Error getting subMenu in menu named [" + this.modelMenu.getName() + "]: " + e3.toString();
159                 Debug.logError(e3, errMsg, module);
160                 throw new RuntimeException JavaDoc(errMsg);
161             }
162         }
163         Element JavaDoc linkElement = UtilXml.firstChildElement(fieldElement, "link");
164         //if (Debug.infoOn()) Debug.logInfo("in ModelMenuItem, linkElement:" + linkElement, module);
165
if (linkElement != null) {
166             link = new Link(linkElement, this);
167         }
168         
169 // Element permissionElement = UtilXml.firstChildElement(fieldElement, "if-entity-permission");
170
// if (permissionElement != null)
171
// permissionChecker = new EntityPermissionChecker(permissionElement);
172

173         // read in add item defs, add/override one by one using the menuItemList and menuItemMap
174
List JavaDoc itemElements = UtilXml.childElementList(fieldElement, "menu-item");
175         Iterator JavaDoc itemElementIter = itemElements.iterator();
176         while (itemElementIter.hasNext()) {
177             Element JavaDoc itemElement = (Element JavaDoc) itemElementIter.next();
178             ModelMenuItem modelMenuItem = new ModelMenuItem(itemElement, this);
179             modelMenuItem = this.addUpdateMenuItem(modelMenuItem);
180             //Debug.logInfo("Added item " + modelMenuItem.getName() + " from def, mapName=" + modelMenuItem.getMapName(), module);
181
}
182         // read condition under the "condition" element
183
Element JavaDoc conditionElement = UtilXml.firstChildElement(fieldElement, "condition");
184         if (conditionElement != null) {
185             this.condition = new ModelMenuCondition(this, conditionElement);
186         }
187         // read all actions under the "actions" element
188
Element JavaDoc actionsElement = UtilXml.firstChildElement(conditionElement, "actions");
189         if (actionsElement != null) {
190             this.actions = ModelMenuAction.readSubActions(this, actionsElement);
191         }
192
193     }
194     
195     public ModelMenuItem addUpdateMenuItem(ModelMenuItem modelMenuItem) {
196
197         // not a conditional item, see if a named item exists in Map
198
ModelMenuItem existingMenuItem = (ModelMenuItem) this.menuItemMap.get(modelMenuItem.getName());
199         if (existingMenuItem != null) {
200             // does exist, update the item by doing a merge/override
201
existingMenuItem.mergeOverrideModelMenuItem(modelMenuItem);
202             return existingMenuItem;
203         } else {
204             // does not exist, add to List and Map
205
this.menuItemList.add(modelMenuItem);
206             this.menuItemMap.put(modelMenuItem.getName(), modelMenuItem);
207             return modelMenuItem;
208         }
209     }
210
211
212     public void setHideIfSelected(String JavaDoc val) {
213         if (UtilValidate.isNotEmpty(val))
214             if (val.equalsIgnoreCase("true"))
215                 hideIfSelected = new Boolean JavaDoc(true);
216             else
217                 hideIfSelected = new Boolean JavaDoc(false);
218         else
219             hideIfSelected = null;
220
221         return;
222     }
223
224     public void setDisabled(boolean val) {
225          this.disabled = val;
226     }
227
228     public boolean getDisabled() {
229          return this.disabled;
230     }
231
232     public void mergeOverrideModelMenuItem(ModelMenuItem overrideModelMenuItem) {
233         if (overrideModelMenuItem == null)
234             return;
235 /*
236         // incorporate updates for values that are not empty in the overrideMenuItem
237         if (UtilValidate.isNotEmpty(overrideMenuItem.name))
238             this.name = overrideMenuItem.name;
239         if (UtilValidate.isNotEmpty(overrideMenuItem.entityName))
240             this.entityName = overrideMenuItem.entityName;
241         if (overrideMenuItem.entryAcsr != null && !overrideMenuItem.entryAcsr.isEmpty())
242             this.entryAcsr = overrideMenuItem.entryAcsr;
243         if (UtilValidate.isNotEmpty(overrideMenuItem.attributeName))
244             this.attributeName = overrideMenuItem.attributeName;
245         if (overrideMenuItem.title != null && !overrideMenuItem.title.isEmpty())
246             this.title = overrideMenuItem.title;
247         if (overrideMenuItem.tooltip != null && !overrideMenuItem.tooltip.isEmpty())
248             this.tooltip = overrideMenuItem.tooltip;
249         if (UtilValidate.isNotEmpty(overrideMenuItem.titleStyle))
250             this.titleStyle = overrideMenuItem.titleStyle;
251         if (UtilValidate.isNotEmpty(overrideMenuItem.selectedStyle))
252             this.selectedStyle = overrideMenuItem.selectedStyle;
253         if (UtilValidate.isNotEmpty(overrideMenuItem.widgetStyle))
254             this.widgetStyle = overrideMenuItem.widgetStyle;
255         if (overrideMenuItem.position != null)
256             this.position = overrideMenuItem.position;
257 */

258         return;
259     }
260
261     public void renderMenuItemString(StringBuffer JavaDoc buffer, Map JavaDoc context, MenuStringRenderer menuStringRenderer) {
262         
263         boolean passed = true;
264         if (this.condition != null) {
265             if (!this.condition.eval(context)) {
266                 passed = false;
267             }
268         }
269            //Debug.logInfo("in ModelMenu, name:" + this.getName(), module);
270
if (passed) {
271             ModelMenuAction.runSubActions(this.actions, context);
272             menuStringRenderer.renderMenuItem(buffer, context, this);
273         }
274     }
275
276
277     /**
278      * @return
279      */

280     public ModelMenu getModelMenu() {
281         return modelMenu;
282     }
283
284
285     /**
286      * @return
287      */

288     public String JavaDoc getEntityName() {
289         if (UtilValidate.isNotEmpty(this.entityName)) {
290             return this.entityName;
291         } else if (parentMenuItem != null) {
292             return parentMenuItem.getEntityName();
293         } else {
294             return this.modelMenu.getDefaultEntityName();
295         }
296     }
297
298     /**
299      * @return
300      */

301     public String JavaDoc getAlign() {
302         if (UtilValidate.isNotEmpty(this.align)) {
303             return this.align;
304         } else if (parentMenuItem != null) {
305             return parentMenuItem.getAlign();
306         } else {
307             return this.modelMenu.getDefaultAlign();
308         }
309     }
310
311
312     /**
313      * @return
314      */

315     public String JavaDoc getName() {
316         return name;
317     }
318
319     /**
320      * @return
321      */

322     public int getPosition() {
323         if (this.position == null) {
324             return 1;
325         } else {
326             return position.intValue();
327         }
328     }
329
330     /**
331      * @return
332      */

333     public String JavaDoc getTitle(Map JavaDoc context) {
334             return title.expandString(context);
335     }
336
337     /**
338      * @return
339      */

340     public String JavaDoc getTitleStyle() {
341         if (UtilValidate.isNotEmpty(this.titleStyle)) {
342             return this.titleStyle;
343         } else if (parentMenuItem != null) {
344             return parentMenuItem.getTitleStyle();
345          } else {
346             return this.modelMenu.getDefaultTitleStyle();
347         }
348     }
349
350     /**
351      * @return
352      */

353     public String JavaDoc getDisabledTitleStyle() {
354         if (UtilValidate.isNotEmpty(this.disabledTitleStyle)) {
355             return this.disabledTitleStyle;
356         } else if (parentMenuItem != null) {
357             return parentMenuItem.getDisabledTitleStyle();
358         } else {
359             return this.modelMenu.getDefaultDisabledTitleStyle();
360         }
361     }
362     
363     public void setDisabledTitleStyle(String JavaDoc style) {
364             this.disabledTitleStyle = style;
365     }
366
367     /**
368      * @return
369      */

370     public String JavaDoc getSelectedStyle() {
371         if (UtilValidate.isNotEmpty(this.selectedStyle)) {
372             return this.selectedStyle;
373         } else if (parentMenuItem != null) {
374             return parentMenuItem.getSelectedStyle();
375         } else {
376             return this.modelMenu.getDefaultSelectedStyle();
377         }
378     }
379
380     /**
381      * @return
382      */

383     public String JavaDoc getTooltip(Map JavaDoc context) {
384         if (tooltip != null && !tooltip.isEmpty()) {
385             return tooltip.expandString(context);
386         } else {
387             return "";
388         }
389     }
390
391
392     /**
393      * @return
394      */

395     public String JavaDoc getWidgetStyle() {
396         if (UtilValidate.isNotEmpty(this.widgetStyle)) {
397             return this.widgetStyle;
398         } else if (parentMenuItem != null) {
399             return parentMenuItem.getWidgetStyle();
400         } else {
401             return this.modelMenu.getDefaultWidgetStyle();
402         }
403     }
404
405     /**
406      * @return
407      */

408     public String JavaDoc getAlignStyle() {
409         if (UtilValidate.isNotEmpty(this.alignStyle)) {
410             return this.alignStyle;
411         } else if (parentMenuItem != null) {
412             return parentMenuItem.getAlignStyle();
413         } else {
414             return this.modelMenu.getDefaultAlignStyle();
415         }
416     }
417
418     /**
419      * @return
420      */

421     public String JavaDoc getTooltipStyle() {
422         if (UtilValidate.isNotEmpty(this.tooltipStyle)) {
423             return this.tooltipStyle;
424         } else if (parentMenuItem != null) {
425             return parentMenuItem.getTooltipStyle();
426         } else {
427             return this.modelMenu.getDefaultTooltipStyle();
428         }
429     }
430
431     /**
432      * @param string
433      */

434     public void setEntityName(String JavaDoc string) {
435         entityName = string;
436     }
437
438     /**
439      * @param string
440      */

441     public void setName(String JavaDoc string) {
442         name = string;
443     }
444
445     /**
446      * @param i
447      */

448     public void setPosition(int i) {
449         position = new Integer JavaDoc(i);
450     }
451
452
453     /**
454      * @param string
455      */

456     public void setTitle(String JavaDoc string) {
457         this.title = new FlexibleStringExpander(string);
458     }
459
460     /**
461      * @param string
462      */

463     public void setTitleStyle(String JavaDoc string) {
464         this.titleStyle = string;
465     }
466
467     /**
468      * @param string
469      */

470     public void setTooltip(String JavaDoc string) {
471         this.tooltip = new FlexibleStringExpander(string);
472     }
473
474
475     /**
476      * @param string
477      */

478     public void setWidgetStyle(String JavaDoc string) {
479         this.widgetStyle = string;
480     }
481
482     /**
483      * @param string
484      */

485     public void setTooltipStyle(String JavaDoc string) {
486         this.tooltipStyle = string;
487     }
488
489
490     /**
491      * @param string
492      */

493     public void setAssociatedContentId(String JavaDoc string) {
494         this.associatedContentId = new FlexibleStringExpander(string);
495     }
496
497     /**
498      * @return
499      */

500     public String JavaDoc getAssociatedContentId(Map JavaDoc context) {
501         String JavaDoc retStr = null;
502         if (this.associatedContentId != null) {
503             retStr = associatedContentId.expandString(context);
504         }
505         if (UtilValidate.isEmpty(retStr)) {
506             retStr = this.modelMenu.getDefaultAssociatedContentId(context);
507         }
508         return retStr;
509     }
510
511
512     /**
513      * @param string
514      */

515     public void setCellWidth(String JavaDoc string) {
516         this.cellWidth = string;
517     }
518
519     /**
520      * @return
521      */

522     public String JavaDoc getCellWidth() {
523         if (UtilValidate.isNotEmpty(this.cellWidth )) {
524             return this.cellWidth ;
525         } else {
526             return this.modelMenu.getDefaultCellWidth ();
527         }
528     }
529
530     /**
531      * @param boolean
532      */

533     public void setHideIfSelected(Boolean JavaDoc val) {
534         this.hideIfSelected = val;
535     }
536
537     /**
538      * @return
539      */

540     public Boolean JavaDoc getHideIfSelected() {
541         if (hideIfSelected != null) {
542             return this.hideIfSelected;
543         } else {
544             return this.modelMenu.getDefaultHideIfSelected();
545         }
546     }
547
548     /**
549      * @return
550      */

551     public String JavaDoc getDisableIfEmpty() {
552             return this.disableIfEmpty;
553     }
554
555     /**
556      * @param boolean
557      */

558     public void setHasPermission(Boolean JavaDoc val) {
559         this.hasPermission = val;
560     }
561
562     /**
563      * @return
564      */

565     public Boolean JavaDoc getHasPermission() {
566         return this.hasPermission;
567     }
568
569     public void dump(StringBuffer JavaDoc buffer ) {
570         buffer.append("ModelMenuItem:"
571             + "\n title=" + this.title
572             + "\n name=" + this.name
573             + "\n entityName=" + this.entityName
574             + "\n titleStyle=" + this.titleStyle
575             + "\n widgetStyle=" + this.widgetStyle
576             + "\n tooltipStyle=" + this.tooltipStyle
577             + "\n selectedStyle=" + this.selectedStyle
578             + "\n\n");
579      
580             
581         return;
582     }
583
584     public Link getLink() {
585        return this.link;
586     }
587     
588     public boolean isSelected(Map JavaDoc context) {
589
590         String JavaDoc currentMenuItemName = modelMenu.getSelectedMenuItemContextFieldName(context);
591         if (currentMenuItemName != null && currentMenuItemName.equals(this.name))
592             return true;
593         else
594             return false;
595     }
596
597
598
599
600         public static class Link {
601
602             protected ModelMenuItem linkMenuItem;
603             protected FlexibleStringExpander textExdr;
604             protected FlexibleStringExpander idExdr;
605             protected FlexibleStringExpander styleExdr;
606             protected FlexibleStringExpander targetExdr;
607             protected FlexibleStringExpander targetWindowExdr;
608             protected FlexibleStringExpander prefixExdr;
609             protected FlexibleStringExpander nameExdr;
610             protected Image image;
611             protected String JavaDoc urlMode = "intra-app";
612             protected boolean fullPath = false;
613             protected boolean secure = false;
614             protected boolean encode = false;
615             
616             public Link( Element JavaDoc linkElement, ModelMenuItem parentMenuItem) {
617     
618                 this.linkMenuItem = parentMenuItem;
619                 setText(linkElement.getAttribute("text"));
620                 setId(linkElement.getAttribute("id"));
621                 setStyle(linkElement.getAttribute("style"));
622                 setTarget(linkElement.getAttribute("target"));
623                 setTargetWindow(linkElement.getAttribute("target-window"));
624                 setPrefix(linkElement.getAttribute("prefix"));
625                 setUrlMode(linkElement.getAttribute("url-mode"));
626                 setFullPath(linkElement.getAttribute("full-path"));
627                 setSecure(linkElement.getAttribute("secure"));
628                 setEncode(linkElement.getAttribute("encode"));
629                 setName(linkElement.getAttribute("name"));
630                 Element JavaDoc imageElement = UtilXml.firstChildElement(linkElement, "image");
631                 if (imageElement != null) {
632                     this.image = new Image(imageElement);
633                 }
634     
635             }
636     
637             public void renderLinkString(StringBuffer JavaDoc buffer, Map JavaDoc context, MenuStringRenderer menuStringRenderer) {
638                 menuStringRenderer.renderLink(buffer, context, this);
639             }
640             
641             public String JavaDoc getText(Map JavaDoc context) {
642                 String JavaDoc txt = this.textExdr.expandString(context);
643                 if (UtilValidate.isEmpty(txt))
644                     txt = linkMenuItem.getTitle(context);
645                 return txt;
646             }
647             
648             public String JavaDoc getId(Map JavaDoc context) {
649                 return this.idExdr.expandString(context);
650             }
651             
652             public String JavaDoc getStyle(Map JavaDoc context) {
653                 String JavaDoc style = this.styleExdr.expandString(context);
654                 if (UtilValidate.isEmpty(style)) {
655                     style = this.linkMenuItem.getWidgetStyle();
656                 }
657                 return style;
658             }
659             
660             public String JavaDoc getName(Map JavaDoc context) {
661                 return this.nameExdr.expandString(context);
662             }
663         
664             public String JavaDoc getTarget(Map JavaDoc context) {
665                 return this.targetExdr.expandString(context);
666             }
667             
668             public String JavaDoc getTargetWindow(Map JavaDoc context) {
669                 return this.targetWindowExdr.expandString(context);
670             }
671             
672             public String JavaDoc getUrlMode() {
673                 return this.urlMode;
674             }
675             
676             public String JavaDoc getPrefix(Map JavaDoc context) {
677                 return this.prefixExdr.expandString(context);
678             }
679             
680             public boolean getFullPath() {
681                 return this.fullPath;
682             }
683             
684             public boolean getSecure() {
685                 return this.secure;
686             }
687             
688             public boolean getEncode() {
689                 return this.encode;
690             }
691             
692             public Image getImage() {
693                 return this.image;
694             }
695
696             public void setText( String JavaDoc val ) {
697                 String JavaDoc textAttr = UtilFormatOut.checkNull(val);
698                 this.textExdr = new FlexibleStringExpander(textAttr);
699             }
700             public void setId( String JavaDoc val ) {
701                 this.idExdr = new FlexibleStringExpander(val);
702             }
703             public void setStyle( String JavaDoc val ) {
704                 this.styleExdr = new FlexibleStringExpander(val);
705             }
706             public void setTarget( String JavaDoc val ) {
707                 this.targetExdr = new FlexibleStringExpander(val);
708             }
709             public void setTargetWindow( String JavaDoc val ) {
710                 this.targetWindowExdr = new FlexibleStringExpander(val);
711             }
712             public void setPrefix( String JavaDoc val ) {
713                 this.prefixExdr = new FlexibleStringExpander(val);
714             }
715             public void setUrlMode( String JavaDoc val ) {
716                 if (UtilValidate.isNotEmpty(val))
717                     this.urlMode = val;
718             }
719             public void setName( String JavaDoc val ) {
720                 this.nameExdr = new FlexibleStringExpander(val);
721             }
722             public void setFullPath( String JavaDoc val ) {
723                 String JavaDoc sFullPath = val;
724                 if (sFullPath != null && sFullPath.equalsIgnoreCase("true"))
725                     this.fullPath = true;
726                 else
727                     this.fullPath = false;
728             }
729
730             public void setSecure( String JavaDoc val ) {
731                 String JavaDoc sSecure = val;
732                 if (sSecure != null && sSecure.equalsIgnoreCase("true"))
733                     this.secure = true;
734                 else
735                     this.secure = false;
736             }
737
738             public void setEncode( String JavaDoc val ) {
739                 String JavaDoc sEncode = val;
740                 if (sEncode != null && sEncode.equalsIgnoreCase("true"))
741                     this.encode = true;
742                 else
743                     this.encode = false;
744             }
745             public void setImage( Image img ) {
746                 this.image = img;
747             }
748             
749             public ModelMenuItem getLinkMenuItem() {
750                 return linkMenuItem;
751             }
752                 
753         }
754
755         public static class Image {
756
757             protected FlexibleStringExpander srcExdr;
758             protected FlexibleStringExpander idExdr;
759             protected FlexibleStringExpander styleExdr;
760             protected FlexibleStringExpander widthExdr;
761             protected FlexibleStringExpander heightExdr;
762             protected FlexibleStringExpander borderExdr;
763             protected String JavaDoc urlMode;
764             
765             public Image( Element JavaDoc imageElement) {
766     
767                 setSrc(imageElement.getAttribute("src"));
768                 setId(imageElement.getAttribute("id"));
769                 setStyle(imageElement.getAttribute("style"));
770                 setWidth(imageElement.getAttribute("width"));
771                 setHeight(imageElement.getAttribute("height"));
772                 setBorder(UtilFormatOut.checkEmpty(imageElement.getAttribute("border"), "0"));
773                 setUrlMode(UtilFormatOut.checkEmpty(imageElement.getAttribute("url-mode"), "content"));
774     
775             }
776     
777             public void renderImageString(StringBuffer JavaDoc buffer, Map JavaDoc context, MenuStringRenderer menuStringRenderer) {
778                 menuStringRenderer.renderImage(buffer, context, this);
779             }
780             
781             public String JavaDoc getSrc(Map JavaDoc context) {
782                 return this.srcExdr.expandString(context);
783             }
784             
785             public String JavaDoc getId(Map JavaDoc context) {
786                 return this.idExdr.expandString(context);
787             }
788             
789             public String JavaDoc getStyle(Map JavaDoc context) {
790                 return this.styleExdr.expandString(context);
791             }
792
793             public String JavaDoc getWidth(Map JavaDoc context) {
794                 return this.widthExdr.expandString(context);
795             }
796
797             public String JavaDoc getHeight(Map JavaDoc context) {
798                 return this.heightExdr.expandString(context);
799             }
800
801             public String JavaDoc getBorder(Map JavaDoc context) {
802                 return this.borderExdr.expandString(context);
803             }
804             
805             public String JavaDoc getUrlMode() {
806                 return this.urlMode;
807             }
808             
809             public void setSrc( String JavaDoc val ) {
810                 String JavaDoc textAttr = UtilFormatOut.checkNull(val);
811                 this.srcExdr = new FlexibleStringExpander(textAttr);
812             }
813             public void setId( String JavaDoc val ) {
814                 this.idExdr = new FlexibleStringExpander(val);
815             }
816             public void setStyle( String JavaDoc val ) {
817                 this.styleExdr = new FlexibleStringExpander(val);
818             }
819             public void setWidth( String JavaDoc val ) {
820                 this.widthExdr = new FlexibleStringExpander(val);
821             }
822             public void setHeight( String JavaDoc val ) {
823                 this.heightExdr = new FlexibleStringExpander(val);
824             }
825             public void setBorder( String JavaDoc val ) {
826                 this.borderExdr = new FlexibleStringExpander(val);
827             }
828             public void setUrlMode( String JavaDoc val ) {
829                 if (UtilValidate.isEmpty(val))
830                     this.urlMode = "content";
831                 else
832                     this.urlMode = val;
833             }
834                 
835         }
836
837     
838 }
839
Popular Tags