1 16 package ui; 17 18 import org.apache.xerces.parsers.DOMParser; 19 import org.apache.xerces.util.EncodingMap; 20 import org.apache.xerces.xni.Augmentations; 21 import org.apache.xerces.xni.XMLResourceIdentifier; 22 import org.apache.xerces.xni.XNIException; 23 24 31 32 33 public class DOMParserSaveEncoding extends DOMParser { 34 String _mimeEncoding = "UTF-8"; private void setMimeEncoding( String encoding ) { 36 _mimeEncoding = encoding; 37 } 38 private String getMimeEncoding() { 39 return(_mimeEncoding); 40 } 41 public String getJavaEncoding() { 42 String javaEncoding = null; 43 String mimeEncoding = getMimeEncoding(); 44 45 if (mimeEncoding != null) { 46 if (mimeEncoding.equals( "DEFAULT" )) 47 javaEncoding = "UTF8"; 48 else if (mimeEncoding.equalsIgnoreCase( "UTF-16" )) 49 javaEncoding = "Unicode"; 50 else 51 javaEncoding = EncodingMap.getIANA2JavaMapping( mimeEncoding ); 52 } 53 if(javaEncoding == null) javaEncoding = "UTF8"; 55 return(javaEncoding); 56 } 57 public void startGeneralEntity(String name, 58 XMLResourceIdentifier identifier, 59 String encoding, Augmentations augs) throws XNIException { 60 if( encoding != null){ 61 setMimeEncoding( encoding); 62 } 63 super.startGeneralEntity(name, identifier, encoding, augs); 64 } 65 66 } 67 68 | Popular Tags |