Skip to content

Commit e832a97

Browse files
authored
Merge pull request #3 from maxprograms-com/Java25
Migration to Java25
2 parents 42a79a7 + 80e0542 commit e832a97

11 files changed

Lines changed: 38 additions & 25 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ Features in development:
1616

1717
## Building
1818

19-
You need Java 21 and [Gradle](https://gradle.org/)
19+
You need Java 25 and [Gradle](https://gradle.org/)
2020

2121
- Clone this repository
22-
- Point your JAVA_HOME variable to JDK 21
22+
- Point your JAVA_HOME variable to JDK 25
2323
- Run `gradle` to compile the source code
2424

2525
``` text

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44

55
java {
66
toolchain {
7-
languageVersion = JavaLanguageVersion.of(21)
7+
languageVersion = JavaLanguageVersion.of(25)
88
}
99
}
1010

lib/xmljava.jar

406 Bytes
Binary file not shown.

sonar-project.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
sonar.projectKey=XMLJava
33
# this is the name displayed in the SonarQube UI
44
sonar.projectName=XMLJava
5-
sonar.projectVersion=4.1.0
5+
sonar.projectVersion=5.0.0
66

77
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
88
# Since SonarQube 4.2, this property is optional if sonar.modules is set.
99
# If not set, SonarQube starts looking for source code from the directory containing
1010
# the sonar-project.properties file.
1111
sonar.sources=src
12-
sonar.java.source=21
12+
sonar.java.source=25
1313
sonar.java.binaries=bin
1414
sonar.java.libraries=lib
1515
sonar.scm.provider=git

src/com/maxprograms/xml/Catalog.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class Catalog implements EntityResolver2 {
5757
private Map<String, Catalog> delegateCatalogs;
5858
private String workDir;
5959
private String base = "";
60-
private String documentParent = "";
60+
private final ThreadLocal<String> documentParent = ThreadLocal.withInitial(() -> "");
6161
private String prefer = "public";
6262

6363
protected Catalog(String catalogFile)
@@ -442,7 +442,7 @@ public InputSource resolveEntity(String name, String publicId, String baseURI, S
442442
return new InputSource(uri.toURL().openStream());
443443
}
444444
return new InputSource(new FileInputStream(uri.toURL().toString()));
445-
} catch (URISyntaxException | IllegalArgumentException | NullPointerException e) {
445+
} catch (URISyntaxException | IllegalArgumentException | NullPointerException _) {
446446
// ignore
447447
}
448448
if (dtdPublicEntities != null && publicId != null && dtdPublicEntities.containsKey(publicId)) {
@@ -554,7 +554,7 @@ public String matchSystem(String baseURI, String systemId) {
554554
}
555555
// this resource is not in catalog.
556556

557-
if (!documentParent.isEmpty()) {
557+
if (!documentParent.get().isEmpty()) {
558558
// try to find the file in parent folder
559559
File f = new File(systemId);
560560
String name = f.getAbsolutePath();
@@ -566,19 +566,19 @@ public String matchSystem(String baseURI, String systemId) {
566566
name = f.getName();
567567
}
568568
}
569-
File parent = new File(documentParent);
569+
File parent = new File(documentParent.get());
570570
File file = new File(parent, name);
571571
if (file.exists()) {
572572
return file.getAbsolutePath();
573573
}
574574
}
575575
try {
576-
URI u = new URI(baseURI != null ? baseURI : documentParent).resolve(systemId).normalize();
576+
URI u = new URI(baseURI != null ? baseURI : documentParent.get()).resolve(systemId).normalize();
577577
File file = new File(u.toURL().toString());
578578
if (file.exists()) {
579579
return file.getAbsolutePath();
580580
}
581-
} catch (MalformedURLException | URISyntaxException | IllegalArgumentException e) {
581+
} catch (MalformedURLException | URISyntaxException | IllegalArgumentException _) {
582582
// ignore
583583
}
584584
}
@@ -628,15 +628,15 @@ public String matchURI(String uri) {
628628
if (u.isAbsolute() && u.toURL().getProtocol().startsWith("file")) {
629629
return u.toString();
630630
}
631-
} catch (URISyntaxException | MalformedURLException | IllegalArgumentException e) {
631+
} catch (URISyntaxException | MalformedURLException | IllegalArgumentException _) {
632632
// ignore
633633
}
634634
}
635635
return null;
636636
}
637637

638638
public void currentDocumentBase(String parentFile) {
639-
documentParent = parentFile;
639+
documentParent.set(parentFile);
640640
}
641641

642642
public String getDTD(String name) {
@@ -681,7 +681,7 @@ public void parseDTD(String publicId) {
681681
EntityDecl entity = it.next();
682682
addDtdSystemEntity(entity.getValue(), entity.getSystemId());
683683
}
684-
} catch (IOException | SAXException e) {
684+
} catch (IOException | SAXException _) {
685685
// do nothing
686686
MessageFormat mf = new MessageFormat(Messages.getString("Catalog.0"));
687687
logger.log(Level.WARNING, mf.format(new String[] { publicId }));

src/com/maxprograms/xml/Constants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
public class Constants {
1414

15-
public static final String VERSION = "4.2.0";
16-
public static final String BUILD = "20260601_1626";
15+
public static final String VERSION = "5.0.0";
16+
public static final String BUILD = "20260613_1707";
1717

1818
private Constants() {
1919
// private for security

src/com/maxprograms/xml/CustomContentHandler.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class CustomContentHandler implements IContentHandler {
4444
private String encoding;
4545
private Catalog catalog;
4646
private boolean isRelaxNG;
47+
private static Hashtable<String, Map<String, Map<String, String>>> relaxNgCache = new Hashtable<>();
4748
private Map<String, Map<String, String>> defaultAttributes;
4849
private File documentBase;
4950

@@ -100,7 +101,7 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
100101
}
101102
}
102103
current = stack.pop();
103-
} catch (EmptyStackException es) {
104+
} catch (EmptyStackException _) {
104105
throw new SAXException(Messages.getString("CustomContentHandler.0"));
105106
}
106107
}
@@ -215,7 +216,7 @@ public void setDocumentLocator(Locator locator) {
215216
}
216217
try {
217218
documentBase = new File(new URI(sysId)).getParentFile();
218-
} catch (Exception e) {
219+
} catch (Exception _) {
219220
documentBase = new File(sysId).getParentFile();
220221
}
221222
}
@@ -432,8 +433,13 @@ private void parseRelaxNG(String href) throws SAXException, IOException, ParserC
432433
}
433434
}
434435
if (system != null) {
435-
RelaxNGParser relaxngParser = new RelaxNGParser(system, catalog);
436-
defaultAttributes = relaxngParser.getElements();
436+
synchronized (relaxNgCache) {
437+
if (!relaxNgCache.containsKey(system)) {
438+
RelaxNGParser relaxngParser = new RelaxNGParser(system, catalog);
439+
relaxNgCache.put(system, relaxngParser.getElements());
440+
}
441+
defaultAttributes = relaxNgCache.get(system);
442+
}
437443
isRelaxNG = true;
438444
}
439445
}

src/com/maxprograms/xml/DTDResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public InputSource resolveEntity(String publicId, String systemId) throws IOExce
2828
if (file.exists()) {
2929
return new InputSource(new FileInputStream(file));
3030
}
31-
} catch (URISyntaxException e) {
31+
} catch (URISyntaxException _) {
3232
// ignore
3333
}
3434
return null;

src/com/maxprograms/xml/Messages.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static String getString(String key) {
4848
}
4949
}
5050
return props.getProperty(key, '!' + key + '!');
51-
} catch (IOException | NullPointerException e) {
51+
} catch (IOException | NullPointerException _) {
5252
return '!' + key + '!';
5353
}
5454
}

src/com/maxprograms/xml/RelaxNGParser.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private void nameAttribute(Element e, Map<String, String> context) {
187187
nameEl.setAttribute("ns", e.getAttributeValue("ns"));
188188
e.removeAttribute("ns");
189189
} else {
190-
String resolvedNs = resolveNamespaceBinding(value, currentContext, isElementPattern, isAttributePattern);
190+
String resolvedNs = resolveNamespaceBinding(value, currentContext, isElementPattern);
191191
if (resolvedNs != null && !resolvedNs.isEmpty()) {
192192
nameEl.setAttribute("ns", resolvedNs);
193193
}
@@ -216,8 +216,7 @@ private Map<String, String> augmentNamespaceContext(Map<String, String> base, El
216216
return updated;
217217
}
218218

219-
private String resolveNamespaceBinding(String lexicalName, Map<String, String> context, boolean isElementPattern,
220-
boolean isAttributePattern) {
219+
private String resolveNamespaceBinding(String lexicalName, Map<String, String> context, boolean isElementPattern) {
221220
int separatorIndex = lexicalName.indexOf(':');
222221
if (separatorIndex == -1) {
223222
if (isElementPattern) {

0 commit comments

Comments
 (0)