- Timestamp:
- 2008-08-15T16:07:28+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gli/trunk/src/org/greenstone/gatherer/collection/CollectionTreeNode.java
r16770 r16834 64 64 } 65 65 66 /** Similar to calcDisplayString, but this version only checks whether the filename67 * String is UTF8. If so, it converts it into UTF8 and returns it. If the filename68 * is not UTF8, it is returned unchanged.69 */70 protected String quickCalcDisplayString() {71 String filename = super.toString();72 try{73 String utf8filename = new String(filename.getBytes(), "UTF8");74 if(utf8filename.indexOf('\ufffd') == -1) {75 return utf8filename;76 } else { // contains the character indicating that it's invalid utf877 // return the original string78 return filename;79 }80 } catch(java.io.UnsupportedEncodingException e) {81 return filename;82 }83 }84 66 85 67 /** This method returns a string representation of the filenodes in the Collection … … 107 89 protected String calcDisplayString() { 108 90 String filename = super.toString(); 109 110 91 try{ 111 String[] charsets = {"UTF-8", "ISO-8859-1", "US-ASCII", "UTF-16BE", "UTF-16LE", "UTF-16"}; 112 for(int i = 0; i < charsets.length; i++) { 113 String charset = charsets[i]; 114 String convertedfilename = new String(filename.getBytes(), charset); 115 if(convertedfilename.indexOf('\ufffd') != -1) { 116 // encountered the character that indicates when the conversion is invalid 117 convertedfilename = null; 118 continue; // try to use the next charset to encode the filename as 119 } 120 else { // valid conversion 121 return convertedfilename; 122 } 92 String utf8filename = new String(filename.getBytes(), "UTF8"); 93 if(utf8filename.indexOf('\ufffd') == -1) { 94 return utf8filename; 95 } else { // contains the character indicating that it's invalid utf8 96 // return the original string 97 return filename; 123 98 } 124 99 } catch(java.io.UnsupportedEncodingException e) { 125 100 return filename; 126 101 } 127 128 return filename; // attempted conversions all failed129 102 } 130 103
Note:
See TracChangeset
for help on using the changeset viewer.