11/*
2- * Copyright IBM Corp. 2016
2+ * Copyright IBM Corp. 2016, 2017
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -211,15 +211,37 @@ private void exportLanguageResource(ServiceClient client, SourceBundleFile bf, S
211211 outputFile .getParentFile ().mkdirs ();
212212 }
213213
214+ Bundle bundle ;
215+
214216 switch (outContntOpt ) {
215217 case MERGE_TO_SOURCE :
216- mergeTranslation (client , bf .getBundleId (), language , bf .getType (), bf .getFile (), outputFile );
218+ bundle = getBundle (client , bf .getBundleId (), language , false , true );
219+ mergeTranslation (bundle , language , bf .getType (), bf .getFile (), outputFile );
217220 break ;
221+
218222 case TRANSLATED_WITH_FALLBACK :
219- exportTranslation (client , bf .getBundleId (), language , bf .getType (), outputFile , true );
223+ bundle = getBundle (client , bf .getBundleId (), language , false , true );
224+ exportTranslation (bundle , language , bf .getType (), outputFile );
220225 break ;
226+
221227 case TRANSLATED_ONLY :
222- exportTranslation (client , bf .getBundleId (), language , bf .getType (), outputFile , false );
228+ bundle = getBundle (client , bf .getBundleId (), language , false , false );
229+ exportTranslation (bundle , language , bf .getType (), outputFile );
230+ break ;
231+
232+ case MERGE_REVIEWED_TO_SOURCE :
233+ bundle = getBundle (client , bf .getBundleId (), language , true , true );
234+ mergeTranslation (bundle , language , bf .getType (), bf .getFile (), outputFile );
235+ break ;
236+
237+ case REVIEWED_WITH_FALLBACK :
238+ bundle = getBundle (client , bf .getBundleId (), language , true , true );
239+ exportTranslation (bundle , language , bf .getType (), outputFile );
240+ break ;
241+
242+ case REVIEWED_ONLY :
243+ bundle = getBundle (client , bf .getBundleId (), language , true , false );
244+ exportTranslation (bundle , language , bf .getType (), outputFile );
223245 break ;
224246 }
225247 }
@@ -244,63 +266,61 @@ private String getLanguageId(String gpLanguageTag, LanguageIdStyle langIdStyle,
244266 return languageId ;
245267 }
246268
247- private void mergeTranslation (ServiceClient client , String bundleId , String language ,
248- ResourceType type , File srcFile , File outFile ) throws MojoFailureException {
249- Bundle resBundle = null ;
250- try {
251- resBundle = getBundle (client , bundleId , language , false );
252- } catch (ServiceException e ) {
253- throw new MojoFailureException ("Globalization Pipeline service error" , e );
254- }
255-
269+ private void mergeTranslation (Bundle bundle , String language , ResourceType type ,
270+ File srcFile , File outFile ) throws MojoFailureException {
256271 ResourceFilter filter = ResourceFilterFactory .get (type );
257272 try (FileOutputStream fos = new FileOutputStream (outFile );
258273 FileInputStream fis = new FileInputStream (srcFile )) {
259- filter .merge (fis , fos , language , resBundle );
274+ filter .merge (fis , fos , language , bundle );
260275 } catch (IOException e ) {
261276 throw new MojoFailureException ("I/O error while merging the translated values to "
262277 + outFile .getAbsolutePath (), e );
263278 }
264279 }
265280
266- private void exportTranslation (ServiceClient client , String bundleId , String language ,
267- ResourceType type , File outFile , boolean withFallback ) throws MojoFailureException {
268- Bundle resBundle = null ;
269- try {
270- resBundle = getBundle (client , bundleId , language , withFallback );
271- } catch (ServiceException e ) {
272- throw new MojoFailureException ("Globalization Pipeline service error" , e );
273- }
274-
281+ private void exportTranslation (Bundle bundle , String language , ResourceType type ,
282+ File outFile ) throws MojoFailureException {
275283 ResourceFilter filter = ResourceFilterFactory .get (type );
276284 try (FileOutputStream fos = new FileOutputStream (outFile )) {
277- filter .write (fos , language , resBundle );
285+ filter .write (fos , language , bundle );
278286 } catch (IOException e ) {
279287 throw new MojoFailureException ("Failed to write the translated resoruce data to "
280288 + outFile .getAbsolutePath (), e );
281289 }
282290 }
283291
284- private Bundle getBundle (ServiceClient client ,
285- String bundleId , String language , boolean withFallback ) throws ServiceException {
286- Map <String , ResourceEntryData > resEntries = client .getResourceEntries (bundleId , language );
287- Collection <ResourceString > resStrings = new LinkedList <>();
288- for (Entry <String , ResourceEntryData > entry : resEntries .entrySet ()) {
289- String key = entry .getKey ();
290- ResourceEntryData data = entry .getValue ();
291- String resVal = data .getValue ();
292- Integer seqNum = data .getSequenceNumber ();
293- if (resVal == null && withFallback ) {
294- resVal = data .getSourceValue ();
295- }
296- if (resVal != null ) {
297- ResourceString resString = new ResourceString (key , resVal );
298- if (seqNum != null ) {
299- resString .setSequenceNumber (seqNum .intValue ());
292+ private Bundle getBundle (ServiceClient client , String bundleId , String language ,
293+ boolean reviewedOnly , boolean withFallback ) throws MojoFailureException {
294+ try {
295+ Map <String , ResourceEntryData > resEntries = client .getResourceEntries (bundleId , language );
296+ Collection <ResourceString > resStrings = new LinkedList <>();
297+ for (Entry <String , ResourceEntryData > entry : resEntries .entrySet ()) {
298+ String key = entry .getKey ();
299+ ResourceEntryData data = entry .getValue ();
300+ String resVal = data .getValue ();
301+ Integer seqNum = data .getSequenceNumber ();
302+
303+ if (reviewedOnly ) {
304+ if (!data .isReviewed ()) {
305+ resVal = null ;
306+ }
307+ }
308+
309+ if (resVal == null && withFallback ) {
310+ resVal = data .getSourceValue ();
311+ }
312+
313+ if (resVal != null ) {
314+ ResourceString resString = new ResourceString (key , resVal );
315+ if (seqNum != null ) {
316+ resString .setSequenceNumber (seqNum .intValue ());
317+ }
318+ resStrings .add (resString );
300319 }
301- resStrings .add (resString );
302320 }
321+ return new Bundle (resStrings , null );
322+ } catch (ServiceException e ) {
323+ throw new MojoFailureException ("Globalization Pipeline service error" , e );
303324 }
304- return new Bundle (resStrings , null );
305325 }
306326}
0 commit comments