private static Transformer createMaskingXslTransformer() { return XmlProcessingCallback.execute(() -> { try (InputStream inputStream = JaxbUtil.class.getResourceAsStream("/xsl/mask-config.xsl")) { return TransformerFactory.newInstance().newTransformer(new StreamSource(inputStream)); } }); }
private static Transformer createMaskingXslTransformer() { return XmlProcessingCallback.execute(() -> { try (InputStream inputStream = JaxbUtil.class.getResourceAsStream("/xsl/mask-config.xsl")) { return TransformerFactory.newInstance().newTransformer(new StreamSource(inputStream)); } }); }
public static void marshalMasked(Config object, OutputStream outputStream) { XmlProcessingCallback.execute(() -> { Marshaller marshaller = MarshallerBuilder.create() .withXmlMediaType() .withoutBeanValidation() .build(); String xmlData; try (StringWriter writer = new StringWriter()) { marshaller.marshal(object, writer); xmlData = writer.toString(); } StreamSource xmlSource = new StreamSource(new StringReader(xmlData)); try (StringWriter writer = new StringWriter()) { StreamResult xmlResult = new StreamResult(writer); createMaskingXslTransformer().transform(xmlSource, xmlResult); writer.flush(); Unmarshaller unmarshaller = UnmarshallerBuilder.create() .withXmlMediaType() .withoutBeanValidation() .build(); Config masked = (Config) unmarshaller.unmarshal(new StringReader(writer.toString())); marshalWithNoValidation(masked, outputStream); return null; } }); }
public static void marshalMasked(Config object, OutputStream outputStream) { XmlProcessingCallback.execute(() -> { Marshaller marshaller = MarshallerBuilder.create() .withXmlMediaType() .withoutBeanValidation() .build(); String xmlData; try (StringWriter writer = new StringWriter()) { marshaller.marshal(object, writer); xmlData = writer.toString(); } StreamSource xmlSource = new StreamSource(new StringReader(xmlData)); try (StringWriter writer = new StringWriter()) { StreamResult xmlResult = new StreamResult(writer); createMaskingXslTransformer().transform(xmlSource, xmlResult); writer.flush(); Unmarshaller unmarshaller = UnmarshallerBuilder.create() .withXmlMediaType() .withoutBeanValidation() .build(); Config masked = (Config) unmarshaller.unmarshal(new StringReader(writer.toString())); marshalWithNoValidation(masked, outputStream); return null; } }); }