Skip to content

Commit

Permalink
fix: correct namespace usage in doc example
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-grgt committed Mar 9, 2024
1 parent c93f1c4 commit 86f642a
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 74 deletions.
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,22 @@ public class Location {
```java
String document = """
<?xml version="1.0" encoding="UTF-8"?>
<w:WeatherData xmlns:xjx="https://github.com/jonas-grgt/xjx">
<w:Location>
<w:Country City="New York">USA</w:Country>
</w:Location>
<w:CurrentConditions>
<w:Temperature>
<w:Value>75</Value>
<w:Unit><![CDATAF]]></w:Unit>
</w:Temperature>
<w:Humidity>
<w:Value>60</w:Value>
<w:Unit>%</w:Unit>
</w:Humidity>
<w:WeatherCondition>Sunny</w:WeatherCondition>
</w:CurrentConditions>
</w:WeatherData>""";
<xjx:WeatherData xmlns:xjx="https://github.com/jonas-grgt/xjx">
<xjx:Location>
<xjx:Country City="New York">USA</xjx:Country>
</xjx:Location>
<xjx:CurrentConditions>
<xjx:Temperature>
<xjx:Value>75</Value>
<xjx:Unit><![CDATAF]]></xjx:Unit>
</xjx:Temperature>
<xjx:Humidity>
<xjx:Value>60</xjx:Value>
<xjx:Unit>%</xjx:Unit>
</xjx:Humidity>
<xjx:WeatherCondition>Sunny</xjx:WeatherCondition>
</xjx:CurrentConditions>
</xjx:WeatherData>""";
var xjx = new XjxSerdes();
Expand Down
1 change: 0 additions & 1 deletion xjx-sax/src/main/java/io/jonasg/xjx/Attributes.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.jonasg.xjx;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.StringJoiner;
Expand Down
6 changes: 6 additions & 0 deletions xjx-sax/src/main/java/io/jonasg/xjx/Token.java
Original file line number Diff line number Diff line change
@@ -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 <T> the type of the value
*/
public record Token<T>(Type type, T value) {

public Token(Type type) {
Expand Down
9 changes: 6 additions & 3 deletions xjx-sax/src/main/java/io/jonasg/xjx/Tokenizer.java
Original file line number Diff line number Diff line change
@@ -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<Token<?>> tokenize(Reader reader) {
Expand Down
21 changes: 21 additions & 0 deletions xjx-sax/src/main/java/io/jonasg/xjx/sax/SaxHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Attribute> 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);
}
6 changes: 3 additions & 3 deletions xjx-sax/src/main/java/io/jonasg/xjx/sax/SaxParser.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions xjx-sax/src/test/java/io/jonasg/xjx/sax/SaxParserTest.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;
import java.util.Objects;
import java.util.Set;

Expand All @@ -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 {

Expand Down

0 comments on commit 86f642a

Please sign in to comment.