001 package railo.transformer.library.tag; 002 003 import java.util.Iterator; 004 005 import railo.commons.lang.StringUtil; 006 007 public final class TagLibTagScript { 008 009 public static final short TYPE_NONE = 0; 010 public static final short TYPE_SINGLE = 1; 011 public static final short TYPE_MULTIPLE = 2; 012 013 public static final short CTX_OTHER = -1; 014 public static final short CTX_NONE = 0; 015 public static final short CTX_IF = 1; 016 public static final short CTX_ELSE_IF = 2; 017 public static final short CTX_ELSE = 3; 018 public static final short CTX_FOR = 4; 019 public static final short CTX_WHILE = 5; 020 public static final short CTX_DO_WHILE = 6; 021 public static final short CTX_CFC = 7; 022 public static final short CTX_INTERFACE = 8; 023 public static final short CTX_FUNCTION = 9; 024 public static final short CTX_BLOCK = 10; 025 public static final short CTX_FINALLY = 11; 026 public static final short CTX_SWITCH = 12; 027 public static final short CTX_TRY = 13; 028 public static final short CTX_CATCH = 14; 029 public static final short CTX_TRANSACTION = 15; 030 public static final short CTX_THREAD = 16; 031 public static final short CTX_SAVECONTENT = 17; 032 public static final short CTX_LOCK = 18; 033 public static final short CTX_LOOP = 19; 034 public static final short CTX_QUERY = 20; 035 public static final short CTX_ZIP = 21; 036 037 038 039 040 private final static TagLibTagAttr UNDEFINED=new TagLibTagAttr(null); 041 042 private TagLibTag tag; 043 private boolean rtexpr; 044 private short type=TYPE_NONE; 045 private TagLibTagAttr singleAttr=UNDEFINED; 046 private short context=CTX_OTHER; 047 048 049 public TagLibTagScript(TagLibTag tag) { 050 this.tag=tag; 051 } 052 053 public void setType(String type) { 054 if(!StringUtil.isEmpty(type,true)) { 055 type=type.trim().toLowerCase(); 056 if("single".equals(type)) this.type=TYPE_SINGLE; 057 else if("multiple".equals(type)) this.type=TYPE_MULTIPLE; 058 } 059 } 060 061 public void setRtexpr(boolean rtexpr) { 062 this.rtexpr=rtexpr; 063 } 064 065 /** 066 * @return the tag 067 */ 068 public TagLibTag getTag() { 069 return tag; 070 } 071 072 /** 073 * @return the rtexpr 074 */ 075 public boolean getRtexpr() { 076 return rtexpr; 077 } 078 079 /** 080 * @return the type 081 */ 082 public short getType() { 083 return type; 084 } 085 086 087 public String getTypeAsString() { 088 if(type==TYPE_MULTIPLE) return "multiple"; 089 if(type==TYPE_SINGLE) return "single"; 090 return "none"; 091 } 092 093 public TagLibTagAttr getSingleAttr() { 094 if(singleAttr==UNDEFINED) { 095 singleAttr=null; 096 Iterator<TagLibTagAttr> it = tag.getAttributes().values().iterator(); 097 TagLibTagAttr attr; 098 while(it.hasNext()){ 099 attr=it.next(); 100 if(attr.getScriptSupport()!=TagLibTagAttr.SCRIPT_SUPPORT_NONE){ 101 singleAttr=attr; 102 break; 103 } 104 } 105 } 106 return singleAttr; 107 } 108 109 public void setContext(String str) { 110 if(!StringUtil.isEmpty(str,true)) { 111 str=str.trim().toLowerCase(); 112 if("none".equals(str)) this.context=CTX_NONE; 113 else if("if".equals(str)) this.context=CTX_IF; 114 else if("elseif".equals(str)) this.context=CTX_ELSE_IF; 115 else if("else".equals(str)) this.context=CTX_ELSE; 116 else if("for".equals(str)) this.context=CTX_FOR; 117 else if("while".equals(str)) this.context=CTX_WHILE; 118 else if("dowhile".equals(str)) this.context=CTX_DO_WHILE; 119 else if("cfc".equals(str)) this.context=CTX_CFC; 120 else if("component".equals(str)) this.context=CTX_CFC; 121 else if("interface".equals(str)) this.context=CTX_INTERFACE; 122 else if("function".equals(str)) this.context=CTX_FUNCTION; 123 else if("block".equals(str)) this.context=CTX_BLOCK; 124 else if("finally".equals(str)) this.context=CTX_FINALLY; 125 else if("switch".equals(str)) this.context=CTX_SWITCH; 126 else if("try".equals(str)) this.context=CTX_TRY; 127 else if("catch".equals(str)) this.context=CTX_CATCH; 128 else if("transaction".equals(str)) this.context=CTX_TRANSACTION; 129 else if("thread".equals(str)) this.context=CTX_THREAD; 130 else if("savecontent".equals(str)) this.context=CTX_SAVECONTENT; 131 else if("lock".equals(str)) this.context=CTX_LOCK; 132 else if("loop".equals(str)) this.context=CTX_LOOP; 133 else if("query".equals(str)) this.context=CTX_QUERY; 134 else if("zip".equals(str)) this.context=CTX_ZIP; 135 } 136 } 137 138 /** 139 * @return the context 140 */ 141 public short getContext() { 142 return context; 143 } 144 145 146 }