Examples of ParserString


Examples of railo.commons.lang.ParserString

   
  }

  public static String removeLiterals(String sql) {
    if(StringUtil.isEmpty(sql)) return sql;
    return removeLiterals(new ParserString(sql),true);
  }
View Full Code Here

Examples of railo.commons.lang.ParserString

    try{
      DocComment dc = new DocComment();
      str=str.trim();
      if(str.startsWith("/**")) str=str.substring(3);
      if(str.endsWith("*/")) str=str.substring(0,str.length()-2);
      ParserString ps=new ParserString(str);
      transform(dc,ps);
      dc.getHint();// TODO do different -> make sure internal structure is valid
      return dc;
    }
    catch(Throwable t){
View Full Code Here

Examples of railo.commons.lang.ParserString

  private int columnIndex=0;

  // select <select-statement> from <tables> where <where-statement>
  public Selects parse(String sql) throws SQLParserException {
    columnIndex=0;
    ParserString raw = new ParserString(sql.trim());
    Selects selects = new Selects();
    Select select = new Select();
   
    boolean runAgain=false;
    do {
     
      // select
      if(!raw.forwardIfCurrentAndNoWordNumberAfter("select")) throw new SQLParserException("missing select");
      raw.removeSpace();
 
      // top
      if(raw.forwardIfCurrentAndNoWordNumberAfter("top")) {
        raw.removeSpace();
        ValueNumber number = number(raw);
        if(number==null)throw new SQLParserException("missing top number");
        select.setTop(number);
        raw.removeSpace();
      }
 
      // distinct
      if(raw.forwardIfCurrentAndNoWordNumberAfter("distinct")) {
        select.setDistinct(true);
        raw.removeSpace();
      }
     
      // all
      if(raw.forwardIfCurrentAndNoWordNumberAfter("all")) {
        select.setDistinct(false);
        raw.removeSpace();
      }
     
      // select expression
      selectExpressions(raw,select);
      raw.removeSpace();
     
      // from
      if(!raw.forwardIfCurrentAndNoWordNumberAfter("from")) throw new SQLParserException("missing from");
      tableList(raw,select);
      raw.removeSpace();
     
      // where
      if(raw.forwardIfCurrentAndNoWordNumberAfter("where")) whereExpressions(raw,select);
      raw.removeSpace();
     
      // group by
      if(raw.forwardIfCurrentAndNoWordNumberAfter("group by")) {
        groupByExpressions(raw,select);
        raw.removeSpace();
       
        // having
        if(raw.forwardIfCurrentAndNoWordNumberAfter("having")) havingExpressions(raw,select);
        raw.removeSpace();
      }
      selects.addSelect(select);
     
      runAgain=false;
      // union
      if(raw.forwardIfCurrentAndNoWordNumberAfter("union")) {
        select = new Select();
        raw.removeSpace();
        if(raw.forwardIfCurrentAndNoWordNumberAfter("all")){
          raw.removeSpace();
          select.setUnionDistinct(false);
        }
        else if(raw.forwardIfCurrentAndNoWordNumberAfter("distinct")){
          raw.removeSpace();
          select.setUnionDistinct(true);
        }
        else select.setDistinct(true);
        raw.removeSpace();
        runAgain=true;
      }
 
    }
    while(runAgain);
   
             
    // order by
    if(raw.forwardIfCurrentAndNoWordNumberAfter("order by")) orderByExpressions(raw,selects);
    raw.removeSpace();
   
    if(raw.forwardIfCurrent(';'))raw.removeSpace();
   
    if(!raw.isAfterLast()) throw new SQLParserException("can not read the full sql statement (stop at:"+raw.getCurrent()+")");
    return selects;
  }
View Full Code Here

Examples of railo.commons.lang.ParserString

    return prettyfie(sql,false);
  }
 
  public static String prettyfie(String sql, boolean validZql){
 
    ParserString ps=new ParserString(sql.trim());
    boolean insideString=false;
    //short insideKlammer=0;
    StringBuffer sb=new StringBuffer(sql.length());
    //char last=0;
   
    outer:while(!ps.isAfterLast()) {
      if(insideString) {
            if(ps.isCurrent('\'')) {
                if(!ps.hasNext() || !ps.isNext('\''))insideString=false;
            }
        }
      else {
        if(ps.isCurrent('\''))insideString=true;
            else if(ps.isCurrent('?')) {
                sb.append(" "+PLACEHOLDER_QUESTION+" ");
                ps.next();
                continue;
            }
            else if(ps.isCurrent('{')) {
              StringBuffer date=new StringBuffer();
              int pos=ps.getPos();
              while(true) {
                if(ps.isAfterLast()){
                  ps.setPos(pos);
                  break;
                }
                else if(ps.isCurrent('}')) {
                  date.append('}');
                  DateTime d;
              try {
                d = DateCaster.toDateAdvanced(date.toString(), null);
              }
              catch (PageException e) {
                ps.setPos(pos);
                    break;
              }
              sb.append('\'');
                  sb.append(new DateFormat(Locale.US).format(d,"yyyy-mm-dd"));
                  sb.append(' ');
                  sb.append(new TimeFormat(Locale.US).format(d,"HH:mm:ss"));
                  sb.append('\'');
                  ps.next();
                  continue outer;
                }
                else {
                  date.append(ps.getCurrent());
                  ps.next();
                }
              }
            }
            else if(ps.isCurrent('*')) {
              sb.append(" "+PLACEHOLDER_ASTERIX+" ");
              ps.next();
                //last=ps.getCurrent();
            continue;
            }
            else if(validZql && ps.isCurrent('a')) {
                if(ps.isPreviousWhiteSpace() && ps.isNext('s') && ps.isNextNextWhiteSpace())  {
                    ps.next();
                    ps.next();
                    ps.removeSpace();
                   
                    continue;
                  }
             
            }
            /*for(int i=0;i<reseved_words.length;i++) {
              if(ps.isCurrent(reseved_words[i])) {
                int pos=ps.getPos();
                ps.setPos(pos+4);
                if(ps.isCurrentWhiteSpace()) {
                  sb.append(" placeholder_"+reseved_words[i]+" ");
                  continue;
                }
                if(ps.isCurrent(',')) {
                  sb.append(" placeholder_"+reseved_words[i]+",");
                  continue;
                }
                ps.setPos(pos);
              }
            }*/
        /*if(ps.isCurrent("char")) {
              int pos=ps.getPos();
              ps.setPos(pos+4);
              if(ps.isCurrentWhiteSpace()) {
                sb.append(" "+PLACEHOLDER_CHAR+" ");
                continue;
              }
              if(ps.isCurrent(',')) {
                sb.append(" "+PLACEHOLDER_CHAR+",");
                continue;
              }
              ps.setPos(pos);
            }*/
      }
        sb.append(ps.getCurrent());
      ps.next();
    }
   
    if(!ps.isLast(';'))sb.append(';');
   
    //print.err(sb.toString());
    //print.err("---------------------------------------------------------------------------------");
    return sb.toString();
  }
