001    package railo.runtime.tag;
002    
003    import javax.servlet.jsp.tagext.Tag;
004    
005    import railo.runtime.exp.ApplicationException;
006    import railo.runtime.exp.TagNotSupported;
007    import railo.runtime.ext.tag.TagImpl;
008    import railo.runtime.op.Caster;
009    
010    public class TreeItem extends TagImpl{
011    
012            private String value=null;
013            private String display=null;
014            private String parent=null;
015            private String strImg=null;
016            private int intImg=TreeItemBean.IMG_FOLDER;
017            private String strImgOpen=null;
018            private int intImgOpen=TreeItemBean.IMG_FOLDER;
019            private String href=null;
020            private String target=null;
021            private String query=null;
022            private String strQueryAsRootCustom=null;
023            private int intQueryAsRoot=TreeItemBean.QUERY_AS_ROOT_YES;
024            private boolean expand=true;
025     
026            
027            public TreeItem() throws TagNotSupported{
028                    throw new TagNotSupported("TreeItem");
029            }
030            
031            /**
032             *
033             * @see railo.runtime.ext.tag.TagImpl#release()
034             */
035            public void release() {
036                    value=null;
037                    display=null;
038                    parent=null;
039                    strImg=null;
040                    intImg=TreeItemBean.IMG_FOLDER;
041                    strImgOpen=null;
042                    intImgOpen=TreeItemBean.IMG_FOLDER;
043                    href=null;
044                    target=null;
045                    query=null;
046                    strQueryAsRootCustom=null;
047                    intQueryAsRoot=TreeItemBean.QUERY_AS_ROOT_YES;
048                    expand=true;
049            }
050            /**
051             * @param display the display to set
052             */
053            public void setDisplay(String display) {
054                    this.display=display;
055            }
056            /**
057             * @param expand the expand to set
058             */
059            public void setExpand(boolean expand) {
060                    this.expand=expand;
061            }
062            /**
063             * @param href the href to set
064             */
065            public void setHref(String href) {
066                    this.href=href;
067            }
068            /**
069             * @param img the img to set
070             */
071            public void setImg(String img) {
072                    this.strImg=img;
073                    this.intImg=toIntImg(img);
074            }
075            
076            /**
077             * @param imgopen the imgopen to set
078             */
079            public void setImgopen(String imgopen) {
080                    this.strImgOpen=imgopen;
081                    this.intImgOpen=toIntImg(imgopen);
082            }
083            
084            private int toIntImg(String img) {
085                    img=img.trim().toLowerCase();
086                    if("cd".equals(img))                            return TreeItemBean.IMG_CD;
087                    else if("computer".equals(img))         return TreeItemBean.IMG_COMPUTER;
088                    else if("document".equals(img))         return TreeItemBean.IMG_DOCUMENT;
089                    else if("element".equals(img))          return TreeItemBean.IMG_ELEMENT;
090                    else if("folder".equals(img))           return TreeItemBean.IMG_FOLDER;
091                    else if("floppy".equals(img))           return TreeItemBean.IMG_FLOPPY;
092                    else if("fixed".equals(img))            return TreeItemBean.IMG_FIXED;
093                    else if("remote".equals(img))           return TreeItemBean.IMG_REMOTE;
094                    return TreeItemBean.IMG_CUSTOM;
095            }
096            
097            /**
098             * @param parent the parent to set
099             */
100            public void setParent(String parent) {
101                    this.parent=parent;
102            }
103            /**
104             * @param query the query to set
105             */
106            public void setQuery(String query) {
107                    this.query=query;
108            }
109            /**
110             * @param queryAsRoot the queryAsRoot to set
111             */
112            public void setQueryasroot(String queryAsRoot) {
113                    strQueryAsRootCustom = queryAsRoot;
114                    
115                    Boolean b = Caster.toBoolean(queryAsRoot,null);
116                    if(b==null)     intQueryAsRoot=TreeItemBean.QUERY_AS_ROOT_CUSTOM;
117                    else            intQueryAsRoot=b.booleanValue()?TreeItemBean.QUERY_AS_ROOT_YES:TreeItemBean.QUERY_AS_ROOT_NO;
118            }
119            /**
120             * @param target the target to set
121             */
122            public void setTarget(String target) {
123                    this.target=target;
124            }
125            /**
126             * @param value the value to set
127             */
128            public void setValue(String value) {
129                    this.value=value;
130            }
131            
132            public int doStartTag() throws ApplicationException {
133                    Tree tree=getTree();
134                    
135                    if(display==null)display=value;
136                    if(query!=null) doStartTagQuery(tree);
137                    else doStartTagNormal(tree);
138                    
139                    return SKIP_BODY;
140            }
141            
142            
143            
144            
145            private void doStartTagQuery(Tree tree) {
146                    // TODO Auto-generated method stub
147                    
148            }
149            
150            private void doStartTagNormal(Tree tree) {
151                    TreeItemBean bean = new TreeItemBean();
152                    bean.setDisplay(display);
153                    bean.setExpand(expand);
154                    bean.setHref(href);
155                    bean.setImg(intImg);
156                    bean.setImgCustom(strImg);
157                    bean.setImgOpen(intImgOpen);
158                    bean.setImgOpenCustom(strImgOpen);
159                    bean.setParent(parent);
160                    bean.setTarget(target);
161                    bean.setValue(value);
162                    
163                    tree.addTreeItem(bean);
164            }
165            
166            
167            private Tree getTree() throws ApplicationException {
168                    Tag parent=getParent();
169                    while(parent!=null && !(parent instanceof Tree)) {
170                            parent=parent.getParent();
171                    }
172                    
173                    if(parent instanceof Tree) return (Tree) parent;
174                    throw new ApplicationException("Wrong Context, tag TreeItem must be inside a Tree tag");        
175                    
176            }
177    }