[jboss-svn-commits] JBL Code SVN: r8348 - labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Dec 15 10:41:08 EST 2006
Author: ddegroff
Date: 2006-12-15 10:41:07 -0500 (Fri, 15 Dec 2006)
New Revision: 8348
Modified:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/XmlValidatorImpl.java
Log:
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/XmlValidatorImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/XmlValidatorImpl.java 2006-12-15 15:23:26 UTC (rev 8347)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/XmlValidatorImpl.java 2006-12-15 15:41:07 UTC (rev 8348)
@@ -21,7 +21,12 @@
*/
package org.jboss.soa.esb.listeners.config;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
import java.util.Collection;
import java.util.HashSet;
@@ -44,6 +49,7 @@
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
+
/**
* A Helper classes used to validate xml files against supplied schemas.
*
@@ -87,51 +93,27 @@
* @throws XmlValidatorException Failure during validation.
*/
public boolean validate(InputSource xmlSource) throws XmlValidatorException {
+ String defaultSchema = "jbossesb-1.0.xsd";
+ StreamSource validationInputSource = null;
- try {
- DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder parser = builderFactory.newDocumentBuilder();
- xmlDocument = parser.parse(xmlSource);
- } catch (SAXException e) {
- log.error("Failed to validate xml",e);
- isValid = false;
- } catch (ParserConfigurationException e) {
- log.error("ParserConfigurationException occurred: " + e.getMessage());
- isValid = false;
- } catch (IOException e) {
- log.error("IOException occurred: " + e.getMessage());
- isValid = false;
- }
-
- SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
- Source schemaFile = new StreamSource("jbossesb.xsd");
- Schema schema = null;
-
- try {
- schema = factory.newSchema(schemaFile);
- } catch (SAXException e) {
- log.error("Failed to validate xml",e);
- isValid = false;
- }
-
- // Request validation
- Validator validator = schema.newValidator();
-
- // Register the error handler
- validator.setErrorHandler(new XmlErrorHandler());
-
- try {
- validator.validate(new DOMSource(xmlDocument));
- } catch (SAXException e) {
- log.error("Failed to validate xml",e);
- isValid = false;
- } catch (IOException e) {
- log.error("IOException occurred: " + e.getMessage());
- isValid = false;
- }
-
- log.error("validate() - validationResults.size() = "+validationResults.size());
- return isValid;
+ InputStream validationInputStream = this.getClass().getResourceAsStream(defaultSchema);
+ //if this fails try using the
+ if (validationInputStream==null) {
+ File validationFile = new File(defaultSchema);
+ log.debug("Validation file " + defaultSchema + " exists?:" + validationFile.exists());
+ try {
+ validationInputStream = new FileInputStream(validationFile);
+ } catch (FileNotFoundException e) {
+ log.error(e.getMessage(),e);
+ }
+ }
+ if (validationInputStream==null) {
+ log.warn("Could not obtain validation file " + defaultSchema);
+ } else {
+ log.debug("Reading validation info from " + defaultSchema);
+ validationInputSource = new StreamSource(validationInputStream);
+ }
+ return validate(xmlSource,validationInputSource);
}
/**
@@ -234,5 +216,5 @@
public Document getXMLDocument() {
return xmlDocument;
}
-
+
}
More information about the jboss-svn-commits
mailing list