001 /** 002 * Implements the CFML Function getbasetaglist 003 */ 004 package railo.runtime.functions.other; 005 006 import java.util.Iterator; 007 import java.util.Map; 008 009 import javax.servlet.jsp.tagext.Tag; 010 011 import railo.runtime.PageContext; 012 import railo.runtime.config.ConfigImpl; 013 import railo.runtime.ext.function.Function; 014 import railo.runtime.ext.tag.AppendixTag; 015 import railo.runtime.tag.CFImportTag; 016 import railo.runtime.tag.CFTag; 017 import railo.runtime.tag.CFTagCore; 018 import railo.runtime.tag.Module; 019 import railo.runtime.type.util.ListUtil; 020 import railo.transformer.library.tag.TagLib; 021 import railo.transformer.library.tag.TagLibTag; 022 023 public final class GetBaseTagList implements Function { 024 public static String call(PageContext pc) { 025 return call(pc,","); 026 } 027 public static String call(PageContext pc, String delimiter) { 028 Tag tag=pc.getCurrentTag(); 029 StringBuffer sb=new StringBuffer(); 030 while(tag!=null) { 031 if(sb.length()>0)sb.append(delimiter); 032 sb.append(getName(pc,tag)); 033 tag=tag.getParent(); 034 } 035 return sb.toString(); 036 } 037 private static String getName(PageContext pc, Tag tag) { 038 Class clazz = tag.getClass(); 039 if(clazz==CFImportTag.class)clazz=CFTag.class; 040 String className=clazz.getName(); 041 TagLib[] tlds = ((ConfigImpl)pc.getConfig()).getTLDs(); 042 TagLibTag tlt; 043 044 045 046 for(int i=0;i<tlds.length;i++) { 047 //String ns = tlds[i].getNameSpaceAndSeparator(); 048 049 050 Map tags = tlds[i].getTags(); 051 Iterator it = tags.keySet().iterator(); 052 053 while(it.hasNext()){ 054 tlt=(TagLibTag) tags.get(it.next()); 055 if(tlt.getTagClassName().equals(className)) { 056 // custm tag 057 if(tag instanceof AppendixTag) { 058 AppendixTag atag=(AppendixTag)tag; 059 if(atag.getAppendix()!=null && !(tag instanceof Module)) { 060 return tlt.getFullName().toUpperCase()+atag.getAppendix().toUpperCase(); 061 } 062 } 063 // built in cfc based custom tag 064 if(tag instanceof CFTagCore) { 065 if(((CFTagCore)tag).getName().equals(tlt.getAttribute("__name").getDefaultValue())) 066 return tlt.getFullName().toUpperCase(); 067 continue; 068 } 069 070 return tlt.getFullName().toUpperCase(); 071 } 072 } 073 } 074 return ListUtil.last(className,".",true).toUpperCase(); 075 076 } 077 }