1 57 58 package org.enhydra.apache.xerces.readers; 59 60 import java.io.InputStreamReader ; 61 import java.io.UnsupportedEncodingException ; 62 63 import org.enhydra.apache.xerces.framework.XMLErrorReporter; 64 import org.enhydra.apache.xerces.utils.ChunkyByteArray; 65 import org.enhydra.apache.xerces.utils.StringPool; 66 67 71 final class EBCDICRecognizer extends XMLDeclRecognizer { 72 public XMLEntityHandler.EntityReader recognize(XMLEntityReaderFactory readerFactory, 76 XMLEntityHandler entityHandler, 77 XMLErrorReporter errorReporter, 78 boolean sendCharDataAsCharArray, 79 StringPool stringPool, 80 ChunkyByteArray data, 81 boolean xmlDecl, 82 boolean allowJavaEncodingName) throws Exception 83 { 84 XMLEntityHandler.EntityReader reader = null; 85 byte b0 = data.byteAt(0); 86 byte b1 = data.byteAt(1); 87 byte b2 = data.byteAt(2); 88 byte b3 = data.byteAt(3); 89 boolean debug = false; 90 91 if (b0 != 0x4c || b1 != 0x6f || b2 != (byte)0xa7 || b3 != (byte)0x94) 92 return reader; 93 XMLEntityHandler.EntityReader declReader = readerFactory.createCharReader(entityHandler, errorReporter, sendCharDataAsCharArray, new InputStreamReader (data, "CP037"), stringPool); 94 int encoding = prescanXMLDeclOrTextDecl(declReader, xmlDecl); 95 if (encoding == -1) { 96 data.rewind(); 97 throw new UnsupportedEncodingException (null); 100 } 101 String enc = stringPool.orphanString(encoding).toUpperCase(); 102 if ("ISO-10646-UCS-2".equals(enc)) throw new UnsupportedEncodingException (enc); 103 if ("ISO-10646-UCS-4".equals(enc)) throw new UnsupportedEncodingException (enc); 104 if ("UTF-16".equals(enc)) throw new UnsupportedEncodingException (enc); 105 String javaencname = MIME2Java.convert(enc); 106 if (null == javaencname) { 107 if (allowJavaEncodingName) { 108 javaencname = enc; 109 } else { 110 throw new UnsupportedEncodingException (enc); 111 } 112 } 113 try { 114 data.rewind(); 115 reader = readerFactory.createCharReader(entityHandler, errorReporter, sendCharDataAsCharArray, new InputStreamReader (data, javaencname), stringPool); 116 } catch (UnsupportedEncodingException e) { 117 throw e; 118 } catch (Exception e) { 119 if( debug == true ) 120 e.printStackTrace(); } 122 return reader; 123 } 124 } 125 | Popular Tags |