<commit_before>package nonregressiontest.descriptor.validateall;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URL;

import org.apache.xerces.parsers.SAXParser;
import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;

import testsuite.test.Assertions;
import testsuite.test.FunctionalTest;


/**
 * A stripped-down Active Object example. The object has only one public method,
 * sayHello() The object does nothing but reflect the host its on.
 */
public class Test extends FunctionalTest {
    ProActiveDescriptor pad;
    transient SAXParser parser = null;
    transient Validator handler = null;

    /** ProActive compulsory no-args constructor */
    public Test() {
        super("Deployment descriptors in \"descriptors\" validation.",
            "Test service: validating every deployment descriptors in folder \"descriptors\"");
    }

    /*
     * (non-Javadoc)
     *
     * @see testsuite.test.FunctionalTest#action()
     */
    public void action() throws Exception {
        URL baseurl = Test.class.getResource("/nonregressiontest/");
        URI baseuri = baseurl.toURI();

        // locates the descriptor directory
        // FIXME if ever the classes are compiled to a location other than a direct child of the PROACTIVE_DIR, the descriptor folder won't be found
        URI descriptorsuri = baseuri.resolve("../../descriptors");
        File descriptorsfolder = new File(descriptorsuri);
        Assertions.assertTrue("\"" + descriptorsuri +
            "\" directory could not be found", descriptorsfolder.exists());
        Assertions.assertTrue("\"" + descriptorsuri + "\" is not a directory",
            descriptorsfolder.isDirectory());
        Assertions.assertTrue("\"" + descriptorsuri + "\" is read-protected",
            descriptorsfolder.canRead());

        // recurse into directory tree to locate xml files
        checkValidationRecursive(descriptorsfolder);

        // locates the examples directory
        URI examplesuri = baseuri.resolve("../../src/org/objectweb/proactive/examples");
        File examplesfolder = new File(examplesuri);
        Assertions.assertTrue("\"" + examplesuri +
            "\" directory could not be found", examplesfolder.exists());
        Assertions.assertTrue("\"" + examplesuri + "\" is not a directory",
            examplesfolder.isDirectory());
        Assertions.assertTrue("\"" + examplesuri + "\" is read-protected",
            examplesfolder.canRead());

        // recurse into directory tree to locate xml files
        checkValidationRecursive(examplesfolder);
    }

    private void checkValidationRecursive(File basedirectory)
        throws SAXException, IOException {
        for (File file : basedirectory.listFiles()) {
            if (file.isDirectory() && file.canRead()) {
                checkValidationRecursive(file);
            } else if (file.canRead()) {
                String filename = file.getName();
                int index = filename.lastIndexOf('.');

                if (index > 0) {
                    String extension = filename.substring(index + 1,
                            filename.length());

                    if (extension.equals("xml")) {
                        checkValidation(file);
                    }
                }
            }
        }
    }

    private void checkValidation(File xmlDescriptor)
        throws SAXException, IOException {
        //Since Validator implements ErrorHandler, you can use it to parse the example XML document. 
        // The parse methods parse(java.lang.String systemId) and parse(org.xml.sax.InputSource inputSource) 
        // may be used for parsing an XML document.
        try {
            parser.parse(xmlDescriptor.getAbsolutePath());
        } catch (SAXException exp) {
        } finally {
            if (handler.validationError) {
                System.out.println("Error occured when parsing \"" +
                    xmlDescriptor.getAbsolutePath() + "\".");
                throw new SAXException(handler.saxParseException);
            }
        }

        //The errors generated by the parser get registered with the ErrorHandler 
    }

    /*
     * (non-Javadoc)
     *
     * @see testsuite.test.AbstractTest#initTest()
     */
    public void initTest() throws Exception {
        //To validate with a SAXParser, create a SAXParser. The SAXParser class is a subclass of the XMLParser class.
        parser = new SAXParser();

        //Set the validation feature to true to report validation errors. If the validation feature is set to true, the XML document should specify a XML schema or a DTD.
        parser.setFeature("http://apache.org/xml/features/validation/dynamic", true);

        //Set the validation/schema feature to true to report validation errors against a schema.
        parser.setFeature("http://apache.org/xml/features/validation/schema",
            true);

        //Set the validation/schema-full-checking feature to true to enable full schema, grammar-constraint checking.
        parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking",
            true);

