Changeset 909


Ignore:
Timestamp:
2008-12-02 12:23:33 (4 years ago)
Author:
jgou
Message:

make t:init compatible with t:import/t:include
see http://kauriproject.org/trac/ticket/130 and http://kauriproject.org/trac/ticket/149

Location:
trunk/universe/kauri-template/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/universe/kauri-template/src/main/java/org/kauriproject/template/DocumentBlock.java

    r822 r909  
    7171            if (!include) { 
    7272                context.getMacroRegistry().putAll(getCompiledTemplate().getMacroRegistry()); 
    73                 // TODO: always or conditional ? add to start or end of list ? 
    74                 context.getExtendList().addAll(0, getCompiledTemplate().getExtendList()); 
    7573            } 
    7674            if (!context.isInherited() && !include) { 
     
    7876            } 
    7977 
     78            // update init context 
     79            context.getInitList().addAll(0, getCompiledTemplate().getExtendList()); 
     80             
    8081            return super.executeAndProceed(context, result); 
    8182        } 
     
    104105 
    105106            if (!context.isInherited()) { 
    106                 result.endDocument(); 
     107                result.endDocument(); 
    107108            } 
    108109            return super.executeAndProceed(context, result); 
  • trunk/universe/kauri-template/src/main/java/org/kauriproject/template/ExecutionContext.java

    r841 r909  
    4444    private Map<String, List<InheritanceBlock>> inheritanceChain; 
    4545    private Stack<SuperBlock> superBlockStack; 
    46     private List<InitBlock> extendList; 
     46    private Stack<List<InitBlock>> initStack; 
    4747 
    4848    private int inherited = 0; 
     
    6666        this.inheritanceChain = new HashMap<String, List<InheritanceBlock>>(); 
    6767        this.superBlockStack = new Stack<SuperBlock>(); 
    68         this.extendList = new ArrayList<InitBlock>(); 
     68        this.initStack = new Stack<List<InitBlock>>(); 
     69        saveInit(); 
    6970    } 
    7071 
     
    154155        return attributes; 
    155156    } 
    156  
    157     public List<InitBlock> getExtendList() { 
    158         return extendList; 
     157     
     158    public List<InitBlock> getInitList() { 
     159        return initStack.peek(); 
    159160    } 
    160161     
     162    public List<InitBlock> saveInit() { 
     163        List<InitBlock> list = new ArrayList<InitBlock>(); 
     164        return initStack.push(list); 
     165    } 
     166     
     167    public List<InitBlock> restoreInit() { 
     168        return initStack.pop(); 
     169    } 
     170 
    161171    public void setExtending(boolean extending) { 
    162172        this.extending = extending; 
  • trunk/universe/kauri-template/src/main/java/org/kauriproject/template/ImportBlock.java

    r832 r909  
    104104            } 
    105105 
    106             // start new context 
     106            // start new template and init context 
    107107            context.getTemplateContext().saveContext(); 
     108            context.saveInit(); 
    108109 
    109110            return imported; 
     
    124125            } 
    125126 
    126             // restore context 
     127            // restore template and init context 
    127128            context.getTemplateContext().restoreContext(); 
     129            context.restoreInit(); 
    128130            return super.executeAndProceed(context, result); 
    129131        } 
  • trunk/universe/kauri-template/src/main/java/org/kauriproject/template/IncludeBlock.java

    r832 r909  
    109109            context.getMacroRegistry().putAll(included.getMacroRegistry()); 
    110110 
     111            // start new init context 
     112            context.saveInit(); 
     113 
    111114            return included; 
    112115        } 
     
    122125            super(templateBlock, locator); 
    123126        } 
    124          
     127 
    125128        @Override 
    126129        public Step executeAndProceed(ExecutionContext context, TemplateResult result) throws SAXException { 
     
    128131                context.setSilencing(false); 
    129132            } 
     133            // restore init context 
     134            context.restoreInit(); 
    130135            return super.executeAndProceed(context, result); 
    131136        } 
  • trunk/universe/kauri-template/src/main/java/org/kauriproject/template/OutputBlock.java

    r894 r909  
    9191            result.startElement(el.getUri(), el.getLocalName(), el.getName(), atts); 
    9292 
    93             if (root && context.getExtendList().size() > 0) { 
     93            if (root && context.getInitList().size() > 0) { 
    9494                context.setExtending(true); 
    9595                // execute the extend blocks before proceding to next 
    96                 for (InitBlock extendBlock : context.getExtendList()) { 
     96                for (InitBlock extendBlock : context.getInitList()) { 
    9797                    context.getExecutor().execute(extendBlock.getStartStep(), extendBlock.getEndStep().getCompiledNext(), context, result); 
    9898                } 
  • trunk/universe/kauri-template/src/test/resources/org/kauriproject/template/include.xml

    r822 r909  
    1616    <p>but now we also know ${new}</p> 
    1717    <t:callMacro name="macro" /> 
    18     <t:include src="included2.xml" mode="silent"/> 
     18    <t:include src="included2.xml" mode="silent" /> 
    1919    <p>after silent inclusion</p> 
    2020    <p>we have ${x} here</p> 
    2121    <t:callMacro name="m" /> 
     22    <t:include src="init_special.xml" /> 
    2223</root> 
  • trunk/universe/kauri-template/src/test/resources/org/kauriproject/template/include_result.xml

    r822 r909  
    1414    <p>we have ieks here</p> 
    1515    <p>pee and ieks</p> 
     16    <root xmlns:t="http://kauriproject.org/template"> 
     17        <a>aa en ieks</a> 
     18        <b>bee en "ei en ieks"</b> 
     19    </root> 
    1620</root> 
Note: See TracChangeset for help on using the changeset viewer.