本文整理汇总了Java中org.apache.velocity.context.InternalContextAdapter类的典型用法代码示例。如果您正苦于以下问题:Java InternalContextAdapter类的具体用法?Java InternalContextAdapter怎么用?Java InternalContextAdapter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InternalContextAdapter类属于org.apache.velocity.context包,在下文中一共展示了InternalContextAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: render
import org.apache.velocity.context.InternalContextAdapter; //导入依赖的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.context.InternalContextAdapter; //导入依赖的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;
}
示例3: render
import org.apache.velocity.context.InternalContextAdapter; //导入依赖的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;
}
示例4: render
import org.apache.velocity.context.InternalContextAdapter; //导入依赖的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;
}
示例5: render
import org.apache.velocity.context.InternalContextAdapter; //导入依赖的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;
}
示例6: render
import org.apache.velocity.context.InternalContextAdapter; //导入依赖的package包/类
@Override
public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException {
String block = "";
TypeDef clazz = null;
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
if (node.jjtGetChild(i) != null) {
if (!(node.jjtGetChild(i) instanceof ASTBlock)) {
//reading and casting inline parameters
if (i == 0) {
clazz = (TypeDef) node.jjtGetChild(i).value(context);
} else {
break;
}
} else {
//reading block content and rendering it
StringWriter blockContent = new StringWriter();
node.jjtGetChild(i).render(context, blockContent);
block = blockContent.toString();
break;
}
}
}
writeClazz(writer, clazz, block);
return true;
}
示例7: render
import org.apache.velocity.context.InternalContextAdapter; //导入依赖的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;
}
示例8: render
import org.apache.velocity.context.InternalContextAdapter; //导入依赖的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;
}
示例9: render
import org.apache.velocity.context.InternalContextAdapter; //导入依赖的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;
}
示例10: render
import org.apache.velocity.context.InternalContextAdapter; //导入依赖的package包/类
public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
if(node.jjtGetNumChildren() != 2){
throw new RuntimeException(getName() + " accepts 2 parameters. The first is a boolean value indicating whether or not to add this conditon; the second is a List containing your conditions!") ;
}
Boolean test = (Boolean) node.jjtGetChild(0).value(context) ;
if(Boolean.FALSE.equals(test)){ //ignore this condition.
return true ;
}
Collection conditions = (Collection) node.jjtGetChild(1).value(context) ;
BoundaryChain chain = (BoundaryChain) context.get(GuzzBoundaryDirective.BOUNDARY_CONTEXT_NAME) ;
if(chain == null){
throw new ParseErrorException(getName() + " must be resided inside a guzzBoundary directive.") ;
}
chain.addLimitConditions(conditions) ;
return true;
}
示例11: render
import org.apache.velocity.context.InternalContextAdapter; //导入依赖的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;
}
示例12: render
import org.apache.velocity.context.InternalContextAdapter; //导入依赖的package包/类
@Override
public boolean render(InternalContextAdapter context, Writer writer,
Node node) throws IOException, ResourceNotFoundException,
ParseErrorException, MethodInvocationException {
Node bodyNode = getBodyNode(context, node);
if (AsynchronousContain.isAsyncConext()) {
StringWriter sw = new StringWriter();
bodyNode.render(context, sw);
PipelineTask task = (PipelineTask) context
.get(PipelineTask.ATTR_KEY);
task.addJsCode(sw.toString());
} else {
writer.write("<script type=\"text/javascript\">\r\n");
bodyNode.render(context, writer);
writer.write("</script>\r\n");
}
return true;
}
示例13: render
import org.apache.velocity.context.InternalContextAdapter; //导入依赖的package包/类
public boolean render(InternalContextAdapter context, Writer writer, Node node)
throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
//setting default params
String moneyValue = null;
//reading params
if (node.jjtGetChild(0) != null) {
moneyValue = node.jjtGetChild(0).value(context) == null ? null : String.valueOf(node.jjtGetChild(0).value(context));
}
//truncate and write result to writer
writer.write(moneyUAH(moneyValue));
return true;
}
示例14: render
import org.apache.velocity.context.InternalContextAdapter; //导入依赖的package包/类
public boolean render(InternalContextAdapter context, Writer writer, Node node)
throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
//setting default params
String ukrValue = null;
//reading params
if (node.jjtGetChild(0) != null) {
ukrValue = node.jjtGetChild(0).value(context) == null ? null : String.valueOf(node.jjtGetChild(0).value(context));
}
if (ukrValue == null) {
return false;
}
//truncate and write result to writer
writer.write(UkrainianToLatin.generateLat(ukrValue));
return true;
}
示例15: render
import org.apache.velocity.context.InternalContextAdapter; //导入依赖的package包/类
public boolean render(InternalContextAdapter context, Writer writer, Node node)
throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
//setting default params
String moneyValue = null;
//reading params
if (node.jjtGetChild(0) != null) {
moneyValue = String.valueOf(node.jjtGetChild(0).value(context));
}
//truncate and write result to writer
writer.write(moneyToStrUAH(moneyValue));
return true;
}