-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Edirom/feature/validation
enable validation for all MEI versions and customizations in 4.0.1 us…
- Loading branch information
Showing
5 changed files
with
162 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/main/java/de/edirom/meigarage/StandardErrorHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package de.edirom.meigarage; | ||
|
||
import org.xml.sax.ErrorHandler; | ||
import org.xml.sax.SAXException; | ||
import org.xml.sax.SAXParseException; | ||
import pl.psnc.dl.ege.types.ValidationResult; | ||
|
||
/** | ||
* Catches errors received during XML validation process | ||
* of SAX parser. <br/> | ||
* | ||
* Each object contains one {@link ValidationResult} instance - where | ||
* all received notifications are stored. Depending on received errors | ||
* status of validation result is changed.<br/> | ||
* | ||
* After validation, validation result instance can be retrieved in order | ||
* to read status and contained messages. | ||
* | ||
* @author mariuszs | ||
* | ||
*/ | ||
public class StandardErrorHandler | ||
implements ErrorHandler | ||
{ | ||
|
||
private final ValidationResult valResult; | ||
|
||
/** | ||
* Constructs error handler with validation result of SUCCESS status. | ||
*/ | ||
public StandardErrorHandler(){ | ||
valResult = new ValidationResult(ValidationResult.Status.SUCCESS); | ||
} | ||
|
||
/** | ||
* Constructs error handler with specified validation result instance. | ||
* If referenced valResult parameter is 'null' a default instance is created. | ||
* | ||
* @param valResult | ||
*/ | ||
public StandardErrorHandler(ValidationResult valResult){ | ||
if(valResult == null){ | ||
valResult = new ValidationResult(ValidationResult.Status.SUCCESS); | ||
} | ||
this.valResult = valResult; | ||
} | ||
|
||
public void error(SAXParseException exception) | ||
throws SAXException | ||
{ | ||
valResult.putMessage( | ||
"Error in line (" + exception.getLineNumber() + "), column (" | ||
+ exception.getColumnNumber() + ") : " | ||
+ exception.getMessage()); | ||
if(!valResult.getStatus().equals(ValidationResult.Status.FATAL)){ | ||
valResult.setStatus(ValidationResult.Status.ERROR); | ||
} | ||
} | ||
|
||
|
||
public void fatalError(SAXParseException exception) | ||
throws SAXException | ||
{ | ||
valResult.putMessage( | ||
"Fatal error! in line (" + exception.getLineNumber() | ||
+ "), column (" + exception.getColumnNumber() + ") : " | ||
+ exception.getMessage()); | ||
valResult.setStatus(ValidationResult.Status.FATAL); | ||
} | ||
|
||
|
||
public void warning(SAXParseException exception) | ||
throws SAXException | ||
{ | ||
valResult.putMessage( | ||
"Warning in line (" + exception.getLineNumber() + "), column (" | ||
+ exception.getColumnNumber() + ") : " | ||
+ exception.getMessage()); | ||
} | ||
|
||
/** | ||
* Returns contained validation result instance. | ||
* | ||
* @return | ||
*/ | ||
public ValidationResult getValidationResult() | ||
{ | ||
return valResult; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<validators> | ||
<validator format="MEI 4.0" mimeType="text/xml" rng="https://raw.githubusercontent.com/music-encoding/music-encoding/develop/schemata/mei-all.rng"/> | ||
<validator format="MEI 2.1.1" mimeType="text/xml" | ||
rng="https://raw.githubusercontent.com/music-encoding/schema/main/2.1.1/mei-all.rng"/> | ||
<validator format="MEI 3.0.0" mimeType="text/xml" | ||
rng="https://raw.githubusercontent.com/music-encoding/schema/main/3.0.0/mei-all.rng"/> | ||
<validator format="MEI 4.0.0" mimeType="text/xml" | ||
rng="https://raw.githubusercontent.com/music-encoding/schema/main/4.0.0/mei-all.rng"/> | ||
<validator format="MEI 4.0.1" mimeType="text/xml" | ||
rng="https://raw.githubusercontent.com/music-encoding/schema/main/4.0.1/mei-all.rng"/> | ||
<validator format="MEI dev" mimeType="text/xml" | ||
rng="https://raw.githubusercontent.com/music-encoding/schema/main/dev/mei-all.rng"/> | ||
<validator format="MEI 4.0.0" mimeType="text/xml" | ||
rng="https://raw.githubusercontent.com/music-encoding/schema/main/4.0.0/mei-all.rng"/> | ||
<validator format="MEI 4.0.1 all any" mimeType="text/xml" | ||
rng="https://raw.githubusercontent.com/music-encoding/schema/4.0.1/mei-all_anyStart.rng"/> | ||
<validator format="MEI 4.0.1 cmn" mimeType="text/xml" | ||
rng="https://raw.githubusercontent.com/music-encoding/schema/4.0.1/mei-CMN.rng"/> | ||
<validator format="MEI 4.0.1 mensural" mimeType="text/xml" | ||
rng="https://raw.githubusercontent.com/music-encoding/schema/4.0.1/mei-Mensural.rng "/> | ||
<validator format="MEI 4.0.1 neumes" mimeType="text/xml" | ||
rng="https://raw.githubusercontent.com/music-encoding/schema/4.0.1/mei-Neumes.rng"/> | ||
</validators> |