Search in sources :

Example 6 with XmlStreamReader

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);
    }
}
Also used : XmlStreamReader(org.apache.commons.io.input.XmlStreamReader)

Example 7 with XmlStreamReader

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);
    }
}
Also used : Schema(javax.xml.validation.Schema) StreamSource(javax.xml.transform.stream.StreamSource) Reader(java.io.Reader) XmlStreamReader(org.apache.commons.io.input.XmlStreamReader) XmlStreamReader(org.apache.commons.io.input.XmlStreamReader) IOException(java.io.IOException) Validator(javax.xml.validation.Validator) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException)

Aggregations

XmlStreamReader (org.apache.commons.io.input.XmlStreamReader)7 IOException (java.io.IOException)4 File (java.io.File)3 Reader (java.io.Reader)2 StringReader (java.io.StringReader)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 SAXParser (javax.xml.parsers.SAXParser)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Schema (javax.xml.validation.Schema)1 Validator (javax.xml.validation.Validator)1 DecorationModel (org.apache.maven.doxia.site.decoration.DecorationModel)1 DecorationXpp3Reader (org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader)1 SiteToolException (org.apache.maven.doxia.tools.SiteToolException)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MavenReportException (org.apache.maven.reporting.MavenReportException)1 MavenFileFilterRequest (org.apache.maven.shared.filtering.MavenFileFilterRequest)1 MavenFilteringException (org.apache.maven.shared.filtering.MavenFilteringException)1 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)1