Changeset 693
- Timestamp:
- 2008-10-13 08:59:27 (5 years ago)
- Location:
- trunk/universe/kauri-template/src
- Files:
-
- 1 added
- 6 edited
-
main/java/org/kauriproject/template/DefaultTemplateBuilder.java (modified) (2 diffs)
-
main/java/org/kauriproject/template/Directive.java (modified) (2 diffs)
-
main/java/org/kauriproject/template/ExecutionContext.java (modified) (4 diffs)
-
main/java/org/kauriproject/template/InheritanceBlock.java (modified) (1 diff)
-
main/java/org/kauriproject/template/SuperBlock.java (added)
-
test/resources/org/kauriproject/template/inherit_multiple.xml (modified) (2 diffs)
-
test/resources/org/kauriproject/template/inherit_multiple_result.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/universe/kauri-template/src/main/java/org/kauriproject/template/DefaultTemplateBuilder.java
r686 r693 163 163 last.setCompiledNext(endStep); 164 164 last = endStep; 165 } 166 167 protected TemplateBlock findParentOnStack(Class<? extends TemplateBlock> blockClass) { 168 boolean result = false; 169 int index = stack.size() - 1; 170 TemplateBlock block = null; 171 while (!result && index >= 0) { 172 block = stack.elementAt(index); 173 if (block.getClass().isAssignableFrom(blockClass)) { 174 result = true; 175 } 176 index--; 177 } 178 if (!result) { 179 return null; 180 } 181 return block; 165 182 } 166 183 … … 329 346 } 330 347 inheritanceRegistry.put(inheritblock.getName(), inheritblock); 348 } else if (Directive.SUPERBLOCK == directive) { 349 InheritanceBlock parent = (InheritanceBlock) findParentOnStack(InheritanceBlock.class); 350 SuperBlock superblock = new SuperBlock(locator, new SaxElement(uri, localName, name, 351 attributes), parent); 352 if (parent == null) { 353 throw new RuntimeException( 354 "A call to a superBlock is only possible from within an overriding block, location " 355 + superblock.getStartStep().getLocation()); 356 } 357 pushBlock(superblock); 331 358 } else { 332 359 log.warn("Unsupported KTL directive: " + localName); -
trunk/universe/kauri-template/src/main/java/org/kauriproject/template/Directive.java
r686 r693 99 99 * block name="blockid" 100 100 */ 101 BLOCK("block"); 101 BLOCK("block"), 102 /** 103 * directive (in block construct) to call the overriden block 104 */ 105 SUPERBLOCK("superBlock"); 102 106 103 107 private final String tagName; … … 144 148 else if (name.equals(BLOCK.tagName)) 145 149 return BLOCK; 150 else if (name.equals(SUPERBLOCK.tagName)) 151 return SUPERBLOCK; 146 152 else 147 153 return null;// throw RuntimeException ? -
trunk/universe/kauri-template/src/main/java/org/kauriproject/template/ExecutionContext.java
r686 r693 19 19 import java.util.List; 20 20 import java.util.Map; 21 import java.util.Stack; 21 22 22 23 import org.kauriproject.template.el.FunctionRegistry; … … 38 39 private Map<String, IncludeBlock> includeRegistry; 39 40 private Map<String, List<InheritanceBlock>> inheritanceChain; 41 private Stack<SuperBlock> superBlockStack; 40 42 41 43 private boolean inherited = false; … … 54 56 this.includeRegistry = new HashMap<String, IncludeBlock>(); 55 57 this.inheritanceChain = new HashMap<String, List<InheritanceBlock>>(); 58 this.superBlockStack = new Stack<SuperBlock>(); 56 59 } 57 60 … … 104 107 } 105 108 109 public Stack<SuperBlock> getSuperBlockStack() { 110 return superBlockStack; 111 } 112 106 113 } -
trunk/universe/kauri-template/src/main/java/org/kauriproject/template/InheritanceBlock.java
r686 r693 81 81 // lookup base block and execute baseblock.endstep.next 82 82 if (context.isInherited()) { 83 // InheritanceBlock block = context.getBaseTemplate().getInheritanceRegistry().get(getName()); 83 // check if this block is executed as a superblock and return to the calling block 84 if (!context.getSuperBlockStack().isEmpty()) { 85 SuperBlock superBlock = context.getSuperBlockStack().peek(); 86 return superBlock.getEndStep(); 87 } 88 // otherwise: lookup highest overridden block in chain 84 89 List<InheritanceBlock> chain = context.getInheritanceChain().get(getName()); 85 90 if (chain != null && chain.size() > 0) { -
trunk/universe/kauri-template/src/test/resources/org/kauriproject/template/inherit_multiple.xml
r686 r693 6 6 <body> 7 7 <ktl:block name="block1"> 8 <p>first block - 2nd level child</p> 8 <div> 9 <ktl:superBlock /> 10 <p>first block - 2nd level child</p> 11 <ktl:superBlock /> 12 </div> 9 13 </ktl:block> 10 14 <ktl:block name="block2"> … … 12 16 </ktl:block> 13 17 <ktl:block name="child"> 14 <p>overriding block defined in parent</p>15 </ktl:block>16 <p>blablabla</p>18 <p>overriding block defined in parent</p> 19 </ktl:block> 20 <p>blablabla</p> 17 21 </body> 18 22 </html> -
trunk/universe/kauri-template/src/test/resources/org/kauriproject/template/inherit_multiple_result.xml
r686 r693 6 6 <body> 7 7 <p>leading stuff from base</p> 8 <div> 9 <p>first block - child</p> 8 10 <p>first block - 2nd level child</p> 11 <p>first block - child</p> 12 </div> 9 13 <p>second block - 2nd level child</p> 10 14 <div>
Note: See TracChangeset
for help on using the changeset viewer.