update to Java 17, fix field list for MarcContentHandler

This commit is contained in:
Jörg Prante 2022-10-13 20:50:32 +02:00
parent ee55fa7ff8
commit d2fa91317c
18 changed files with 134 additions and 79 deletions

View file

@ -5,7 +5,7 @@ plugins {
}
wrapper {
gradleVersion = "${rootProject.property('gradle.wrapper.version')}"
gradleVersion = libs.versions.gradle.get()
distributionType = Wrapper.DistributionType.ALL
}
@ -27,17 +27,17 @@ ext {
apply plugin: 'java-library'
dependencies {
testImplementation "org.xbib:bibliographic-character-sets:${project.property('xbib-bibliographic-character-sets.version')}"
testImplementation "org.xbib:content-json:${project.property('xbib-content.version')}"
testImplementation "xalan:xalan:${project.property('xalan.version')}"
testImplementation "org.xmlunit:xmlunit-matchers:${project.property('xmlunit-matchers.version')}"
testImplementation("com.github.stefanbirkner:system-rules:${project.property('system-rules.version')}") {
testImplementation libs.charactersets
testImplementation libs.json
testImplementation libs.xalan
testImplementation libs.xmlunit
testImplementation (libs.system.rules) {
exclude module: 'junit'
}
testImplementation("org.mockito:mockito-core:${project.property('mockito.version')}") {
testImplementation(libs.mockito) {
exclude group: 'org.hamcrest'
}
testImplementation "org.marc4j:marc4j:${project.property('marc4j.version')}"
testImplementation libs.marc4j
}
apply from: rootProject.file('gradle/ide/idea.gradle')

View file

@ -1,12 +1,9 @@
def junitVersion = project.hasProperty('junit.version')?project.property('junit.version'):'5.8.2'
def hamcrestVersion = project.hasProperty('hamcrest.version')?project.property('hamcrest.version'):'2.2'
dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-params:${junitVersion}"
testImplementation "org.hamcrest:hamcrest-library:${hamcrestVersion}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
testImplementation libs.junit.jupiter.api
testImplementation libs.junit.jupiter.params
testImplementation libs.hamcrest
testRuntimeOnly libs.junit.jupiter.engine
}
test {
@ -24,17 +21,6 @@ test {
"${result.skippedTestCount} skipped"
}
}
jvmArgs '-Xmx2048m',
'--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED',
'--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED',
'--add-exports=java.base/sun.nio.ch=ALL-UNNAMED',
'--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED',
'--add-opens=jdk.compiler/com.sun.tools.javac=ALL-UNNAMED',
'--add-opens=java.base/java.lang=ALL-UNNAMED',
'--add-opens=java.base/java.lang.reflect=ALL-UNNAMED',
'--add-opens=java.base/java.io=ALL-UNNAMED',
'--add-opens=java.base/java.nio=ALL-UNNAMED',
'--add-opens=java.base/java.util=ALL-UNNAMED'
jvmArgs '-Xmx2048m'
systemProperty 'java.util.logging.config.file', 'src/test/resources/logging.properties'
}

Binary file not shown.

View file

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

6
gradlew vendored
View file

@ -205,6 +205,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.

14
gradlew.bat vendored
View file

@ -14,7 +14,7 @@
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@ -25,7 +25,7 @@
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal

20
settings.gradle Normal file
View file

@ -0,0 +1,20 @@
dependencyResolutionManagement {
versionCatalogs {
libs {
version('gradle', '7.5.1')
version('groovy', '3.0.10')
version('junit', '5.9.1')
library('junit-jupiter-api', 'org.junit.jupiter', 'junit-jupiter-api').versionRef('junit')
library('junit-jupiter-params', 'org.junit.jupiter', 'junit-jupiter-params').versionRef('junit')
library('junit-jupiter-engine', 'org.junit.jupiter', 'junit-jupiter-engine').versionRef('junit')
library('hamcrest', 'org.hamcrest', 'hamcrest-library').version('2.2')
library('charactersets', 'org.xbib', 'bibliographic-character-sets').version('2.0.0')
library('json', 'org.xbib', 'content-json').version('4.0.0')
library('xalan', 'xalan', 'xalan').version('2.7.2')
library('xmlunit', 'org.xmlunit', 'xmlunit-matchers').version('2.8.4')
library('system-rules', 'com.github.stefanbirkner', 'system-rules').version('1.19.0')
library('mockito', 'org.mockito', 'mockito-core').version('3.3.3')
library('marc4j', 'org.marc4j', 'marc4j').version('2.9.2')
}
}
}

View file

@ -20,6 +20,10 @@ package org.xbib.marc;
* A MARC listener with empty methods. Useful for extending.
*/
public class MarcFieldAdapter implements MarcListener {
public MarcFieldAdapter() {
}
@Override
public void beginCollection() {
// empty by design

View file

@ -16,14 +16,13 @@
*/
package org.xbib.marc.dialects.pica;
import java.util.HashSet;
import org.xbib.marc.MarcField;
import org.xbib.marc.label.RecordLabel;
import org.xbib.marc.xml.MarcContentHandler;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
@ -32,8 +31,12 @@ import java.util.Set;
*/
public class PicaXMLContentHandler extends MarcContentHandler implements PicaConstants {
private Set<String> validNamespaces =
new HashSet<>(Arrays.asList(PICAXML_NAMESPACE, SRW_PICAXML_NAMESPACE));
private final Set<String> validNamespaces;
public PicaXMLContentHandler() {
this.validNamespaces = new HashSet<>();
this.validNamespaces.addAll(Set.of(PICAXML_NAMESPACE, SRW_PICAXML_NAMESPACE));
}
@Override
protected String getDefaultFormat() {

View file

@ -16,13 +16,13 @@
*/
package org.xbib.marc.json;
/**
*
*/
public class JsonDefaultHandler implements JsonHandler<JsonArray, JsonObject> {
protected JsonValue value;
public JsonDefaultHandler() {
}
public JsonValue getValue() {
return value;
}

View file

@ -51,6 +51,9 @@ import java.io.StringWriter;
*/
public abstract class JsonValue {
public JsonValue() {
}
/**
* Detects whether this value represents a JSON object. If this is the case, this value is an
* instance of {@link JsonObject}.

View file

@ -39,13 +39,23 @@ public class MarcTool {
private static final Logger logger = Logger.getLogger(MarcTool.class.getName());
private String mode = null;
private String input = null;
private String output = null;
private String charset = "UTF-8";
private String schema = null;
private String stylesheet = null;
private String result = null;
private String mode;
private String input;
private String output;
private String charset;
private String schema;
private String stylesheet;
private String result;
public MarcTool() {
this.charset = "UTF-8";
}
public static void main(String[] args) {
MarcTool marcTool = new MarcTool();

View file

@ -21,11 +21,11 @@ import org.xbib.marc.MarcField;
import java.util.LinkedList;
import java.util.List;
/**
*/
@SuppressWarnings("serial")
public class MarcFieldTransformers extends LinkedList<MarcFieldTransformer> {
private static final long serialVersionUID = 2704484673464559115L;
public MarcFieldTransformers() {
}
public List<MarcField> transform(List<MarcField> marcFields) {
LinkedList<MarcField> list = new LinkedList<>();

View file

@ -21,15 +21,18 @@ import org.xbib.marc.MarcField;
import java.util.HashMap;
import java.util.Map;
/**
*/
public class MarcValueTransformers {
private static final String DEFAULT = "_default";
private final Map<String, MarcValueTransformer> marcValueTransformerMap = new HashMap<>();
private final Map<String, MarcValueTransformer> marcValueTransformerMap;
private final Map<String, String> subfieldMap = new HashMap<>();
private final Map<String, String> subfieldMap;
public MarcValueTransformers() {
marcValueTransformerMap = new HashMap<>();
subfieldMap = new HashMap<>();
}
public MarcValueTransformers setMarcValueTransformer(MarcValueTransformer transformer) {
this.marcValueTransformerMap.put(DEFAULT, transformer);

View file

@ -16,9 +16,11 @@
*/
package org.xbib.marc.transformer.value;
/**
*/
public class Xml10MarcValueCleaner implements MarcValueTransformer {
public Xml10MarcValueCleaner() {
}
@Override
public String transform(String string) {
StringBuilder sb = new StringBuilder();

View file

@ -16,6 +16,7 @@
*/
package org.xbib.marc.xml;
import java.util.HashSet;
import org.xbib.marc.MarcField;
import org.xbib.marc.MarcListener;
import org.xbib.marc.MarcRecord;
@ -35,10 +36,8 @@ import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import java.io.IOException;
import java.util.Arrays;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -57,13 +56,13 @@ public class MarcContentHandler
private static final Logger logger = Logger.getLogger(MarcContentHandler.class.getName());
protected final AtomicInteger recordCounter = new AtomicInteger();
protected final AtomicInteger recordCounter;
protected Deque<MarcField.Builder> stack = new LinkedList<>();
protected Deque<MarcField.Builder> stack;
protected Map<String, MarcListener> listeners = new HashMap<>();
protected Map<String, MarcListener> listeners;
protected StringBuilder content = new StringBuilder();
protected StringBuilder content;
protected MarcListener marcListener;
@ -77,16 +76,25 @@ public class MarcContentHandler
protected MarcValueTransformers marcValueTransformers;
protected boolean trim = false;
protected boolean trim;
private MarcFieldTransformers marcFieldTransformers;
private boolean isCollection = false;
private boolean isCollection;
private final List<MarcField> marcFieldList = new LinkedList<>();
private List<MarcField> marcFieldList;
private final Set<String> validNamespaces =
new HashSet<>(Arrays.asList(MARCXCHANGE_V1_NS_URI, MARCXCHANGE_V2_NS_URI, MARC21_SCHEMA_URI));
private final Set<String> validNamespaces;
public MarcContentHandler() {
this.recordCounter = new AtomicInteger();
this.stack = new LinkedList<>();
this.listeners = new HashMap<>();
this.content = new StringBuilder();
this.marcFieldList = new LinkedList<>();
this.validNamespaces = new HashSet<>();
this.validNamespaces.addAll(Set.of(MARCXCHANGE_V1_NS_URI, MARCXCHANGE_V2_NS_URI, MARC21_SCHEMA_URI));
}
protected String getDefaultFormat() {
return MARC21_FORMAT;
@ -249,7 +257,7 @@ public class MarcContentHandler
if (marcFieldTransformers != null) {
marcFieldTransformers.reset();
}
marcFieldList.clear();
marcFieldList = new LinkedList<>();
}
}

View file

@ -16,16 +16,15 @@
*/
package org.xbib.marc.xml;
import java.util.HashSet;
import org.xbib.marc.MarcField;
import org.xbib.marc.MarcListener;
import org.xbib.marc.MarcXchangeConstants;
import org.xbib.marc.label.RecordLabel;
import org.xbib.marc.transformer.value.MarcValueTransformers;
import java.util.Arrays;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
@ -45,22 +44,31 @@ import javax.xml.stream.util.XMLEventConsumer;
*/
public class MarcXchangeEventConsumer implements XMLEventConsumer, MarcXchangeConstants, MarcListener {
private Deque<MarcField.Builder> stack = new LinkedList<>();
private final Deque<MarcField.Builder> stack;
private Map<String, MarcListener> listeners = new HashMap<>();
private final Map<String, MarcListener> listeners;
private MarcValueTransformers marcValueTransformers;
private MarcListener listener;
private StringBuilder content = new StringBuilder();
private final StringBuilder content;
private String format = MARC21_FORMAT;
private String format;
private String type = BIBLIOGRAPHIC_TYPE;
private String type;
private Set<String> validNamespaces =
new HashSet<>(Arrays.asList(MARCXCHANGE_V1_NS_URI, MARCXCHANGE_V2_NS_URI, MARC21_SCHEMA_URI));
private final Set<String> validNamespaces;
public MarcXchangeEventConsumer() {
this.stack = new LinkedList<>();
this.listeners = new HashMap<>();
this.content = new StringBuilder();
this.format = MARC21_FORMAT;
this.type = BIBLIOGRAPHIC_TYPE;
this.validNamespaces = new HashSet<>();
this.validNamespaces.addAll(Set.of(MARCXCHANGE_V1_NS_URI, MARCXCHANGE_V2_NS_URI, MARC21_SCHEMA_URI));
}
public MarcXchangeEventConsumer setMarcListener(String type, MarcListener listener) {
this.listeners.put(type, listener);

View file

@ -25,7 +25,7 @@ import static org.junit.jupiter.api.Assertions.fail;
/**
* This class is original inspired from project {@code system-rules},
* rewrite it to JUnit5. It is a JUnit Jupiter extension that allows
* rewritten to JUnit5. It is a JUnit Jupiter extension that allows
* in-test specification of expected {@code System.exit(...)} calls.
*/
@Target({TYPE, METHOD})