Skip to content

Commit 28fde25

Browse files
Bring code into 2026.
1 parent 0ca7bf0 commit 28fde25

34 files changed

+1503
-1308
lines changed

README.textile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Since version 0.7.1 I have changed the API of _OembedService_ and removed _Optio
2020

2121
Since version 0.8.1 this project is Java 11 *only*.
2222

23-
The project is not yet on the module path because java-oembed uses JAXB for parsing XML which currently leads to a "split-package problem":https://github.com/javaee/jaxb-v2/issues/1168.
23+
Since version 1.0.0 this project is Java 17 *only*.
2424

2525
h2. Usage
2626

etc/checkstyle/config.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
4+
Copyright 2025 the original author or authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
https://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
<!DOCTYPE module PUBLIC
20+
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
21+
"https://checkstyle.org/dtds/configuration_1_3.dtd">
22+
<module name="com.puppycrawl.tools.checkstyle.Checker">
23+
<module name="io.spring.javaformat.checkstyle.SpringChecks">
24+
<property name="excludes" value="io.spring.javaformat.checkstyle.check.SpringAvoidStaticImportCheck"/>
25+
<property name="excludes" value="io.spring.javaformat.checkstyle.check.SpringHeaderCheck"/>
26+
<property name="excludes" value="io.spring.javaformat.checkstyle.check.SpringLambdaCheck"/>
27+
<property name="excludes" value="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck"/>
28+
<property name="excludes" value="com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceBeforeCheck"/>
29+
</module>
30+
<module name="NewlineAtEndOfFile"/>
31+
<module name="SuppressWarningsFilter"/>
32+
<module name="com.puppycrawl.tools.checkstyle.TreeWalker">
33+
<module name="SuppressWarningsHolder"/>
34+
<module name="JavadocMethod">
35+
<property name="allowInlineReturn" value="true"/>
36+
</module>
37+
<module name="NoWhitespaceBefore">
38+
<property name="tokens" value="COMMA , SEMI , POST_INC , POST_DEC , LABELED_STAT"/>
39+
</module>
40+
</module>
41+
</module>

etc/checkstyle/suppressions.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
4+
Copyright 2025 the original author or authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
https://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
20+
<!DOCTYPE suppressions PUBLIC
21+
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
22+
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
23+
<suppressions />

etc/license.tpl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright ${year} the original author or authors.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
https://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

pom.xml

