Changeset 183:8b0ec19c213c
- Timestamp:
- 09/25/08 10:02:01 (5 years ago)
- Author:
- jbarouh
- Branch:
- default
- convert_revision:
- svn:cdcfb263-7567-472c-a848-e2c2df3466e7/trunk@184
- Message:
-
Also adds the contents which are in an unknown xml block.
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r177
|
r183
|
|
| 9 | 9 | import java.io.InputStream; |
| 10 | 10 | import java.io.PrintWriter; |
| | 11 | import java.math.BigInteger; |
| 11 | 12 | import java.net.URL; |
| 12 | 13 | import java.util.ArrayList; |
| … |
… |
|
| 18 | 19 | import javax.xml.datatype.DatatypeFactory; |
| 19 | 20 | import javax.xml.datatype.XMLGregorianCalendar; |
| | 21 | import javax.xml.namespace.QName; |
| 20 | 22 | |
| 21 | 23 | import org.apache.commons.logging.Log; |
| … |
… |
|
| 64 | 66 | try { |
| 65 | 67 | org.w3.unicorn.observationresponse.ObservationresponseDocument ord = org.w3.unicorn.observationresponse.ObservationresponseDocument.Factory |
| 66 | | .parse(r); |
| | 68 | .parse(r); |
| | 69 | /* |
| | 70 | File xml = new File("validator.xml"); |
| | 71 | BufferedReader fr = new BufferedReader(new FileReader(xml)); |
| | 72 | String s; |
| | 73 | String resp =""; |
| | 74 | while ((s=fr.readLine()) != null) { |
| | 75 | resp += s + "\n"; |
| | 76 | } |
| | 77 | //System.out.println(resp); |
| | 78 | fr.close(); |
| | 79 | org.w3.unicorn.observationresponse.ObservationresponseDocument ord = org.w3.unicorn.observationresponse.ObservationresponseDocument.Factory |
| | 80 | .parse(resp); |
| | 81 | */ |
| 67 | 82 | return swap(ord); |
| 68 | | } catch (XmlException e) { |
| | 83 | } catch (Exception e) { |
| 69 | 84 | e.printStackTrace(); |
| 70 | 85 | return null; |
| … |
… |
|
| 365 | 380 | } |
| 366 | 381 | |
| 367 | | // If the class is not recognized, we check the name |
| 368 | | |
| 369 | | // Case : A |
| | 382 | // If the class is not recognized, we check the name and eventually |
| | 383 | // build the corresponding object |
| | 384 | |
| | 385 | // Case : A from XmlAnyTypeImpl |
| 370 | 386 | else if (cursor.getName().toString().equals( |
| 371 | 387 | "{http://www.w3.org/unicorn/observationresponse}a")) { |
| … |
… |
|
| 377 | 393 | coy.setHref(cursor.getTextValue()); |
| 378 | 394 | cursor.toPrevToken(); |
| 379 | | cursor.toNextAttribute(); |
| | 395 | cursor.push(); |
| 380 | 396 | content = swapObj(current, lang); |
| | 397 | cursor.pop(); |
| 381 | 398 | coy.setContent(content); |
| 382 | 399 | list.add(coy); |
| … |
… |
|
| 386 | 403 | count++; |
| 387 | 404 | } |
| | 405 | cursor.toEndToken(); |
| | 406 | count--; |
| 388 | 407 | |
| 389 | | cursor.toEndToken(); |
| 390 | | |
| 391 | | |
| 392 | | } |
| 393 | | |
| 394 | | // Case : Code |
| | 408 | } |
| | 409 | |
| | 410 | // Case : Code from XmlAnyTypeImpl |
| 395 | 411 | else if (cursor.getName().toString().equals( |
| 396 | 412 | "{http://www.w3.org/unicorn/observationresponse}code")) { |
| | 413 | |
| 397 | 414 | Code coy = new Code(); |
| 398 | 415 | List<Object> content = new ArrayList<Object>(); |
| | 416 | cursor.push(); |
| 399 | 417 | content = swapObj(current, lang); |
| | 418 | cursor.pop(); |
| 400 | 419 | coy.setContent(content); |
| 401 | 420 | list.add(coy); |
| … |
… |
|
| 404 | 423 | count++; |
| 405 | 424 | } |
| 406 | | cursor.toEndToken(); |
| 407 | | } |
| 408 | | |
| 409 | | // Case : Img |
| | 425 | cursor.toEndToken(); |
| | 426 | count--; |
| | 427 | } |
| | 428 | |
| | 429 | // Case : Img from XmlAnyTypeImpl |
| 410 | 430 | else if (cursor.getName().toString().equals( |
| 411 | 431 | "{http://www.w3.org/unicorn/observationresponse}img")) { |
| 412 | | org.w3.unicorn.observationresponse.ImgDocument.Img img = (org.w3.unicorn.observationresponse.ImgDocument.Img) current; |
| | 432 | |
| | 433 | cursor.toNextToken(); |
| | 434 | |
| 413 | 435 | Img coy = new Img(); |
| 414 | | coy.setAlt(img.getAlt()); |
| 415 | | coy.setHeight(img.getHeight()); |
| 416 | | coy.setLongdesc(img.getLongdesc()); |
| 417 | | coy.setName(img.getName()); |
| 418 | | coy.setSrc(img.getSrc()); |
| 419 | | coy.setWidth(img.getWidth()); |
| 420 | | list.add(coy); |
| 421 | | |
| 422 | | cursor.toEndToken(); |
| | 436 | while (cursor.isAttr() && cursor.hasNextToken()) { |
| | 437 | |
| | 438 | if (cursor.getName().toString().equals("src")) |
| | 439 | coy.setSrc(cursor.getTextValue()); |
| | 440 | else if (cursor.getName().toString().equals("alt")) |
| | 441 | coy.setAlt(cursor.getTextValue()); |
| | 442 | else if (cursor.getName().toString().equals("longdesc")) |
| | 443 | coy.setLongdesc(cursor.getTextValue()); |
| | 444 | else if (cursor.getName().toString().equals("name")) |
| | 445 | coy.setName(cursor.getTextValue()); |
| | 446 | else if (cursor.getName().toString().equals("width")) |
| | 447 | coy.setWidth(new BigInteger(cursor.getTextValue())); |
| | 448 | else if (cursor.getName().toString().equals("height")) |
| | 449 | coy.setHeight(new BigInteger(cursor.getTextValue())); |
| | 450 | |
| | 451 | cursor.toNextToken(); |
| | 452 | } |
| | 453 | list.add(coy); |
| | 454 | cursor.toEndToken(); |
| | 455 | count--; |
| | 456 | |
| 423 | 457 | } |
| 424 | 458 | |
| … |
… |
|
| 426 | 460 | // We still want to append what's inside a block even if the block's unknown |
| 427 | 461 | else { |
| | 462 | cursor.push(); |
| 428 | 463 | list.addAll(swapObj(current,lang)); |
| 429 | | cursor.toEndToken(); |
| | 464 | cursor.pop(); |
| | 465 | cursor.toEndToken(); |
| | 466 | count--; |
| 430 | 467 | } |
| 431 | 468 | } |
| … |
… |
|
| 439 | 476 | else if (cursor.isEnd()) { |
| 440 | 477 | count--; |
| 441 | | if (count < 0) |
| | 478 | if (count <= 0) |
| 442 | 479 | break; |
| 443 | 480 | } |