Commit 90903c1b authored by Luc Maisonobe's avatar Luc Maisonobe

Merge branch 'issue-474' into develop

parents 5f029941 c0937196
......@@ -273,9 +273,7 @@ public class AemWriter extends AbstractMessageWriter<Header, AemSegment, AemFile
// Loop on attitude data
startAttitudeBlock(generator);
if (segment instanceof AemSegment) {
generator.writeComments(((AemSegment) segment).getData().getComments());
}
generator.writeComments(((AemSegment) segment).getData().getComments());
for (final TimeStampedAngularCoordinates coordinates : segment.getAngularCoordinates()) {
writeAttitudeEphemerisLine(generator, metadata, coordinates);
}
......
......@@ -27,6 +27,7 @@ import org.orekit.files.ccsds.section.Header;
import org.orekit.files.ccsds.utils.FileFormat;
import org.orekit.files.ccsds.utils.generation.Generator;
import org.orekit.files.ccsds.utils.generation.KvnGenerator;
import org.orekit.files.ccsds.utils.generation.XmlGenerator;
import org.orekit.files.general.AttitudeEphemerisFile;
import org.orekit.files.general.AttitudeEphemerisFile.SatelliteAttitudeEphemeris;
import org.orekit.files.general.AttitudeEphemerisFileWriter;
......@@ -136,7 +137,7 @@ public class AttitudeWriter implements AttitudeEphemerisFileWriter {
try (Generator generator = fileFormat == FileFormat.KVN ?
new KvnGenerator(appendable, AemWriter.KVN_PADDING_WIDTH, outputName) :
null) {
new XmlGenerator(appendable, XmlGenerator.DEFAULT_INDENT, outputName)) {
writer.writeHeader(generator, header);
// Loop on segments
......
......@@ -95,7 +95,7 @@ public class OcmWriter extends AbstractMessageWriter<Header, Segment<OcmMetadata
}
}
if (segment.getData().getPhysicBlock() != null && segment.getData().getPhysicBlock() != null) {
if (segment.getData().getPhysicBlock() != null) {
// write optional physical properties block
new PhysicalPropertiesWriter(segment.getData().getPhysicBlock(),
getTimeConverter()).
......@@ -117,21 +117,21 @@ public class OcmWriter extends AbstractMessageWriter<Header, Segment<OcmMetadata
}
}
if (segment.getData().getPerturbationsBlock() != null && segment.getData().getPerturbationsBlock() != null) {
if (segment.getData().getPerturbationsBlock() != null) {
// write optional perturbation parameters block
new PerturbationsWriter(segment.getData().getPerturbationsBlock(),
getTimeConverter()).
write(generator);
}
if (segment.getData().getOrbitDeterminationBlock() != null && segment.getData().getOrbitDeterminationBlock() != null) {
if (segment.getData().getOrbitDeterminationBlock() != null) {
// write optional orbit determination block
new OrbitDeterminationWriter(segment.getData().getOrbitDeterminationBlock(),
getTimeConverter()).
write(generator);
}
if (segment.getData().getUserDefinedBlock() != null && segment.getData().getUserDefinedBlock() != null) {
if (segment.getData().getUserDefinedBlock() != null) {
// write optional user defined parameters block
new UserDefinedWriter(OcmDataSubStructureKey.userDef.name(),
OcmDataSubStructureKey.USER.name(),
......
......@@ -28,6 +28,7 @@ import org.orekit.files.ccsds.section.Header;
import org.orekit.files.ccsds.utils.FileFormat;
import org.orekit.files.ccsds.utils.generation.Generator;
import org.orekit.files.ccsds.utils.generation.KvnGenerator;
import org.orekit.files.ccsds.utils.generation.XmlGenerator;
import org.orekit.files.general.EphemerisFile;
import org.orekit.files.general.EphemerisFile.SatelliteEphemeris;
import org.orekit.files.general.EphemerisFileWriter;
......@@ -139,7 +140,7 @@ public class EphemerisWriter implements EphemerisFileWriter {
try (Generator generator = fileFormat == FileFormat.KVN ?
new KvnGenerator(appendable, OemWriter.KVN_PADDING_WIDTH, outputName) :
null) {
new XmlGenerator(appendable, XmlGenerator.DEFAULT_INDENT, outputName)) {
writer.writeHeader(generator, header);
// Loop on segments
......
......@@ -46,6 +46,12 @@ public interface Generator extends AutoCloseable {
*/
void startMessage(String messageTypeKey, double version) throws IOException;
/** End CCSDS message.
* @param messageTypeKey key for message type
* @throws IOException if an I/O error occurs.
*/
void endMessage(String messageTypeKey) throws IOException;
/** Write comment lines.
* @param comments comments to write
* @throws IOException if an I/O error occurs.
......
......@@ -80,6 +80,12 @@ public class KvnGenerator extends AbstractGenerator {
writeEntry(messageTypeKey, String.format(AccurateFormatter.STANDARDIZED_LOCALE, "%.1f", version), true);
}
/** {@inheritDoc} */
@Override
public void endMessage(final String messageTypeKey) throws IOException {
// nothing to do
}
/** {@inheritDoc} */
@Override
public void writeComments(final List<String> comments) throws IOException {
......
/* Copyright 2002-2021 CS GROUP
* Licensed to CS GROUP (CS) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* CS licenses this file to You 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.orekit.files.ccsds.utils.generation;
import java.io.IOException;
import java.util.List;
import org.orekit.files.ccsds.utils.FileFormat;
import org.orekit.utils.AccurateFormatter;
/** Generator for eXtended Markup Language CCSDS messages.
* @author Luc Maisonobe
* @since 11.0
*/
public class XmlGenerator extends AbstractGenerator {
/** Default number of space for each indentation level. */
public static final int DEFAULT_INDENT = 2;
/** XML prolog. */
private static final String PROLOG = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
/** Root element start tag. */
private static final String ROOT_START = "<%s id=\"%s\" version=\"%.1f\">";
/** Element end tag. */
private static final String START_TAG = "<%s>";
/** Element end tag. */
private static final String END_TAG = "</%s>";
/** Leaf element format. */
private static final String LEAF = "<%s>%s</%s>";
/** Comment key. */
private static final String COMMENT = "COMMENT";
/** Indentation size. */
private final int indentation;
/** Nesting level. */
private int level;
/** Simple constructor.
* @param output destination of generated output
* @param indentation number of space for each indentation level
* @param outputName output name for error messages
* @see #DEFAULT_INDENT
*/
public XmlGenerator(final Appendable output, final int indentation, final String outputName) {
super(output, outputName);
this.indentation = indentation;
this.level = 0;
}
/** {@inheritDoc} */
@Override
public FileFormat getFormat() {
return FileFormat.XML;
}
/** {@inheritDoc} */
@Override
public void startMessage(final String messageTypeKey, final double version) throws IOException {
writeRawData(PROLOG);
newLine();
indent();
writeRawData(String.format(AccurateFormatter.STANDARDIZED_LOCALE, ROOT_START,
messageTypeKey, messageTypeKey, version));
newLine();
++level;
}
/** {@inheritDoc} */
@Override
public void endMessage(final String messageTypeKey) throws IOException {
--level;
indent();
writeRawData(String.format(AccurateFormatter.STANDARDIZED_LOCALE, END_TAG,
messageTypeKey));
newLine();
}
/** {@inheritDoc} */
@Override
public void writeComments(final List<String> comments) throws IOException {
for (final String comment : comments) {
writeEntry(COMMENT, comment, false);
}
}
/** {@inheritDoc} */
@Override
public void writeEntry(final String key, final String value, final boolean mandatory) throws IOException {
if (value == null) {
complain(key, mandatory);
} else {
indent();
append(String.format(AccurateFormatter.STANDARDIZED_LOCALE, LEAF, key, value, key));
}
}
/** {@inheritDoc} */
@Override
public void enterSection(final String name) throws IOException {
indent();
append(String.format(AccurateFormatter.STANDARDIZED_LOCALE, START_TAG, name));
++level;
super.enterSection(name);
}
/** {@inheritDoc} */
@Override
public String exitSection() throws IOException {
final String name = super.exitSection();
--level;
indent();
append(String.format(AccurateFormatter.STANDARDIZED_LOCALE, END_TAG, name));
return name;
}
/** Indent line.
*/
private void indent() throws IOException {
for (int i = 0; i < level * indentation; ++i) {
writeRawData(' ');
}
}
}
......@@ -43,6 +43,7 @@ import org.orekit.files.ccsds.utils.FileFormat;
import org.orekit.files.ccsds.utils.generation.Generator;
import org.orekit.files.ccsds.utils.generation.KvnGenerator;
import org.orekit.files.ccsds.utils.generation.MessageWriter;
import org.orekit.files.ccsds.utils.generation.XmlGenerator;
import org.orekit.files.ccsds.utils.lexical.MessageParser;
import org.orekit.frames.Frame;
import org.orekit.time.AbsoluteDate;
......@@ -59,7 +60,7 @@ public abstract class AbstractNdmWriterTest<H extends Header, S extends Segment<
protected void doTest(final String name) {
doTest(name, FileFormat.KVN);
// TODO doTest(name, FileFormat.XML);
// doTest(name, FileFormat.XML);
}
protected void doTest(final String name, final FileFormat format) {
......@@ -70,8 +71,8 @@ public abstract class AbstractNdmWriterTest<H extends Header, S extends Segment<
// write the parsed file back to a characters array
final CharArrayWriter caw = new CharArrayWriter();
final Generator generator = format == FileFormat.KVN ?
new KvnGenerator(caw, 25, "dummy") :
null; // TODO
new KvnGenerator(caw, 25, "dummy.kvn") :
new XmlGenerator(caw, XmlGenerator.DEFAULT_INDENT, "dummy.xml");
getWriter().writeMessage(generator, original);
// reparse the written file
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment