Skip to content

Commit

Permalink
Added a customizer method for #176
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Jul 31, 2024
1 parent 98c78a5 commit 1a8464e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.net.URL;
import java.util.Enumeration;
import java.util.Locale;
import java.util.function.Consumer;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -44,6 +45,8 @@
* {@link TransformerFactory} before calling the SPI version
* <code>TransformerFactory.newInstance ()</code>. This is mainly to solve the
* interoperability issue when using Xalan and Saxon together in the class path.
* Also in general, Saxon is always to be preferred to Xalan. Xalan is simply
* out of date.
*
* @author Philip Helger
*/
Expand All @@ -52,15 +55,16 @@ public final class SchematronTransformerFactory
{
public static final String SAXON_TRANSFORMER_FACTORY_CLASS = "net.sf.saxon.TransformerFactoryImpl";
private static final Logger LOGGER = LoggerFactory.getLogger (SchematronTransformerFactory.class);
private static final TransformerFactory DEFAULT_FACTORY;

static
private static final class SingletonHolder
{
DEFAULT_FACTORY = createTransformerFactorySaxonFirst (SchematronTransformerFactory.class.getClassLoader (),
new LoggingTransformErrorListener (Locale.US),
new DefaultTransformURIResolver ());
static final TransformerFactory INSTANCE = createTransformerFactorySaxonFirst (SchematronTransformerFactory.class.getClassLoader (),
new LoggingTransformErrorListener (Locale.US),
new DefaultTransformURIResolver ());
}

private static Consumer <TransformerFactory> s_aFactoryCustomizer;

private SchematronTransformerFactory ()
{}

Expand All @@ -71,7 +75,21 @@ private SchematronTransformerFactory ()
@Nonnull
public static TransformerFactory getDefaultSaxonFirst ()
{
return DEFAULT_FACTORY;
return SingletonHolder.INSTANCE;
}

/**
* Set an optional {@link Consumer} that is called for every
* {@link TransformerFactory} created by this class. This may e.g. be used, to
* add implementation specific configuration. Based on #176.
*
* @param a
* The consumer to invoke. May be <code>null</code>.
* @since 8.0.3
*/
public static void setTransformerFactoryCustomizer (@Nullable final Consumer <TransformerFactory> a)
{
s_aFactoryCustomizer = a;
}

/**
Expand Down Expand Up @@ -158,6 +176,10 @@ public static TransformerFactory createTransformerFactorySaxonFirst (@Nullable f
if (aURIResolver != null)
aFactory.setURIResolver (aURIResolver);

// Call the customizer
if (s_aFactoryCustomizer != null)
s_aFactoryCustomizer.accept (aFactory);

if (LOGGER.isDebugEnabled ())
LOGGER.debug ("Created TransformerFactory is " + aFactory);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
public class SchematronProviderXSLTPrebuild implements ISchematronXSLTBasedProvider
{
private static final Logger LOGGER = LoggerFactory.getLogger (SchematronProviderXSLTPrebuild.class);

private Document m_aSchematronXSLTDoc;
private Templates m_aSchematronXSLTTemplates;

Expand Down

0 comments on commit 1a8464e

Please sign in to comment.