Package railo.transformer.library.tag

Examples of railo.transformer.library.tag.TagLibTag


            page.addPrintOut("</", null,null);
          }
          else {
            String name = identifier(data.cfml,true);
            if(tagLib.getIgnoreUnknowTags()) {
              TagLibTag tlt = tagLib.getTag(name);
              if(tlt==null) {
                data.cfml.setPos(pos);
                page.addPrintOut("</", null,null);
              }
            }
View Full Code Here


      return false;
    }
   
    String strName=strNameNormal.toLowerCase();
    String appendix=null;
    TagLibTag tagLibTag=tagLib.getTag(strName);
   
    // get taglib
    if(tagLibTag==null)  {
      tagLibTag=tagLib.getAppendixTag(strName);
       if(tagLibTag==null) {
         if(tagLib.getIgnoreUnknowTags()){
           data.cfml.setPos(start);
           return false;
         }
         throw new TemplateException(data.cfml,"undefined tag ["+tagLib.getNameSpaceAndSeparator()+strName+"]");
       }
      appendix=StringUtil.removeStartingIgnoreCase(strNameNormal,tagLibTag.getName());
     }
   
    // CFXD Element
    Tag tag;
    try {
      tag = tagLibTag.getTag(line,data.cfml.getPosition());
    }
    catch (Exception e) {
      throw new TemplateException(data.cfml,e);
    }
    parent.addStatement(tag);
   
    // get tag from tag library
     if(appendix!=null)  {
      tag.setAppendix(appendix);
      tag.setFullname(tagLibTag.getFullName().concat(appendix));
     }
     else {
       tag.setFullname(tagLibTag.getFullName());    
     }
     if(tag.getFullname().equalsIgnoreCase("cfcomponent"))data.page.setIsComponent(true)// MUST to hardcoded, to better
     else if(tag.getFullname().equalsIgnoreCase("cfinterface"))data.page.setIsInterface(true)// MUST to hardcoded, to better
      
    tag.setTagLibTag(tagLibTag);
    comment(data.cfml,true);
   
    // Tag Translator Evaluator
    if(tagLibTag.hasTteClass())  {
      data.ep.add(tagLibTag,tag,data.flibs,data.cfml);
    }
   
    //get Attributes
    attributes(data,tagLibTag,tag);
   
    if(tagLibTag.hasAttributeEvaluator()) {
      try {
        tagLibTag=tagLibTag.getAttributeEvaluator().evaluate(tagLibTag,tag);
      } catch (AttributeEvaluatorException e) {
       
        throw new TemplateException(data.cfml, e);
      }
    }
   
   
   
    // End of begin Tag