        handler = new Validator();
        parser.setErrorHandler(handler);

        //		// Specify a validation schema for the parser with the schema/external-noNamespaceSchemaLocation or the schema/external-schemaLocation property. The schema/external-schemaLocation property is used to specify a schema with a namespace. A schema list may be specified with the schema/external-schemaLocation property. The schema/external-noNamespaceSchemaLocation property is used to specify a schema that does not have a namespace. A parser is not required to locate a schema specified with the schema/external-noNamespaceSchemaLocation and schema/external-schemaLocation properties. For our purposes, a schema without a namespace is used to validate an XML document.
        //
        //		parser.setProperty(
        //		     "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
        //		     SchemaUrl);
    }

    /*
     * (non-Javadoc)
     *
     * @see testsuite.test.AbstractTest#endTest()
     */
    public void endTest() throws Exception {
    }

    public boolean postConditions() throws Exception {
        return !handler.validationError;
    }

    public static void main(String[] args) {
        Test test = new Test();

        try {
            test.initTest();
            test.action();
            test.endTest();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Validator extends DefaultHandler {
        public boolean validationError = false;
        public SAXParseException saxParseException = null;

        public void error(SAXParseException exception)
            throws SAXException {
            validationError = true;
            saxParseException = exception;
        }

        public void fatalError(SAXParseException exception)
            throws SAXException {
            validationError = true;
            saxParseException = exception;
        }

        public void warning(SAXParseException exception)
            throws SAXException {
        }
    }
}
<commit_msg>changed the description of the descriptor/validateall nonregression test<commit_after>package nonregressiontest.descriptor.validateall;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URL;

import org.apache.xerces.parsers.SAXParser;
import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;

import testsuite.test.Assertions;
import testsuite.test.FunctionalTest;


/**
 * A stripped-down Active Object example. The object has only one public method,
 * sayHello() The object does nothing but reflect the host its on.
 */
public class Test extends FunctionalTest {
    ProActiveDescriptor pad;
    transient SAXParser parser = null;
    transient Validator handler = null;

    /** ProActive compulsory no-args constructor */
    public Test() {
        super("Deployment descriptors in \"descriptors\" and \"examples\" validation.",
            "Test service: validating every deployment descriptors in folder \"descriptors\" and \"PROACTIVE/examples\"");
    }

    /*
     * (non-Javadoc)
     *
     * @see testsuite.test.FunctionalTest#action()
     */
    public void action() throws Exception {
        URL baseurl = Test.class.getResource("/nonregressiontest/");
        URI baseuri = baseurl.toURI();

        // locates the descriptor directory
        // FIXME if ever the classes are compiled to a location other than a direct child of the PROACTIVE_DIR, the descriptor folder won't be found
        URI descriptorsuri = baseuri.resolve("../../descriptors");
        File descriptorsfolder = new File(descriptorsuri);
        Assertions.assertTrue("\"" + descriptorsuri +
            "\" directory could not be found", descriptorsfolder.exists());
        Assertions.assertTrue("\"" + descriptorsuri + "\" is not a directory",
            descriptorsfolder.isDirectory());
        Assertions.assertTrue("\"" + descriptorsuri + "\" is read-protected",
            descriptorsfolder.canRead());

        // recurse into directory tree to locate xml files
        checkValidationRecursive(descriptorsfolder);

        // locates the examples directory
        URI examplesuri = baseuri.resolve("../../src/org/objectweb/proactive/examples");
        File examplesfolder = new File(examplesuri);
        Assertions.assertTrue("\"" + examplesuri +
            "\" directory could not be found", examplesfolder.exists());
        Assertions.assertTrue("\"" + examplesuri + "\" is not a directory",
            examplesfolder.isDirectory());
        Assertions.assertTrue("\"" + examplesuri + "\" is read-protected",
            examplesfolder.canRead());

        // recurse into directory tree to locate xml files
        checkValidationRecursive(examplesfolder);
    }

    private void checkValidationRecursive(File basedirectory)
        throws SAXException, IOException {
        for (File file : basedirectory.listFiles()) {
            if (file.isDirectory() && file.canRead()) {
                checkValidationRecursive(file);
            } else if (file.canRead()) {
                String filename = file.getName();
                int index = filename.lastIndexOf('.');

                if (index > 0) {
                    String extension = filename.substring(index + 1,
                            filename.length());

                    if (extension.equals("xml")) {
                        checkValidation(file);
                    }
                }
            }
        }
    }

    private void checkValidation(File xmlDescriptor)
        throws SAXException, IOException {
        //Since Validator implements ErrorHandler, you can use it to parse the example XML document. 
        // The parse methods parse(java.lang.String systemId) and parse(org.xml.sax.InputSource inputSource) 
        // may be used for parsing an XML document.
        try {
            parser.parse(xmlDescriptor.getAbsolutePath());
        } catch (SAXException exp) {
        } finally {
            if (handler.validationError) {
                System.out.println("Error occured when parsing \"" +
                    xmlDescriptor.getAbsolutePath() + "\".");
                throw new SAXException(handler.saxParseException);
            }
        }

        //The errors generated by the parser get registered with the ErrorHandler 
    }

    /*
     * (non-Javadoc)
     *
     * @see testsuite.test.AbstractTest#initTest()
     */
    public void initTest() throws Exception {
        //To validate with a SAXParser, create a SAXParser. The SAXParser class is a subclass of the XMLParser class.
        parser = new SAXParser();

        //Set the validation feature to true to report validation errors. If the validation feature is set to true, the XML document should specify a XML schema or a DTD.
        parser.setFeature("http://apache.org/xml/features/validation/dynamic", true);

        //Set the validation/schema feature to true to report validation errors against a schema.
        parser.setFeature("http://apache.org/xml/features/validation/schema",
            true);

        //Set the validation/schema-full-checking feature to true to enable full schema, grammar-constraint checking.
        parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking",
            true);

        handler = new Validator();
        parser.setErrorHandler(handler);

        //		// Specify a validation schema for the parser with the schema/external-noNamespaceSchemaLocation or the schema/external-schemaLocation property. The schema/external-schemaLocation property is used to specify a schema with a namespace. A schema list may be specified with the schema/external-schemaLocation property. The schema/external-noNamespaceSchemaLocation property is used to specify a schema that does not have a namespace. A parser is not required to locate a schema specified with the schema/external-noNamespaceSchemaLocation and schema/external-schemaLocation properties. For our purposes, a schema without a namespace is used to validate an XML document.
        //
        //		parser.setProperty(
        //		     "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
        //		     SchemaUrl);
    }

    /*
     * (non-Javadoc)
     *
     * @see testsuite.test.AbstractTest#endTest()
     */
    public void endTest() throws Exception {
    }

    public boolean postConditions() throws Exception {
        return !handler.validationError;
    }

    public static void main(String[] args) {
        Test test = new Test();

        try {
            test.initTest();
            test.action();
            test.endTest();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Validator extends DefaultHandler {
        public boolean validationError = false;
        public SAXParseException saxParseException = null;

        public void error(SAXParseException exception)
            throws SAXException {
            validationError = true;
            saxParseException = exception;
        }

        public void fatalError(SAXParseException exception)
            throws SAXException {
            validationError = true;
            saxParseException = exception;
        }

        public void warning(SAXParseException exception)
            throws SAXException {
        }
    }
}

{'fraction_non_alphanumeric': 0.09182228814130655, 'fraction_numerical': 0.00026966898132542303, 'mean_word_length': 2.403854979348325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 28}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5391870', 'n_tokens_mistral': 3676, 'n_tokens_neox': 3564, 'n_words': 1107}