| 1 |
package com.thaiopensource.validation; |
| 2 |
|
| 3 |
import org.xml.sax.SAXException; |
| 4 |
import org.xml.sax.ErrorHandler; |
| 5 |
import org.xml.sax.SAXNotRecognizedException; |
| 6 |
import org.xml.sax.SAXNotSupportedException; |
| 7 |
import org.xml.sax.InputSource; |
| 8 |
import org.w3c.dom.ls.LSResourceResolver; |
| 9 |
|
| 10 |
import javax.xml.transform.Source; |
| 11 |
import javax.xml.transform.sax.SAXSource; |
| 12 |
import javax.xml.transform.stream.StreamSource; |
| 13 |
import javax.xml.validation.SchemaFactory; |
| 14 |
import javax.xml.XMLConstants; |
| 15 |
import java.io.File; |
| 16 |
import java.net.URL; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public abstract class SchemaFactory2 extends SchemaFactory { |
| 25 |
|
| 26 |
private boolean secureProcessing = false; |
| 27 |
private ErrorHandler errorHandler = null; |
| 28 |
private LSResourceResolver resourceResolver = null; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public abstract Schema2 newSchema(SAXSource schema) throws SAXException; |
| 35 |
|
| 36 |
public Schema2 newSchema(Source[] schemas) throws SAXException { |
| 37 |
if (schemas.length != 1) |
| 38 |
throw new UnsupportedOperationException(); |
| 39 |
return newSchema(schemas[0]); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public Schema2 newSchema() throws SAXException { |
| 47 |
throw new UnsupportedOperationException(); |
| 48 |
} |
| 49 |
|
| 50 |
public Schema2 newSchema(Source source) throws SAXException { |
| 51 |
if (source == null) |
| 52 |
throw new NullPointerException(); |
| 53 |
if (source instanceof SAXSource) |
| 54 |
return newSchema((SAXSource)source); |
| 55 |
InputSource inputSource = SAXSource.sourceToInputSource(source); |
| 56 |
|
| 57 |
if (inputSource == null) |
| 58 |
throw new IllegalArgumentException("unsupported type of Source for schema"); |
| 59 |
return newSchema(new SAXSource(inputSource)); |
| 60 |
} |
| 61 |
|
| 62 |
public Schema2 newSchema(File schema) throws SAXException { |
| 63 |
return newSchema(new StreamSource(schema)); |
| 64 |
} |
| 65 |
|
| 66 |
public Schema2 newSchema(URL schema) throws SAXException { |
| 67 |
return newSchema(new StreamSource(schema.toExternalForm())); |
| 68 |
} |
| 69 |
|
| 70 |
public void setErrorHandler(ErrorHandler errorHandler) { |
| 71 |
this.errorHandler = errorHandler; |
| 72 |
} |
| 73 |
|
| 74 |
public ErrorHandler getErrorHandler() { |
| 75 |
return errorHandler; |
| 76 |
} |
| 77 |
|
| 78 |
public void setResourceResolver(LSResourceResolver resourceResolver) { |
| 79 |
this.resourceResolver = resourceResolver; |
| 80 |
} |
| 81 |
|
| 82 |
public LSResourceResolver getResourceResolver() { |
| 83 |
return resourceResolver; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { |
| 94 |
if (XMLConstants.FEATURE_SECURE_PROCESSING.equals(name)) |
| 95 |
secureProcessing = value; |
| 96 |
else |
| 97 |
super.setFeature(name, value); |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException { |
| 108 |
if (XMLConstants.FEATURE_SECURE_PROCESSING.equals(name)) |
| 109 |
return secureProcessing; |
| 110 |
return super.getFeature(name); |
| 111 |
} |
| 112 |
|
| 113 |
public void setSecureProcessing(boolean secureProcessing) { |
| 114 |
this.secureProcessing = secureProcessing; |
| 115 |
} |
| 116 |
|
| 117 |
public boolean getSecureProcessing() { |
| 118 |
return secureProcessing; |
| 119 |
} |
| 120 |
} |