Search in sources :

Example 31 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project checkstyle by checkstyle.

the class ImportControlLoaderTest method testSafeGetThrowsException.

@Test
public // UT uses Reflection to avoid removing null-validation from static method
void testSafeGetThrowsException() throws Exception {
    final AttributesImpl attr = new AttributesImpl() {

        @Override
        public String getValue(int index) {
            return null;
        }
    };
    try {
        final Class<?> clazz = ImportControlLoader.class;
        final Method privateMethod = clazz.getDeclaredMethod("safeGet", Attributes.class, String.class);
        privateMethod.setAccessible(true);
        privateMethod.invoke(null, attr, "you_cannot_find_me");
        fail("exception expected");
    } catch (InvocationTargetException ex) {
        assertSame(SAXException.class, ex.getCause().getClass());
        assertEquals("missing attribute you_cannot_find_me", ex.getCause().getMessage());
    }
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) SAXException(org.xml.sax.SAXException) Test(org.junit.Test)

Example 32 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project intellij-community by JetBrains.

the class TestResultsXmlFormatter method startElement.

private void startElement(String name, Map<String, String> attributes) throws SAXException {
    AttributesImpl attrs = new AttributesImpl();
    for (Map.Entry<String, String> entry : attributes.entrySet()) {
        attrs.addAttribute("", entry.getKey(), entry.getKey(), "CDATA", entry.getValue());
    }
    myResultHandler.startElement("", name, name, attrs);
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl)

Example 33 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project WordPress-Android by wordpress-mobile.

the class WPHtmlTest method testStartImg.

