XLIFFResource extends ResourceFilter { @Override public void write(OutputStream outStream, LanguageBundle languageBundle, FilterOptions options) throws IOException, ResourceFilterException { List<ResourceString> resStrings = languageBundle.getSortedResourceStrings(); String targetLanguage = languageBundle.getEmbeddedLanguageCode(); if (targetLanguage == null || targetLanguage.isEmpty()) { throw new ResourceFilterException("Target language is not specified."); } DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = null; try { docBuilder = docFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } Document doc = docBuilder.newDocument(); Element xliff = doc.createElement(XLIFF_STRING); xliff.setAttribute(VERSION_STRING, VERSION_NUMBER_STRING); xliff.setAttribute(XMLNS_STRING,XMLNS_VALUE_STRING); xliff.setAttribute(XSI_STRING,XSI_VALUE_STRING); Element file = doc.createElement(FILE_STRING); file.setAttribute(ORIGINAL_STRING, GLOBAL_STRING); file.setAttribute(DATATYPE_STRING, PLAINTEXT_STRING); file.setAttribute(SOURCE_LANGUAGE_STRING, ENGLISH); file.setAttribute(TARGET_LANGUAGE_STRING, targetLanguage); xliff.appendChild(file); Element body = doc.createElement(BODY_STRING); file.appendChild(body); for (ResourceString resString : resStrings) { Element trans_unit = doc.createElement(UNIT_STRING); trans_unit.setAttribute(ID_STRING, resString.getKey()); Element source = doc.createElement(SOURCE_STRING); source.setTextContent(resString.getSourceValue()); trans_unit.appendChild(source); Element target = doc.createElement(TARGET_STRING); target.setTextContent(resString.getValue()); trans_unit.appendChild(target); body.appendChild(trans_unit); } doc.appendChild(xliff); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = null; try { transformer = transformerFactory.newTransformer(); } catch (TransformerConfigurationException e) { throw new RuntimeException(e); } transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http: DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(outStream); try { transformer.transform(source, result); } catch (TransformerException e) { throw new RuntimeException(e); } }  @Override LanguageBundle parse(InputStream inStream, FilterOptions options); @Override void write(OutputStream outStream, LanguageBundle languageBundle,
            FilterOptions options); @Override @Deprecated /* * This method is incomplete and may not produce the expected output. * * (non-Javadoc) * @see com.ibm.g11n.pipeline.resfilter.ResourceFilter#merge(java.io.InputStream, java.io.OutputStream, java.lang.String, java.util.Collection) */ void merge(InputStream baseStream, OutputStream outStream, LanguageBundle languageBundle,
            FilterOptions options);  }
@Test public void testWrite() throws IOException, ResourceFilterException { File tempFile = File.createTempFile(this.getClass().getSimpleName(), ".xlf"); tempFile.deleteOnExit(); try (OutputStream os = new FileOutputStream(tempFile)) { res.write(os, WRITE_BUNDLE, new FilterOptions(Locale.JAPANESE)); os.flush(); assertThat(EXPECTED_WRITE_FILE, CompareMatcher.isIdenticalTo(tempFile)); } }