本文整理匯總了Java中org.apache.velocity.exception.ParseErrorException類的典型用法代碼示例。如果您正苦於以下問題:Java ParseErrorException類的具體用法?Java ParseErrorException怎麽用?Java ParseErrorException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ParseErrorException類屬於org.apache.velocity.exception包,在下文中一共展示了ParseErrorException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: render
import org.apache.velocity.exception.ParseErrorException; //導入依賴的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;
}
示例2: render
import org.apache.velocity.exception.ParseErrorException; //導入依賴的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;
}
示例3: render
import org.apache.velocity.exception.ParseErrorException; //導入依賴的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;
}
示例4: render
import org.apache.velocity.exception.ParseErrorException; //導入依賴的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;
}
示例5: render
import org.apache.velocity.exception.ParseErrorException; //導入依賴的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;
}
示例6: renderTemplate
import org.apache.velocity.exception.ParseErrorException; //導入依賴的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();
}
示例7: prepareVelocityTemplate
import org.apache.velocity.exception.ParseErrorException; //導入依賴的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;
}
示例8: evaluateVelocityTemplate
import org.apache.velocity.exception.ParseErrorException; //導入依賴的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();
}
示例9: testBuildSystemMonitorResponseInvalidVelocityTemplate
import org.apache.velocity.exception.ParseErrorException; //導入依賴的package包/類
@Test
public void testBuildSystemMonitorResponseInvalidVelocityTemplate() throws Exception
{
// Override the configuration to use an invalid velocity template for building the system monitor response.
Map<String, Object> overrideMap = new HashMap<>();
overrideMap.put(ConfigurationValue.HERD_NOTIFICATION_SQS_SYS_MONITOR_RESPONSE_VELOCITY_TEMPLATE.getKey(), "#if($missingEndOfIfStatement");
modifyPropertySourceInEnvironment(overrideMap);
try
{
// Try to build a system monitor response message when velocity template is invalid.
defaultNotificationMessageBuilder.buildSystemMonitorResponse(getTestSystemMonitorIncomingMessage());
fail();
}
catch (ParseErrorException e)
{
assertTrue(e.getMessage().startsWith("Encountered \"<EOF>\" at systemMonitorResponse[line 1, column 28]"));
}
finally
{
// Restore the property sources so we don't affect other tests.
restorePropertySourceInEnvironment();
}
}
示例10: render
import org.apache.velocity.exception.ParseErrorException; //導入依賴的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;
}
示例11: render
import org.apache.velocity.exception.ParseErrorException; //導入依賴的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;
}
示例12: evaluate
import org.apache.velocity.exception.ParseErrorException; //導入依賴的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);
}
}
示例13: render
import org.apache.velocity.exception.ParseErrorException; //導入依賴的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;
}
示例14: render
import org.apache.velocity.exception.ParseErrorException; //導入依賴的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;
}
示例15: render
import org.apache.velocity.exception.ParseErrorException; //導入依賴的package包/類
public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
Object value = node.jjtGetChild(0).value(context);
boolean isEmpty = false ;
if(value == null){
isEmpty = true ;
}else{
if(value instanceof String){
isEmpty = StringUtil.isEmpty((String) value) ;
}else if(value instanceof Collection){
isEmpty = ((Collection) value).isEmpty() ;
}else if(value.getClass().isArray()){
isEmpty = Array.getLength(value) > 0 ;
}
}
if (isEmpty) {
Node content = node.jjtGetChild(1);
content.render(context, writer);
}
return true;
}