@Test public void testParseDocument() throws FileNotFoundException { final int entriesCount = 5; File sourceFile = new File("src/test/resources/test.pot"); InputStream inputStream = new FileInputStream(sourceFile); LocaleCode fromLocaleCode = LocaleCode.EN; String filename = "test.pot"; Pair<DocumentContent, Map<String, Message>> contents = poFileAdapter.parseSourceDocument(inputStream, filename, fromLocaleCode); assertThat(contents.getLeft()).isNotNull(); assertThat(contents.getLeft().getUrl()).isEqualTo(filename); assertThat(contents.getLeft().getLocaleCode()).isEqualTo(fromLocaleCode.getId()); assertThat(contents.getLeft().getContents()).hasSize(entriesCount); assertThat(contents.getRight()).isNotEmpty(); }
@Override public Pair<DocumentContent, Map<String, Message>> parseSourceDocument( InputStream inputStream, String url, LocaleCode fromLocaleCode) { List<TypeString> contents = new ArrayList<>(); Map<String, Message> messages = new LinkedHashMap<>(); MessageStreamParser messageParser = createParser(inputStream); while (messageParser.hasNext()) { Message message = messageParser.next(); String id = createId(message); if (message.isHeader()) { } else if (message.isObsolete()) { } else { contents.add(new TypeString(getSourceContent(message), MediaType.TEXT_PLAIN_TYPE.toString(), id)); } messages.put(id, message); } return Pair.of( new DocumentContent(contents, url, fromLocaleCode.getId()), messages); }
PoFileAdapter implements TranslationFileAdapter { @Override public Pair<DocumentContent, Map<String, Message>> parseSourceDocument( InputStream inputStream, String url, LocaleCode fromLocaleCode) { List<TypeString> contents = new ArrayList<>(); Map<String, Message> messages = new LinkedHashMap<>(); MessageStreamParser messageParser = createParser(inputStream); while (messageParser.hasNext()) { Message message = messageParser.next(); String id = createId(message); if (message.isHeader()) { } else if (message.isObsolete()) { } else { contents.add(new TypeString(getSourceContent(message), MediaType.TEXT_PLAIN_TYPE.toString(), id)); } messages.put(id, message); } return Pair.of( new DocumentContent(contents, url, fromLocaleCode.getId()), messages); } }
PoFileAdapter implements TranslationFileAdapter { @Override public Pair<DocumentContent, Map<String, Message>> parseSourceDocument( InputStream inputStream, String url, LocaleCode fromLocaleCode) { List<TypeString> contents = new ArrayList<>(); Map<String, Message> messages = new LinkedHashMap<>(); MessageStreamParser messageParser = createParser(inputStream); while (messageParser.hasNext()) { Message message = messageParser.next(); String id = createId(message); if (message.isHeader()) { } else if (message.isObsolete()) { } else { contents.add(new TypeString(getSourceContent(message), MediaType.TEXT_PLAIN_TYPE.toString(), id)); } messages.put(id, message); } return Pair.of( new DocumentContent(contents, url, fromLocaleCode.getId()), messages); } PoFileAdapter(Charset charset); }
PoFileAdapter implements TranslationFileAdapter { @Override public Pair<DocumentContent, Map<String, Message>> parseSourceDocument( InputStream inputStream, String url, LocaleCode fromLocaleCode) { List<TypeString> contents = new ArrayList<>(); Map<String, Message> messages = new LinkedHashMap<>(); MessageStreamParser messageParser = createParser(inputStream); while (messageParser.hasNext()) { Message message = messageParser.next(); String id = createId(message); if (message.isHeader()) { } else if (message.isObsolete()) { } else { contents.add(new TypeString(getSourceContent(message), MediaType.TEXT_PLAIN_TYPE.toString(), id)); } messages.put(id, message); } return Pair.of( new DocumentContent(contents, url, fromLocaleCode.getId()), messages); } PoFileAdapter(Charset charset); @Override Pair<DocumentContent, Map<String, Message>> parseSourceDocument(
        InputStream inputStream, String url, LocaleCode fromLocaleCode); @Override void writeTranslatedFile(@NotNull OutputStream output,
        LocaleCode fromLocaleCode, LocaleCode toLocaleCode,
        DocumentContent translatedDocContent, Map<String, Message> messages,
        String attribution); @Override String getTranslationFileExtension(); }
PoFileAdapter implements TranslationFileAdapter { @Override public Pair<DocumentContent, Map<String, Message>> parseSourceDocument( InputStream inputStream, String url, LocaleCode fromLocaleCode) { List<TypeString> contents = new ArrayList<>(); Map<String, Message> messages = new LinkedHashMap<>(); MessageStreamParser messageParser = createParser(inputStream); while (messageParser.hasNext()) { Message message = messageParser.next(); String id = createId(message); if (message.isHeader()) { } else if (message.isObsolete()) { } else { contents.add(new TypeString(getSourceContent(message), MediaType.TEXT_PLAIN_TYPE.toString(), id)); } messages.put(id, message); } return Pair.of( new DocumentContent(contents, url, fromLocaleCode.getId()), messages); } PoFileAdapter(Charset charset); @Override Pair<DocumentContent, Map<String, Message>> parseSourceDocument(
        InputStream inputStream, String url, LocaleCode fromLocaleCode); @Override void writeTranslatedFile(@NotNull OutputStream output,
        LocaleCode fromLocaleCode, LocaleCode toLocaleCode,
        DocumentContent translatedDocContent, Map<String, Message> messages,
        String attribution); @Override String getTranslationFileExtension();  }