1 25 package org.jrobin.graph; 26 27 import java.util.Vector ; 28 import java.util.ArrayList ; 29 30 import org.jrobin.core.RrdException; 31 import org.jrobin.core.XmlWriter; 32 33 38 class Comment 39 { 40 protected static final int CMT_DEFAULT = 0; 44 protected static final int CMT_LEGEND = 1; 45 protected static final int CMT_GPRINT = 2; 46 protected static final int CMT_NOLEGEND = 3; 47 48 protected static final Byte TKN_ALF = new Byte ( (byte) 1); protected static final Byte TKN_ARF = new Byte ( (byte) 2); protected static final Byte TKN_ACF = new Byte ( (byte) 3); protected static final Byte TKN_AL = new Byte ( (byte) 4); protected static final Byte TKN_AR = new Byte ( (byte) 5); protected static final Byte TKN_AC = new Byte ( (byte) 6); protected static final Byte TKN_NULL = null; 55 56 protected int lineCount = 0; 57 protected boolean endLf = false; 58 protected boolean addSpacer = true; 59 protected boolean trimString = false; 60 protected int commentType = CMT_DEFAULT; 61 protected Byte lfToken = TKN_ALF; 62 63 protected String text; 64 protected ArrayList oList = new ArrayList (3); 65 66 67 Comment( ) { 71 } 72 73 80 Comment( String text ) throws RrdException 81 { 82 this.text = text; 83 84 if ( text != null ) 85 parseComment(); 86 } 87 88 89 97 void parseComment() throws RrdException 98 { 99 String text = this.text; 101 102 int mpos = text.indexOf("@g"); 103 if ( mpos >= 0 && mpos == (text.length() - 2) ) { 104 addSpacer = false; 105 trimString = true; 106 text = text.substring( 0, text.length() - 2); 107 } 108 else { 109 mpos = text.indexOf("@G"); 110 if ( mpos >= 0 && mpos == (text.length() - 2) ) { 111 addSpacer = false; 112 trimString = false; 113 text = text.substring( 0, text.length() - 2); 114 } 115 } 116 117 Byte tkn; 119 int lastPos = 0; 120 mpos = text.indexOf("@"); 121 int lfpos = text.indexOf("\n"); 122 if ( mpos == text.length() ) mpos = -1; 123 if ( lfpos == text.length() ) lfpos = -1; 124 125 while ( mpos >= 0 || lfpos >= 0 ) 126 { 127 if ( mpos >= 0 && lfpos >= 0 ) 128 { 129 if ( mpos < lfpos ) 130 { 131 tkn = getToken( text.charAt(mpos + 1) ); 132 if ( tkn != TKN_NULL ) { 133 oList.add( text.substring(lastPos, mpos) ); 134 oList.add( tkn ); 135 lastPos = mpos + 2; 136 mpos = text.indexOf("@", lastPos); 137 } 138 else { 139 mpos = text.indexOf("@", mpos + 1); 140 } 141 } 142 else 143 { 144 oList.add( text.substring(lastPos, lfpos) ); 145 oList.add( lfToken ); 146 endLf = true; 147 lineCount++; 148 lastPos = lfpos + 1; 149 lfpos = text.indexOf("\n", lastPos); 150 } 151 } 152 else if ( mpos >= 0 ) 153 { 154 tkn = getToken( text.charAt(mpos + 1) ); 155 if ( tkn != TKN_NULL ) { 156 oList.add( text.substring(lastPos, mpos) ); 157 oList.add( tkn ); 158 lastPos = mpos + 2; 159 mpos = text.indexOf("@", lastPos); 160 } 161 else 162 mpos = text.indexOf("@", mpos + 1); 163 } 164 else 165 { 166 oList.add( text.substring(lastPos, lfpos) ); 167 oList.add( lfToken ); 168 endLf = true; 169 lineCount++; 170 lastPos = lfpos + 1; 171 lfpos = text.indexOf("\n", lastPos); 172 } 173 174 if ( mpos == text.length() ) mpos = -1; 176 if ( lfpos == text.length() ) lfpos = -1; 177 } 178 179 if ( lastPos < text.length() ) 181 { 182 oList.add( text.substring(lastPos) ); 183 oList.add( TKN_NULL ); 184 } 185 } 186 187 192 Byte getToken( char tokenChar ) 193 { 194 switch ( tokenChar ) 195 { 196 case 'l': 197 lineCount++; 198 endLf = true; 199 return TKN_ALF; 200 case 'L': 201 return TKN_AL; 202 case 'r': 203 lineCount++; 204 endLf = true; 205 return TKN_ARF; 206 case 'R': 207 return TKN_AR; 208 case 'c': 209 lineCount++; 210 endLf = true; 211 return TKN_ACF; 212 case 'C': 213 return TKN_AC; 214 default: 215 return TKN_NULL; 216 } 217 } 218 219 223 boolean isCompleteLine() 224 { 225 return endLf; 226 } 227 228 232 ArrayList getTokens() 233 { 234 return oList; 235 } 236 237 241 int getLineCount() 242 { 243 return lineCount; 244 } 245 246 boolean addSpacer() { 247 return addSpacer; 248 } 249 250 boolean trimString() { 251 return trimString; 252 } 253 254 String getText() { 255 return text; 256 } 257 258 void exportXmlTemplate(XmlWriter xml) { 259 xml.writeTag("comment", getText()); 260 } 261 } 262 | Popular Tags |