bboss.org.apache.velocity.VelocityContext

Here are the examples of the java api class bboss.org.apache.velocity.VelocityContext taken from open source projects.

1. VelocityServlet#createContext()

Project: bboss
File: VelocityServlet.java
/**
     *  Returns a context suitable to pass to the handleRequest() method
     *  <br><br>
     *  Default implementation will create a VelocityContext object,
     *   put the HttpServletRequest and HttpServletResponse
     *  into the context accessable via the keys VelocityServlet.REQUEST and
     *  VelocityServlet.RESPONSE, respectively.
     *
     *  @param request servlet request from client
     *  @param response servlet reponse to client
     *
     *  @return context
     */
protected Context createContext(HttpServletRequest request, HttpServletResponse response) {
    /*
         *   create a new context
         */
    VelocityContext context = new VelocityContext();
    /*
         *   put the request/response objects into the context
         *   wrap the HttpServletRequest to solve the introspection
         *   problems
         */
    context.put(REQUEST, request);
    context.put(RESPONSE, response);
    return context;
}

2. VelocityUtil#buildVelocityContext()

Project: bboss
File: VelocityUtil.java
public static VelocityContext buildVelocityContext(Map<String, Object> context) {
    VelocityContext context_ = new VelocityContext();
    if (context != null && context.size() > 0) {
        Iterator<String> it = context.keySet().iterator();
        while (it.hasNext()) {
            String key = it.next();
            context_.put(key, context.get(key));
        }
    }
    return context_;
}

3. SQLParams#buildVelocityContext()

Project: bboss
File: SQLParams.java
public VelocityContext buildVelocityContext() {
    VelocityContext context_ = new VelocityContext();
    Param temp = null;
    if (sqlparams != null && sqlparams.size() > 0) {
        Iterator<Entry<String, Param>> it = sqlparams.entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, Param> entry = it.next();
            temp = entry.getValue();
            if (!temp.getType().equals(NULL))
                context_.put(entry.getKey(), temp.getData());
        }
    }
    return context_;
}

4. NodeHelper#getSelectedScript()

