1 package com.teamkonzept.webman.barmer; 2 3 import com.teamkonzept.lib.*; 4 5 8 public class TKBarmerConverter extends TKHtmlConverter { 9 public final static String CONV_ID = "BE"; 10 public final static String CONV_NAME = "BARMER-HTML-ISO-8859_1"; 11 12 public String getName() 13 { 14 return CONV_NAME; 15 } 16 17 public final static byte TAGSTART = (byte) '<'; 18 public final static byte TAGEND = (byte) '>'; 19 20 public int charsToBytes(char src[], byte dst[], int srcBegin, int length, int dstBegin) 21 { 22 int lastPos = srcBegin+length; 23 int firstPos = dstBegin; 24 int openCount = 0; 25 MAIN_LOOP: 26 for( int i=srcBegin; i<lastPos; i++ ) { 27 28 char c = src[i]; 29 boolean done = ( c != '<' ); 30 while( !done ) { 31 done = true; 32 if( src[i+1] == 'B' 33 || src[i+1] == 'b' 34 || src[i+1] == 'I' 35 || src[i+1] == 'i' 36 || src[i+1] == 'A' 37 || src[i+1] == 'a' 38 || ((openCount > 0) && (src[i+1] == '/')) 39 ) { 40 int startpos = ( src[i+1] == 'A' || src[i+1] == 'a' ) ? i+1 : -1; 41 42 if( src[i+1] == '/' ) { 43 openCount--; 44 } 45 else { 46 openCount++; 47 } 48 char srcC; 49 boolean ignore; 50 do { 51 ignore = false; 52 srcC = src[i++]; 53 if( srcC == '\\' && i <= lastPos ) { 54 srcC = src[i++]; 55 ignore = true; 56 } 57 dst[ dstBegin++ ] = (byte) srcC; 58 if( i>=lastPos ) break MAIN_LOOP; 59 } while( ignore || src[i-1] != '>' ); 60 c = src[i]; 61 done = ( c != '<' ); 62 } 63 } 64 65 byte b = (byte) c; 66 int code = (int) c; 67 String subst = HTML_CODES[ code ]; 68 if( subst == null ) { 69 if( c <='\u0080' ) { 71 if( (lastPos - i >= 2) 72 && (c == '\015') 73 && (src[i+1] == '\012') 74 ) { 75 dst[ dstBegin++ ] = TAGSTART; 76 dst[ dstBegin++ ] = (byte) 'B'; 77 dst[ dstBegin++ ] = (byte) 'R'; 78 dst[ dstBegin++ ] = TAGEND; 79 } 80 else { 81 dst[ dstBegin++ ] = b; 82 } 83 } 84 else if( c < '\u0100' ) { 85 dst[ dstBegin++ ] = AMPERCENT; 86 dst[ dstBegin++ ] = HASH; 87 dst[ dstBegin++ ] = (byte) Character.forDigit( ( code / 100 ), 10 ); 88 dst[ dstBegin++ ] = (byte) Character.forDigit( ( code % 100 / 10 ), 10 ); 89 dst[ dstBegin++ ] = (byte) Character.forDigit( ( code % 10 ), 10 ); 90 dst[ dstBegin++ ] = SEMICOLON; 91 } 92 } 93 else { 94 dst[ dstBegin++ ] = AMPERCENT; 95 int len = subst.length(); 96 subst.getBytes( 0, len, dst, dstBegin ); 97 dstBegin += len; 98 dst[ dstBegin++ ] = SEMICOLON; 99 } 100 } 101 102 return dstBegin - firstPos; 103 } 104 105 } | Popular Tags |