1 package com.teamkonzept.webman.bchannel; 2 3 import com.teamkonzept.lib.*; 4 5 8 public class TKBChannelConverter2 extends TKHtmlConverter { 9 public final static String CONV_ID = "BC2"; 10 public final static String CONV_NAME = "BC2-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 || src[i+1] == 'R' 39 || src[i+1] == 'r' 40 || ((openCount > 0) && (src[i+1] == '/')) 41 ) { 42 int startpos = ( src[i+1] == 'A' || src[i+1] == 'a' ) ? i+1 : -1; 43 boolean isEndTag = src[i+1] == '/'; 44 char codeChar = Character.toUpperCase( src[ i + (isEndTag ? 2 : 1) ] ); 45 46 if( isEndTag ) { 47 openCount--; 48 } 49 else { 50 openCount++; 51 } 52 53 if( codeChar == 'R' ) { 54 do { 55 i++; 56 if( i>=lastPos ) break MAIN_LOOP; 57 } while( src[i-1] != '>' ); 58 dst[ dstBegin++ ] = (byte) '<'; 59 if( !isEndTag ) { 60 dst[ dstBegin++ ] = (byte) 'F'; 61 dst[ dstBegin++ ] = (byte) 'O'; 62 dst[ dstBegin++ ] = (byte) 'N'; 63 dst[ dstBegin++ ] = (byte) 'T'; 64 dst[ dstBegin++ ] = (byte) ' '; 65 dst[ dstBegin++ ] = (byte) 'C'; 66 dst[ dstBegin++ ] = (byte) 'O'; 67 dst[ dstBegin++ ] = (byte) 'L'; 68 dst[ dstBegin++ ] = (byte) 'O'; 69 dst[ dstBegin++ ] = (byte) 'R'; 70 dst[ dstBegin++ ] = (byte) '='; 71 dst[ dstBegin++ ] = (byte) '"'; 72 dst[ dstBegin++ ] = (byte) '#'; 73 dst[ dstBegin++ ] = (byte) 'F'; 74 dst[ dstBegin++ ] = (byte) 'F'; 75 dst[ dstBegin++ ] = (byte) '0'; 76 dst[ dstBegin++ ] = (byte) '0'; 77 dst[ dstBegin++ ] = (byte) '0'; 78 dst[ dstBegin++ ] = (byte) '0'; 79 dst[ dstBegin++ ] = (byte) '"'; 80 } 81 else { 82 dst[ dstBegin++ ] = (byte) '/'; 83 dst[ dstBegin++ ] = (byte) 'F'; 84 dst[ dstBegin++ ] = (byte) 'O'; 85 dst[ dstBegin++ ] = (byte) 'N'; 86 dst[ dstBegin++ ] = (byte) 'T'; 87 } 88 dst[ dstBegin++ ] = (byte) '>'; 89 } 90 else { 91 do { 92 dst[ dstBegin++ ] = (byte) src[i++]; 93 if( i>=lastPos ) break MAIN_LOOP; 94 } while( src[i-1] != '>' ); 95 } 96 c = src[i]; 97 done = ( c != '<' ); 98 } 99 else if( src[i+1] == 'R' || src[i+1] == 'r' ) { 100 } 101 } 102 103 byte b = (byte) c; 104 int code = (int) c; 105 String subst = HTML_CODES[ code ]; 106 if( subst == null ) { 107 if( c <='\u0080' ) { 109 if( (lastPos - i >= 2) 110 && (c == '\015') 111 && (src[i+1] == '\012') 112 ) { 113 dst[ dstBegin++ ] = TAGSTART; 114 dst[ dstBegin++ ] = (byte) 'B'; 115 dst[ dstBegin++ ] = (byte) 'R'; 116 dst[ dstBegin++ ] = TAGEND; 117 } 118 else { 119 dst[ dstBegin++ ] = b; 120 } 121 } 122 else if( c < '\u0100' ) { 123 dst[ dstBegin++ ] = AMPERCENT; 124 dst[ dstBegin++ ] = HASH; 125 dst[ dstBegin++ ] = (byte) Character.forDigit( ( code / 100 ), 10 ); 126 dst[ dstBegin++ ] = (byte) Character.forDigit( ( code % 100 / 10 ), 10 ); 127 dst[ dstBegin++ ] = (byte) Character.forDigit( ( code % 10 ), 10 ); 128 dst[ dstBegin++ ] = SEMICOLON; 129 } 130 } 131 else { 132 dst[ dstBegin++ ] = AMPERCENT; 133 int len = subst.length(); 134 subst.getBytes( 0, len, dst, dstBegin ); 135 dstBegin += len; 136 dst[ dstBegin++ ] = SEMICOLON; 137 } 138 } 139 140 return dstBegin - firstPos; 141 } 142 143 } | Popular Tags |