001 package railo.transformer.bytecode.statement.tag; 002 003 import java.util.HashMap; 004 import java.util.LinkedHashMap; 005 import java.util.Map; 006 007 import railo.runtime.op.Caster; 008 import railo.transformer.bytecode.Body; 009 import railo.transformer.bytecode.BytecodeContext; 010 import railo.transformer.bytecode.BytecodeException; 011 import railo.transformer.bytecode.statement.StatementBase; 012 import railo.transformer.bytecode.visitor.ParseBodyVisitor; 013 import railo.transformer.library.tag.TagLibTag; 014 015 /** 016 * 017 */ 018 public class TagBase extends StatementBase implements Tag { 019 020 private Body body=null; 021 private String appendix; 022 private String fullname; 023 private TagLibTag tagLibTag; 024 Map attributes=new LinkedHashMap(); 025 Map missingAttributes=new HashMap(); 026 private boolean scriptBase=false; 027 028 private Map<String, Attribute> metadata; 029 030 031 public TagBase(int startLine,int endLine) { 032 super(startLine,endLine); 033 } 034 public TagBase(int startLine) { 035 super(startLine,-1); 036 } 037 038 039 /** 040 * @see railo.transformer.bytecode.statement.tag.Tag#getAppendix() 041 */ 042 public String getAppendix() { 043 return appendix; 044 } 045 046 /** 047 * @see railo.transformer.bytecode.statement.tag.Tag#getAttributes() 048 */ 049 public Map getAttributes() { 050 return attributes; 051 } 052 053 /** 054 * 055 * @see railo.transformer.bytecode.statement.tag.Tag#getFullname() 056 */ 057 public String getFullname() { 058 return fullname; 059 } 060 061 /** 062 * @see railo.transformer.bytecode.statement.tag.Tag#getTagLibTag() 063 */ 064 public TagLibTag getTagLibTag() { 065 return tagLibTag; 066 } 067 068 /** 069 * @see railo.transformer.bytecode.statement.tag.Tag#setAppendix(java.lang.String) 070 */ 071 public void setAppendix(String appendix) { 072 this.appendix=appendix; 073 } 074 075 /** 076 * @see railo.transformer.bytecode.statement.tag.Tag#setFullname(java.lang.String) 077 */ 078 public void setFullname(String fullname) { 079 this.fullname=fullname; 080 } 081 082 /** 083 * @see railo.transformer.bytecode.statement.tag.Tag#setTagLibTag(railo.transformer.library.tag.TagLibTag) 084 */ 085 public void setTagLibTag(TagLibTag tagLibTag) { 086 this.tagLibTag=tagLibTag; 087 } 088 089 /** 090 * @see railo.transformer.bytecode.statement.tag.Tag#addAttribute(railo.transformer.bytecode.statement.tag.Attribute) 091 */ 092 public void addAttribute(Attribute attribute) { 093 attributes.put(attribute.getName().toLowerCase(), attribute); 094 } 095 096 /** 097 * 098 * @see railo.transformer.bytecode.statement.tag.Tag#containsAttribute(java.lang.String) 099 */ 100 public boolean containsAttribute(String name) { 101 return attributes.containsKey(name.toLowerCase()); 102 } 103 104 /** 105 * 106 * @see railo.transformer.bytecode.statement.tag.Tag#getBody() 107 */ 108 public Body getBody() { 109 return body; 110 } 111 112 /** 113 * 114 * @see railo.transformer.bytecode.statement.tag.Tag#setBody(railo.transformer.bytecode.Body) 115 */ 116 public void setBody(Body body) { 117 this.body = body; 118 body.setParent(this); 119 } 120 121 122 /** 123 * @see railo.transformer.bytecode.statement.StatementBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter) 124 */ 125 public void _writeOut(BytecodeContext bc) throws BytecodeException { 126 _writeOut(bc, true); 127 } 128 129 public void _writeOut(BytecodeContext bc, boolean doReuse) throws BytecodeException { 130 boolean output=tagLibTag.getParseBody() || Caster.toBooleanValue(getAttribute("output"), false); 131 132 if(output) { 133 ParseBodyVisitor pbv=new ParseBodyVisitor(); 134 pbv.visitBegin(bc); 135 _writeOutTag(bc,doReuse); 136 pbv.visitEnd(bc); 137 138 139 } 140 else _writeOutTag(bc,doReuse); 141 } 142 143 private void _writeOutTag(BytecodeContext bc, boolean doReuse) throws BytecodeException { 144 TagOther.writeOut(this,bc, doReuse); 145 146 } 147 148 /** 149 * @see railo.transformer.bytecode.statement.tag.Tag#getAttribute(java.lang.String) 150 */ 151 public Attribute getAttribute(String name) { 152 return (Attribute) attributes.get(name.toLowerCase()); 153 } 154 155 /** 156 * 157 * @see railo.transformer.bytecode.statement.tag.Tag#removeAttribute(java.lang.String) 158 */ 159 public Attribute removeAttribute(String name) { 160 return (Attribute) attributes.remove(name); 161 } 162 163 /** 164 * 165 * @see java.lang.Object#toString() 166 */ 167 public String toString() { 168 return appendix+":"+fullname+":"+super.toString(); 169 } 170 171 /** 172 * @return the scriptBase 173 */ 174 public boolean isScriptBase() { 175 return scriptBase; 176 } 177 /** 178 * @param scriptBase the scriptBase to set 179 */ 180 public void setScriptBase(boolean scriptBase) { 181 this.scriptBase = scriptBase; 182 } 183 /** 184 * @see railo.transformer.bytecode.statement.tag.Tag#addMissingAttribute(java.lang.String, java.lang.String) 185 */ 186 public void addMissingAttribute(String name, String type) { 187 missingAttributes.put(name, type); 188 } 189 190 /** 191 * @see railo.transformer.bytecode.statement.tag.Tag#getMissingAttributes() 192 */ 193 public Map getMissingAttributes() { 194 return missingAttributes; 195 } 196 197 public void addMetaData(Attribute metadata) { 198 if(this.metadata==null) this.metadata=new HashMap<String, Attribute>(); 199 this.metadata.put(metadata.getName(), metadata); 200 } 201 202 public Map<String, Attribute> getMetaData() { 203 return metadata; 204 } 205 }