Skip to content

Commit

Permalink
#132 new jcabi-xml
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Dec 1, 2024
1 parent b285582 commit 5db31e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ SOFTWARE.
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-xml</artifactId>
<version>0.30.1</version>
<version>0.31.0</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
Expand Down
29 changes: 19 additions & 10 deletions src/main/java/com/yegor256/xsline/StSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@
package com.yegor256.xsline;

import com.jcabi.xml.XML;
import com.jcabi.xml.XSD;
import com.jcabi.xml.XSDDocument;
import com.jcabi.xml.XMLDocument;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import javax.xml.transform.dom.DOMSource;
import org.xml.sax.SAXParseException;

/**
Expand All @@ -45,6 +43,13 @@
*/
public final class StSchema extends StEnvelope {

/**
* Ctor.
*/
public StSchema() {
this((XML) null);
}

/**
* Ctor.
* @param path The path of XSD document in classpath
Expand All @@ -59,14 +64,14 @@ public StSchema(final String path) {
* @throws FileNotFoundException If file not found
*/
public StSchema(final Path path) throws FileNotFoundException {
this(new XSDDocument(path));
this(new XMLDocument(path));
}

/**
* Ctor.
* @param schema The schema
*/
public StSchema(final XSD schema) {
public StSchema(final XML schema) {
super(
new StLambda(
"xsd-schema",
Expand All @@ -81,9 +86,13 @@ public StSchema(final XSD schema) {
* @param xml The XML
* @return The same XML
*/
private static XML validate(final XSD schema, final XML xml) {
final Collection<SAXParseException> violations =
schema.validate(new DOMSource(xml.node()));
private static XML validate(final XML schema, final XML xml) {
final Collection<SAXParseException> violations;
if (schema == null) {
violations = xml.validate();
} else {
violations = xml.validate(schema);
}
if (!violations.isEmpty()) {
final Collection<String> msgs = new ArrayList<>(violations.size());
for (final SAXParseException violation : violations) {
Expand Down Expand Up @@ -112,7 +121,7 @@ private static XML validate(final XSD schema, final XML xml) {
* @param path Path in classpath
* @return XSD
*/
private static XSD make(final String path) {
private static XML make(final String path) {
final URL url = StClasspath.class.getResource(path);
if (url == null) {
throw new IllegalArgumentException(
Expand All @@ -122,7 +131,7 @@ private static XSD make(final String path) {
);
}
try {
return new XSDDocument(url);
return new XMLDocument(url);
} catch (final IOException ex) {
throw new IllegalStateException(
String.format("Failed to read '%s' from classpath", path),
Expand Down

0 comments on commit 5db31e4

Please sign in to comment.