Skip to content

Commit

Permalink
Fix encoding of Inspire observations for streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
CarstenHollmann committed Nov 18, 2022
1 parent 66e76d6 commit bc73350
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (C) 2015-2022 52°North Spatial Information Research GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.n52.shetland.arcgis.service.feature;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.n52.svalbard.encode;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -48,8 +47,7 @@
* @since 1.0.0
*
*/
public class InspireOmObservationEncoder
extends AbstractXmlEncoder<XmlObject, Object>
public class InspireOmObservationEncoder extends AbstractXmlEncoder<XmlObject, Object>
implements ObservationEncoder<XmlObject, Object>, StreamingEncoder<XmlObject, Object> {

private static final Set<EncoderKey> ENCODER_KEYS =
Expand Down Expand Up @@ -87,10 +85,13 @@ public void encode(Object element, OutputStream outputStream, EncodingContext ct
.with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions),
outputStream, (OmObservation) element).write();
} else {
// writeIndent(encodingValues.getIndent(), outputStream);
encode(element, ctx).save(outputStream, getXmlOptions());
new InspireOmObservationXmlStreamWriter(
ctx.with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository())
.with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions),
outputStream, (OmObservation) element, this).write();

}
} catch (IOException | XMLStreamException e) {
} catch (XMLStreamException e) {
throw new EncodingException("Error while writing element to stream!", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2015-2022 52°North Spatial Information Research GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.n52.svalbard.encode;

import java.io.OutputStream;

import javax.xml.stream.XMLStreamException;

import org.n52.shetland.ogc.om.OmObservation;
import org.n52.svalbard.encode.exception.EncodingException;
import org.n52.svalbard.write.XmlStreamWriter;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@SuppressFBWarnings({"EI_EXPOSE_REP2"})
public class InspireOmObservationXmlStreamWriter extends XmlStreamWriter<OmObservation> {


private InspireOmObservationEncoder encoder;

public InspireOmObservationXmlStreamWriter(EncodingContext context, OutputStream outputStream,
OmObservation element, InspireOmObservationEncoder encoder) throws XMLStreamException {
super(context, outputStream, element);
this.encoder = encoder;
}

@Override
public void write() throws XMLStreamException, EncodingException {
rawText(encoder.encode(getElement(), getContext()).xmlText(getXmlOptions().setSaveNoXmlDecl()));
}

}

0 comments on commit bc73350

Please sign in to comment.