001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.tag; 020 021import javax.servlet.jsp.tagext.Tag; 022 023import lucee.runtime.exp.ApplicationException; 024import lucee.runtime.exp.TagNotSupported; 025import lucee.runtime.ext.tag.TagImpl; 026import lucee.runtime.op.Caster; 027 028public class TreeItem extends TagImpl{ 029 030 private String value=null; 031 private String display=null; 032 private String parent=null; 033 private String strImg=null; 034 private int intImg=TreeItemBean.IMG_FOLDER; 035 private String strImgOpen=null; 036 private int intImgOpen=TreeItemBean.IMG_FOLDER; 037 private String href=null; 038 private String target=null; 039 private String query=null; 040 private String strQueryAsRootCustom=null; 041 private int intQueryAsRoot=TreeItemBean.QUERY_AS_ROOT_YES; 042 private boolean expand=true; 043 044 045 public TreeItem() throws TagNotSupported{ 046 throw new TagNotSupported("TreeItem"); 047 } 048 049 @Override 050 public void release() { 051 value=null; 052 display=null; 053 parent=null; 054 strImg=null; 055 intImg=TreeItemBean.IMG_FOLDER; 056 strImgOpen=null; 057 intImgOpen=TreeItemBean.IMG_FOLDER; 058 href=null; 059 target=null; 060 query=null; 061 strQueryAsRootCustom=null; 062 intQueryAsRoot=TreeItemBean.QUERY_AS_ROOT_YES; 063 expand=true; 064 } 065 /** 066 * @param display the display to set 067 */ 068 public void setDisplay(String display) { 069 this.display=display; 070 } 071 /** 072 * @param expand the expand to set 073 */ 074 public void setExpand(boolean expand) { 075 this.expand=expand; 076 } 077 /** 078 * @param href the href to set 079 */ 080 public void setHref(String href) { 081 this.href=href; 082 } 083 /** 084 * @param img the img to set 085 */ 086 public void setImg(String img) { 087 this.strImg=img; 088 this.intImg=toIntImg(img); 089 } 090 091 /** 092 * @param imgopen the imgopen to set 093 */ 094 public void setImgopen(String imgopen) { 095 this.strImgOpen=imgopen; 096 this.intImgOpen=toIntImg(imgopen); 097 } 098 099 private int toIntImg(String img) { 100 img=img.trim().toLowerCase(); 101 if("cd".equals(img)) return TreeItemBean.IMG_CD; 102 else if("computer".equals(img)) return TreeItemBean.IMG_COMPUTER; 103 else if("document".equals(img)) return TreeItemBean.IMG_DOCUMENT; 104 else if("element".equals(img)) return TreeItemBean.IMG_ELEMENT; 105 else if("folder".equals(img)) return TreeItemBean.IMG_FOLDER; 106 else if("floppy".equals(img)) return TreeItemBean.IMG_FLOPPY; 107 else if("fixed".equals(img)) return TreeItemBean.IMG_FIXED; 108 else if("remote".equals(img)) return TreeItemBean.IMG_REMOTE; 109 return TreeItemBean.IMG_CUSTOM; 110 } 111 112 /** 113 * @param parent the parent to set 114 */ 115 public void setParent(String parent) { 116 this.parent=parent; 117 } 118 /** 119 * @param query the query to set 120 */ 121 public void setQuery(String query) { 122 this.query=query; 123 } 124 /** 125 * @param queryAsRoot the queryAsRoot to set 126 */ 127 public void setQueryasroot(String queryAsRoot) { 128 strQueryAsRootCustom = queryAsRoot; 129 130 Boolean b = Caster.toBoolean(queryAsRoot,null); 131 if(b==null) intQueryAsRoot=TreeItemBean.QUERY_AS_ROOT_CUSTOM; 132 else intQueryAsRoot=b.booleanValue()?TreeItemBean.QUERY_AS_ROOT_YES:TreeItemBean.QUERY_AS_ROOT_NO; 133 } 134 /** 135 * @param target the target to set 136 */ 137 public void setTarget(String target) { 138 this.target=target; 139 } 140 /** 141 * @param value the value to set 142 */ 143 public void setValue(String value) { 144 this.value=value; 145 } 146 147 public int doStartTag() throws ApplicationException { 148 Tree tree=getTree(); 149 150 if(display==null)display=value; 151 if(query!=null) doStartTagQuery(tree); 152 else doStartTagNormal(tree); 153 154 return SKIP_BODY; 155 } 156 157 158 159 160 private void doStartTagQuery(Tree tree) { 161 // TODO Auto-generated method stub 162 163 } 164 165 private void doStartTagNormal(Tree tree) { 166 TreeItemBean bean = new TreeItemBean(); 167 bean.setDisplay(display); 168 bean.setExpand(expand); 169 bean.setHref(href); 170 bean.setImg(intImg); 171 bean.setImgCustom(strImg); 172 bean.setImgOpen(intImgOpen); 173 bean.setImgOpenCustom(strImgOpen); 174 bean.setParent(parent); 175 bean.setTarget(target); 176 bean.setValue(value); 177 178 tree.addTreeItem(bean); 179 } 180 181 182 private Tree getTree() throws ApplicationException { 183 Tag parent=getParent(); 184 while(parent!=null && !(parent instanceof Tree)) { 185 parent=parent.getParent(); 186 } 187 188 if(parent instanceof Tree) return (Tree) parent; 189 throw new ApplicationException("Wrong Context, tag TreeItem must be inside a Tree tag"); 190 191 } 192}