Examples of Regex


Examples of pt.opensoft.text.Regex

    if (columnNames == null) columnNames = selectFields;

    try {

      List columns = new Regex(",").split(columnNames);
      List selectColumns = new Regex(",").split(selectFields);

      int i = 0;
      for (Iterator it = columns.iterator(); it.hasNext(); i++) {
        String column = (String) it.next();
        String selectColumn = (String) selectColumns.get(i);

                Regex regex1 = new Regex("(\\S+)");

        if (!regex1.contains(column)) {
          throw new Exception("incorrect syntax::missing column name::"+columnNames);
                }

        String columnName = regex1.getGroup(1);

                Regex regex2 = new Regex("\\S+\\.(\\S+))");
        if (regex2.contains(columnName)){
          columnName = regex2.getGroup(1);
                }

        Hashtable field = new Hashtable();

        String fieldId = getFieldId(columnName);

        field.put("name", columnName);
        field.put("id", fieldId);

        if (fieldId.length() > max) max = fieldId.length();

        String tableName = null;
        String tableFieldName = null;

                Regex regex3 = new Regex("(\\S+)\\.(\\S+)");
        if (regex3.contains(selectColumn)) {
          tableName = regex3.getGroup(1);
          tableFieldName = regex3.getGroup(2);
        }

        if (debug >= 2) System.out.println("    Adding field: "+columnName+" "+tableName+" "+tableFieldName);

        if (tableName != null) {
View Full Code Here

Examples of pt.opensoft.text.Regex

  //-----------------------------------------------------------------------------------------

  public static void alterTable (Hashtable tables, String ddl) {
    try {

            Regex tableNameRegex = new Regex("ALTER\\s+TABLE\\s+(\\w+)", Regex.CASE_INSENSITIVE_MASK);

            if (!tableNameRegex.contains(ddl)) {
        throw new Exception("missing table name::"+ddl);
            }

            String tableName = tableNameRegex.getGroup(1);

      Hashtable table = (Hashtable) tables.get(tableName);

      Hashtable fields = (Hashtable) table.get("fields");

      String expr = "ADD\\s.*PRIMARY\\s+KEY\\s*\\((.*)\\)";

      if (server.equalsIgnoreCase("ORACLE")) {
        if( new Regex("ADD\\s*CONSTRAINT", Regex.CASE_INSENSITIVE_MASK).contains(ddl) )  // added support for named primary keys constraints
          expr = "ADD\\s+CONSTRAINT\\s.*PRIMARY\\s+KEY\\s*\\((.*)\\)";
        else
          expr = "ADD\\s*\\(\\s*PRIMARY\\s+KEY\\s*\\((.*)\\)\\s*\\)";
      }else if(server.equalsIgnoreCase("SQLSERVER")) {
        expr = "ADD\\s.*PRIMARY\\s+KEY\\s+CLUSTERED\\s*\\((.*)\\)";
      }

            Regex regex1 = new Regex(expr, Regex.CASE_INSENSITIVE_MASK);

      if (regex1.contains(ddl)) {

                if (debug >= 1) System.out.println(lineSeparator+"  Altering table '"+tableName+"'");

        String keyFieldsDDL = regex1.getGroup(1);

                Regex regex2 = new Regex(",");

        List keyFields = regex2.split(keyFieldsDDL);

        for (Iterator it = keyFields.iterator(); it.hasNext(); ) {
          String fieldName = ((String) it.next()).trim();

          Hashtable field = (Hashtable) fields.get(fieldName);
View Full Code Here

Examples of pt.opensoft.text.Regex

      if (debug >= 1) System.out.println("  Inserting package name in template...");

      if (packageName == null)  {

        tableTemplate = new Regex("\\<packageDeclaration.*;\\s*\\>").substitute(tableTemplate, "");

            } else {

        tableTemplate = new Regex("\\<packageDeclaration\\s*(.*;\\s*)\\>").substitute(tableTemplate,"$1");

        tableTemplate = new Regex("\\<packageName\\>").substitute(tableTemplate, packageName, Regex.SUBSTITUTE_ALL);

      }

      //le a declaracao de um field do template

      if (debug >= 1) System.out.println("  Reading field declaration from template...");

            Regex regex = new Regex("\\<fieldDeclaration(.*;)\\>");

      if (!regex.contains(tableTemplate)) {
        throw new Exception("invalid syntax in template::field declaration");
            }

      String fieldDeclaration = regex.getGroup(1);

      //substitui a declaracao completa, pela tag de declaracao

      if (debug >= 1) System.out.println("  Replacing field declaration in template...");

      tableTemplate = new Regex("(\\<fieldDeclaration).*;(\\>)").substitute(tableTemplate,"$1$2");

      //le a declaracao do metodo de adicionar um field a Table

      if (debug >= 1) System.out.println("  Reading addField declaration from template...");

            Regex regex2 = new Regex("\\<addFieldDeclaration(.*;)\\>");
      if (!regex2.contains(tableTemplate)) {
        throw new Exception("invalid syntax in template::add field declaration");
            }

            String addFieldDeclaration = regex2.getGroup(1);

      //substitui a declaracao completa, pela tag de declaracao

      if (debug >= 1) System.out.println("  Replacing addField declaration in template...");

      tableTemplate = new Regex("(\\<addFieldDeclaration).*;(\\>)").substitute(tableTemplate, "$1$2");

      if (debug >= 1) System.out.println("  Making templates for each table...");

      for (Enumeration en = tables.keys(); en.hasMoreElements(); ) {
        //comeca a gerar uma nova tabela

        String newTable = tableTemplate;

        String tableName = (String) en.nextElement();
        newTable = new Regex("\\<tableName\\>", Regex.DEFAULT_MASK).substitute(newTable, tableName, Regex.SUBSTITUTE_ALL);

        Hashtable table = (Hashtable) tables.get(tableName);

        String className = tableName + "Table";
        String fullClassName = (String) table.get("fullClassName");

        newTable = new Regex("\\<className\\>", Regex.DEFAULT_MASK).substitute(newTable, className, Regex.SUBSTITUTE_ALL);

        newTable = new Regex("\\<fullClassName\\>", Regex.DEFAULT_MASK).substitute(newTable, fullClassName, Regex.SUBSTITUTE_ALL);
       
        newTable = new Regex("\\<serialVersionUID\\>", Regex.DEFAULT_MASK).substitute(newTable, String.valueOf(RandomUtil.randomLong()), Regex.SUBSTITUTE_ALL);

        String tableType = (String) table.get("type");
        newTable = new Regex("\\<tableType\\>", Regex.DEFAULT_MASK).substitute(newTable, tableType, Regex.SUBSTITUTE_ALL);

        int max = Integer.parseInt((String) table.get("max"));
        Hashtable fields = (Hashtable) table.get("fields");
        Vector orderedFields = (Vector) table.get("orderedFields");

        StringBuffer fieldDeclarations = new StringBuffer();
        StringBuffer addKeyDeclarations = new StringBuffer();
        StringBuffer addFieldDeclarations = new StringBuffer();

        for (Enumeration enum1 = orderedFields.elements(); enum1.hasMoreElements(); ) {
          String fieldName = (String) enum1.nextElement();
          Hashtable field = (Hashtable) fields.get(fieldName);

          String fieldId = (String) field.get("id");

          fieldId = StringUtil.appendChars(fieldId, ' ', max);

          String newFieldDeclaration = new Regex("<fieldId>").substitute(fieldDeclaration, fieldId);
          newFieldDeclaration = new Regex("<fieldName>").substitute(newFieldDeclaration, fieldName);

          String newAddFieldDeclaration = new Regex("<fieldId>").substitute(addFieldDeclaration, fieldId);

          String fieldType = (String) field.get("type");
          newAddFieldDeclaration = new Regex("<fieldType>").substitute(newAddFieldDeclaration, fieldType);

          if (sizes) {
            String fieldSize = (String) field.get("size");
            if (fieldSize == null) fieldSize = "";
            newAddFieldDeclaration = new Regex("<fieldSize>").substitute(newAddFieldDeclaration, fieldSize);
          } else {
            newAddFieldDeclaration = new Regex(",\\s+<fieldSize>").substitute(newAddFieldDeclaration, "");
          }

          String fieldKey = (String) field.get("key");

          if (fieldDeclarations.length() != 0) fieldDeclarations.append(lineSeparator);
          fieldDeclarations.append(newFieldDeclaration);

          if (fieldKey != null && fieldKey.equals("true")) {
            newAddFieldDeclaration = new Regex("<fieldKey>").substitute(newAddFieldDeclaration, "Key  ");
            if (addKeyDeclarations.length() != 0) addKeyDeclarations.append(lineSeparator);
            addKeyDeclarations.append(newAddFieldDeclaration);
          } else {
            newAddFieldDeclaration = new Regex("<fieldKey>").substitute(newAddFieldDeclaration, "Field");
            if (addFieldDeclarations.length() != 0) addFieldDeclarations.append(lineSeparator);
            addFieldDeclarations.append(newAddFieldDeclaration);
          }
        }

        if (addKeyDeclarations.length() != 0) addKeyDeclarations.append(lineSeparator+lineSeparator);

        newTable = new Regex("<fieldDeclaration>").substitute(newTable, fieldDeclarations.toString());
        newTable = new Regex("<addFieldDeclaration>").substitute(newTable, addKeyDeclarations.toString()+addFieldDeclarations.toString());

        writeFile(destinationDir+fileSeparator+tableName+"Table.java", newTable);
      }
    } catch (Exception e) {
      System.err.println("ERROR: "+e);
View Full Code Here

Examples of pt.opensoft.text.Regex

      //caso o packageName seja null retira a declaracao do package no template

      if (debug >= 1) System.out.println("  Inserting package name in template...");

      if (packageName == null) {
        tableTemplate = new Regex("\\<packageDeclaration.*;\\s*\\>").substitute(tableTemplate, "");
            } else {
        tableTemplate = new Regex("\\<packageDeclaration\\s*(.*;\\s*)\\>").substitute(tableTemplate, "$1");
        tableTemplate = new Regex("\\<packageName\\>", Regex.DEFAULT_MASK).substitute(tableTemplate, packageName, Regex.SUBSTITUTE_ALL);
      }

      //le a declaracao de um field do template

      if (debug >= 1) System.out.println("  Reading field declaration from template...");

            Regex regex1 = new Regex("\\<fieldDeclaration(.*;)\\>");
      if (!regex1.contains(tableTemplate)) {
        throw new Exception("invalid syntax in template::field declaration");
            }

      String fieldDeclaration = regex1.getGroup(1);

      //substitui a declaracao completa, pela tag de declaracao

      if (debug >= 1) System.out.println("  Replacing field declaration in template...");

      tableTemplate = new Regex("(\\<fieldDeclaration).*;(\\>)").substitute(tableTemplate, "$1$2");

      //le a declaracao de um table field do template

      if (debug >= 1) System.out.println("  Reading tableField declaration from template...");

            Regex regex2 = new Regex("\\<tableFieldDeclaration(.*;)\\>");

            if (!regex2.contains(tableTemplate))
        throw new Exception("invalid syntax in template::table field declaration");

      String tableFieldDeclaration = regex2.getGroup(1);

      //substitui a declaracao completa, pela tag de declaracao

      if (debug >= 1) System.out.println("  Replacing tableField declaration in template...");

      tableTemplate = new Regex("(\\<tableFieldDeclaration).*;(\\>)").substitute(tableTemplate, "$1$2");

      //le a declaracao do metodo de adicionar uma tabela

      if (debug >= 1) System.out.println("  Reading addTable declaration from template...");

            Regex regex3 = new Regex("\\<addTableDeclaration(.*;)\\>");

      if (!regex3.contains(tableTemplate)) {
        throw new Exception("invalid syntax in template::add table declaration");
            }

      String addTableDeclaration = regex3.getGroup(1);

      //substitui a declaracao completa, pela tag de declaracao

      if (debug >= 1) System.out.println("  Replacing table declaration from template...");

      tableTemplate = new Regex("(\\<addTableDeclaration).*;(\\>)").substitute(tableTemplate, "$1$2");

      //le a declaracao do metodo de adicionar um field a Table

      if (debug >= 1) System.out.println("  Reading addField declaration from template...");

            Regex regex4 = new Regex("\\<addFieldDeclaration(.*;)\\>");
      if (!regex4.contains(tableTemplate)) {
        throw new Exception("invalid syntax in template::add field declaration");
            }

      String addFieldDeclaration = regex4.getGroup(1);

      //substitui a declaracao completa, pela tag de declaracao

      if (debug >= 1) System.out.println("  Replacing addField declaration from template...");

      tableTemplate = new Regex("(\\<addFieldDeclaration).*;(\\>)").substitute(tableTemplate, "$1$2");

      if (debug >= 1) System.out.println("  Making templates for each view...");

      for (Enumeration en = views.keys(); en.hasMoreElements(); ) {
        //comeca a gerar uma nova view

        String newTable = tableTemplate;

        String viewName = (String) en.nextElement();

        if (debug >= 2) System.out.println("    Replacing view name tag by: '"+viewName+"'...");

        newTable = new Regex("\\<viewName\\>", Regex.DEFAULT_MASK).substitute(newTable, viewName, Regex.SUBSTITUTE_ALL);

        if (debug >= 2) System.out.println("    Getting view '"+viewName+"'...");

        Hashtable view = (Hashtable) views.get(viewName);

        if (debug >= 2) System.out.println("    Getting view table name...");

        String tableName = (String) view.get("tableName");

        if (debug >= 2) System.out.println("    Getting table '"+tableName+"'...");

        Hashtable table = (Hashtable) tables.get(tableName);

        if (debug >= 2) System.out.println("    Getting table class name...");

        String tableClassName = (String) table.get("className");

        if (debug >= 2) System.out.println("    Getting view class name...");

        String viewClassName = (String) view.get("className");

        if (debug >= 2) System.out.println("    Getting view full class name...");

        String fullViewClassName = (String) view.get("fullClassName");

        if (debug >= 2) System.out.println("    Replacing viewClassName tag '"+viewClassName+"'...");

        newTable = new Regex("<viewClassName>", Regex.DEFAULT_MASK).substitute(newTable, viewClassName, Regex.SUBSTITUTE_ALL);

        if (debug >= 2) System.out.println("    Replacing fullViewClassName tag '"+fullViewClassName+"'...");

        newTable = new Regex("<fullViewClassName>", Regex.DEFAULT_MASK).substitute(newTable, fullViewClassName, Regex.SUBSTITUTE_ALL);

        if (debug >= 2) System.out.println("    Replacing className tag '"+tableClassName+"'...");

        newTable = new Regex("<className>", Regex.DEFAULT_MASK).substitute(newTable, tableClassName, Regex.SUBSTITUTE_ALL);

        String viewType = (String) view.get("type");
        newTable = new Regex("<viewType>", Regex.DEFAULT_MASK).substitute(newTable, viewType, Regex.SUBSTITUTE_ALL);

        int max = Integer.parseInt((String) view.get("max"));
        Hashtable fields = (Hashtable) view.get("fields");
        Vector orderedFields = (Vector) view.get("orderedFields");
        Vector viewTables = (Vector) view.get("tables");

        StringBuffer fieldDeclarations = new StringBuffer();
        StringBuffer tableFieldDeclarations = new StringBuffer();
        StringBuffer addTableDeclarations = new StringBuffer();
        StringBuffer addFieldDeclarations = new StringBuffer();

        for (int i = 1; i < viewTables.size(); i++) {
          String thisTableName = (String) viewTables.elementAt(i);
          String newAddTableDeclaration = new Regex("<className>", Regex.DEFAULT_MASK).substitute(addTableDeclaration, thisTableName+"Table", Regex.SUBSTITUTE_ALL);

          if (addTableDeclarations.length() != 0) addTableDeclarations.append(lineSeparator);
          addTableDeclarations.append(newAddTableDeclaration);
        }

        for (Enumeration enum1 = orderedFields.elements(); enum1.hasMoreElements(); ) {
          String fieldName = (String) enum1.nextElement();
          Hashtable field = (Hashtable) fields.get(fieldName);

          String fieldId = (String) field.get("id");
          String fieldTableName = (String) field.get("tableName");
          String tableFieldId = getFieldId((String) field.get("tableFieldName"));

          fieldId = StringUtil.appendChars(fieldId, ' ', max);

          String newFieldDeclaration = new Regex("<fieldId>").substitute(fieldDeclaration, fieldId);
          newFieldDeclaration = new Regex("<fieldName>").substitute(newFieldDeclaration, fieldName);

          String newTableFieldDeclaration = new Regex("<fieldId>").substitute(tableFieldDeclaration, fieldId);
          newTableFieldDeclaration = new Regex("<tableName>").substitute(newTableFieldDeclaration, fieldTableName + "Table");
          newTableFieldDeclaration = new Regex("<tableFieldId>").substitute(newTableFieldDeclaration, tableFieldId);

          String newAddFieldDeclaration = new Regex("<fieldId>", Regex.DEFAULT_MASK).substitute(addFieldDeclaration, fieldId, Regex.SUBSTITUTE_ALL);
          newAddFieldDeclaration = new Regex("<className>",  Regex.DEFAULT_MASK).substitute(newAddFieldDeclaration, fieldTableName+"Table", Regex.SUBSTITUTE_ALL);

          if (sizes) {
            String fieldSize = (String) field.get("size");
            if (fieldSize == null) fieldSize = "";
            newAddFieldDeclaration = new Regex("<fieldSize>").substitute(newAddFieldDeclaration, fieldSize);
          } else {
            newAddFieldDeclaration = new Regex(",\\s+<fieldSize>").substitute(newAddFieldDeclaration, "");
          }

          if (fieldDeclarations.length() != 0) fieldDeclarations.append(lineSeparator);
          fieldDeclarations.append(newFieldDeclaration);

          if (tableFieldDeclarations.length() != 0) tableFieldDeclarations.append(lineSeparator);
          tableFieldDeclarations.append(newTableFieldDeclaration);

          if (addFieldDeclarations.length() != 0) addFieldDeclarations.append(lineSeparator);
          addFieldDeclarations.append(newAddFieldDeclaration);
        }

        newTable = new Regex("<fieldDeclaration>").substitute(newTable, fieldDeclarations.toString()+lineSeparator);
        newTable = new Regex("<tableFieldDeclaration>").substitute(newTable, tableFieldDeclarations.toString());
        newTable = new Regex("<addTableDeclaration>").substitute(newTable, addTableDeclarations.toString());
        newTable = new Regex("<addFieldDeclaration>").substitute(newTable, addFieldDeclarations.toString());

        writeFile(destinationDir+fileSeparator+viewName+"ViewTable.java", newTable);
      }
    } catch (Exception e) {
      System.err.println("ERROR: "+e.getMessage());
View Full Code Here

Examples of pt.opensoft.text.Regex

      if (type == null) throw new Exception("unknown type::"+type);

      for (Enumeration en = types.keys(); en.hasMoreElements(); ) {
        String key = (String) en.nextElement();

        if (!new Regex(server, Regex.CASE_INSENSITIVE_MASK).contains(key)) continue;

        if (debug >= 5) System.out.println("        searching key: "+key+"  "+server+"  "+type);

        String expression = key.substring(key.lastIndexOf(".")+1);

        if (!new Regex(expression, Regex.CASE_INSENSITIVE_MASK).matches(type)) continue;

        String value = (String) types.get(key);

        if (debug >= 4) System.out.print("        "+server+": "+type+" =~ "+expression+" -> "+value);

        if (value == null) throw new Exception("unknown type::"+type);
        type = value;

        if (new Regex("Types").contains(type)) return type;

        value = (String) types.get(type);
        if (type == null) throw new Exception("unknown type::"+type);

        if (debug >= 4) System.out.println(" -> "+value);
View Full Code Here

Examples of pt.opensoft.text.Regex

  public static void parseDDL (Hashtable tables, Hashtable views, Hashtable types, String ddl) {

        try {

            Regex regex = new Regex("\\sgo\\s|;",Regex.CASE_INSENSITIVE_MASK);

      List commands = regex.split(ddl);

      for (Iterator it = commands.iterator(); it.hasNext(); ) {

                String command = (String) it.next();

        if (debug == 0) System.out.print(".");

        if ((new Regex("create table",Regex.CASE_INSENSITIVE_MASK)).contains(command)) {
          createTable(types, tables, command);
          continue;
        }

        if ((new Regex("create view",Regex.CASE_INSENSITIVE_MASK)).contains(command)) {
          createView(tables, views, command);
          continue;
        }

        if ((new Regex("alter table",Regex.CASE_INSENSITIVE_MASK)).contains(command)) {
          alterTable(tables, command);
          continue;
        }
      }
View Full Code Here

Examples of pt.opensoft.text.Regex

        regex = StringUtil.replace(regex, ".", "\\.");
        regex = StringUtil.replace(regex, "*", ".*");
        regex = StringUtil.replace(regex, "?", ".?");

        _regex = new Regex(regex, Regex.CASE_INSENSITIVE_MASK);
    }
View Full Code Here

Examples of pt.opensoft.text.Regex

    public RegularExpressionFilenameFilter() {
    }

  public RegularExpressionFilenameFilter (String regex) {
    _regex = new Regex(regex);
  }
View Full Code Here

Examples of pt.opensoft.text.Regex

  public RegularExpressionFilenameFilter (String regex) {
    _regex = new Regex(regex);
  }

  public RegularExpressionFilenameFilter (String regex, int mask) {
    _regex = new Regex(regex, mask);
  }
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.