Search in sources :

Example 6 with Attributes

use of org.xml.sax.Attributes in project adempiere by adempiere.

the class CodeSnipitElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    String elementValue = element.getElementValue();
    int AD_Backup_ID = -1;
    String Object_Status = null;
    log.info(elementValue);
    Object_Status = "Update";
    Attributes atts = element.attributes;
    String releaseNumber = atts.getValue("ReleaseNo");
    //Check Release Number
    if (Adempiere.MAIN_VERSION.equals(releaseNumber) || releaseNumber.equals("all")) {
        String sourceName = atts.getValue("filename");
        String targetDirectory = atts.getValue("filedir");
        String oldCode = atts.getValue("oldcode");
        String newCode = atts.getValue("newcode");
        int idDetail = 0;
        // Stream for reading from the source file.
        InputStream source;
        // Stream for writing the copy.
        OutputStream copy;
        File currentDirectory = new File(".");
        String packagePath = null;
        String sourcePath = null;
        //get adempiere-all directory
        try {
            packagePath = getPackageDirectory(ctx);
            File parentDirectory = new File(packagePath);
            while (!parentDirectory.getName().equals("packages")) {
                parentDirectory = parentDirectory.getParentFile();
            }
            parentDirectory = parentDirectory.getParentFile();
            sourcePath = parentDirectory.getCanonicalPath();
        } catch (IOException e1) {
            System.out.println("Can't find adempiere-all directory.");
        }
        //	Create backup directory if required
        File backupDir = new File(packagePath + File.separator + "backup" + File.separator);
        if (!backupDir.exists()) {
            boolean success = (new File(packagePath + File.separator + "backup" + File.separator)).mkdirs();
            if (!success) {
                log.info("Backup directory creation failed");
            }
        }
        //Correct target directory for proper file separator
        String fullDirectory = sourcePath + targetDirectory;
        String targetDirectoryModified = null;
        String fileDate = null;
        char slash1 = '\\';
        char slash2 = '/';
        if (File.separator.equals("/"))
            targetDirectoryModified = fullDirectory.replace(slash1, slash2);
        else
            targetDirectoryModified = fullDirectory.replace(slash2, slash1);
        File file = new File(targetDirectoryModified + sourceName);
        log.info(targetDirectoryModified + sourceName);
        //TODO: derived force from user parameter
        boolean force = true;
        //	check to see if overwrites are allowed
        if (file.exists() && force == false) {
            System.out.println("Output file exists.  Use the -f option to replace it.");
            return;
        } else //backup file to package directory
        if (file.exists() && force == true) {
            Object_Status = "Update";
            log.info("Target Backup:" + targetDirectoryModified + sourceName);
            source = OpenInputfile(targetDirectoryModified + sourceName);
            SimpleDateFormat formatter_file = new SimpleDateFormat("yyMMddHHmmssSSSSZ");
            Date today = new Date();
            fileDate = formatter_file.format(today);
            copy = OpenOutputfile(packagePath + File.separator + "backup" + File.separator + fileDate + "_" + sourceName);
            log.info("Source Backup:" + packagePath + File.separator + "backup" + File.separator + fileDate + "_" + sourceName);
            copyFile(source, copy);
            log.info("Backup Complete");
        }
        int success = readReplace(targetDirectoryModified + sourceName, oldCode, newCode);
        //			Record in log
        int idBackup = DB.getNextID(getClientId(ctx), "AD_Package_Imp_Backup", getTrxName(ctx));
        if (success != -1) {
            try {
                idDetail = record_log(ctx, 1, sourceName, "codesnipit", 0, 0, Object_Status, sourceName, 0);
            } catch (SAXException e) {
                log.info("setfile:" + e);
            }
        } else {
            try {
                idDetail = record_log(ctx, 0, sourceName, "codesnipit", 0, 0, Object_Status, sourceName, 0);
            } catch (SAXException e) {
                log.info("setfile:" + e);
            }
        }
        //Record in transaction file 
        StringBuffer sqlB = new StringBuffer("INSERT INTO AD_Package_Imp_Backup").append("(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, ").append("AD_PACKAGE_IMP_BACKUP_ID, AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID,").append(" AD_PACKAGE_IMP_ORG_DIR, AD_PACKAGE_IMP_BCK_DIR)").append("VALUES(").append(" " + Env.getAD_Client_ID(ctx)).append(", " + Env.getAD_Org_ID(ctx)).append(", " + Env.getAD_User_ID(ctx)).append(", " + Env.getAD_User_ID(ctx)).append(", " + idBackup).append(", " + idDetail).append(", " + getPackageImpId(ctx)).append(", '" + targetDirectoryModified + sourceName).append("', '" + packagePath + File.separator + "backup" + File.separator + fileDate + "_" + sourceName).append("')");
        int no = DB.executeUpdate(sqlB.toString(), getTrxName(ctx));
        if (no == -1)
            log.info("Insert to import backup failed");
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Attributes(org.xml.sax.Attributes) IOException(java.io.IOException) Date(java.util.Date) SAXException(org.xml.sax.SAXException) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

Example 7 with Attributes

use of org.xml.sax.Attributes in project adempiere by adempiere.

the class CommonTranslationHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    if (!MSysConfig.getBooleanValue("2PACK_HANDLE_TRANSLATIONS", false)) {
        //translation import option is disabled
        return;
    }
    if (element.parent.skip) {
        return;
    }
    if (element.parent.defer) {
        element.defer = true;
        return;
    }
    String elementValue = element.getElementValue();
    Attributes atts = element.attributes;
    int parentID = element.parent.recordId;
    if (parentID == 0)
        throw new SAXException();
    String parentTable = atts.getValue(SPECIAL_ATRRIBUTE__TABLE_NAME);
    String language = atts.getValue("AD_Language");
    log.info(elementValue + " " + parentTable + " " + atts.getValue("Name"));
    if (isRecordExists(parentTable, parentID, language, ctx)) {
        updateTranslation(parentTable, parentID, ctx, atts);
    } else {
        insertTranslation(parentTable, parentID, ctx, atts);
    }
}
Also used : Attributes(org.xml.sax.Attributes) SAXException(org.xml.sax.SAXException)