View Full Code Here

Examples of railo.commons.lang.ParserString

public class ClientScopeConverter {

  public static Struct unserialize(String str) {
    Struct sct=new StructImpl();
    ParserString ps=new ParserString(str);
   
    StringBuffer sb=new StringBuffer();
    String key=null;
    while(!ps.isAfterLast()) {
      if(ps.isCurrent('#')) {
        if(ps.isNext('=')){
          ps.next();
          sb.append('=');
        }
        else if(ps.isNext('#')){
          ps.next();
          sb.append('#');
        }
        else {
          sct.setEL(key, sb.toString());
          sb=new StringBuffer();
        }
      }
      else if(ps.isCurrent('=')) {
        key=sb.toString();
        sb=new StringBuffer();
      }
      else sb.append(ps.getCurrent());
      ps.next();
    }
   
   
    if(!StringUtil.isEmpty(key) && !StringUtil.isEmpty(sb)) {
      sct.setEL(key, sb.toString());
View Full Code Here

Examples of railo.commons.lang.ParserString

    public Object interpret(PageContext pc,String str, boolean preciseMath) throws PageException {

      //Ref ref = data.get(str+":"+preciseMath);
      //if(ref!=null)return ref.getValue();
     
      this.cfml=new ParserString(str);
      this.preciseMath = preciseMath;
      this.pc=ThreadLocalPageContext.get(pc);
        if(pc!=null)fld=((ConfigImpl)pc.getConfig()).getCombinedFLDs();
       
        if(JSON_ARRAY==null)JSON_ARRAY=fld.getFunction("_jsonArray");
View Full Code Here

Examples of railo.commons.lang.ParserString

   * @param var
   * @return matching Object
   * @throws PageException
   */
  public static Object getVariable(PageContext pc, Collection collection,String var) throws PageException {     
      StringList list = parse(pc,new ParserString(var),false);
        if(list==null) throw new InterpreterException("invalid variable declaration ["+var+"]");
       
        while(list.hasNextNext()) {
            collection=Caster.toCollection(collection.get(KeyImpl.init(list.next())));
        }
View Full Code Here

Examples of railo.commons.lang.ParserString

    return null;
  }
 

  public static Object getVariableEL(PageContext pc, Collection collection,String var) {     
      StringList list = parse(pc,new ParserString(var),false);
        if(list==null) return null;
      
        while(list.hasNextNext()) {
          collection=Caster.toCollection(collection.get(list.next(),null),null);
          if(collection==null) return null;
View Full Code Here

Examples of railo.commons.lang.ParserString

   * @param var variable string to get value to
   * @return the value
     * @throws PageException
   */
  public static Object getVariable(PageContext pc,String var) throws PageException {
        StringList list = parse(pc,new ParserString(var),false);
        if(list==null) throw new InterpreterException("invalid variable declaration ["+var+"]");
       
    int scope=scopeString2Int(list.next());
    Object coll =null;
    if(scope==Scope.SCOPE_UNDEFINED) {
View Full Code Here

Examples of railo.commons.lang.ParserString

    }
 


  public static Object getVariableAsCollection(PageContext pc,String var) throws PageException {
        StringList list = parse(pc,new ParserString(var),false);
        if(list==null) throw new InterpreterException("invalid variable declaration ["+var+"]");
       
    int scope=scopeString2Int(list.next());
    Object coll =null;
    if(scope==Scope.SCOPE_UNDEFINED) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.