1919
2020import static org .dkpro .core .io .bioc .BioCComponent .getCollectionMetadataField ;
2121
22- import javax .xml .bind .JAXBContext ;
23- import javax .xml .bind .JAXBException ;
24- import javax .xml .bind .Marshaller ;
25-
2622import org .apache .uima .UimaContext ;
2723import org .apache .uima .analysis_engine .AnalysisEngineProcessException ;
2824import org .apache .uima .fit .descriptor .ConfigurationParameter ;
3935
4036import de .tudarmstadt .ukp .dkpro .core .api .metadata .type .DocumentMetaData ;
4137import eu .openminted .share .annotations .api .DocumentationResource ;
38+ import jakarta .xml .bind .JAXBContext ;
39+ import jakarta .xml .bind .JAXBException ;
40+ import jakarta .xml .bind .Marshaller ;
4241
4342/**
4443 * Writer for the BioC format.
@@ -75,14 +74,17 @@ public class BioCWriter
7574 private String targetEncoding ;
7675
7776 private JAXBContext context ;
77+ private Marshaller marshaller ;
7878
7979 @ Override
8080 public void initialize (UimaContext aContext ) throws ResourceInitializationException
8181 {
8282 super .initialize (aContext );
83-
8483 try {
8584 context = JAXBContext .newInstance (BioCCollection .class );
85+ marshaller = context .createMarshaller ();
86+ marshaller .setProperty (Marshaller .JAXB_FORMATTED_OUTPUT , indent );
87+ marshaller .setProperty (Marshaller .JAXB_ENCODING , targetEncoding );
8688 }
8789 catch (JAXBException e ) {
8890 throw new ResourceInitializationException (e );
@@ -93,11 +95,6 @@ public void initialize(UimaContext aContext) throws ResourceInitializationExcept
9395 public void process (JCas aJCas ) throws AnalysisEngineProcessException
9496 {
9597 try (var docOS = getOutputStream (aJCas , filenameSuffix )) {
96- Marshaller marshaller = context .createMarshaller ();
97- marshaller .setProperty (Marshaller .JAXB_FORMATTED_OUTPUT , true );
98- // Set to fragment mode to omit XML declaration
99- marshaller .setProperty (Marshaller .JAXB_FRAGMENT , true );
100-
10198 var bioCCollection = new BioCCollection ();
10299
103100 // Base-information - may be overwritten by the metadata fields below
0 commit comments