Changeset 834
- Timestamp:
- 2008-11-26 13:13:36 (4 years ago)
- Location:
- trunk/universe/kauri-template/src/main/java/org/kauriproject/template
- Files:
-
- 1 added
- 3 edited
-
DefaultTemplateBuilder.java (modified) (3 diffs)
-
InheritBlock.java (added)
-
OutputBlock.java (modified) (6 diffs)
-
TemplateExecutor.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/universe/kauri-template/src/main/java/org/kauriproject/template/DefaultTemplateBuilder.java
r832 r834 283 283 } 284 284 285 int blocksPushed = 1; 285 286 if (silencedLevel > 0) { 286 287 silencedLevel++; 288 blocksPushed = 0; 289 } else if (root && attributes.getValue(TemplateBuilder.NAMESPACE_KTL, InheritBlock.INHERIT) != null) { 290 InheritBlock inherit = new InheritBlock(elFacade, locator, new SaxElement(uri, 291 localName, name, attributes), templateService); 292 pushBlock(inherit); 287 293 } else { 288 294 // KTL directives 289 int blocksPushed = 1;290 295 if (uri != null && uri.equals(NAMESPACE_KTL)) { 291 296 Directive directive = Directive.fromString(localName); … … 402 407 // TODO: maybe we should provide an errorblock in this case ? 403 408 OutputBlock outblock = new OutputBlock(elFacade, locator, new SaxElement("", 404 localName, localName, attributes), templateService,root);409 localName, localName, attributes), root); 405 410 pushBlock(outblock); 406 411 } … … 410 415 } else if (outputAllowed()) { // "ordinary" start elements 411 416 OutputBlock outblock = new OutputBlock(elFacade, locator, new SaxElement(uri, localName, 412 name, attributes), templateService,root);417 name, attributes), root); 413 418 pushBlock(outblock); 414 419 } else { 415 420 silencedLevel++; 416 421 } 417 if (silencedLevel == 0) 418 pushCountStack.push(blocksPushed); 419 } 420 422 } 423 if (silencedLevel == 0) 424 pushCountStack.push(blocksPushed); 421 425 } 422 426 -
trunk/universe/kauri-template/src/main/java/org/kauriproject/template/OutputBlock.java
r832 r834 17 17 18 18 import java.util.ArrayList; 19 import java.util.LinkedList;20 19 import java.util.List; 21 import java.util.Map;22 20 23 21 import org.kauriproject.template.el.ELFacade; … … 38 36 39 37 protected ELFacade elFacade; 40 protected TemplateService templateService;41 38 protected boolean root; 42 39 43 public OutputBlock(ELFacade elFacade, Locator locator, SaxElement saxElement, 44 TemplateService templateService, boolean root) { 40 public OutputBlock(ELFacade elFacade, Locator locator, SaxElement saxElement, boolean root) { 45 41 super(locator, saxElement); 46 42 this.elFacade = elFacade; 47 43 this.attributes = saxElement.getAttributes(); 48 44 this.startStep = new StartStep(this, locator); 49 this.templateService = templateService;50 45 this.root = root; 51 46 } … … 82 77 public Step executeAndProceed(ExecutionContext context, TemplateResult result) throws SAXException { 83 78 AttributesImpl atts = new AttributesImpl(attributes); 79 if (context.isSilencing()) { 80 return getEndStep().getCompiledNext(); 81 } 82 84 83 Expression elExpression; 85 84 for (int i = 0; i < attributes.getLength(); i++) { … … 88 87 } 89 88 90 if (root) {91 // check inheritance92 String sourceLocation = atts.getValue(TemplateBuilder.NAMESPACE_KTL, INHERIT);93 // TODO: check all attributes in ktl namespace, log warning if not supported94 if (sourceLocation != null) {95 sourceLocation = context.getSourceResolver().toAbsolutePath(sourceLocation, context.getBaseUri());96 // inheritance => lookup base97 CompiledTemplate baseTemplate;98 try {99 // ask service to get compiled template for sourcelocation100 // this may trigger a build of the base template101 baseTemplate = templateService.buildTemplate(sourceLocation, context);102 } catch (Exception ex) {103 throw new RuntimeException("Error generating base template, location "104 + getLocation() + " : " + ex);105 }106 107 // merge inheritance mappings108 Map<String, List<InheritanceBlock>> inheritanceChain = context.getInheritanceChain();109 Map<String, InheritanceBlock> baseRegistry = baseTemplate.getInheritanceRegistry();110 for (String block : baseRegistry.keySet()) {111 if (!inheritanceChain.containsKey(block)) {112 List<InheritanceBlock> chain = new LinkedList<InheritanceBlock>();113 chain.add(baseRegistry.get(block));114 inheritanceChain.put(block, chain);115 } else {116 inheritanceChain.get(block).add(baseRegistry.get(block));117 }118 }119 120 context.inheritInc();121 context.getExecutor().execute(baseTemplate, null, context, result);122 context.inheritDecr();123 124 return getEndStep().getCompiledNext();125 }126 }127 128 if(context.isSilencing()) {129 return getEndStep().getCompiledNext();130 }131 132 89 SaxElement el = getSaxElement(); 133 90 result.startElement(el.getUri(), el.getLocalName(), el.getName(), atts); … … 136 93 // execute the extend blocks before proceding to next 137 94 for (ExtendBlock extendBlock : context.getExtendList()) { 138 executeBlock(extendBlock, context, result);95 context.getExecutor().execute(extendBlock.getStartStep(), extendBlock.getEndStep().getCompiledNext(), context, result); 139 96 } 140 97 } … … 142 99 return super.executeAndProceed(context, result); 143 100 } 144 145 private void executeBlock(TemplateBlock block, ExecutionContext context, TemplateResult result)146 throws SAXException {147 Step step = block.getStartStep();148 Step end = block.getEndStep();149 while (step != end) {150 step = step.executeAndProceed(context, result);151 }152 end.executeAndProceed(context, result);153 }154 155 101 } 156 102 -
trunk/universe/kauri-template/src/main/java/org/kauriproject/template/TemplateExecutor.java
r816 r834 4 4 5 5 public interface TemplateExecutor { 6 /** 7 * Executes steps, starting from the startStep up to, but excluding, the endStep. 8 */ 6 9 void execute(Step startStep, Step endStep, ExecutionContext context, TemplateResult result) throws SAXException; 7 10 }
Note: See TracChangeset
for help on using the changeset viewer.