dion 2004/09/07 21:52:07
Modified:
jelly/jelly-tags/validate/src/java/org/apache/commons/jelly/tags/validate
ValidateTag.java VerifierTag.java
Log:
detab
Revision Changes Path
1.5 +58 -58
jakarta-commons/jelly/jelly-tags/validate/src/java/org/apache/commons/jelly/tags/validate/ValidateTag.java
Index: ValidateTag.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/jelly/jelly-tags/validate/src/java/org/apache/commons/jelly/tags/validate/ValidateTag.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ValidateTag.java 25 Feb 2004 01:31:58 -0000 1.4
+++ ValidateTag.java 8 Sep 2004 04:52:07 -0000 1.5
@@ -1,12 +1,12 @@
/*
* Copyright 2002,2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -28,7 +28,7 @@
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.AttributesImpl;
-/**
+/**
* This tag validates its body using a schema Verifier which can
* validate against DTDs, XML Schema, RelaxNG, Relax or TREX.
* Any JARV compliant Verifier could be used.
@@ -44,130 +44,130 @@
/** The SAX ErrorHandler */
private ErrorHandler errorHandler;
-
+
/** The boolean flag for whether the XML is valid */
private String var;
-
+
// Tag interface
- //-------------------------------------------------------------------------
- public void doTag(final XMLOutput output) throws MissingAttributeException,
JellyTagException {
+ //-------------------------------------------------------------------------
+ public void doTag(final XMLOutput output) throws MissingAttributeException,
JellyTagException {
if ( verifier == null ) {
throw new MissingAttributeException("verifier");
}
boolean valid = false;
-
- // evaluate the body using the current Verifier
+
+ // evaluate the body using the current Verifier
if ( errorHandler != null ) {
-
+
try {
// we are redirecting errors to another handler
// so just filter the body
- VerifierFilter filter = verifier.getVerifierFilter();
-
+ VerifierFilter filter = verifier.getVerifierFilter();
+
// now install the current output in the filter chain...
// ####
-
+
ContentHandler handler = filter.getContentHandler();
handler.startDocument();
invokeBody( new XMLOutput( handler ) );
handler.endDocument();
valid = filter.isValid();
- }
+ }
catch (SAXException e) {
throw new JellyTagException(e);
}
}
else {
- // outputting the errors to the current output
- verifier.setErrorHandler(
- new ErrorHandler() {
- public void error(SAXParseException exception) throws
SAXException {
- outputException(output, "error", exception);
- }
-
- public void fatalError(SAXParseException exception) throws
SAXException {
- outputException(output, "fatalError", exception);
- }
-
- public void warning(SAXParseException exception) throws
SAXException {
- outputException(output, "warning", exception);
- }
- }
- );
-
+ // outputting the errors to the current output
+ verifier.setErrorHandler(
+ new ErrorHandler() {
+ public void error(SAXParseException exception) throws
SAXException {
+ outputException(output, "error", exception);
+ }
+
+ public void fatalError(SAXParseException exception) throws
SAXException {
+ outputException(output, "fatalError", exception);
+ }
+
+ public void warning(SAXParseException exception) throws
SAXException {
+ outputException(output, "warning", exception);
+ }
+ }
+ );
+
try {
- VerifierHandler handler = verifier.getVerifierHandler();
+ VerifierHandler handler = verifier.getVerifierHandler();
handler.startDocument();
- invokeBody( new XMLOutput( handler ) );
+ invokeBody( new XMLOutput( handler ) );
handler.endDocument();
valid = handler.isValid();
- }
+ }
catch (SAXException e) {
throw new JellyTagException(e);
}
}
handleValid(valid);
}
-
+
// Properties
- //-------------------------------------------------------------------------
+ //-------------------------------------------------------------------------
- /**
+ /**
* Sets the schema Verifier that this tag will use to verify its body
- *
+ *
* @jelly:required
*/
public void setVerifier(Verifier verifier) {
this.verifier = verifier;
}
-
+
/**
* @return the ErrorHandler used when validating
*/
public ErrorHandler getErrorHandler() {
return errorHandler;
}
-
- /**
- * Sets the SAX ErrorHandler which is used to capture
- * XML validation events.
+
+ /**
+ * Sets the SAX ErrorHandler which is used to capture
+ * XML validation events.
* If an ErrorHandler is specified
* then this tag will output its body and redirect all error messages
* to the ErrorHandler.
* If no ErrorHandler is specified then this tag will just output the
* error messages as XML events
- *
+ *
* @jelly:optional
*/
public void setErrorHandler(ErrorHandler errorHandler) {
this.errorHandler = errorHandler;
}
-
- /**
- * Sets the name of the variable that will contain a boolean flag for whether
or
- * not the XML is valid.
- *
+
+ /**
+ * Sets the name of the variable that will contain a boolean flag for whether or
+ * not the XML is valid.
+ *
* @jelly:optional
*/
public void setVar(String var) {
this.var = var;
}
-
+
// Implementation methods
- //-------------------------------------------------------------------------
-
+ //-------------------------------------------------------------------------
+
/**
* Processes whether or not the document is valid.
- * Derived classes can overload this method to do different things, such
+ * Derived classes can overload this method to do different things, such
* as to throw assertion exceptions etc.
- */
+ */
protected void handleValid(boolean valid) {
if (var != null ) {
Boolean value = (valid) ? Boolean.TRUE : Boolean.FALSE;
context.setVariable(var, value);
}
}
-
+
/**
* Outputs the given validation exception as XML to the output
*/
@@ -191,6 +191,6 @@
output.write( e.getMessage() );
output.endElement( uri, name, name );
}
-
+
}
1.9 +60 -60
jakarta-commons/jelly/jelly-tags/validate/src/java/org/apache/commons/jelly/tags/validate/VerifierTag.java
Index: VerifierTag.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/jelly/jelly-tags/validate/src/java/org/apache/commons/jelly/tags/validate/VerifierTag.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- VerifierTag.java 25 Feb 2004 01:31:58 -0000 1.8
+++ VerifierTag.java 8 Sep 2004 04:52:07 -0000 1.9
@@ -1,12 +1,12 @@
/*
* Copyright 2002,2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -32,7 +32,7 @@
import org.iso_relax.verifier.VerifierFactory;
import org.xml.sax.SAXException;
-/**
+/**
* This tag creates a new Verifier of a schema as a variable
* so that it can be used by a <validate> tag.
*
@@ -43,22 +43,22 @@
/** the variable name to export the Verifier as */
private String var;
-
+
/** The URI to load the schema from */
private String uri;
-
+
/** The file to load the schema from */
private File file;
-
+
/** The system ID to use when parsing the schema */
private String systemId;
/** The factory used to create new schema verifier objects */
private VerifierFactory factory;
-
+
// Tag interface
- //-------------------------------------------------------------------------
- public void doTag(final XMLOutput output) throws MissingAttributeException,
JellyTagException {
+ //-------------------------------------------------------------------------
+ public void doTag(final XMLOutput output) throws MissingAttributeException,
JellyTagException {
if ( var == null ) {
throw new MissingAttributeException("var");
}
@@ -70,11 +70,11 @@
throw new JellyTagException( "Could not find resource for uri: " +
uri );
}
} else if (file != null) {
- try {
- in = new FileInputStream(file);
- } catch (FileNotFoundException e) {
- throw new JellyTagException(e);
- }
+ try {
+ in = new FileInputStream(file);
+ } catch (FileNotFoundException e) {
+ throw new JellyTagException(e);
+ }
} else {
String text = getBodyText();
in = new ByteArrayInputStream( text.getBytes() );
@@ -92,32 +92,32 @@
else{
schema = getFactory().compileSchema(in);
}
-
+
if ( schema == null ) {
throw new JellyTagException( "Could not create a valid schema" );
}
verifier = schema.newVerifier();
- }
+ }
catch (VerifierConfigurationException e) {
throw new JellyTagException(e);
}
catch (SAXException e) {
throw new JellyTagException(e);
- }
+ }
catch (IOException e) {
throw new JellyTagException(e);
}
-
+
context.setVariable(var, verifier);
}
-
+
// Properties
- //-------------------------------------------------------------------------
+ //-------------------------------------------------------------------------
- /**
+ /**
* Sets the name of the variable that will be set to the new Verifier
- *
+ *
* @jelly:required
*/
public void setVar(String var) {
@@ -127,64 +127,64 @@
/**
* Sets the URI of the schema file to parse. If no URI and no file is
* specified then the body of this tag is used as the source of the schema
- *
+ *
* @jelly:optional
- */
+ */
public void setUri(String uri) {
this.uri = uri;
}
- /**
- * Sets the [EMAIL PROTECTED] File} of the schema to parse. If no URI and no
file is
- * specified then the body of this tag is used as the source of the schema
- *
- * @jelly:optional
- */
- public void setFile(File aFile) {
- file = aFile;
- }
+ /**
+ * Sets the [EMAIL PROTECTED] File} of the schema to parse. If no URI and no
file is
+ * specified then the body of this tag is used as the source of the schema
+ *
+ * @jelly:optional
+ */
+ public void setFile(File aFile) {
+ file = aFile;
+ }
/**
* Sets the system ID used when parsing the schema
- *
+ *
* @jelly:optional
- */
+ */
public void setSystemId(String systemId) {
this.systemId = systemId;
}
- /**
+ /**
* Sets the factory used to create new schema verifier objects.
* If none is provided then the default MSV factory is used.
- *
+ *
* @jelly:optional
*/
public void setFactory(VerifierFactory factory) {
this.factory = factory;
}
-
+
public VerifierFactory getFactory() throws JellyTagException {
- if ( factory == null ) {
- try {
- ClassLoader loader =
Thread.currentThread().getContextClassLoader();
- if (loader == null) {
- loader = getClass().getClassLoader();
- }
- factory = (VerifierFactory)loader.loadClass(
-
"com.sun.msv.verifier.jarv.TheFactoryImpl").newInstance();
- } catch (ClassNotFoundException e) {
- throw new JellyTagException(e);
- } catch (InstantiationException e) {
- throw new JellyTagException(e);
- } catch (IllegalAccessException e) {
- throw new JellyTagException(e);
- }
- }
- return factory;
+ if ( factory == null ) {
+ try {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ if (loader == null) {
+ loader = getClass().getClassLoader();
+ }
+ factory = (VerifierFactory)loader.loadClass(
+ "com.sun.msv.verifier.jarv.TheFactoryImpl").newInstance();
+ } catch (ClassNotFoundException e) {
+ throw new JellyTagException(e);
+ } catch (InstantiationException e) {
+ throw new JellyTagException(e);
+ } catch (IllegalAccessException e) {
+ throw new JellyTagException(e);
+ }
+ }
+ return factory;
}
-
+
// Implementation methods
- //-------------------------------------------------------------------------
-
+ //-------------------------------------------------------------------------
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]