use of org.apache.commons.io.input.XmlStreamReader in project maven-plugins by apache.
the class EjbMojo method getEncoding.
/**
* Get the encoding from an XML-file.
*
* @param xmlFile the XML-file
* @return The encoding of the XML-file, or UTF-8 if it's not specified in the file
* @throws IOException if an error occurred while reading the file
*/
private String getEncoding(File xmlFile) throws IOException {
XmlStreamReader xmlReader = null;
try {
xmlReader = new XmlStreamReader(xmlFile);
final String encoding = xmlReader.getEncoding();
xmlReader.close();
xmlReader = null;
return encoding;
} finally {
IOUtils.closeQuietly(xmlReader);
}
}
use of org.apache.commons.io.input.XmlStreamReader in project maven-plugins by apache.
the class DefaultChangesSchemaValidator method validateXmlWithSchema.
public XmlValidationHandler validateXmlWithSchema(File file, String schemaVersion, boolean failOnValidationError) throws SchemaValidatorException {
Reader reader = null;
try {
String schemaPath = CHANGES_SCHEMA_PATH + "changes-" + schemaVersion + ".xsd";
Schema schema = getSchema(schemaPath);
Validator validator = schema.newValidator();
XmlValidationHandler baseHandler = new XmlValidationHandler(failOnValidationError);
validator.setErrorHandler(baseHandler);
reader = new XmlStreamReader(file);
validator.validate(new StreamSource(reader));
reader.close();
reader = null;
return baseHandler;
} catch (IOException e) {
throw new SchemaValidatorException("IOException : " + e.getMessage(), e);
} catch (SAXException e) {
throw new SchemaValidatorException("SAXException : " + e.getMessage(), e);
} catch (Exception e) {
throw new SchemaValidatorException("Exception : " + e.getMessage(), e);
} finally {
IOUtil.close(reader);
}
}
Aggregations