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.transformer.library.tag; 020 021import java.io.File; 022import java.util.Map; 023 024import lucee.commons.collection.MapFactory; 025import lucee.runtime.tag.CFImportTag; 026 027 028/** 029 * extends the normal tag library, because Custom Tags has no restrictions by a TLD this Taglib accept everything 030 */ 031public final class CustomTagLib extends TagLib { 032 033 private String textTagLib; 034 private TagLib[] taglibs; 035 036 037 /** 038 * constructor of the class 039 * @param textTagLib 040 * @param nameSpace the namespace definition 041 * @param nameSpaceSeperator the seperator beetween namespace and name of the tag 042 */ 043 public CustomTagLib(String textTagLib, String nameSpace,String nameSpaceSeperator) { 044 super(false); 045 this.textTagLib = textTagLib; 046 setNameSpace(nameSpace); 047 setNameSpaceSeperator(nameSpaceSeperator); 048 049 } 050 051 /** 052 * @see lucee.transformer.library.tag.TagLib#getAppendixTag(java.lang.String) 053 */ 054 public TagLibTag getAppendixTag(String name) { 055 056 TagLibTag tlt = new TagLibTag(this); 057 tlt.setName(""); 058 tlt.setAppendix(true); 059 tlt.setTagClass(CFImportTag.class.getName()); 060 tlt.setHandleExceptions(true); 061 tlt.setBodyContent("free"); 062 tlt.setParseBody(false); 063 tlt.setDescription("Creates a CFML Custom Tag"); 064 tlt.setAttributeType(TagLibTag.ATTRIBUTE_TYPE_DYNAMIC); 065 066 TagLibTagAttr tlta=new TagLibTagAttr(tlt); 067 tlta.setName("__custom_tag_path"); 068 tlta.setRequired(true); 069 tlta.setRtexpr(true); 070 tlta.setType("string"); 071 tlta.setHidden(true); 072 tlta.setDefaultValue(textTagLib); 073 074 tlt.setAttribute(tlta); 075 setTag(tlt); 076 077 return tlt; 078 } 079 080 /** 081 * @see lucee.transformer.library.tag.TagLib#getTag(java.lang.String) 082 */ 083 public TagLibTag getTag(String name) { 084 if(taglibs!=null){ 085 TagLibTag tag=null; 086 for(int i=0;i<taglibs.length;i++){ 087 if((tag=taglibs[i].getTag(name))!=null) return tag; 088 } 089 } 090 return null; 091 } 092 /** 093 * @see lucee.transformer.library.tag.TagLib#getTags() 094 */ 095 public Map getTags() { 096 return MapFactory.<String,String>getConcurrentMap(); 097 } 098 099 /** 100 * @see lucee.transformer.library.tag.TagLib#setTag(lucee.transformer.library.tag.TagLibTag) 101 */ 102 public void setTag(TagLibTag tag) {} 103 104 public void append(TagLib other) { 105 if(other instanceof CustomTagLib) 106 textTagLib+=File.pathSeparatorChar+((CustomTagLib)other).textTagLib; 107 else{ 108 if(taglibs==null){ 109 taglibs=new TagLib[]{other}; 110 } 111 else { 112 TagLib[] tmp = new TagLib[taglibs.length+1]; 113 for(int i=0;i<taglibs.length;i++){ 114 tmp[i]=taglibs[i]; 115 } 116 tmp[taglibs.length]=other; 117 } 118 119 } 120 } 121 122 123}