Project: bboss
File: NodeHelper.java
public static void getSelectedScript(StringBuilder buffer, ITree tree, String treeid) {
    Template tpl = VelocityUtil.getTemplate("tree.vm");
    VelocityContext context = new VelocityContext();
    context.put("isStaticDynamic", new Boolean(tree.isStaticDynamic()));
    context.put("isStatic", new Boolean(tree.isStatic()));
    context.put("tree", treeid);
    context.put("rootid", tree.getRoot().getId());
    try {
        StringWriter out = new StringWriter();
        tpl.merge(context, out);
        out.flush();
        String temp = out.toString();
        buffer.append(temp);
        out.close();
    } catch (ResourceNotFoundException e) {
        e.printStackTrace();
    } catch (ParseErrorException e) {
        e.printStackTrace();
    } catch (MethodInvocationException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

5. QueryTag#doStartTag()

Project: bboss
File: QueryTag.java
public int doStartTag() throws JspException {
    Template template = VelocityUtil.getTemplate(templatepath);
    VelocityContext context = new VelocityContext();
    context.put("contextpath", request.getContextPath());
    context.put("rootid", rootid);
    try {
        template.merge(context, this.getJspWriter());
    } catch (ResourceNotFoundException e) {
        e.printStackTrace();
    } catch (ParseErrorException e) {
        e.printStackTrace();
    } catch (MethodInvocationException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return super.doStartTag();
}

6. VelocityUtil#main()

Project: bboss
File: VelocityUtil.java
public static void main(String[] args) {
    VelocityUtil velocityutil = new VelocityUtil();
    VelocityContext fcontext = new VelocityContext();
}

7. SQLUtil#_getSQL()

Project: bboss
File: SQLUtil.java
public static String _getSQL(SQLInfo sqlinfo, Map variablevalues) {
    //		String newsql = null;
    //		if(sqlinfo.istpl() )
    //		{
    //			StringWriter sw = new StringWriter();
    //			sqlinfo.getSqltpl().merge(BBossVelocityUtil.buildVelocityContext(variablevalues),sw);
    //			newsql = sw.toString();
    //		}
    //		else
    //			newsql = sqlinfo.getSql();
    //		return newsql;
    String sql = null;
    VelocityContext vcontext = null;
    if (sqlinfo.istpl()) {
        //??sql????????velocity sql??
        sqlinfo.getSqltpl().process();
        if (sqlinfo.istpl()) {
            //??context???????????????
            vcontext = BBossVelocityUtil.buildVelocityContext(variablevalues);
            StringWriter sw = new StringWriter();
            sqlinfo.getSqltpl().merge(vcontext, sw);
            sql = sw.toString();
        } else {
            sql = sqlinfo.getSql();
        }
    } else {
        sql = sqlinfo.getSql();
    }
    return sql;
}

8. SQLParams#buildParamsByVariableParser()

Project: bboss
File: SQLParams.java
private void buildParamsByVariableParser(SQLInfo sqlinfo, SQLInfo totalsizesqlinfo, String dbname, NewSQLInfo firstnewsql) throws SetSQLParamException {
    String sql = null;
    String totalsizesql = null;
    List<Param> _realParams = new ArrayList<Param>();
    SQLStruction sqlstruction = null;
    VelocityContext vcontext = null;
    if (firstnewsql == null) {
        if (sqlinfo.istpl()) {
            //??sql????????velocity sql??
            sqlinfo.getSqltpl().process();
            if (sqlinfo.istpl()) {
                //??context???????????????
                vcontext = buildVelocityContext();
                StringWriter sw = new StringWriter();
                sqlinfo.getSqltpl().merge(vcontext, sw);
                sql = sw.toString();
            } else {
                sql = sqlinfo.getSql();
            }
        } else {
            sql = sqlinfo.getSql();
        }
        if (sqlinfo.getSqlutil() == null) {
            sqlstruction = SQLUtil.getGlobalSQLUtil().getSQLStruction(sqlinfo, sql);
        } else {
            sqlstruction = sqlinfo.getSqlutil().getSQLStruction(sqlinfo, sql);
        }
        newsql = new NewSQLInfo(sqlstruction.getSql());
        newsql.setOldsql(sqlinfo);
        newsql.setSqlstruction(sqlstruction);
        if (totalsizesqlinfo != null) {
            if (totalsizesqlinfo.istpl()) {
                totalsizesqlinfo.getSqltpl().process();
                if (totalsizesqlinfo.istpl()) {
                    if (vcontext == null)
                        vcontext = buildVelocityContext();
                    StringWriter sw = new StringWriter();
                    totalsizesqlinfo.getSqltpl().merge(vcontext, sw);
                    totalsizesql = sw.toString();
                } else
                    totalsizesql = totalsizesqlinfo.getSql();
            } else {
                totalsizesql = totalsizesqlinfo.getSql();
            }
            SQLStruction totalsizesqlstruction = null;
            if (//??sql????????????????????????sql????????
            totalsizesqlinfo.getSqlutil() == null) {
                totalsizesqlstruction = SQLUtil.getGlobalSQLUtil().getTotalsizeSQLStruction(totalsizesqlinfo, totalsizesql);
            } else {
                totalsizesqlstruction = totalsizesqlinfo.getSqlutil().getTotalsizeSQLStruction(totalsizesqlinfo, totalsizesql);
            }
            newsql.setOldtotalsizesql(totalsizesqlinfo);
            String newtotalsizesql = totalsizesqlstruction.getSql();
            newsql.setNewtotalsizesql(newtotalsizesql);
        }
    } else //??????????sql??????????????sql?????
    {
        this.newsql = firstnewsql;
        sqlstruction = this.newsql.getSqlstruction();
    }
    //        String vars[] = args[1];  
    if (!sqlstruction.hasVars()) {
    //log.debug("???sql?????????????,sql??????????????????" + this.toString());
    //            throw new SetSQLParamException("???sql?????????????,sql??????????????????" + this);
    } else {
        Param temp = null;
        List<Variable> vars = sqlstruction.getVariables();
        for (int i = 0; i < vars.size(); i++) {
            Variable var = vars.get(i);
            temp = this.sqlparams.get(var.getVariableName());
            if (temp == null)
                throw new SetSQLParamException("??????????" + var.getVariableName() + "\r\n" + this.toString());
            Param newparam = temp.clone(var);
            //???????1??
            newparam.index = i + 1;
            _realParams.add(newparam);
        }
    }
    this.realParams = new Params(_realParams);
    //???????????????rownum_over??orderby??
    if (pagineOrderby != null) {
        String _pagineOrderby = null;
        if (!pagineOrderby.isPlain()) {
            SQLInfo conditionsqlinfo = null;
            if (pagineOrderby.isConfig()) {
                conditionsqlinfo = sqlinfo.getSQLInfo(dbname, pagineOrderby.getPagineOrderby());
            } else {
                conditionsqlinfo = SQLUtil.getGlobalSQLUtil().getSQLInfo(pagineOrderby.getPagineOrderby(), true, true);
            }
            if (conditionsqlinfo == null)
                throw new SetSQLParamException(pagineOrderby.toString(":???????ROW_NUMBER () OVER() order by ?????"));
            if (conditionsqlinfo.istpl()) {
                //??sql????????velocity sql??
                conditionsqlinfo.getSqltpl().process();
                if (conditionsqlinfo.istpl()) {
                    if (vcontext == null)
                        vcontext = buildVelocityContext();
                    StringWriter sw = new StringWriter();
                    conditionsqlinfo.getSqltpl().merge(vcontext, sw);
                    _pagineOrderby = sw.toString();
                } else {
                    _pagineOrderby = conditionsqlinfo.getSql();
                }
            } else {
                _pagineOrderby = conditionsqlinfo.getSql();
            }
        } else {
            if (pagineOrderby.isConfig())
                _pagineOrderby = sqlinfo.getPlainSQL(dbname, pagineOrderby.getPagineOrderby());
            else
                _pagineOrderby = pagineOrderby.getPagineOrderby();
        }
        this.realParams.setPagineOrderby(_pagineOrderby.trim());
    }
    if (sqlstruction.hasVars()) {
        JDBCPool pool = SQLManager.getInstance().getPool(dbname);
        if (pool != null && pool.showsql()) {
            log.debug("SQL INFO:" + this.toString());
        }
    }
}

9. SQLParams#buildParamsByRegex()

Project: bboss
File: SQLParams.java
//    private void buildParamsByRegex(String sql,String totalsizesql,String dbname) throws SetSQLParamException
//    {
//    	List<Param> _realParams = new ArrayList<Param>();   
//    	VelocityContext vcontext = buildVelocityContext();
//        sql = this.evaluateSqlTemplate(vcontext,sql);
//        String[][] args =  parserResults.get(sql);
//        if(args == null)
//        {
//            synchronized(lock)
//            {
//            	args =  parserResults.get(sql);
//                if(args == null)
//                {
//                    args = VariableHandler.parser2ndSubstitution(sql, this.pretoken,this.endtoken, "?");
//                    parserResults.put(sql,args);
//                }
//            }
//        }            
//        newsql = args[0][0];
//        if(totalsizesql != null)
//        {
//        	totalsizesql = this.evaluateSqlTemplate(vcontext,totalsizesql);
//	        String[][] totalsizesqlargs =  parserResults.get(totalsizesql);
//	        if(totalsizesqlargs == null)
//	        {
//	            synchronized(lock)
//	            {
//	            	totalsizesqlargs =  parserResults.get(totalsizesql);
//	                if(totalsizesqlargs == null)
//	                {
//	                	totalsizesqlargs = VariableHandler.parser2ndSubstitution(totalsizesql, this.pretoken,this.endtoken, "?");
//	                    parserResults.put(totalsizesql,totalsizesqlargs);
//	                }
//	            }
//	        }            
//	        newtotalsizesql = totalsizesqlargs[0][0];
//        }
//        String vars[] = args[1];  
//        if(vars.length == 0 )
//        {
//        	log.debug("???sql?????????????,sql??????????????????" + this);
////            throw new SetSQLParamException("???sql?????????????,sql??????????????????" + this);
//        }
//        Param temp = null;
//        for(int i = 0;i < vars.length; i ++)
//        {
//            temp = this.sqlparams.get(vars[i]);
//            if(temp == null)
//                throw new SetSQLParamException("??????????" 
//                                                + vars[i] 
//                                                + "\r\n" 
//                                                + this);
//            Param newparam = temp.clone();
//            //???????1??
//            newparam.index = i + 1;
//            _realParams.add(newparam);
//        }
//        
//        this.realParams = new Params(_realParams);
//    }
private void buildParamsByRegex(SQLInfo sqlinfo, SQLInfo totalsizesqlinfo, String dbname) throws SetSQLParamException {
    String sql = null;
    String totalsizesql = null;
    List<Param> _realParams = new ArrayList<Param>();
    VelocityContext vcontext = null;
    if (sqlinfo.istpl()) {
        sqlinfo.getSqltpl().process();
        if (sqlinfo.istpl()) {
            vcontext = buildVelocityContext();
            StringWriter sw = new StringWriter();
            sqlinfo.getSqltpl().merge(vcontext, sw);
            sql = sw.toString();
        } else {
            sql = sqlinfo.getSql();
        }
    } else {
        sql = sqlinfo.getSql();
    }
    //        sql = this.evaluateSqlTemplate(vcontext,sql);
    String[][] args = parserResults.get(sql);
    if (args == null) {
        synchronized (lock) {
            args = parserResults.get(sql);
            if (args == null) {
                args = VariableHandler.parser2ndSubstitution(sql, this.pretoken, this.endtoken, "?");
                parserResults.put(sql, args);
            }
        }
    }
    newsql = new NewSQLInfo(args[0][0]);
    newsql.setOldsql(sqlinfo);
    if (totalsizesqlinfo != null) {
        if (totalsizesqlinfo.istpl()) {
            totalsizesqlinfo.getSqltpl().process();
            if (totalsizesqlinfo.istpl()) {
                if (vcontext == null)
                    vcontext = buildVelocityContext();
                StringWriter sw = new StringWriter();
                totalsizesqlinfo.getSqltpl().merge(vcontext, sw);
                totalsizesql = sw.toString();
            } else {
                totalsizesql = totalsizesqlinfo.getSql();
            }
        } else {
            totalsizesql = totalsizesqlinfo.getSql();
        }
        //        	totalsizesql = this.evaluateSqlTemplate(vcontext,totalsizesql);
        String[][] totalsizesqlargs = parserResults.get(totalsizesql);
        if (totalsizesqlargs == null) {
            synchronized (lock) {
                totalsizesqlargs = parserResults.get(totalsizesql);
                if (totalsizesqlargs == null) {
                    totalsizesqlargs = VariableHandler.parser2ndSubstitution(totalsizesql, this.pretoken, this.endtoken, "?");
                    parserResults.put(totalsizesql, totalsizesqlargs);
                }
            }
        }
        newsql.setNewtotalsizesql(totalsizesqlargs[0][0]);
        newsql.setOldtotalsizesql(totalsizesqlinfo);
    }
    String vars[] = args[1];
    if (vars.length == 0) {
        log.debug("???sql?????????????,sql??????????????????" + this);
    //            throw new SetSQLParamException("???sql?????????????,sql??????????????????" + this);
    }
    Param temp = null;
    for (int i = 0; i < vars.length; i++) {
        temp = this.sqlparams.get(vars[i]);
        if (temp == null)
            throw new SetSQLParamException("??????????" + vars[i] + "\r\n" + this);
        Param newparam = temp.clone();
        //???????1??
        newparam.index = i + 1;
        _realParams.add(newparam);
    }
    this.realParams = new Params(_realParams);
//        if(this.oldsql.fromConfig() && pagineOrderby.isConfig())
//        {
//        	
//        }
//        this.realParams.setPagineOrderby(pagineOrderby);
}