Search in sources :

Example 1 with SAXParser

use of org.apache.xerces.parsers.SAXParser in project ACS by ACS-Community.

the class CDBChecker method main.

/**
	 * Main function to run the cdbChecker tool.
	 * System.exit(0/1) is used to return success if everything if fine or
	 * failure in case errors were encountered.
	 */
public static void main(String[] args) {
    Logger logger = ClientLogManager.getAcsLogManager().getLoggerForApplication(CDBChecker.class.getSimpleName(), false);
    CDBChecker cdbchecker = new CDBChecker(logger);
    cdbchecker.props = System.getProperties();
    /* Blank lines to see the output clearly */
    System.out.println("\n\n");
    /*
		 * Retrieves the CDB path from the property, if given
		 */
    String ACS_cdbpath = cdbchecker.props.getProperty("ACS.cdbpath");
    if (cdbchecker.checkArgs(args)) {
        //add panta@naoj 2009/10/05
        String[] pathsMulti = cdbchecker.XMLPath.split(File.pathSeparator);
        for (int i = 0; i < pathsMulti.length; i++) {
            File file_ = new File(pathsMulti[i]);
            if (!file_.exists()) {
                System.out.println("*** ImplLang Check: Specified path " + file_ + " does not exist");
                cdbchecker.setGlobalErrorFlag(true);
                cdbchecker.showEndResult();
                break;
            }
        }
        //add panta@naoj 2009/10/05 end
        //Creating the parser
        //			System.setProperty("org.apache.xerces.xni.parser.XMLParserConfiguration", "org.apache.xerces.parsers.XIncludeAwareParserConfiguration");
        cdbchecker.SP = new SAXParser();
        cdbchecker.xsd_targetns = new Hashtable<String, String>();
        if (cdbchecker.verbose) {
            System.out.println("*** Reading required schema files");
        }
        if (cdbchecker.configLoader()) {
            if (cdbchecker.verbose) {
                System.out.println("*** Reading given schema files");
            }
            // Appends command line schema files, if any
            if (ACS_cdbpath != null) {
                // Modify panta@naoj 2009/10/15
                if (cdbchecker.XSDPath == null) {
                    cdbchecker.XSDPath = ACS_cdbpath;
                } else {
                    cdbchecker.XSDPath = cdbchecker.XSDPath + ":" + ACS_cdbpath;
                }
            }
            if (cdbchecker.checkidl) {
                if (cdbchecker.verbose) {
                    System.out.println("*** Checking Idl Types");
                }
                cdbchecker.checkIdlTypes();
            }
            String[] paths = cdbchecker.XSDPath.split(File.pathSeparator);
            Vector<String> xsdFilenames = cdbchecker.getFilenames(paths, "xsd");
            if (cdbchecker.verbose)
                System.out.println("*** Reading given XML files");
            // We assume that cdbchecker.XMLPath is at least
            // initialised to the empty string and never null
            paths = cdbchecker.XMLPath.split(File.pathSeparator);
            Vector<String> XMLFilenames = cdbchecker.getFilenames(paths, "xml");
            // Fill the map with the targetNamespace and the filenames
            if (cdbchecker.verbose)
                System.out.println("*** Getting TargetNamespaces from schema files");
            cdbchecker.getTargetNamespace(xsdFilenames);
            // Validating Schemas
            if (cdbchecker.verbose)
                System.out.println("*** Validating Schemas");
            cdbchecker.validateSchemas(xsdFilenames);
            // Validating XML files
            if (cdbchecker.verbose)
                System.out.println("*** Validating XML files");
            cdbchecker.XMLValidate(XMLFilenames);
            // checks if implLang matches, those written in XXComponents.xml and XXContainers.xml
            for (int i = 0; i < pathsMulti.length; i++) {
                cdbchecker.componentsFolder = pathsMulti[i] + File.separator + "MACI" + File.separator + "Components";
                cdbchecker.containersFolder = pathsMulti[i] + File.separator + "MACI" + File.separator + "Containers";
                File compFolder = new File(cdbchecker.componentsFolder);
                File contFolder = new File(cdbchecker.containersFolder);
                if (compFolder.exists() && contFolder.exists()) {
                    cdbchecker.setGlobalErrorFlag(cdbchecker.checkImplLangMatch(compFolder, contFolder));
                    // exit if error
                    if (cdbchecker.isGlobalErrorFlag()) {
                        break;
                    }
                }
            }
        // add panta@naoj 2009/10/05 end
        }
    } else {
        printUsage();
    }
    cdbchecker.cleanUp();
    cdbchecker.showEndResult();
}
Also used : SAXParser(org.apache.xerces.parsers.SAXParser) Logger(java.util.logging.Logger) File(java.io.File)

