Skip to content

Commit f9d6f70

Browse files
committed
GRDDL filters loaded susing ServiceLoader
1 parent e6e1719 commit f9d6f70

4 files changed

Lines changed: 83 additions & 11 deletions

File tree

src/main/java/com/atomgraph/linkeddatahub/Application.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
import com.atomgraph.client.util.XsltResolver;
7171
import com.atomgraph.linkeddatahub.client.GraphStoreClient;
7272
import com.atomgraph.linkeddatahub.client.filter.ClientUriRewriteFilter;
73-
import com.atomgraph.linkeddatahub.client.filter.grddl.YouTubeGRDDLFilter;
73+
import com.atomgraph.linkeddatahub.client.filter.JSONGRDDLFilter;
74+
import com.atomgraph.linkeddatahub.client.filter.JSONGRDDLFilterProvider;
7475
import com.atomgraph.linkeddatahub.imports.ImportExecutor;
7576
import com.atomgraph.linkeddatahub.io.HtmlJsonLDReaderFactory;
7677
import com.atomgraph.linkeddatahub.io.JsonLDReader;
@@ -153,6 +154,7 @@
153154
import java.security.cert.CertificateException;
154155
import java.security.cert.X509Certificate;
155156
import java.util.HashMap;
157+
import java.util.ServiceLoader;
156158
import java.util.Map;
157159
import java.util.Properties;
158160
import jakarta.mail.Authenticator;
@@ -1168,17 +1170,19 @@ protected void registerExceptionMappers()
11681170
*/
11691171
protected void registerClientFilters()
11701172
{
1171-
try
1172-
{
1173-
// Register YouTube GRDDL filter
1174-
YouTubeGRDDLFilter youtubeFilter = new YouTubeGRDDLFilter(xsltComp);
1175-
client.register(youtubeFilter);
1176-
externalClient.register(youtubeFilter);
1177-
}
1178-
catch (SaxonApiException ex)
1173+
ServiceLoader.load(JSONGRDDLFilterProvider.class).forEach(provider ->
11791174
{
1180-
if (log.isErrorEnabled()) log.error("Failed to initialize GRDDL client filter");
1181-
}
1175+
try
1176+
{
1177+
JSONGRDDLFilter filter = provider.getFilter(xsltComp);
1178+
client.register(filter);
1179+
externalClient.register(filter);
1180+
}
1181+
catch (SaxonApiException ex)
1182+
{
1183+
if (log.isErrorEnabled()) log.error("Failed to initialize GRDDL client filter for {}", provider.getClass().getSimpleName());
1184+
}
1185+
});
11821186
}
11831187

11841188
/**
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright 2025 Martynas Jusevičius <martynas@atomgraph.com>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package com.atomgraph.linkeddatahub.client.filter;
18+
19+
import net.sf.saxon.s9api.SaxonApiException;
20+
import net.sf.saxon.s9api.XsltCompiler;
21+
22+
/**
23+
* SPI interface for providing {@link JSONGRDDLFilter} instances.
24+
* Implementations are discovered via {@link java.util.ServiceLoader}.
25+
*/
26+
public interface JSONGRDDLFilterProvider
27+
{
28+
29+
JSONGRDDLFilter getFilter(XsltCompiler xsltCompiler) throws SaxonApiException;
30+
31+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright 2025 Martynas Jusevičius <martynas@atomgraph.com>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package com.atomgraph.linkeddatahub.client.filter.grddl;
18+
19+
import com.atomgraph.linkeddatahub.client.filter.JSONGRDDLFilter;
20+
import com.atomgraph.linkeddatahub.client.filter.JSONGRDDLFilterProvider;
21+
import net.sf.saxon.s9api.SaxonApiException;
22+
import net.sf.saxon.s9api.XsltCompiler;
23+
24+
/**
25+
* {@link JSONGRDDLFilterProvider} implementation for YouTube GRDDL transformation.
26+
*/
27+
public class YouTubeGRDDLFilterProvider implements JSONGRDDLFilterProvider
28+
{
29+
30+
@Override
31+
public JSONGRDDLFilter getFilter(XsltCompiler xsltCompiler) throws SaxonApiException
32+
{
33+
return new YouTubeGRDDLFilter(xsltCompiler);
34+
}
35+
36+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com.atomgraph.linkeddatahub.client.filter.grddl.YouTubeGRDDLFilterProvider

0 commit comments

Comments
 (0)