feat(serialize-xml): scaffold wrapper
This commit is contained in:
parent
006424fb00
commit
b7ef2741b3
@ -1,7 +1,8 @@
|
|||||||
package io.gitlab.jfronny.commons.serialize.xml.impl;
|
package io.gitlab.jfronny.commons.serialize.xml;
|
||||||
|
|
||||||
import io.gitlab.jfronny.commons.serialize.MalformedDataException;
|
import io.gitlab.jfronny.commons.serialize.MalformedDataException;
|
||||||
import io.gitlab.jfronny.commons.serialize.StringEscapeUtil;
|
import io.gitlab.jfronny.commons.serialize.StringEscapeUtil;
|
||||||
|
import io.gitlab.jfronny.commons.serialize.xml.impl.XmlScope;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
@ -10,7 +11,7 @@ import java.io.Reader;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class BaseXmlReader implements Closeable {
|
public class NativeXmlReader implements Closeable {
|
||||||
private static final int PEEKED_NONE = 0;
|
private static final int PEEKED_NONE = 0;
|
||||||
private static final int PEEKED_BEGIN_TAG = 1;
|
private static final int PEEKED_BEGIN_TAG = 1;
|
||||||
private static final int PEEKED_END_TAG = 2;
|
private static final int PEEKED_END_TAG = 2;
|
||||||
@ -75,11 +76,11 @@ public class BaseXmlReader implements Closeable {
|
|||||||
|
|
||||||
private boolean lenient = false;
|
private boolean lenient = false;
|
||||||
private boolean skipWhitespace = true;
|
private boolean skipWhitespace = true;
|
||||||
public BaseXmlReader(Reader in) {
|
public NativeXmlReader(Reader in) {
|
||||||
this.in = Objects.requireNonNull(in, "in == null");
|
this.in = Objects.requireNonNull(in, "in == null");
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseXmlReader setLenient(boolean lenient) {
|
public NativeXmlReader setLenient(boolean lenient) {
|
||||||
this.lenient = lenient;
|
this.lenient = lenient;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -88,7 +89,7 @@ public class BaseXmlReader implements Closeable {
|
|||||||
return lenient;
|
return lenient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseXmlReader setSkipWhitespace(boolean skipWhitespace) {
|
public NativeXmlReader setSkipWhitespace(boolean skipWhitespace) {
|
||||||
this.skipWhitespace = skipWhitespace;
|
this.skipWhitespace = skipWhitespace;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
@ -1,4 +0,0 @@
|
|||||||
package io.gitlab.jfronny.commons.serialize.xml;
|
|
||||||
|
|
||||||
public class XmlReader {
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package io.gitlab.jfronny.commons.serialize.xml.impl;
|
package io.gitlab.jfronny.commons.serialize.xml;
|
||||||
|
|
||||||
public enum XmlToken {
|
public enum XmlToken {
|
||||||
BEGIN_TAG,
|
BEGIN_TAG,
|
@ -1,4 +1,26 @@
|
|||||||
package io.gitlab.jfronny.commons.serialize.xml;
|
package io.gitlab.jfronny.commons.serialize.xml;
|
||||||
|
|
||||||
public class XmlTransport {
|
import io.gitlab.jfronny.commons.serialize.Transport;
|
||||||
|
import io.gitlab.jfronny.commons.serialize.xml.wrapper.XmlReader;
|
||||||
|
import io.gitlab.jfronny.commons.serialize.xml.wrapper.XmlWriter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.io.Writer;
|
||||||
|
|
||||||
|
public class XmlTransport implements Transport<IOException, XmlReader, XmlWriter> {
|
||||||
|
@Override
|
||||||
|
public XmlReader createReader(Reader source) throws IOException {
|
||||||
|
return new XmlReader(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public XmlWriter createWriter(Writer target) throws IOException {
|
||||||
|
return new XmlWriter(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFormatMime() {
|
||||||
|
return "application/xml";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
package io.gitlab.jfronny.commons.serialize.xml;
|
|
||||||
|
|
||||||
public class XmlWriter {
|
|
||||||
}
|
|
@ -0,0 +1,96 @@
|
|||||||
|
package io.gitlab.jfronny.commons.serialize.xml.wrapper;
|
||||||
|
|
||||||
|
import io.gitlab.jfronny.commons.serialize.SerializeReader;
|
||||||
|
import io.gitlab.jfronny.commons.serialize.Token;
|
||||||
|
import io.gitlab.jfronny.commons.serialize.xml.NativeXmlReader;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class XmlReader extends SerializeReader<IOException, XmlReader> {
|
||||||
|
private final NativeXmlReader reader;
|
||||||
|
|
||||||
|
public XmlReader(NativeXmlReader reader) {
|
||||||
|
this.reader = Objects.requireNonNull(reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public XmlReader(Reader source) {
|
||||||
|
this(new NativeXmlReader(source));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public XmlReader beginArray() throws IOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public XmlReader endArray() throws IOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public XmlReader beginObject() throws IOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public XmlReader endObject() throws IOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() throws IOException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Token peek() throws IOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String nextName() throws IOException {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String nextString() throws IOException {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean nextBoolean() throws IOException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void nextNull() throws IOException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Number nextNumber() throws IOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void skipValue() throws IOException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPath() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPreviousPath() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
package io.gitlab.jfronny.commons.serialize.xml.wrapper;
|
||||||
|
|
||||||
|
import io.gitlab.jfronny.commons.serialize.SerializeWriter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Writer;
|
||||||
|
|
||||||
|
public class XmlWriter extends SerializeWriter<IOException, XmlWriter> {
|
||||||
|
public XmlWriter(Writer target) {
|
||||||
|
throw new UnsupportedOperationException("Not yet implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public XmlWriter beginArray() throws IOException {
|
||||||
|
throw new UnsupportedOperationException("Not yet implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public XmlWriter endArray() throws IOException {
|
||||||
|
throw new UnsupportedOperationException("Not yet implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public XmlWriter beginObject() throws IOException {
|
||||||
|
throw new UnsupportedOperationException("Not yet implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public XmlWriter endObject() throws IOException {
|
||||||
|
throw new UnsupportedOperationException("Not yet implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public XmlWriter comment(String comment) throws IOException {
|
||||||
|
throw new UnsupportedOperationException("Not yet implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public XmlWriter name(String name) throws IOException {
|
||||||
|
throw new UnsupportedOperationException("Not yet implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public XmlWriter value(String value) throws IOException {
|
||||||
|
throw new UnsupportedOperationException("Not yet implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public XmlWriter literalValue(String value) throws IOException {
|
||||||
|
throw new UnsupportedOperationException("Not yet implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void flush() throws IOException {
|
||||||
|
throw new UnsupportedOperationException("Not yet implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws Exception {
|
||||||
|
throw new UnsupportedOperationException("Not yet implemented");
|
||||||
|
}
|
||||||
|
}
|
@ -3,4 +3,5 @@ module io.gitlab.jfronny.commons.serialize.xml {
|
|||||||
requires io.gitlab.jfronny.commons.serialize;
|
requires io.gitlab.jfronny.commons.serialize;
|
||||||
requires static org.jetbrains.annotations;
|
requires static org.jetbrains.annotations;
|
||||||
exports io.gitlab.jfronny.commons.serialize.xml;
|
exports io.gitlab.jfronny.commons.serialize.xml;
|
||||||
|
exports io.gitlab.jfronny.commons.serialize.xml.wrapper;
|
||||||
}
|
}
|
@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
package io.gitlab.jfronny.commons.serialize.xml.test;
|
package io.gitlab.jfronny.commons.serialize.xml.test;
|
||||||
|
|
||||||
import io.gitlab.jfronny.commons.serialize.xml.impl.BaseXmlReader;
|
import io.gitlab.jfronny.commons.serialize.xml.NativeXmlReader;
|
||||||
import io.gitlab.jfronny.commons.serialize.xml.impl.XmlToken;
|
import io.gitlab.jfronny.commons.serialize.xml.XmlToken;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -25,7 +25,7 @@ import java.io.Reader;
|
|||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static io.gitlab.jfronny.commons.serialize.xml.impl.XmlToken.*;
|
import static io.gitlab.jfronny.commons.serialize.xml.XmlToken.*;
|
||||||
import static org.junit.Assert.assertThrows;
|
import static org.junit.Assert.assertThrows;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ public final class BaseXmlReaderTest {
|
|||||||
+ " \"c\"]]>\n"
|
+ " \"c\"]]>\n"
|
||||||
+ "</tag>";
|
+ "</tag>";
|
||||||
|
|
||||||
BaseXmlReader reader = new BaseXmlReader(reader(json)).setLenient(true);
|
NativeXmlReader reader = new NativeXmlReader(reader(json)).setLenient(true);
|
||||||
assertThat(reader.peek()).isEqualTo(BEGIN_TAG);
|
assertThat(reader.peek()).isEqualTo(BEGIN_TAG);
|
||||||
assertThat(reader.beginTag()).isEqualTo("tag");
|
assertThat(reader.beginTag()).isEqualTo("tag");
|
||||||
assertThat(reader.peek()).isEqualTo(TEXT);
|
assertThat(reader.peek()).isEqualTo(TEXT);
|
||||||
@ -58,14 +58,14 @@ public final class BaseXmlReaderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetLenientTrue() {
|
public void testSetLenientTrue() {
|
||||||
BaseXmlReader reader = new BaseXmlReader(reader("<tag></tag>"));
|
NativeXmlReader reader = new NativeXmlReader(reader("<tag></tag>"));
|
||||||
reader.setLenient(true);
|
reader.setLenient(true);
|
||||||
assertThat(reader.isLenient()).isEqualTo(true);
|
assertThat(reader.isLenient()).isEqualTo(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetLenientFalse() {
|
public void testSetLenientFalse() {
|
||||||
BaseXmlReader reader = new BaseXmlReader(reader("<tag></tag>"));
|
NativeXmlReader reader = new NativeXmlReader(reader("<tag></tag>"));
|
||||||
reader.setLenient(false);
|
reader.setLenient(false);
|
||||||
assertThat(reader.isLenient()).isEqualTo(false);
|
assertThat(reader.isLenient()).isEqualTo(false);
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ public final class BaseXmlReaderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testStrictModeFailsToParseUnescapedControlCharacter() throws IOException {
|
public void testStrictModeFailsToParseUnescapedControlCharacter() throws IOException {
|
||||||
String json = "<t a='\0'/>";
|
String json = "<t a='\0'/>";
|
||||||
BaseXmlReader reader = new BaseXmlReader(reader(json));
|
NativeXmlReader reader = new NativeXmlReader(reader(json));
|
||||||
reader.setLenient(false);
|
reader.setLenient(false);
|
||||||
|
|
||||||
assertThat(reader.beginTag()).isEqualTo("t");
|
assertThat(reader.beginTag()).isEqualTo("t");
|
||||||
@ -84,7 +84,7 @@ public final class BaseXmlReaderTest {
|
|||||||
.startsWith("Control character in attribute value at line 1 column 7 (char '\\0') path t.a");
|
.startsWith("Control character in attribute value at line 1 column 7 (char '\\0') path t.a");
|
||||||
|
|
||||||
json = "<t b='\u001F'/>";
|
json = "<t b='\u001F'/>";
|
||||||
reader = new BaseXmlReader(reader(json));
|
reader = new NativeXmlReader(reader(json));
|
||||||
reader.setLenient(false);
|
reader.setLenient(false);
|
||||||
|
|
||||||
assertThat(reader.beginTag()).isEqualTo("t");
|
assertThat(reader.beginTag()).isEqualTo("t");
|
||||||
@ -100,7 +100,7 @@ public final class BaseXmlReaderTest {
|
|||||||
// JSON specification only forbids control characters U+0000 - U+001F, other control characters
|
// JSON specification only forbids control characters U+0000 - U+001F, other control characters
|
||||||
// should be allowed
|
// should be allowed
|
||||||
String json = "\"\u007F\u009F\"";
|
String json = "\"\u007F\u009F\"";
|
||||||
BaseXmlReader reader = new BaseXmlReader(reader(json));
|
NativeXmlReader reader = new NativeXmlReader(reader(json));
|
||||||
reader.setLenient(false);
|
reader.setLenient(false);
|
||||||
assertThat(reader.nextText()).isEqualTo("\"\u007F\u009F\"");
|
assertThat(reader.nextText()).isEqualTo("\"\u007F\u009F\"");
|
||||||
}
|
}
|
||||||
@ -108,13 +108,13 @@ public final class BaseXmlReaderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testNonStrictModeParsesUnescapedControlCharacter() throws IOException {
|
public void testNonStrictModeParsesUnescapedControlCharacter() throws IOException {
|
||||||
String json = "\"\t\"";
|
String json = "\"\t\"";
|
||||||
BaseXmlReader reader = new BaseXmlReader(reader(json)).setLenient(true);
|
NativeXmlReader reader = new NativeXmlReader(reader(json)).setLenient(true);
|
||||||
assertThat(reader.nextText()).isEqualTo("\"\t\"");
|
assertThat(reader.nextText()).isEqualTo("\"\t\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadArray() throws IOException {
|
public void testReadArray() throws IOException {
|
||||||
BaseXmlReader reader = new BaseXmlReader(reader("<array><item></item><item/></array>"));
|
NativeXmlReader reader = new NativeXmlReader(reader("<array><item></item><item/></array>"));
|
||||||
assertThat(reader.beginTag()).isEqualTo("array");
|
assertThat(reader.beginTag()).isEqualTo("array");
|
||||||
assertThat(reader.beginTag()).isEqualTo("item");
|
assertThat(reader.beginTag()).isEqualTo("item");
|
||||||
assertThat(reader.endTag()).isEqualTo("item");
|
assertThat(reader.endTag()).isEqualTo("item");
|
||||||
@ -126,7 +126,7 @@ public final class BaseXmlReaderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadEmptyArray() throws IOException {
|
public void testReadEmptyArray() throws IOException {
|
||||||
BaseXmlReader reader = new BaseXmlReader(reader("<array></array>"));
|
NativeXmlReader reader = new NativeXmlReader(reader("<array></array>"));
|
||||||
assertThat(reader.hasNext()).isTrue();
|
assertThat(reader.hasNext()).isTrue();
|
||||||
reader.beginTag();
|
reader.beginTag();
|
||||||
assertThat(reader.hasNext()).isFalse();
|
assertThat(reader.hasNext()).isFalse();
|
||||||
@ -137,7 +137,7 @@ public final class BaseXmlReaderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadEmptyArrayWithWhitespace() throws IOException {
|
public void testReadEmptyArrayWithWhitespace() throws IOException {
|
||||||
BaseXmlReader reader = new BaseXmlReader(reader("<array> </array>"));
|
NativeXmlReader reader = new NativeXmlReader(reader("<array> </array>"));
|
||||||
assertThat(reader.hasNext()).isTrue();
|
assertThat(reader.hasNext()).isTrue();
|
||||||
reader.beginTag();
|
reader.beginTag();
|
||||||
assertThat(reader.hasNext()).isFalse();
|
assertThat(reader.hasNext()).isFalse();
|
||||||
@ -148,7 +148,7 @@ public final class BaseXmlReaderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadEmptyArrayWithComment() throws IOException {
|
public void testReadEmptyArrayWithComment() throws IOException {
|
||||||
BaseXmlReader reader = new BaseXmlReader(reader("<array><!-- comment --></array>"));
|
NativeXmlReader reader = new NativeXmlReader(reader("<array><!-- comment --></array>"));
|
||||||
assertThat(reader.hasNext()).isTrue();
|
assertThat(reader.hasNext()).isTrue();
|
||||||
reader.beginTag();
|
reader.beginTag();
|
||||||
assertThat(reader.hasNext()).isFalse();
|
assertThat(reader.hasNext()).isFalse();
|
||||||
@ -159,7 +159,7 @@ public final class BaseXmlReaderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadConciseEmptyArray() throws IOException {
|
public void testReadConciseEmptyArray() throws IOException {
|
||||||
BaseXmlReader reader = new BaseXmlReader(reader("<array/>"));
|
NativeXmlReader reader = new NativeXmlReader(reader("<array/>"));
|
||||||
assertThat(reader.hasNext()).isTrue();
|
assertThat(reader.hasNext()).isTrue();
|
||||||
reader.beginTag();
|
reader.beginTag();
|
||||||
assertThat(reader.hasNext()).isFalse();
|
assertThat(reader.hasNext()).isFalse();
|
||||||
|
Loading…
Reference in New Issue
Block a user