mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-26 01:05:38 +00:00
#59 fix unparsed text uri resolving
This commit is contained in:
parent
13de7f00a4
commit
0717e22d33
10 changed files with 58 additions and 16 deletions
|
|
@ -52,6 +52,7 @@ import de.kosit.validationtool.model.scenarios.ResourceType;
|
|||
import de.kosit.validationtool.model.scenarios.ScenarioType;
|
||||
import de.kosit.validationtool.model.scenarios.ValidateWithSchematron;
|
||||
|
||||
import net.sf.saxon.lib.UnparsedTextURIResolver;
|
||||
import net.sf.saxon.s9api.Processor;
|
||||
import net.sf.saxon.s9api.SaxonApiException;
|
||||
import net.sf.saxon.s9api.XPathCompiler;
|
||||
|
|
@ -77,6 +78,8 @@ public class ContentRepository {
|
|||
|
||||
private final URIResolver resolver;
|
||||
|
||||
private final UnparsedTextURIResolver unparsedTextURIResolver;
|
||||
|
||||
private final SchemaFactory schemaFactory;
|
||||
|
||||
@Getter
|
||||
|
|
@ -94,6 +97,7 @@ public class ContentRepository {
|
|||
this.resolvingConfigurationStrategy = strategy;
|
||||
this.processor = this.resolvingConfigurationStrategy.getProcessor();
|
||||
this.resolver = this.resolvingConfigurationStrategy.createResolver(repository);
|
||||
this.unparsedTextURIResolver = this.resolvingConfigurationStrategy.createUnparsedTextURIResolver(repository);
|
||||
this.schemaFactory = this.resolvingConfigurationStrategy.createSchemaFactory();
|
||||
}
|
||||
|
||||
|
|
@ -251,14 +255,18 @@ public class ContentRepository {
|
|||
}
|
||||
|
||||
/**
|
||||
* Erzeugt einen resolver für dieses Repository, der nur relativ auflösen kann
|
||||
* Returns the {@link URIResolver} to use for resolving xml artifacts.
|
||||
*
|
||||
* @return ein neuer Resolver
|
||||
* @return the resolver
|
||||
*/
|
||||
public URIResolver getResolver() {
|
||||
return this.resolver;
|
||||
}
|
||||
|
||||
public UnparsedTextURIResolver getUnparsedTextURIResolver() {
|
||||
return this.unparsedTextURIResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt eine Transformation zurück.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -85,7 +85,8 @@ public class DefaultCheck implements Check {
|
|||
this.checkSteps.add(new SchemaValidationAction(content.getResolvingConfigurationStrategy(), processor));
|
||||
this.checkSteps.add(new SchematronValidationAction(content.getResolver(), this.conversionService));
|
||||
this.checkSteps.add(new ValidateReportInputAction(this.conversionService, content.getReportInputSchema()));
|
||||
this.checkSteps.add(new CreateReportAction(processor, this.conversionService, content.getResolver()));
|
||||
this.checkSteps.add(
|
||||
new CreateReportAction(processor, this.conversionService, content.getResolver(), content.getUnparsedTextURIResolver()));
|
||||
this.checkSteps.add(new ComputeAcceptanceAction());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import javax.xml.bind.Marshaller;
|
|||
import javax.xml.bind.util.JAXBSource;
|
||||
import javax.xml.transform.URIResolver;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.DTDHandler;
|
||||
import org.xml.sax.EntityResolver;
|
||||
|
|
@ -41,6 +40,7 @@ import org.xml.sax.XMLReader;
|
|||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import de.kosit.validationtool.impl.CollectingErrorEventHandler;
|
||||
import de.kosit.validationtool.impl.ConversionService;
|
||||
|
|
@ -48,6 +48,7 @@ import de.kosit.validationtool.impl.EngineInformation;
|
|||
import de.kosit.validationtool.impl.Scenario;
|
||||
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
|
||||
|
||||
import net.sf.saxon.lib.UnparsedTextURIResolver;
|
||||
import net.sf.saxon.s9api.BuildingContentHandler;
|
||||
import net.sf.saxon.s9api.DocumentBuilder;
|
||||
import net.sf.saxon.s9api.Processor;
|
||||
|
|
@ -175,6 +176,8 @@ public class CreateReportAction implements CheckAction {
|
|||
|
||||
private final URIResolver resolver;
|
||||
|
||||
private final UnparsedTextURIResolver unparsedTextURIResolver;
|
||||
|
||||
private static XsltExecutable loadFromScenario(final Scenario object) {
|
||||
return object.getReportTransformation().getExecutable();
|
||||
}
|
||||
|
|
@ -198,7 +201,9 @@ public class CreateReportAction implements CheckAction {
|
|||
final CollectingErrorEventHandler e = new CollectingErrorEventHandler();
|
||||
transformer.setMessageListener(e);
|
||||
transformer.setURIResolver(this.resolver);
|
||||
// transformer.getUnderlyingController().setUnparsedTextURIResolver(resolver);
|
||||
if (this.unparsedTextURIResolver != null) {
|
||||
transformer.getUnderlyingController().setUnparsedTextURIResolver(this.unparsedTextURIResolver);
|
||||
}
|
||||
if (parsedDocument != null) {
|
||||
transformer.setParameter(new QName("input-document"), parsedDocument);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
package de.kosit.validationtool.impl.xml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.net.URI;
|
||||
|
||||
|
|
@ -32,6 +31,8 @@ import javax.xml.transform.stream.StreamSource;
|
|||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import net.sf.saxon.Configuration;
|
||||
import net.sf.saxon.lib.StandardUnparsedTextResolver;
|
||||
import net.sf.saxon.lib.UnparsedTextURIResolver;
|
||||
import net.sf.saxon.trans.XPathException;
|
||||
|
||||
/**
|
||||
|
|
@ -41,7 +42,7 @@ import net.sf.saxon.trans.XPathException;
|
|||
* @author Andreas Penski
|
||||
*/
|
||||
@RequiredArgsConstructor()
|
||||
public class RelativeUriResolver implements URIResolver {
|
||||
public class RelativeUriResolver implements URIResolver, UnparsedTextURIResolver {
|
||||
|
||||
/** the base uri */
|
||||
private final URI baseUri;
|
||||
|
|
@ -93,6 +94,16 @@ public class RelativeUriResolver implements URIResolver {
|
|||
return r.startsWith(base);
|
||||
}
|
||||
|
||||
// from UnparsedTextURIResolver
|
||||
@Override
|
||||
public Reader resolve(final URI absoluteURI, final String encoding, final Configuration config) throws XPathException {
|
||||
if (isUnderBaseUri(absoluteURI, this.baseUri)) {
|
||||
return new StandardUnparsedTextResolver().resolve(absoluteURI, encoding, config);
|
||||
} else {
|
||||
throw new XPathException(String.format("The resolved transformation artifact %s is not within the configured repository %s",
|
||||
absoluteURI, this.baseUri));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -109,6 +109,11 @@ public class StrictRelativeResolvingStrategy extends BaseResolvingStrategy {
|
|||
return new RelativeUriResolver(repositoryURI);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnparsedTextURIResolver createUnparsedTextURIResolver(final URI scenarioRepository) {
|
||||
return new RelativeUriResolver(scenarioRepository);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Validator createValidator(final Schema schema) {
|
||||
if (schema == null) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue