Changeset 1436 for trunk/universe/kauri-template/src/main/java/org/kauriproject/template/VariableBlock.java
- Timestamp:
- 2010-02-16 09:06:52 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/universe/kauri-template/src/main/java/org/kauriproject/template/VariableBlock.java
r1350 r1436 59 59 } 60 60 61 private static final Object NO_VALUE = new Object(); 62 61 63 class StartStep extends Step { 62 64 … … 101 103 } 102 104 105 103 106 @Override 104 107 public Step executeAndProceed(ExecutionContext context, TemplateResult result) throws SAXException { 105 108 TemplateContext tmplContext = context.getTemplateContext(); 106 109 if (overwrite || !tmplContext.containsKey(name)) { 110 Object value = NO_VALUE; 107 111 if (valueExpression != null) { 108 final Object value = valueExpression.evaluate(context.getTemplateContext()); 109 tmplContext.put(name, value); 110 } else if (srcExpression != null) { 111 Object data = loadFromSrc(context); 112 tmplContext.put(name, data); 112 value = valueExpression.evaluate(context.getTemplateContext()); 113 113 } else { 114 114 // use element body as value … … 123 123 buffer.endDocument(); 124 124 buffer.flush(); 125 String value;126 125 try { 127 126 bos.flush(); 128 value = bos.toString("UTF-8"); 127 final String content = bos.toString("UTF-8"); 128 if (content != null && content.length() > 0) 129 value = content; 129 130 } catch (IOException ex) { 130 131 throw new TemplateException("Error building variable value.", ex); 131 132 } 132 133 tmplContext.put(name, value); 134 } 135 } 133 } 134 135 // value retrieved from @value or body can be overwritten by loaded data from @src 136 if (srcExpression != null) { 137 value = loadFromSrc(context, value); 138 } 139 140 tmplContext.put(name, value); 141 } 142 136 143 return endStep.getCompiledNext(); 137 144 } 138 145 139 private Object loadFromSrc(ExecutionContext context ) {146 private Object loadFromSrc(ExecutionContext context, Object fallbackValue) { 140 147 String src = (String)srcExpression.evaluate(context.getTemplateContext()); 141 148 String accept = acceptExpression != null ? (String)acceptExpression.evaluate(context.getTemplateContext()) : null; … … 152 159 } 153 160 } catch (Throwable e) { 161 if (fallbackValue != NO_VALUE) 162 return fallbackValue; 163 // else 154 164 throw new TemplateException("Some error occured while loading data for variable " + name + " from URI " + src, e); 155 165 } finally {
Note: See TracChangeset
for help on using the changeset viewer.