Changeset 1346
- Timestamp:
- 02/07/09 15:06:52 (8 months ago)
- Files:
-
- trunk/universe/kauri-template/src/main/java/org/kauriproject/template/CallMacroBlock.java (modified) (1 diff)
- trunk/universe/kauri-template/src/main/java/org/kauriproject/template/CommentBlock.java (modified) (1 diff)
- trunk/universe/kauri-template/src/main/java/org/kauriproject/template/DefaultTemplateBuilder.java (modified) (6 diffs)
- trunk/universe/kauri-template/src/main/java/org/kauriproject/template/Directive.java (modified) (2 diffs)
- trunk/universe/kauri-template/src/main/java/org/kauriproject/template/ElementBlock.java (modified) (1 diff)
- trunk/universe/kauri-template/src/main/java/org/kauriproject/template/ForEachBlock.java (modified) (1 diff)
- trunk/universe/kauri-template/src/main/java/org/kauriproject/template/IfBlock.java (modified) (1 diff)
- trunk/universe/kauri-template/src/main/java/org/kauriproject/template/ImportBlock.java (modified) (3 diffs)
- trunk/universe/kauri-template/src/main/java/org/kauriproject/template/IncludeBlock.java (modified) (3 diffs)
- trunk/universe/kauri-template/src/main/java/org/kauriproject/template/InheritBlock.java (modified) (1 diff)
- trunk/universe/kauri-template/src/main/java/org/kauriproject/template/InheritanceBlock.java (modified) (1 diff)
- trunk/universe/kauri-template/src/main/java/org/kauriproject/template/InsertBlock.java (modified) (1 diff)
- trunk/universe/kauri-template/src/main/java/org/kauriproject/template/KauriSaxHandler.java (modified) (2 diffs)
- trunk/universe/kauri-template/src/main/java/org/kauriproject/template/MacroBlock.java (modified) (1 diff)
- trunk/universe/kauri-template/src/main/java/org/kauriproject/template/ProtectBlock.java (modified) (2 diffs)
- trunk/universe/kauri-template/src/main/java/org/kauriproject/template/SuperBlock.java (modified) (2 diffs)
- trunk/universe/kauri-template/src/main/java/org/kauriproject/template/TemplateException.java (added)
- trunk/universe/kauri-template/src/main/java/org/kauriproject/template/VariableBlock.java (modified) (3 diffs)
- trunk/universe/kauri-template/src/main/java/org/kauriproject/template/el/Expression.java (modified) (2 diffs)
- trunk/universe/kauri-template/src/main/java/org/kauriproject/template/el/TemplateFunctionMapper.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/universe/kauri-template/src/main/java/org/kauriproject/template/CallMacroBlock.java
r1110 r1346 78 78 MacroBlock block = context.getMacroRegistry().get(getName()); 79 79 if (block == null) { 80 throw new RuntimeException("KTL: macro " + getName() + " not found, location " 81 + getLocation()); 80 throw new TemplateException("Macro " + getName() + " not found, location " + getLocation()); 82 81 } 83 82 trunk/universe/kauri-template/src/main/java/org/kauriproject/template/CommentBlock.java
r600 r1346 83 83 value = bos.toString("UTF-8"); 84 84 } catch (IOException ex) { 85 log.error(ex);85 throw new TemplateException(ex); 86 86 } 87 87 result.comment(value.toCharArray(), 0, value.length()); trunk/universe/kauri-template/src/main/java/org/kauriproject/template/DefaultTemplateBuilder.java
r1344 r1346 139 139 xmlReader.parse(is); 140 140 } catch (Exception ex) { 141 throw new RuntimeException("Error parsing template file " + source.getReference(), ex);141 throw new TemplateException("Error parsing template file " + source.getReference(), ex); 142 142 } finally { 143 143 IOUtils.closeQuietly(in); … … 160 160 parser = factory.newSAXParser(); 161 161 } catch (SAXException saxex) { 162 log.error(saxex);162 throw new TemplateException(saxex); 163 163 } catch (ParserConfigurationException parsex) { 164 log.error(parsex);164 throw new TemplateException(parsex); 165 165 } 166 166 return parser; … … 396 396 blocksPushed++; 397 397 if (macroRegistry.containsKey(macroblock.getName())) { 398 throw new RuntimeException("A macro with name " + macroblock.getName()398 throw new TemplateException("A macro with name " + macroblock.getName() 399 399 + " is already defined, location " 400 400 + macroblock.getStartStep().getLocation()); … … 417 417 418 418 if (parentBlock == null) { 419 throw new RuntimeException(419 throw new TemplateException( 420 420 "Parameter must appear as a direct child in a macro or callMacro element, location " 421 421 + parameterblock.getStartStep().getLocation()); … … 435 435 blocksPushed++; 436 436 if (inheritanceRegistry.containsKey(inheritblock.getName())) { 437 throw new RuntimeException("A block with name " + inheritblock.getName()437 throw new TemplateException("A block with name " + inheritblock.getName() 438 438 + " is already defined, location " 439 439 + inheritblock.getStartStep().getLocation()); … … 445 445 attributes), parent); 446 446 if (parent == null) { 447 throw new RuntimeException(447 throw new TemplateException( 448 448 "A call to a superBlock is only possible from within an overriding block, location " 449 449 + superblock.getStartStep().getLocation()); trunk/universe/kauri-template/src/main/java/org/kauriproject/template/Directive.java
r1344 r1346 121 121 } 122 122 123 /** 124 * Returns null if name is not recognized. 125 */ 123 126 public static Directive fromString(String name) { 124 127 if (name.equals(FOREACH.tagName)) … … 163 166 return TEXT; 164 167 else 165 return null; // throw RuntimeException ?168 return null; 166 169 } 167 170 } trunk/universe/kauri-template/src/main/java/org/kauriproject/template/ElementBlock.java
r967 r1346 67 67 // TODO is this the place and the way to check this? 68 68 if (name == null) 69 throw new RuntimeException("name attribute required on " + Directive.ELEMENT.getTagName() + " instruction.");69 throw new TemplateException("name attribute required on " + Directive.ELEMENT.getTagName() + " instruction."); 70 70 71 71 nameExpression = elFacade.createExpression(name, String.class); trunk/universe/kauri-template/src/main/java/org/kauriproject/template/ForEachBlock.java
r966 r1346 179 179 return Integer.parseInt(value); 180 180 } catch (NumberFormatException e) { 181 throw new RuntimeException("Value \"" + value + "\" is not a valid integer, in forEach attribute " + what + " at " + startStep.getLocation());181 throw new TemplateException("Value \"" + value + "\" is not a valid integer, in forEach attribute " + what + " at " + startStep.getLocation()); 182 182 } 183 183 } trunk/universe/kauri-template/src/main/java/org/kauriproject/template/IfBlock.java
r921 r1346 70 70 String expression = attributes.getValue(TEST); 71 71 if (expression == null) 72 throw new RuntimeException("if instruction is missing required test attribute. Location: " + getLocation());72 throw new TemplateException("if instruction is missing required test attribute. Location: " + getLocation()); 73 73 74 74 elExpression = elFacade.createExpression(expression, Boolean.class); trunk/universe/kauri-template/src/main/java/org/kauriproject/template/ImportBlock.java
r1111 r1346 65 65 String expression = attributes.getValue(SRC); 66 66 if (expression == null) 67 throw new RuntimeException(SRC + " attribute is required on " + templateBlock.getSaxElement().getName());67 throw new TemplateException(SRC + " attribute is required on " + templateBlock.getSaxElement().getName()); 68 68 sourceExpression = elFacade.createExpression(expression, String.class); 69 69 String mode = attributes.getValue(MODE); … … 87 87 imported = templateService.buildTemplate(sourceLocation, context, context.isSilencing()); 88 88 } catch (Exception ex) { 89 throw new RuntimeException("Error parsing template included at location " + getLocation(), ex);89 throw new TemplateException("Error parsing template included at location " + getLocation(), ex); 90 90 } 91 91 … … 93 93 // detect recursion 94 94 if (old != null) { 95 throw new RuntimeException("KTL: recursion is not allowed in import, location "95 throw new TemplateException("KTL: recursion is not allowed in import, location " 96 96 + getLocation()); 97 97 } trunk/universe/kauri-template/src/main/java/org/kauriproject/template/IncludeBlock.java
r1111 r1346 76 76 String expression = attributes.getValue(SRC); 77 77 if (expression == null) 78 throw new RuntimeException(SRC + " attribute is required on " + templateBlock.getSaxElement().getName());78 throw new TemplateException(SRC + " attribute is required on " + templateBlock.getSaxElement().getName()); 79 79 sourceExpression = elFacade.createExpression(expression, String.class); 80 80 String mode = attributes.getValue(MODE); … … 98 98 included = templateService.buildTemplate(sourceLocation, context, context.isSilencing()); 99 99 } catch (Exception ex) { 100 throw new RuntimeException("Error parsing template included at location " + getLocation(), ex);100 throw new TemplateException("Error parsing template included at location " + getLocation(), ex); 101 101 } 102 102 … … 104 104 // detect recursion 105 105 if (old != null) { 106 throw new RuntimeException("KTL: recursion is not allowed in include, location " 107 + getLocation()); 106 throw new TemplateException("Recursion is not allowed in include, location " + getLocation()); 108 107 } 109 108 trunk/universe/kauri-template/src/main/java/org/kauriproject/template/InheritBlock.java
r1020 r1346 80 80 baseTemplate = templateService.buildTemplate(sourceLocation, context); 81 81 } catch (Exception ex) { 82 throw new RuntimeException("Error parsing inherited template specified at location " + getLocation(), ex);82 throw new TemplateException("Error parsing inherited template specified at location " + getLocation(), ex); 83 83 } 84 84 trunk/universe/kauri-template/src/main/java/org/kauriproject/template/InheritanceBlock.java
r894 r1346 94 94 return chain.get(chain.size() - 1).getEndStep().getCompiledNext(); 95 95 } else { 96 throw new RuntimeException("Parent block not found for " + getName() + ", location "96 throw new TemplateException("Parent block not found for " + getName() + ", location " 97 97 + getLocation()); 98 98 } trunk/universe/kauri-template/src/main/java/org/kauriproject/template/InsertBlock.java
r900 r1346 112 112 } 113 113 } catch (FileNotFoundException ex) { 114 throw new RuntimeException("Error inserting XML from " + sourceLocation + ": " + ex);114 throw new TemplateException("Error inserting XML from " + sourceLocation + ": " + ex); 115 115 } catch (Exception ex) { 116 throw new RuntimeException("Error parsing XML from " + sourceLocation + ": " + ex);116 throw new TemplateException("Error parsing XML from " + sourceLocation + ": " + ex); 117 117 } finally { 118 118 if (source != null) { trunk/universe/kauri-template/src/main/java/org/kauriproject/template/KauriSaxHandler.java
r600 r1346 109 109 xmlHandler)) : new TransformerHandlerAdapter(xmlHandler); 110 110 } catch (TransformerConfigurationException ex) { 111 throw new RuntimeException("Error creating serializer.", ex);111 throw new TemplateException("Error creating serializer.", ex); 112 112 } 113 113 } … … 270 270 return needsIt; 271 271 } catch (Throwable t) { 272 throw new RuntimeException(272 throw new TemplateException( 273 273 "Error while testing if we need to add namespace attributes before xml serialization", t); 274 274 } trunk/universe/kauri-template/src/main/java/org/kauriproject/template/MacroBlock.java
r1110 r1346 81 81 @Override 82 82 public Step executeAndProceed(ExecutionContext context, TemplateResult result) throws SAXException { 83 throw new RuntimeException("This situation should never occur.");83 throw new TemplateException("This situation should never occur."); 84 84 } 85 85 trunk/universe/kauri-template/src/main/java/org/kauriproject/template/ProtectBlock.java
r1301 r1346 45 45 String expression = attributes.getValue(ACCESS_ATTR); 46 46 if (expression == null) 47 throw new RuntimeException("protect instruction is missing required access attribute. Location: "47 throw new TemplateException("protect instruction is missing required access attribute. Location: " 48 48 + getLocation()); 49 49 … … 55 55 AccessDecider decider = context.getAccessDecider(); 56 56 if (decider == null) 57 throw new RuntimeException("protect instruction is used but no AccessDecider is provided.");57 throw new TemplateException("protect instruction is used but no AccessDecider is provided."); 58 58 59 59 String accessString = (String) accessExpr.evaluate(context.getTemplateContext()); trunk/universe/kauri-template/src/main/java/org/kauriproject/template/SuperBlock.java
r894 r1346 66 66 public Step executeAndProceed(ExecutionContext context, TemplateResult result) throws SAXException { 67 67 if (!context.isInherited()) { 68 throw new RuntimeException(68 throw new TemplateException( 69 69 "No template inheritance, so call to super block not possible, location " 70 70 + getLocation()); … … 79 79 return chain.get(index + 1).getStartStep().getCompiledNext(); 80 80 } else { 81 throw new RuntimeException("Parent block not found for " + inheritanceBlock.getName()81 throw new TemplateException("Parent block not found for " + inheritanceBlock.getName() 82 82 + ", location " + getLocation()); 83 83 } trunk/universe/kauri-template/src/main/java/org/kauriproject/template/VariableBlock.java
r1329 r1346 37 37 */ 38 38 public class VariableBlock extends TemplateBlock { 39 40 private static Log log = LogFactory.getLog(VariableBlock.class);41 39 42 40 // VARIABLE CONSTANTS … … 135 133 buffer.endDocument(); 136 134 buffer.flush(); 137 String value = "";135 String value; 138 136 try { 139 137 bos.flush(); 140 138 value = bos.toString("UTF-8"); 141 139 } catch (IOException ex) { 142 log.error(ex);140 throw new TemplateException("Error building variable value.", ex); 143 141 } 144 142 … … 164 162 } 165 163 } catch (Throwable e) { 166 throw new RuntimeException("Some error occured while loading data for variable " + name + " from URI " + src, e);164 throw new TemplateException("Some error occured while loading data for variable " + name + " from URI " + src, e); 167 165 } finally { 168 166 if (source != null) { trunk/universe/kauri-template/src/main/java/org/kauriproject/template/el/Expression.java
r999 r1346 51 51 } 52 52 53 /** 54 * Returns null if value is not recongized. 55 */ 53 56 public static ExpressionParser fromString(String value) { 54 57 if (value.equals(EL.id)) … … 57 60 return GROOVY; 58 61 else 59 return null; // throw RuntimeException ?62 return null; 60 63 } 61 64 } trunk/universe/kauri-template/src/main/java/org/kauriproject/template/el/TemplateFunctionMapper.java
r1020 r1346 16 16 package org.kauriproject.template.el; 17 17 18 import org.apache.commons.logging.Log; 19 import org.apache.commons.logging.LogFactory; 18 import org.kauriproject.template.TemplateException; 20 19 21 20 import javax.el.FunctionMapper; … … 26 25 public class TemplateFunctionMapper extends FunctionMapper { 27 26 private Map<String, Method> functions = new HashMap<String, Method>(); 28 private Log log = LogFactory.getLog(getClass());29 27 30 28 public TemplateFunctionMapper(FunctionRegistry functionRegistry) { … … 52 50 addFunction(prefix, "max", Math.class.getMethod("max", double.class, double.class)); 53 51 addFunction(prefix, "min", Math.class.getMethod("min", double.class, double.class)); 54 // add additional math functions55 Method[] methods = MathFunctions.class.getDeclaredMethods();56 for (Method method : methods) {57 addFunction(prefix, method.getName(), method);58 }59 52 } catch (NoSuchMethodException nex) { 60 log.error("Error adding math functions to the EL: " + nex); 53 throw new TemplateException("Error registering math functions with EL", nex); 54 } 55 56 // add additional math functions 57 Method[] methods = MathFunctions.class.getDeclaredMethods(); 58 for (Method method : methods) { 59 addFunction(prefix, method.getName(), method); 61 60 } 62 61 }
