| 1 |
package cds.astrores.sax; |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
import java.io.BufferedInputStream; |
| 25 |
import java.io.DataInputStream; |
| 26 |
import java.io.File; |
| 27 |
import java.io.FileInputStream; |
| 28 |
import java.io.IOException; |
| 29 |
import java.io.InputStream; |
| 30 |
import java.net.URL; |
| 31 |
import java.util.ArrayList; |
| 32 |
|
| 33 |
|
| 34 |
import org.kxml2.io.KXmlParser; |
| 35 |
import org.xmlpull.v1.XmlPullParser; |
| 36 |
|
| 37 |
import cds.savot.model.SavotCoosys; |
| 38 |
|
| 39 |
import cds.savot.model.SavotData; |
| 40 |
import cds.savot.model.SavotDefinitions; |
| 41 |
import cds.savot.model.SavotInfo; |
| 42 |
import cds.savot.model.SavotLink; |
| 43 |
import cds.savot.model.SavotOption; |
| 44 |
import cds.savot.model.SavotValues; |
| 45 |
import cds.table.TableModel; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
@SuppressWarnings({"deprecation", "UseOfSystemOutOrSystemErr"}) |
| 53 |
public class AstroresSAXEngine { |
| 54 |
|
| 55 |
|
| 56 |
private static String ASTRO = "ASTRO"; |
| 57 |
private static String TABLE = "TABLE"; |
| 58 |
private static String FIELD = "FIELD"; |
| 59 |
private static String TABLEDATA = "TABLEDATA"; |
| 60 |
private static String DESCRIPTION = "DESCRIPTION"; |
| 61 |
private static String DATA = "DATA"; |
| 62 |
private static String RESOURCE = "RESOURCE"; |
| 63 |
private static String DEFINITIONS = "DEFINITIONS"; |
| 64 |
private static String LINK = "LINK"; |
| 65 |
private static String INFO = "INFO"; |
| 66 |
private static String ROW = "ROW"; |
| 67 |
private static String CELL = "CELL"; |
| 68 |
private static String COOSYS = "COOSYS"; |
| 69 |
private static String SYSTEM = "SYSTEM"; |
| 70 |
private static String OPTION = "OPTION"; |
| 71 |
private static String VALUES = "VALUES"; |
| 72 |
private static String CSV = "CSV"; |
| 73 |
|
| 74 |
|
| 75 |
private static String ARRAYSIZE = "arraysize"; |
| 76 |
private static String DATATYPE = "datatype"; |
| 77 |
private static String EPOCH = "epoch"; |
| 78 |
private static String EQUINOX = "equinox"; |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
private static String PRECISION = "precision"; |
| 83 |
private static String REF = "ref"; |
| 84 |
private static String TYPE = "type"; |
| 85 |
private static String UTYPE = "utype"; |
| 86 |
|
| 87 |
private static String UCD = "ucd"; |
| 88 |
private static String UNIT = "unit"; |
| 89 |
private static String VALUE = "value"; |
| 90 |
private static String WIDTH = "width"; |
| 91 |
private static String ID = "ID"; |
| 92 |
private static String CONTENTROLE = "content-role"; |
| 93 |
private static String CONTENTTYPE = "content-type"; |
| 94 |
private static String HREF = "href"; |
| 95 |
private static String GREF = "gref"; |
| 96 |
private static String ACTION = "action"; |
| 97 |
|
| 98 |
private static String INVALID = "invalid"; |
| 99 |
|
| 100 |
|
| 101 |
private static String NAME = "NAME"; |
| 102 |
private static String TITLE = "TITLE"; |
| 103 |
private static String NULL = "NULL"; |
| 104 |
|
| 105 |
|
| 106 |
private ArrayList<TableModel> allTables = new ArrayList<TableModel>(); |
| 107 |
|
| 108 |
private boolean trace = false; |
| 109 |
|
| 110 |
TableModel tb = new TableModel(); |
| 111 |
|
| 112 |
|
| 113 |
protected XmlPullParser parser = null; |
| 114 |
|
| 115 |
|
| 116 |
protected AstroresSAXConsumer consumer; |
| 117 |
|
| 118 |
|
| 119 |
@SuppressWarnings("unused") |
| 120 |
private int resourceCounter; |
| 121 |
@SuppressWarnings("unused") |
| 122 |
private int tableCounter; |
| 123 |
@SuppressWarnings("unused") |
| 124 |
private int dataCounter; |
| 125 |
@SuppressWarnings("unused") |
| 126 |
private int rowCounter; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
public AstroresSAXEngine(AstroresSAXConsumer consumer, |
| 136 |
XmlPullParser parser, String file, boolean debug) { |
| 137 |
|
| 138 |
try { |
| 139 |
this.parser = parser; |
| 140 |
this.consumer = consumer; |
| 141 |
|
| 142 |
|
| 143 |
FileInputStream inStream = new FileInputStream(new File(file)); |
| 144 |
BufferedInputStream dataBuffInStream = new BufferedInputStream(inStream); |
| 145 |
|
| 146 |
parser.setInput(dataBuffInStream, "UTF-8"); |
| 147 |
|
| 148 |
parse(parser); |
| 149 |
|
| 150 |
} catch (IOException e) { |
| 151 |
System.err.println("AstroresSAXEngine : " + e); |
| 152 |
} catch (Exception f) { |
| 153 |
System.err.println("AstroresSAXEngine : " + f); |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
public AstroresSAXEngine(AstroresSAXConsumer consumer, |
| 167 |
XmlPullParser parser, URL url, String enc, boolean debug) { |
| 168 |
|
| 169 |
try { |
| 170 |
this.parser = parser; |
| 171 |
this.consumer = consumer; |
| 172 |
|
| 173 |
|
| 174 |
parser.setInput(new DataInputStream(url.openStream()), enc); |
| 175 |
|
| 176 |
parse(parser); |
| 177 |
|
| 178 |
} catch (IOException e) { |
| 179 |
System.err.println("AstroresSAXEngine : " + e); |
| 180 |
} catch (Exception f) { |
| 181 |
System.err.println("AstroresSAXEngine : " + f); |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
public AstroresSAXEngine(AstroresSAXConsumer consumer, |
| 195 |
XmlPullParser parser, InputStream instream, String enc, |
| 196 |
boolean debug) { |
| 197 |
try { |
| 198 |
this.parser = parser; |
| 199 |
this.consumer = consumer; |
| 200 |
|
| 201 |
|
| 202 |
BufferedInputStream dataBuffInStream = new BufferedInputStream(instream); |
| 203 |
|
| 204 |
|
| 205 |
parser.setInput(dataBuffInStream, enc); |
| 206 |
|
| 207 |
parse(parser); |
| 208 |
|
| 209 |
} catch (IOException e) { |
| 210 |
System.err.println("AstroresSAXEngine : " + e); |
| 211 |
} catch (Exception f) { |
| 212 |
System.err.println("AstroresSAXEngine : " + f); |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
@SuppressWarnings("unchecked") |
| 222 |
private void CSVCut(String buffer) { |
| 223 |
|
| 224 |
int begin = 0; |
| 225 |
int linecount = 0; |
| 226 |
int headlines = 3; |
| 227 |
char colsep = 9; |
| 228 |
char recsep = 10; |
| 229 |
|
| 230 |
if (trace) { |
| 231 |
System.err.println("Entree CSVCut"); |
| 232 |
} |
| 233 |
|
| 234 |
for (int i = 0; i < buffer.length(); i++) { |
| 235 |
|
| 236 |
if (buffer.charAt(i) == recsep) { |
| 237 |
linecount++; |
| 238 |
|
| 239 |
@SuppressWarnings("rawtypes") |
| 240 |
ArrayList row = new ArrayList(); |
| 241 |
|
| 242 |
if (linecount < headlines) { |
| 243 |
System.err.println("L" + linecount + " ---> " + buffer.substring(begin, i)); |
| 244 |
} |
| 245 |
int begin2 = begin; |
| 246 |
for (int j = begin; j <= i; j++) { |
| 247 |
|
| 248 |
if (buffer.charAt(j) == colsep || buffer.charAt(j) == recsep) { |
| 249 |
if (linecount < headlines) { |
| 250 |
System.err.println("colsep-->"); |
| 251 |
System.err.println("---> " |
| 252 |
+ buffer.substring(begin2, j)); |
| 253 |
} else { |
| 254 |
|
| 255 |
row.add(buffer.substring(begin2, j)); |
| 256 |
} |
| 257 |
begin2 = j + 1; |
| 258 |
} |
| 259 |
} |
| 260 |
begin = i + 1; |
| 261 |
tb.addRow(row); |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
} |
| 273 |
System.err.println("row count : " + tb.getRowCount()); |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
} |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
| 290 |
public void parse(XmlPullParser parser) throws IOException { |
| 291 |
|
| 292 |
String name = ""; |
| 293 |
ArrayList father = new ArrayList(); |
| 294 |
String currentMarkup = "XML"; |
| 295 |
|
| 296 |
ArrayList currentRow = new ArrayList(); |
| 297 |
StringBuffer description = new StringBuffer(); |
| 298 |
@SuppressWarnings("unused") |
| 299 |
String id = null; |
| 300 |
@SuppressWarnings("unused") |
| 301 |
String type = null; |
| 302 |
|
| 303 |
ArrayList fieldPropertyNames = new ArrayList(); |
| 304 |
ArrayList fieldPropertyValues = new ArrayList(); |
| 305 |
|
| 306 |
@SuppressWarnings("unused") |
| 307 |
SavotData currentData = new SavotData(); |
| 308 |
SavotValues currentValues = new SavotValues(); |
| 309 |
|
| 310 |
String currentDescription = ""; |
| 311 |
SavotLink currentLink = new SavotLink(); |
| 312 |
SavotInfo currentInfo = new SavotInfo(); |
| 313 |
SavotOption currentOption = new SavotOption(); |
| 314 |
SavotCoosys currentCoosys = new SavotCoosys(); |
| 315 |
SavotDefinitions currentDefinitions = new SavotDefinitions(); |
| 316 |
|
| 317 |
try { |
| 318 |
|
| 319 |
|
| 320 |
int eventType = parser.getEventType(); |
| 321 |
int previousDepth = 0; |
| 322 |
|
| 323 |
|
| 324 |
while (eventType != XmlPullParser.END_DOCUMENT) { |
| 325 |
|
| 326 |
switch (eventType) { |
| 327 |
|
| 328 |
case KXmlParser.START_TAG: |
| 329 |
try { |
| 330 |
|
| 331 |
name = parser.getName(); |
| 332 |
|
| 333 |
if (trace) { |
| 334 |
System.err.println("Name ---> " + parser.getName()); |
| 335 |
} |
| 336 |
|
| 337 |
if (name != null) { |
| 338 |
|
| 339 |
|
| 340 |
if (name.equalsIgnoreCase(ASTRO)) { |
| 341 |
if (trace) { |
| 342 |
System.err.println("VOTABLE begin"); |
| 343 |
} |
| 344 |
currentMarkup = ASTRO; |
| 345 |
} else |
| 346 |
if (name.equalsIgnoreCase(DESCRIPTION)) { |
| 347 |
currentMarkup = DESCRIPTION; |
| 348 |
if (trace) { |
| 349 |
System.err.println("DESCRIPTION begin"); |
| 350 |
} |
| 351 |
} |
| 352 |
else if (name.equalsIgnoreCase(RESOURCE)) { |
| 353 |
|
| 354 |
if (trace) { |
| 355 |
System.err.println("RESOURCE begin"); |
| 356 |
} |
| 357 |
currentMarkup = RESOURCE; |
| 358 |
|
| 359 |
|
| 360 |
resourceCounter++; |
| 361 |
|
| 362 |
|
| 363 |
id = ""; |
| 364 |
type = ""; |
| 365 |
|
| 366 |
if (parser.getAttributeCount() != 0) { |
| 367 |
if (parser.getAttributeValue(null, TYPE) != null) { |
| 368 |
type = parser.getAttributeValue(null, TYPE); |
| 369 |
} |
| 370 |
if (parser.getAttributeValue(null, ID) != null) { |
| 371 |
id = parser.getAttributeValue(null, ID); |
| 372 |
} |
| 373 |
} |
| 374 |
} |
| 375 |
else if (name.equalsIgnoreCase(TABLE)) { |
| 376 |
tb = new TableModel(); |
| 377 |
currentMarkup = TABLE; |
| 378 |
|
| 379 |
|
| 380 |
tableCounter++; |
| 381 |
|
| 382 |
if (parser.getAttributeCount() != 0 && parser.getAttributeValue(null, ID) != null) { |
| 383 |
tb.setId(parser.getAttributeValue(null, ID)); |
| 384 |
} |
| 385 |
} |
| 386 |
else if (name.equalsIgnoreCase(FIELD)) { |
| 387 |
fieldPropertyNames = new ArrayList(); |
| 388 |
fieldPropertyValues = new ArrayList(); |
| 389 |
currentMarkup = FIELD; |
| 390 |
if (parser.getAttributeCount() != 0) { |
| 391 |
if (parser.getAttributeValue(null, UNIT) != null) { |
| 392 |
fieldPropertyNames.add(UNIT); |
| 393 |
fieldPropertyValues.add(parser.getAttributeValue(null, UNIT)); |
| 394 |
} |
| 395 |
if (parser.getAttributeValue(null, DATATYPE) != null) { |
| 396 |
fieldPropertyNames.add(DATATYPE); |
| 397 |
fieldPropertyValues.add(parser.getAttributeValue(null, DATATYPE)); |
| 398 |
} |
| 399 |
if (parser.getAttributeValue(null, PRECISION) != null) { |
| 400 |
fieldPropertyNames.add(PRECISION); |
| 401 |
fieldPropertyValues.add(parser.getAttributeValue(null, PRECISION)); |
| 402 |
} |
| 403 |
if (parser.getAttributeValue(null, WIDTH) != null) { |
| 404 |
fieldPropertyNames.add(WIDTH); |
| 405 |
fieldPropertyValues.add(parser.getAttributeValue(null, WIDTH)); |
| 406 |
} |
| 407 |
if (parser.getAttributeValue(null, REF) != null) { |
| 408 |
fieldPropertyNames.add(REF); |
| 409 |
fieldPropertyValues.add(parser.getAttributeValue(null, REF)); |
| 410 |
} |
| 411 |
if (parser.getAttributeValue(null, NAME) != null) { |
| 412 |
fieldPropertyNames.add(NAME); |
| 413 |
fieldPropertyValues.add(parser.getAttributeValue(null, NAME)); |
| 414 |
} |
| 415 |
if (parser.getAttributeValue(null, UCD) != null) { |
| 416 |
fieldPropertyNames.add(UCD); |
| 417 |
fieldPropertyValues.add(parser.getAttributeValue(null, UCD)); |
| 418 |
} |
| 419 |
if (parser.getAttributeValue(null, ARRAYSIZE) != null) { |
| 420 |
fieldPropertyNames.add(ARRAYSIZE); |
| 421 |
fieldPropertyValues.add(parser.getAttributeValue(null, ARRAYSIZE)); |
| 422 |
} |
| 423 |
if (parser.getAttributeValue(null, TYPE) != null) { |
| 424 |
fieldPropertyNames.add(TYPE); |
| 425 |
fieldPropertyValues.add(parser.getAttributeValue(null, TYPE)); |
| 426 |
} |
| 427 |
if (parser.getAttributeValue(null, UTYPE) != null) { |
| 428 |
fieldPropertyNames.add(UTYPE); |
| 429 |
fieldPropertyValues.add(parser.getAttributeValue(null, UTYPE)); |
| 430 |
} |
| 431 |
if (parser.getAttributeValue(null, ID) != null) { |
| 432 |
fieldPropertyNames.add(ID); |
| 433 |
fieldPropertyValues.add(parser.getAttributeValue(null, ID)); |
| 434 |
} |
| 435 |
} |
| 436 |
} |
| 437 |
else if (name.equalsIgnoreCase(VALUES)) { |
| 438 |
currentValues = new SavotValues(); |
| 439 |
currentMarkup = VALUES; |
| 440 |
if (parser.getAttributeCount() != 0) { |
| 441 |
if (parser.getAttributeValue(null, TYPE) != null) { |
| 442 |
currentValues.setType(parser.getAttributeValue(null, TYPE)); |
| 443 |
} |
| 444 |
if (parser.getAttributeValue(null, NULL) != null) { |
| 445 |
currentValues.setNull(parser.getAttributeValue(null, NULL)); |
| 446 |
} |
| 447 |
if (parser.getAttributeValue(null, INVALID) != null) |
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
{ |
| 453 |
currentValues.setInvalid(parser.getAttributeValue(null, INVALID)); |
| 454 |
} |
| 455 |
if (parser.getAttributeValue(null, REF) != null) |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
{ |
| 461 |
currentValues.setRef(parser.getAttributeValue(null, REF)); |
| 462 |
} |
| 463 |
if (parser.getAttributeValue(null, ID) != null) { |
| 464 |
currentValues.setId(parser.getAttributeValue(null, ID)); |
| 465 |
} |
| 466 |
} |
| 467 |
} |
| 468 |
else if (name.equalsIgnoreCase(ROW)) { |
| 469 |
if (trace) { |
| 470 |
System.err.println("ROW begin"); |
| 471 |
} |
| 472 |
currentMarkup = ROW; |
| 473 |
|
| 474 |
|
| 475 |
currentRow = new ArrayList(); |
| 476 |
} |
| 477 |
else if (name.equalsIgnoreCase(CELL)) { |
| 478 |
if (trace) { |
| 479 |
System.err.println("CELL begin"); |
| 480 |
} |
| 481 |
currentMarkup = CELL; |
| 482 |
|
| 483 |
|
| 484 |
dataCounter++; |
| 485 |
} |
| 486 |
else if (name.equalsIgnoreCase(DATA)) { |
| 487 |
currentData = new SavotData(); |
| 488 |
currentMarkup = DATA; |
| 489 |
} |
| 490 |
else if (name.equalsIgnoreCase(TABLEDATA)) { |
| 491 |
|
| 492 |
currentMarkup = TABLEDATA; |
| 493 |
} |
| 494 |
else if (name.equalsIgnoreCase(LINK)) { |
| 495 |
currentLink = new SavotLink(); |
| 496 |
currentMarkup = LINK; |
| 497 |
|
| 498 |
if (parser.getAttributeCount() != 0) { |
| 499 |
if (parser.getAttributeValue(null, CONTENTROLE) != null) { |
| 500 |
currentLink.setContentRole(parser.getAttributeValue(null, CONTENTROLE)); |
| 501 |
} |
| 502 |
if (parser.getAttributeValue(null, CONTENTTYPE) != null) { |
| 503 |
currentLink.setContentType(parser.getAttributeValue(null, CONTENTTYPE)); |
| 504 |
} |
| 505 |
if (parser.getAttributeValue(null, TITLE) != null) { |
| 506 |
currentLink.setTitle(parser.getAttributeValue(null, TITLE)); |
| 507 |
} |
| 508 |
if (parser.getAttributeValue(null, VALUE) != null) { |
| 509 |
currentLink.setValue(parser.getAttributeValue(null, VALUE)); |
| 510 |
} |
| 511 |
if (parser.getAttributeValue(null, HREF) != null) { |
| 512 |
currentLink.setHref(parser.getAttributeValue(null, HREF)); |
| 513 |
} |
| 514 |
if (parser.getAttributeValue(null, GREF) != null) { |
| 515 |
currentLink.setGref(parser.getAttributeValue(null, GREF)); |
| 516 |
} |
| 517 |
if (parser.getAttributeValue(null, ACTION) != null) { |
| 518 |
currentLink.setAction(parser.getAttributeValue(null, ACTION)); |
| 519 |
} |
| 520 |
if (parser.getAttributeValue(null, ID) != null) { |
| 521 |
currentLink.setId(parser.getAttributeValue(null, ID)); |
| 522 |
} |
| 523 |
} |
| 524 |
if (trace) { |
| 525 |
System.err.println("LINK"); |
| 526 |
} |
| 527 |
} |
| 528 |
else if (name.equalsIgnoreCase(INFO)) { |
| 529 |
currentInfo = new SavotInfo(); |
| 530 |
currentMarkup = INFO; |
| 531 |
if (parser.getAttributeCount() != 0) { |
| 532 |
if (parser.getAttributeValue(null, NAME) != null) { |
| 533 |
currentInfo.setName(parser.getAttributeValue(null, NAME)); |
| 534 |
} |
| 535 |
if (parser.getAttributeValue(null, VALUE) != null) { |
| 536 |
currentInfo.setValue(parser.getAttributeValue(null, VALUE)); |
| 537 |
} |
| 538 |
if (parser.getAttributeValue(null, ID) != null) { |
| 539 |
currentInfo.setId(parser.getAttributeValue(null, ID)); |
| 540 |
} |
| 541 |
} |
| 542 |
if (trace) { |
| 543 |
System.err.println("INFO"); |
| 544 |
} |
| 545 |
} |
| 546 |
else if (name.equalsIgnoreCase(OPTION)) { |
| 547 |
currentMarkup = OPTION; |
| 548 |
if (trace) { |
| 549 |
System.err.println("OPTION"); |
| 550 |
} |
| 551 |
currentOption = new SavotOption(); |
| 552 |
if (parser.getAttributeCount() != 0) { |
| 553 |
if (parser.getAttributeValue(null, NAME) != null) { |
| 554 |
currentOption.setName(parser.getAttributeValue(null, NAME)); |
| 555 |
} |
| 556 |
if (parser.getAttributeValue(null, VALUE) != null) { |
| 557 |
currentOption.setValue(parser.getAttributeValue(null, VALUE)); |
| 558 |
} |
| 559 |
} |
| 560 |
} else if (name.equalsIgnoreCase(COOSYS)) { |
| 561 |
currentMarkup = COOSYS; |
| 562 |
if (trace) { |
| 563 |
System.err.println("COOSYS"); |
| 564 |
} |
| 565 |
currentCoosys = new SavotCoosys(); |
| 566 |
if (parser.getAttributeCount() != 0) { |
| 567 |
if (parser.getAttributeValue(null, EQUINOX) != null) { |
| 568 |
currentCoosys.setEquinox(parser.getAttributeValue(null, EQUINOX)); |
| 569 |
} |
| 570 |
if (parser.getAttributeValue(null, EPOCH) != null) { |
| 571 |
currentCoosys.setEpoch(parser.getAttributeValue(null, EPOCH)); |
| 572 |
} |
| 573 |
if (parser.getAttributeValue(null, SYSTEM) != null) { |
| 574 |
currentCoosys.setSystem(parser.getAttributeValue(null, SYSTEM)); |
| 575 |
} |
| 576 |
if (parser.getAttributeValue(null, ID) != null) { |
| 577 |
currentCoosys.setId(parser.getAttributeValue(null, ID)); |
| 578 |
} |
| 579 |
} |
| 580 |
} |
| 581 |
else if (name.equalsIgnoreCase(DEFINITIONS)) { |
| 582 |
currentMarkup = DEFINITIONS; |
| 583 |
currentDefinitions = new SavotDefinitions(); |
| 584 |
if (trace) { |
| 585 |
System.err.println("DEFINITIONS"); |
| 586 |
} |
| 587 |
} |
| 588 |
} |
| 589 |
currentMarkup = name; |
| 590 |
} catch (Exception e) { |
| 591 |
System.err.println("START_TAG : " + e); |
| 592 |
} |
| 593 |
break; |
| 594 |
|
| 595 |
|
| 596 |
case KXmlParser.END_TAG: |
| 597 |
name = parser.getName(); |
| 598 |
try { |
| 599 |
|
| 600 |
if (trace) { |
| 601 |
System.err.println("End ---> " + name); |
| 602 |
} |
| 603 |
|
| 604 |
|
| 605 |
if (name.equalsIgnoreCase(DESCRIPTION)) { |
| 606 |
if (((String) father.get(father.size() - 2)).equalsIgnoreCase(ASTRO)) { |
| 607 |
description.append(currentDescription); |
| 608 |
currentMarkup = ""; |
| 609 |
} else if (((String) father.get(father.size() - 2)).equalsIgnoreCase(RESOURCE)) { |
| 610 |
description.append(currentDescription); |
| 611 |
currentMarkup = ""; |
| 612 |
} else if (((String) father.get(father.size() - 2)).equalsIgnoreCase(TABLE)) { |
| 613 |
tb.setDescription(currentDescription); |
| 614 |
currentMarkup = ""; |
| 615 |
} else if (((String) father.get(father.size() - 2)).equalsIgnoreCase(FIELD)) { |
| 616 |
fieldPropertyNames.add(DESCRIPTION); |
| 617 |
fieldPropertyValues.add(currentDescription); |
| 618 |
currentMarkup = ""; |
| 619 |
} |
| 620 |
} |
| 621 |
else if (name.equalsIgnoreCase(TABLE)) { |
| 622 |
allTables.add(tb); |
| 623 |
currentMarkup = ""; |
| 624 |
|
| 625 |
if (trace) { |
| 626 |
System.err.println(tb.getName()); |
| 627 |
} |
| 628 |
} |
| 629 |
else if (name.equalsIgnoreCase(FIELD)) { |
| 630 |
if (((String) father.get(father.size() - 2)).equalsIgnoreCase(TABLE)) { |
| 631 |
tb.setTableProperties(fieldPropertyNames, fieldPropertyValues); |
| 632 |
if (trace) { |
| 633 |
System.err.println("FIELD from TABLE father = " + father); |
| 634 |
} |
| 635 |
} |
| 636 |
} |
| 637 |
else if (name.equalsIgnoreCase(ROW)) { |
| 638 |
if (trace) { |
| 639 |
System.err.println("TR end"); |
| 640 |
} |
| 641 |
currentMarkup = ""; |
| 642 |
|
| 643 |
|
| 644 |
tb.addRow((String[]) currentRow.toArray()); |
| 645 |
|
| 646 |
|
| 647 |
rowCounter++; |
| 648 |
|
| 649 |
if (trace) { |
| 650 |
System.err.println("ADD row"); |
| 651 |
} |
| 652 |
|
| 653 |
} |
| 654 |
else if (name.equalsIgnoreCase(DATA)) { |
| 655 |
currentMarkup = ""; |
| 656 |
|
| 657 |
} |
| 658 |
else if (name.equalsIgnoreCase(CELL)) { |
| 659 |
currentMarkup = ""; |
| 660 |
if (trace) { |
| 661 |
System.err.println("CELL end"); |
| 662 |
} |
| 663 |
} |
| 664 |
else if (name.equalsIgnoreCase(RESOURCE)) { |
| 665 |
if (trace) { |
| 666 |
System.err.println("RESOURCE end"); |
| 667 |
} |
| 668 |
currentMarkup = ""; |
| 669 |
} |
| 670 |
else if (name.equalsIgnoreCase(OPTION)) { |
| 671 |
if (trace) { |
| 672 |
System.err.println("OPTION end"); |
| 673 |
} |
| 674 |
currentMarkup = ""; |
| 675 |
} |
| 676 |
else if (name.equalsIgnoreCase(TABLEDATA)) { |
| 677 |
currentMarkup = ""; |
| 678 |
|
| 679 |
if (trace) { |
| 680 |
System.err.println(tb.getName()); |
| 681 |
} |
| 682 |
} |
| 683 |
else if (name.equalsIgnoreCase(COOSYS)) { |
| 684 |
currentMarkup = ""; |
| 685 |
|
| 686 |
if (((String) father.get(father.size() - 2)).equalsIgnoreCase(DEFINITIONS)) { |
| 687 |
currentDefinitions.getCoosys().addItem(currentCoosys); |
| 688 |
if (trace) { |
| 689 |
System.err.println("COOSYS from DEFINITIONS father = " + father); |
| 690 |
} |
| 691 |
} else if (((String) father.get(father.size() - 2)).equalsIgnoreCase(RESOURCE)) { |
| 692 |
|
| 693 |
if (trace) { |
| 694 |
System.err.println("COOSYS from RESOURCE father = " + father); |
| 695 |
} |
| 696 |
} |
| 697 |
} |
| 698 |
else if (name.equalsIgnoreCase(LINK)) { |
| 699 |
currentMarkup = ""; |
| 700 |
|
| 701 |
if (((String) father.get(father.size() - 2)).equalsIgnoreCase(RESOURCE)) { |
| 702 |
|
| 703 |
if (trace) { |
| 704 |
System.err.println("LINK from RESOURCE father = " + father); |
| 705 |
} |
| 706 |
} else if (((String) father.get(father.size() - 2)).equalsIgnoreCase(TABLE)) { |
| 707 |
|
| 708 |
if (trace) { |
| 709 |
System.err.println("LINK from TABLE father = " + father); |
| 710 |
} |
| 711 |
} else if (((String) father.get(father.size() - 2)).equalsIgnoreCase(FIELD)) { |
| 712 |
|
| 713 |
if (trace) { |
| 714 |
System.err.println("LINK from FIELD father = " + father); |
| 715 |
} |
| 716 |
} |
| 717 |
} |
| 718 |
else if (name.equalsIgnoreCase(VALUES)) { |
| 719 |
currentMarkup = ""; |
| 720 |
|
| 721 |
if (((String) father.get(father.size() - 2)).equalsIgnoreCase(FIELD)) { |
| 722 |
|
| 723 |
if (trace) { |
| 724 |
System.err.println("VALUES from FIELD father = " + father + " ID : " + currentValues.getId()); |
| 725 |
} |
| 726 |
} |
| 727 |
} |
| 728 |
else if (name.equalsIgnoreCase(INFO)) { |
| 729 |
currentMarkup = ""; |
| 730 |
if (trace) { |
| 731 |
System.err.println("INFO father = " + father); |
| 732 |
} |
| 733 |
|
| 734 |
if (((String) father.get(father.size() - 2)).equalsIgnoreCase(ASTRO)) { |
| 735 |
if (trace) { |
| 736 |
System.err.println("INFO from VOTABLE father = " + father); |
| 737 |
} |
| 738 |
} else if (((String) father.get(father.size() - 2)).equalsIgnoreCase(RESOURCE)) { |
| 739 |
if (trace) { |
| 740 |
System.err.println("INFO from RESOURCE father = " + father); |
| 741 |
} |
| 742 |
} |
| 743 |
} |
| 744 |
else if (name.equalsIgnoreCase(DEFINITIONS)) { |
| 745 |
currentMarkup = ""; |
| 746 |
if (trace) { |
| 747 |
System.err.println("DEFINITIONS"); |
| 748 |
} |
| 749 |
|
| 750 |
} |
| 751 |
} catch (Exception e) { |
| 752 |
System.err.println("FATHER : " + father + " END_TAG (" |
| 753 |
+ name + ") : " + e); |
| 754 |
} |
| 755 |
break; |
| 756 |
|
| 757 |
case KXmlParser.END_DOCUMENT: |
| 758 |
try { |
| 759 |
if (trace) { |
| 760 |
System.err.println("Document end reached!"); |
| 761 |
} |
| 762 |
} catch (Exception e) { |
| 763 |
System.err.println("END_DOCUMENT : " + e); |
| 764 |
} |
| 765 |
break; |
| 766 |
|
| 767 |
case KXmlParser.TEXT: |
| 768 |
try { |
| 769 |
if (currentMarkup.equalsIgnoreCase(CSV)) { |
| 770 |
|
| 771 |
CSVCut((parser.getText()).trim()); |
| 772 |
if (trace) { |
| 773 |
System.err.println((parser.getText()).trim()); |
| 774 |
} |
| 775 |
|
| 776 |
|
| 777 |
} else |
| 778 |
if (currentMarkup.equalsIgnoreCase(CELL)) { |
| 779 |
if (trace) { |
| 780 |
System.err.println("CELL : " + (parser.getText()).trim()); |
| 781 |
} |
| 782 |
currentRow.add(parser.getText()); |
| 783 |
} else if (currentMarkup.equalsIgnoreCase(DESCRIPTION)) { |
| 784 |
if (trace) { |
| 785 |
System.err.println("DESCRIPTION : " + (parser.getText()).trim()); |
| 786 |
} |
| 787 |
currentDescription = (parser.getText()).trim(); |
| 788 |
} else if (currentMarkup.equalsIgnoreCase(COOSYS)) { |
| 789 |
if (trace) { |
| 790 |
System.err.println("COOSYS : " + (parser.getText()).trim()); |
| 791 |
} |
| 792 |
currentCoosys.setContent((parser.getText()).trim()); |
| 793 |
} else if (currentMarkup.equalsIgnoreCase(LINK)) { |
| 794 |
if (trace) { |
| 795 |
System.err.println("LINK : " + (parser.getText()).trim()); |
| 796 |
} |
| 797 |
currentLink.setContent((parser.getText()).trim()); |
| 798 |
} else if (currentMarkup.equalsIgnoreCase(OPTION)) { |
| 799 |
if (trace) { |
| 800 |
System.err.println("OPTION : " + (parser.getText()).trim()); |
| 801 |
} |
| 802 |
} else if (currentMarkup.equalsIgnoreCase(INFO)) { |
| 803 |
currentInfo.setContent((parser.getText()).trim()); |
| 804 |
if (trace) { |
| 805 |
System.err.println("INFO : " + (parser.getText()).trim()); |
| 806 |
} |
| 807 |
} |
| 808 |
} catch (Exception e) { |
| 809 |
System.err.println("TEXT : " + e); |
| 810 |
} |
| 811 |
break; |
| 812 |
|
| 813 |
case KXmlParser.START_DOCUMENT: |
| 814 |
break; |
| 815 |
|
| 816 |
default: |
| 817 |
if (trace) { |
| 818 |
System.err.println(" ignoring some other (legacy) event at line : " + parser.getLineNumber()); |
| 819 |
} |
| 820 |
} |
| 821 |
|
| 822 |
|
| 823 |
previousDepth = parser.getDepth(); |
| 824 |
|
| 825 |
|
| 826 |
eventType = parser.next(); |
| 827 |
if (parser.getDepth() > previousDepth) { |
| 828 |
father.add((parser.getName())); |
| 829 |
} else if (parser.getDepth() == previousDepth) { |
| 830 |
if (((String) father.get(father.size() - 1)).equals((parser.getName()))) { |
| 831 |
father.remove(father.size() - 1); |
| 832 |
father.add((parser.getName())); |
| 833 |
} |
| 834 |
} else { |
| 835 |
father.remove(father.size() - 1); |
| 836 |
} |
| 837 |
if (trace) { |
| 838 |
System.err.println("father = " + father); |
| 839 |
} |
| 840 |
} |
| 841 |
|
| 842 |
} catch (Exception f) { |
| 843 |
if (trace) { |
| 844 |
System.err.println("parse : " + f); |
| 845 |
} |
| 846 |
} |
| 847 |
} |
| 848 |
} |