-
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.
Browse files
Browse the repository at this point in the history
#26 Implement XML validation
- Loading branch information
Showing
7 changed files
with
81 additions
and
4 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
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
7 changes: 7 additions & 0 deletions
7
src/main/java/com/example/postgresneo4jmigrationtool/parser/validator/Validator.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,7 @@ | ||
package com.example.postgresneo4jmigrationtool.parser.validator; | ||
|
||
public interface Validator { | ||
|
||
void validate(); | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/example/postgresneo4jmigrationtool/parser/validator/XmlValidator.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,35 @@ | ||
package com.example.postgresneo4jmigrationtool.parser.validator; | ||
|
||
import com.jcabi.xml.XML; | ||
import com.jcabi.xml.XSD; | ||
import lombok.Data; | ||
import org.xml.sax.SAXParseException; | ||
|
||
import javax.xml.transform.stream.StreamSource; | ||
import java.io.StringReader; | ||
import java.util.Collection; | ||
|
||
@Data | ||
public class XmlValidator implements Validator { | ||
|
||
private final XML xml; | ||
private final XSD xsd; | ||
private boolean valid = true; | ||
|
||
@Override | ||
public void validate() { | ||
Collection<SAXParseException> errors = xsd.validate( | ||
new StreamSource(new StringReader(xml.toString())) | ||
); | ||
if (!errors.isEmpty()) { | ||
System.out.println("VALIDATION FAILED"); | ||
for (SAXParseException e : errors) { | ||
System.out.println(e.toString()); | ||
} | ||
valid = false; | ||
} else { | ||
valid = true; | ||
} | ||
} | ||
|
||
} |
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