BrandingMojo extends AbstractNbmMojo { static String[] getLocale(String name) { String suffix = ""; int dot = name.indexOf( "."); if (dot > -1) { suffix = name.substring( dot ); name = name.substring( 0, dot); } String locale = null; int count = 1; while (count <= 3) { int underscore = name.lastIndexOf( '_'); if (underscore > -1) { String loc1 = name.substring( underscore + 1); if (loc1.length() != 2) { break; } locale = loc1 + (locale == null ? "" : "_" + locale); name = name.substring( 0, underscore); } else { break; } count = count + 1; } return new String[] {name, locale, suffix}; }  void execute();  }
@Test public void testLocale() { assertEquals("en_us", BrandingMojo.getLocale( "aaa_en_us.properties")[1]); assertEquals("en_us_ca", BrandingMojo.getLocale( "aaa_en_us_ca.properties")[1]); assertEquals("en_us_ca", BrandingMojo.getLocale( "aa_en_us_ca.properties")[1]); assertEquals("en_us_ca", BrandingMojo.getLocale( "bb_aa_en_us_ca.properties")[1]); assertEquals("en", BrandingMojo.getLocale( "bb_aaa_en.properties")[1]); assertEquals(null, BrandingMojo.getLocale( "bb_aaa_end.properties")[1]); assertEquals(null, BrandingMojo.getLocale( "bb_aa_end.properties")[1]); assertEquals(null, BrandingMojo.getLocale( "bb.properties")[1]); }