Skip to content

Commit

Permalink
A bit of code hgyiene tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
ndw committed Apr 16, 2023
1 parent b4d94b0 commit 62a0e1c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/xmlcalabash/core/XProcRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,14 @@ public XProcRuntime(XProcConfiguration config) {

try {
if (config.uriResolver != null) {
uriResolver.setUnderlyingURIResolver(Class.forName(config.uriResolver).asSubclass(URIResolver.class).newInstance());
uriResolver.setUnderlyingURIResolver(Class.forName(config.uriResolver).asSubclass(URIResolver.class).getDeclaredConstructor().newInstance());
}
if (config.entityResolver != null) {
uriResolver.setUnderlyingEntityResolver(Class.forName(config.entityResolver).asSubclass(EntityResolver.class).newInstance());
uriResolver.setUnderlyingEntityResolver(Class.forName(config.entityResolver).asSubclass(EntityResolver.class).getDeclaredConstructor().newInstance());
}

if (config.errorListener != null) {
msgListener = Class.forName(config.errorListener).asSubclass(XProcMessageListener.class).newInstance();
msgListener = Class.forName(config.errorListener).asSubclass(XProcMessageListener.class).getDeclaredConstructor().newInstance();
} else {
msgListener = new DefaultXProcMessageListener();
}
Expand Down Expand Up @@ -280,7 +280,7 @@ public XProcRuntime(XProcConfiguration config) {
Object def = null;

try {
def = Class.forName(className).newInstance();
def = Class.forName(className).getDeclaredConstructor().newInstance();
} catch (Throwable e) {
logger.trace("Attempting to instantiate " + className + " with processor context");
Class<?> cl = Class.forName(className);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/xmlcalabash/extensions/CssFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void run() throws SaxonApiException {

final CssProcessor provider;
try {
provider = (CssProcessor) Class.forName(cssClass).newInstance();
provider = (CssProcessor) Class.forName(cssClass).getDeclaredConstructor().newInstance();
provider.initialize(runtime,step,options);
} catch (Exception e) {
logger.debug(e.getMessage(), e);
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/com/xmlcalabash/library/ValidateWithSCH.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.xmlcalabash.runtime.XAtomicStep;
import com.xmlcalabash.util.S9apiUtils;
import net.sf.saxon.Configuration;
import net.sf.saxon.lib.ResourceRequest;
import net.sf.saxon.lib.ResourceResolver;
import net.sf.saxon.om.NamespaceUri;
import net.sf.saxon.om.StructuredQName;
import net.sf.saxon.s9api.QName;
Expand Down Expand Up @@ -131,7 +133,7 @@ public void run() throws SaxonApiException {

compiler = runtime.getProcessor().newXsltCompiler();
compiler.setSchemaAware(schemaAware);
compiler.setURIResolver(new UResolver());
compiler.setResourceResolver(new UResolver());
exec = compiler.compile(getSchematronXSLT("iso_svrl_for_xslt2.xsl"));
XsltTransformer schemaCompiler = exec.load();

Expand Down Expand Up @@ -239,13 +241,13 @@ private boolean checkFailedAssert(XdmNode doc) {
return results.size() != 0;
}

private class UResolver implements URIResolver {

public Source resolve(String href, String base) throws TransformerException {
if ("iso_schematron_skeleton_for_saxon.xsl".equals(href)) {
private class UResolver implements ResourceResolver {
@Override
public Source resolve(ResourceRequest request) throws XPathException {
if ("iso_schematron_skeleton_for_saxon.xsl".equals(request.relativeUri)) {
return new SAXSource(new InputSource(skeleton));
} else {
throw new XProcException(step.getNode(), "Failed to resolve " + href + " from JAR file.");
throw new XProcException(step.getNode(), "Failed to resolve " + request.uri + " from JAR file.");
}
}
}
Expand All @@ -262,7 +264,7 @@ private SAXSource getSchematronXSLT(String xslt) {
private XdmNode transform(XdmNode source, SAXSource stylesheet) throws SaxonApiException {
XsltCompiler compiler = runtime.getProcessor().newXsltCompiler();
compiler.setSchemaAware(schemaAware);
compiler.setURIResolver(new UResolver());
compiler.setResourceResolver(new UResolver());
XsltExecutable exec = compiler.compile(stylesheet);
XsltTransformer schemaCompiler = exec.load();

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/xmlcalabash/library/XSLFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void run() throws SaxonApiException {
for (String className : foClasses) {
if (provider == null) {
try {
provider = (FoProcessor) Class.forName(className).newInstance();
provider = (FoProcessor) Class.forName(className).getDeclaredConstructor().newInstance();
provider.initialize(runtime,step,options);
break;
} catch (NoClassDefFoundError ncdfe) {
Expand Down

0 comments on commit 62a0e1c

Please sign in to comment.