Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't related to the protobuf serialization

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/***************************** BEGIN LICENSE BLOCK ***************************

The contents of this file are subject to the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one
at http://mozilla.org/MPL/2.0/.

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the License.

Copyright (C) 2012-2015 Sensia Software LLC. All Rights Reserved.

******************************* END LICENSE BLOCK ***************************/

package org.vast.swe.fast;

import com.ctc.wstx.api.WstxOutputProperties;
import com.google.gson.FormattingStyle;
import com.google.gson.Strictness;
import net.opengis.swe.v20.*;
import net.opengis.swe.v20.Boolean;
import org.vast.data.AbstractArrayImpl;
import org.vast.data.XMLEncodingImpl;
import org.vast.swe.SWEDataTypeUtils;
import org.vast.util.DateTimeFormat;
import org.vast.util.WriterException;

import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.stream.*;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Reader;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
* <p>
* New implementation of XML data writer with better efficiency since the
* write tree is pre-computed during init instead of being re-evaluated
* while iterating through the component tree.
* </p>
*
* @author Ashley Poteau
* @since Dec 2, 2025
*/

public class CotDataReader extends XmlDataParser {
static final String COT_ERROR = "Error writing XML stream for ";
private final Reader in;

protected XMLStreamReader xmlReader;
protected XMLStreamWriter xmlWriter;
protected String namespace;
protected String prefix;
protected Map<String, XmlDataWriter.IntegerWriter> countWriters = new HashMap<>();

public CotDataReader(Reader in) {
this.in = Objects.requireNonNull(in, "in == null");
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/***************************** BEGIN LICENSE BLOCK ***************************

The contents of this file are subject to the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one
at http://mozilla.org/MPL/2.0/.

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the License.

Copyright (C) 2012-2015 Sensia Software LLC. All Rights Reserved.

******************************* END LICENSE BLOCK ***************************/

package org.vast.swe.fast;

import com.ctc.wstx.api.WstxOutputProperties;
import com.google.gson.FormattingStyle;
import com.google.gson.Strictness;
import net.opengis.swe.v20.*;
import net.opengis.swe.v20.Boolean;
import org.vast.data.AbstractArrayImpl;
import org.vast.data.XMLEncodingImpl;
import org.vast.swe.SWEDataTypeUtils;
import org.vast.util.DateTimeFormat;
import org.vast.util.WriterException;

import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;


/**
* <p>
* New implementation of XML data writer with better efficiency since the
* write tree is pre-computed during init instead of being re-evaluated
* while iterating through the component tree.
* </p>
*
* @author Ashley Poteau
* @since Oct 31, 2025
*/
public class CotDataWriter extends XmlDataWriter {
static final String COT_ERROR = "Error writing XML stream for ";

protected String namespace;
protected String prefix;
protected Map<String, XmlDataWriter.IntegerWriter> countWriters = new HashMap<>();
private boolean serializeNulls = true;
private FormattingStyle formattingStyle;
// These fields cache data derived from the formatting style, to avoid having to
// re-evaluate it every time something is written
private String formattedColon;
private String formattedComma;
private boolean usesEmptyNewlineAndIndent;


public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
xmlWriter.writeStartElement(namespaceURI, localName);
}

public void writeCotCharacters(String text) throws XMLStreamException {
if (xmlWriter == null) {
throw new IllegalStateException("XMLStreamWriter not initialized. Call setOutput() first.");
}
xmlWriter.writeCharacters(text);
}

public void writeCotStartElement(String text) throws XMLStreamException {
if (xmlWriter == null) {
throw new IllegalStateException("XMLStreamWriter not initialized. Call setOutput() first.");
}
xmlWriter.writeStartElement(text);
}

public void writeCotAttribute(String var1, String var2) throws XMLStreamException {
if (xmlWriter == null) {
throw new IllegalStateException("XMLStreamWriter not initialized. Call setOutput() first.");
}
xmlWriter.writeAttribute(var1, var2);
}

@Override
public void startStream(boolean addWrapper) throws IOException
{
try
{
if (addWrapper)
xmlWriter.writeStartElement("event");
}
catch (XMLStreamException e)
{
throw new IOException(e.getMessage(), e.getCause());
}
}

public void writeCotEndElement() throws XMLStreamException {
xmlWriter.writeEndElement();
}

public final void setSerializeNulls(boolean serializeNulls) {

this.serializeNulls = serializeNulls;
}

/**
* Returns true if object members are serialized when their value is null. This has no impact on
* array elements. The default is true.
*/
public final boolean getSerializeNulls() {
return serializeNulls;
}

// public final void setFormattingStyle(FormattingStyle formattingStyle) {
// this.formattingStyle = Objects.requireNonNull(formattingStyle);
//
// this.formattedComma = ",";
// if (this.formattingStyle.usesSpaceAfterSeparators()) {
// this.formattedColon = ": ";
//
// // Only add space if no newline is written
// if (this.formattingStyle.getNewline().isEmpty()) {
// this.formattedComma = ", ";
// }
// } else {
// this.formattedColon = ":";
// }
//
// this.usesEmptyNewlineAndIndent =
// this.formattingStyle.getNewline().isEmpty() && this.formattingStyle.getIndent().isEmpty();
// }
//
//
// public final void setIndent(String indent) {
// if (indent.isEmpty()) {
// setFormattingStyle(FormattingStyle.COMPACT);
// } else {
// setFormattingStyle(FormattingStyle.PRETTY.withIndent(indent));
// }
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public int process(DataBlock data, int index) throws IOException
}


protected void writeStartElement(String eltName) throws XMLStreamException
public void writeStartElement(String eltName) throws XMLStreamException
{
if (namespace != null)
{
Expand Down
Loading
Loading