Lines changed: 73 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<url>https://github.com/michael-simons/java-oembed</url>
3333
</scm>
3434
<properties>
35+
<assertj.version>3.27.6</assertj.version>
3536
<central-publishing-maven-plugin.version>0.9.0</central-publishing-maven-plugin.version>
3637
<checkstyle.version>12.3.0</checkstyle.version>
3738
<commons-beanutils.version>1.11.0</commons-beanutils.version>
@@ -60,13 +61,14 @@
6061
<maven-source-plugin.version>3.4.0</maven-source-plugin.version>
6162
<maven-surefire-plugin.version>3.5.4</maven-surefire-plugin.version>
6263
<maven.compiler.parameters>true</maven.compiler.parameters>
63-
<maven.compiler.release>11</maven.compiler.release>
64+
<maven.compiler.release>17</maven.compiler.release>
6465
<maven.version>3.9.12</maven.version>
6566
<mockito.version>5.21.0</mockito.version>
6667
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
6768
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
6869
<slf4j.version>2.0.17</slf4j.version>
6970
<sortpom-maven-plugin.version>4.0.0</sortpom-maven-plugin.version>
71+
<spring-javaformat.version>0.0.47</spring-javaformat.version>
7072
<versions-maven-plugin.version>2.20.1</versions-maven-plugin.version>
7173
</properties>
7274
<dependencyManagement>
@@ -79,6 +81,13 @@
7981
<type>pom</type>
8082
<scope>import</scope>
8183
</dependency>
84+
<dependency>
85+
<groupId>org.assertj</groupId>
86+
<artifactId>assertj-bom</artifactId>
87+
<version>${assertj.version}</version>
88+
<type>pom</type>
89+
<scope>import</scope>
90+
</dependency>
8291
<dependency>
8392
<groupId>org.junit</groupId>
8493
<artifactId>junit-bom</artifactId>
@@ -175,6 +184,11 @@
175184
<artifactId>jcl-over-slf4j</artifactId>
176185
<scope>runtime</scope>
177186
</dependency>
187+
<dependency>
188+
<groupId>org.assertj</groupId>
189+
<artifactId>assertj-core</artifactId>
190+
<scope>test</scope>
191+
</dependency>
178192
<dependency>
179193
<groupId>org.junit.jupiter</groupId>
180194
<artifactId>junit-jupiter</artifactId>
@@ -236,18 +250,6 @@
236250
</rules>
237251
</configuration>
238252
</plugin>
239-
<plugin>
240-
<groupId>org.apache.maven.plugins</groupId>
241-
<artifactId>maven-checkstyle-plugin</artifactId>
242-
<version>${maven-checkstyle-plugin.version}</version>
243-
<dependencies>
244-
<dependency>
245-
<groupId>com.puppycrawl.tools</groupId>
246-
<artifactId>checkstyle</artifactId>
247-
<version>${checkstyle.version}</version>
248-
</dependency>
249-
</dependencies>
250-
</plugin>
251253
<plugin>
252254
<groupId>com.github.ekryd.sortpom</groupId>
253255
<artifactId>sortpom-maven-plugin</artifactId>
@@ -286,6 +288,38 @@
286288
</ruleSet>
287289
</configuration>
288290
</plugin>
291+
<plugin>
292+
<groupId>io.spring.javaformat</groupId>
293+
<artifactId>spring-javaformat-maven-plugin</artifactId>
294+
<version>${spring-javaformat.version}</version>
295+
</plugin>
296+
<plugin>
297+
<groupId>org.apache.maven.plugins</groupId>
298+
<artifactId>maven-checkstyle-plugin</artifactId>
299+
<version>${maven-checkstyle-plugin.version}</version>
300+
<configuration>
301+
<excludes>**/module-info.java</excludes>
302+
<includeTestSourceDirectory>true</includeTestSourceDirectory>
303+
<configLocation>etc/checkstyle/config.xml</configLocation>
304+
<suppressionsLocation>etc/checkstyle/suppressions.xml</suppressionsLocation>
305+
<inputEncoding>${project.build.sourceEncoding}</inputEncoding>
306+
<consoleOutput>true</consoleOutput>
307+
<failsOnError>true</failsOnError>
308+
<includeTestSourceDirectory>true</includeTestSourceDirectory>
309+
</configuration>
310+
<dependencies>
311+
<dependency>
312+
<groupId>com.puppycrawl.tools</groupId>
313+
<artifactId>checkstyle</artifactId>
314+
<version>${checkstyle.version}</version>
315+
</dependency>
316+
<dependency>
317+
<groupId>io.spring.javaformat</groupId>
318+
<artifactId>spring-javaformat-checkstyle</artifactId>
319+
<version>${spring-javaformat.version}</version>
320+
</dependency>
321+
</dependencies>
322+
</plugin>
289323
<plugin>
290324
<groupId>org.apache.maven.plugins</groupId>
291325
<artifactId>maven-compiler-plugin</artifactId>
@@ -370,6 +404,19 @@
370404
</execution>
371405
</executions>
372406
</plugin>
407+
<plugin>
408+
<groupId>io.spring.javaformat</groupId>
409+
<artifactId>spring-javaformat-maven-plugin</artifactId>
410+
<executions>
411+
<execution>
412+
<goals>
413+
<goal>validate</goal>
414+
</goals>
415+
<phase>validate</phase>
416+
<inherited>true</inherited>
417+
</execution>
418+
</executions>
419+
</plugin>
373420
<plugin>
374421
<groupId>org.apache.maven.plugins</groupId>
375422
<artifactId>maven-checkstyle-plugin</artifactId>
@@ -380,13 +427,19 @@
380427
<goal>check</goal>
381428
</goals>
382429
<phase>validate</phase>
383-
<configuration>
384-
<configLocation>src/checkstyle/checkstyle.xml</configLocation>
385-
<suppressionsLocation>src/checkstyle/checkstyle-suppressions.xml</suppressionsLocation>
386-
<inputEncoding>${project.build.sourceEncoding}</inputEncoding>
387-
<consoleOutput>true</consoleOutput>
388-
<failsOnError>true</failsOnError>
389-
</configuration>
430+
</execution>
431+
</executions>
432+
</plugin>
433+
<plugin>
434+
<groupId>org.apache.maven.plugins</groupId>
435+
<artifactId>maven-enforcer-plugin</artifactId>
436+
<executions>
437+
<execution>
438+
<id>enforce</id>
439+
<goals>
440+
<goal>enforce</goal>
441+
</goals>
442+
<phase>validate</phase>
390443
</execution>
391444
</executions>
392445
</plugin>
@@ -429,19 +482,6 @@
429482
</execution>
430483
</executions>
431484
</plugin>
432-
<plugin>
433-
<groupId>org.apache.maven.plugins</groupId>
434-
<artifactId>maven-enforcer-plugin</artifactId>
435-
<executions>
436-
<execution>
437-
<id>enforce</id>
438-
<goals>
439-
<goal>enforce</goal>
440-
</goals>
441-
<phase>validate</phase>
442-
</execution>
443-
</executions>
444-
</plugin>
445485
<plugin>
446486
<groupId>org.apache.maven.plugins</groupId>
447487
<artifactId>maven-failsafe-plugin</artifactId>

src/main/java/ac/simons/oembed/AutodiscoveredOembedEndpoint.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515
*/
1616
package ac.simons.oembed;
1717

18-
import ac.simons.oembed.OembedResponse.Format;
19-
2018
import java.net.URI;
2119

