001/* 002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Anahide Tchertchian 016 */ 017package org.nuxeo.ecm.platform.test; 018 019import java.io.File; 020import java.io.FileInputStream; 021import java.io.IOException; 022import java.io.InputStream; 023import java.util.ArrayList; 024import java.util.Collections; 025import java.util.List; 026import java.util.Properties; 027 028/** 029 * Differ for translation files. 030 * 031 * @since 7.3 032 */ 033public class TranslationMessagesDiffer { 034 035 protected final Properties src; 036 037 protected final Properties dst; 038 039 public TranslationMessagesDiffer(Properties src, Properties dst) { 040 super(); 041 this.src = src; 042 this.dst = dst; 043 } 044 045 public List<String> getMissingDestKeys() { 046 return getMissingKeys(src, dst); 047 } 048 049 public List<String> getAdditionalDestKeys() { 050 return getMissingKeys(dst, src); 051 } 052 053 protected List<String> getMissingKeys(Properties src, Properties dst) { 054 List<String> missing = new ArrayList<>(); 055 for (Object item : src.keySet()) { 056 if (!dst.containsKey(item)) { 057 missing.add((String) item); 058 } 059 } 060 Collections.sort(missing); 061 return missing; 062 } 063 064 public static TranslationProperties extractProps(File file) throws IOException { 065 InputStream in = new FileInputStream(file); 066 TranslationProperties props = new TranslationProperties(); 067 props.load(in); 068 return props; 069 } 070 071}