some cleanup

This commit is contained in:
Andreas Penski 2020-05-03 16:52:55 +02:00
parent 1a001a1af4
commit 7dc62012a6
22 changed files with 144 additions and 50 deletions

View file

@ -1,5 +1,7 @@
package de.kosit.validationtool.impl;
import lombok.SneakyThrows;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
@ -65,6 +67,10 @@ public class EngineInformation {
return getFrameworkVersion().substring(0, 1);
}
public static String getBuild() {
return PROPERTIES.getProperty("build_number");
}
/**
* Gibt den Namespace des eingesetzten Frameworks zurück.
*

View file

@ -60,7 +60,7 @@ public class ComputeAcceptanceAction implements CheckAction {
} catch (final SaxonApiException e) {
final String msg = String.format("Error evaluating accept recommendation: %s", selector.getUnderlyingXPathContext().toString());
log.error(msg, e);
results.addProcessingError(msg);
results.stopProcessing(msg);
}
}

View file

@ -28,6 +28,7 @@ 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;
@ -64,6 +65,7 @@ import net.sf.saxon.s9api.XsltTransformer;
* @author Andreas Penski
*/
@RequiredArgsConstructor
@Slf4j
public class CreateReportAction implements CheckAction {
/**
@ -206,7 +208,8 @@ public class CreateReportAction implements CheckAction {
results.setReport(destination.getXdmNode());
} catch (final SaxonApiException | SAXException | JAXBException e) {
throw new IllegalStateException("Can not create final report", e);
log.error("Error creating final report", e);
results.stopProcessing("Can not create final report: " + e.getMessage());
}
}

View file

@ -94,16 +94,5 @@ public class RelativeUriResolver implements URIResolver {
}
public Reader resolve(final URI absoluteURI, final String encoding, final Configuration config) throws XPathException {
if (isUnderBaseUri(absoluteURI)) {
try {
return new InputStreamReader(absoluteURI.toURL().openStream(), encoding);
} catch (final IOException e) {
throw new IllegalStateException(String.format("Can not resolve required %s", absoluteURI), e);
}
} else {
throw new IllegalStateException(String.format(
"The resolved transformation artifact %s is not within the configured repository %s", absoluteURI, this.baseUri));
}
}
}

View file

@ -0,0 +1,7 @@
package de.kosit.validationtool.impl.xml;
public class RemoteResolvingStrategy extends StrictLocalResolvingStrategy {
}

View file

@ -10,7 +10,9 @@ import javax.xml.validation.Validator;
import lombok.extern.slf4j.Slf4j;
/**
*
* This is a slightly more open implementation that allows resolving artifacts from local filesystems. Your are not
* bound to a specific 'repository'. But your validation artifacts (schema, xsl, etc.) must be available locally. This
* implementation does not allow loading from http sources
*
* @author Andreas Penski
*/
@ -18,16 +20,23 @@ import lombok.extern.slf4j.Slf4j;
public class StrictLocalResolvingStrategy extends StrictRelativeResolvingStrategy {
/**
* e.g. don't allow any scheme
* Allow loading schema files from any local location.
*
* @return a configured {@link SchemaFactory}
*/
@Override
public SchemaFactory createSchemaFactory() {
final SchemaFactory schemaFactory = super.createSchemaFactory();
allowExternalSchema(schemaFactory, "file", "jar");
allowExternalSchema(schemaFactory, "file");
return schemaFactory;
}
/**
* The default resolver is able to resolve locally and relative.
*
* @param repository the repository is not used by this strategy
* @return null!
*/
@Override
public URIResolver createResolver(final URI repository) {
// intentionally return 'null', since all resolving is configured with the other objects
@ -37,7 +46,7 @@ public class StrictLocalResolvingStrategy extends StrictRelativeResolvingStrateg
@Override
public Validator createValidator(final Schema schema) {
final Validator validator = super.createValidator(schema);
allowExternalSchema(validator, "file", "jar");
allowExternalSchema(validator, "file");
return validator;
}

View file

@ -95,6 +95,7 @@ public class StrictRelativeResolvingStrategy extends BaseResolvingStrategy {
processor.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(FEATURE_SECURE_PROCESSING), true);
processor.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(DISSALLOW_DOCTYPE_DECL_FEATURE), true);
processor.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(LOAD_EXTERNAL_DTD_FEATURE), false);
processor.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(XMLConstants.ACCESS_EXTERNAL_DTD), false);
return processor;
}