//    TODO muss erlaubt sein
    if(data.cfml.forwardIfCurrent('>'))  {
      hasBody=tagLibTag.getHasBody();
    }
    else if(data.cfml.forwardIfCurrent('/','>')) {
      if(tagLibTag.getHasBody())tag.setBody(new BodyBase());
    }
    else {
      throw createTemplateException(data.cfml, "tag ["+tagLibTag.getFullName()+"] is not closed",tagLibTag);
    }
   

    // Body
    if(hasBody)  {

       
      // get Body
      if(tagLibTag.isTagDependent()) {
        // get TagDependentBodyTransformer
        TagDependentBodyTransformer tdbt=null;
        try {
          tdbt=tagLibTag.getBodyTransformer();
        } catch (TagLibException e) {
          throw new TemplateException(data.cfml,e);
        }
        if(tdbt==null) throw createTemplateException(data.cfml,"Tag dependent body Transformer is invalid for Tag ["+tagLibTag.getFullName()+"]",tagLibTag);
        tdbt.transform(data.page,this,data.ep,data.flibs,tag,tagLibTag,data.scriptTags,data.cfml,data.settings);
       
        //  get TagLib of end Tag
        if(!data.cfml.forwardIfCurrent("</")) {
          // MUST this is a patch, do a more proper implementation
          TemplateException te = new TemplateException(data.cfml,"invalid construct");
          if(tdbt instanceof CFMLScriptTransformer && ASMUtil.containsComponent(tag.getBody())) {
            throw new CFMLScriptTransformer.ComponentTemplateException(te);
          }
          throw te;
        }
       
        TagLib tagLibEnd=nameSpace(data);
        // same NameSpace
        if(!(tagLibEnd!=null && tagLibEnd.getNameSpaceAndSeparator().equals(tagLib.getNameSpaceAndSeparator())))
          throw new TemplateException(data.cfml,"invalid construct");
        // get end Tag
        String strNameEnd=identifier(data.cfml,true).toLowerCase();

        // not the same name Tag
        if(!strName.equals(strNameEnd)) {
          data.cfml.setPos(start);
          throw new TemplateException(data.cfml,"Start and End Tag has not the same Name ["+tagLib.getNameSpaceAndSeparator()+strName+"-"+tagLibEnd.getNameSpaceAndSeparator()+strNameEnd+"]");       
         }
         data.cfml.removeSpace();
         if(!data.cfml.forwardIfCurrent('>'))
           throw new TemplateException(data.cfml,"End Tag ["+tagLibEnd.getNameSpaceAndSeparator()+strNameEnd+"] not closed");
      }
      else {
        // get body of Tag
        BodyBase body=new BodyBase();
        body.setParent(tag);
        //tag.setBody(body);
          //parseExpression=(tagLibTag.getParseBody())?true:parseExpression;
        if(tagLibTag.getParseBody())parseExpression=true;
       
        while(true)  {
         
          // Load Expession Transformer from TagLib
          ExprTransformer transfomer=null;
          if(parseExpression) {
            try {
              transfomer = tagLibTag.getTagLib().getExprTransfomer();
            } catch (TagLibException e) {
              throw new TemplateException(data.cfml,e);
            }
          }
         

          // call body
         
            body(data,body,parseExpression,transfomer);
          
           
            // no End Tag
          if(data.cfml.isAfterLast()) {
             
            if(tagLibTag.isBodyReq()) {
                data.cfml.setPos(start);
              throw createTemplateException(data.cfml,"No matching end tag found for tag ["+tagLibTag.getFullName()+"]",tagLibTag);
            }
            body.moveStatmentsTo(parent);
            return executeEvaluator(data,tagLibTag, tag);
          }
         
          // Invalid Construct
          int posBeforeEndTag=data.cfml.getPos();
          if(!data.cfml.forwardIfCurrent('<','/'))
            throw createTemplateException(data.cfml,"Missing end tag for ["+tagLibTag.getFullName()+"]",tagLibTag);
         
          // get TagLib of end Tag
          int _start = data.cfml.getPos();
          TagLib tagLibEnd=nameSpace(data);
         
          // same NameSpace
          if(tagLibEnd!=null)  {
              String strNameEnd="";
              //railo.print.ln(data.cfml.getLine()+" - "+data.cfml.getColumn()+" - "+tagLibEnd.getNameSpaceAndSeperator()+".equals("+tagLib.getNameSpaceAndSeperator()+")");
              if(tagLibEnd.getNameSpaceAndSeparator().equals(tagLib.getNameSpaceAndSeparator())) {
                 
                // get end Tag
              strNameEnd=identifier(data.cfml,true).toLowerCase();
              // not the same name Tag
             
              // new part
              data.cfml.removeSpace();
              if(strName.equals(strNameEnd)) {
                  if(!data.cfml.forwardIfCurrent('>'))
                  throw new TemplateException(data.cfml,"End Tag ["+tagLibEnd.getNameSpaceAndSeparator()+strNameEnd+"] not closed");
                break;
              }
             
              }
              // new part
              if(tagLibTag.isBodyReq()) {
              TagLibTag endTag = tagLibEnd.getTag(strNameEnd);
              if(endTag!=null && !endTag.getHasBody())
                throw new TemplateException(data.cfml,
                    "End Tag ["+
                    tagLibEnd.getNameSpaceAndSeparator()+strNameEnd+"] is not allowed, for this tag only a Start Tag is allowed");
              data.cfml.setPos(start);
              if(tagLibEnd.getIgnoreUnknowTags() && (tagLibEnd.getTag(strNameEnd))==null){
View Full Code Here

   * @param doReuse
   * @throws BytecodeException
   */
  public static void writeOut(Tag tag, BytecodeContext bc, boolean doReuse, final FlowControlFinal fcf) throws BytecodeException {
    final GeneratorAdapter adapter = bc.getAdapter();
    final TagLibTag tlt = tag.getTagLibTag();
    final Type currType=getTagType(tag);
   
    final int currLocal=adapter.newLocal(currType);
    Label tagBegin=new Label();
    Label tagEnd=new Label();
    ExpressionUtil.visitLine(bc, tag.getStart());
    // TODO adapter.visitLocalVariable("tag", "L"+currType.getInternalName()+";", null, tagBegin, tagEnd, currLocal);

    adapter.visitLabel(tagBegin);
   
  // tag=pc.use(str);
    adapter.loadArg(0);
    adapter.push(tlt.getTagClassName());
    adapter.invokeVirtual(Types.PAGE_CONTEXT, USE);
    adapter.checkCast(currType);
    adapter.storeLocal(currLocal);
 
  TryFinallyVisitor outerTcfv=new TryFinallyVisitor(new OnFinally() {
    public void writeOut(BytecodeContext bc) {

      adapter.loadArg(0);
      adapter.loadLocal(currLocal);
      adapter.invokeVirtual(Types.PAGE_CONTEXT, RE_USE);
    }
  },null);
  if(doReuse)outerTcfv.visitTryBegin(bc);
   
  // appendix
    if(tlt.hasAppendix()) {
      adapter.loadLocal(currLocal);
      adapter.push(tag.getAppendix());
      adapter.invokeVirtual(currType, SET_APPENDIX);
    }
 
  // hasBody
    boolean hasBody=tag.getBody()!=null;
    if(tlt.isBodyFree() && tlt.hasBodyMethodExists()) {
      adapter.loadLocal(currLocal);
      adapter.push(hasBody);
      adapter.invokeVirtual(currType, HAS_BODY);
    }
   
  // attributes
    Attribute attr;
   
    // attributeCollection
    attr=tag.getAttribute("attributecollection");
    if(attr!=null){
      int attrType = tag.getTagLibTag().getAttributeType();
      if(TagLibTag.ATTRIBUTE_TYPE_NONAME!=attrType) {
        tag.removeAttribute("attributecollection");
        // TagUtil.setAttributeCollection(Tag, Struct)
        adapter.loadArg(0);
        adapter.loadLocal(currLocal);
        adapter.cast(currType, TAG);
       
        ///
        Map missings = tag.getMissingAttributes();
        if(missings.size()>0) {
          ArrayVisitor av=new ArrayVisitor();
                av.visitBegin(adapter,MISSING_ATTRIBUTE,missings.size());
                Map.Entry entry;
                int count=0;
                Iterator it = missings.entrySet().iterator();
                while(it.hasNext()){
                  entry=(Entry) it.next();
              av.visitBeginItem(adapter, count++);
                Variable.registerKey(bc, LitString.toExprString((String)entry.getKey()));
                adapter.push((String)entry.getValue());
                adapter.invokeStatic(MISSING_ATTRIBUTE, NEW_INSTANCE_MAX);
              av.visitEndItem(bc.getAdapter());
                }
                av.visitEnd();
        }
        else {
          ASMConstants.NULL(adapter);
        }
        ///
        attr.getValue().writeOut(bc, Expression.MODE_REF);
       
        adapter.push(attrType);
        adapter.invokeStatic(TAG_UTIL, SET_ATTRIBUTE_COLLECTION);
      }
    }


    // metadata
    Map<String, Attribute> metadata = tag.getMetaData();
    if(metadata!=null){
      Iterator<Attribute> it = metadata.values().iterator();
      while(it.hasNext()) {
        attr=it.next();
          adapter.loadLocal(currLocal);
          adapter.push(attr.getName());
          attr.getValue().writeOut(bc, Expression.MODE_REF);
          adapter.invokeVirtual(currType, SET_META_DATA);
      }
    }
   
   
   
    String methodName;
    Map attributes = tag.getAttributes();

    // static attributes
    Iterator it = attributes.values().iterator();
    while(it.hasNext()) {
      attr=(Attribute) it.next();
      if(!attr.isDynamicType()){
        Type type = CastOther.getType(attr.getType());
        methodName=tag.getTagLibTag().getSetter(attr,type);
        adapter.loadLocal(currLocal);
        attr.getValue().writeOut(bc, Types.isPrimitiveType(type)?Expression.MODE_VALUE:Expression.MODE_REF);
        adapter.invokeVirtual(currType, new Method(methodName,Type.VOID_TYPE,new Type[]{type}));
      }
    }
   
    // dynamic attributes
    it = attributes.values().iterator();
    while(it.hasNext()) {
      attr=(Attribute) it.next();
      if(attr.isDynamicType()){
        adapter.loadLocal(currLocal);
        adapter.visitInsn(Opcodes.ACONST_NULL);
        //adapter.push(attr.getName());
        Variable.registerKey(bc, LitString.toExprString(attr.getName()));
        attr.getValue().writeOut(bc, Expression.MODE_REF);
        adapter.invokeVirtual(currType, SET_DYNAMIC_ATTRIBUTE);
      }
    }
   
   
  // Body
    if(hasBody){
      final int state=adapter.newLocal(Types.INT_VALUE);
     
      // int state=tag.doStartTag();
      adapter.loadLocal(currLocal);
      adapter.invokeVirtual(currType, DO_START_TAG);
      adapter.storeLocal(state);
     
      // if (state!=Tag.SKIP_BODY)
      Label endBody=new Label();
      adapter.loadLocal(state);
      adapter.push(javax.servlet.jsp.tagext.Tag.SKIP_BODY);
      adapter.visitJumpInsn(Opcodes.IF_ICMPEQ, endBody);
        // pc.initBody(tag, state);
        adapter.loadArg(0);
        adapter.loadLocal(currLocal);
        adapter.loadLocal(state);
        adapter.invokeVirtual(Types.PAGE_CONTEXT, INIT_BODY);
       
       
        OnFinally onFinally = new OnFinally() {
         
          public void writeOut(BytecodeContext bc) {
            Label endIf = new Label();
            /*if(tlt.handleException() && fcf!=null && fcf.getAfterFinalGOTOLabel()!=null){
              ASMUtil.visitLabel(adapter, fcf.getFinalEntryLabel());
            }*/
            adapter.loadLocal(state);
            adapter.push(javax.servlet.jsp.tagext.Tag.EVAL_BODY_INCLUDE);
            adapter.visitJumpInsn(Opcodes.IF_ICMPEQ, endIf);
              // ... pc.popBody();
              adapter.loadArg(0);
              adapter.invokeVirtual(Types.PAGE_CONTEXT, POP_BODY);
              adapter.pop();
            adapter.visitLabel(endIf);
         
            // tag.doFinally();
            if(tlt.handleException()) {
              adapter.loadLocal(currLocal);
              adapter.invokeVirtual(currType, DO_FINALLY);
            }
            // GOTO after execution body, used when a continue/break was called before
            /*if(fcf!=null) {
              Label l = fcf.getAfterFinalGOTOLabel();
              if(l!=null)adapter.visitJumpInsn(Opcodes.GOTO, l);
            }*/
           
          }
        };
       
       
        if(tlt.handleException()) {
          TryCatchFinallyVisitor tcfv=new TryCatchFinallyVisitor(onFinally,fcf);
          tcfv.visitTryBegin(bc);
            doTry(bc,adapter,tag,currLocal,currType);
          int t=tcfv.visitTryEndCatchBeging(bc);
            // tag.doCatch(t);
View Full Code Here

      adapter.push(IterationTag.EVAL_BODY_AGAIN);
    adapter.visitJumpInsn(Opcodes.IF_ICMPEQ, beginDoWhile);
  }

  private static Type getTagType(Tag tag) throws BytecodeException {
    TagLibTag tlt = tag.getTagLibTag();
    try {
      return tlt.getTagType();
    } catch (ClassException e) {
      throw new BytecodeException(e,tag.getStart());
    }
  }
View Full Code Here

    TagLib[] tlds;
    tlds = ((ConfigImpl)pc.getConfig()).getTLDs();

   
    TagLib tld=null;
    TagLibTag tag=null;
    for(int i=0;i<tlds.length;i++) {
        tld=tlds[i];
      if(tld.getNameSpaceAndSeparator().equalsIgnoreCase(nameSpace)) {
          tag = tld.getTag(strTagName.toLowerCase());
          if(tag!=null)break;
      }
     
    }
    if(tag == null) throw new ExpressionException("tag ["+nameSpace+strTagName+"] is not a built in tag");

    // CFML Based Function
    Class clazz=null;
    try{
      clazz=tag.getClazz();
    }
    catch(Throwable t){}
   
    if(clazz==CFTagCore.class){
      PageContextImpl pci=(PageContextImpl) pc;
View Full Code Here

    if(sct==null) {
        sct=new StructImpl();
      //synchronized(sct) {
        //hasSet=true;
        TagLib[] tlds;
        TagLibTag tag;
        tlds = ((ConfigImpl)pc.getConfig()).getTLDs();
       
        for(int i=0;i<tlds.length;i++) {
            String ns = tlds[i].getNameSpaceAndSeparator();
           
           
          Map tags = tlds[i].getTags();
          Iterator it = tags.keySet().iterator();
          Struct inner=new StructImpl();
                    sct.set(ns,inner);
          while(it.hasNext()){
            Object n=it.next();
            tag = tlds[i].getTag(n.toString());
            if(tag.getStatus()!=TagLib.STATUS_HIDDEN && tag.getStatus()!=TagLib.STATUS_UNIMPLEMENTED)
              inner.set(n.toString(),"");
          }
         
        }
      //}
View Full Code Here

    private static String getName(PageContext pc, Tag tag) {
      Class clazz = tag.getClass();
        if(clazz==CFImportTag.class)clazz=CFTag.class;
        String className=clazz.getName();
        TagLib[] tlds = ((ConfigImpl)pc.getConfig()).getTLDs();
        TagLibTag tlt;
       
       
       
        for(int i=0;i<tlds.length;i++) {
            //String ns = tlds[i].getNameSpaceAndSeparator();
           
           
            Map tags = tlds[i].getTags();
            Iterator it = tags.keySet().iterator();
           
            while(it.hasNext()){
                tlt=(TagLibTag) tags.get(it.next());
                if(tlt.getTagClassName().equals(className)) {
                    // custm tag
                  if(tag instanceof AppendixTag) {
                        AppendixTag atag=(AppendixTag)tag;
                        if(atag.getAppendix()!=null && !(tag instanceof Module)) {
                            return tlt.getFullName().toUpperCase()+atag.getAppendix().toUpperCase();
                        }
                    }
                  // built in cfc based custom tag
                  if(tag instanceof CFTagCore) {
                    if(((CFTagCore)tag).getName().equals(tlt.getAttribute("__name").getDefaultValue()))
                      return tlt.getFullName().toUpperCase();
                    continue;
                  }
                 
                  return tlt.getFullName().toUpperCase();
                }
            }
        }
        return ListUtil.last(className,".",true).toUpperCase();
       
View Full Code Here

TOP

Related Classes of railo.transformer.library.tag.TagLibTag

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.