This method is responsable with document conversion
()
| 441 | This method is responsable with document conversion |
| 442 | */ |
| 443 | public String convert()throws IOException,MalformedURLException { |
| 444 | while (thereAreCharsToBeProcessed()) { |
| 445 | // read() gets the next char and increment the m_cursor |
| 446 | m_currChar = read(); |
| 447 | switch(m_currState){ |
| 448 | case 1: doState1(m_currChar);break; |
| 449 | case 2: doState2(m_currChar);break; |
| 450 | case 3: doState3(m_currChar);break; |
| 451 | case 4: doState4(m_currChar);break; |
| 452 | case 5: doState5(m_currChar);break; |
| 453 | case 6: doState6(m_currChar);break; |
| 454 | case 7: doState7(m_currChar);break; |
| 455 | case 8: doState8(m_currChar);break; |
| 456 | case 9: doState9(m_currChar);break; |
| 457 | case 10: doState10(m_currChar);break; |
| 458 | case 11: doState11(m_currChar);break; |
| 459 | case 12: doState12(m_currChar);break; |
| 460 | case 13: doState13(m_currChar);break; |
| 461 | }// switch(m_currState) |
| 462 | }// while (thereAreCharsToBeProcessed()) |
| 463 | |
| 464 | // put all the elements from the stack into the dubiousElements list |
| 465 | // we do that in order to colect all the dubious elements |
| 466 | while (!stack.isEmpty()) { |
| 467 | CustomObject obj = stack.pop(); |
| 468 | dubiousElements.add(obj); |
| 469 | } |
| 470 | |
| 471 | // sort the dubiousElements list descending on closePos... |
| 472 | // This is vital for the alghorithm because we have to make |
| 473 | // all the modifications from the bottom to the top... |
| 474 | // If we fail to do that, insert will change indices and |
| 475 | // CustomObject.getClosePos() will not be acurate anymore. |
| 476 | Collections.sort(dubiousElements, new MyComparator()); |
| 477 | |
| 478 | //here we resolve all the dubious Elements... |
| 479 | // see the description of makeFinalModifications() method |
| 480 | ListIterator<CustomObject> listIterator = dubiousElements.listIterator(); |
| 481 | while (listIterator.hasNext()){ |
| 482 | CustomObject obj = listIterator.next(); |
| 483 | makeFinalModifications(obj); |
| 484 | } |
| 485 | |
| 486 | //finally add the XML prolog |
| 487 | m_modifier.insert(0,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); |
| 488 | //Out.println(m_modifier.toString()); |
| 489 | /* |
| 490 | // get a InputStream from m_modifier and write it into a temp file |
| 491 | // finally return the URI of the new XML document |
| 492 | ByteArrayInputStream is = new ByteArrayInputStream( |
| 493 | m_modifier.toString().getBytes() |
| 494 | ); |
| 495 | */ |
| 496 | // this method is in gate.util package |
| 497 | File file = Files.writeTempFile(m_modifier.toString(),"UTF-8"); |
| 498 | |
| 499 | //return m_doc.getSourceURL().toString(); |
| 500 | return file.toURI().toURL().toString(); |
no test coverage detected