How to find ISD code from ISO 3166 code? - java
I want to show ISO 3166 country code and its ISD code in list
Like:
ind +91
irq +964
ita +39
With the help of java.util.Locale I have got all ISO 3166 country codes but now I want ISD codes of every country.
You can use Google's libphonenumber and use its PhoneNumberUtil.getInstance().getCountryCodeForRegion(). It takes an ISO 3166 code as a String as an argument.
Note that this utility class also has a .getSupportedRegions() method.
I also have same requirement in my application, I couldn't find any api regarding this. So what I did, I create a array in res and put all the ISD codes in it and then use Local for all details. List of code is as follow
<string-array name="countryArray">
<item>AC,247</item>
<item>AD,376</item>
<item>AE,971</item>
<item>AF,93</item>
<item>AG,1</item>
<item>AI,1</item>
<item>AL,355</item>
<item>AM,374</item>
<item>AN,599</item>
<item>AO,244</item>
<item>AQ,672</item>
<item>AR,54</item>
<item>AS,1</item>
<item>AT,43</item>
<item>AU,61</item>
<item>AW,297</item>
<item>AZ,994</item>
<item>BA,387</item>
<item>BB,1</item>
<item>BD,880</item>
<item>BE,32</item>
<item>BF,226</item>
<item>BG,359</item>
<item>BH,973</item>
<item>BI,257</item>
<item>BJ,229</item>
<item>BL,590</item>
<item>BM,1</item>
<item>BN,673</item>
<item>BO,591</item>
<item>BR,55</item>
<item>BS,1</item>
<item>BT,975</item>
<item>BW,267</item>
<item>BY,375</item>
<item>BZ,501</item>
<item>CA,1</item>
<item>CD,243</item>
<item>CF,236</item>
<item>CG,242</item>
<item>CH,41</item>
<item>CI,225</item>
<item>CK,682</item>
<item>CL,56</item>
<item>CM,237</item>
<item>CN,86</item>
<item>CO,57</item>
<item>CR,506</item>
<item>CU,53</item>
<item>CV,238</item>
<item>CY,357</item>
<item>CZ,420</item>
<item>DE,49</item>
<item>DJ,253</item>
<item>DK,45</item>
<item>DM,1</item>
<item>DO,1</item>
<item>DZ,213</item>
<item>EC,593</item>
<item>EE,372</item>
<item>EG,20</item>
<item>ER,291</item>
<item>ES,34</item>
<item>ET,251</item>
<item>FI,358</item>
<item>FJ,679</item>
<item>FK,500</item>
<item>FM,691</item>
<item>FO,298</item>
<item>FR,33</item>
<item>GA,241</item>
<item>GB,44</item>
<item>GD,1</item>
<item>DE,995</item>
<item>GF,594</item>
<item>GH,233</item>
<item>GI,350</item>
<item>GL,299</item>
<item>GM,220</item>
<item>GN,224</item>
<item>GP,590</item>
<item>GQ,240</item>
<item>GR,30</item>
<item>GT,502</item>
<item>GU,1</item>
<item>GW,245</item>
<item>GY,592</item>
<item>HK,852</item>
<item>HN,504</item>
<item>HR,385</item>
<item>HT,509</item>
<item>HU,36</item>
<item>ID,62</item>
<item>IE,353</item>
<item>IL,972</item>
<item>IN,91</item>
<item>IO,246</item>
<item>IQ,964</item>
<item>IR,98</item>
<item>IS,354</item>
<item>IT,39</item>
<item>JA,81</item>
<item>JM,1</item>
<item>JO,962</item>
<item>JP,81</item>
<item>KE,254</item>
<item>KG,996</item>
<item>KH,855</item>
<item>KI,686</item>
<item>KM,269</item>
<item>KN,1</item>
<item>KP,850</item>
<item>KR,82</item>
<item>KW,965</item>
<item>KY,1</item>
<item>KZ,7</item>
<item>LA,856</item>
<item>LB,961</item>
<item>LC,1</item>
<item>LI,423</item>
<item>LK,94</item>
<item>LR,231</item>
<item>LS,266</item>
<item>LT,370</item>
<item>LU,352</item>
<item>LV,371</item>
<item>LY,218</item>
<item>MA,212</item>
<item>MC,377</item>
<item>MD,373</item>
<item>ME,382</item>
<item>MG,261</item>
<item>MH,692</item>
<item>MK,389</item>
<item>ML,223</item>
<item>MM,95</item>
<item>MN,976</item>
<item>MO,853</item>
<item>MP,1</item>
<item>MQ,596</item>
<item>MR,222</item>
<item>MS,1</item>
<item>MT,356</item>
<item>MU,230</item>
<item>MV,960</item>
<item>MW,265</item>
<item>MX,52</item>
<item>MY,60</item>
<item>MZ,258</item>
<item>NA,264</item>
<item>NC,687</item>
<item>NE,227</item>
<item>NG,234</item>
<item>NI,505</item>
<item>NL,31</item>
<item>NO,47</item>
<item>NP,977</item>
<item>NR,674</item>
<item>NU,683</item>
<item>NZ,64</item>
<item>OM,968</item>
<item>PA,507</item>
<item>PE,51</item>
<item>PF,689</item>
<item>PG,675</item>
<item>PH,63</item>
<item>PK,92</item>
<item>PL,48</item>
<item>PM,508</item>
<item>PR,1</item>
<item>PS,970</item>
<item>PT,351</item>
<item>PW,680</item>
<item>PY,595</item>
<item>QA,974</item>
<item>RE,262</item>
<item>RO,40</item>
<item>RS,381</item>
<item>RU,7</item>
<item>RW,250</item>
<item>SA,966</item>
<item>SB,677</item>
<item>SC,248</item>
<item>SD,249</item>
<item>SE,46</item>
<item>SG,65</item>
<item>SH,290</item>
<item>SI,386</item>
<item>SK,421</item>
<item>SL,232</item>
<item>SM,378</item>
<item>SN,221</item>
<item>SO,252</item>
<item>SR,597</item>
<item>ST,239</item>
<item>SV,503</item>
<item>SX,1</item>
<item>SY,963</item>
<item>SZ,268</item>
<item>TC,1</item>
<item>TD,235</item>
<item>TG,228</item>
<item>TH,66</item>
<item>TJ,992</item>
<item>TK,690</item>
<item>TM,993</item>
<item>TN,216</item>
<item>TO,676</item>
<item>TR,90</item>
<item>TT,1</item>
<item>TV,688</item>
<item>TW,886</item>
<item>TZ,255</item>
<item>UA,380</item>
<item>UG,256</item>
<item>UK,44</item>
<item>US,1</item>
<item>UY,598</item>
<item>UZ,998</item>
<item>VA,379</item>
<item>VC,1</item>
<item>VE,58</item>
<item>VG,1</item>
<item>VI,1</item>
<item>VN,84</item>
<item>VU,678</item>
<item>WF,681</item>
<item>WS,685</item>
<item>XT,800</item>
<item>YE,967</item>
<item>ZA,27</item>
<item>ZM,260</item>
<item>ZW,263</item>
</string-array>
Related
How do I set the date to the current day in Korea or anywhere else?
So, I got the time to be in Korean time with this code: formatClock = new SimpleDateFormat("hh:mm:ss a"); formatClock.setTimeZone(TimeZone.getTimeZone("Asia/Seoul")); However, how do I set the date to the current day in Korean? For instance, I want it to output Sunday 7/23/2017.
Old API Use another SimpleDateFormat with the desired format, and use java.util.Locale to explicity uses the English names for days of the week: SimpleDateFormat sdf = new SimpleDateFormat("EEEE M/dd/yyyy", Locale.ENGLISH); sdf.setTimeZone(TimeZone.getTimeZone("Asia/Seoul")); System.out.println(sdf.format(new Date())); The output will be: Sunday 7/23/2017 If you don't specify the locale, it uses the system's default, which is not guaranteed to always be English (and it can also be changed without notice, even at runtime, so it's always better to make it explicit in your code by using a proper Locale, if you always want the days of the week in English - or in any other language). Java new Date/Time API The old classes (Date, Calendar and SimpleDateFormat) have lots of problems and design issues, and they're being replaced by the new APIs. If you're using Java 8, consider using the new java.time API. It's easier, less bugged and less error-prone than the old APIs. If you're using Java <= 7, you can use the ThreeTen Backport, a great backport for Java 8's new date/time classes. And for Android, there's the ThreeTenABP (more on how to use it here). The code below works for both. The only difference is the package names (in Java 8 is java.time and in ThreeTen Backport (or Android's ThreeTenABP) is org.threeten.bp), but the classes and methods names are the same. To get the current date in a timezone, you can use a LocalDate (a date with day/month/year) with a ZoneId (a timezone), and you use a DateTimeFormatter to format it: // Korean timezone ZoneId zone = ZoneId.of("Asia/Seoul"); // current date in Korea timezone LocalDate currentDateInKorea = LocalDate.now(zone); // formatter (use English locale to correctly use English name for day of week) DateTimeFormatter fmt = DateTimeFormatter.ofPattern("EEEE M/dd/yyyy", Locale.ENGLISH); System.out.println(fmt.format(currentDateInKorea)); The output will be: Sunday 7/23/2017 Note: a java.util.Date itself has no format, it just represents the number of milliseconds since epoch (1970-01-01T00:00Z). What we're doing here is just changing the representation of this value in a specific format, for a specific timezone.
suppose you should try like this. This should display 'Sun 7/23/2017': new SimpleDateFormat("EEE dd/MM/yyyy").format(new Date()); This should display 'Sunday 7/23/2017': new SimpleDateFormat("EEEE dd/MM/yyyy").format(new Date());
If you want leading zero in month then use MM else use M. NOTE: View all valid time zones by TimeZone.getAvailableIDs() import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; import java.util.TimeZone; public class Time { /** * #param args */ public static void main(String[] args) throws Exception { // Day month/date/year SimpleDateFormat formatClock = new SimpleDateFormat("EEEE MM/dd/yyyy"); formatClock.setTimeZone(TimeZone.getTimeZone("Asia/Seoul")); System.out.println(formatClock.format(new Date())); System.out.println(); // FYI You can check Available TimeZones as follows System.out.println(Arrays.toString(TimeZone.getAvailableIDs())); } } Sample Run Sunday 07/23/2017 [Etc/GMT+12, Etc/GMT+11, Pacific/Midway, Pacific/Niue, Pacific/Pago_Pago, Pacific/Samoa, US/Samoa, America/Adak, America/Atka, Etc/GMT+10, HST, Pacific/Honolulu, Pacific/Johnston, Pacific/Rarotonga, Pacific/Tahiti, SystemV/HST10, US/Aleutian, US/Hawaii, Pacific/Marquesas, AST, America/Anchorage, America/Juneau, America/Nome, America/Sitka, America/Yakutat, Etc/GMT+9, Pacific/Gambier, SystemV/YST9, SystemV/YST9YDT, US/Alaska, America/Dawson, America/Ensenada, America/Los_Angeles, America/Metlakatla, America/Santa_Isabel, America/Tijuana, America/Vancouver, America/Whitehorse, Canada/Pacific, Canada/Yukon, Etc/GMT+8, Mexico/BajaNorte, PST, PST8PDT, Pacific/Pitcairn, SystemV/PST8, SystemV/PST8PDT, US/Pacific, US/Pacific-New, America/Boise, America/Cambridge_Bay, America/Chihuahua, America/Creston, America/Dawson_Creek, America/Denver, America/Edmonton, America/Hermosillo, America/Inuvik, America/Mazatlan, America/Ojinaga, America/Phoenix, America/Shiprock, America/Yellowknife, Canada/Mountain, Etc/GMT+7, MST, MST7MDT, Mexico/BajaSur, Navajo, PNT, SystemV/MST7, SystemV/MST7MDT, US/Arizona, US/Mountain, America/Bahia_Banderas, America/Belize, America/Cancun, America/Chicago, America/Costa_Rica, America/El_Salvador, America/Guatemala, America/Indiana/Knox, America/Indiana/Tell_City, America/Knox_IN, America/Managua, America/Matamoros, America/Menominee, America/Merida, America/Mexico_City, America/Monterrey, America/North_Dakota/Beulah, America/North_Dakota/Center, America/North_Dakota/New_Salem, America/Rainy_River, America/Rankin_Inlet, America/Regina, America/Resolute, America/Swift_Current, America/Tegucigalpa, America/Winnipeg, CST, CST6CDT, Canada/Central, Canada/East-Saskatchewan, Canada/Saskatchewan, Chile/EasterIsland, Etc/GMT+6, Mexico/General, Pacific/Easter, Pacific/Galapagos, SystemV/CST6, SystemV/CST6CDT, US/Central, US/Indiana-Starke, America/Atikokan, America/Bogota, America/Cayman, America/Coral_Harbour, America/Detroit, America/Fort_Wayne, America/Grand_Turk, America/Guayaquil, America/Havana, America/Indiana/Indianapolis, America/Indiana/Marengo, America/Indiana/Petersburg, America/Indiana/Vevay, America/Indiana/Vincennes, America/Indiana/Winamac, America/Indianapolis, America/Iqaluit, America/Jamaica, America/Kentucky/Louisville, America/Kentucky/Monticello, America/Lima, America/Louisville, America/Montreal, America/Nassau, America/New_York, America/Nipigon, America/Panama, America/Pangnirtung, America/Port-au-Prince, America/Thunder_Bay, America/Toronto, Canada/Eastern, Cuba, EST, EST5EDT, Etc/GMT+5, IET, Jamaica, SystemV/EST5, SystemV/EST5EDT, US/East-Indiana, US/Eastern, US/Michigan, America/Caracas, America/Anguilla, America/Antigua, America/Argentina/San_Luis, America/Aruba, America/Asuncion, America/Barbados, America/Blanc-Sablon, America/Boa_Vista, America/Campo_Grande, America/Cuiaba, America/Curacao, America/Dominica, America/Eirunepe, America/Glace_Bay, America/Goose_Bay, America/Grenada, America/Guadeloupe, America/Guyana, America/Halifax, America/Kralendijk, America/La_Paz, America/Lower_Princes, America/Manaus, America/Marigot, America/Martinique, America/Moncton, America/Montserrat, America/Port_of_Spain, America/Porto_Acre, America/Porto_Velho, America/Puerto_Rico, America/Rio_Branco, America/Santiago, America/Santo_Domingo, America/St_Barthelemy, America/St_Kitts, America/St_Lucia, America/St_Thomas, America/St_Vincent, America/Thule, America/Tortola, America/Virgin, Antarctica/Palmer, Atlantic/Bermuda, Brazil/Acre, Brazil/West, Canada/Atlantic, Chile/Continental, Etc/GMT+4, PRT, SystemV/AST4, SystemV/AST4ADT, America/St_Johns, CNT, Canada/Newfoundland, AGT, America/Araguaina, America/Argentina/Buenos_Aires, America/Argentina/Catamarca, America/Argentina/ComodRivadavia, America/Argentina/Cordoba, America/Argentina/Jujuy, America/Argentina/La_Rioja, America/Argentina/Mendoza, America/Argentina/Rio_Gallegos, America/Argentina/Salta, America/Argentina/San_Juan, America/Argentina/Tucuman, America/Argentina/Ushuaia, America/Bahia, America/Belem, America/Buenos_Aires, America/Catamarca, America/Cayenne, America/Cordoba, America/Fortaleza, America/Godthab, America/Jujuy, America/Maceio, America/Mendoza, America/Miquelon, America/Montevideo, America/Paramaribo, America/Recife, America/Rosario, America/Santarem, America/Sao_Paulo, Antarctica/Rothera, Atlantic/Stanley, BET, Brazil/East, Etc/GMT+3, America/Noronha, Atlantic/South_Georgia, Brazil/DeNoronha, Etc/GMT+2, America/Scoresbysund, Atlantic/Azores, Atlantic/Cape_Verde, Etc/GMT+1, Africa/Abidjan, Africa/Accra, Africa/Bamako, Africa/Banjul, Africa/Bissau, Africa/Casablanca, Africa/Conakry, Africa/Dakar, Africa/El_Aaiun, Africa/Freetown, Africa/Lome, Africa/Monrovia, Africa/Nouakchott, Africa/Ouagadougou, Africa/Sao_Tome, Africa/Timbuktu, America/Danmarkshavn, Atlantic/Canary, Atlantic/Faeroe, Atlantic/Faroe, Atlantic/Madeira, Atlantic/Reykjavik, Atlantic/St_Helena, Eire, Etc/GMT, Etc/GMT+0, Etc/GMT-0, Etc/GMT0, Etc/Greenwich, Etc/UCT, Etc/UTC, Etc/Universal, Etc/Zulu, Europe/Belfast, Europe/Dublin, Europe/Guernsey, Europe/Isle_of_Man, Europe/Jersey, Europe/Lisbon, Europe/London, GB, GB-Eire, GMT, GMT0, Greenwich, Iceland, Portugal, UCT, UTC, Universal, WET, Zulu, Africa/Algiers, Africa/Bangui, Africa/Brazzaville, Africa/Ceuta, Africa/Douala, Africa/Kinshasa, Africa/Lagos, Africa/Libreville, Africa/Luanda, Africa/Malabo, Africa/Ndjamena, Africa/Niamey, Africa/Porto-Novo, Africa/Tripoli, Africa/Tunis, Africa/Windhoek, Arctic/Longyearbyen, Atlantic/Jan_Mayen, CET, ECT, Etc/GMT-1, Europe/Amsterdam, Europe/Andorra, Europe/Belgrade, Europe/Berlin, Europe/Bratislava, Europe/Brussels, Europe/Budapest, Europe/Busingen, Europe/Copenhagen, Europe/Gibraltar, Europe/Ljubljana, Europe/Luxembourg, Europe/Madrid, Europe/Malta, Europe/Monaco, Europe/Oslo, Europe/Paris, Europe/Podgorica, Europe/Prague, Europe/Rome, Europe/San_Marino, Europe/Sarajevo, Europe/Skopje, Europe/Stockholm, Europe/Tirane, Europe/Vaduz, Europe/Vatican, Europe/Vienna, Europe/Warsaw, Europe/Zagreb, Europe/Zurich, Libya, MET, Poland, ART, Africa/Blantyre, Africa/Bujumbura, Africa/Cairo, Africa/Gaborone, Africa/Harare, Africa/Johannesburg, Africa/Kigali, Africa/Lubumbashi, Africa/Lusaka, Africa/Maputo, Africa/Maseru, Africa/Mbabane, Asia/Amman, Asia/Beirut, Asia/Damascus, Asia/Gaza, Asia/Hebron, Asia/Istanbul, Asia/Jerusalem, Asia/Nicosia, Asia/Tel_Aviv, CAT, EET, Egypt, Etc/GMT-2, Europe/Athens, Europe/Bucharest, Europe/Chisinau, Europe/Helsinki, Europe/Istanbul, Europe/Kiev, Europe/Mariehamn, Europe/Nicosia, Europe/Riga, Europe/Simferopol, Europe/Sofia, Europe/Tallinn, Europe/Tiraspol, Europe/Uzhgorod, Europe/Vilnius, Europe/Zaporozhye, Israel, Turkey, Africa/Addis_Ababa, Africa/Asmara, Africa/Asmera, Africa/Dar_es_Salaam, Africa/Djibouti, Africa/Juba, Africa/Kampala, Africa/Khartoum, Africa/Mogadishu, Africa/Nairobi, Antarctica/Syowa, Asia/Aden, Asia/Baghdad, Asia/Bahrain, Asia/Kuwait, Asia/Qatar, Asia/Riyadh, EAT, Etc/GMT-3, Europe/Kaliningrad, Europe/Minsk, Indian/Antananarivo, Indian/Comoro, Indian/Mayotte, Asia/Riyadh87, Asia/Riyadh88, Asia/Riyadh89, Mideast/Riyadh87, Mideast/Riyadh88, Mideast/Riyadh89, Asia/Tehran, Iran, Asia/Baku, Asia/Dubai, Asia/Muscat, Asia/Tbilisi, Asia/Yerevan, Etc/GMT-4, Europe/Moscow, Europe/Samara, Europe/Volgograd, Indian/Mahe, Indian/Mauritius, Indian/Reunion, NET, W-SU, Asia/Kabul, Antarctica/Mawson, Asia/Aqtau, Asia/Aqtobe, Asia/Ashgabat, Asia/Ashkhabad, Asia/Dushanbe, Asia/Karachi, Asia/Oral, Asia/Samarkand, Asia/Tashkent, Etc/GMT-5, Indian/Kerguelen, Indian/Maldives, PLT, Asia/Calcutta, Asia/Colombo, Asia/Kolkata, IST, Asia/Kathmandu, Asia/Katmandu, Antarctica/Vostok, Asia/Almaty, Asia/Bishkek, Asia/Dacca, Asia/Dhaka, Asia/Qyzylorda, Asia/Thimbu, Asia/Thimphu, Asia/Yekaterinburg, BST, Etc/GMT-6, Indian/Chagos, Asia/Rangoon, Indian/Cocos, Antarctica/Davis, Asia/Bangkok, Asia/Ho_Chi_Minh, Asia/Hovd, Asia/Jakarta, Asia/Novokuznetsk, Asia/Novosibirsk, Asia/Omsk, Asia/Phnom_Penh, Asia/Pontianak, Asia/Saigon, Asia/Vientiane, Etc/GMT-7, Indian/Christmas, VST, Antarctica/Casey, Asia/Brunei, Asia/Choibalsan, Asia/Chongqing, Asia/Chungking, Asia/Harbin, Asia/Hong_Kong, Asia/Kashgar, Asia/Krasnoyarsk, Asia/Kuala_Lumpur, Asia/Kuching, Asia/Macao, Asia/Macau, Asia/Makassar, Asia/Manila, Asia/Shanghai, Asia/Singapore, Asia/Taipei, Asia/Ujung_Pandang, Asia/Ulaanbaatar, Asia/Ulan_Bator, Asia/Urumqi, Australia/Perth, Australia/West, CTT, Etc/GMT-8, Hongkong, PRC, Singapore, Australia/Eucla, Asia/Dili, Asia/Irkutsk, Asia/Jayapura, Asia/Pyongyang, Asia/Seoul, Asia/Tokyo, Etc/GMT-9, JST, Japan, Pacific/Palau, ROK, ACT, Australia/Adelaide, Australia/Broken_Hill, Australia/Darwin, Australia/North, Australia/South, Australia/Yancowinna, AET, Antarctica/DumontDUrville, Asia/Khandyga, Asia/Yakutsk, Australia/ACT, Australia/Brisbane, Australia/Canberra, Australia/Currie, Australia/Hobart, Australia/Lindeman, Australia/Melbourne, Australia/NSW, Australia/Queensland, Australia/Sydney, Australia/Tasmania, Australia/Victoria, Etc/GMT-10, Pacific/Chuuk, Pacific/Guam, Pacific/Port_Moresby, Pacific/Saipan, Pacific/Truk, Pacific/Yap, Australia/LHI, Australia/Lord_Howe, Antarctica/Macquarie, Asia/Sakhalin, Asia/Ust-Nera, Asia/Vladivostok, Etc/GMT-11, Pacific/Efate, Pacific/Guadalcanal, Pacific/Kosrae, Pacific/Noumea, Pacific/Pohnpei, Pacific/Ponape, SST, Pacific/Norfolk, Antarctica/McMurdo, Antarctica/South_Pole, Asia/Anadyr, Asia/Kamchatka, Asia/Magadan, Etc/GMT-12, Kwajalein, NST, NZ, Pacific/Auckland, Pacific/Fiji, Pacific/Funafuti, Pacific/Kwajalein, Pacific/Majuro, Pacific/Nauru, Pacific/Tarawa, Pacific/Wake, Pacific/Wallis, NZ-CHAT, Pacific/Chatham, Etc/GMT-13, MIT, Pacific/Apia, Pacific/Enderbury, Pacific/Fakaofo, Pacific/Tongatapu, Etc/GMT-14, Pacific/Kiritimati]
Below is the code to do it import java.text.SimpleDateFormat; import java.util.Date; public class Test { public static void main(String[] args) { // TODO Auto-generated method stub SimpleDateFormat format = new SimpleDateFormat("E, dd/MM/yyyy"); // DateToStr = format.format(new Date()); System.out.println(format.format(new Date())); } } Link for different formats https://examples.javacodegeeks.com/core-java/text/java-simpledateformat-example/
Exception in EDI Stream to Java Object conversion
I am trying to read an EDI Message and converting it to Java object ,but I am ended with below exception . Exception in thread "main" org.milyn.SmooksException: Failed to filter source. at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:97) at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:64) at org.milyn.Smooks._filter(Smooks.java:526) at org.milyn.Smooks.filterSource(Smooks.java:482) at org.milyn.Smooks.filterSource(Smooks.java:456) at org.milyn.edi.unedifact.d97a.D97AInterchangeFactory.fromUNEdifact(D97AInterchangeFactory.java:58) at org.milyn.edi.unedifact.d97a.D97AInterchangeFactory.fromUNEdifact(D97AInterchangeFactory.java:40) at com.ibm.gpohub.edi.common.SmooksSample.main(SmooksSample.java:18) Caused by: org.milyn.edisax.EDIParseException: EDI message processing failed [ORDRSP][D:97A:UN]. Segment [FTX], field 4 (TEXT_LITERAL), component 1 (Free_text_-_-1) expected to contain a value. Currently at segment number 6. at org.milyn.edisax.EDIParser.mapComponent(EDIParser.java:687) at org.milyn.edisax.EDIParser.mapField(EDIParser.java:636) at org.milyn.edisax.EDIParser.mapFields(EDIParser.java:606) at org.milyn.edisax.EDIParser.mapSegment(EDIParser.java:564) at org.milyn.edisax.EDIParser.mapSegments(EDIParser.java:535) at org.milyn.edisax.EDIParser.mapSegments(EDIParser.java:453) at org.milyn.edisax.EDIParser.parse(EDIParser.java:428) at org.milyn.edisax.EDIParser.parse(EDIParser.java:410) at org.milyn.edisax.unedifact.handlers.UNHHandler.process(UNHHandler.java:97) at org.milyn.edisax.unedifact.handlers.UNGHandler.process(UNGHandler.java:58) at org.milyn.edisax.unedifact.handlers.UNBHandler.process(UNBHandler.java:75) at org.milyn.edisax.unedifact.UNEdifactInterchangeParser.parse(UNEdifactInterchangeParser.java:113) at org.milyn.smooks.edi.unedifact.UNEdifactReader.parse(UNEdifactReader.java:75) at org.milyn.delivery.sax.SAXParser.parse(SAXParser.java:76) at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:86) ... 7 more Here is the code snippet: D97AInterchangeFactory d97InterChangeFactory = (D97AInterchangeFactory)SmooksFactoryImpl.D97A_FACTORY.getInstance(); InputStream ediSource = new FileInputStream("C:\\EDIFACT_MSG.txt"); UNEdifactInterchange interchange = d97InterChangeFactory.fromUNEdifact(ediSource); if(interchange instanceof UNEdifactInterchange41){ List<UNEdifactMessage41> messages = ((UNEdifactInterchange41) interchange).getMessages(); for(UNEdifactMessage41 msg:messages){ System.out.println(msg.toString()); } } EDIMessage : UNA:+.? UNB+UNOC:3+662424795TEST:16+IBMEDIID:ZZ+160330:1416+IG-62779496 UNG+ORDRSP+662424795TEST:16+IBMEDIID:ZZ+160330:1420+FG-34160863+UN+D:97A UNH+80534414+ORDRSP:D:97A:UN BGM+231+20160330+4 DTM+69:20150501150000UTC?+12:304 FTX+SSR+++:Blank FTX+AAR++ST FTX+COI+++CLW FTX+PRI++8 FTX+DEL++06 FTX+CUR+++Pack all item into one box FTX+DIN+++make a call to customer before delivery FTX+PRD+++1:1:PC01 FTX+AAP+++900:accept RFF+PC:20AMS67000 RFF+SE:PC01K33E RFF+SZ:ND RFF+ABO:Y RFF+CO:IBM1234501 DTM+4:20150501010101UTC?+12:304 RFF+ACW:CASE_12345 RFF+ADG:Y RFF+ACH:Y RFF+ZOD:order_desk01 RFF+ZSD:IBM RFF+ZPD:30006672 RFF+ZCS:Blank RFF+ZZZ NAD+SE+30001234++IBM NAD+BY+US00000001++Coca Cola:CA+9/F:841 WEBSTER ST:stress 3:Blank+SAN FRANCISCO++94117+US CTA+PD+:Jordan Surzyn COM+Minako#DHL.com:EM COM+6508624654:TE NAD+OY+US00000001++IBM Field Service:CA+9/F:900 WEBSTER ST:stress 3:Blank+SAN FRANCISCO++94117+US CTA+CR+:Will Smith COM+Will#ibm.com:EM COM+6508624654:TE LIN+10 PIA+5+04X6076 IMD+F++:::KEYBOARD NetVista Keyboard (USB) QTY+21:1:EA DTM+69:20160610120000UTC?+12:304 FTX+OSI+++INW FTX+LIN+++ZSP1 FTX+AAP+++900:Accept FTX+ZCT+++STO from DC to FSL RFF+ZSB:01 RFF+ZRO:Y RFF+ZOR:KEYBOARD in good condition RFF+ZST:SOFT UNS+S UNT+50+80534414 UNE+1+FG-34160863 UNZ+1+IG-62779496 Can anyone guide me , where I am doing wrong ? thanks in advance.
It was because of the improper EDIFACT message format. It is resolved after I got the proper EDIFACT message, as shown below. Hope any one faced similar issue may help this . --thanks UNA:+.? ' UNB+UNOC:3+IBM:ZZZ+662424795TEST:16+160330:1416+00000016086706++++1' UNG+ORDRSP+IBM:ZZZ+662424795TEST:16+160330:1420+00000000160867+UN+D:97A' UNH+1+ORDRSP:D:97A:UN' BGM+231+20160330+4' DTM+69:20160501150000UTC?+12:304' FTX+AAR++ER' FTX+SSR+++N:AM' FTX+COI+++CLW' FTX+PRI++8' FTX+DEL++04' FTX+CUR+++Pack all item into one box' FTX+DIN+++make a call to customer before delivery' FTX+PRD+++IBMDECK001::PC01' FTX+AAP+++900:accept' RFF+PC:20AMS67000' RFF+SE:PC01K33E' RFF+SZ:ND' RFF+ABO:N' RFF+CO:IBM1234501' RFF+ACW:IBMCASE12301' DTM+4:20150501000000UTC?+12:304' NAD+SE+30006672++3100001' NAD+BY+US00000001++CA:NEC Personal Computers, Ltd.+9/F:841 WEBSTER ST:stress 3+SAN FRANCISCO++941171717+US' CTA+PD+:Jordan Surzyn' COM+Minako#DHL.com:EM' COM+6508624654:TE' NAD+OY+US00000001++CA:NEC Personal Computers, Ltd.+9/F:841 WEBSTER ST:stress 3+SAN FRANCISCO++941171717+US' CTA+CR+:Jordan Surzyn' COM+Minako#DHL.com:EM' COM+6508624654:TE' LIN+20+++1:10' PIA+5+04X6076' IMD+F++:::KEYBOARD NetVista Keyboard (USB)' QTY+21:1:EA' DTM+69:20160610120000UTC?+12:304' FTX+LIN+++ZSP1' FTX+AAP+++900:Accpet' FTX+OSI+++INW' FTX+BSC+++KEYBOARD in good condition' RFF+SE:Y' NAD+OY+01+SOFT' UNS+S' UNT+41+1' UNE+1+00000000160867' UNZ+1+00000016086706'
Regex to extract a specific string
1X79 "The X-Files" (1.01) 9/10/93 1/17/94* 11/ 6/94* 1X01 "Deep Throat" (1.02) 9/17/93 12/24/93 6/24/94 1X02 "Squeeze" (1.03) 9/24/93 12/ 3/93 6/10/94 11/ 4/95* 1X03 "Conduit" (1.04) 10/ 1/93 12/14/93* 5/27/94 1X04 "Jersey Devil" (1.05) 10/ 8/93 12/31/93 7/22/94 1X05 "Shadows" (1.06) 10/22/93 3/ 4/94 5/26/95 1X06 "Ghost in the Machine" (1.07) 10/29/93 1/14/94 1X07 "Ice" (1.08) 11/ 5/93 1/17/94* 8/12/94 3/ 3/95 1X08 "Space" (1.09) 11/12/93 1/28/94 8/22/94* 1X09 "Fallen Angel" (1.10) 11/19/93 3/29/94* 11/13/94* 1X10 "Eve" (1.11) 12/10/93 3/11/94 8/26/94 1X11 "Fire" (1.12) 12/17/93 3/25/94 11/20/94* 1X12 "Beyond the Sea" (1.13) 1/ 7/94 4/ 8/94 12/22/95? 1X13 "GenderBender" (1.14) 1/21/94 5/20/94 7/21/95 1X14 "Lazarus" (1.15) 2/ 4/94 6/ 3/94 9/ 2/94 1X15 "Young at Heart" (1.16) 2/11/94 6/17/94 8/19/94 1X16 "E.B.E." (1.17) 2/18/94 7/ 8/94 11/27/94* 1X17 "Miracle Man" (1.18) 3/18/94 7/ 1/94 1X18 "Shapes" (1.19) 4/ 1/94 10/28/94 8/ 4/95 1X19 "Darkness Falls" (1.20) 4/15/94 8/ 5/94 12/ 2/94 1X20 "Tooms" (1.21) 4/22/94 7/15/94 11/ 4/95* 1X21 "Born Again" (1.22) 4/29/94 8/22/94* 1X22 "Roland" (1.23) 5/ 6/94 7/29/94 1X23 "The Erlenmeyer Flask" (1.24) 5/13/94 9/ 9/94 9/ 1/95 given this list I need to extract: the name (in quotes) the season (in parentheses) the the first year mentioned. ex) for "The X-Files" I would need to extract '93' I've come up with: "(.*?)"+([\D]+)(.{4}) Which get the first two items needed but I cant figure out how to grab the year
Consider the following: "([^"]+)"\s*\(([^\)]+)\)\s*\d+\/\s*\d+\/(\d+) https://regex101.com/r/jU6kI0/1 Name is group(1), season is group(2), year is group(3)
displaytag customise pagination
I'm trying to style the <displaytag> to obtain something that look great. The official demo look like : http://demo.displaytag.org/displaytag-examples-1.2/example-paging.jsp But I obtain only this : How can I change the rendering of the pagination part of the displaytag so that page numbers are in <li> elements ? Thanks in advance
To customise the pagination, I had to add a displayTag.properties file with the following properties : paging.banner.no_items_found=<span class="pagebanner">No {0} found.</span> paging.banner.one_item_found=<span class="pagebanner">One {0} found.</span> paging.banner.all_items_found=<span class="pagebanner">{0} {1} found, displaying all {2}.</span> paging.banner.some_items_found=<span class="pagebanner">{0} {1} found, displaying {2} to {3}.</span> paging.banner.full=<div class="pagination"><ul><li class="prev disabled"><img src="static/images/first.png" alt="first" /></li><li class="prev disabled"><img src="static/images/previous.png" alt="previous" /></li>{0}<li><img src="static/images/next.png" alt="next" /></li><li class="next"><img src="static/images/last.png" alt="last" /></li></ul></div> paging.banner.first=<div class="pagination"><ul><li class="prev"><img src="static/images/first.png" alt="first" /></li><li class="prev"><img src="static/images/previous.png" alt="previous" /></li>{0}<li><img src="static/images/next.png" alt="next" /></li><li class="next"><img src="static/images/last.png" alt="last" /></li></ul></div> paging.banner.last=<div class="pagination"><ul><li class="prev"><img src="static/images/first.png" alt="first" /></li><li class="prev"><img src="static/images/previous.png" alt="previous" /></li>{0}<li class="next disabled"><img src="static/images/next.png" alt="next" /></li><li class="next disabled"><img src="static/images/last.png" alt="last" /></li></ul></div> paging.banner.onepage=<div class="pagination"><ul>{0}</ul></div> paging.banner.page.selected=<li><strong>{0}</strong></li> paging.banner.page.link=<li>{0}</li> paging.banner.page.separator=
In displayTag.properties: paging.banner.placement=top paging.banner.onepage= paging.banner.first=<span class="pagination pagination-right"><ul>{0}<li>...{6}</li></ul></span> paging.banner.full=<span class="pagination pagination-right"><ul><li>1\u00aa</li>{0}<li>...{6}</li></ul></span> paging.banner.last=<span class="pagination pagination-right"><ul><li>1\u00aa</li>{0}</ul></span> paging.banner.page.link=<li>{0}</li> paging.banner.page.selected=<li class="disabled"><span>{0}</span></li> paging.banner.page.separator= Another format More information on http://www.displaytag.org/1.2/configuration.html
non standard locale with java.util.Calendar
We have a customer in Sweden, using the software in English. So we set the Locale(en, SV). We did hope the Calendar class would adhere to the country settings, but it uses the language and with this locale it assumes US settings. So I am now searching for a way to let the calendar get to know the new firstDayOfWeek and minimumDayinFirstWeek settings preferred by a standard way other than setting it manually and thus hardcoded. For clarification: The 29. August 2010 is in Sweden in CW 34 (also in Germany and Great Britain) but in the US it is reported as CW 36. The different results from the fact that the 01.01.2010 is a Friday and the 29.08.2010 a Sunday. I cannot change the language setting itself to Swedish and use the English fallback since we do not support Swedish as language, but Sun/Oracle/.. does, so the Swing UI would have a mixture of Swedish and English texts, which not acceptable. And just adding a properties file named "sun.util.resources.CalendarData_en_SV.properties" does not work out: it does not get read! Manually as a ResourceBundle that's possible. Somehow LocaleData.getCalendarData(Locale) does its own magic in reading the resourcfiles which i cannot find out since the source of it is not available. The method is called here: java.util.Calendar.setWeekCountData(Locale). I also found the java.util.spi package but it does not provide access to the firstDayOfWeek and minimumDaysInFirstWeek settings. Perhaps I can try to intercept the calls to the resourcebundles and use the default fallback to English and only let the calls to CalendarData proceed!? But that sounds hacky. package de.drews.i18n; import java.util.Calendar; import java.util.Locale; import java.util.ResourceBundle; public class Test { /** * #param args */ public static void main(String[] args) { // en_GB = 34 // en_US = 36 // sv_SV = 34 // en_SV = 36 --> wrong printTest("en", "GB", 34); printTest("en", "US", 36); printTest("sv", "SV", 34); printTest("en", "SV", 34); } private static void printTest(String language, String country, int expected) { Locale locale = new Locale(language, country); Calendar cal = Calendar.getInstance(locale); cal.set(Calendar.YEAR, 2010); cal.set(Calendar.MONTH, Calendar.AUGUST); cal.set(Calendar.DATE, 29); int actual = cal.get(Calendar.WEEK_OF_YEAR); System.out.println(actual + "\t" + expected + "\t" + ((actual == expected) ? "Yeah!" : "-") + "\t" + language + "\t" + country); } }
How about using getInstance(TimeZone zone, Locale aLocale) providing a timezone to select calendar behaviour and locale to define language?
One ugly workaround that I can offer is to reflectively obtain the cachedLocaleData static field of the Calendar class, and put there the following: key = new Locale(..); // your english-swedish locale value = new int[] {firstDayOfWeek, minimalDaysInFirstWeek}; This can be done at init-time and will work for the entire application