20+
import ac.simons.oembed.OembedResponse.Format;
21+
2222
/**
23-
* This is an autodiscovered endpoint. It doesn't support api url generation but
24-
* only fixed api urls. The format is also fixed.
23+
* This is an auto-discovered endpoint. It doesn't support api url generation but only
24+
* fixed api urls. The format is also fixed.
2525
*
2626
* @author Michael J. Simons, 2015-01-01
2727
*/
2828
final class AutodiscoveredOembedEndpoint extends OembedEndpoint {
2929

3030
/**
31-
* The autodiscovered api url
31+
* The automatically discovered api url.
3232
*/
3333
private final URI apiUrl;
3434

@@ -46,4 +46,5 @@ public URI toApiUrl(final String url) {
4646
public void setFormat(final Format format) {
4747
// Cannot be changed
4848
}
49+
4950
}

src/main/java/ac/simons/oembed/DefaultOembedResponseRenderer.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,34 @@
1818
import org.jsoup.nodes.Element;
1919

2020
/**
21-
* A simple, default oembed response renderer. Uses the deliviered HTML in most
22-
* cases.
21+
* A simple, default oembed response renderer. Uses the delivered HTML in most cases.
2322
*
24-
* @author Michael J. Simons, 2015-01-02
23+
* @author Michael J. Simons
24+
* @since 2015-01-02
2525
*/
2626
class DefaultOembedResponseRenderer implements OembedResponseRenderer {
2727

2828
@Override
2929
public String render(final OembedResponse response, final Element originalAnchor) {
3030
String rv = null;
3131
if (response.getType().equalsIgnoreCase("photo")) {
32-
final String title = response.getTitle() == null ? "" : response.getTitle();
33-
rv = String.format("<img src=\"%s\" style=\"width:%dpx; height:%dpx;\" alt=\"%s\" title=\"%s\"/>", response.getUrl(), response.getWidth(), response.getHeight(), title, title);
34-
} else if (response.getType().equalsIgnoreCase("video")) {
32+
final String title = (response.getTitle() != null) ? response.getTitle() : "";
33+
rv = String.format("<img src=\"%s\" style=\"width:%dpx; height:%dpx;\" alt=\"%s\" title=\"%s\"/>",
34+
response.getUrl(), response.getWidth(), response.getHeight(), title, title);
35+
}
36+
else if (response.getType().equalsIgnoreCase("video")) {
3537
rv = response.getHtml();
36-
} else if (response.getType().equalsIgnoreCase("link")) {
38+
}
39+
else if (response.getType().equalsIgnoreCase("link")) {
3740
final String originalUrl = originalAnchor.absUrl("href");
38-
final String title = response.getTitle() == null ? originalUrl : response.getTitle();
39-
final String url = response.getUrl() == null ? originalUrl : response.getUrl();
41+
final String title = (response.getTitle() != null) ? response.getTitle() : originalUrl;
42+
final String url = (response.getUrl() != null) ? response.getUrl() : originalUrl;
4043
rv = String.format("<a href=\"%s\">%s</a>", url, title);
41-
} else if (response.getType().equalsIgnoreCase("rich")) {
44+
}
45+
else if (response.getType().equalsIgnoreCase("rich")) {
4246
rv = response.getHtml();
4347
}
4448
return rv;
4549
}
50+
4651
}

src/main/java/ac/simons/oembed/DefaultRequestProvider.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,39 @@
1515
*/
1616
package ac.simons.oembed;
1717

18+
import java.net.URI;
19+
import java.util.Optional;
20+
1821
import org.apache.http.client.methods.HttpGet;
1922
import org.slf4j.Logger;
2023
import org.slf4j.LoggerFactory;
2124

22-
import java.net.URI;
23-
import java.util.Optional;
24-
2525
/**
2626
* The default implementation of an oembed provider. Creates plain GET requests.
2727
*
28-
* @author Michael J. Simons, 2014-12-31
28+
* @author Michael J. Simons
29+
* @since 2014-12-31
2930
*/
3031
public class DefaultRequestProvider implements RequestProvider {
3132

32-
public static final Logger LOGGER = LoggerFactory.getLogger(DefaultRequestProvider.class.getPackage().getName());
33+
static final Logger LOGGER = LoggerFactory.getLogger(DefaultRequestProvider.class.getPackage().getName());
3334

3435
/**
3536
* Must return an HTTP-Request against the given URL.
36-
* @param userAgent Our user agent
37-
* @param applicationName An optional application name, will be added to the
38-
* userAgent if present
39-
* @param uri The api url of the oembed endpoint
40-
* @return A prepared HTTP-Request
37+
* @param userAgent our user agent
38+
* @param applicationName an optional application name, will be added to the userAgent
39+
* if present
40+
* @param uri the api url of the oembed endpoint
41+
* @return a prepared HTTP-Request
4142
*/
4243
@Override
4344
public HttpGet createRequestFor(final String userAgent, final String applicationName, final URI uri) {
4445
LOGGER.debug("Creating HttpGet for url '{}'", uri.toString());
4546

4647
final HttpGet request = new HttpGet(uri);
47-
request.setHeader("User-Agent", String.format("%s%s", userAgent, Optional.ofNullable(applicationName).map(s -> "; " + s).orElse("")));
48+
request.setHeader("User-Agent",
49+
String.format("%s%s", userAgent, Optional.ofNullable(applicationName).map(s -> "; " + s).orElse("")));
4850
return request;
4951
}
52+
5053
}

0 commit comments

Comments
 (0)