Example 8 with Attributes

use of org.xml.sax.Attributes in project adempiere by adempiere.

the class MenuElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    String elementValue = element.getElementValue();
    int AD_Backup_ID = -1;
    String Object_Status = null;
    Attributes atts = element.attributes;
    log.info(elementValue + " " + atts.getValue("ADMenuNameID"));
    // String entitytype = atts.getValue("EntityType");
    // if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0
    // && m_UpdateMode == true ) {
    String name = null;
    int idDetail = 0;
    StringBuffer sqlB = null;
    name = atts.getValue("ADMenuNameID");
    int menuid = get_IDWithColumn(ctx, "AD_Menu", "Name", name);
    X_AD_Menu m_Menu = new X_AD_Menu(ctx, menuid, getTrxName(ctx));
    if (menuid <= 0 && atts.getValue("AD_Menu_ID") != null && Integer.parseInt(atts.getValue("AD_Menu_ID")) <= PackOut.MAX_OFFICIAL_ID)
        m_Menu.setAD_Menu_ID(Integer.parseInt(atts.getValue("AD_Menu_ID")));
    if (menuid > 0) {
        AD_Backup_ID = copyRecord(ctx, "AD_Menu", m_Menu);
        Object_Status = "Update";
    } else {
        Object_Status = "New";
        AD_Backup_ID = 0;
    }
    m_Menu.setName(name);
    name = atts.getValue("ADWindowNameID");
    if (name != null && name.trim().length() > 0) {
        int id = get_IDWithColumn(ctx, "AD_Window", "Name", name);
        if (id <= 0) {
            element.defer = true;
            return;
        }
        m_Menu.setAD_Window_ID(id);
    }
    name = atts.getValue("ADProcessNameID");
    if (name != null && name.trim().length() > 0) {
        int id = get_IDWithColumn(ctx, "AD_Process", "Name", name);
        if (id <= 0) {
            element.defer = true;
            return;
        }
        m_Menu.setAD_Process_ID(id);
    }
    name = atts.getValue("ADFormNameID");
    if (name != null && name.trim().length() > 0) {
        int id = get_IDWithColumn(ctx, "AD_Form", "Name", name);
        if (id <= 0) {
            element.defer = true;
            return;
        }
        m_Menu.setAD_Form_ID(id);
    }
    name = atts.getValue("ADBrowseNameID");
    if (name != null && name.trim().length() > 0) {
        int id = get_IDWithColumn(ctx, "AD_Browse", "Name", name);
        if (id <= 0) {
            element.defer = true;
            return;
        }
        m_Menu.setAD_Browse_ID(id);
    }
    name = atts.getValue("ADTaskNameID");
    if (name != null && name.trim().length() > 0) {
        int id = get_IDWithColumn(ctx, "AD_Task", "Name", name);
        if (id <= 0) {
            element.defer = true;
            return;
        }
        m_Menu.setAD_Task_ID(id);
    }
    name = atts.getValue("ADWorkbenchNameID");
    if (name != null && name.trim().length() > 0) {
        int id = get_IDWithColumn(ctx, "AD_Workbench", "Name", name);
        if (id <= 0) {
            element.defer = true;
            return;
        }
        m_Menu.setAD_Workbench_ID(id);
    }
    name = atts.getValue("ADWorkflowNameID");
    if (name != null && name.trim().length() > 0) {
        int id = get_IDWithColumn(ctx, "AD_Workflow", "Name", name);
        if (id <= 0) {
            element.defer = true;
            return;
        }
        m_Menu.setAD_Workflow_ID(id);
    }
    String action = (atts.getValue("Action") != null ? atts.getValue("Action") : " ");
    if (action.compareTo(" ") > -1)
        m_Menu.setAction(action);
    m_Menu.setDescription(getStringValue(atts, "Description"));
    m_Menu.setEntityType(atts.getValue("EntityType"));
    m_Menu.setIsReadOnly(Boolean.valueOf(atts.getValue("isReadOnly")).booleanValue());
    m_Menu.setIsSOTrx(Boolean.valueOf(atts.getValue("isSOTrx")).booleanValue());
    m_Menu.setIsSummary(Boolean.valueOf(atts.getValue("isSummary")).booleanValue());
    m_Menu.setIsActive(Boolean.valueOf(atts.getValue("isActive")).booleanValue());
    if (m_Menu.save(getTrxName(ctx)) == true) {
        try {
            idDetail = record_log(ctx, 1, m_Menu.getName(), "Menu", m_Menu.get_ID(), AD_Backup_ID, Object_Status, "AD_Menu", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Menu"));
        } catch (SAXException e) {
            log.info("setmenu:" + e);
        }
    } else {
        try {
            idDetail = record_log(ctx, 0, m_Menu.getName(), "Menu", m_Menu.get_ID(), AD_Backup_ID, Object_Status, "AD_Menu", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Menu"));
        } catch (SAXException e) {
            log.info("setmenu:" + e);
        }
    }
    name = atts.getValue("ADParentMenuNameID");
    int id = get_ID(ctx, "AD_Menu", name);
    String sql2 = "SELECT count(Parent_ID) FROM AD_TREENODEMM WHERE AD_Tree_ID = 10" + " AND Node_ID = " + menuid;
    int countRecords = DB.getSQLValue(getTrxName(ctx), sql2);
    if (countRecords > 0) {
        StringBuffer sqlC = new StringBuffer("select * from AD_TREENODEMM where AD_Tree_ID = 10 and " + " Node_ID =?");
        try {
            PreparedStatement pstmt1 = DB.prepareStatement(sqlC.toString(), getTrxName(ctx));
            pstmt1.setInt(1, menuid);
            ResultSet rs1 = pstmt1.executeQuery();
            if (rs1.next()) {
                String colValue = null;
                ResultSetMetaData meta = rs1.getMetaData();
                int columns = meta.getColumnCount();
                int tableID = get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_TreeNodeMM");
                for (int q = 1; q <= columns; q++) {
                    String col_Name = meta.getColumnName(q);
                    StringBuffer sql = new StringBuffer("SELECT AD_Column_ID FROM AD_column WHERE Upper(ColumnName) = '" + col_Name + "' AND AD_Table_ID = ?");
                    int columnID = DB.getSQLValue(getTrxName(ctx), sql.toString(), tableID);
                    sql = new StringBuffer("SELECT AD_Reference_ID FROM AD_COLUMN WHERE AD_Column_ID = " + (columnID == -1 ? "null" : columnID));
                    int referenceID = DB.getSQLValue(getTrxName(ctx), sql.toString());
                    int idBackup = DB.getNextID(Env.getAD_Client_ID(ctx), "AD_Package_Imp_Backup", getTrxName(ctx));
                    if (referenceID == 20 || referenceID == 28)
                        if (rs1.getObject(q).equals("Y"))
                            colValue = "true";
                        else
                            colValue = "false";
                    else
                        colValue = rs1.getObject(q).toString();
                    StringBuffer sqlD = new StringBuffer("INSERT INTO AD_Package_Imp_Backup" + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " + "AD_PACKAGE_IMP_BACKUP_ID, AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID," + " AD_TABLE_ID, AD_COLUMN_ID, AD_REFERENCE_ID, COLVALUE)" + "VALUES(" + " " + Env.getAD_Client_ID(ctx) + ", " + Env.getAD_Org_ID(ctx) + ", " + Env.getAD_User_ID(ctx) + ", " + Env.getAD_User_ID(ctx) + ", " + idBackup + ", " + idDetail + ", " + getPackageImpId(ctx) + ", " + tableID + ", " + (columnID == -1 ? "null" : columnID) + ", " + (referenceID == -1 ? "null" : referenceID) + ", '" + colValue + "')");
                    int no = DB.executeUpdate(sqlD.toString(), getTrxName(ctx));
                    if (no == -1)
                        log.info("Insert to import backup failed");
                }
            }
            rs1.close();
            pstmt1.close();
            pstmt1 = null;
        } catch (Exception e) {
            log.info("get_IDWithMasterID:" + e);
        }
        MTree tree = new MTree(ctx, 10, getTrxName(ctx));
        MTree_NodeMM treeNode = MTree_NodeMM.get(tree, m_Menu.getAD_Menu_ID());
        treeNode.setSeqNo(Integer.valueOf(atts.getValue("ADParentSeqno")));
        treeNode.set_CustomColumn("Parent_ID", id);
        treeNode.saveEx();
    } else {
        MTree tree = new MTree(ctx, 10, getTrxName(ctx));
        MTree_NodeMM treeNode = new MTree_NodeMM(tree, m_Menu.getAD_Menu_ID());
        treeNode.setSeqNo(Integer.valueOf(atts.getValue("ADParentSeqno")));
        treeNode.set_CustomColumn("Parent_ID", id);
        treeNode.setNode_ID(m_Menu.getAD_Menu_ID());
        treeNode.saveEx();
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) X_AD_Menu(org.compiere.model.X_AD_Menu) Attributes(org.xml.sax.Attributes) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) MTree(org.compiere.model.MTree) MTree_NodeMM(org.compiere.model.MTree_NodeMM)

Example 9 with Attributes

use of org.xml.sax.Attributes in project adempiere by adempiere.

the class EntityTypeElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    final String elementValue = element.getElementValue();
    final Attributes atts = element.attributes;
    final String entitytype = atts.getValue(I_AD_EntityType.COLUMNNAME_EntityType);
    log.info(elementValue + " " + entitytype);
    if (isProcessElement(ctx, entitytype)) {
        int id = get_IDWithColumn(ctx, I_AD_EntityType.Table_Name, I_AD_EntityType.COLUMNNAME_EntityType, entitytype);
        final MEntityType entity = new MEntityType(ctx, id, getTrxName(ctx));
        final int AD_Backup_ID;
        final String Object_Status;
        if (id <= 0 && getIntValue(atts, I_AD_EntityType.COLUMNNAME_AD_EntityType_ID, 0) <= PackOut.MAX_OFFICIAL_ID) {
            entity.setAD_EntityType_ID(getIntValue(atts, I_AD_EntityType.COLUMNNAME_AD_EntityType_ID, 0));
        }
        if (id > 0) {
            AD_Backup_ID = copyRecord(ctx, I_AD_EntityType.Table_Name, entity);
            Object_Status = "Update";
        } else {
            Object_Status = "New";
            AD_Backup_ID = 0;
        }
        entity.setName(getStringValue(atts, I_AD_EntityType.COLUMNNAME_Name));
        entity.setDescription(getStringValue(atts, I_AD_EntityType.COLUMNNAME_Description));
        entity.setHelp(getStringValue(atts, I_AD_EntityType.COLUMNNAME_Help));
        entity.setEntityType(getStringValue(atts, I_AD_EntityType.COLUMNNAME_EntityType));
        entity.setVersion(atts.getValue(I_AD_EntityType.COLUMNNAME_Version));
        entity.setIsActive(getBooleanValue(atts, I_AD_EntityType.COLUMNNAME_IsActive, true));
        entity.setModelPackage(getStringValue(atts, I_AD_EntityType.COLUMNNAME_ModelPackage));
        entity.setClasspath(getStringValue(atts, I_AD_EntityType.COLUMNNAME_Classpath));
        if (entity.save(getTrxName(ctx)) == true) {
            record_log(ctx, 1, entity.getEntityType(), TAG_Name, entity.get_ID(), AD_Backup_ID, Object_Status, I_AD_EntityType.Table_Name, I_AD_EntityType.Table_ID);
        } else {
            record_log(ctx, 0, entity.getEntityType(), TAG_Name, entity.get_ID(), AD_Backup_ID, Object_Status, I_AD_EntityType.Table_Name, I_AD_EntityType.Table_ID);
            throw new POSaveFailedException("Failed to save message.");
        }
    } else {
        element.skip = true;
    }
}
Also used : Attributes(org.xml.sax.Attributes) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) MEntityType(org.compiere.model.MEntityType)

