first commit

This commit is contained in:
MaddoScientisto 2026-03-14 20:04:39 +01:00
commit 4d332ef662
27586 changed files with 3281783 additions and 0 deletions

View file

@ -0,0 +1,76 @@
package com.ablia.tools.Db2Bean;
import com.ablia.util.FileWr;
public class ClassWriter extends FileWr {
private String dichiarazioni = "";
private String imports = "";
private String metodi = "";
private String definizione = "";
private String packages;
public ClassWriter(String filename) {
super(String.valueOf(filename) + ".java", false);
}
public void addDeclaration(String declaration) {
setDichiarazioni(String.valueOf(getDichiarazioni()) + "\n" + declaration);
}
public void addImport(String importString) {
setImports(String.valueOf(getImports()) + "\n" + importString);
}
public void addMethod(String method) {
setMetodi(String.valueOf(getMetodi()) + "\n" + method);
}
public String getDefinizione() {
return this.definizione;
}
public String getDichiarazioni() {
return this.dichiarazioni;
}
public String getImports() {
return this.imports;
}
public String getMetodi() {
return this.metodi;
}
public String getPackages() {
return this.packages;
}
public void setDefinizione(String newDefinizione) {
this.definizione = newDefinizione;
}
public void setDichiarazioni(String newDichiarazioni) {
this.dichiarazioni = newDichiarazioni;
}
public void setImports(String newImports) {
this.imports = newImports;
}
public void setMetodi(String newMetodi) {
this.metodi = newMetodi;
}
public void setPackages(String newPackages) {
this.packages = newPackages.isEmpty() ? "" : ("package " + newPackages);
}
public void writeClass() {
String temp = getDefinizione().substring(0, getDefinizione().lastIndexOf("}"));
writeLine(String.valueOf(getPackages()) + "\n" + getImports() + "\n" + temp + "\n" + getDichiarazioni() + "\n" + getMetodi() + "\n}");
}
}

View file

