diff --git a/build.gradle.kts b/build.gradle.kts index ba3a6e58..6c79fa51 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -67,7 +67,6 @@ val kotestVersion = "5.9.1" val retrofit2Vertion = "2.11.0" val junitVersion = "5.11.1" val mockkVersion = "1.13.12" -val ibmMqVersion = "9.4.0.0" val jGraphTVersion = "1.5.2" val zoweKotlinSdkVersion = "0.5.0" val javaKeytarVersion = "1.0.0" @@ -128,7 +127,6 @@ dependencies { implementation("org.jgrapht:jgrapht-core:$jGraphTVersion") implementation("com.starxg:java-keytar:$javaKeytarVersion") implementation("org.zowe.sdk:zowe-kotlin-sdk:$zoweKotlinSdkVersion") - implementation("com.ibm.mq:com.ibm.mq.allclient:$ibmMqVersion") implementation("org.junit.jupiter:junit-jupiter-params:$junitVersion") testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion") testImplementation("io.mockk:mockk:$mockkVersion") diff --git a/src/main/kotlin/org/zowe/explorer/utils/ccsidUtils.kt b/src/main/kotlin/org/zowe/explorer/utils/ccsidUtils.kt new file mode 100644 index 00000000..5f39b52e --- /dev/null +++ b/src/main/kotlin/org/zowe/explorer/utils/ccsidUtils.kt @@ -0,0 +1,570 @@ +/* + * Copyright (c) 2024 IBA Group. + * + * This program and the accompanying materials are made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBA Group + * Zowe Community + */ + +package org.zowe.explorer.utils + +/** Matching file tag with CCSID value */ +private val fileTagToCcsidMap = mapOf( + "IBM-037" to 37, + "IBM-273" to 273, + "IBM-274" to 274, + "IBM-275" to 275, + "IBM-277" to 277, + "IBM-278" to 278, + "IBM-280" to 280, + "IBM-281" to 281, + "IBM-282" to 282, + "IBM-284" to 284, + "IBM-285" to 285, + "IBM-290" to 290, + "IBM-297" to 297, + "IBM-300" to 300, + "IBM-301" to 301, + "IBM-420" to 420, + "IBM-424" to 424, + "IBM-425" to 425, + "IBM-437" to 437, + "IBM-500" to 500, + "IBM-808" to 808, + "ISO8859-7" to 813, + "ISO8859-1" to 819, + "IBM-833" to 833, + "IBM-834" to 834, + "IBM-835" to 835, + "IBM-836" to 836, + "IBM-837" to 837, + "IBM-838" to 838, + "IBM-848" to 848, + "IBM-850" to 850, + "IBM-852" to 852, + "IBM-855" to 855, + "IBM-856" to 856, + "IBM-858" to 858, + "IBM-859" to 859, + "IBM-861" to 861, + "IBM-862" to 862, + "IBM-864" to 864, + "IBM-866" to 866, + "IBM-867" to 867, + "IBM-869" to 869, + "IBM-870" to 870, + "IBM-871" to 871, + "IBM-872" to 872, + "TIS-620" to 874, + "IBM-875" to 875, + "IBM-880" to 880, + "IBM-901" to 901, + "IBM-902" to 902, + "IBM-904" to 904, + "ISO8859-2" to 912, + "ISO8859-4" to 914, + "ISO8859-5" to 915, + "ISO8859-8" to 916, + "ISO8859-9" to 920, + "ISO8859-13" to 921, + "IBM-922" to 922, + "ISO8859-15" to 923, + "IBM-924" to 924, + "IBM-927" to 927, + "IBM-928" to 928, + "IBM-930" to 930, + "IBM-EUCJC" to 932, + "IBM-933" to 933, + "IBM-935" to 935, + "IBM-936" to 936, + "IBM-937" to 937, + "IBM-938" to 938, + "IBM-939" to 939, + "IBM-942" to 942, + "IBM-943" to 943, + "IBM-946" to 946, + "IBM-947" to 947, + "IBM-948" to 948, + "IBM-949" to 949, + "BIG5" to 950, + "IBM-951" to 951, + "IBM-956" to 956, + "IBM-957" to 957, + "IBM-958" to 958, + "IBM-959" to 959, + "IBM-EUCTW" to 964, + "IBM-EUCKR" to 970, + "IBM-1025" to 1025, + "IBM-1026" to 1026, + "IBM-1027" to 1027, + "IBM-1046" to 1046, + "IBM-1047" to 1047, + "IBM-1088" to 1088, + "ISO8859-6" to 1089, + "IBM-1112" to 1112, + "IBM-1115" to 1115, + "IBM-1122" to 1122, + "IBM-1123" to 1123, + "IBM-1124" to 1124, + "IBM-1125" to 1125, + "IBM-1126" to 1126, + "IBM-1140" to 1140, + "IBM-1141" to 1141, + "IBM-1142" to 1142, + "IBM-1143" to 1143, + "IBM-1144" to 1144, + "IBM-1145" to 1145, + "IBM-1146" to 1146, + "IBM-1147" to 1147, + "IBM-1148" to 1148, + "IBM-1149" to 1149, + "IBM-1153" to 1153, + "IBM-1154" to 1154, + "IBM-1155" to 1155, + "IBM-1156" to 1156, + "IBM-1157" to 1157, + "IBM-1158" to 1158, + "IBM-1159" to 1159, + "IBM-1160" to 1160, + "IBM-1161" to 1161, + "IBM-1165" to 1165, + "UTF-8" to 1208, + "IBM-1250" to 1250, + "IBM-1251" to 1251, + "IBM-1252" to 1252, + "IBM-1253" to 1253, + "IBM-1254" to 1254, + "IBM-1255" to 1255, + "IBM-1256" to 1256, + "IBM-1362" to 1362, + "IBM-1363" to 1363, + "IBM-1364" to 1364, + "IBM-1370" to 1370, + "IBM-1371" to 1371, + "IBM-1380" to 1380, + "IBM-1381" to 1381, + "IBM-EUCCN" to 1383, + "IBM-1386" to 1386, + "IBM-1388" to 1388, + "IBM-1390" to 1390, + "IBM-1399" to 1399, + "IBM-4396" to 4396, + "IBM-4909" to 4909, + "IBM-4930" to 4930, + "IBM-4933" to 4933, + "IBM-4946" to 4946, + "IBM-4971" to 4971, + "IBM-5026" to 5026, + "IBM-5031" to 5031, + "IBM-5035" to 5035, + "ISO-2022-JP" to 5052, + "IBM-5053" to 5053, + "IBM-5054" to 5054, + "IBM-5055" to 5055, + "IBM-5123" to 5123, + "IBM-5346" to 5346, + "IBM-5347" to 5347, + "IBM-5348" to 5348, + "IBM-5349" to 5349, + "IBM-5350" to 5350, + "IBM-5351" to 5351, + "IBM-5352" to 5352, + "IBM-5488" to 5488, + "IBM-8482" to 8482, + "IBM-9027" to 9027, + "IBM-9044" to 9044, + "IBM-9061" to 9061, + "IBM-9238" to 9238, + "IBM-12712" to 12712, + "IBM-13121" to 13121, + "IBM-13124" to 13124, + "UCS-2" to 13488, + "IBM-16684" to 16684, + "IBM-16804" to 16804, + "IBM-17248" to 17248, + "IBM-28709" to 28709, + "EUCJP" to 33722, + "IBM-53668" to 53668, + "IBM-54191" to 54191, + "IBM-62383" to 62383 +) + +/** Matching CCSID value with code page */ +private val ccsidToCodepageMap = mapOf( + 0 to "UTF-8", + 37 to "IBM037", + 273 to "IBM273", + 277 to "IBM277", + 278 to "IBM278", + 280 to "IBM280", + 284 to "IBM284", + 285 to "IBM285", + 290 to "IBM290", + 297 to "IBM297", + 300 to "x-IBM300", + 367 to "US-ASCII", + 420 to "IBM420", + 424 to "IBM424", + 437 to "IBM437", + 500 to "IBM500", + 737 to "x-IBM737", + 775 to "IBM775", + 806 to "x-ISCII91", + 813 to "ISO-8859-7", + 819 to "ISO-8859-1", + 833 to "x-IBM833", + 834 to "x-IBM834", + 838 to "IBM-Thai", + 850 to "IBM850", + 852 to "IBM852", + 855 to "IBM855", + 856 to "x-IBM856", + 857 to "IBM857", + 858 to "IBM00858", + 860 to "IBM860", + 861 to "IBM861", + 862 to "IBM862", + 863 to "IBM863", + 864 to "IBM864", + 865 to "IBM865", + 866 to "IBM866", + 868 to "IBM868", + 869 to "IBM869", + 870 to "IBM870", + 871 to "IBM871", + 874 to "x-IBM874", + 875 to "x-IBM875", + 878 to "KOI8-R", + 912 to "ISO-8859-2", + 913 to "ISO-8859-3", + 915 to "ISO-8859-5", + 916 to "ISO-8859-8", + 918 to "IBM918", + 920 to "ISO-8859-9", + 921 to "x-IBM921", + 922 to "x-IBM922", + 923 to "ISO-8859-15", + 930 to "x-IBM930", + 932 to "x-IBM942C", + 933 to "x-IBM933", + 935 to "x-IBM935", + 936 to "GBK", + 937 to "x-IBM937", + 939 to "x-IBM939", + 942 to "x-IBM942", + 943 to "x-IBM943C", + 948 to "x-IBM948", + 949 to "x-IBM949", + 950 to "x-IBM950", + 954 to "x-IBM33722", + 964 to "x-IBM964", + 970 to "x-IBM970", + 1006 to "x-IBM1006", + 1025 to "x-IBM1025", + 1026 to "IBM1026", + 1046 to "x-IBM1046", + 1047 to "IBM1047", + 1051 to "hp-roman8", + 1089 to "ISO-8859-6", + 1097 to "x-IBM1097", + 1098 to "x-IBM1098", + 1112 to "x-IBM1112", + 1122 to "x-IBM1122", + 1123 to "x-IBM1123", + 1124 to "x-IBM1124", + 1129 to "x-IBM1129", + 1140 to "IBM01140", + 1141 to "IBM01141", + 1142 to "IBM01142", + 1143 to "IBM01143", + 1144 to "IBM01144", + 1145 to "IBM01145", + 1146 to "IBM01146", + 1147 to "IBM01147", + 1148 to "IBM01148", + 1149 to "IBM01149", + 1166 to "x-IBM1166", + 1200 to "UTF-16", + 1201 to "UTF-16BE", + 1202 to "UTF-16LE", + 1208 to "UTF-8", + 1250 to "windows-1250", + 1251 to "windows-1251", + 1252 to "windows-1252", + 1253 to "windows-1253", + 1254 to "windows-1254", + 1255 to "windows-1255", + 1256 to "windows-1256", + 1257 to "windows-1257", + 1258 to "windows-1258", + 1275 to "x-MacRoman", + 1280 to "x-MacGreek", + 1281 to "x-MacTurkish", + 1282 to "x-MacCentralEurope", + 1283 to "x-MacCyrillic", + 1284 to "x-MacCroatian", + 1285 to "x-MacRomania", + 1364 to "x-IBM1364", + 1381 to "x-IBM1381", + 1383 to "x-IBM1383", + 1392 to "GB18030", + 2022 to "ISO-2022-JP", + 4133 to "IBM037", + 4369 to "IBM273", + 4373 to "IBM277", + 4374 to "IBM278", + 4376 to "IBM280", + 4380 to "IBM284", + 4381 to "IBM285", + 4386 to "IBM290", + 4393 to "IBM297", + 4396 to "x-IBM300", + 4516 to "IBM420", + 4520 to "IBM424", + 4533 to "IBM437", + 4596 to "IBM500", + 4929 to "x-IBM833", + 4934 to "IBM-Thai", + 4946 to "IBM850", + 4948 to "IBM852", + 4951 to "IBM855", + 4952 to "x-IBM856", + 4953 to "IBM857", + 4960 to "IBM864", + 4964 to "IBM868", + 4965 to "IBM869", + 4966 to "IBM870", + 4967 to "IBM871", + 4970 to "x-IBM874", + 5014 to "IBM918", + 5026 to "x-IBM930", + 5028 to "x-IBM942C", + 5029 to "x-IBM933", + 5031 to "x-IBM935", + 5033 to "x-IBM937", + 5035 to "x-IBM939", + 5045 to "x-IBM949", + 5046 to "x-IBM950", + 5050 to "x-IBM33722", + 5060 to "x-IBM964", + 5066 to "x-IBM970", + 5142 to "x-IBM1046", + 5143 to "IBM1047", + 5346 to "windows-1250", + 5347 to "windows-1251", + 5348 to "windows-1252", + 5349 to "windows-1253", + 5350 to "windows-1254", + 5353 to "windows-1257", + 5477 to "x-IBM1381", + 5479 to "x-IBM1383", + 5488 to "GB18030", + 5601 to "x-IBM970", + 8229 to "IBM037", + 8478 to "IBM284", + 8489 to "IBM297", + 8492 to "x-IBM300", + 8629 to "IBM437", + 8692 to "IBM500", + 9025 to "x-IBM833", + 9026 to "x-IBM834", + 9030 to "IBM-Thai", + 9047 to "IBM855", + 9056 to "IBM864", + 9060 to "IBM868", + 9066 to "x-IBM874", + 9122 to "x-IBM930", + 9124 to "x-IBM942C", + 9125 to "x-IBM933", + 9127 to "x-IBM935", + 9131 to "x-IBM939", + 9142 to "x-IBM950", + 9146 to "x-IBM33722", + 12325 to "IBM037", + 12588 to "x-IBM300", + 12725 to "IBM437", + 12788 to "IBM500", + 13152 to "IBM864", + 13218 to "x-IBM930", + 13221 to "x-IBM933", + 13223 to "x-IBM935", + 13238 to "x-IBM950", + 13242 to "x-IBM33722", + 13488 to "UTF-16", + 16421 to "IBM037", + 16821 to "IBM437", + 16884 to "IBM500", + 17314 to "x-IBM930", + 17584 to "UTF-16", + 20517 to "IBM037", + 20917 to "IBM437", + 20980 to "IBM500", + 24613 to "IBM037", + 25076 to "IBM500", + 29172 to "IBM500", + 32805 to "IBM037", + 33058 to "IBM290", + 33268 to "IBM500", + 33618 to "IBM850", + 33698 to "x-IBM930", + 33722 to "x-IBM33722", + 37364 to "IBM500", + 41460 to "IBM500", + 45556 to "IBM500", + 49652 to "IBM500", + 53748 to "IBM500", + 61696 to "IBM500", + 61697 to "IBM850", + 61698 to "IBM850", + 61699 to "ISO-8859-1", + 61710 to "ISO-8859-1", + 61711 to "IBM500", + 61712 to "IBM500" +) + +/** Matching code page with CCSID value */ +private val codepageToCcsidMap = mapOf( + "UTF-8" to 1208, + "IBM037" to 37, + "IBM273" to 273, + "IBM277" to 277, + "IBM278" to 278, + "IBM280" to 280, + "IBM284" to 284, + "IBM285" to 285, + "IBM290" to 290, + "IBM297" to 297, + "x-IBM300" to 300, + "US-ASCII" to 367, + "IBM420" to 420, + "IBM424" to 424, + "IBM437" to 437, + "IBM500" to 500, + "x-IBM737" to 737, + "IBM775" to 775, + "x-ISCII91" to 806, + "ISO-8859-7" to 813, + "ISO-8859-1" to 819, + "x-IBM833" to 833, + "x-IBM834" to 834, + "IBM-Thai" to 838, + "IBM850" to 850, + "IBM852" to 852, + "IBM855" to 855, + "x-IBM856" to 856, + "IBM857" to 857, + "IBM00858" to 858, + "IBM860" to 860, + "IBM861" to 861, + "IBM862" to 862, + "IBM863" to 863, + "IBM864" to 864, + "IBM865" to 865, + "IBM866" to 866, + "IBM868" to 868, + "IBM869" to 869, + "IBM870" to 870, + "IBM871" to 871, + "x-IBM874" to 874, + "x-IBM875" to 875, + "KOI8-R" to 878, + "ISO-8859-2" to 912, + "ISO-8859-3" to 913, + "ISO-8859-5" to 915, + "ISO-8859-8" to 916, + "IBM918" to 918, + "ISO-8859-9" to 920, + "x-IBM921" to 921, + "x-IBM922" to 922, + "ISO-8859-15" to 923, + "x-IBM930" to 930, + "x-IBM942C" to 932, + "x-IBM933" to 933, + "x-IBM935" to 935, + "GBK" to 936, + "x-IBM937" to 937, + "x-IBM939" to 939, + "x-IBM942" to 942, + "x-IBM943C" to 943, + "x-IBM948" to 948, + "x-IBM949" to 949, + "x-IBM950" to 950, + "x-IBM33722" to 954, + "x-IBM964" to 964, + "x-IBM970" to 970, + "x-IBM1006" to 1006, + "x-IBM1025" to 1025, + "IBM1026" to 1026, + "x-IBM1046" to 1046, + "IBM1047" to 1047, + "hp-roman8" to 1051, + "ISO-8859-6" to 1089, + "x-IBM1097" to 1097, + "x-IBM1098" to 1098, + "x-IBM1112" to 1112, + "x-IBM1122" to 1122, + "x-IBM1123" to 1123, + "x-IBM1124" to 1124, + "x-IBM1129" to 1129, + "IBM01140" to 1140, + "IBM01141" to 1141, + "IBM01142" to 1142, + "IBM01143" to 1143, + "IBM01144" to 1144, + "IBM01145" to 1145, + "IBM01146" to 1146, + "IBM01147" to 1147, + "IBM01148" to 1148, + "IBM01149" to 1149, + "x-IBM1166" to 1166, + "UTF-16" to 1200, + "UTF-16BE" to 1201, + "UTF-16LE" to 1202, + "windows-1250" to 1250, + "windows-1251" to 1251, + "windows-1252" to 1252, + "windows-1253" to 1253, + "windows-1254" to 1254, + "windows-1255" to 1255, + "windows-1256" to 1256, + "windows-1257" to 1257, + "windows-1258" to 1258, + "x-MacRoman" to 1275, + "x-MacGreek" to 1280, + "x-MacTurkish" to 1281, + "x-MacCentralEurope" to 1282, + "x-MacCyrillic" to 1283, + "x-MacCroatian" to 1284, + "x-MacRomania" to 1285, + "x-IBM1364" to 1364, + "x-IBM1381" to 1381, + "x-IBM1383" to 1383, + "GB18030" to 1392, + "ISO-2022-JP" to 2022 +) + +/** Get CCSID value by file tag from the map or try to convert file tag to Int, otherwise return null */ +fun getCcsidByFileTag(fileTag: String): Int? { + return fileTagToCcsidMap[fileTag.uppercase()] ?: fileTag.toIntOrNull() +} + +/** Get code page by CCSID value from the map, otherwise return null */ +fun getCodepage(ccsid: Int): String? { + return ccsidToCodepageMap[ccsid] +} + +/** Get CCSID value by code page from the map, otherwise return null */ +fun getCcsid(codepage: String): Int? { + return codepageToCcsidMap[codepage] +} + +/** Get list of all available code pages */ +fun getCodepages(): List { + return codepageToCcsidMap.keys.toList() +} diff --git a/src/main/kotlin/org/zowe/explorer/utils/ussFileTagUtils.kt b/src/main/kotlin/org/zowe/explorer/utils/ussFileTagUtils.kt index b83fd923..a627db52 100644 --- a/src/main/kotlin/org/zowe/explorer/utils/ussFileTagUtils.kt +++ b/src/main/kotlin/org/zowe/explorer/utils/ussFileTagUtils.kt @@ -14,7 +14,6 @@ package org.zowe.explorer.utils -import com.ibm.mq.headers.CCSID import org.zowe.explorer.common.message import org.zowe.explorer.config.connect.ConnectionConfig import org.zowe.explorer.dataops.DataOpsManager @@ -30,6 +29,7 @@ import org.zowe.kotlinsdk.FileTagList import org.zowe.kotlinsdk.TagAction import org.zowe.kotlinsdk.UssFileDataType import java.nio.charset.Charset +import java.nio.charset.UnsupportedCharsetException /** * Checks if the uss file tag is set. @@ -54,25 +54,6 @@ fun checkUssFileTag(attributes: RemoteUssAttributes) { } } -/** Matching file tag with CCSID value */ -private val fileTagToCcsidMap = mapOf( - "TIS-620" to 874, - "ISO8859-13" to 921, - "IBM-EUCJC" to 932, - "IBM-943" to 943, - "BIG5" to 950, - "IBM-4396" to 4396, - "IBM-4946" to 4946, - "IBM-5031" to 5031, - "IBM-5346" to 5346, - "IBM-5347" to 5347, - "IBM-5348" to 5348, - "IBM-5349" to 5349, - "IBM-5350" to 5350, - "IBM-5488" to 5488, - "EUCJP" to 33722, -) - /** * Get encoding from file tag or return null if it doesn't exist or encoding could not be determined. * @param attributes uss file attributes. @@ -87,19 +68,15 @@ fun getUssFileTagCharset(attributes: RemoteUssAttributes): Charset? { val endPos = stdout.indexOf(' ', startPos) val tagCharset = stdout.substring(startPos, endPos) runCatching { - val ccsid = fileTagToCcsidMap[tagCharset] ?: CCSID.getCCSID(tagCharset) - val codePage = CCSID.getCodepage(ccsid) - return Charset.forName(codePage) + val ccsid = getCcsidByFileTag(tagCharset) + val codePage = ccsid?.let { getCodepage(it) } + return Charset.forName(codePage ?: tagCharset) }.onFailure { - runCatching { - return Charset.forName(tagCharset) - }.onFailure { - NotificationsService.errorNotification( - it, - custTitle = message("filetag.encoding.detection.error.title"), - custDetailsShort = message("filetag.encoding.detection.error.message", DEFAULT_BINARY_CHARSET.name()), - ) - } + NotificationsService.errorNotification( + it, + custTitle = message("filetag.encoding.detection.error.title"), + custDetailsShort = message("filetag.encoding.detection.error.message", DEFAULT_BINARY_CHARSET.name()), + ) } } } @@ -168,14 +145,8 @@ fun setUssFileTag(charset: String, path: String, connectionConfig: ConnectionCon * @param connectionConfig connection config on which the file is located. */ private fun setUssFileTagCommon(charsetName: String, filePath: String, connectionConfig: ConnectionConfig) { - var charset = charsetName - if (charset.contains("x-IBM")) { - charset = charset.substring(2) - } - val ccsid = CCSID.getCCSID(charset) - val codeSet = ccsid.toString() - runCatching { + val codeSet = getCcsid(charsetName)?.toString() ?: throw UnsupportedCharsetException(charsetName) DataOpsManager.getService().performOperation( operation = ChangeFileTagOperation( request = ChangeFileTagOperationParams( @@ -214,18 +185,16 @@ fun removeUssFileTag(attributes: RemoteUssAttributes) { } private val unsupportedEncodings = listOf( - "GBK", "x-IBM300", "UTF-16" + "UTF-16" ) /** * Returns a list of supported encodings to set in a file tag. */ fun getSupportedEncodings(): List { - val ccsids = CCSID.getCCSIDs().toList() - val encodings = ccsids.mapNotNull { + val encodings = getCodepages().mapNotNull { runCatching { - val codepage = CCSID.getCodepage(it as Int) - Charset.forName(codepage) + Charset.forName(it) }.getOrNull() }.distinct().filter { !unsupportedEncodings.contains(it.name())