Example 10 with Attributes

use of org.xml.sax.Attributes in project adempiere by adempiere.

the class FieldElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    final String include_tabname = element.attributes.getValue("ADIncludeTabNameID");
    // Set Included Tab ID if this task was previously postponed 
    if (element.defer && element.recordId > 0 && include_tabname != null) {
        MField field = new MField(ctx, element.recordId, getTrxName(ctx));
        setIncluded_Tab_ID(ctx, field, include_tabname);
        field.saveEx();
        return;
    }
    PackIn packIn = (PackIn) ctx.get("PackInProcess");
    String elementValue = element.getElementValue();
    Attributes atts = element.attributes;
    log.info(elementValue + " " + atts.getValue("Name"));
    String entitytype = atts.getValue("EntityType");
    if (isProcessElement(ctx, entitytype)) {
        if (element.parent != null && element.parent.getElementValue().equals("tab") && element.parent.defer) {
            element.defer = true;
            return;
        }
        String name = atts.getValue("Name");
        String tabname = atts.getValue("ADTabNameID");
        String colname = atts.getValue("ADColumnNameID");
        String tableName = atts.getValue("ADTableNameID");
        int tableid = packIn.getTableId(tableName);
        if (tableid <= 0) {
            tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName);
            if (tableid > 0)
                packIn.addTable(tableName, tableid);
        }
        if (tableid <= 0) {
            element.defer = true;
            return;
        }
        int windowid = get_ID(ctx, "AD_Window", atts.getValue("ADWindowNameID"));
        if (windowid <= 0) {
            element.defer = true;
            return;
        }
        int columnid = packIn.getColumnId(tableName, colname);
        if (columnid <= 0) {
            columnid = get_IDWithMasterAndColumn(ctx, "AD_Column", "ColumnName", colname, "AD_Table", tableid);
            if (columnid > 0)
                packIn.addColumn(tableName, colname, columnid);
        }
        if (columnid <= 0) {
            element.defer = true;
            return;
        }
        int tabid = 0;
        if (element.parent != null && element.parent.getElementValue().equals("tab") && element.parent.recordId > 0) {
            tabid = element.parent.recordId;
        } else {
            StringBuffer sqlB = new StringBuffer("select AD_Tab_ID from AD_Tab where AD_Window_ID = " + windowid).append(" and Name = '" + tabname + "'").append(" and AD_Table_ID = ?");
            tabid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), tableid);
            if (element.parent != null && element.parent.getElementValue().equals("tab") && tabid > 0) {
                element.parent.recordId = tabid;
            }
        }
        if (tabid > 0) {
            StringBuffer sqlB = new StringBuffer("select AD_Field_ID from AD_Field where AD_Column_ID = ").append(columnid).append(" and AD_Tab_ID = ?");
            int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), tabid);
            final MField m_Field = new MField(ctx, id, getTrxName(ctx));
            if (id <= 0 && atts.getValue("AD_Field_ID") != null && Integer.parseInt(atts.getValue("AD_Field_ID")) <= PackOut.MAX_OFFICIAL_ID)
                m_Field.setAD_Field_ID(Integer.parseInt(atts.getValue("AD_Field_ID")));
            int AD_Backup_ID = -1;
            String Object_Status = null;
            if (id > 0) {
                AD_Backup_ID = copyRecord(ctx, "AD_Field", m_Field);
                Object_Status = "Update";
            } else {
                Object_Status = "New";
                AD_Backup_ID = 0;
            }
            m_Field.setName(atts.getValue("Name"));
            m_Field.setAD_Column_ID(columnid);
            name = atts.getValue("ADFieldGroupNameID");
            id = get_IDWithColumn(ctx, "AD_FieldGroup", "Name", name);
            m_Field.setAD_FieldGroup_ID(id);
            m_Field.setAD_Tab_ID(tabid);
            m_Field.setEntityType(atts.getValue("EntityType"));
            m_Field.setIsSameLine(Boolean.valueOf(atts.getValue("SameLine")).booleanValue());
            m_Field.setIsCentrallyMaintained(Boolean.valueOf(atts.getValue("isCentrallyMaintained")).booleanValue());
            m_Field.setIsDisplayed(Boolean.valueOf(atts.getValue("Displayed")).booleanValue());
            // m_Field.setIsEncrypted(Boolean.valueOf(atts.getValue("isEncrypted")).booleanValue());
            m_Field.setIsFieldOnly(Boolean.valueOf(atts.getValue("isFieldOnly")).booleanValue());
            m_Field.setIsHeading(Boolean.valueOf(atts.getValue("isHeading")).booleanValue());
            m_Field.setIsReadOnly(Boolean.valueOf(atts.getValue("isReadOnly")).booleanValue());
            m_Field.setSeqNo(Integer.parseInt(atts.getValue("SeqNo")));
            m_Field.setDisplayLength(Integer.parseInt(atts.getValue("DisplayLength")));
            m_Field.setDescription(getStringValue(atts, "Description"));
            m_Field.setHelp(getStringValue(atts, "Help"));
            m_Field.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
            String sortNo = getStringValue(atts, "SortNo");
            if (sortNo != null)
                m_Field.setSortNo(new BigDecimal(sortNo));
            m_Field.setDisplayLogic(getStringValue(atts, "DisplayLogic"));
            String Name = atts.getValue("ADReferenceNameID");
            id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
            m_Field.setAD_Reference_ID(id);
            Name = atts.getValue("ADValRuleNameID");
            id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", Name);
            m_Field.setAD_Val_Rule_ID(id);
            Name = atts.getValue("ADReferenceNameValueID");
            id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
            m_Field.setAD_Reference_Value_ID(id);
            m_Field.setInfoFactoryClass(getStringValue(atts, "InfoFactoryClass"));
            if ("Y".equals(atts.getValue("isMandatory")))
                m_Field.setIsMandatory(atts.getValue("isMandatory"));
            else if ("N".equals(atts.getValue("isMandatory")))
                m_Field.setIsMandatory(atts.getValue("isMandatory"));
            m_Field.setDefaultValue(atts.getValue("DefaultValue"));
            if (atts.getValue("IsDisplayedGrid") != null)
                m_Field.setIsDisplayedGrid(Boolean.valueOf(atts.getValue("IsDisplayedGrid")).booleanValue());
            if (atts.getValue("PreferredWidth") != null)
                m_Field.setPreferredWidth(Integer.parseInt(atts.getValue("PreferredWidth")));
            setIncluded_Tab_ID(ctx, m_Field, include_tabname);
            if (m_Field.save(getTrxName(ctx)) == true) {
                record_log(ctx, 1, m_Field.getName(), "Field", m_Field.get_ID(), AD_Backup_ID, Object_Status, "AD_Field", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Field"));
                element.recordId = m_Field.getAD_Field_ID();
            } else {
                record_log(ctx, 0, m_Field.getName(), "Field", m_Field.get_ID(), AD_Backup_ID, Object_Status, "AD_Field", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Field"));
                throw new POSaveFailedException("Failed to save field definition.");
            }
            // If Included Tab not found, then postpone this task for later processing 
            if (m_Field.getAD_Field_ID() > 0 && include_tabname != null && m_Field.getIncluded_Tab_ID() <= 0) {
                element.defer = true;
            }
        } else {
            element.defer = true;
            return;
        }
    } else {
        element.skip = true;
    }
}
Also used : PackIn(org.adempiere.pipo.PackIn) Attributes(org.xml.sax.Attributes) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) MField(org.compiere.model.MField) BigDecimal(java.math.BigDecimal)

Aggregations

Attributes (org.xml.sax.Attributes)274 DefaultHandler (org.xml.sax.helpers.DefaultHandler)70 SAXException (org.xml.sax.SAXException)66 Test (org.junit.Test)59 AttributesImpl (org.xml.sax.helpers.AttributesImpl)50 SAXParser (javax.xml.parsers.SAXParser)48 POSaveFailedException (org.adempiere.pipo.exception.POSaveFailedException)37 InputSource (org.xml.sax.InputSource)31 SAXParserFactory (javax.xml.parsers.SAXParserFactory)30 IOException (java.io.IOException)29 File (java.io.File)22 ByteArrayInputStream (java.io.ByteArrayInputStream)19 ArrayList (java.util.ArrayList)17 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)17 InputStream (java.io.InputStream)16 ContentHandler (org.xml.sax.ContentHandler)15 XMLReader (org.xml.sax.XMLReader)15 StringReader (java.io.StringReader)10 Transformer (org.apache.sling.rewriter.Transformer)10 MockBundle (org.apache.sling.commons.testing.osgi.MockBundle)9