1 package org.kuali.ole.utility.callnumber;
2
3
4
5
6
7
8
9
10
11 import org.marc4j.marc.DataField;
12 import org.marc4j.marc.Record;
13 import org.marc4j.marc.Subfield;
14 import org.marc4j.marc.VariableField;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 import java.io.*;
19 import java.net.MalformedURLException;
20 import java.net.URL;
21 import java.text.DecimalFormat;
22 import java.text.SimpleDateFormat;
23 import java.util.*;
24 import java.util.regex.Matcher;
25 import java.util.regex.Pattern;
26
27
28
29
30
31
32
33
34 public final class Utils {
35
36 private final static Pattern FOUR_DIGIT_PATTERN_BRACES = Pattern.compile("\\[[12]\\d{3,3}\\]");
37 private final static Pattern FOUR_DIGIT_PATTERN_ONE_BRACE = Pattern.compile("\\[[12]\\d{3,3}");
38 private final static Pattern FOUR_DIGIT_PATTERN_STARTING_WITH_1_2 = Pattern.compile("(20|19|18|17|16|15)[0-9][0-9]");
39 private final static Pattern FOUR_DIGIT_PATTERN_OTHER_1 = Pattern.compile("l\\d{3,3}");
40 private final static Pattern FOUR_DIGIT_PATTERN_OTHER_2 = Pattern.compile("\\[19\\]\\d{2,2}");
41 private final static Pattern FOUR_DIGIT_PATTERN_OTHER_3 = Pattern.compile("(20|19|18|17|16|15)[0-9][-?0-9]");
42 private final static Pattern FOUR_DIGIT_PATTERN_OTHER_4 = Pattern.compile("i.e. (20|19|18|17|16|15)[0-9][0-9]");
43 private final static Pattern BC_DATE_PATTERN = Pattern.compile("[0-9]+ [Bb][.]?[Cc][.]?");
44 private final static Pattern FOUR_DIGIT_PATTERN = Pattern.compile("\\d{4,4}");
45 private static Matcher matcher;
46 private static Matcher matcher_braces;
47 private static Matcher matcher_one_brace;
48 private static Matcher matcher_start_with_1_2;
49 private static Matcher matcher_l_plus_three_digits;
50 private static Matcher matcher_bracket_19_plus_two_digits;
51 private static Matcher matcher_ie_date;
52 private static Matcher matcher_bc_date;
53 private static Matcher matcher_three_digits_plus_unk;
54 private final static DecimalFormat timeFormat = new DecimalFormat("00.00");
55 protected static Logger logger = LoggerFactory.getLogger(Utils.class);
56
57
58
59
60
61 private Utils() {
62 }
63
64
65
66
67
68
69
70
71
72
73 public static String getProperty(Properties props, String propname) {
74 return getProperty(props, propname, null);
75 }
76
77
78
79
80
81
82
83
84
85
86
87 public static String getProperty(Properties props, String propname, String defVal) {
88 String prop;
89 if ((prop = System.getProperty(propname)) != null) {
90 return (prop);
91 }
92 if (props != null && (prop = props.getProperty(propname)) != null) {
93 return (prop);
94 }
95 return defVal;
96 }
97
98
99
100
101
102
103
104
105 public static Properties loadProperties(String propertyPaths[], String propertyFileName) {
106 return (loadProperties(propertyPaths, propertyFileName, false, null));
107 }
108
109
110
111
112
113
114
115
116 public static Properties loadProperties(String propertyPaths[], String propertyFileName, boolean showName) {
117 return (loadProperties(propertyPaths, propertyFileName, showName, null));
118 }
119
120
121
122
123
124
125
126 public static Properties loadProperties(String fullFilenameURLStr) {
127 InputStream in = getPropertyFileInputStream(fullFilenameURLStr);
128 String errmsg = "Fatal error: Unable to find specified properties file: " + fullFilenameURLStr;
129
130
131 Properties props = new Properties();
132 try {
133 if (fullFilenameURLStr.endsWith(".xml") || fullFilenameURLStr.endsWith(".XML")) {
134 props.loadFromXML(in);
135 } else {
136 props.load(in);
137 }
138 in.close();
139 } catch (IOException e) {
140 throw new IllegalArgumentException(errmsg);
141 }
142 return props;
143 }
144
145
146
147
148
149
150
151
152
153 public static Properties loadProperties(String propertyPaths[], String propertyFileName, boolean showName, String filenameProperty) {
154 String inputStreamSource[] = new String[]{null};
155 InputStream in = getPropertyFileInputStream(propertyPaths, propertyFileName, showName, inputStreamSource);
156 String errmsg = "Fatal error: Unable to find specified properties file: " + propertyFileName;
157
158
159 Properties props = new Properties();
160 try {
161 if (propertyFileName.endsWith(".xml") || propertyFileName.endsWith(".XML")) {
162 props.loadFromXML(in);
163 } else {
164 props.load(in);
165 }
166 in.close();
167 if (filenameProperty != null && inputStreamSource[0] != null) {
168 File tmpFile = new File(inputStreamSource[0]);
169
170 props.setProperty(filenameProperty, tmpFile.getParent());
171 }
172 } catch (IOException e) {
173 throw new IllegalArgumentException(errmsg);
174 }
175 return props;
176 }
177
178 public static InputStream getPropertyFileInputStream(String[] propertyPaths, String propertyFileName) {
179 return (getPropertyFileInputStream(propertyPaths, propertyFileName, false));
180 }
181
182 public static InputStream getPropertyFileInputStream(String[] propertyPaths, String propertyFileName, boolean showName) {
183 return (getPropertyFileInputStream(propertyPaths, propertyFileName, false, null));
184 }
185
186 public static InputStream getPropertyFileInputStream(String propertyFileURLStr) {
187 InputStream in = null;
188 String errmsg = "Fatal error: Unable to open specified properties file: " + propertyFileURLStr;
189 try {
190 URL url = new URL(propertyFileURLStr);
191 in = url.openStream();
192 } catch (IOException e) {
193 throw new IllegalArgumentException(errmsg);
194 }
195
196 return (in);
197 }
198
199 public static InputStream getPropertyFileInputStream(String[] propertyPaths, String propertyFileName, boolean showName, String inputSource[]) {
200 InputStream in = null;
201 String fullPropertyFileURLStr = getPropertyFileAbsoluteURL(propertyPaths, propertyFileName, showName, inputSource);
202 return (getPropertyFileInputStream(fullPropertyFileURLStr));
203 }
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283 public static String getPropertyFileAbsoluteURL(String[] propertyPaths, String propertyFileName, boolean showName, String inputSource[]) {
284 InputStream in = null;
285
286 String verboseStr = System.getProperty("marc.test.verbose");
287 boolean verbose = (verboseStr != null && verboseStr.equalsIgnoreCase("true"));
288 String lookedIn = "";
289 String fullPathName = null;
290 if (propertyPaths != null) {
291 File propertyFile = new File(propertyFileName);
292 int pathCnt = 0;
293 do {
294 if (propertyFile.exists() && propertyFile.isFile() && propertyFile.canRead()) {
295 try {
296 fullPathName = propertyFile.toURI().toURL().toExternalForm();
297 if (inputSource != null && inputSource.length >= 1) {
298 inputSource[0] = propertyFile.getAbsolutePath();
299 }
300 } catch (MalformedURLException e) {
301
302 e.printStackTrace();
303 }
304 if (showName)
305 logger.info("Opening file: " + propertyFile.getAbsolutePath());
306 else
307 logger.debug("Opening file: " + propertyFile.getAbsolutePath());
308 break;
309 }
310 if (verbose) lookedIn = lookedIn + propertyFile.getAbsolutePath() + "\n";
311 if (propertyPaths != null && pathCnt < propertyPaths.length) {
312 propertyFile = new File(propertyPaths[pathCnt], propertyFileName);
313 }
314 pathCnt++;
315 } while (propertyPaths != null && pathCnt <= propertyPaths.length);
316 }
317
318 String errmsg = "Fatal error: Unable to find specified properties file: " + propertyFileName;
319 if (verbose) errmsg = errmsg + "\n Looked in: " + lookedIn;
320 if (fullPathName == null) {
321 Utils utilObj = new Utils();
322 URL url = utilObj.getClass().getClassLoader().getResource(propertyFileName);
323 if (url == null)
324 url = utilObj.getClass().getResource("/" + propertyFileName);
325 if (url == null) {
326 logger.error(errmsg);
327 throw new IllegalArgumentException(errmsg);
328 }
329 if (showName)
330 logger.info("Opening resource via URL: " + url.toString());
331 else
332 logger.debug("Opening resource via URL: " + url.toString());
333
334
335
336
337
338
339
340 fullPathName = url.toExternalForm();
341 }
342 return (fullPathName);
343 }
344
345
346
347
348
349
350
351
352 public static String readStreamIntoString(InputStream stream) throws IOException {
353 Reader in = new BufferedReader(new InputStreamReader(stream));
354
355 StringBuilder sb = new StringBuilder();
356 char[] chars = new char[4096];
357 int length;
358
359 while ((length = in.read(chars)) > 0) {
360 sb.append(chars, 0, length);
361 }
362
363 return sb.toString();
364 }
365
366
367
368
369
370
371
372
373 public static String cleanDate(final String date) {
374 matcher_braces = FOUR_DIGIT_PATTERN_BRACES.matcher(date);
375 matcher_one_brace = FOUR_DIGIT_PATTERN_ONE_BRACE.matcher(date);
376 matcher_start_with_1_2 = FOUR_DIGIT_PATTERN_STARTING_WITH_1_2.matcher(date);
377 matcher_l_plus_three_digits = FOUR_DIGIT_PATTERN_OTHER_1.matcher(date);
378 matcher_bracket_19_plus_two_digits = FOUR_DIGIT_PATTERN_OTHER_2.matcher(date);
379 matcher_three_digits_plus_unk = FOUR_DIGIT_PATTERN_OTHER_3.matcher(date);
380 matcher_ie_date = FOUR_DIGIT_PATTERN_OTHER_4.matcher(date);
381 matcher = FOUR_DIGIT_PATTERN.matcher(date);
382 matcher_bc_date = BC_DATE_PATTERN.matcher(date);
383
384 String cleanDate = null;
385
386 if (matcher_braces.find()) {
387 cleanDate = matcher_braces.group();
388 cleanDate = Utils.removeOuterBrackets(cleanDate);
389 if (matcher.find()) {
390 String tmp = matcher.group();
391 if (!tmp.equals(cleanDate)) {
392 tmp = "" + tmp;
393 }
394 }
395 } else if (matcher_ie_date.find()) {
396 cleanDate = matcher_ie_date.group().replaceAll("i.e. ", "");
397 } else if (matcher_one_brace.find()) {
398 cleanDate = matcher_one_brace.group();
399 cleanDate = Utils.removeOuterBrackets(cleanDate);
400 if (matcher.find()) {
401 String tmp = matcher.group();
402 if (!tmp.equals(cleanDate)) {
403 tmp = "" + tmp;
404 }
405 }
406 } else if (matcher_bc_date.find()) {
407 cleanDate = null;
408 } else if (matcher_start_with_1_2.find()) {
409 cleanDate = matcher_start_with_1_2.group();
410 } else if (matcher_l_plus_three_digits.find()) {
411 cleanDate = matcher_l_plus_three_digits.group().replaceAll("l", "1");
412 } else if (matcher_bracket_19_plus_two_digits.find()) {
413 cleanDate = matcher_bracket_19_plus_two_digits.group().replaceAll("\\[", "").replaceAll("\\]", "");
414 } else if (matcher_three_digits_plus_unk.find()) {
415 cleanDate = matcher_three_digits_plus_unk.group().replaceAll("[-?]", "0");
416 }
417 if (cleanDate != null) {
418 Calendar calendar = Calendar.getInstance();
419 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");
420 String thisYear = dateFormat.format(calendar.getTime());
421 try {
422 if (Integer.parseInt(cleanDate) > Integer.parseInt(thisYear) + 1)
423 cleanDate = null;
424 } catch (NumberFormatException nfe) {
425 cleanDate = null;
426 }
427 }
428 if (cleanDate != null) {
429 logger.debug("Date : " + date + " mapped to : " + cleanDate);
430 } else {
431 logger.debug("No Date match: " + date);
432 }
433 return cleanDate;
434 }
435
436
437
438
439
440
441
442
443
444
445 public static String cleanData(String origStr) {
446 String currResult = origStr;
447 String prevResult;
448 do {
449 prevResult = currResult;
450 currResult = currResult.trim();
451
452 currResult = currResult.replaceAll(" *([,/;:])$", "");
453
454
455 if (currResult.endsWith(".")) {
456 if (currResult.matches(".*[JS]r\\.$")) {
457
458 } else if (currResult.matches(".*\\w\\w\\.$")) {
459 currResult = currResult.substring(0, currResult.length() - 1);
460 } else if (currResult.matches(".*\\p{L}\\p{L}\\.$")) {
461 currResult = currResult.substring(0, currResult.length() - 1);
462 } else if (currResult.matches(".*\\w\\p{InCombiningDiacriticalMarks}?\\w\\p{InCombiningDiacriticalMarks}?\\.$")) {
463 currResult = currResult.substring(0, currResult.length() - 1);
464 } else if (currResult.matches(".*\\p{Punct}\\.$")) {
465 currResult = currResult.substring(0, currResult.length() - 1);
466 }
467 }
468
469 currResult = removeOuterBrackets(currResult);
470
471 if (currResult.length() == 0)
472 return currResult;
473
474 } while (!currResult.equals(prevResult));
475
476
477
478
479 return currResult;
480 }
481
482
483
484
485
486
487
488
489 private static Set<String> cleanData(Set<String> values) {
490 Set<String> result = new LinkedHashSet<String>();
491 for (String entry : values) {
492 String cleaned = cleanData(entry);
493 result.add(cleaned);
494 }
495 return (result);
496 }
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518 public static String removeAllTrailingCharAndPeriod(String origStr, String trailingCharsRegEx, String charsB4periodRegEx) {
519 if (origStr == null)
520 return null;
521
522 String currResult = origStr;
523 String prevResult;
524 do {
525 prevResult = currResult;
526 currResult = removeTrailingCharAndPeriod(currResult.trim(), trailingCharsRegEx, charsB4periodRegEx);
527
528 if (currResult.length() == 0)
529 return currResult;
530
531 } while (!currResult.equals(prevResult));
532
533 return currResult;
534 }
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555 public static String removeTrailingCharAndPeriod(String origStr, String trailingCharsRegEx, String charsB4periodRegEx) {
556 if (origStr == null)
557 return null;
558
559 String result = removeTrailingChar(origStr, trailingCharsRegEx);
560
561 result = removeTrailingPeriod(result, charsB4periodRegEx);
562
563 return result;
564 }
565
566
567
568
569
570
571
572
573
574
575
576
577 public static String removeTrailingChar(String origStr, String charsToReplaceRegEx) {
578 if (origStr == null)
579 return origStr;
580
581 return origStr.trim().replaceAll(charsToReplaceRegEx + "$", "");
582 }
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598 public static String removeTrailingPeriod(String origStr, String precedingCharsRegEx) {
599 if (origStr == null)
600 return origStr;
601 String result = origStr.trim();
602 if (result.endsWith(".") && result.matches(".*" + precedingCharsRegEx + "\\.$"))
603 result = result.substring(0, result.length() - 1).trim();
604
605 return result;
606 }
607
608
609
610
611
612
613
614 public static String removeOuterBrackets(String origStr) {
615 if (origStr == null || origStr.length() == 0)
616 return origStr;
617
618 String result = origStr.trim();
619
620 if (result.length() > 0) {
621 boolean openBracketFirst = result.charAt(0) == '[';
622 boolean closeBracketLast = result.endsWith("]");
623 if (openBracketFirst && closeBracketLast &&
624 result.indexOf('[', 1) == -1 &&
625 result.lastIndexOf(']', result.length() - 2) == -1)
626
627 result = result.substring(1, result.length() - 1);
628 else if (openBracketFirst && result.indexOf(']') == -1)
629
630 result = result.substring(1);
631 else if (closeBracketLast && result.indexOf('[') == -1)
632
633 result = result.substring(0, result.length() - 1);
634 }
635
636 return result.trim();
637 }
638
639
640
641
642
643
644
645
646 public static String calcTime(final long totalTime) {
647 return totalTime / 60000 + ":" + timeFormat.format((totalTime % 60000) / 1000);
648 }
649
650
651
652
653
654
655
656 public static boolean isNumber(final String number) {
657 boolean isNumber;
658
659 try {
660 Integer.parseInt(number);
661 isNumber = true;
662 } catch (NumberFormatException nfe) {
663
664 isNumber = false;
665 }
666
667 return isNumber;
668 }
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692 public static String remap(String fieldVal, Map<String, String> map, boolean allowDefault) {
693 String result = null;
694
695 if (map.keySet().contains("pattern_0")) {
696 for (int i = 0; i < map.keySet().size(); i++) {
697 String patternStr = map.get("pattern_" + i);
698 String parts[] = patternStr.split("=>");
699 if (containsMatch(fieldVal, parts[0])) {
700 String newVal = parts[1];
701 if (parts[1].contains("$")) {
702 newVal = fieldVal.replaceAll(parts[0], parts[1]);
703 fieldVal = newVal;
704 }
705 result = newVal;
706 }
707 }
708 }
709 if (map.containsKey(fieldVal)) {
710 result = map.get(fieldVal);
711 } else if (map.containsKey("displayRawIfMissing")) {
712 result = fieldVal;
713 } else if (allowDefault && map.containsKey("__DEFAULT")) {
714 result = map.get("__DEFAULT");
715 } else if (allowDefault && map.containsKey("")) {
716 result = map.get("");
717 }
718 if (result == null || result.length() == 0) return null;
719 return result;
720 }
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745 public static Set<String> remap(Set<String> set, Map<String, String> map, boolean allowDefault) {
746 if (map == null) return (set);
747 Iterator<String> iter = set.iterator();
748 Set<String> result = new LinkedHashSet<String>();
749
750 while (iter.hasNext()) {
751 String val = iter.next();
752 if (map.keySet().contains("pattern_0")) {
753 String tmpResult = null;
754 for (int i = 0; i < map.keySet().size(); i++) {
755 String patternStr = map.get("pattern_" + i);
756 String parts[] = patternStr.split("=>");
757 if (containsMatch(val, parts[0])) {
758 String newVal = parts[1];
759 if (parts[1].contains("$")) {
760 newVal = val.replaceAll(parts[0], parts[1]);
761 val = newVal;
762 } else {
763 result.add(newVal);
764 }
765 tmpResult = newVal;
766 }
767 }
768 if (tmpResult != null) result.add(tmpResult);
769 } else {
770 String mappedVal = remap(val, map, allowDefault);
771 if (mappedVal != null) {
772 if (mappedVal.contains("|")) {
773 String vals[] = mappedVal.split("[|]");
774 for (String oneVal : vals) {
775 result.add(oneVal);
776 }
777 } else
778 result.add(mappedVal);
779 }
780 }
781 }
782 return result;
783 }
784
785 private static boolean containsMatch(String val, String pattern) {
786 String rep = val.replaceFirst(pattern, "###match###");
787
788 if (!rep.equals(val)) {
789 return true;
790 }
791
792 return false;
793 }
794
795
796
797
798
799
800
801
802 public static boolean setItemContains(Set<String> set, String pattern) {
803 if (set.isEmpty()) {
804 return (false);
805 }
806
807 Iterator<String> iter = set.iterator();
808
809 while (iter.hasNext()) {
810 String value = (String) iter.next();
811
812 if (containsMatch(value, pattern)) {
813 return true;
814 }
815
816 }
817 return false;
818 }
819
820
821
822
823
824
825
826
827 public static String join(Set<String> set, String separator) {
828 Iterator<String> iter = set.iterator();
829
830 StringBuffer result = new StringBuffer("");
831
832 while (iter.hasNext()) {
833
834 result.append(iter.next());
835 if (iter.hasNext()) {
836
837 result.append(separator);
838 }
839 }
840
841 return result.toString();
842 }
843
844 public static Set<String> trimNearDuplicates(Set<String> locations) {
845 locations = cleanData(locations);
846 if (locations.size() <= 1) return (locations);
847 Object locArr[] = locations.toArray();
848 int size = locArr.length;
849 for (int i = 0; i < size; i++) {
850 boolean copyStrI = true;
851 for (int j = 0; j < size; j++) {
852 if (i == j) continue;
853 if (locArr[j].toString().contains(locArr[i].toString())) {
854 copyStrI = false;
855 break;
856 }
857 }
858 if (copyStrI == false) locations.remove(locArr[i]);
859 }
860 return locations;
861 }
862
863
864
865
866
867
868
869
870
871 public final static boolean isRightToLeftLanguage(String langcode) {
872 if (
873
874 langcode.equals("ara") || langcode.equals("per") || langcode.equals("urd")
875 ||
876
877 langcode.equals("heb") || langcode.equals("yid") || langcode.equals("lad")
878 || langcode.equals("jpr") || langcode.equals("jrb")
879 )
880 return true;
881 else
882 return false;
883 }
884
885
886
887
888
889
890
891
892
893
894 public final static int getIxUnescapedOpenParen(String str) {
895 if (str.startsWith("("))
896 return 0;
897 Pattern p = Pattern.compile(".*[^\\\\](\\().*");
898 Matcher m = p.matcher(str);
899 if (m.matches())
900 return m.start(1);
901 else
902 return -1;
903 }
904
905
906
907
908
909
910
911
912
913
914 public final static int getIxUnescapedComma(String str) {
915 if (str.startsWith(","))
916 return 0;
917 Pattern p = Pattern.compile(".*[^\\\\](,).*");
918 Matcher m = p.matcher(str);
919 if (m.matches())
920 return m.start(1);
921 else
922 return -1;
923 }
924
925
926
927
928
929
930
931
932
933
934
935 public final static Set<String> getPrefixedVals(Set<String> valueSet, String prefix) {
936 Set<String> resultSet = new LinkedHashSet<String>();
937 if (!valueSet.isEmpty()) {
938 Iterator<String> iter = valueSet.iterator();
939 while (iter.hasNext()) {
940 String s = removePrefix((String) iter.next(), prefix);
941 if (s != null) {
942 String value = s.trim();
943 if (value != null && value.length() != 0)
944 resultSet.add(value);
945 }
946 }
947 }
948 return resultSet;
949 }
950
951
952
953
954 public final static String removePrefix(String value, String prefix) {
955 if (value.startsWith(prefix)) {
956 value = value.substring(prefix.length());
957 if (value != null && value.length() != 0)
958 return value;
959 }
960 return null;
961 }
962
963
964
965
966
967
968 public static Set<String> returnValidISBNs(Set<String> candidates) {
969
970
971
972
973
974 Set<String> isbnSet = new LinkedHashSet<String>();
975
976 Pattern p10 = Pattern.compile("^\\d{9}[\\dX].*");
977 Pattern p13 = Pattern.compile("^(978|979)\\d{9}[X\\d].*");
978
979 Pattern p13any = Pattern.compile("^\\d{12}[X\\d].*");
980
981 Iterator<String> iter = candidates.iterator();
982 while (iter.hasNext()) {
983 String value = (String) iter.next().trim();
984
985 if (p13.matcher(value).matches())
986 isbnSet.add(value.substring(0, 13));
987 else if (p10.matcher(value).matches() && !p13any.matcher(value).matches())
988 isbnSet.add(value.substring(0, 10));
989 }
990 return isbnSet;
991 }
992
993
994
995
996
997
998
999 @SuppressWarnings("unchecked")
1000 public static final Set<String> getAllSubfields(final Record record, String[] tags) {
1001 Set<String> result = new LinkedHashSet<String>();
1002
1003 List<VariableField> varFlds = record.getVariableFields(tags);
1004 for (VariableField vf : varFlds) {
1005
1006 StringBuffer buffer = new StringBuffer(500);
1007
1008 DataField df = (DataField) vf;
1009 if (df != null) {
1010 List<Subfield> subfields = df.getSubfields();
1011 for (Subfield sf : subfields) {
1012 if (buffer.length() > 0) {
1013 buffer.append(" " + sf.getData());
1014 } else {
1015 buffer.append(sf.getData());
1016 }
1017 }
1018 }
1019 if (buffer.length() > 0)
1020 result.add(buffer.toString());
1021 }
1022
1023 return result;
1024 }
1025
1026
1027
1028
1029
1030
1031
1032
1033 public static final String getSubfieldData(DataField df, char code) {
1034 String result = null;
1035 if (df != null) {
1036 Subfield sf = df.getSubfield(code);
1037 if (sf != null && sf.getData() != null) {
1038 result = sf.getData();
1039 }
1040 }
1041 return result;
1042 }
1043
1044
1045
1046
1047
1048 @SuppressWarnings("unchecked")
1049 public static final List<String> getSubfieldStrings(DataField df, char code) {
1050 List<Subfield> listSubcode = df.getSubfields(code);
1051 List<String> vals = new ArrayList(listSubcode.size());
1052 for (Subfield s : listSubcode) {
1053 vals.add(s.getData());
1054 }
1055 return vals;
1056 }
1057
1058
1059
1060
1061
1062
1063
1064
1065 public static char foldDiacriticLatinChar(char c) {
1066 switch (c) {
1067 case 0x0181:
1068 return (0x0042);
1069 case 0x0182:
1070 return (0x0042);
1071 case 0x0187:
1072 return (0x0043);
1073 case 0x0110:
1074 return (0x0044);
1075 case 0x018A:
1076 return (0x0044);
1077 case 0x018B:
1078 return (0x0044);
1079 case 0x0191:
1080 return (0x0046);
1081 case 0x0193:
1082 return (0x0047);
1083 case 0x01E4:
1084 return (0x0047);
1085 case 0x0126:
1086 return (0x0048);
1087 case 0x0197:
1088 return (0x0049);
1089 case 0x0198:
1090 return (0x004B);
1091 case 0x0141:
1092 return (0x004C);
1093 case 0x019D:
1094 return (0x004E);
1095 case 0x0220:
1096 return (0x004E);
1097 case 0x00D8:
1098 return (0x004F);
1099 case 0x019F:
1100 return (0x004F);
1101 case 0x01FE:
1102 return (0x004F);
1103 case 0x01A4:
1104 return (0x0050);
1105 case 0x0166:
1106 return (0x0054);
1107 case 0x01AC:
1108 return (0x0054);
1109 case 0x01AE:
1110 return (0x0054);
1111 case 0x01B2:
1112 return (0x0056);
1113 case 0x01B3:
1114 return (0x0059);
1115 case 0x01B5:
1116 return (0x005A);
1117 case 0x0224:
1118 return (0x005A);
1119 case 0x0180:
1120 return (0x0062);
1121 case 0x0183:
1122 return (0x0062);
1123 case 0x0253:
1124 return (0x0062);
1125 case 0x0188:
1126 return (0x0063);
1127 case 0x0255:
1128 return (0x0063);
1129 case 0x0111:
1130 return (0x0064);
1131 case 0x018C:
1132 return (0x0064);
1133 case 0x0221:
1134 return (0x0064);
1135 case 0x0256:
1136 return (0x0064);
1137 case 0x0257:
1138 return (0x0064);
1139 case 0x0192:
1140 return (0x0066);
1141 case 0x01E5:
1142 return (0x0067);
1143 case 0x0260:
1144 return (0x0067);
1145 case 0x0127:
1146 return (0x0068);
1147 case 0x0266:
1148 return (0x0068);
1149 case 0x0268:
1150 return (0x0069);
1151 case 0x029D:
1152 return (0x006A);
1153 case 0x0199:
1154 return (0x006B);
1155 case 0x0142:
1156 return (0x006C);
1157 case 0x019A:
1158 return (0x006C);
1159 case 0x0234:
1160 return (0x006C);
1161 case 0x026B:
1162 return (0x006C);
1163 case 0x026C:
1164 return (0x006C);
1165 case 0x026D:
1166 return (0x006C);
1167 case 0x0271:
1168 return (0x006D);
1169 case 0x019E:
1170 return (0x006E);
1171 case 0x0235:
1172 return (0x006E);
1173 case 0x0272:
1174 return (0x006E);
1175 case 0x0273:
1176 return (0x006E);
1177 case 0x00F8:
1178 return (0x006F);
1179 case 0x01FF:
1180 return (0x006F);
1181 case 0x01A5:
1182 return (0x0070);
1183 case 0x02A0:
1184 return (0x0071);
1185 case 0x027C:
1186 return (0x0072);
1187 case 0x027D:
1188 return (0x0072);
1189 case 0x0282:
1190 return (0x0073);
1191 case 0x0167:
1192 return (0x0074);
1193 case 0x01AB:
1194 return (0x0074);
1195 case 0x01AD:
1196 return (0x0074);
1197 case 0x0236:
1198 return (0x0074);
1199 case 0x0288:
1200 return (0x0074);
1201 case 0x028B:
1202 return (0x0076);
1203 case 0x01B4:
1204 return (0x0079);
1205 case 0x01B6:
1206 return (0x007A);
1207 case 0x0225:
1208 return (0x007A);
1209 case 0x0290:
1210 return (0x007A);
1211 case 0x0291:
1212 return (0x007A);
1213 default:
1214 return (0x00);
1215 }
1216 }
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254 }