From 86f642a365ff1b022dc4efdbd6c6ca0a42487c5f Mon Sep 17 00:00:00 2001 From: JonasG Date: Mon, 4 Mar 2024 14:18:32 +0100 Subject: [PATCH] fix: correct namespace usage in doc example --- README.md | 32 +++++++++---------- .../main/java/io/jonasg/xjx/Attributes.java | 1 - .../src/main/java/io/jonasg/xjx/Token.java | 6 ++++ .../main/java/io/jonasg/xjx/Tokenizer.java | 9 ++++-- .../java/io/jonasg/xjx/sax/SaxHandler.java | 21 ++++++++++++ .../java/io/jonasg/xjx/sax/SaxParser.java | 6 ++-- .../xjx/scanners/CommentBodyScanner.java | 3 +- .../io/jonasg/xjx/scanners/EndTagScanner.java | 4 +-- .../xjx/BufferedPositionedReaderTest.java | 4 +-- .../jonasg/xjx/TokenizerIntegrationTest.java | 12 +++---- .../java/io/jonasg/xjx/sax/SaxParserTest.java | 8 ++--- .../jonasg/xjx/scanners/CDATAScannerTest.java | 11 ++++--- .../xjx/scanners/CharacterScannerTest.java | 9 +++--- .../xjx/scanners/CommentBodyScannerTest.java | 11 ++++--- .../DocumentTypeDeclarationScannerTest.java | 9 +++--- .../xjx/scanners/EndTagScannerTest.java | 15 +++++---- .../xjx/scanners/StartTagScannerTest.java | 15 +++++---- .../deserialize/SetDeserializationTest.java | 3 -- 18 files changed, 105 insertions(+), 74 deletions(-) diff --git a/README.md b/README.md index 7099f8b..7eafa54 100644 --- a/README.md +++ b/README.md @@ -61,22 +61,22 @@ public class Location { ```java String document = """ - - - USA - - - - 75 - - - - 60 - % - - Sunny - - """; + + + USA + + + + 75 + + + + 60 + % + + Sunny + + """; var xjx = new XjxSerdes(); diff --git a/xjx-sax/src/main/java/io/jonasg/xjx/Attributes.java b/xjx-sax/src/main/java/io/jonasg/xjx/Attributes.java index 2823d5e..1871575 100644 --- a/xjx-sax/src/main/java/io/jonasg/xjx/Attributes.java +++ b/xjx-sax/src/main/java/io/jonasg/xjx/Attributes.java @@ -1,6 +1,5 @@ package io.jonasg.xjx; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.StringJoiner; diff --git a/xjx-sax/src/main/java/io/jonasg/xjx/Token.java b/xjx-sax/src/main/java/io/jonasg/xjx/Token.java index 1e1441d..1e26fbc 100644 --- a/xjx-sax/src/main/java/io/jonasg/xjx/Token.java +++ b/xjx-sax/src/main/java/io/jonasg/xjx/Token.java @@ -1,5 +1,11 @@ package io.jonasg.xjx; +/** + * Represents a single token in an XML document. + * @param type the type of the token + * @param value the value of the token or null if not relevant for that token type + * @param the type of the value + */ public record Token(Type type, T value) { public Token(Type type) { diff --git a/xjx-sax/src/main/java/io/jonasg/xjx/Tokenizer.java b/xjx-sax/src/main/java/io/jonasg/xjx/Tokenizer.java index d4f6a4d..307d2a9 100644 --- a/xjx-sax/src/main/java/io/jonasg/xjx/Tokenizer.java +++ b/xjx-sax/src/main/java/io/jonasg/xjx/Tokenizer.java @@ -1,14 +1,17 @@ package io.jonasg.xjx; -import io.jonasg.xjx.scanners.Scanner; -import io.jonasg.xjx.scanners.WhiteSpaceScanner; - import java.io.Reader; import java.util.Spliterator; import java.util.function.Consumer; import java.util.stream.Stream; import java.util.stream.StreamSupport; +import io.jonasg.xjx.scanners.Scanner; +import io.jonasg.xjx.scanners.WhiteSpaceScanner; + +/** + * Tokenize an XML document into a stream of {@link Token}. + */ public class Tokenizer { public Stream> tokenize(Reader reader) { diff --git a/xjx-sax/src/main/java/io/jonasg/xjx/sax/SaxHandler.java b/xjx-sax/src/main/java/io/jonasg/xjx/sax/SaxHandler.java index 87875f4..69cf2ac 100644 --- a/xjx-sax/src/main/java/io/jonasg/xjx/sax/SaxHandler.java +++ b/xjx-sax/src/main/java/io/jonasg/xjx/sax/SaxHandler.java @@ -2,13 +2,34 @@ import java.util.List; +/** + * A handler for SAX parsing. + */ public interface SaxHandler { + /** + * Called when the document starts. + */ void startDocument(); + /** + * Called when a start tag is encountered. + * @param namespace the namespace of the tag or null when no namespace is present + * @param name the name of the tag + * @param attributes the attributes of the tag + */ void startTag(String namespace, String name, List attributes); + /** + * Called when a end tag is encountered. + * @param namespace the namespace of the tag or null when no namespace is present + * @param name the name of the tag + */ void endTag(String namespace, String name); + /** + * Called when character data is encountered. + * @param data the character data + */ void characters(String data); } diff --git a/xjx-sax/src/main/java/io/jonasg/xjx/sax/SaxParser.java b/xjx-sax/src/main/java/io/jonasg/xjx/sax/SaxParser.java index 66fbee8..4773817 100644 --- a/xjx-sax/src/main/java/io/jonasg/xjx/sax/SaxParser.java +++ b/xjx-sax/src/main/java/io/jonasg/xjx/sax/SaxParser.java @@ -1,13 +1,13 @@ package io.jonasg.xjx.sax; +import java.io.Reader; +import java.util.List; + import io.jonasg.xjx.EndTag; import io.jonasg.xjx.StartTag; import io.jonasg.xjx.Token; import io.jonasg.xjx.Tokenizer; -import java.io.Reader; -import java.util.List; - public class SaxParser { private final Tokenizer tokenizer; diff --git a/xjx-sax/src/main/java/io/jonasg/xjx/scanners/CommentBodyScanner.java b/xjx-sax/src/main/java/io/jonasg/xjx/scanners/CommentBodyScanner.java index 6a5c9f8..2404516 100644 --- a/xjx-sax/src/main/java/io/jonasg/xjx/scanners/CommentBodyScanner.java +++ b/xjx-sax/src/main/java/io/jonasg/xjx/scanners/CommentBodyScanner.java @@ -1,11 +1,10 @@ package io.jonasg.xjx.scanners; +import static io.jonasg.xjx.Token.Type.CLOSE_COMMENT; import io.jonasg.xjx.PositionedReader; import io.jonasg.xjx.Token; import io.jonasg.xjx.TokenEmitter; -import static io.jonasg.xjx.Token.Type.CLOSE_COMMENT; - class CommentBodyScanner implements Scanner { @Override public Scanner scan(PositionedReader reader, TokenEmitter tokenEmitter) { diff --git a/xjx-sax/src/main/java/io/jonasg/xjx/scanners/EndTagScanner.java b/xjx-sax/src/main/java/io/jonasg/xjx/scanners/EndTagScanner.java index 1a3b526..dd71224 100644 --- a/xjx-sax/src/main/java/io/jonasg/xjx/scanners/EndTagScanner.java +++ b/xjx-sax/src/main/java/io/jonasg/xjx/scanners/EndTagScanner.java @@ -1,12 +1,12 @@ package io.jonasg.xjx.scanners; +import java.util.Objects; + import io.jonasg.xjx.EndTag; import io.jonasg.xjx.PositionedReader; import io.jonasg.xjx.Token; import io.jonasg.xjx.TokenEmitter; -import java.util.Objects; - class EndTagScanner implements Scanner { @Override diff --git a/xjx-sax/src/test/java/io/jonasg/xjx/BufferedPositionedReaderTest.java b/xjx-sax/src/test/java/io/jonasg/xjx/BufferedPositionedReaderTest.java index edf4294..450faec 100644 --- a/xjx-sax/src/test/java/io/jonasg/xjx/BufferedPositionedReaderTest.java +++ b/xjx-sax/src/test/java/io/jonasg/xjx/BufferedPositionedReaderTest.java @@ -1,11 +1,11 @@ package io.jonasg.xjx; +import java.io.StringReader; + import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import java.io.StringReader; - class BufferedPositionedReaderTest { @Nested diff --git a/xjx-sax/src/test/java/io/jonasg/xjx/TokenizerIntegrationTest.java b/xjx-sax/src/test/java/io/jonasg/xjx/TokenizerIntegrationTest.java index fe15388..c979c27 100644 --- a/xjx-sax/src/test/java/io/jonasg/xjx/TokenizerIntegrationTest.java +++ b/xjx-sax/src/test/java/io/jonasg/xjx/TokenizerIntegrationTest.java @@ -1,16 +1,16 @@ package io.jonasg.xjx; -import org.assertj.core.api.Condition; -import org.junit.jupiter.api.Test; - -import java.io.BufferedReader; -import java.io.StringReader; - import static io.jonasg.xjx.Token.Type.CHARACTER_DATA; import static io.jonasg.xjx.Token.Type.START_TAG; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.Index.atIndex; +import java.io.BufferedReader; +import java.io.StringReader; + +import org.assertj.core.api.Condition; +import org.junit.jupiter.api.Test; + class TokenizerIntegrationTest { @Test diff --git a/xjx-sax/src/test/java/io/jonasg/xjx/sax/SaxParserTest.java b/xjx-sax/src/test/java/io/jonasg/xjx/sax/SaxParserTest.java index 3a4d241..c49f668 100644 --- a/xjx-sax/src/test/java/io/jonasg/xjx/sax/SaxParserTest.java +++ b/xjx-sax/src/test/java/io/jonasg/xjx/sax/SaxParserTest.java @@ -1,15 +1,15 @@ package io.jonasg.xjx.sax; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; - import java.io.BufferedReader; import java.io.StringReader; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + class SaxParserTest { @Nested diff --git a/xjx-sax/src/test/java/io/jonasg/xjx/scanners/CDATAScannerTest.java b/xjx-sax/src/test/java/io/jonasg/xjx/scanners/CDATAScannerTest.java index 2a2483a..50a20b6 100644 --- a/xjx-sax/src/test/java/io/jonasg/xjx/scanners/CDATAScannerTest.java +++ b/xjx-sax/src/test/java/io/jonasg/xjx/scanners/CDATAScannerTest.java @@ -1,14 +1,15 @@ package io.jonasg.xjx.scanners; -import io.jonasg.xjx.BufferedPositionedReader; -import io.jonasg.xjx.Token; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; - import java.io.StringReader; import java.util.ArrayList; import java.util.List; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +import io.jonasg.xjx.BufferedPositionedReader; +import io.jonasg.xjx.Token; + class CDATAScannerTest { @Test diff --git a/xjx-sax/src/test/java/io/jonasg/xjx/scanners/CharacterScannerTest.java b/xjx-sax/src/test/java/io/jonasg/xjx/scanners/CharacterScannerTest.java index d58512e..6a4ee53 100644 --- a/xjx-sax/src/test/java/io/jonasg/xjx/scanners/CharacterScannerTest.java +++ b/xjx-sax/src/test/java/io/jonasg/xjx/scanners/CharacterScannerTest.java @@ -1,12 +1,13 @@ package io.jonasg.xjx.scanners; -import io.jonasg.xjx.BufferedPositionedReader; -import io.jonasg.xjx.Token; +import java.io.StringReader; +import java.util.ArrayList; + import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; -import java.io.StringReader; -import java.util.ArrayList; +import io.jonasg.xjx.BufferedPositionedReader; +import io.jonasg.xjx.Token; class CharacterScannerTest { diff --git a/xjx-sax/src/test/java/io/jonasg/xjx/scanners/CommentBodyScannerTest.java b/xjx-sax/src/test/java/io/jonasg/xjx/scanners/CommentBodyScannerTest.java index 747b93f..be34392 100644 --- a/xjx-sax/src/test/java/io/jonasg/xjx/scanners/CommentBodyScannerTest.java +++ b/xjx-sax/src/test/java/io/jonasg/xjx/scanners/CommentBodyScannerTest.java @@ -1,14 +1,15 @@ package io.jonasg.xjx.scanners; -import io.jonasg.xjx.BufferedPositionedReader; -import io.jonasg.xjx.Token; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.List; + import org.assertj.core.api.Assertions; import org.assertj.core.api.ThrowableAssert; import org.junit.jupiter.api.Test; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.List; +import io.jonasg.xjx.BufferedPositionedReader; +import io.jonasg.xjx.Token; class CommentBodyScannerTest { @Test diff --git a/xjx-sax/src/test/java/io/jonasg/xjx/scanners/DocumentTypeDeclarationScannerTest.java b/xjx-sax/src/test/java/io/jonasg/xjx/scanners/DocumentTypeDeclarationScannerTest.java index 084f20a..b706f2a 100644 --- a/xjx-sax/src/test/java/io/jonasg/xjx/scanners/DocumentTypeDeclarationScannerTest.java +++ b/xjx-sax/src/test/java/io/jonasg/xjx/scanners/DocumentTypeDeclarationScannerTest.java @@ -1,13 +1,14 @@ package io.jonasg.xjx.scanners; -import io.jonasg.xjx.BufferedPositionedReader; -import io.jonasg.xjx.Token; +import java.io.StringReader; +import java.util.ArrayList; + import org.assertj.core.api.Assertions; import org.assertj.core.api.ThrowableAssert; import org.junit.jupiter.api.Test; -import java.io.StringReader; -import java.util.ArrayList; +import io.jonasg.xjx.BufferedPositionedReader; +import io.jonasg.xjx.Token; class DocumentTypeDeclarationScannerTest { diff --git a/xjx-sax/src/test/java/io/jonasg/xjx/scanners/EndTagScannerTest.java b/xjx-sax/src/test/java/io/jonasg/xjx/scanners/EndTagScannerTest.java index 057e184..9ea880e 100644 --- a/xjx-sax/src/test/java/io/jonasg/xjx/scanners/EndTagScannerTest.java +++ b/xjx-sax/src/test/java/io/jonasg/xjx/scanners/EndTagScannerTest.java @@ -1,16 +1,17 @@ package io.jonasg.xjx.scanners; -import io.jonasg.xjx.BufferedPositionedReader; -import io.jonasg.xjx.EndTag; -import io.jonasg.xjx.Token; -import org.assertj.core.api.Assertions; -import org.assertj.core.api.ThrowableAssert; -import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.StringReader; import java.util.ArrayList; -import static org.assertj.core.api.Assertions.*; +import org.assertj.core.api.ThrowableAssert; +import org.junit.jupiter.api.Test; + +import io.jonasg.xjx.BufferedPositionedReader; +import io.jonasg.xjx.EndTag; +import io.jonasg.xjx.Token; class EndTagScannerTest { diff --git a/xjx-sax/src/test/java/io/jonasg/xjx/scanners/StartTagScannerTest.java b/xjx-sax/src/test/java/io/jonasg/xjx/scanners/StartTagScannerTest.java index 9c1de00..52706db 100644 --- a/xjx-sax/src/test/java/io/jonasg/xjx/scanners/StartTagScannerTest.java +++ b/xjx-sax/src/test/java/io/jonasg/xjx/scanners/StartTagScannerTest.java @@ -1,16 +1,17 @@ package io.jonasg.xjx.scanners; -import io.jonasg.xjx.Attributes; -import io.jonasg.xjx.BufferedPositionedReader; -import io.jonasg.xjx.StartTag; -import io.jonasg.xjx.Token; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.List; + import org.assertj.core.api.Assertions; import org.assertj.core.api.ThrowableAssert; import org.junit.jupiter.api.Test; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.List; +import io.jonasg.xjx.Attributes; +import io.jonasg.xjx.BufferedPositionedReader; +import io.jonasg.xjx.StartTag; +import io.jonasg.xjx.Token; class StartTagScannerTest { diff --git a/xjx-serdes/src/test/java/io/jonasg/xjx/serdes/deserialize/SetDeserializationTest.java b/xjx-serdes/src/test/java/io/jonasg/xjx/serdes/deserialize/SetDeserializationTest.java index ddffc31..4b8e439 100644 --- a/xjx-serdes/src/test/java/io/jonasg/xjx/serdes/deserialize/SetDeserializationTest.java +++ b/xjx-serdes/src/test/java/io/jonasg/xjx/serdes/deserialize/SetDeserializationTest.java @@ -2,7 +2,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.util.List; import java.util.Objects; import java.util.Set; @@ -12,8 +11,6 @@ import io.jonasg.xjx.serdes.Tag; import io.jonasg.xjx.serdes.XjxSerdes; -import io.jonasg.xjx.serdes.deserialize.ListDeserializationTest.Gpx; -import io.jonasg.xjx.serdes.deserialize.ListDeserializationTest.Wpt; public class SetDeserializationTest {