@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; }
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; }
@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; }
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; }
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; }
@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; }
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; }
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; }
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; }
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; }
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; }
@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; }
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; }
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; }
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; }
public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException { //setting default params String dateValue = null; //reading params if (node.jjtGetChild(0) != null) { dateValue = String.valueOf(node.jjtGetChild(0).value(context)); } //truncate and write result to writer writer.write(date(dateValue)); return true; }
@Override protected Params getParams(InternalContextAdapter context, Node node) throws IOException { final Params params = new Params(); params.setPrefix("WHERE"); params.setPrefixOverrides("AND |OR |AND\n|OR\n|AND\r|OR\r"); if (node.jjtGetNumChildren() == 1) { final Node child = node.jjtGetChild(0); if (child instanceof ASTBlock) { StringWriter blockContent = new StringWriter(); child.render(context, blockContent); params.setBody(blockContent.toString().trim()); return params; } } return null; }
@Override public void init(RuntimeServices rs, InternalContextAdapter context, Node node) { super.init(rs, context, node); final int n = node.jjtGetNumChildren() - 1; for (int i = 1; i < n; i++) { Node child = node.jjtGetChild(i); if (i == 1) { if (child.getType() == ParserTreeConstants.JJTREFERENCE) { this.var = ((ASTReference) child).getRootString(); } else { throw new TemplateInitException("Syntax error", getTemplateName(), getLine(), getColumn()); } } else if (child.getType() == ParserTreeConstants.JJTSTRINGLITERAL) { String value = (String) ((ASTStringLiteral) child).value(context); if (i == 2) { this.column = value; } } else { throw new TemplateInitException("Syntax error", getTemplateName(), getLine(), getColumn()); } } this.uberInfo = new Info(this.getTemplateName(), getLine(), getColumn()); }
@Override protected Params getParams(InternalContextAdapter context, Node node) throws IOException { final Params params = new Params(); params.setPrefix("SET"); params.setSuffixOverrides(","); if (node.jjtGetNumChildren() == 1) { final Node child = node.jjtGetChild(0); if (child instanceof ASTBlock) { StringWriter blockContent = new StringWriter(); child.render(context, blockContent); params.setBody(blockContent.toString().trim()); return params; } } return null; }
@Override public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException { List placeList=(List) context.get("placeList"); if(placeList==null){ return true; } Object value=node.jjtGetChild(0).value(context); placeList.add(value); writer.write("?"); return true; }
@Override public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException { String value = (String) node.jjtGetChild(0).value(context); String result = value.replaceFirst(value.substring(0, 1), value.substring(0, 1).toLowerCase()); writer.write(result); return true; }
@Override public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException { String clazz = (String) node.jjtGetChild(0).value(context); if (context.containsKey(clazz)) { String packagePath = context.get(clazz).toString(); packagePath = new StringBuilder("import ").append(packagePath).append(";\n").toString(); writer.write(packagePath); return true; } return false; }
@Override public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException { String prefix = (String) node.jjtGetChild(0).value(context); String str = (String) node.jjtGetChild(1).value(context); String suffix = (String) node.jjtGetChild(2).value(context); writer.write(String.valueOf(prefix + str + suffix)); return true; }
@Override public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException { String value = (String) node.jjtGetChild(0).value(context); String result = value.replaceFirst(value.substring(0, 1), value.substring(0, 1).toUpperCase()); writer.write(result); return true; }
/** * 重载init方法,初始自定义指令的配制参数 */ @Override public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException { super.init(rs, context, node); initBean(); }
/** * <p> * Create a Map of properties that the user has passed in. For example: * </p> * * <pre> * #xxx("name=hello" "value=world" "template=foo") * </pre> * * <p> * would yield a params that contains {["name", "hello"], ["value", "world"], ["template", "foo"]} * </p> * @param contextAdapter the context adapter * @param node the Node passed in to the render method * @return a Map of the user specified properties * @throws org.apache.velocity.exception.ParseErrorException * if the was an error in the format of the property */ protected Map createPropertyMap(InternalContextAdapter contextAdapter, Node node) throws ParseErrorException, MethodInvocationException { Map propertyMap; int children = node.jjtGetNumChildren(); if (getType() == BLOCK) { children--; } // Velocity supports an on-the-fly Map-definition syntax that leads // to more readable and faster code: // // #url({'id':'url', 'action':'MyAction'}) // // We support this syntax by checking for a single Map argument // to any directive and using that as the property map instead // of building one from individual name-value pair strings. Node firstChild = null; Object firstValue = null; if(children == 1 && null != (firstChild = node.jjtGetChild(0)) && null != (firstValue = firstChild.value(contextAdapter)) && firstValue instanceof Map) { propertyMap = (Map)firstValue; } else { propertyMap = new HashMap(); for (int index = 0, length = children; index < length; index++) { this.putProperty(propertyMap, contextAdapter, node.jjtGetChild(index)); } } return propertyMap; }
public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException { StringWriter sw = new StringWriter(); node.jjtGetChild(1).render(context, sw); // store the contents against the variable context.put("body_content", sw.toString()); return super.render(context, writer, node); }
@Override public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException { super.init(rs, context, node); log = rs.getLog(); //set compressor properties enabled = rs.getBoolean("userdirective.compressJs.enabled", true); jsCompressor = rs.getString("userdirective.compressHtml.jsCompressor", HtmlCompressor.JS_COMPRESSOR_YUI); yuiJsNoMunge = rs.getBoolean("userdirective.compressJs.yuiJsNoMunge", false); yuiJsPreserveAllSemiColons = rs.getBoolean("userdirective.compressJs.yuiJsPreserveAllSemiColons", false); yuiJsLineBreak = rs.getInt("userdirective.compressJs.yuiJsLineBreak", -1); closureOptLevel = rs.getString("userdirective.compressHtml.closureOptLevel", ClosureJavaScriptCompressor.COMPILATION_LEVEL_SIMPLE); }
@Override public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException { super.init(rs, context, node); log = rs.getLog(); //set compressor properties enabled = rs.getBoolean("userdirective.compressCss.enabled", true); yuiCssLineBreak = rs.getInt("userdirective.compressCss.yuiCssLineBreak", -1); }
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 if(enabled) { try { YuiCssCompressor compressor = new YuiCssCompressor(); compressor.setLineBreak(yuiCssLineBreak); String result = compressor.compress(content.toString()); writer.write(result); } catch (Exception e) { writer.write(content.toString()); String msg = "Failed to compress content: "+content.toString(); log.error(msg, e); throw new RuntimeException(msg, e); } } else { writer.write(content.toString()); } return true; }
@Override public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException { super.init(rs, context, node); log = rs.getLog(); //set compressor properties xmlCompressor.setEnabled(rs.getBoolean("userdirective.compressXml.enabled", true)); xmlCompressor.setRemoveComments(rs.getBoolean("userdirective.compressXml.removeComments", true)); xmlCompressor.setRemoveIntertagSpaces(rs.getBoolean("userdirective.compressXml.removeIntertagSpaces", true)); }
@Override public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException { String block = ""; Property field = null; //reading params if (node.jjtGetChild(0) != null) { field = (Property) node.jjtGetChild(0).value(context); } writeField(writer, field, block); return true; }
@Override public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException { String block = ""; Method method = null; Boolean isInterface = false; 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) { method = (Method) node.jjtGetChild(i).value(context); } else if (i == 1) { isInterface = (Boolean) 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; } } } writeMethod(writer, method, block, isInterface); return true; }
@Override public boolean render(final InternalContextAdapter context, final Writer writer, final Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException { return true; }
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 param = node.jjtGetChild(0).value(context) ; //如果为null,则什么都不输出。 if(param != null){ writer.append(URLEncoder.encode(String.valueOf(param), "UTF-8")) ; } return true; }
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 param = node.jjtGetChild(0).value(context) ; //如果为null,则什么都不输出。 if(param != null){ writer.append(TagSupportUtil.escapeXml(String.valueOf(param))) ; } return true; }
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 Map parameter!") ; } if(this.slowUpdateService == null){ throw new ResourceNotFoundException("slowUpdateService is not available.") ; } Map params = (Map) node.jjtGetChild(0).value(context) ; Object business = params.get("business") ; String updatePropName = (String) params.get("updatePropName") ; int count = TypeConvertHashMap.getIntParam(params, "count", 1) ; Serializable pkValue = (Serializable) params.get("pkValue") ; Object tableCondition = params.get("tableCondition") ; Assert.assertResouceNotNull(business, "parameter [business] in Map is requried.") ; Assert.assertResouceNotNull(updatePropName, "parameter [updatePropName] in Map is requried.") ; Assert.assertResouceNotNull(pkValue, "parameter [pkValue] in Map is requried.") ; String ghostName ; if(business instanceof java.lang.String){ ghostName = (String) business ; }else{ ghostName = business.getClass().getName() ; } if(tableCondition == null){ BoundaryChain chain = (BoundaryChain) context.get(GuzzBoundaryDirective.BOUNDARY_CONTEXT_NAME) ; if(chain != null){ tableCondition = chain.getTableCondition() ; } } this.slowUpdateService.updateCount(ghostName, tableCondition, updatePropName, pkValue, count) ; return true; }