Example 2 with SAXParser

use of org.apache.xerces.parsers.SAXParser in project jena by apache.

the class SAX2RDFTest method loadXMLModel.

void loadXMLModel(Model m2, InputStream in, RDFEHArray eh2) throws SAXException, IOException {
    XMLReader saxParser = new SAXParser();
    SAX2Model handler = SAX2Model.create(base, m2);
    SAX2RDF.installHandlers(saxParser, handler);
    handler.setErrorHandler(eh2);
    InputSource ins = new InputSource(in);
    ins.setSystemId(base);
    try {
        try {
            saxParser.parse(ins);
        } finally {
            handler.close();
        }
    } catch (SAXParseException e) {
    // already reported, leave it be.
    }
}
Also used : InputSource(org.xml.sax.InputSource) SAX2Model(org.apache.jena.rdfxml.xmlinput.SAX2Model) SAXParseException(org.xml.sax.SAXParseException) SAXParser(org.apache.xerces.parsers.SAXParser) XMLReader(org.xml.sax.XMLReader)

Example 3 with SAXParser

use of org.apache.xerces.parsers.SAXParser in project jena by apache.

the class SAX2RDFMoreTests method testLang.

public void testLang() throws Exception {
    Model m = ModelFactory.createDefaultModel();
    Model m2 = ModelFactory.createDefaultModel();
    RDFEHArray eh = new RDFEHArray();
    try (InputStream in = new FileInputStream("testing/wg/rdfms-xmllang/test004.rdf")) {
        RDFReader w = m.getReader();
        w.setErrorHandler(eh);
        w.read(m, in, "http://example.org/");
    }
    RDFEHArray eh2 = new RDFEHArray();
    try (InputStream in = new FileInputStream("testing/wg/rdfms-xmllang/test003.rdf")) {
        XMLReader saxParser = new SAXParser();
        SAX2Model handler = SAX2Model.create("http://example.org/", m2, "fr");
        SAX2RDF.installHandlers(saxParser, handler);
        handler.setErrorHandler(eh2);
        InputSource ins = new InputSource(in);
        ins.setSystemId("http://example.org/");
        try {
            try {
                saxParser.parse(ins);
            } finally {
                handler.close();
            }
        } catch (SAXParseException e) {
        // already reported, leave it be.
        }
    }
    /*
		 * System.out.println("Normal:"); m.write(System.out,"N-TRIPLE");
		 * 
		 * System.out.println("New:"); m2.write(System.out,"N-TRIPLE");
		 */
    if (eh.v.size() == 0)
        assertTrue("Not isomorphic", m.isIsomorphicWith(m2));
    /*
		 * if ( eh.v.size()!=eh2.v.size()) { for (int i=0; i <a.length;i++)
		 * System.err.println(eh.v.get(i)); }
		 */
    assertEquals("Different number of errors", eh.v.size(), eh2.v.size());
    Object[] a = eh.v.toArray();
    Object[] a2 = eh2.v.toArray();
    Arrays.sort(a);
    Arrays.sort(a2);
    for (int i = 0; i < eh.v.size(); i++) {
        assertEquals("Error " + i + " different.", a[i], a2[i]);
    }
}
Also used : InputSource(org.xml.sax.InputSource) SAX2Model(org.apache.jena.rdfxml.xmlinput.SAX2Model) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream) RDFReader(org.apache.jena.rdf.model.RDFReader) SAXParseException(org.xml.sax.SAXParseException) SAX2Model(org.apache.jena.rdfxml.xmlinput.SAX2Model) Model(org.apache.jena.rdf.model.Model) RDFEHArray(org.apache.jena.rdfxml.xmlinput.SAX2RDFTest.RDFEHArray) SAXParser(org.apache.xerces.parsers.SAXParser) XMLReader(org.xml.sax.XMLReader)

Aggregations

SAXParser (org.apache.xerces.parsers.SAXParser)3 SAX2Model (org.apache.jena.rdfxml.xmlinput.SAX2Model)2 InputSource (org.xml.sax.InputSource)2 SAXParseException (org.xml.sax.SAXParseException)2 XMLReader (org.xml.sax.XMLReader)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Logger (java.util.logging.Logger)1 Model (org.apache.jena.rdf.model.Model)1 RDFReader (org.apache.jena.rdf.model.RDFReader)1 RDFEHArray (org.apache.jena.rdfxml.xmlinput.SAX2RDFTest.RDFEHArray)1