本文整理汇总了Java中org.apache.velocity.exception.MethodInvocationException类的典型用法代码示例。如果您正苦于以下问题:Java MethodInvocationException类的具体用法?Java MethodInvocationException怎么用?Java MethodInvocationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MethodInvocationException类属于org.apache.velocity.exception包,在下文中一共展示了MethodInvocationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mergeTemplate
import org.apache.velocity.exception.MethodInvocationException; //导入依赖的package包/类
/**
* Merge the template with the context.
* Can be overridden to customize the behavior.
* @param template the template to merge
* @param context the Velocity context to use for rendering
* @param response servlet response (use this to get the OutputStream or Writer)
* @throws Exception if thrown by Velocity
* @see org.apache.velocity.Template#merge
*/
protected void mergeTemplate(
Template template, Context context, HttpServletResponse response) throws Exception {
try {
template.merge(context, response.getWriter());
}
catch (MethodInvocationException ex) {
Throwable cause = ex.getWrappedThrowable();
throw new NestedServletException(
"Method invocation failed during rendering of Velocity view with name '" +
getBeanName() + "': " + ex.getMessage() + "; reference [" + ex.getReferenceName() +
"], method '" + ex.getMethodName() + "'",
cause==null ? ex : cause);
}
}
示例2: render
import org.apache.velocity.exception.MethodInvocationException; //导入依赖的package包/类
@Override
public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
String value = (String) node.jjtGetChild(0).value(context);
String character = (String) node.jjtGetChild(1).value(context);
int len = value.length();
StringBuilder sb = new StringBuilder(len);
sb.append(value.charAt(0));
for (int i = 1; i < len; i++) {
char c = value.charAt(i);
if (Character.isUpperCase(c)) {
sb.append(character).append(Character.toLowerCase(c));
} else {
sb.append(c);
}
}
writer.write(sb.toString());
return true;
}
示例3: wal
import org.apache.velocity.exception.MethodInvocationException; //导入依赖的package包/类
@Override
public WAL wal(String topicsDir, TopicPartition topicPart) {
try {
Class<? extends WAL> walClass = (Class<? extends WAL>) Class
.forName(config.getString(S3SinkConnectorConfig.WAL_CLASS_CONFIG));
if (walClass.equals(DummyWAL.class)) {
return new DummyWAL();
}
else {
Constructor<? extends WAL> ctor = walClass.getConstructor(String.class, TopicPartition.class, Storage.class, HdfsSinkConnectorConfig.class);
return ctor.newInstance(topicsDir, topicPart, this, config);
}
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | MethodInvocationException | InstantiationException | IllegalAccessException e) {
throw new ConnectException(e);
}
}
示例4: render
import org.apache.velocity.exception.MethodInvocationException; //导入依赖的package包/类
@Override
public boolean render(RenderHandler handler)
throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, IOException {
String src = handler.getStringParameter(0);
String base = handler.getRequest().getContextPath();
// 判断是否启用图片域名
if (Global.getImageDomain()) {
base = Global.getImageHost();
}
StringBuffer buf = new StringBuffer();
buf.append(base);
buf.append(src);
handler.write(buf.toString());
return true;
}
示例5: render
import org.apache.velocity.exception.MethodInvocationException; //导入依赖的package包/类
@Override
public boolean render(RenderHandler handler) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, IOException {
ServletRequest request = handler.getRequest();
// request 获取参数
String ord = ServletRequestUtils.getStringParameter(request, "ord", Consts.order.NEWEST);
int pn = ServletRequestUtils.getIntParameter(request, "pn", 1);
// 标签中获取参数
int groupId = handler.getIntParameter(0);
String alias = handler.getStringParameter(1);
Paging paging = wrapPaing(pn);
Paging result = postPlanet.paging(paging, groupId, ord);
handler.put(alias, result);
handler.doRender();
postRender(handler.getContext());
return true;
}
示例6: render
import org.apache.velocity.exception.MethodInvocationException; //导入依赖的package包/类
public boolean render(InternalContextAdapter ctx, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
// get the bean
ValueStack stack = (ValueStack) ctx.get("stack");
HttpServletRequest req = (HttpServletRequest) stack.getContext().get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse res = (HttpServletResponse) stack.getContext().get(ServletActionContext.HTTP_RESPONSE);
Component bean = getBean(stack, req, res);
Container container = (Container) stack.getContext().get(ActionContext.CONTAINER);
container.inject(bean);
// get the parameters
Map params = createPropertyMap(ctx, node);
bean.copyParams(params);
//bean.addAllParameters(params);
bean.start(writer);
if (getType() == BLOCK) {
Node body = node.jjtGetChild(node.jjtGetNumChildren() - 1);
body.render(ctx, writer);
}
bean.end(writer, "");
return true;
}
示例7: render
import org.apache.velocity.exception.MethodInvocationException; //导入依赖的package包/类
@Override
public boolean render(InternalContextAdapter context, Writer writer,
Node node) throws IOException, ResourceNotFoundException,
ParseErrorException, MethodInvocationException
{
int argsNum = node.jjtGetNumChildren();
for(int step = 0 ; step < argsNum; step++)
{
SimpleNode simpleNode = (SimpleNode) node.jjtGetChild(step);
Object argObject = simpleNode.value(context);
//传入参数
if(argObject instanceof String)
{
System.out.println((String)argObject);
writer.write((String)argObject);
writer.flush();
}
}
return true;
}
示例8: renderTemplate
import org.apache.velocity.exception.MethodInvocationException; //导入依赖的package包/类
/**
* Return the String representation of the template rendered using Velocity.
*
* @param context context use to render the template
* @param templateFileName file name of the template in the classpath
* @throws TemplateRenderException if there is an error with the template
*/
public static String renderTemplate(String templateFileName,
VelocityContext context)
throws TemplateRenderException {
VelocityEngine ve = new VelocityEngine();
ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
ve.setProperty("classpath.resource.loader.class",
ClasspathResourceLoader.class.getName());
StringWriter sw = new StringWriter();
try {
ve.mergeTemplate(templateFileName, "UTF-8", context, sw);
} catch (ResourceNotFoundException
| ParseErrorException
| MethodInvocationException e) {
throw new TemplateRenderException("Error rendering template file: " + templateFileName, e);
}
return sw.toString();
}
示例9: prepareVelocityTemplate
import org.apache.velocity.exception.MethodInvocationException; //导入依赖的package包/类
private Set<String> prepareVelocityTemplate(String template) throws PIPException {
VelocityContext vctx = new VelocityContext();
EventCartridge vec = new EventCartridge();
VelocityParameterReader reader = new VelocityParameterReader();
vec.addEventHandler(reader);
vec.attachToContext(vctx);
try {
Velocity.evaluate(vctx, new StringWriter(), "LdapResolver", template);
} catch (ParseErrorException pex) {
throw new PIPException("Velocity template preparation failed", pex);
} catch (MethodInvocationException mix) {
throw new PIPException("Velocity template preparation failed", mix);
} catch (ResourceNotFoundException rnfx) {
throw new PIPException("Velocity template preparation failed", rnfx);
}
if (this.logger.isTraceEnabled()) {
this.logger.trace("(" + id + ") " + template + " with parameters " + reader.parameters);
}
return reader.parameters;
}
示例10: evaluateVelocityTemplate
import org.apache.velocity.exception.MethodInvocationException; //导入依赖的package包/类
private String evaluateVelocityTemplate(String template,
final Map<String, PIPRequest> templateParameters,
final PIPFinder pipFinder)
throws PIPException {
StringWriter out = new StringWriter();
VelocityContext vctx = new VelocityContext();
EventCartridge vec = new EventCartridge();
VelocityParameterWriter writer = new VelocityParameterWriter(pipFinder, templateParameters);
vec.addEventHandler(writer);
vec.attachToContext(vctx);
try {
Velocity.evaluate(vctx, out, "LdapResolver", template);
} catch (ParseErrorException pex) {
throw new PIPException("Velocity template evaluation failed", pex);
} catch (MethodInvocationException mix) {
throw new PIPException("Velocity template evaluation failed", mix);
} catch (ResourceNotFoundException rnfx) {
throw new PIPException("Velocity template evaluation failed", rnfx);
}
this.logger.warn("(" + id + ") " + " template yields " + out.toString());
return out.toString();
}
示例11: render
import org.apache.velocity.exception.MethodInvocationException; //导入依赖的package包/类
public boolean render(InternalContextAdapter context, Writer writer, Node node)
throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
//render content
StringWriter content = new StringWriter();
node.jjtGetChild(0).render(context, content);
//compress
try {
writer.write(htmlCompressor.compress(content.toString()));
} catch (Exception e) {
writer.write(content.toString());
String msg = "Failed to compress content: "+content.toString();
log.error(msg, e);
throw new RuntimeException(msg, e);
}
return true;
}
示例12: render
import org.apache.velocity.exception.MethodInvocationException; //导入依赖的package包/类
public boolean render(InternalContextAdapter context, Writer writer, Node node)
throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
//render content
StringWriter content = new StringWriter();
node.jjtGetChild(0).render(context, content);
//compress
try {
writer.write(xmlCompressor.compress(content.toString()));
} catch (Exception e) {
writer.write(content.toString());
String msg = "Failed to compress content: "+content.toString();
log.error(msg, e);
throw new RuntimeException(msg, e);
}
return true;
}
示例13: evaluate
import org.apache.velocity.exception.MethodInvocationException; //导入依赖的package包/类
public String evaluate(Map<String, Object> context, TemplatePack templatePack, Template template) throws IOException {
StringWriter sw = new StringWriter();
try {
engine.evaluate(new VelocityContext(context), sw, template.getName(), template.getTemplate());
return sw.toString();
} catch (ParseErrorException parseException) {
handleStopFileGeneration(parseException);
log.error("In " + templatePack.getName() + ":" + template.getName() + " template, parse exception " + parseException.getMessage(),
parseException.getCause());
displayLinesInError(parseException, templatePack, template);
throw new IllegalStateException();
} catch (MethodInvocationException mie) {
handleStopFileGeneration(mie);
log.error("In " + templatePack.getName() + ":" + mie.getTemplateName() + " method [" + mie.getMethodName() + "] has not been set", mie.getCause());
displayLinesInError(mie, templatePack, template);
throw mie;
} finally {
closeQuietly(sw);
}
}
示例14: render
import org.apache.velocity.exception.MethodInvocationException; //导入依赖的package包/类
public boolean render( InternalContextAdapter context, Writer writer, org.apache.velocity.runtime.parser.node.Node node ) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
String var = node.jjtGetChild( 0 ).getFirstToken().image.substring( 1 );
Node document = ( Node ) node.jjtGetChild( 1 ).value( context );
String xpath = String.valueOf( node.jjtGetChild( 2 ).value( context ) );
XPath xPath = XPathFactory.newInstance().newXPath();
try {
Node element = ( Node ) xPath.evaluate( xpath, document, XPathConstants.NODE );
if( element != null )
if( TEXT_NODES.contains( element.getNodeType() ) )
context.put( var, element.getTextContent() );
else context.put( var, element );
else log.warn( "for " + xpath + " nothing found" );
} catch( XPathExpressionException e ) {
throw new IOException( "cannot evaluate xpath: " + e.getMessage() );
}
return true;
}
示例15: render
import org.apache.velocity.exception.MethodInvocationException; //导入依赖的package包/类
public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
if(node.jjtGetNumChildren() != 1){
throw new RuntimeException(getName() + " only and must accept one parameter!") ;
}
Object param2 = node.jjtGetChild(0).value(context) ;
//如果为null,则什么都不输出。
if(param2 != null){
String param = String.valueOf(param2) ;
param = StringUtil.replaceStringIgnoreCase(param, "<script", "< script") ;
param = StringUtil.replaceStringIgnoreCase(param, "</script", "</ script") ;
writer.append(param) ;
}
return true;
}