@ -0,0 +1,668 @@
package com.ablia.tools.Db2Bean;
import com.ablia.db.ColumnDescriptor;
import com.ablia.util.DbConsole;
import com.ablia.util.FileWr;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Vector;
public class Db2Bean extends DbConsole {
String serialId;
private static final String OVERRIDE = "@Override";
private static final String COLUMN_TO_SKIP = "lastUpdTmst,lastUpdId_user,created,createdby,updated,updatedby,ad_client,ad_client_id,ad_org,ad_org_id";
ColumnDescriptor cd;
int colNumb;
String columnName;
int columnSize;
short dataType;
public static void main(String[] args) {
Db2Bean d2b = new Db2Bean();
d2b.createBean();
System.out.println("bye");
}
String dichiarazioneOggetti = "";
String dichiarazioni = "";
String fillField;
Hashtable FKColumns;
String getMethods = "";
String initField;
FileWr javaFile;
Hashtable keyColumns;
Vector keyTableNames = new Vector();
String navigationMethods;
String cascadeMethods;
int numColonne = 0;
int numPk = 0;
int numRighe = 0;
private String packages;
int pkIdx;
String prepareDeleteKeyField;
String prepareKeyField;
String prepareSave;
String findByCR;
int prepareSaveColumnNumber;
int prepareSaveColumnNumberKey;
String prepareSaveWhere;
String retrievePkMethod;
ResultSet rstColumns;
ResultSetMetaData rstMd;
ResultSet rstPk;
ResultSet rstTables;
String setMethods = "";
String sqlInsert;
String sqlInsertValue;
String sqlStringDelete;
String sqlStringFindAll;
String sqlStringFindByPrimaryKey;
String sqlUpdate;
ColumnDescriptor[] tableColumns;
String tableName = "";
int totCol;
int totPk;
String whereCondition;
public boolean createBean() {
String filtroTab = "";
String temp = getCi().readLine("Filtro tabelle: ");
if (!temp.isEmpty())
filtroTab = temp;
try {
this.rstTables = getDb().getConn().getMetaData().getTables(null, null, null, null);
HashSet<String> tableNames = new HashSet<>();
while (this.rstTables.next()) {
this.tableName = this.rstTables.getString("TABLE_NAME");
if (filtroTab.isEmpty() || this.tableName.indexOf(filtroTab) >= 0) {
if (!tableNames.contains(this.tableName)) {
tableNames.add(this.tableName);
if (!this.tableName.toLowerCase().startsWith("view") && !this.tableName.toLowerCase().startsWith("sys") &&
!this.tableName.toLowerCase().startsWith("dt")) {
ClassWriter cw = new ClassWriter(String.valueOf(getOutputPaht()) + getClassName(this.tableName));
ClassWriter cwCR = new ClassWriter(String.valueOf(getOutputPaht()) + getClassName(this.tableName) + "CR");
cw.setPackages(getPackages());
cwCR.setPackages(getPackages());
init(cw);
initCR(cwCR);
createTableDescriptor();
System.out.print("creating table bean " + this.tableName + "..... ");
this.numPk = 0;
HashSet<String> columns = new HashSet<>();
for (int i = 0; i < this.totCol; i++) {
this.cd = this.tableColumns[i];
this.columnName = this.cd.getColumnName();
this.dataType = this.cd.getDataType();
if (!columns.contains(this.columnName)) {
columns.add(this.columnName);
if ("lastUpdTmst,lastUpdId_user,created,createdby,updated,updatedby,ad_client,ad_client_id,ad_org,ad_org_id".indexOf(this.columnName) < 0) {
if (this.cd.isPk()) {
this.numPk++;
this.prepareDeleteKeyField = String.valueOf(this.prepareDeleteKeyField) + "\n\t\tps.set" + getRstTypeName(this.dataType) + "(" +
this.numPk + ", get" + getMethodName(this.columnName) + "());";
if (this.numPk == 1) {
if (this.totPk > 1) {
this.retrievePkMethod = "\n\tprotected void retrieveAutoIncrementID() throws java.sql.SQLException\n\t{\n\t}";
this.prepareKeyField = String.valueOf(this.prepareKeyField) + "\n\t\t" + getClassName(this.tableName) +
"Key classKey = (" + getClassName(this.tableName) + "Key) pk;";
this.prepareKeyField = String.valueOf(this.prepareKeyField) + "\n\t\tps.set" + getRstTypeName(this.dataType) + "(" +
this.numPk + ", classKey.get" + getMethodName(this.columnName) + "());\n";
} else {
this.retrievePkMethod = "\n\tprotected void retrieveAutoIncrementID() throws java.sql.SQLException\n\t{";
if (this.cd.isAutoIncrement())
this.retrievePkMethod = String.valueOf(this.retrievePkMethod) + "\n\t\tset" + getMethodName(this.columnName) +
"(getLastInsertId());";
this.retrievePkMethod = String.valueOf(this.retrievePkMethod) + "\n\t}";
if (getTypeInitValue(this.dataType).equals("null")) {
this.prepareKeyField = String.valueOf(this.prepareKeyField) + "\n\t\tps.set" + getRstTypeName(this.dataType) + "(" +
this.numPk + ",(" + getRstTypeName(this.dataType) + ") pk);\n";
} else {
this.prepareKeyField = String.valueOf(this.prepareKeyField) + "\n\t\tps.set" + getRstTypeName(this.dataType) + "(" +
this.numPk + ",((" + getRstTypeName(this.dataType) + ") pk)." +
getTypeName(this.dataType) + "Value());\n";
}
}
} else {
this.prepareKeyField = String.valueOf(this.prepareKeyField) + "\n\t\tps.set" + getRstTypeName(this.dataType) + "(" + this.numPk +
", classKey.get" + getMethodName(this.columnName) + "());\n";
}
if (this.numPk == 1) {
this.whereCondition = String.valueOf(this.whereCondition) + " where " + this.columnName + "=?";
} else {
this.whereCondition = String.valueOf(this.whereCondition) + " and " + this.columnName + "=?";
}
if (this.numPk == 1) {
this.sqlInsert = String.valueOf(this.sqlInsert) + "\n\t\treturn \"insert into " + this.tableName.toUpperCase() + " (" +
this.columnName;
this.sqlInsertValue = " values(?";
} else {
this.sqlInsert = String.valueOf(this.sqlInsert) + ", " + this.columnName;
this.sqlInsertValue = String.valueOf(this.sqlInsertValue) + ",?";
}
if (this.numPk == 1) {
this.sqlUpdate = String.valueOf(this.sqlUpdate) + "\n\t\treturn \"update " + this.tableName.toUpperCase() + " set " +
this.columnName + "=?";
} else {
this.sqlUpdate = String.valueOf(this.sqlUpdate) + ", " + this.columnName + "=?";
}
this.prepareSaveColumnNumber++;
this.prepareSave = String.valueOf(this.prepareSave) + "\n\t\tps.set" + getRstTypeName(this.dataType) + "(" +
this.prepareSaveColumnNumber + ", get" + getMethodName(this.columnName) + "());";
this.prepareSaveColumnNumberKey = this.totCol + 1 + i;
this.prepareSaveWhere = String.valueOf(this.prepareSaveWhere) + "\n\t\t\tps.set" + getRstTypeName(this.dataType) + "(" +
this.prepareSaveColumnNumberKey + ", get" + getMethodName(this.columnName) + "());";
}
this.dichiarazioni = String.valueOf(this.dichiarazioni) + "\n\tprivate " + getTypeName(this.dataType) + " " + this.columnName + ";";
this.getMethods = String.valueOf(this.getMethods) + "\n\n\tpublic " + getTypeName(this.dataType) + " get" +
getMethodName(this.columnName) + "() {";
if (getTypeName(this.dataType).equals("String")) {
this.getMethods = String.valueOf(this.getMethods) + "\n\t\treturn " + this.columnName +
" == null ? DBAdapter.AB_EMPTY_STRING : " + this.columnName + ".trim();\n\t}";
} else {
this.getMethods = String.valueOf(this.getMethods) + "\n\t\treturn " + this.columnName + ";\n\t}";
}
this.setMethods = String.valueOf(this.setMethods) + "\n\n\tpublic void" + " set" + getMethodName(this.columnName) + "(" +
getTypeName(this.dataType) + " new" + getMethodName(this.columnName) + ") {";
this.setMethods = String.valueOf(this.setMethods) + "\n\t\t" + this.columnName + "=new" + getMethodName(this.columnName) + ";";
if (this.columnName.length() >= 2 && (
!this.columnName.endsWith("_id") ? false : true) & (this.cd.isPk() ? false : true)) {
String navigationField, navigationObject;
if (this.columnName.substring(0, 2).equals("id")) {
navigationField = getSingleNavigationFieldName(this.columnName);
navigationObject = getSingleNavigationObjectName(this.columnName);
} else {
navigationField = getSingleNavigationFieldNameAdempiere(this.columnName);
navigationObject = getSingleNavigationObjectNameAdempiere(this.columnName);
}
this.dichiarazioneOggetti = String.valueOf(this.dichiarazioneOggetti) + "\n\tprivate " + navigationObject + " " +
navigationField + ";";
this.navigationMethods = String.valueOf(this.navigationMethods) + "\n\n\tpublic void" + " set" + navigationObject + "(" +
navigationObject + " new" + navigationObject + ") {";
this.navigationMethods = String.valueOf(this.navigationMethods) + "\n\t\t" + navigationField + "=new" + navigationObject +
";\n\t}";
this.navigationMethods = String.valueOf(this.navigationMethods) + "\n\n\tpublic " + navigationObject + " get" +
navigationObject + "() {";
this.navigationMethods = String.valueOf(this.navigationMethods) + "\n\t\t" + navigationField + " = (" + navigationObject +
") getSecondaryObject(";
this.navigationMethods = String.valueOf(this.navigationMethods) + "\n\t\t" + navigationField + ",";
this.navigationMethods = String.valueOf(this.navigationMethods) + "\n\t\t" + navigationObject + ".class,";
this.navigationMethods = String.valueOf(this.navigationMethods) + "get" + getMethodName(this.columnName) + "());";
this.navigationMethods = String.valueOf(this.navigationMethods) + "\n\t\treturn " + navigationField + ";";
this.navigationMethods = String.valueOf(this.navigationMethods) + "\n\t}";
this.setMethods = String.valueOf(this.setMethods) + "\n\t\t" + "set" + navigationObject + "(null);";
}
this.setMethods = String.valueOf(this.setMethods) + "\n\t}";
this.fillField = String.valueOf(this.fillField) + "\n\t\tset" + getMethodName(this.columnName) + "(rst.get" +
getRstTypeName(this.dataType) + "(\"" + this.columnName + "\"));";
this.initField = String.valueOf(this.initField) + "\n\t\tset" + getMethodName(this.columnName) + "(" + getTypeInitValue(this.dataType) +
");";
if (!this.cd.isPk()) {
this.sqlInsert = String.valueOf(this.sqlInsert) + "\"\n\t\t+\", " + this.columnName;
this.sqlInsertValue = String.valueOf(this.sqlInsertValue) + ",?";
}
if (!this.cd.isPk())
this.sqlUpdate = String.valueOf(this.sqlUpdate) + "\"\n\t\t+\", " + this.columnName + "=?";
if (!this.cd.isPk()) {
this.prepareSaveColumnNumber++;
this.prepareSave = String.valueOf(this.prepareSave) + "\n\t\tps.set" + getRstTypeName(this.dataType) + "(" +
this.prepareSaveColumnNumber + ", get" + getMethodName(this.columnName) + "());";
}
} else {
System.out.print("#" + this.columnName + " ");
}
} else {
System.out.print("@" + this.columnName + " ");
}
}
System.out.println(" fine");
this.sqlStringFindAll = String.valueOf(this.sqlStringFindAll) + "\n\t\treturn \"select * from " + this.tableName.toUpperCase() + "\";";
this.sqlStringFindByPrimaryKey = String.valueOf(this.sqlStringFindByPrimaryKey) + "\n\t\treturn \"select * from " +
this.tableName.toUpperCase() + this.whereCondition + "\";";
this.sqlStringDelete = String.valueOf(this.sqlStringDelete) + "\n\t\treturn \"delete from " + this.tableName.toUpperCase() + this.whereCondition +
"\";";
this.fillField = String.valueOf(this.fillField) + "\n\t}";
this.initField = String.valueOf(this.initField) + "\n\t}";
this.sqlStringFindAll = String.valueOf(this.sqlStringFindAll) + "\n\t}";
this.prepareDeleteKeyField = String.valueOf(this.prepareDeleteKeyField) + "\n\t}";
this.prepareKeyField = String.valueOf(this.prepareKeyField) + "\n\t}";
this.prepareSave = String.valueOf(this.prepareSave) + this.prepareSaveWhere + "\n\t\t}\n\t}";
this.sqlStringDelete = String.valueOf(this.sqlStringDelete) + "\n\t}";
this.sqlStringFindByPrimaryKey = String.valueOf(this.sqlStringFindByPrimaryKey) + "\n\t}";
this.sqlInsert = String.valueOf(this.sqlInsert) + ") " + this.sqlInsertValue + ")\";\n\t}";
this.sqlUpdate = String.valueOf(this.sqlUpdate) + " " + this.whereCondition + "\";\n\t}";
this.findByCR = "\n\n\t@SuppressWarnings(\"unchecked\")\n\tpublic com.ablia.util.Vectumerator<" +
getClassName(this.tableName) + "> findByCR(" + getClassName(this.tableName) +
"CR CR,int pageNumber,\tint pageRows)\n";
this.findByCR = String.valueOf(this.findByCR) + "\t{\n\t//////////////////////////////////////////////////" + "\n\t// search statement" +
"\n\t//////////////////////////////////////////////////" +
"\n\tString s_Sql_Find = \"select DISTINCT A.* from " + this.tableName.toUpperCase() + " AS A\";" +
"\n\t///////////////////////////////////////////////////" +
"\n\tString s_Sql_Order = com.ablia.db.DBAdapter.AB_EMPTY_STRING;" + "\n\t// where condition" +
"\n\tWcString wc = new WcString();" + "\n\tif (!CR.getSearchTxt().trim().isEmpty()) {" +
"\n\t\tStringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(),\" \");" +
"\n\t\tStringBuffer txt = new StringBuffer(\"(\");" + "\n\t\tString token;" +
"\n\t\twhile (st.hasMoreTokens()) {" + "\n\t\t\ttoken = st.nextToken();" +
"\n\t\t\ttxt.append(\"(A.Cognome like '%\" + token + \"%' or A.Nome like '%\"+ token + \"%')\");" +
"\n\t\t\tif (st.hasMoreTokens())" + "\n\t\t\t\ttxt.append(\" and \");" + "\n\t\t}" +
"\n\t\ttxt.append(\")\");" +
"\n\t\twc.addWc(txt.toString());" + "\n\t}" +
"\n\ttry" + "\n\t{" +
"\n\t\tjava.sql.PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + wc.toString() + s_Sql_Order);" +
"\n\t\treturn (Vectumerator<" + getClassName(this.tableName) + ">) findRows(stmt, pageNumber, pageRows);" +
"\n\t}\n\tcatch (SQLException e)\n\t{\n\t\tremoveCPConnection();\n\t\thandleDebug(e);\n\t\treturn (Vectumerator<" +
getClassName(this.tableName) + ">) AB_EMPTY_VECTUMERATOR;\n\t}\n}";
cw.addDeclaration(this.serialId);
cw.addDeclaration(this.dichiarazioni);
cw.addDeclaration(this.dichiarazioneOggetti);
cw.addMethod(this.setMethods);
cw.addMethod(this.getMethods);
cw.addMethod(this.navigationMethods);
cw.addMethod(this.cascadeMethods);
cw.addMethod(this.findByCR);
cw.writeClass();
cw.closeFile();
cwCR.addDeclaration(this.dichiarazioni);
cwCR.addDeclaration(this.dichiarazioneOggetti);
cwCR.addMethod(this.setMethods);
cwCR.addMethod(this.getMethods);
cwCR.addMethod(this.navigationMethods);
cwCR.writeClass();
cwCR.closeFile();
}
continue;
}
System.out.println("Tabella duplicata probabilmente su schemi deiversi (postgres):" + this.tableName);
}
}
Enumeration<TableDescriptor> enu = this.keyTableNames.elements();
while (enu.hasMoreElements()) {
TableDescriptor td = enu.nextElement();
this.dichiarazioni = "";
this.getMethods = "";
this.setMethods = "";
String constructorMethods = "";
String cmArgs = "";
String cmBody = "";
this.dichiarazioneOggetti = "";
this.navigationMethods = "";
this.tableName = td.getTableName();
this.tableColumns = td.getTableColumns();
this.totCol = td.getTotColumn();
System.out.print("Creating key classes " + this.tableName + " ........");
ClassWriter cw = new ClassWriter(String.valueOf(getOutputPaht()) + getClassName(this.tableName) + "Key");
cw.setPackages(getPackages());
cw.addImport(getImport());
cw.setDefinizione("public class " + getClassName(this.tableName) + "Key implements java.io.Serializable {\n}");
constructorMethods = "\n\tpublic " + getClassName(this.tableName) + "Key(";
for (int i = 0; i < this.totCol; i++) {
this.cd = this.tableColumns[i];
this.dataType = this.cd.getDataType();
this.columnName = this.cd.getColumnName();
if (this.cd.isPk()) {
if (cmArgs.isEmpty()) {
cmArgs = String.valueOf(getTypeName(this.dataType)) + " new" + getMethodName(this.columnName);
} else {
cmArgs = String.valueOf(cmArgs) + ", " + getTypeName(this.dataType) + " new" + getMethodName(this.columnName);
}
cmBody = String.valueOf(cmBody) + "\n\t\t\tset" + getMethodName(this.columnName) + "(new" + getMethodName(this.columnName) + ");";
this.dichiarazioni = String.valueOf(this.dichiarazioni) + "\n\tprivate " + getTypeName(this.dataType) + " " + this.columnName + ";";
this.getMethods = String.valueOf(this.getMethods) + "\n\n\tpublic " + getTypeName(this.dataType) + " get" + getMethodName(this.columnName) + "() {";
this.getMethods = String.valueOf(this.getMethods) + "\n\t\treturn " + this.columnName + ";\n\t}\n";
this.setMethods = String.valueOf(this.setMethods) + "\n\n\tpublic void" + " set" + getMethodName(this.columnName) + "(" + getTypeName(this.dataType) +
" new" + getMethodName(this.columnName) + ") {";
this.setMethods = String.valueOf(this.setMethods) + "\n\t\t" + this.columnName + "=new" + getMethodName(this.columnName) + ";";
this.setMethods = String.valueOf(this.setMethods) + "\n\t}";
}
}
constructorMethods = String.valueOf(constructorMethods) + cmArgs + ")\n\t{\n\t\t" + cmBody + "\n\t}";
cw.addDeclaration(this.dichiarazioni);
cw.addDeclaration(this.dichiarazioneOggetti);
cw.addMethod(constructorMethods);
cw.addMethod(this.setMethods);
cw.addMethod(this.getMethods);
cw.addMethod(this.navigationMethods);
cw.writeClass();
cw.closeFile();
System.out.println("Done");
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
protected void createTableDescriptor() throws SQLException {
this.keyColumns = new Hashtable();
this.FKColumns = new Hashtable();
this.pkIdx = 0;
this.colNumb = 0;
this.totCol = 0;
if (this.tableName.equals("profilo_utente_utente"))
this.totCol = 0;
this.rstPk = getDb().getConn().getMetaData().getPrimaryKeys(null, null, this.tableName);
this.totPk = 0;
while (this.rstPk.next()) {
this.totPk++;
this.columnName = this.rstPk.getString("COLUMN_NAME");
this.keyColumns.put(this.columnName, this.columnName);
}
this.rstPk.close();
this.rstColumns = getDb().getConn().getMetaData().getColumns(null, null, this.tableName, null);
try {
while (this.rstColumns.next()) {
this.dataType = this.rstColumns.getShort("DATA_TYPE");
this.columnName = this.rstColumns.getString("COLUMN_NAME");
this.columnSize = this.rstColumns.getInt("COLUMN_SIZE");
HashSet<String> columnNames = new HashSet<>();
if (!columnNames.contains(columnNames)) {
columnNames.add(this.columnName);
this.totCol++;
if (this.keyColumns.containsKey(this.columnName)) {
this.tableColumns[this.pkIdx] = new ColumnDescriptor(this.columnName, this.dataType, this.columnSize, true);
if (this.dataType == 4) {
this.tableColumns[this.pkIdx].setAutoIncrement(true);
} else {
this.tableColumns[this.pkIdx].setAutoIncrement(false);
}
if (this.FKColumns.containsKey(this.columnName))
this.tableColumns[this.pkIdx].setFk(true);
this.pkIdx++;
continue;
}
this.tableColumns[this.totPk + this.colNumb] = new ColumnDescriptor(this.columnName, this.dataType, this.columnSize, false);
if (this.FKColumns.containsKey(this.columnName))
this.tableColumns[this.totPk + this.colNumb].setFk(true);
this.colNumb++;
continue;
}
System.out.println("Colonna duplicata:" + this.columnName);
}
} catch (SecurityException e) {
e.printStackTrace();
}
if (this.totPk > 1)
this.keyTableNames.add(new TableDescriptor(this.tableName, this.tableColumns, this.totCol, this.totPk));
}
private boolean displayResultset(ResultSet rst) {
int maxColWidth = 30;
String str = "";
Object myObj = null;
int numColonne = 0;
int numRighe = 0;
try {
ResultSetMetaData rstMd = rst.getMetaData();
numColonne = rstMd.getColumnCount();
int[] colWidth = new int[numColonne + 1];
System.out.println("Numero Colonne: " + numColonne);
for (int i = 1; i <= numColonne; i++) {
if (rstMd.getColumnDisplaySize(i) < rstMd.getColumnName(i).length()) {
colWidth[i] = rstMd.getColumnName(i).length();
} else if (rstMd.getColumnDisplaySize(i) > maxColWidth) {
colWidth[i] = maxColWidth;
} else {
colWidth[i] = rstMd.getColumnDisplaySize(i);
}
str = String.valueOf(rstMd.getColumnName(i)) + spaces(colWidth[i] - rstMd.getColumnName(i).length()) + " | ";
System.out.print(str);
}
System.out.println();
numRighe = 0;
while (rst.next()) {
numRighe++;
for (int j = 1; j <= numColonne; j++) {
if ((myObj = rst.getObject(j)) == null) {
str = "null";
} else {
str = myObj.toString();
}
str = String.valueOf(str) + spaces(colWidth[j] - str.length());
if (str.length() > maxColWidth)
str = str.substring(0, maxColWidth);
System.out.print(String.valueOf(str) + " | ");
}
System.out.println();
}
System.out.println("Numero di record; " + numRighe + "\n");
} catch (Exception e) {
System.out.println(e.getMessage());
}
return true;
}
protected String getClassName(String tableName) {
int usIdx = -1;
String temp = String.valueOf(tableName.substring(0, 1).toUpperCase()) + tableName.substring(1).toLowerCase();
while ((usIdx = temp.indexOf("_")) != -1)
temp = String.valueOf(temp.substring(0, usIdx)) + temp.substring(usIdx + 1, usIdx + 2).toUpperCase() + temp.substring(usIdx + 2, temp.length());
return temp;
}
private String getImport() {
String temp = "import java.sql.SQLException;\n";
temp = String.valueOf(temp) + "import java.sql.Date;\n";
temp = String.valueOf(temp) + "import java.sql.Time;\n";
temp = String.valueOf(temp) + "import java.sql.Timestamp;\n";
temp = String.valueOf(temp) + "import com.ablia.db.DBAdapter;\n";
temp = String.valueOf(temp) + "import com.ablia.db.ResParm;\n";
temp = String.valueOf(temp) + "import com.ablia.db.WcString;\n";
temp = String.valueOf(temp) + "import com.ablia.util.StringTokenizer;\n";
temp = String.valueOf(temp) + "import com.ablia.util.Vectumerator;\n";
temp = String.valueOf(temp) + "/**\n";
temp = String.valueOf(temp) + " * Bean class: " + getClassName(this.tableName) + "\n";
temp = String.valueOf(temp) + " * <br>Creation date:" + new Date(System.currentTimeMillis()) + "\n";
temp = String.valueOf(temp) + " * @author com.ablia.tool.DB2Bean \n";
temp = String.valueOf(temp) + " */\n";
return temp;
}
private String getImportCR() {
String temp = "import com.ablia.db.*;\n";
temp = String.valueOf(temp) + "import java.sql.*;\n\n";
temp = String.valueOf(temp) + "/**\n";
temp = String.valueOf(temp) + " * Bean class: " + getClassName(this.tableName) + "CR\n";
temp = String.valueOf(temp) + " * <br>Creation date:" + new Date(System.currentTimeMillis()) + "\n";
temp = String.valueOf(temp) + " * @author Andrea Colzi \n";
temp = String.valueOf(temp) + " */\n";
return temp;
}
private String getMethodName(String columnName) {
String temp = String.valueOf(columnName.substring(0, 1).toUpperCase()) + columnName.substring(1);
return temp;
}
public String getPackages() {
if (this.packages == null) {
this.packages = getCi().readLine("Package: ");
if (!this.packages.isEmpty() &&
!this.packages.endsWith(";"))
this.packages = String.valueOf(this.packages) + ";";
}
return this.packages;
}
private String getRstTypeName(short dataType) {
return String.valueOf(getTypeName(dataType).substring(0, 1).toUpperCase()) + getTypeName(dataType).substring(1);
}
private String getSingleNavigationFieldName(String columnName) {
String temp = columnName.substring(3);
return temp;
}
private String getSingleNavigationFieldNameAdempiere(String columnName) {
String temp = columnName.substring(0, columnName.length() - 3);
return temp;
}
private String getSingleNavigationObjectName(String columnName) {
String temp = String.valueOf(columnName.substring(3, 4).toUpperCase()) + columnName.substring(4);
return temp;
}
private String getSingleNavigationObjectNameAdempiere(String columnName) {
try {
String temp = getSingleNavigationFieldNameAdempiere(columnName);
temp = String.valueOf(temp.substring(0, 1).toUpperCase()) + temp.substring(1);
return temp;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private String getTypeInitValue(short dataType) {
switch (dataType) {
case -7:
case -6:
case 2:
case 3:
case 4:
case 5:
case 6:
case 8:
return "0";
case 1:
case 12:
case 91:
case 92:
case 93:
case 1111:
return "null";
}
return "null";
}
private String getTypeName(short dataType) {
switch (dataType) {
case 6:
return "float";
case -6:
case 5:
return "int";
case 2:
case 4:
return "long";
case -7:
return "boolean";
case 3:
case 8:
return "double";
case 1:
case 12:
case 1111:
return "String";
case 91:
return "Date";
case 92:
return "Time";
case 93:
if (getApFull().getDbType() == 13 || getApFull().getDbType() == 14)
return "Date";
return "Timestamp";
}
return "String";
}
protected void init(ClassWriter cw) {
this.serialId = "\n\tprivate static final long serialVersionUID =" + Calendar.getInstance().getTimeInMillis() + "L;";
this.fillField = "\n\n\tpublic void fillFields(java.sql.ResultSet rst) throws java.sql.SQLException {\n";
this.initField = "\n\n\tpublic void initFields()\n\t{\n";
this.sqlStringFindAll = "\n\tprotected java.lang.String sqlStringfindAll() {\n";
this.prepareDeleteKeyField = "\n\n\tprotected void prepareDeleteKeyField(java.sql.PreparedStatement ps) throws java.sql.SQLException {\n";
this.prepareKeyField = "\n\n\tprotected void prepareKeyField(java.sql.PreparedStatement ps, Object pk) throws java.sql.SQLException {";
this.prepareSave = "\n\n\tprotected void prepareSave(java.sql.PreparedStatement ps) throws java.sql.SQLException {\n";
this.prepareSaveWhere = "\n\n\t\t// campo chiave per where\n\t\tif (getDBState() == ST_EDIT)\n\t\t{";
this.prepareSaveColumnNumber = 0;
this.sqlStringDelete = "\n\n\tprotected String sqlStringDelete() {\n";
this.sqlStringFindByPrimaryKey = "\n\n\tprotected String sqlStringfindByPrimaryKey() {\n";
this.sqlInsert = "\n\n\tprotected String sqlStringInsert() {\n";
this.sqlInsertValue = "";
this.sqlUpdate = "\n\n\tprotected String sqlStringUpdate() {\n";
this.whereCondition = "";
this.dichiarazioni = "";
this.dichiarazioneOggetti = "";
this.getMethods = "";
this.setMethods = "";
this.navigationMethods = "";
this.cascadeMethods = "\n\t@Override\n\tprotected ResParm checkDeleteCascade()\n\t{\n\t\treturn new ResParm(true);\n\t}";
this.cascadeMethods = String.valueOf(this.cascadeMethods) + "\n\t" + "@Override" + "\n\tprotected void deleteCascade() {}";
this.findByCR = "";
this.tableColumns = new ColumnDescriptor[300];
cw.addImport(getImport());
cw.setDefinizione("public class " + getClassName(this.tableName) + " extends DBAdapter implements java.io.Serializable {\n}");
cw.addMethod(
"\tpublic " + getClassName(this.tableName) + "(com.ablia.db.ApplParmFull newApplParmFull) {\n\t\tsuper(newApplParmFull);\n\t}");
cw.addMethod("\tpublic " + getClassName(this.tableName) + "(){}");
}
protected void initCR(ClassWriter cw) {
cw.addImport(getImportCR());
cw.setDefinizione("public class " + getClassName(this.tableName) + "CR extends CRAdapter {\n}");
cw.addMethod("\tpublic " + getClassName(this.tableName) + "CR(ApplParmFull newApplParmFull) {\n\t\tsuper(newApplParmFull);\n\t}");
cw.addMethod("\tpublic " + getClassName(this.tableName) + "CR(){}");
}
private String spaces(int n_spaces) {
String str = "";
for (int i = 0; i < n_spaces; i++)
str = String.valueOf(str) + " ";
return str;
}
}

View file

@ -0,0 +1,230 @@
package com.ablia.tools.Db2Bean;
import com.ablia.db.ApplParm;
import com.ablia.db.DBAdapter;
import com.ablia.db.DriversJdbc;
import com.ablia.db.JdbcStub;
import com.ablia.util.Vectumerator;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import javax.servlet.http.HttpServletRequest;
public class MigraDB extends Db2Bean {
private JdbcStub dbTarget;
private ApplParm apTarget;
protected void fillObject(HttpServletRequest request, Object obj, int index) {}
protected ApplParm getApTarget() {
if (this.apTarget == null)
try {
System.out.print("Target database. . . . .");
System.out.println("Choose the Jdbc driver (it must be in your classpath):");
for (int i = 0; i < DriversJdbc.getTotNumberOfDrivers(); i++)
System.out.println("(" + i + ") " + DriversJdbc.getDriverDescription(i));
String driver = getCi().readLine("Driver=");
String DSN = getCi().readLine(
"jdbc resource" +
DriversJdbc.getDriverDescription(Integer.parseInt(driver)));
String login = getCi().readLine("Login: ");
String pwd = getCi().readLine("Password: ");
this.apTarget = new ApplParm(Integer.parseInt(driver), DSN, login, pwd);
} catch (Exception e) {
e.printStackTrace(System.out);
return null;
}
return this.apTarget;
}
protected JdbcStub getDbTarget() {
if (this.dbTarget == null)
try {
this.dbTarget = new JdbcStub(getApTarget());
} catch (Exception e) {
e.printStackTrace(System.out);
return null;
}
return this.dbTarget;
}
private Field getField(Object obj, String parmName) throws Exception {
Field field = null;
Class<?> cls = obj.getClass();
while (!cls.equals(Object.class)) {
try {
field = cls.getDeclaredField(parmName);
break;
} catch (NoSuchFieldException nsfe) {
cls = cls.getSuperclass();
if (cls.equals(Object.class))
throw nsfe;
} catch (Exception e) {
throw e;
}
}
return field;
}
public String getPackages() {
String temp = super.getPackages();
return temp.substring(0, temp.length() - 1);
}
private String getRealColumnName(Class theClass, String columnName) {
Field[] fields = theClass.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
String fieldName = fields[i].getName();
if (fieldName.equals(columnName) ||
fieldName.toLowerCase().equals(columnName) ||
fieldName.toUpperCase().equals(columnName))
return fieldName;
}
if (theClass.equals(Object.class))
return null;
return getRealColumnName(theClass.getSuperclass(), columnName);
}
private int getStopEvery() {
String se = getCi().readLine("Stop every num. record[1000]: ");
if (se.isEmpty())
return 1000;
return Integer.valueOf(se);
}
public static void main(String[] args) {
String l_table = null;
if (args.length > 0)
l_table = args[0];
new MigraDB().migra(l_table);
System.exit(0);
}
public boolean migra(String l_table) {
try {
int recordCount = 0;
int se = 0;
System.out.print("Inserire il database source . . . . .");
this.tableColumns = new com.ablia.db.ColumnDescriptor[100];
Object[] apSource = { getApFull() };
Object[] apTarget = { getApTarget() };
Class[] apClass = { ApplParm.class };
Method setApMth = DBAdapter.class
.getMethod("setAp", apClass);
Method findAllMth = DBAdapter.class
.getMethod("migraFindAll", null);
Method saveMth = DBAdapter.class
.getMethod("save", null);
Method gpkdMth = DBAdapter.class
.getMethod("getPrimaryKeysDescription", null);
String setMethodName = "";
Object[] args = new Object[1];
Class[] param = new Class<?>[1];
se = getStopEvery();
do {
this.rstTables = getDb().getConn().getMetaData()
.getTables(null, null, null, null);
while (this.rstTables.next()) {
try {
this.tableName = this.rstTables.getString("TABLE_NAME");
createTableDescriptor();
Class<?> beanClass = Class.forName(String.valueOf(getPackages()) + "." +
getClassName(this.tableName));
if (l_table == null ||
this.tableName.toUpperCase().equals(
l_table.toUpperCase())) {
System.out.print("Migrating table " + this.tableName +
".....");
System.out.print("Continue?");
if (consoleYN()) {
Object beanSource = beanClass.newInstance();
setApMth.invoke(beanSource, apSource);
Vectumerator vecSource = (Vectumerator)findAllMth.invoke(
beanSource, null);
System.out.println("Find source done for " +
vecSource.getTotNumberOfRecords() +
" records");
while (vecSource.hasMoreElements()) {
recordCount++;
System.out.print("Rec. # " + recordCount +
":");
if (se > 0 && recordCount % se == 0) {
System.out.print("Continue ");
if (!consoleYN())
break;
}
beanSource = vecSource.nextElement();
Object beanTarget = beanClass.newInstance();
setApMth.invoke(beanTarget, apTarget);
for (int i = 0; i < this.totCol; i++) {
this.cd = this.tableColumns[i];
this.columnName = this.cd.getColumnName();
this.columnName = getRealColumnName(
beanClass, this.columnName);
this.columnName.equals("dataFineVld");
Method mth = beanSource.getClass()
.getMethod(
"get" +
this.columnName.substring(
0,
1)
.toUpperCase() +
this.columnName.substring(1),
null);
args[0] = mth.invoke(beanSource, null);
Field field = getField(beanTarget,
this.columnName);
param[0] = field.getType();
setMethodName = "set" +
this.columnName.substring(0, 1)
.toUpperCase() +
this.columnName.substring(1);
mth = beanTarget.getClass()
.getMethod(setMethodName,
param);
mth.invoke(beanTarget, args);
}
try {
saveMth.invoke(beanTarget, null);
} catch (Exception dbae) {
System.out.println(dbae.getMessage());
System.out.println("tablename: " +
this.tableName + " colname: " +
this.columnName);
System.out.println(gpkdMth.invoke(
beanTarget, null));
dbae.printStackTrace();
System.out.print("Continue ");
if (!consoleYN())
break;
}
}
System.out.println("END Migrating table " +
this.tableName);
continue;
}
System.out.println("Table " + this.tableName +
" Skipped!");
}
} catch (Exception dbae) {
System.out.println(dbae.getMessage());
System.out.println("tablename: " + this.tableName +
" colname: " + this.columnName);
dbae.printStackTrace();
}
}
System.out.print("Begin again ");
} while (consoleYN());
System.out.println("Done");
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println("tablename: " + this.tableName + " colname: " +
this.columnName);
e.printStackTrace();
}
return true;
}
}

View file

@ -0,0 +1,54 @@
package com.ablia.tools.Db2Bean;
import com.ablia.db.ColumnDescriptor;
public class TableDescriptor {
private String tableName;
private ColumnDescriptor[] tableColumns;
private int totColumn;
private int totPk;
public TableDescriptor() {}
public TableDescriptor(String theTableName, ColumnDescriptor[] theTableColumns, int theTotCol, int theTotpk) {
setTableName(theTableName);
setTableColumns(theTableColumns);
setTotColumn(theTotCol);
setTotPk(theTotpk);
}
public ColumnDescriptor[] getTableColumns() {
return this.tableColumns;
}
public String getTableName() {
return this.tableName;
}
public int getTotColumn() {
return this.totColumn;
}
public int getTotPk() {
return this.totPk;
}
public void setTableColumns(ColumnDescriptor[] newTableColumns) {
this.tableColumns = newTableColumns;
}
public void setTableName(String newTableName) {
this.tableName = newTableName;
}
public void setTotColumn(int newTotColumn) {
this.totColumn = newTotColumn;
}
public void setTotPk(int newTotPk) {
this.totPk = newTotPk;
}
}

View file

@ -0,0 +1 @@
package com.ablia.tools.Db2Bean;

View file

@ -0,0 +1,75 @@
package com.ablia.tools;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class FileHash {
public static final String SHA = "SHA";
public static final String MD5 = "MD5";
private File file;
private String algoritmo;
public FileHash(String filename, String Algoritmo) {
this.file = new File(filename);
setAlgoritmo(Algoritmo);
}
public String getFileHash() {
try {
MessageDigest digest = MessageDigest.getInstance(getAlgoritmo());
InputStream is = new FileInputStream(this.file);
byte[] buffer = new byte[8192];
int read = 0;
try {
while ((read = is.read(buffer)) > 0)
digest.update(buffer, 0, read);
byte[] md5sum = digest.digest();
BigInteger bigInt = new BigInteger(1, md5sum);
String output = bigInt.toString(16);
return output;
} catch (IOException e) {
throw new RuntimeException("Unable to process file for " +
getAlgoritmo(), e);
} finally {
try {
is.close();
} catch (IOException e) {
throw new RuntimeException(
"Unable to close input stream for " +
getAlgoritmo() + " calculation", e);
}
}
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (FileNotFoundException e2) {
e2.printStackTrace();
}
return this.algoritmo;
}
public String toString() {
return this.algoritmo + " : " + getFileHash();
}
public boolean equals(Object o) {
FileHash p = (FileHash)o;
return getFileHash().equals(p.getFileHash());
}
public String getAlgoritmo() {
return this.algoritmo;
}
public void setAlgoritmo(String algoritmo) {
this.algoritmo = algoritmo;
}
}

View file

@ -0,0 +1,153 @@
package com.ablia.tools;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.security.KeyStore;
import java.security.MessageDigest;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
public class InstallCert {
public static void main(String[] args) throws Exception {
int k;
String host = "";
host = "api.sandbox.ebay.com";
int port = 443;
String p = "changeit";
if (args.length == 1 || args.length == 2) {
String[] c = args[0].split(":");
host = c[0];
port = (c.length == 1) ? 443 : Integer.parseInt(c[1]);
p = (args.length == 1) ? "changeit" : args[1];
}
if (host.isEmpty() || p.isEmpty()) {
System.out.println("Usage: java InstallCert <host>[:port] [passphrase]");
return;
}
char[] passphrase = p.toCharArray();
File file = new File("jssecacerts");
if (!file.isFile()) {
char SEP = File.separatorChar;
File dir = new File(String.valueOf(System.getProperty("java.home")) + SEP + "lib" + SEP + "security");
file = new File(dir, "jssecacerts");
if (!file.isFile())
file = new File(dir, "cacerts");
}
System.out.println("Loading KeyStore " + file + "...");
InputStream in = new FileInputStream(file);
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(in, passphrase);
in.close();
SSLContext context = SSLContext.getInstance("TLS");
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ks);
X509TrustManager defaultTrustManager = (X509TrustManager)tmf.getTrustManagers()[0];
SavingTrustManager tm = new SavingTrustManager(defaultTrustManager);
context.init(null, new TrustManager[] { tm }, null);
SSLSocketFactory factory = context.getSocketFactory();
System.out.println("Opening connection to " + host + ":" + port + "...");
SSLSocket socket = (SSLSocket)factory.createSocket(host, port);
socket.setSoTimeout(10000);
try {
System.out.println("Starting SSL handshake...");
socket.startHandshake();
socket.close();
System.out.println();
System.out.println("No errors, certificate is already trusted");
} catch (SSLException e) {
System.out.println();
e.printStackTrace(System.out);
}
X509Certificate[] chain = tm.chain;
if (chain == null) {
System.out.println("Could not obtain server certificate chain");
return;
}
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println();
System.out.println("Server sent " + chain.length + " certificate(s):");
System.out.println();
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
MessageDigest md5 = MessageDigest.getInstance("MD5");
for (int i = 0; i < chain.length; i++) {
X509Certificate x509Certificate = chain[i];
System.out.println(" " + (i + 1) + " Subject " + x509Certificate.getSubjectDN());
System.out.println(" Issuer " + x509Certificate.getIssuerDN());
sha1.update(x509Certificate.getEncoded());
System.out.println(" sha1 " + toHexString(sha1.digest()));
md5.update(x509Certificate.getEncoded());
System.out.println(" md5 " + toHexString(md5.digest()));
System.out.println();
}
System.out.println("Enter certificate to add to trusted keystore or 'q' to quit: [1]");
String line = reader.readLine().trim();
try {
k = (line.length() == 0) ? 0 : (Integer.parseInt(line) - 1);
} catch (NumberFormatException e) {
System.out.println("KeyStore not changed");
return;
}
X509Certificate cert = chain[k];
String alias = String.valueOf(host) + "-" + (k + 1);
ks.setCertificateEntry(alias, cert);
OutputStream out = new FileOutputStream("jssecacerts");
ks.store(out, passphrase);
out.close();
System.out.println();
System.out.println(cert);
System.out.println();
System.out.println("Added certificate to keystore 'jssecacerts' using alias '" + alias + "'");
System.out.println("Copy 'jssecacerts' to [path_to_java]...jre/lib/security/");
}
private static final char[] HEXDIGITS = "0123456789abcdef".toCharArray();
private static String toHexString(byte[] bytes) {
StringBuilder sb = new StringBuilder(bytes.length * 3);
byte[] arrayOfByte;
for (int j = (arrayOfByte = bytes).length, i = 0; i < j; ) {
int b = arrayOfByte[i];
b &= 0xFF;
sb.append(HEXDIGITS[b >> 4]);
sb.append(HEXDIGITS[b & 0xF]);
sb.append(' ');
i++;
}
return sb.toString();
}
private static class SavingTrustManager implements X509TrustManager {
private final X509TrustManager tm;
private X509Certificate[] chain;
SavingTrustManager(X509TrustManager tm) {
this.tm = tm;
}
public X509Certificate[] getAcceptedIssuers() {
throw new UnsupportedOperationException();
}
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
throw new UnsupportedOperationException();
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
this.chain = chain;
this.tm.checkServerTrusted(chain, authType);
}
}
}

View file

@ -0,0 +1,241 @@
package com.ablia.tools;
import com.ablia.util.DbConsole;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
public class LteTools extends DbConsole {
public static void main(String[] args) {
LteTools bean = new LteTools();
String content = readFile("/Users/acolzi/Downloads/aa.txt", StandardCharsets.UTF_8);
String result = bean.convertiTabRicerca(content);
System.out.println(result);
System.exit(0);
}
static String readFile(String path, Charset encoding) {
try {
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
private String convertiTabRicercaDettaglio(String txtDaConvertire, String tipo) {
String temp = txtDaConvertire;
try {
String head = "<div class=\"row hidden-print\"><div class=\"col-lg-12\"><div class=\"box box-" + tipo +
"\"><div class=\"box-body\">";
String foot = " </div></div></div></div>";
String startRiga = " <div class=\"row\">";
String fineDiv = "</div>";
String startColonna = "<div class=\"col-lg-3\">";
String startLabel = "<label for=\"txtRicerca\">";
String endLabel = "</label>";
String classInputText = "class=\"form-control input-sm\"";
String classCheckBox = "class=\"minimal\"";
String classSelect = " class=\"form-control input-sm select2\" style=\"width: 100%;\"";
String result = head;
for (int i = 1; i < 999; i++) {
String colonna;
String riga = getContenutoTr(temp, i);
if (riga.isEmpty())
break;
result = String.valueOf(result) + startRiga;
int j = 1;
do {
colonna = getContenutoTd(riga, j);
if (colonna.isEmpty())
continue;
int idx = colonna.indexOf("<");
if (idx >= 0) {
result = String.valueOf(result) + startColonna + startLabel + colonna.substring(0, idx) + endLabel + colonna.substring(idx) +
fineDiv;
j++;
} else {
break;
}
} while (!colonna.isEmpty());
result = String.valueOf(result) + fineDiv;
}
result = String.valueOf(result) + foot;
result = result.replace("type=\"text\"", "type=\"text\" " + classInputText);
result = result.replace("<select", "<select " + classSelect);
result = result.replace("type=\"checkbox\"", "type=\"checkbox\" " + classCheckBox);
result = result.replace("class=\"mandatoryField\"", "");
result = result.replace("Â", "");
result = result.replace("</ab:optionvec>", "&nbsp;</ab:optionvec>");
while (result.contains("size=")) {
int idxSize = result.indexOf("size=");
int idxfine = result.substring(idxSize + 7).indexOf("\"") + idxSize + 8;
if (idxfine < idxSize || idxSize < 0) {
System.out.println("ERRORE! TAG NON CHIUSO: " + result.substring(idxSize + 7));
continue;
}
String size = result.substring(idxSize, idxfine);
result = result.replace(size, " ");
}
while (result.contains("<%=Ab.jsCr")) {
int idxSize = result.indexOf("<%=Ab.jsCr");
int idxfine = result.substring(idxSize + 7).indexOf("%>") + idxSize + 9;
if (idxfine < idxSize || idxSize < 0) {
System.out.println("ERRORE! TAG NON CHIUSO: " + result.substring(idxSize + 7));
continue;
}
String size = result.substring(idxSize, idxfine);
result = result.replace(size, "");
}
return result;
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
}
}
public String getContenutoTr(String txt, int n) {
int startIdx = 0, endIdx = 0;
for (int i = 0; i < n; i++)
startIdx = txt.indexOf("<tr", startIdx + 1);
if (startIdx < 0)
return "";
startIdx = txt.indexOf(">", startIdx + 1) + 1;
endIdx = txt.indexOf("</tr>", startIdx);
if (endIdx < startIdx)
return "ERRORE! non trovo chiusura tr n." + n + ": " + txt;
String temp = txt.substring(startIdx, endIdx);
return temp;
}
public String getContenutoTd(String txt, int n) {
int startIdx = 0, endIdx = 0;
for (int i = 0; i < n; i++)
startIdx = txt.indexOf("<td", startIdx + 1);
if (startIdx < 0)
return "";
startIdx = txt.indexOf(">", startIdx + 1) + 1;
endIdx = txt.indexOf("</td>", startIdx);
if (endIdx == -1) {
System.out.println("ERRORE! non trovo chiusura td n." + n + ": " + txt);
return "ERRORE! non trovo chiusura td n." + n + ": " + txt;
}
String temp = txt.substring(startIdx, endIdx);
return temp;
}
public String convertiTabellaListe(String txtDaConvertire) {
String temp = txtDaConvertire;
try {
String head = "<div class=\"box-body \" id=\"no-more-tables\" > <table class=\"table table-bordered table-hover table-striped dataTable table-condensed\">";
String foot = " </table></div>";
String tdComandi = "<td class=\"comandi text-center\"><div class=\"inline text-center hidden-print\"> <a href=\"javascript:modifyCommand('<%=rowBean.getId_xxx()%>');\"><i class=\"fa fa-edit\" title=\"Modifica Record\"></i></a> <a href=\"javascript:deleteCommandCR('<%=rowBean.getId_xxx()%>','<%= rowBean.getLastUpdTmstString() %>');\"><i class=\"fa fa-trash-o\" title=\"Cancella Record\"></i></a></td> ";
String startTd = "<td data-title=\" ";
String endTd = "</td>";
String endTr = "</tr>";
String inizioWhile = "<ab:whilevec rowbeanclass=\"xxx\" vectumerator=\"list\">";
String fineWhile = "</ab:whilevec> ";
String result = head;
ArrayList<String> colonneTh = new ArrayList<>();
result = String.valueOf(result) + "<tr>";
String rigaTH = getContenutoTr(temp, 1);
for (int i = 1; i < 999; i++) {
String riga = getContenutoTH(rigaTH, i);
if (riga.equals("XX_FINE_XX"))
break;
colonneTh.add(riga);
System.out.println(String.valueOf(i) + " " + riga);
result = String.valueOf(result) + "<th>" + riga + "</th>";
}
result = String.valueOf(result) + endTr;
String rbc = "xxx";
int idxRbc = txtDaConvertire.indexOf("rowbeanclass=");
int idxfineRbc = txtDaConvertire.substring(idxRbc + 14).indexOf("\"") + idxRbc + 14;
if (idxfineRbc < idxRbc || idxRbc < 0) {
System.out.println("ERRORE! ROWBEANCLASS NON TROVATO: " + txtDaConvertire.substring(idxRbc + 9));
} else {
rbc = txtDaConvertire.substring(idxRbc + 14, idxfineRbc);
}
result = String.valueOf(result) + inizioWhile.replace("xxx", rbc);
for (int j = 2; j < 999; j++) {
String riga = getContenutoTr(temp, j);
if (riga.isEmpty())
break;
result = String.valueOf(result) + "<tr>";
int k = 1;
while (true) {
String colonna = getContenutoTd(riga, k);
System.out.println(colonna);
if (!colonna.isEmpty() || k <= 1) {
if (k == 1) {
String id_comandi = "xxx";
int idxGet = colonna.indexOf("rowBean.getId_");
if (idxGet > 0) {
int idxfine = colonna.substring(idxGet + 7).indexOf("(") + idxGet + 9;
if (idxfine < idxGet || idxGet < 0) {
System.out.println("ERRORE! TAG NON CHIUSO: " + colonna.substring(idxGet + 9));
} else {
id_comandi = colonna.substring(idxGet + 14, idxfine);
}
result = String.valueOf(result) + tdComandi.replace("xxx()", id_comandi);
}
} else {
result = String.valueOf(result) + startTd + (String)colonneTh.get(k - 1) + "\">" + colonna + endTd;
}
k++;
if (colonna.isEmpty())
break;
continue;
}
break;
}
result = String.valueOf(result) + endTr;
}
result = String.valueOf(result) + fineWhile;
result = String.valueOf(result) + foot;
result = result.replace("Â", "");
while (result.contains("width=")) {
int idxSize = result.indexOf("width=");
int idxfine = result.substring(idxSize + 7).indexOf("\"") + idxSize + 8;
if (idxfine < idxSize || idxSize < 0) {
System.out.println("ERRORE! width NON CHIUSO: " + result.substring(idxSize + 7));
continue;
}
String size = result.substring(idxSize, idxfine);
result = result.replace(size, " ");
}
return result;
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
}
}
public String convertiTabRicerca(String txtDaConvertire) {
return convertiTabRicercaDettaglio(txtDaConvertire, "ricerca");
}
public String convertiTabDettaglio(String txtDaConvertire) {
return convertiTabRicercaDettaglio(txtDaConvertire, "dettaglio");
}
public String getContenutoTH(String txt, int n) {
int startIdx = -1, endIdx = 0;
for (int i = 0; i < n; i++) {
startIdx = txt.indexOf("<th", startIdx + 1);
if (startIdx < 0)
return "XX_FINE_XX";
}
if (startIdx < 0)
return "XX_FINE_XX";
startIdx = txt.indexOf(">", startIdx + 1) + 1;
endIdx = txt.indexOf("</th>", startIdx);
if (endIdx < startIdx)
return "ERRORE! non trovo chiusura th n." + n + ": " + txt;
String temp = txt.substring(startIdx, endIdx);
return temp;
}
}

View file

@ -0,0 +1,94 @@
package com.ablia.tools;
import com.ablia.util.DbConsole;
import com.ablia.util.FileWr;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
public class MysqlLowerToUppercase extends DbConsole {
private String sqlFileName;
public static void main(String[] args) {
MysqlLowerToUppercase d2b = new MysqlLowerToUppercase();
d2b.converti();
System.out.println("bye");
}
public boolean converti() {
BufferedReader reader = null;
String outputFileName = String.valueOf(getSqlFileName()) + "_up.sql";
new File(outputFileName).delete();
FileWr outputfile = new FileWr(outputFileName);
char delim = '`';
String createTable = "TABLE `";
String lockTable = "LOCK TABLES `";
String insertInto = "INSERT INTO `";
String drop = "DROP TABLE IF EXISTS `";
String references = "REFERENCES `";
try {
reader = new BufferedReader(new FileReader(String.valueOf(getSqlFileName()) +
".sql"));
if (reader != null) {
String currentLine;
while ((currentLine = reader.readLine()) != null) {
if (currentLine.indexOf(createTable) >= 0 ||
currentLine.indexOf(lockTable) >= 0 ||
currentLine.indexOf(insertInto) >= 0 ||
currentLine.indexOf(drop) >= 0 ||
currentLine.indexOf(references) >= 0) {
String currentDelim;
if (currentLine.indexOf(createTable) >= 0) {
currentDelim = createTable;
} else if (currentLine.indexOf(lockTable) >= 0) {
currentDelim = lockTable;
} else if (currentLine.indexOf(insertInto) >= 0) {
currentDelim = insertInto;
} else if (currentLine.indexOf(drop) >= 0) {
currentDelim = drop;
} else if (currentLine.indexOf(references) >= 0) {
currentDelim = references;
} else {
break;
}
int startIdx = currentLine.indexOf(currentDelim) +
currentDelim.length();
int endiIdx = currentLine.substring(startIdx + 1)
.indexOf(delim) +
startIdx + 1;
String table = currentLine.substring(startIdx, endiIdx);
String temp = String.valueOf(currentLine.substring(0, startIdx)) +
table.toUpperCase() +
currentLine.substring(endiIdx);
outputfile.writeLine(temp);
continue;
}
outputfile.writeLine(currentLine);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
reader.close();
outputfile.closeFile();
} catch (Exception e) {
handleDebug(e);
}
}
return true;
}
public void setSqlFileName(String sqlFileName) {
this.sqlFileName = sqlFileName;
}
public String getSqlFileName() {
if (this.sqlFileName == null || this.sqlFileName.equals("")) {
String temp = getCi().readLine("File sql (senza estensione): ");
if (!temp.isEmpty())
this.sqlFileName = temp;
}
return this.sqlFileName;
}
}

View file

@ -0,0 +1,147 @@
package com.ablia.tools;
import com.ablia.db.ResParm;
import com.ablia.util.ConsoleInput;
import com.ablia.util.FileWr;
import com.ablia.util.Vectumerator;
import com.lowagie.tools.ConcatPdf;
import java.io.File;
import java.io.FileFilter;
import java.util.List;
import org.apache.pdfbox.io.MemoryUsageSetting;
import org.apache.pdfbox.multipdf.PDFMergerUtility;
public class PDFMerger extends ConsoleInput {
private Vectumerator inputFileNames;
private String outputFileName;
private FileWr outFile;
public class PdfFilter implements FileFilter {
public boolean accept(File pathname) {
if (pathname.isDirectory())
return true;
String name = pathname.getName().toLowerCase();
return name.toLowerCase().endsWith("pdf");
}
}
public static void main(String[] args) {
PDFMerger p = new PDFMerger();
p.mergePdf();
}
public String getOutputFileName() {
if (this.outputFileName == null) {
this.outputFileName = readLine("Nome file output?: ");
if (!this.outputFileName.endsWith(".pdf"))
this.outputFileName = String.valueOf(this.outputFileName) + ".pdf";
}
return this.outputFileName;
}
public void mergePdf() {
System.out.println("Merge pdf V. 1.0");
String temp = "";
try {
Vectumerator<String> vec;
System.out.println("Premi D per unire in ordine alfabetico i file PDF di una directori:");
System.out.println("Premi F per unire i singoli file PDF:");
temp = readLine("Scegli D o F ?: ");
while (!temp.toLowerCase().equals("d") && !temp.toLowerCase().equals("f"))
temp = readLine("Scegli D o F ?: ");
if (temp.toLowerCase().equals("f")) {
vec = getInputFileNames();
} else {
vec = getDirFileNames();
}
String[] args = new String[vec.getTotNumberOfRecords() + 1];
int i = 0;
while (vec.hasMoreElements()) {
String currentInputFile = vec.nextElement();
args[i] = currentInputFile;
i++;
}
args[i] = getOutputFileName();
ConcatPdf.main(args);
} catch (Exception e) {
e.printStackTrace(System.out);
System.out.println(temp);
}
}
public void setOutputFileName(String outputFileName) {
this.outputFileName = outputFileName;
}
public Vectumerator getDirFileNames() {
if (this.inputFileNames == null) {
this.inputFileNames = new Vectumerator();
String temp = readLine("Dammi la directori contentente tutti i file pdf: ");
File dirTargetDir = new File(temp);
while (!dirTargetDir.isDirectory() || !dirTargetDir.exists()) {
System.out.println("Directori non trovata!!!");
temp = readLine("Dammi la directori contentente tutti i file pdf: ");
}
try {
File[] pdfFiles = dirTargetDir.listFiles(new PdfFilter());
for (int j = 0; j < pdfFiles.length; j++) {
System.out.println("File n. " + (j + 1) + ": " + pdfFiles[j].getCanonicalPath());
this.inputFileNames.addElement(pdfFiles[j].getCanonicalPath());
}
} catch (Exception e) {
e.printStackTrace();
}
}
return this.inputFileNames;
}
public void setInputFileNames(Vectumerator inputFileNames) {
this.inputFileNames = inputFileNames;
}
public FileWr getOutFile() {
if (this.outFile == null)
this.outFile = new FileWr(getOutputFileName(), false);
return this.outFile;
}
public void setOutFile(FileWr outFile) {
this.outFile = outFile;
}
public Vectumerator getInputFileNames() {
if (this.inputFileNames == null) {
this.inputFileNames = new Vectumerator();
int i = 0;
String temp;
while (!(temp = readLine("Dammi il file pdf n. " + i + ": ")).equals("")) {
if (!temp.endsWith(".pdf"))
temp = String.valueOf(temp) + ".pdf";
this.inputFileNames.add(i, temp);
i++;
}
}
return this.inputFileNames;
}
public static ResParm concatenatePdfs(List<File> listOfPdfFiles, File outputFile) {
ResParm rp = new ResParm(true);
try {
PDFMergerUtility ut = new PDFMergerUtility();
String[] args = new String[listOfPdfFiles.size() + 1];
int i = 0;
for (File inFile : listOfPdfFiles) {
ut.addSource(inFile);
args[i] = inFile.getAbsolutePath();
i++;
}
ut.setDestinationFileName(outputFile.getAbsolutePath());
ut.mergeDocuments(MemoryUsageSetting.setupTempFileOnly());
} catch (Exception e) {
return new ResParm(false, e);
}
return rp;
}
}

View file

@ -0,0 +1,43 @@
package com.ablia.tools;
import com.ablia.util.ConsoleInput;
public class SelectPrintPage extends ConsoleInput {
public static void main(String[] args) throws Exception {
SelectPrintPage p = new SelectPrintPage();
p.go();
}
public void go() {
System.out.println("Select Print Page V. 1.0");
String temp = "";
temp = readLine("Numero pagina finale: ");
long pagFinale = Long.parseLong(temp);
System.out.println("Prima Stampa:");
boolean piu3 = true;
int i = -2;
while ((long)i <= pagFinale) {
if (piu3) {
i += 3;
piu3 = false;
} else {
i++;
piu3 = true;
}
System.out.print(String.valueOf(i) + ",");
}
System.out.println("\n\nseconda Stampa:");
piu3 = true;
i = 0;
while ((long)i <= pagFinale) {
if (piu3) {
i += 3;
piu3 = false;
} else {
i++;
piu3 = true;
}
System.out.print(String.valueOf(i) + ",");
}
}
}