// This test failed before #685 was fixed (throws a InvocationTargetException)
public void testStartImg() throws NoSuchMethodException, IllegalAccessException {
    SpannableStringBuilder text = new SpannableStringBuilder();
    Attributes attributes = new AttributesImpl();
    HtmlToSpannedConverter converter = new HtmlToSpannedConverter(null, null, null, null, null, null, 0);
    // startImg is private, we use reflection to change accessibility and invoke it from here
    Method method = HtmlToSpannedConverter.class.getDeclaredMethod("startImg", SpannableStringBuilder.class, Attributes.class, WPHtml.ImageGetter.class);
    method.setAccessible(true);
    try {
        method.invoke(converter, text, attributes, null);
    } catch (InvocationTargetException e) {
        assertTrue("startImg failed see #685", false);
    }
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Attributes(org.xml.sax.Attributes) Method(java.lang.reflect.Method) SpannableStringBuilder(android.text.SpannableStringBuilder) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 34 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project adempiere by adempiere.

the class PackInHandler method startElement.

/**
     * 	Receive notification of the start of an element.
     *
     * 	@param uri namespace
     * 	@param localName simple name
     * 	@param qName qualified name
     * 	@param atts attributes
     * 	@throws org.xml.sax.SAXException
     */
public void startElement(String uri, String localName, String qName, Attributes atts) throws org.xml.sax.SAXException {
    // Create the package log    	
    if (Start_Doc == 0) {
        init();
    }
    // Check namespace.
    String elementValue = null;
    if ("".equals(uri))
        elementValue = qName;
    else
        elementValue = uri + localName;
    // adempiereAD.	
    if (elementValue.equals("adempiereAD")) {
        log.info("adempiereAD updateMode=" + m_UpdateMode);
        //Start package log
        AttributesImpl attsOut = new AttributesImpl();
        logDocument.startElement("", "", "adempiereDocument", attsOut);
        logDocument.startElement("", "", "header", attsOut);
        logDocument.characters((atts.getValue("Name") + " Install Log").toCharArray(), 0, (atts.getValue("Name") + " Install Log").length());
        logDocument.endElement("", "", "header");
        logDocument.startElement("", "", "H3", attsOut);
        logDocument.characters(("Package Name:").toCharArray(), 0, ("Package Name:").length());
        logDocument.endElement("", "", "H3");
        logDocument.startElement("", "", "packagename4log", attsOut);
        logDocument.characters(atts.getValue("Name").toCharArray(), 0, atts.getValue("Name").length());
        logDocument.endElement("", "", "packagename4log");
        logDocument.startElement("", "", "H3", attsOut);
        logDocument.characters(("Version:").toCharArray(), 0, ("Version:").length());
        logDocument.endElement("", "", "H3");
        logDocument.startElement("", "", "Version", attsOut);
        logDocument.characters(atts.getValue("Version").toCharArray(), 0, atts.getValue("Version").length());
        logDocument.endElement("", "", "Version");
        logDocument.startElement("", "", "H3", attsOut);
        logDocument.characters(("Package Install Date:").toCharArray(), 0, ("Package Install Date:").length());
        logDocument.endElement("", "", "H3");
        logDocument.startElement("", "", "installDate", attsOut);
        logDocument.characters(logDate.toCharArray(), 0, logDate.length());
        logDocument.endElement("", "", "installDate");
        logDocument.startElement("", "", "H3", attsOut);
        logDocument.characters(("Min. Compiere Version:").toCharArray(), 0, ("Min. Compiere Version:").length());
        logDocument.endElement("", "", "H3");
        logDocument.startElement("", "", "CompVer", attsOut);
        logDocument.characters(atts.getValue("CompVer").toCharArray(), 0, atts.getValue("CompVer").length());
        logDocument.endElement("", "", "CompVer");
        logDocument.startElement("", "", "H3", attsOut);
        logDocument.characters(("Min. Database Date:").toCharArray(), 0, ("Min. Database Date:").length());
        logDocument.endElement("", "", "H3");
        logDocument.startElement("", "", "DataBase", attsOut);
        logDocument.characters(atts.getValue("DataBase").toCharArray(), 0, atts.getValue("DataBase").length());
        logDocument.endElement("", "", "DataBase");
        createImp_Sum_table("AD_Package_Imp_Backup");
        createImp_Sum_table("AD_Package_Imp");
        createImp_Sum_table("AD_Package_Imp_Inst");
        createImp_Sum_table("AD_Package_Imp_Detail");
        // Update Summary Package History Table
        String sql2 = "SELECT AD_PACKAGE_IMP_INST_ID FROM AD_PACKAGE_IMP_INST WHERE NAME =" + "'" + atts.getValue("Name") + "' AND PK_VERSION ='" + atts.getValue("Version") + "'";
        int PK_preInstalled = DB.getSQLValue(m_trxName, sql2);
        AD_Package_Imp_ID = DB.getNextID(Env.getAD_Client_ID(m_ctx), "AD_Package_Imp", null);
        StringBuffer sqlB = new StringBuffer("INSERT INTO AD_Package_Imp").append("(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, ").append("AD_PACKAGE_IMP_ID, RELEASENO, PK_VERSION, VERSION ").append(", DESCRIPTION, NAME, CREATOR").append(", CREATORCONTACT, CREATEDDATE,UPDATEDDATE,PK_STATUS)").append("VALUES(").append(" " + Env.getAD_Client_ID(m_ctx)).append(", " + Env.getAD_Org_ID(m_ctx)).append(", " + Env.getAD_User_ID(m_ctx)).append(", " + Env.getAD_User_ID(m_ctx)).append(", " + AD_Package_Imp_ID).append(", '" + atts.getValue("CompVer")).append("', '" + atts.getValue("Version")).append("', '" + atts.getValue("DataBase")).append("', '" + atts.getValue("Description").replaceAll("'", "''")).append("', '" + atts.getValue("Name")).append("', '" + atts.getValue("creator")).append("', '" + atts.getValue("creatorcontact")).append("', '" + atts.getValue("createddate")).append("', '" + atts.getValue("updateddate")).append("', '" + PK_Status).append("')");
        Env.getAD_User_ID(m_ctx);
        int no = DB.executeUpdate(sqlB.toString(), m_trxName);
        if (no == -1)
            log.info("Insert to Package import failed");
        if (PK_preInstalled == -1) {
            AD_Package_Imp_Inst_ID = DB.getNextID(Env.getAD_Client_ID(m_ctx), "AD_Package_Imp_Inst", null);
            //Insert Package into package install log
            sqlB = new StringBuffer("INSERT INTO AD_Package_Imp_Inst").append("(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, ").append("AD_PACKAGE_IMP_INST_ID, RELEASENO, PK_VERSION, VERSION ").append(", DESCRIPTION, NAME, CREATOR").append(", CREATORCONTACT, CREATEDDATE,UPDATEDDATE,PK_STATUS)").append("VALUES(").append(" " + Env.getAD_Client_ID(m_ctx)).append(", " + Env.getAD_Org_ID(m_ctx)).append(", " + Env.getAD_User_ID(m_ctx)).append(", " + Env.getAD_User_ID(m_ctx)).append(", " + AD_Package_Imp_Inst_ID).append(", '" + atts.getValue("CompVer")).append("', '" + atts.getValue("Version")).append("', '" + atts.getValue("DataBase")).append("', '" + atts.getValue("Description").replaceAll("'", "''")).append("', '" + atts.getValue("Name")).append("', '" + atts.getValue("creator")).append("', '" + atts.getValue("creatorcontact")).append("', '" + atts.getValue("createddate")).append("', '" + atts.getValue("updateddate")).append("', '" + PK_Status).append("')");
            Env.getAD_User_ID(m_ctx);
            no = DB.executeUpdate(sqlB.toString(), m_trxName);
            if (no == -1)
                log.info("Insert to Package List import failed");
        } else {
            //Update package list with package status
            AD_Package_Imp_Inst_ID = PK_preInstalled;
            sqlB = new StringBuffer("UPDATE AD_Package_Imp_Inst " + "SET PK_Status = '" + PK_Status + "' WHERE AD_Package_Imp_Inst_ID = " + AD_Package_Imp_Inst_ID);
            no = DB.executeUpdate(sqlB.toString(), m_trxName);
            if (no == -1)
                log.info("Update to package summary failed");
        }
        Env.setContext(m_ctx, "AD_Package_Imp_ID", AD_Package_Imp_ID);
        Env.setContext(m_ctx, "UpdateMode", m_UpdateMode);
        Env.setContext(m_ctx, "TrxName", m_trxName);
        Env.setContext(m_ctx, "PackageDirectory", packageDirectory);
        m_ctx.put("LogDocument", logDocument);
        m_ctx.put("PackInProcess", packIn);
    } else if (elementValue.equals("menu")) {
        //defer
        Element e = new Element(uri, localName, qName, new AttributesImpl(atts));
        if (stack.size() > 0)
            e.parent = stack.peek();
        stack.push(e);
        menus.add(e);
    } else {
        Element e = new Element(uri, localName, qName, new AttributesImpl(atts));
        if (stack.size() > 0)
            e.parent = stack.peek();
        stack.push(e);
        if (elementValue.equals("workflow")) {
            workflow.add(e);
        }
        if (elementValue.equals("workflowNode")) {
            nodes.add(e);
        }
        ElementHandler handler = handlers.get(elementValue);
        if (handler != null)
            handler.startElement(m_ctx, e);
        if (e.defer) {
            defer.add(new DeferEntry(e, true));
        }
    }
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) ProcessElementHandler(org.adempiere.pipo.handler.ProcessElementHandler) UserRoleElementHandler(org.adempiere.pipo.handler.UserRoleElementHandler) PrintFormatItemElementHandler(org.adempiere.pipo.handler.PrintFormatItemElementHandler) WindowElementHandler(org.adempiere.pipo.handler.WindowElementHandler) RoleElementHandler(org.adempiere.pipo.handler.RoleElementHandler) FormElementHandler(org.adempiere.pipo.handler.FormElementHandler) TabElementHandler(org.adempiere.pipo.handler.TabElementHandler) FieldElementHandler(org.adempiere.pipo.handler.FieldElementHandler) ModelValidatorElementHandler(org.adempiere.pipo.handler.ModelValidatorElementHandler) ReportViewColElementHandler(org.adempiere.pipo.handler.ReportViewColElementHandler) ViewColumnElementHandler(org.adempiere.pipo.handler.ViewColumnElementHandler) DataElementHandler(org.adempiere.pipo.handler.DataElementHandler) PreferenceElementHandler(org.adempiere.pipo.handler.PreferenceElementHandler) ReportViewElementHandler(org.adempiere.pipo.handler.ReportViewElementHandler) WorkflowNodeNextElementHandler(org.adempiere.pipo.handler.WorkflowNodeNextElementHandler) ViewDefinitionElementHandler(org.adempiere.pipo.handler.ViewDefinitionElementHandler) DistFileElementHandler(org.adempiere.pipo.handler.DistFileElementHandler) ImpFormatRowElementHandler(org.adempiere.pipo.handler.ImpFormatRowElementHandler) EntityTypeElementHandler(org.adempiere.pipo.handler.EntityTypeElementHandler) MenuElementHandler(org.adempiere.pipo.handler.MenuElementHandler) WorkflowElementHandler(org.adempiere.pipo.handler.WorkflowElementHandler) WorkflowNodeElementHandler(org.adempiere.pipo.handler.WorkflowNodeElementHandler) WindowAccessElementHandler(org.adempiere.pipo.handler.WindowAccessElementHandler) ImpFormatElementHandler(org.adempiere.pipo.handler.ImpFormatElementHandler) ReferenceTableElementHandler(org.adempiere.pipo.handler.ReferenceTableElementHandler) ReferenceListElementHandler(org.adempiere.pipo.handler.ReferenceListElementHandler) AdElementHandler(org.adempiere.pipo.handler.AdElementHandler) PrintFormatElementHandler(org.adempiere.pipo.handler.PrintFormatElementHandler) TaskAccessElementHandler(org.adempiere.pipo.handler.TaskAccessElementHandler) ViewElementHandler(org.adempiere.pipo.handler.ViewElementHandler) ProcessAccessElementHandler(org.adempiere.pipo.handler.ProcessAccessElementHandler) BrowseFieldElementHandler(org.adempiere.pipo.handler.BrowseFieldElementHandler) TableElementHandler(org.adempiere.pipo.handler.TableElementHandler) MessageElementHandler(org.adempiere.pipo.handler.MessageElementHandler) OrgRoleElementHandler(org.adempiere.pipo.handler.OrgRoleElementHandler) FormAccessElementHandler(org.adempiere.pipo.handler.FormAccessElementHandler) SQLStatementElementHandler(org.adempiere.pipo.handler.SQLStatementElementHandler) WorkflowAccessElementHandler(org.adempiere.pipo.handler.WorkflowAccessElementHandler) ColumnElementHandler(org.adempiere.pipo.handler.ColumnElementHandler) DynValRuleElementHandler(org.adempiere.pipo.handler.DynValRuleElementHandler) TaskElementHandler(org.adempiere.pipo.handler.TaskElementHandler) PrintPaperElementHandler(org.adempiere.pipo.handler.PrintPaperElementHandler) ReferenceElementHandler(org.adempiere.pipo.handler.ReferenceElementHandler) BrowseElementHandler(org.adempiere.pipo.handler.BrowseElementHandler) WorkflowNodeNextConditionElementHandler(org.adempiere.pipo.handler.WorkflowNodeNextConditionElementHandler) FieldGroupElementHandler(org.adempiere.pipo.handler.FieldGroupElementHandler) CodeSnipitElementHandler(org.adempiere.pipo.handler.CodeSnipitElementHandler) ProcessParaElementHandler(org.adempiere.pipo.handler.ProcessParaElementHandler)

Example 35 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project adempiere by adempiere.

the class PackOut method doIt.

//	prepare
/**
	 * 	Start the transformation to XML
	 *	@return info
	 *	@throws Exception
	 */
protected String doIt() throws java.lang.Exception {
    initContext();
    OutputStream packageDocStream = null;
    OutputStream packOutDocStream = null;
    log.info("doIt - AD_PACKAGE_EXP_ID=" + p_PackOut_ID);
    if (p_PackOut_ID == 0)
        throw new IllegalArgumentException("No Record");
    String sql1 = "SELECT * FROM AD_Package_Exp WHERE AD_Package_Exp_ID = " + p_PackOut_ID;
    PreparedStatement pstmt1 = null;
    pstmt1 = DB.prepareStatement(sql1, get_TrxName());
    try {
        ResultSet rs1 = pstmt1.executeQuery();
        while (rs1.next()) {
            //Create the package documentation
            packagedir = rs1.getString(X_AD_Package_Exp.COLUMNNAME_File_Directory).trim();
            if (!packagedir.endsWith("/") && !packagedir.endsWith("\\"))
                packagedir += File.separator;
            packagename = packagedir + rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name);
            includesdir = rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name) + File.separator + "**";
            boolean success = (new File(packagename + File.separator + "doc" + File.separator)).mkdirs();
            String file_document = packagename + File.separator + "doc" + File.separator + rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name) + "Doc.xml";
            packageDocStream = new FileOutputStream(file_document, false);
            StreamResult streamResult_document = new StreamResult(new OutputStreamWriter(packageDocStream, "ISO-8859-1"));
            SAXTransformerFactory tf_document = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
            tf_document.setAttribute("indent-number", new Integer(4));
            TransformerHandler packageDocument = tf_document.newTransformerHandler();
            Transformer serializer_document = packageDocument.getTransformer();
            serializer_document.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
            serializer_document.setOutputProperty(OutputKeys.INDENT, "yes");
            packageDocument.setResult(streamResult_document);
            packageDocument.startDocument();
            AttributesImpl atts = new AttributesImpl();
            atts.clear();
            packageDocument.processingInstruction("xml-stylesheet", "type=\"text/css\" href=\"adempiereDocument.css\"");
            packageDocument.startElement("", "", "adempiereDocument", atts);
            packageDocument.startElement("", "", "header", atts);
            packageDocument.characters((rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name) + " Package Description").toCharArray(), 0, (rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name) + " Package Description").length());
            packageDocument.endElement("", "", "header");
            packageDocument.startElement("", "", "H1", atts);
            packageDocument.characters(("Package Name:").toCharArray(), 0, ("Package Name:").length());
            packageDocument.endElement("", "", "H1");
            packageDocument.startElement("", "", "packagename", atts);
            packageDocument.characters(rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name).toCharArray(), 0, rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name).length());
            packageDocument.endElement("", "", "packagename");
            packageDocument.startElement("", "", "H1", atts);
            packageDocument.characters(("Creator:").toCharArray(), 0, ("Creator:").length());
            packageDocument.endElement("", "", "H1");
            packageDocument.startElement("", "", "creator", atts);
            packageDocument.characters(rs1.getString(X_AD_Package_Exp.COLUMNNAME_UserName).toCharArray(), 0, rs1.getString(X_AD_Package_Exp.COLUMNNAME_UserName).length());
            packageDocument.endElement("", "", "creator");
            packageDocument.startElement("", "", "H1", atts);
            packageDocument.characters(("Email Address:").toCharArray(), 0, ("Email Address:").length());
            packageDocument.endElement("", "", "H1");
            packageDocument.startElement("", "", "creatorcontact", atts);
            packageDocument.characters(rs1.getString(X_AD_Package_Exp.COLUMNNAME_EMail).toCharArray(), 0, rs1.getString(X_AD_Package_Exp.COLUMNNAME_EMail).length());
            packageDocument.endElement("", "", "creatorcontact");
            packageDocument.startElement("", "", "H1", atts);
            packageDocument.characters(("Created:").toCharArray(), 0, ("Created:").length());
            packageDocument.endElement("", "", "H1");
            packageDocument.startElement("", "", "createddate", atts);
            packageDocument.characters(rs1.getString("Created").toString().toCharArray(), 0, rs1.getString("Created").toString().length());
            packageDocument.endElement("", "", "createddate");
            packageDocument.startElement("", "", "H1", atts);
            packageDocument.characters(("Updated:").toCharArray(), 0, ("Updated:").length());
            packageDocument.endElement("", "", "H1");
            packageDocument.startElement("", "", "updateddate", atts);
            packageDocument.characters(rs1.getString("Updated").toString().toCharArray(), 0, rs1.getString("Updated".toString()).length());
            packageDocument.endElement("", "", "updateddate");
            packageDocument.startElement("", "", "H1", atts);
            packageDocument.characters(("Description:").toCharArray(), 0, ("Description:").length());
            packageDocument.endElement("", "", "H1");
            packageDocument.startElement("", "", "description", atts);
            packageDocument.characters(rs1.getString(X_AD_Package_Exp.COLUMNNAME_Description).toCharArray(), 0, rs1.getString(X_AD_Package_Exp.COLUMNNAME_Description).length());
            packageDocument.endElement("", "", "description");
            packageDocument.startElement("", "", "H1", atts);
            packageDocument.characters(("Instructions:").toCharArray(), 0, ("Instructions:").length());
            packageDocument.endElement("", "", "H1");
            packageDocument.startElement("", "", "instructions", atts);
            packageDocument.characters(rs1.getString(X_AD_Package_Exp.COLUMNNAME_Instructions).toCharArray(), 0, rs1.getString(X_AD_Package_Exp.COLUMNNAME_Instructions).length());
            packageDocument.endElement("", "", "instructions");
            packageDocument.startElement("", "", "H1", atts);
            packageDocument.characters(("Files in Package:").toCharArray(), 0, ("Files in Package:").length());
            packageDocument.endElement("", "", "H1");
            packageDocument.startElement("", "", "file", atts);
            packageDocument.characters(("File: PackOut.xml").toCharArray(), 0, ("File: PackOut.xml").length());
            packageDocument.endElement("", "", "file");
            packageDocument.startElement("", "", "filedirectory", atts);
            packageDocument.characters("Directory: \\dict\\".toCharArray(), 0, ("Directory: \\dict\\").length());
            packageDocument.endElement("", "", "filedirectory");
            packageDocument.startElement("", "", "filenotes", atts);
            packageDocument.characters("Notes: Contains all application/object settings for package".toCharArray(), 0, "Notes: Contains all application/object settings for package".length());
            packageDocument.endElement("", "", "filenotes");
            success = (new File(packagename + File.separator + "dict" + File.separator)).mkdirs();
            String file_menu = packagename + File.separator + "dict" + File.separator + "PackOut.xml";
            packOutDocStream = new FileOutputStream(file_menu, false);
            StreamResult streamResult_menu = new StreamResult(new OutputStreamWriter(packOutDocStream, "ISO-8859-1"));
            SAXTransformerFactory tf_menu = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
            tf_menu.setAttribute("indent-number", new Integer(4));
            TransformerHandler packOutDocument = tf_menu.newTransformerHandler();
            Transformer serializer_menu = packOutDocument.getTransformer();
            serializer_menu.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
            serializer_menu.setOutputProperty(OutputKeys.INDENT, "yes");
            packOutDocument.setResult(streamResult_menu);
            packOutDocument.startDocument();
            atts.clear();
            atts.addAttribute("", "", "Name", "CDATA", rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name));
            atts.addAttribute("", "", "Version", "CDATA", rs1.getString(X_AD_Package_Exp.COLUMNNAME_PK_Version));
            atts.addAttribute("", "", "CompVer", "CDATA", rs1.getString(X_AD_Package_Exp.COLUMNNAME_ReleaseNo));
            atts.addAttribute("", "", "DataBase", "CDATA", rs1.getString(X_AD_Package_Exp.COLUMNNAME_Version));
            atts.addAttribute("", "", "Description", "CDATA", rs1.getString(X_AD_Package_Exp.COLUMNNAME_Description));
            atts.addAttribute("", "", "creator", "CDATA", rs1.getString(X_AD_Package_Exp.COLUMNNAME_UserName));
            atts.addAttribute("", "", "creatorcontact", "CDATA", rs1.getString(X_AD_Package_Exp.COLUMNNAME_EMail));
            atts.addAttribute("", "", "createddate", "CDATA", rs1.getString("Created"));
            atts.addAttribute("", "", "updateddate", "CDATA", rs1.getString("Updated"));
            atts.addAttribute("", "", "PackOutVer", "CDATA", PackOutVer);
            packOutDocument.startElement("", "", "adempiereAD", atts);
            atts.clear();
            final String sql = "SELECT * FROM AD_Package_Exp_Detail WHERE AD_Package_Exp_ID = " + p_PackOut_ID + " AND IsActive='Y' ORDER BY Line ASC";
            PreparedStatement pstmt = null;
            ResultSet rs = null;
            try {
                pstmt = DB.prepareStatement(sql, get_TrxName());
                rs = pstmt.executeQuery();
                while (rs.next()) {
                    final String Type = rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Type);
                    final int AD_EntityType_ID = rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_EntityType_ID);
                    Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_EntityType_ID, AD_EntityType_ID);
                    //
                    log.info(rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Line));
                    if (Type.compareTo("M") == 0) {
                        createMenu(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Menu_ID), packOutDocument);
                    } else if (Type.compareTo("P") == 0)
                        createProcess(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Process_ID), packOutDocument);
                    else if (Type.compareTo("R") == 0)
                        createReportview(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_ReportView_ID), packOutDocument);
                    else if (Type.compareTo("D") == 0)
                        createData(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID), rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement), packOutDocument);
                    else if (Type.compareTo("T") == 0)
                        createTable(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID), packOutDocument);
                    else if (Type.compareTo("X") == 0)
                        createForm(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Form_ID), packOutDocument);
                    else if (Type.compareTo("W") == 0)
                        createWindow(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Window_ID), packOutDocument);
                    else if (Type.compareTo("SV") == 0)
                        createView(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_View_ID), packOutDocument);
                    else if (Type.compareTo("SB") == 0)
                        createBrowse(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Browse_ID), packOutDocument);
                    else if (Type.compareTo("S") == 0)
                        createRoles(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Role_ID), packOutDocument);
                    else if (Type.compareTo("SQL") == 0)
                        createSQL(rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement), rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_DBType), packOutDocument);
                    else if (Type.compareTo("IMP") == 0)
                        createImpFormat(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_ImpFormat_ID), packOutDocument);
                    else if (Type.compareTo("REF") == 0)
                        createReference(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Reference_ID), packOutDocument);
                    else if (Type.compareTo("SNI") == 0)
                        createSnipit(rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Destination_Directory), rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Destination_FileName), rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_Old), rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_New), rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo), packOutDocument);
                    else if (Type.compareTo("F") == 0)
                        createWorkflow(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID), packOutDocument);
                    else if (Type.compareTo("V") == 0)
                        createDynamicRuleValidation(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID), packOutDocument);
                    else if (Type.compareTo("MSG") == 0)
                        createMessage(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Message_ID), packOutDocument);
                    else if (Type.compareTo("PFT") == 0)
                        createPrintFormat(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_PrintFormat_ID), packOutDocument);
                    else if (Type.compareTo(X_AD_Package_Exp_Detail.TYPE_ModelValidator) == 0)
                        createModelValidator(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_ModelValidator_ID), packOutDocument);
                    else if (Type.compareTo(X_AD_Package_Exp_Detail.TYPE_EntityType) == 0)
                        createEntityType(AD_EntityType_ID, packOutDocument);
                    else if (Type.compareTo("C") == 0) {
                        log.log(Level.INFO, "In PackOut.java handling Code or Other 2pack module creation");
                        String fullDirectory = rs1.getString(X_AD_Package_Exp.COLUMNNAME_File_Directory) + rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name) + rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory);
                        log.log(Level.INFO, "fullDirectory" + fullDirectory);
                        String targetDirectoryModified = null;
                        char fileseperator1 = '/';
                        char fileseperator2 = '\\';
                        //Correct package for proper file separator
                        if (File.separator.equals("/")) {
                            targetDirectoryModified = fullDirectory.replace(fileseperator2, fileseperator1);
                        } else
                            targetDirectoryModified = fullDirectory.replace(fileseperator1, fileseperator2);
                        String target_File = (targetDirectoryModified);
                        success = (new File(target_File).mkdirs());
                        fullDirectory = rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_File_Directory);
                        targetDirectoryModified = null;
                        //Correct package for proper file separator
                        if (File.separator.equals("/")) {
                            targetDirectoryModified = fullDirectory.replace(fileseperator2, fileseperator1);
                        } else
                            targetDirectoryModified = fullDirectory.replace(fileseperator2, fileseperator1);
                        copyCode(targetDirectoryModified + rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_FileName), target_File + rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_FileName));
                        atts.clear();
                        if (rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Destination_Directory) != null) {
                            fullDirectory = rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Destination_Directory);
                            String destinationDirectoryModified = null;
                            //Correct package for proper file separator
                            if (File.separator.equals("/")) {
                                destinationDirectoryModified = fullDirectory.replace(fileseperator2, fileseperator1);
                            } else
                                destinationDirectoryModified = fullDirectory.replace(fileseperator2, fileseperator1);
                            createDistributeFile(rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_FileName), rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory), rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo), destinationDirectoryModified, packOutDocument);
                        }
                        if (rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_FileName) != null) {
                            packageDocument.startElement("", "", "file", atts);
                            packageDocument.characters(("File: " + rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_FileName)).toCharArray(), 0, ("File: " + rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_FileName)).length());
                            packageDocument.endElement("", "", "file");
                        }
                        packageDocument.startElement("", "", "filedirectory", atts);
                        packageDocument.characters(("Directory: " + rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory)).toCharArray(), 0, ("Directory: " + rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory)).length());
                        packageDocument.endElement("", "", "filedirectory");
                        packageDocument.startElement("", "", "filenotes", atts);
                        packageDocument.characters(("Notes: " + rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Description)).toCharArray(), 0, (("Notes: " + rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Description)).length()));
                        packageDocument.endElement("", "", "filenotes");
                    }
                }
                //
                getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_EntityType_ID);
            } finally {
                DB.close(rs, pstmt);
                rs = null;
                pstmt = null;
            }
            atts.clear();
            //no longer use
            //packOutDocument.startElement("","","menuset",atts);
            //packOutDocument.endElement("","","menuset");
            packOutDocument.endElement("", "", "adempiereAD");
            packOutDocument.endDocument();
            packageDocument.endElement("", "", "adempiereDocument");
            packageDocument.endDocument();
        //m_Exp.setProcessed(true);
        //m_Exp.saveEx();
        }
        rs1.close();
        pstmt1.close();
        pstmt1 = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, e.getLocalizedMessage(), e);
        throw e;
    } finally {
        try {
            if (pstmt1 != null)
                pstmt1.close();
        } catch (Exception e) {
        }
        pstmt1 = null;
        // Close streams - teo_sarca [ 1704762 ]
        if (packageDocStream != null)
            try {
                packageDocStream.close();
            } catch (Exception e) {
            }
        if (packOutDocStream != null)
            try {
                packOutDocStream.close();
            } catch (Exception e) {
            }
    }
    //create compressed packages
    //set the files	
    File srcFolder = new File(packagedir);
    File destZipFile = new File(packagename + ".zip");
    File destTarFile = new File(packagename + ".tar");
    File destGZipFile = new File(packagename + ".tar.gz");
    //delete the old packages if necessary
    boolean success = destZipFile.delete();
    success = destTarFile.delete();
    success = destGZipFile.delete();
    //create the compressed packages
    CreateZipFile.zipFolder(srcFolder, destZipFile, includesdir);
    CreateZipFile.tarFolder(srcFolder, destTarFile, includesdir);
    CreateZipFile.gzipFile(destTarFile, destGZipFile);
    //Clean .tar file up
    success = destTarFile.delete();
    return "Finish Process";
}
Also used : TransformerHandler(javax.xml.transform.sax.TransformerHandler) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) PreparedStatement(java.sql.PreparedStatement) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) AttributesImpl(org.xml.sax.helpers.AttributesImpl) FileOutputStream(java.io.FileOutputStream) ResultSet(java.sql.ResultSet) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File)

Aggregations

AttributesImpl (org.xml.sax.helpers.AttributesImpl)310 SAXException (org.xml.sax.SAXException)53 Test (org.junit.Test)34 DiskWriteAttributesImpl (org.apache.geode.internal.cache.DiskWriteAttributesImpl)23 PartitionAttributesImpl (org.apache.geode.internal.cache.PartitionAttributesImpl)23 ContentHandler (org.xml.sax.ContentHandler)21 Attributes (org.xml.sax.Attributes)17 PreparedStatement (java.sql.PreparedStatement)16 ResultSet (java.sql.ResultSet)16 Map (java.util.Map)16 PackOut (org.adempiere.pipo.PackOut)16 IOException (java.io.IOException)15 POSaveFailedException (org.adempiere.pipo.exception.POSaveFailedException)12 Iterator (java.util.Iterator)11 TransformerHandler (javax.xml.transform.sax.TransformerHandler)11 StreamResult (javax.xml.transform.stream.StreamResult)11 Metadata (org.apache.tika.metadata.Metadata)11 File (java.io.File)9 SAXTransformerFactory (javax.xml.transform.sax.SAXTransformerFactory)9 DatabaseAccessException (org.adempiere.pipo.exception.DatabaseAccessException)9