Esempio n. 1
0
    def validate(self, report, img_path, new_name = ''):  
        
        report.write('\nValidating:' + self.xml_filename)

        xml_java.replace_dtd_path(self.xml_filename, self.dtd)
        
        if xml_java.validate(self.xml_filename, self.dtd, self.result_filename, self.err_filename):              
            report.write('transform ' + self.xml_filename + ' '+  self.xsl_prep_report + ' '+  self.xml_report)
            if xml_java.transform(self.xml_filename, self.xsl_prep_report, self.xml_report, self.err_filename):
                # Generate self.report.html
                report.write('transform ' + self.xml_report + ' '+  self.xsl_report + ' '+  self.html_report)
                if xml_java.transform(self.xml_report, self.xsl_report, self.html_report, self.err_filename):
                    os.unlink(self.xml_report)
                    report.write('Validation report:' + self.html_report, True, False, True)
                else:
                    report.write('Unable to create validation report: ' + self.html_report, True, True, True)
            else:
                report.write('Unable to generate xml for report: ' + self.xml_report, True, True, True)

            if ':' in img_path:
                img_path = 'file:///' + img_path 
            if type(self.xsl_preview) == type([]):
                xml_java.tranform_in_steps(self.xml_filename, self.dtd, self.xsl_preview, self.html_preview, {'path_img': img_path +'/', 'css':  self.css, 'new_name': new_name})
            else:
                report.write('transform ' + self.xml_filename + ' '+  self.xsl_preview + ' '+  self.html_preview )
                xml_java.transform(self.xml_filename, self.xsl_preview, self.html_preview, self.err_filename, {'path_img': img_path +'/', 'css':  self.css, 'new_name': new_name})
            if os.path.exists(self.html_preview):
                report.write('Preview ' +  self.html_preview, True, False, True)
            else:
                report.write('Unable to create preview: ' + self.html_preview, True, True, True)
            
            report.write('transform ' + self.xml_filename + ' '+  self.xsl_output + ' '+  self.xml_ouput_filename)

            if xml_java.transform(self.xml_filename, self.xsl_output, self.xml_ouput_filename, self.err_filename):
                report.write('Result ' +  self.xml_ouput_filename)
            else:
                report.write('Unable to create result: ' + self.xml_ouput_filename, True, True, True)
        if os.path.isfile(self.result_filename):
            os.unlink(self.result_filename)
        if os.path.exists(self.xml_ouput_filename):
            report.write('END - OK')
            r = True
        else:
            report.write('END - ERROR')
            if not os.path.exists(self.err_filename):
                f = open(self.err_filename, 'w')
                f.write('error')
                f.close()
            report.write('Errors: read ' + self.err_filename, False, True, True)
            r = False
        return r
Esempio n. 2
0
    def validate_xml_and_style(self, report):          
        is_valid_xml = False
        
        import time

        xml_java.replace_dtd_path(self.xml_filename, self.dtd)        
        if xml_java.validate(self.xml_filename, self.dtd, self.result_filename, self.err_filename):  
            is_valid_xml = True    

            report.write('Transform ' + self.xml_filename + ' + ' + self.xsl_prep_report +  ' => ' + self.xml_report + ' ' + self.err_filename)        
            t = time.time()
            report.write(str(os.path.exists(self.xml_filename)))        
            report.write(str(os.path.exists(self.xsl_prep_report))   )     
            
            if xml_java.transform(self.xml_filename, self.xsl_prep_report, self.xml_report, self.err_filename):
                t1 = time.time()
                report.write(str(t1 - t))
                report.write('Transform ' + self.xml_report + ' + ' + self.xsl_report +  ' => ' + self.html_report + ' ' + self.err_filename)        
                
                report.write(str(os.path.exists(self.xml_report)))        
                report.write(str(os.path.exists(self.xsl_report)))        
                if xml_java.transform(self.xml_report, self.xsl_report, self.html_report, self.err_filename):
                    t2 = time.time()
                    report.write(str(t2 - t1))
                else:
                    t2 = time.time()
                    report.write('Unable to generate ' + self.html_report )
                    report.write(str(t2 - t1))
            else:
                t1 = time.time()
                report.write('Unable to generate ' + self.xml_report)
                report.write(str(t1 - t))
        
        if os.path.isfile(self.result_filename):
            os.unlink(self.result_filename)

        c = ''
        if os.path.exists(self.html_report):
            f = open(self.html_report, 'r')
            c = f.read()
            f.close()
            

        return (is_valid_xml, ('Total of errors = 0' in c))