xml validation (no schema)
This commit is contained in:
parent
c68ae255a3
commit
8933fa2273
|
@ -9,12 +9,13 @@ import javax.xml.XMLConstants;
|
||||||
import javax.xml.transform.stream.StreamSource;
|
import javax.xml.transform.stream.StreamSource;
|
||||||
import javax.xml.validation.Schema;
|
import javax.xml.validation.Schema;
|
||||||
import javax.xml.validation.SchemaFactory;
|
import javax.xml.validation.SchemaFactory;
|
||||||
import javax.xml.validation.Validator;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.dom4j.DocumentException;
|
||||||
|
import org.dom4j.DocumentHelper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -46,16 +47,18 @@ public class ResourceValidator {
|
||||||
|
|
||||||
private void validateXml(final String type, final String content) throws InformationServiceException {
|
private void validateXml(final String type, final String content) throws InformationServiceException {
|
||||||
final Schema schema = getXmlSchema(type);
|
final Schema schema = getXmlSchema(type);
|
||||||
if (schema == null) {
|
if (schema != null) {
|
||||||
log.warn("no registered schema for " + type);
|
try {
|
||||||
return;
|
schema.newValidator().validate(new StreamSource(new StringReader(content)));
|
||||||
}
|
} catch (final Exception e) {
|
||||||
final Validator validator = schema.newValidator();
|
throw new InformationServiceException(e.getMessage(), e);
|
||||||
|
}
|
||||||
try {
|
} else {
|
||||||
validator.validate(new StreamSource(new StringReader(content)));
|
try {
|
||||||
} catch (final Exception e) {
|
DocumentHelper.parseText(content);
|
||||||
throw new InformationServiceException(e.getMessage(), e);
|
} catch (final DocumentException e) {
|
||||||
|
throw new InformationServiceException(e.getMessage(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue