use of ddf.catalog.transformer.api.PrintWriter in project ddf by codice.
the class MetacardMarshallerImpl method geoToXml.
private String geoToXml(BinaryContent content, XmlPullParser parser) throws UnsupportedEncodingException {
PrintWriter destination;
try (InputStreamReader inputStreamReader = new InputStreamReader(content.getInputStream(), StandardCharsets.UTF_8.name())) {
XppReader source = new XppReader(inputStreamReader, parser);
// if multi-threading, cannot abstract PrintWriter to class member
destination = writerProvider.build(Metacard.class);
new HierarchicalStreamCopier().copy(source, destination);
} catch (IOException e) {
throw new RuntimeException(e);
}
return destination.makeString();
}
use of ddf.catalog.transformer.api.PrintWriter in project ddf by codice.
the class TestCswQueryResponseTransformer method testMarshalAcknowledgementWithFailedTransforms.
@Test
public void testMarshalAcknowledgementWithFailedTransforms() throws WebApplicationException, IOException, JAXBException, CatalogTransformerException {
GetRecordsType query = new GetRecordsType();
query.setResultType(ResultType.RESULTS);
query.setMaxRecords(BigInteger.valueOf(6));
query.setStartPosition(BigInteger.valueOf(0));
SourceResponse sourceResponse = createSourceResponse(query, 6);
Map<String, Serializable> args = new HashMap<>();
args.put(CswConstants.RESULT_TYPE_PARAMETER, ResultType.RESULTS);
args.put(CswConstants.GET_RECORDS, query);
PrintWriter printWriter = getSimplePrintWriter();
MetacardTransformer mockMetacardTransformer = mock(MetacardTransformer.class);
final AtomicLong atomicLong = new AtomicLong(0);
when(mockMetacardTransformer.transform(any(Metacard.class), anyMap())).then(invocationOnMock -> {
if (atomicLong.incrementAndGet() == 2) {
throw new CatalogTransformerException("");
}
Metacard metacard = (Metacard) invocationOnMock.getArguments()[0];
BinaryContentImpl bci = new BinaryContentImpl(IOUtils.toInputStream(metacard.getId() + ","), new MimeType("application/xml"));
return bci;
});
when(mockPrintWriterProvider.build((Class<Metacard>) notNull())).thenReturn(printWriter);
when(mockTransformerManager.getTransformerBySchema(anyString())).thenReturn(mockMetacardTransformer);
CswQueryResponseTransformer cswQueryResponseTransformer = new CswQueryResponseTransformer(mockTransformerManager, mockPrintWriterProvider);
cswQueryResponseTransformer.init();
BinaryContent content = cswQueryResponseTransformer.transform(sourceResponse, args);
cswQueryResponseTransformer.destroy();
String xml = new String(content.getByteArray());
assertThat(xml, containsString(CswQueryResponseTransformer.NUMBER_OF_RECORDS_MATCHED_ATTRIBUTE + " 6"));
assertThat(xml, containsString(CswQueryResponseTransformer.NUMBER_OF_RECORDS_RETURNED_ATTRIBUTE + " 5"));
assertThat(xml, containsString(CswQueryResponseTransformer.NEXT_RECORD_ATTRIBUTE + " 0"));
}
use of ddf.catalog.transformer.api.PrintWriter in project ddf by codice.
the class TestEscapingPrintWriter method testXmlMetaCharacters.
@Test
public void testXmlMetaCharacters() throws CatalogTransformerException {
String unescaped = "& > < \" \'";
String escaped = "& > < " '";
StringWriter stringWriter = new StringWriter(128);
PrintWriter escapingPrintWriter = new EscapingPrintWriter(stringWriter);
escapingPrintWriter.setValue(unescaped);
escapingPrintWriter.flush();
String processed = stringWriter.toString();
assertEquals(escaped, processed);
}
use of ddf.catalog.transformer.api.PrintWriter in project ddf by codice.
the class TestEscapingPrintWriter method testSurrogateCharacter.
@Test
public void testSurrogateCharacter() throws CatalogTransformerException {
String input = new String(Character.toChars(888));
String expected = "͸";
StringWriter stringWriter = new StringWriter(8);
PrintWriter escapingPrintWriter = new EscapingPrintWriter(stringWriter);
escapingPrintWriter.setValue(input);
escapingPrintWriter.flush();
String output = stringWriter.toString();
assertEquals(expected, output);
}
Aggregations