1 19 20 package org.netbeans.modules.javadoc.search; 21 22 import java.util.NoSuchElementException ; 23 import java.util.StringTokenizer ; 24 import java.io.BufferedReader ; 25 import java.io.InputStreamReader ; 26 import java.io.Reader ; 27 import java.net.URL ; 28 29 import javax.swing.text.html.parser.ParserDelegator ; 30 import javax.swing.text.html.HTMLEditorKit ; 31 import javax.swing.text.html.HTML ; 32 import javax.swing.text.MutableAttributeSet ; 33 34 import org.openide.ErrorManager; 35 import org.openide.util.NbBundle; 36 import org.openide.filesystems.FileObject; 37 38 41 42 class SearchThreadJdk12_japan extends IndexSearchThread { 43 44 private Reader in; 45 private URL contextURL; 46 47 private boolean stopSearch = false; 48 49 private boolean splitedIndex = false; 50 private int currentIndexNumber; 51 private FileObject folder = null; 52 private String JapanEncoding; 53 private final Object LOCK = new Object (); 54 55 public SearchThreadJdk12_japan(String toFind, FileObject fo, IndexSearchThread.DocIndexItemConsumer diiConsumer, boolean caseSensitive, String JapanEncoding) { 56 57 super( toFind, fo, diiConsumer, caseSensitive ); 58 this.JapanEncoding = JapanEncoding; 59 60 if ( fo.isFolder() ) { 61 63 64 folder = fo; 68 currentIndexNumber = (int)(Character.toUpperCase( lastField.charAt(0) )) - 'A' + 1; 70 if ( currentIndexNumber < 1 ) { 71 currentIndexNumber = 1; 72 } 73 else if ( currentIndexNumber > 26 ) { 74 currentIndexNumber = 27; 75 } 76 77 82 findFileObject( 0 ); 83 84 splitedIndex = true; 85 } 86 else { 87 try { 88 contextURL = this.indexRoot.getURL(); 89 } 91 catch ( org.openide.filesystems.FileStateInvalidException e ) { 92 throw new InternalError ( "Can't create documentation folder URL - file state invalid" ); } 94 95 splitedIndex = false; 96 } 97 } 98 99 public void stopSearch() { 100 Reader br; 101 synchronized (LOCK) { 102 stopSearch = true; 103 br = in; 104 } 105 106 try { 107 if (br != null) 108 br.close(); 109 } 110 catch ( java.io.IOException e ) { 111 ErrorManager.getDefault().notify(e); 112 } 113 } 114 115 public void run () { 116 117 ParserDelegator pd = new ParserDelegator (); 118 119 if ( indexRoot == null || lastField == null || lastField.length() == 0) { 120 taskFinished(); 121 return; 122 } 123 124 125 SearchCallbackJdk12_japan sc = null; 126 127 int theDirection = 0; 128 129 do { 130 if ( sc != null ) { 131 132 if (sc.badFile != theDirection ) { 133 break; 134 } 135 136 findFileObject( sc.badFile ); 137 if ( indexRoot == null ) { 138 break; 140 } 141 } 142 143 try { 144 synchronized (LOCK) { 145 if (stopSearch) { 146 break; 147 } 148 in = new BufferedReader ( new InputStreamReader ( indexRoot.getInputStream (), JapanEncoding )); 149 } 150 pd.parse( in, sc = new SearchCallbackJdk12_japan( splitedIndex, caseSensitive ), true ); 152 } 153 catch ( java.io.IOException e ) { 154 } 156 157 if ( sc.badFile != 0 && theDirection == 0 ) { 158 theDirection = sc.badFile; 159 } 160 } 161 while ( sc.badFile != 0 ); 162 163 try { 164 if (in != null) { 165 in.close(); 166 } 167 } 168 catch ( java.io.IOException e ) { 169 } 171 taskFinished(); 173 } 174 175 void findFileObject( int direction ) { 176 177 178 if ( direction < 0 ) { 179 currentIndexNumber--; 180 } 181 else if ( direction > 0 ) { 182 currentIndexNumber++; 183 } 184 185 do { 186 187 if ( currentIndexNumber < 0 || currentIndexNumber > 27 ) { 189 indexRoot = null; 190 return; 191 } 192 193 String fileName = "index-" + currentIndexNumber; 195 if ( folder == null ) { 196 indexRoot = null; 197 return; 198 } 199 200 indexRoot = folder.getFileObject( fileName, "html" ); 202 if ( indexRoot != null ) { 203 try { 204 contextURL = this.indexRoot.getURL(); 205 } 206 catch ( org.openide.filesystems.FileStateInvalidException e ) { 207 throw new InternalError ( "Can't create documentation folder URL - file state invalid" ); } 209 } 210 else { 211 212 currentIndexNumber += direction > 0 ? 1 : -1; 213 } 214 } 215 while ( indexRoot == null ); 216 217 } 218 219 221 222 223 224 static private final String STR_CLASS = NbBundle.getMessage(SearchThreadJdk12_japan.class, "JDK12_CLASS" ); static private final String STR_INTERFACE = NbBundle.getMessage(SearchThreadJdk12_japan.class, "JDK12_INTERFACE" ); static private final String STR_EXCEPTION = NbBundle.getMessage(SearchThreadJdk12_japan.class, "JDK12_EXCEPTION" ); static private final String STR_CONSTRUCTOR = NbBundle.getMessage(SearchThreadJdk12_japan.class, "JDK12_CONSTRUCTOR" ); static private final String STR_METHOD = NbBundle.getMessage(SearchThreadJdk12_japan.class, "JDK12_METHOD" ); static private final String STR_ERROR = NbBundle.getMessage(SearchThreadJdk12_japan.class, "JDK12_ERROR" ); static private final String STR_VARIABLE = NbBundle.getMessage(SearchThreadJdk12_japan.class, "JDK12_VARIABLE" ); static private final String STR_STATIC = NbBundle.getMessage(SearchThreadJdk12_japan.class, "JDK12_STATIC" ); static private final String STR_DASH = NbBundle.getMessage(SearchThreadJdk12_japan.class, "JDK12_DASH" ); static private final String STR_PACKAGE = NbBundle.getMessage(SearchThreadJdk12_japan.class, "JDK12_PACKAGE" ); private static final String STR_ENUM = NbBundle.getMessage(SearchThreadJdk12_japan.class, "JDK15_ENUM"); private static final String STR_ANNTYPE = NbBundle.getMessage(SearchThreadJdk12_japan.class, "JDK15_ANNOTATION_TYPE"); 237 static private final String STR_CONSTRUCTOR_JA = NbBundle.getMessage(SearchThreadJdk12_japan.class, "JDK12_CONSTRUCTOR_JA" ); static private final String STR_METHOD_JA = NbBundle.getMessage(SearchThreadJdk12_japan.class, "JDK12_METHOD_JA" ); static private final String STR_VARIABLE_JA = NbBundle.getMessage(SearchThreadJdk12_japan.class, "JDK12_VARIABLE_JA" ); 241 static private final int IN_BALAST = 0; 242 static private final int IN_DT = 1; 243 static private final int IN_AREF = 2; 244 static private final int IN_DESCRIPTION = 4; 246 static private final int IN_DESCRIPTION_SUFFIX = 5; 247 248 251 252 private class SearchCallbackJdk12_japan extends HTMLEditorKit.ParserCallback { 253 254 private String hrefVal; 255 private DocIndexItem currentDii = null; 256 private int where = IN_BALAST; 257 258 private boolean splited; 259 private boolean stopOnNext = false; 260 261 private int badFile = 0; 262 263 int printText = 0; 264 265 SearchCallbackJdk12_japan( boolean splited, boolean caseSensitive ) { 266 super(); 267 this.splited = splited; 268 } 269 270 public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) { 271 272 if ( t == HTML.Tag.DT ) { 273 where = IN_DT; 274 currentDii = null; 275 } 276 else if ( t == HTML.Tag.A && where == IN_DT ) { 277 where = IN_AREF; 278 Object val = a.getAttribute( HTML.Attribute.HREF ); 279 if ( val != null ) { 280 hrefVal = (String ) val.toString(); 281 currentDii = new DocIndexItem( null, null, contextURL, hrefVal ); 282 } 283 } 284 else if ( t == HTML.Tag.A && (where == IN_DESCRIPTION_SUFFIX || where == IN_DESCRIPTION) ) { 285 ; } 287 else if ( t == HTML.Tag.B && where == IN_AREF ) { 288 where = IN_AREF; 289 } 290 else { 291 where = IN_BALAST; 292 } 293 } 294 295 public void handleEndTag(HTML.Tag t, int pos) { 296 if (t == HTML.Tag.DT && where != IN_BALAST) { 297 where = IN_BALAST; 298 } 299 } 300 301 public void handleText(char[] data, int pos) { 302 303 if ( where == IN_AREF ) { 304 305 if ( stopOnNext ) { 306 try { 307 in.close(); 308 where = IN_BALAST; 309 return; 310 } 311 catch ( java.io.IOException e ) { 312 ErrorManager.getDefault().notify(e); 313 } 314 } 315 316 String text = new String ( data ); 317 318 if ( splited ) { 319 char first = Character.toUpperCase( lastField.charAt( 0 ) ); 321 char curr = Character.toUpperCase( data[0] ); 322 if ( first != curr ) { 323 324 badFile = first < curr ? -1 : 1; 325 try { 326 in.close(); 327 where = IN_BALAST; 328 return; 329 } 330 catch ( java.io.IOException e ) { 331 ErrorManager.getDefault().notify(e); 332 } 333 } 334 335 } 336 currentDii.setField( text.trim() ); 337 where = IN_DESCRIPTION; 338 } 339 else if ( where == IN_DESCRIPTION ) { 340 String text = new String ( data ); 341 353 354 356 int dashIdx = text.indexOf(STR_DASH); 357 if (dashIdx < 0) { 358 return; 359 } 360 text = text.substring(dashIdx - 1); 361 currentDii.setRemark( text ); 362 363 StringTokenizer st = new StringTokenizer ( text ); 364 String token; 365 366 boolean isStatic = false; 367 try { 368 token = st.nextToken(); 369 if ( token.equals( STR_DASH ) ) 370 token = st.nextToken(); 371 372 if ( token.equalsIgnoreCase( STR_STATIC ) ) { 373 isStatic = true; 374 token = st.nextToken(); 375 } 376 } catch (NoSuchElementException ex) { where = IN_DESCRIPTION_SUFFIX; 378 return; 379 } 380 381 if ( token.equalsIgnoreCase( STR_CLASS ) ) 382 currentDii.setIconIndex( DocSearchIcons.ICON_CLASS ); 383 else if ( token.equalsIgnoreCase( STR_INTERFACE ) ) 384 currentDii.setIconIndex( DocSearchIcons.ICON_INTERFACE ); 385 else if ( token.equalsIgnoreCase( STR_ENUM ) ) 386 currentDii.setIconIndex( DocSearchIcons.ICON_ENUM ); 387 else if ( token.equalsIgnoreCase( STR_ANNTYPE ) ) 388 currentDii.setIconIndex( DocSearchIcons.ICON_ANNTYPE ); 389 else if ( token.equalsIgnoreCase( STR_EXCEPTION ) ) 390 currentDii.setIconIndex( DocSearchIcons.ICON_EXCEPTION ); 391 else if ( token.equalsIgnoreCase( STR_ERROR ) ) 392 currentDii.setIconIndex( DocSearchIcons.ICON_ERROR ); 393 else if ( token.equalsIgnoreCase( STR_PACKAGE ) ) 394 currentDii.setIconIndex( DocSearchIcons.ICON_PACKAGE ); 395 else if ( token.equalsIgnoreCase( STR_CONSTRUCTOR ) ) 396 currentDii.setIconIndex( DocSearchIcons.ICON_CONSTRUCTOR ); 397 else if ( token.equalsIgnoreCase( STR_METHOD ) ) 398 currentDii.setIconIndex( isStatic ? DocSearchIcons.ICON_METHOD_ST : DocSearchIcons.ICON_METHOD ); 399 else if ( token.equalsIgnoreCase( STR_VARIABLE ) ) 400 currentDii.setIconIndex( isStatic ? DocSearchIcons.ICON_VARIABLE_ST : DocSearchIcons.ICON_VARIABLE ); 401 402 405 if (currentDii.getPackage() != null) { 406 where = IN_DESCRIPTION_SUFFIX; 407 } else if ( text.endsWith( "." ) ) { where = IN_DESCRIPTION_SUFFIX; 409 currentDii.setPackage( text.substring( text.lastIndexOf( ' ' ) ).trim() ); 410 } 411 else 412 where = IN_BALAST; 413 } 414 else if ( where == IN_DESCRIPTION_SUFFIX ) { 415 boolean isStatic = false; 416 String remark = String.valueOf(data); 417 currentDii.setRemark( currentDii.getRemark() + remark); 418 String declaringClass = remark.trim(); 419 if( !(".".equals(declaringClass))){ if (currentDii.getDeclaringClass() == null) { 421 currentDii.setDeclaringClass(declaringClass); 422 423 remark = remark.toUpperCase(); 425 if( remark.indexOf( STR_STATIC ) != -1 ) 426 isStatic = true; 427 428 if( remark.indexOf( STR_CONSTRUCTOR_JA ) != -1 ) 429 currentDii.setIconIndex(DocSearchIcons.ICON_CONSTRUCTOR ); 430 else if( remark.indexOf( STR_METHOD_JA ) != -1 ) 431 currentDii.setIconIndex( isStatic ? DocSearchIcons.ICON_METHOD_ST : DocSearchIcons.ICON_METHOD ); 432 else if( remark.indexOf( STR_VARIABLE_JA ) != -1 ) 433 currentDii.setIconIndex( isStatic ? DocSearchIcons.ICON_VARIABLE_ST : DocSearchIcons.ICON_VARIABLE ); 434 insertDocIndexItem( currentDii ); 435 } 436 } 437 } 438 else 439 where = IN_BALAST; 440 441 } 442 443 } 444 445 } 446 | Popular Tags |