/** 规格化模板名。 */ protected final String normalizeTemplateName(String templateName) { if (isEmpty(templateName)) { throw new ResourceNotFoundException("Need to specify a template name!"); } if (templateName.startsWith("/")) { templateName = templateName.substring(1); } return templateName; }
/** * Return our custom message if we have one, else return the default message */ public String getMessage() { if (msg != null) return msg; return super.getMessage(); } }
/** * returns the wrapped Throwable that caused this * MethodInvocationException to be thrown * * @return Throwable thrown by method invocation * @since 1.5 * @deprecated Use {@link java.lang.RuntimeException#getCause()} */ public Throwable getWrappedThrowable() { return getCause(); }
public InputStream getResourceStream(String string) throws ResourceNotFoundException { try { URL url = new URL(string); return url.openStream(); } catch (IOException e) { throw (ResourceNotFoundException) new ResourceNotFoundException(string).initCause(e); } }
@Override public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException { Node escapeTypeNode = node.jjtGetChild(0); Object escapeTypeObject = escapeTypeNode.value(context); String escapeTypeString = escapeTypeObject == null ? null : escapeTypeObject.toString(); EscapeType escapeType = EscapeType.getEscapeType(escapeTypeString); if (escapeType == null) { throw new ParseErrorException("Invalid escape type: " + escapeTypeObject + " at " + new Info(escapeTypeNode.getTemplateName(), escapeTypeNode.getColumn(), escapeTypeNode.getLine()) + ". Available escape types: " + EscapeType.getNames()); } return renderWithEscape(escapeType, context, writer, node.jjtGetChild(1)); } }
@Override public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException { super.init(rs, context, node); if (node.jjtGetNumChildren() != 1) { throw new TemplateInitException("Invalid args for #" + getName() + ". Expected 0 args.", context.getCurrentTemplateName(), node.getColumn(), node.getLine()); } }
VelocitySourceInfo(ParseErrorException e) { lineNumber = e.getLineNumber(); fileName = e.getTemplateName(); lines = readTemplateSource(fileName); }
/** 规格化模板名。 */ protected final String normalizeTemplateName(String templateName) { if (isEmpty(templateName)) { throw new ResourceNotFoundException("Need to specify a template name!"); } if (templateName.startsWith("/")) { templateName = templateName.substring(1); } return templateName; }
@Override public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException { Node escapeTypeNode = node.jjtGetChild(0); Object escapeTypeObject = escapeTypeNode.value(context); String escapeTypeString = escapeTypeObject == null ? null : escapeTypeObject.toString(); EscapeType escapeType = EscapeType.getEscapeType(escapeTypeString); if (escapeType == null) { throw new ParseErrorException("Invalid escape type: " + escapeTypeObject + " at " + new Info(escapeTypeNode.getTemplateName(), escapeTypeNode.getColumn(), escapeTypeNode.getLine()) + ". Available escape types: " + EscapeType.getNames()); } return renderWithEscape(escapeType, context, writer, node.jjtGetChild(1)); } }
/** * Return our custum message if we have one, else return the default message */ public String getMessage() { if (msg != null) return msg; return super.getMessage(); } }
@Override public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException { super.init(rs, context, node); if (node.jjtGetNumChildren() != 1) { throw new TemplateInitException("Invalid args for #" + getName() + ". Expected 0 args.", context.getCurrentTemplateName(), node.getColumn(), node.getLine()); } }
public void handleStopFileGeneration(VelocityException exception) { if (exception.getCause() instanceof StopFileReachedException) { throw new StopFileReachedException(); } }
/** 取得输入流。 */ @Override public final InputStream getResourceStream(String templateName) throws ResourceNotFoundException { Resource resource = getResource(templateName); Exception exception = null; if (resource != null && resource.exists()) { try { return resource.getInputStream(); } catch (IOException e) { exception = e; } } throw new ResourceNotFoundException(getLogID() + " Error: could not find template: " + templateName, exception); }
@Override public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException { super.init(rs, context, node); if (node.jjtGetNumChildren() != 2) { throw new TemplateInitException("Invalid args for #" + getName() + ". Expected 1 and only 1 string arg.", context.getCurrentTemplateName(), node.getColumn(), node.getLine()); } }
/** 取得输入流。 */ @Override public final InputStream getResourceStream(String templateName) throws ResourceNotFoundException { Resource resource = getResource(templateName); Exception exception = null; if (resource != null && resource.exists()) { try { return resource.getInputStream(); } catch (IOException e) { exception = e; } } throw new ResourceNotFoundException(getLogID() + " Error: could not find template: " + templateName, exception); }
@Override public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException { super.init(rs, context, node); if (node.jjtGetNumChildren() != 2) { throw new TemplateInitException("Invalid args for #" + getName() + ". Expected 1 and only 1 string arg.", context.getCurrentTemplateName(), node.getColumn(), node.getLine()); } }
/** Copied from org.apache.velocity.app.VelocityEngine。 */ private boolean mergeTemplate(String templateName, String encoding, Context context, Writer writer) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, Exception { Template template = ri.getTemplate(templateName, encoding); if (template == null) { String msg = "VelocityEngine.mergeTemplate() was unable to load template '" + templateName + "'"; ri.getLog().error(msg); throw new ResourceNotFoundException(msg); } else { template.merge(context, writer); return true; } }
/** Copied from org.apache.velocity.app.VelocityEngine。 */ private boolean mergeTemplate(String templateName, String encoding, Context context, Writer writer) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, Exception { Template template = ri.getTemplate(templateName, encoding); if (template == null) { String msg = "VelocityEngine.mergeTemplate() was unable to load template '" + templateName + "'"; ri.getLog().error(msg); throw new ResourceNotFoundException(msg); } else { template.merge(context, writer); return true; } }
public String getTemplate(String key) throws ResourceNotFoundException { if (!this.store.containsKey(key)) { throw new ResourceNotFoundException("Resource not found:" + key); } return this.store.get(key); }
@Override public InputStream getResourceStream(String template_name) throws ResourceNotFoundException { try { return loader.openResource("velocity/" + template_name); } catch (IOException ioe) { throw new ResourceNotFoundException(ioe); } }