Search in sources :

Example 41 with Transformer

use of javax.xml.transform.Transformer in project midpoint by Evolveum.

the class DomToSchemaProcessor method parseSchema.

private XSSchemaSet parseSchema(Element schema) throws SchemaException {
    // Make sure that the schema parser sees all the namespace declarations
    DOMUtil.fixNamespaceDeclarations(schema);
    XSSchemaSet xss = null;
    try {
        TransformerFactory transfac = TransformerFactory.newInstance();
        Transformer trans = transfac.newTransformer();
        trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
        trans.setOutputProperty(OutputKeys.INDENT, "yes");
        DOMSource source = new DOMSource(schema);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        StreamResult result = new StreamResult(out);
        trans.transform(source, result);
        XSOMParser parser = createSchemaParser();
        InputSource inSource = new InputSource(new ByteArrayInputStream(out.toByteArray()));
        // XXX: hack: it's here to make entity resolver work...
        inSource.setSystemId("SystemId");
        // XXX: end hack
        inSource.setEncoding("utf-8");
        parser.parse(inSource);
        xss = parser.getResult();
    } catch (SAXException e) {
        throw new SchemaException("XML error during XSD schema parsing: " + e.getMessage() + "(embedded exception " + e.getException() + ") in " + shortDescription, e);
    } catch (TransformerException e) {
        throw new SchemaException("XML transformer error during XSD schema parsing: " + e.getMessage() + "(locator: " + e.getLocator() + ", embedded exception:" + e.getException() + ") in " + shortDescription, e);
    } catch (RuntimeException e) {
        // This sometimes happens, e.g. NPEs in Saxon
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error("Unexpected error {} during parsing of schema:\n{}", e.getMessage(), DOMUtil.serializeDOMToString(schema));
        }
        throw new SchemaException("XML error during XSD schema parsing: " + e.getMessage() + " in " + shortDescription, e);
    }
    return xss;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) DOMSource(javax.xml.transform.dom.DOMSource) InputSource(org.xml.sax.InputSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) XSOMParser(com.sun.xml.xsom.parser.XSOMParser) StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SAXException(org.xml.sax.SAXException) ByteArrayInputStream(java.io.ByteArrayInputStream) TransformerException(javax.xml.transform.TransformerException)

Example 42 with Transformer

use of javax.xml.transform.Transformer in project midpoint by Evolveum.

the class DOMUtil method printDom.

public static StringBuffer printDom(Node node, boolean indent, boolean omitXmlDeclaration) {
    StringWriter writer = new StringWriter();
    TransformerFactory transfac = TransformerFactory.newInstance();
    Transformer trans;
    try {
        trans = transfac.newTransformer();
    } catch (TransformerConfigurationException e) {
        throw new SystemException("Error in XML configuration: " + e.getMessage(), e);
    }
    trans.setOutputProperty(OutputKeys.INDENT, (indent ? "yes" : "no"));
    // XALAN-specific
    trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
    trans.setParameter(OutputKeys.ENCODING, "utf-8");
    // Note: serialized XML does not contain xml declaration
    trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, (omitXmlDeclaration ? "yes" : "no"));
    DOMSource source = new DOMSource(node);
    try {
        trans.transform(source, new StreamResult(writer));
    } catch (TransformerException e) {
        throw new SystemException("Error in XML transformation: " + e.getMessage(), e);
    }
    return writer.getBuffer();
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) SystemException(com.evolveum.midpoint.util.exception.SystemException) StreamResult(javax.xml.transform.stream.StreamResult) TransformerException(javax.xml.transform.TransformerException)

Example 43 with Transformer

use of javax.xml.transform.Transformer in project azure-tools-for-java by Microsoft.

the class ParserXMLUtility method saveXMLFile.

/**
	 * save XML file and saves XML document.
	 *
	 * @param fileName
	 * @param doc
	 * @return XML document or <B>null</B> if error occurred
	 * @throws IOException
	 * @throws Exception
	 */
public static boolean saveXMLFile(String fileName, Document doc) throws Exception {
    File xmlFile = null;
    FileOutputStream fos = null;
    Transformer transformer;
    try {
        xmlFile = new File(fileName);
        fos = new FileOutputStream(xmlFile);
        TransformerFactory transFactory = TransformerFactory.newInstance();
        transformer = transFactory.newTransformer();
        DOMSource source = new DOMSource(doc);
        StreamResult destination = new StreamResult(fos);
        // transform source into result will do save
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        transformer.transform(source, destination);
    } finally {
        if (fos != null) {
            fos.close();
        }
    }
    return true;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) TransformerFactory(javax.xml.transform.TransformerFactory) StreamResult(javax.xml.transform.stream.StreamResult) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 44 with Transformer

use of javax.xml.transform.Transformer in project uPortal by Jasig.

the class SitemapTest method testStylesheetCompilation.

@Test
public void testStylesheetCompilation() throws IOException {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    Resource resource = new ClassPathResource(STYLESHEET_LOCATION);
    Source source = new StreamSource(resource.getInputStream(), resource.getURI().toASCIIString());
    try {
        Transformer transformer = TransformerFactory.newInstance().newTransformer(source);
        transformer.setParameter(SitemapPortletController.USE_TAB_GROUPS, useTabGroups);
        transformer.setParameter(SitemapPortletController.USER_LANG, "en_US");
        transformer.setParameter(XsltPortalUrlProvider.CURRENT_REQUEST, request);
        transformer.setParameter(XsltPortalUrlProvider.XSLT_PORTAL_URL_PROVIDER, this.xsltPortalUrlProvider);
        Source xmlSource = new StreamSource(new ClassPathResource(XML_LOCATION).getFile());
        CharArrayWriter buffer = new CharArrayWriter();
        TransformerUtils.enableIndenting(transformer);
        transformer.transform(xmlSource, new StreamResult(buffer));
        if (logger.isTraceEnabled()) {
            logger.trace("XML: " + new String(buffer.toCharArray()));
        }
    } catch (TransformerConfigurationException e) {
        logger.error(e.getMessage(), e);
        throw new RuntimeException(e);
    } catch (TransformerException e) {
        logger.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}
Also used : Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) StreamSource(javax.xml.transform.stream.StreamSource) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) MessageSource(org.springframework.context.MessageSource) StaticMessageSource(org.springframework.context.support.StaticMessageSource) CharArrayWriter(java.io.CharArrayWriter) TransformerException(javax.xml.transform.TransformerException) Test(org.junit.Test)

Example 45 with Transformer

use of javax.xml.transform.Transformer 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

Transformer (javax.xml.transform.Transformer)1034 StreamResult (javax.xml.transform.stream.StreamResult)799 DOMSource (javax.xml.transform.dom.DOMSource)644 TransformerFactory (javax.xml.transform.TransformerFactory)511 TransformerException (javax.xml.transform.TransformerException)398 StringWriter (java.io.StringWriter)322 IOException (java.io.IOException)264 Document (org.w3c.dom.Document)260 StreamSource (javax.xml.transform.stream.StreamSource)204 Source (javax.xml.transform.Source)188 File (java.io.File)162 DocumentBuilder (javax.xml.parsers.DocumentBuilder)149 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)145 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)142 Element (org.w3c.dom.Element)136 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)124 SAXException (org.xml.sax.SAXException)112 StringReader (java.io.StringReader)108 Result (javax.xml.transform.Result)106 ByteArrayOutputStream (java.io.ByteArrayOutputStream)104