| 1 |
package cds.savot.writer; |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
import cds.savot.model.CoosysSet; |
| 25 |
import cds.savot.model.FieldRefSet; |
| 26 |
import cds.savot.model.FieldSet; |
| 27 |
import cds.savot.model.GroupSet; |
| 28 |
import cds.savot.model.InfoSet; |
| 29 |
import cds.savot.model.LinkSet; |
| 30 |
import cds.savot.model.OptionSet; |
| 31 |
import cds.savot.model.ParamRefSet; |
| 32 |
import cds.savot.model.ParamSet; |
| 33 |
import cds.savot.model.ResourceSet; |
| 34 |
import cds.savot.model.SavotBinary; |
| 35 |
import cds.savot.model.SavotCoosys; |
| 36 |
import cds.savot.model.SavotData; |
| 37 |
import cds.savot.model.SavotField; |
| 38 |
import cds.savot.model.SavotFieldRef; |
| 39 |
import cds.savot.model.SavotFits; |
| 40 |
import cds.savot.model.SavotGroup; |
| 41 |
import cds.savot.model.SavotInfo; |
| 42 |
import cds.savot.model.SavotLink; |
| 43 |
import cds.savot.model.SavotMax; |
| 44 |
import cds.savot.model.SavotMin; |
| 45 |
import cds.savot.model.SavotOption; |
| 46 |
import cds.savot.model.SavotParam; |
| 47 |
import cds.savot.model.SavotParamRef; |
| 48 |
import cds.savot.model.SavotResource; |
| 49 |
import cds.savot.model.SavotStream; |
| 50 |
import cds.savot.model.SavotTD; |
| 51 |
import cds.savot.model.SavotTR; |
| 52 |
import cds.savot.model.SavotTable; |
| 53 |
import cds.savot.model.SavotTableData; |
| 54 |
import cds.savot.model.SavotVOTable; |
| 55 |
import cds.savot.model.SavotValues; |
| 56 |
import cds.savot.model.TRSet; |
| 57 |
import cds.savot.model.TableSet; |
| 58 |
import java.io.BufferedOutputStream; |
| 59 |
import java.io.BufferedWriter; |
| 60 |
import java.io.FileOutputStream; |
| 61 |
import java.io.IOException; |
| 62 |
import java.io.OutputStream; |
| 63 |
import java.io.OutputStreamWriter; |
| 64 |
import java.io.PrintWriter; |
| 65 |
import java.io.Writer; |
| 66 |
import java.util.List; |
| 67 |
import java.util.regex.Pattern; |
| 68 |
import java.util.zip.GZIPOutputStream; |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
@SuppressWarnings({"deprecation", "UseOfSystemOutOrSystemErr"}) |
| 83 |
public final class SavotWriter { |
| 84 |
|
| 85 |
private static final String tdempty = "<TD/>"; |
| 86 |
private static final String tdbegin = "<TD>"; |
| 87 |
private static final String tdend = "</TD>"; |
| 88 |
private static final String trbegin = "<TR>"; |
| 89 |
private static final String trend = "</TR>\n"; |
| 90 |
private static final String tabledatabegin = "\n<TABLEDATA>\n"; |
| 91 |
private static final String tabledataend = "</TABLEDATA>"; |
| 92 |
private static final String databegin = "\n<DATA>"; |
| 93 |
private static final String dataend = "\n</DATA>"; |
| 94 |
private static final String tableend = "\n</TABLE>"; |
| 95 |
private static final String resourceend = "\n</RESOURCE>"; |
| 96 |
private static final String descriptionbegin = "\n<DESCRIPTION>"; |
| 97 |
private static final String descriptionend = "</DESCRIPTION>"; |
| 98 |
private static final String groupend = "\n</GROUP>"; |
| 99 |
private static final String definitionsbegin = "\n<DEFINITIONS>"; |
| 100 |
private static final String definitionsend = "\n</DEFINITIONS>"; |
| 101 |
private static final String paramend = "\n</PARAM>"; |
| 102 |
private static final String fieldend = "\n</FIELD>"; |
| 103 |
private static final String linkend = "</LINK>"; |
| 104 |
private static final String valuesend = "\n</VALUES>"; |
| 105 |
private static final String fitsend = "\n</FITS>"; |
| 106 |
private static final String binarybegin = "\n<BINARY>"; |
| 107 |
private static final String binaryend = "\n</BINARY>"; |
| 108 |
private static final String coosysend = "</COOSYS>"; |
| 109 |
private static final String streamend = "\n</STREAM>"; |
| 110 |
private static final String minend = "</MIN>"; |
| 111 |
private static final String maxend = "</MAX>"; |
| 112 |
private static final String optionend = "\n</OPTION>"; |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
private String top1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; |
| 117 |
private String styleSheet = ""; |
| 118 |
private boolean attributeEntities = true; |
| 119 |
private boolean elementEntities = true; |
| 120 |
|
| 121 |
private Writer bw = null; |
| 122 |
|
| 123 |
private final Pattern patternAMP = Pattern.compile("&"); |
| 124 |
private final Pattern patternQUOT = Pattern.compile("\""); |
| 125 |
private final Pattern patternLT = Pattern.compile("<"); |
| 126 |
private final Pattern patternGT = Pattern.compile(">"); |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
public SavotWriter() { |
| 132 |
|
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
public void setTop1(final String top1) { |
| 144 |
this.top1 = top1; |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
public void setStyleSheet(final String href) { |
| 155 |
this.styleSheet = href; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
public void enableAttributeEntities(final boolean entities) { |
| 165 |
this.attributeEntities = entities; |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
public void enableElementEntities(final boolean entities) { |
| 175 |
this.elementEntities = entities; |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
public void enableEntities(final boolean entities) { |
| 185 |
this.attributeEntities = entities; |
| 186 |
this.elementEntities = entities; |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
public String encodeAttribute(final String src) { |
| 195 |
if (attributeEntities) { |
| 196 |
String out = patternAMP.matcher(src).replaceAll("&"); |
| 197 |
out = patternLT.matcher(out).replaceAll("<"); |
| 198 |
out = patternGT.matcher(out).replaceAll(">"); |
| 199 |
out = patternQUOT.matcher(out).replaceAll("""); |
| 200 |
return out; |
| 201 |
} |
| 202 |
return src; |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
public String encodeElement(final String src) { |
| 211 |
if (elementEntities) { |
| 212 |
String out = patternAMP.matcher(src).replaceAll("&"); |
| 213 |
out = patternLT.matcher(out).replaceAll("<"); |
| 214 |
out = patternGT.matcher(out).replaceAll(">"); |
| 215 |
return out; |
| 216 |
} |
| 217 |
return src; |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
public void generateDocument(final SavotVOTable votable) throws IOException { |
| 229 |
generateDocument(votable, null, null); |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
public void generateDocument(final SavotVOTable votable, final OutputStream stream) |
| 242 |
throws IOException { |
| 243 |
generateDocument(votable, null, stream); |
| 244 |
} |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
public void generateDocument(final SavotVOTable votable, final String file) |
| 256 |
throws IOException { |
| 257 |
generateDocument(votable, file, null); |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
public void generateDocument(final SavotVOTable votable, final String file, |
| 272 |
final OutputStream stream) throws IOException { |
| 273 |
|
| 274 |
if (file != null) { |
| 275 |
initStream(file); |
| 276 |
} else if (stream != null) { |
| 277 |
initStream(stream); |
| 278 |
} else { |
| 279 |
initStream(new PrintWriter(System.out)); |
| 280 |
} |
| 281 |
|
| 282 |
writeDocumentHead(votable); |
| 283 |
|
| 284 |
|
| 285 |
writeCoosys(votable.getCoosys()); |
| 286 |
|
| 287 |
|
| 288 |
writeInfo(votable.getInfos()); |
| 289 |
|
| 290 |
|
| 291 |
writeParam(votable.getParams()); |
| 292 |
|
| 293 |
|
| 294 |
writeGroup(votable.getGroups()); |
| 295 |
|
| 296 |
|
| 297 |
writeResource(votable.getResources()); |
| 298 |
|
| 299 |
|
| 300 |
writeInfo(votable.getInfosAtEnd()); |
| 301 |
|
| 302 |
writeDocumentEnd(); |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
public void initStream(final String file) throws IOException { |
| 313 |
final boolean compressed = file.endsWith("gz"); |
| 314 |
|
| 315 |
final OutputStream outStream = getOutputStream(new FileOutputStream(file), compressed); |
| 316 |
initStream(new OutputStreamWriter(outStream)); |
| 317 |
} |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
public void initStream(final OutputStream stream) throws IOException { |
| 327 |
final OutputStream outStream = getOutputStream(stream, false); |
| 328 |
initStream(new OutputStreamWriter(outStream)); |
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
public void initStream(final Writer writer) { |
| 337 |
bw = new BufferedWriter(writer, 64 * 1024); |
| 338 |
} |
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
private OutputStream getOutputStream(final OutputStream outstream, final boolean compressed) throws IOException { |
| 348 |
final int bufferSize = 64 * 1024; |
| 349 |
|
| 350 |
final OutputStream out; |
| 351 |
if (compressed) { |
| 352 |
out = new GZIPOutputStream(outstream, bufferSize); |
| 353 |
} else { |
| 354 |
out = new BufferedOutputStream(outstream, bufferSize); |
| 355 |
} |
| 356 |
|
| 357 |
return out; |
| 358 |
} |
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
public void writeComment(final String comment) throws IOException { |
| 368 |
if (comment.length() != 0) { |
| 369 |
bw.append("\n<!-- ").append(comment).append(" -->\n"); |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
public void writeDescription(final String description) throws IOException { |
| 381 |
if (description.length() != 0) { |
| 382 |
|
| 383 |
bw.append(descriptionbegin).append(encodeElement(description)).append(descriptionend); |
| 384 |
} |
| 385 |
} |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
public void writeDocumentHead(final SavotVOTable votable) throws IOException { |
| 394 |
final Writer w = bw; |
| 395 |
|
| 396 |
w.write(top1); |
| 397 |
|
| 398 |
writeComment(votable.getAbove()); |
| 399 |
|
| 400 |
|
| 401 |
if (styleSheet.length() != 0) { |
| 402 |
w.append("\n<?xml-stylesheet type=\"text/xsl\" href=\"").append(styleSheet).append("\" ?>"); |
| 403 |
} |
| 404 |
|
| 405 |
w.write("\n<VOTABLE"); |
| 406 |
if (votable.getXmlns().length() != 0 || votable.getXmlnsxsi().length() != 0 || votable.getXsischema().length() != 0 || votable.getXsinoschema().length() != 0) { |
| 407 |
if (votable.getXmlns().length() != 0) { |
| 408 |
w.append(" xmlns=\"").append(votable.getXmlns()).append('"'); |
| 409 |
} |
| 410 |
|
| 411 |
if (votable.getXmlnsxsi().length() != 0) { |
| 412 |
w.append(" xmlns:xsi=\"").append(votable.getXmlnsxsi()).append('"'); |
| 413 |
} |
| 414 |
|
| 415 |
if (votable.getXsischema().length() != 0) { |
| 416 |
w.append(" xsi:schemaLocation=\"").append(votable.getXsischema()).append('"'); |
| 417 |
} |
| 418 |
|
| 419 |
if (votable.getXsinoschema().length() != 0) { |
| 420 |
w.append(" xsi:noNamespaceSchemaLocation=\"").append(votable.getXsinoschema()).append('"'); |
| 421 |
} |
| 422 |
|
| 423 |
} |
| 424 |
w.write(" version="); |
| 425 |
|
| 426 |
if (votable.getVersion().length() != 0) { |
| 427 |
if (votable.getId().length() != 0) { |
| 428 |
w.append('"').append(votable.getVersion()).append('"').append(" ID=\"").append(votable.getId()).append('"').append('>'); |
| 429 |
} else { |
| 430 |
w.append('"').append(votable.getVersion()).append('"').append('>'); |
| 431 |
} |
| 432 |
} else { |
| 433 |
if (votable.getId().length() != 0) { |
| 434 |
w.append('"').append("1.2").append('"').append(" ID=\"").append(votable.getId()).append('"').append('>'); |
| 435 |
} else { |
| 436 |
w.append('"').append("1.2").append('"').append('>'); |
| 437 |
} |
| 438 |
} |
| 439 |
|
| 440 |
writeComment(votable.getBelow()); |
| 441 |
|
| 442 |
|
| 443 |
writeDescription(votable.getDescription()); |
| 444 |
|
| 445 |
|
| 446 |
if (votable.getDefinitions() != null) { |
| 447 |
|
| 448 |
w.write(definitionsbegin); |
| 449 |
|
| 450 |
|
| 451 |
writeCoosys(votable.getDefinitions().getCoosys()); |
| 452 |
|
| 453 |
|
| 454 |
writeParam(votable.getDefinitions().getParams()); |
| 455 |
|
| 456 |
|
| 457 |
w.write(definitionsend); |
| 458 |
} |
| 459 |
w.flush(); |
| 460 |
} |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
public void writeDocumentEnd() throws IOException { |
| 468 |
bw.write("\n</VOTABLE>\n"); |
| 469 |
bw.flush(); |
| 470 |
bw.close(); |
| 471 |
bw = null; |
| 472 |
} |
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
public void writeCoosys(final CoosysSet coosysSet) throws IOException { |
| 481 |
final Writer w = bw; |
| 482 |
|
| 483 |
SavotCoosys coosys; |
| 484 |
|
| 485 |
for (int i = 0, len = coosysSet.getItemCount(); i < len; i++) { |
| 486 |
coosys = coosysSet.getItemAt(i); |
| 487 |
|
| 488 |
writeComment(coosys.getAbove()); |
| 489 |
|
| 490 |
w.write("\n<COOSYS"); |
| 491 |
|
| 492 |
if (coosys.getId().length() != 0) { |
| 493 |
w.append(" ID=\"").append(coosys.getId()).append('"'); |
| 494 |
} |
| 495 |
|
| 496 |
if (coosys.getEquinox().length() != 0) { |
| 497 |
w.append(" equinox=\"").append(coosys.getEquinox()).append('"'); |
| 498 |
} |
| 499 |
|
| 500 |
if (coosys.getEpoch().length() != 0) { |
| 501 |
w.append(" epoch=\"").append(coosys.getEpoch()).append('"'); |
| 502 |
} |
| 503 |
|
| 504 |
if (coosys.getSystem().length() != 0) { |
| 505 |
w.append(" system=\"").append(coosys.getSystem()).append('"'); |
| 506 |
} |
| 507 |
|
| 508 |
if (coosys.getContent().length() != 0) { |
| 509 |
w.write(">"); |
| 510 |
|
| 511 |
writeComment(coosys.getBelow()); |
| 512 |
|
| 513 |
w.write(coosys.getContent()); |
| 514 |
|
| 515 |
w.write(coosysend); |
| 516 |
} else { |
| 517 |
|
| 518 |
w.write("/>"); |
| 519 |
|
| 520 |
writeComment(coosys.getBelow()); |
| 521 |
} |
| 522 |
} |
| 523 |
} |
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
public void writeParam(final ParamSet params) throws IOException { |
| 532 |
if (params != null) { |
| 533 |
final Writer w = bw; |
| 534 |
|
| 535 |
SavotParam param; |
| 536 |
|
| 537 |
for (int i = 0, len = params.getItemCount(); i < len; i++) { |
| 538 |
param = params.getItemAt(i); |
| 539 |
|
| 540 |
writeComment(param.getAbove()); |
| 541 |
|
| 542 |
w.write("\n<PARAM"); |
| 543 |
|
| 544 |
if (param.getName().length() != 0) { |
| 545 |
w.append(" name=\"").append(encodeAttribute(param.getName())).append('"'); |
| 546 |
} |
| 547 |
|
| 548 |
if (param.getId().length() != 0) { |
| 549 |
w.append(" ID=\"").append(encodeAttribute(param.getId())).append('"'); |
| 550 |
} |
| 551 |
|
| 552 |
if (param.getDataType().length() != 0) { |
| 553 |
w.append(" datatype=\"").append(encodeAttribute(param.getDataType())).append('"'); |
| 554 |
} |
| 555 |
|
| 556 |
if (param.getArraySize().length() != 0) { |
| 557 |
w.append(" arraysize=\"").append(encodeAttribute(param.getArraySize())).append('"'); |
| 558 |
} |
| 559 |
|
| 560 |
if (param.getPrecision().length() != 0) { |
| 561 |
w.append(" precision=\"").append(encodeAttribute(param.getPrecision())).append('"'); |
| 562 |
} |
| 563 |
|
| 564 |
if (param.getWidth().length() != 0) { |
| 565 |
w.append(" width=\"").append(encodeAttribute(param.getWidth())).append('"'); |
| 566 |
} |
| 567 |
|
| 568 |
|
| 569 |
if (param.getXtype().length() != 0) { |
| 570 |
w.append(" xtype=\"").append(encodeAttribute(param.getXtype())).append('"'); |
| 571 |
} |
| 572 |
|
| 573 |
if (param.getRef().length() != 0) { |
| 574 |
w.append(" ref=\"").append(encodeAttribute(param.getRef())).append('"'); |
| 575 |
} |
| 576 |
|
| 577 |
if (param.getUcd().length() != 0) { |
| 578 |
w.append(" ucd=\"").append(encodeAttribute(param.getUcd())).append('"'); |
| 579 |
} |
| 580 |
|
| 581 |
if (param.getUtype().length() != 0) { |
| 582 |
w.append(" utype=\"").append(encodeAttribute(param.getUtype())).append('"'); |
| 583 |
} |
| 584 |
|
| 585 |
|
| 586 |
w.append(" value=\"").append(encodeAttribute(param.getValue())).append('"'); |
| 587 |
|
| 588 |
if (param.getUnit().length() != 0) { |
| 589 |
w.append(" unit=\"").append(encodeAttribute(param.getUnit())).append('"'); |
| 590 |
} |
| 591 |
|
| 592 |
if (param.getValues() != null || param.getLinks().getItemCount() != 0 || param.getDescription().length() != 0) { |
| 593 |
w.write(">"); |
| 594 |
|
| 595 |
writeComment(param.getBelow()); |
| 596 |
|
| 597 |
|
| 598 |
writeDescription(param.getDescription()); |
| 599 |
|
| 600 |
|
| 601 |
writeValues(param.getValues()); |
| 602 |
|
| 603 |
|
| 604 |
writeLink(param.getLinks()); |
| 605 |
|
| 606 |
|
| 607 |
w.write(paramend); |
| 608 |
} else { |
| 609 |
w.write("/>"); |
| 610 |
|
| 611 |
writeComment(param.getBelow()); |
| 612 |
} |
| 613 |
} |
| 614 |
} |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
public void writeParamRef(final ParamRefSet refparams) throws IOException { |
| 624 |
if (refparams != null) { |
| 625 |
final Writer w = bw; |
| 626 |
|
| 627 |
SavotParamRef paramref; |
| 628 |
|
| 629 |
for (int i = 0, len = refparams.getItemCount(); i < len; i++) { |
| 630 |
paramref = refparams.getItemAt(i); |
| 631 |
|
| 632 |
writeComment(paramref.getAbove()); |
| 633 |
|
| 634 |
w.write("\n<PARAMref"); |
| 635 |
|
| 636 |
if (paramref.getRef().length() != 0) { |
| 637 |
w.append(" ref=\"").append(encodeAttribute(paramref.getRef())).append('"'); |
| 638 |
} |
| 639 |
|
| 640 |
if (paramref.getUcd().length() != 0) { |
| 641 |
w.append(" ucd=\"").append(encodeAttribute(paramref.getUcd())).append('"'); |
| 642 |
} |
| 643 |
|
| 644 |
if (paramref.getUtype().length() != 0) { |
| 645 |
w.append(" utype=\"").append(encodeAttribute(paramref.getUtype())).append('"'); |
| 646 |
} |
| 647 |
|
| 648 |
w.write("/>"); |
| 649 |
|
| 650 |
writeComment(paramref.getBelow()); |
| 651 |
} |
| 652 |
} |
| 653 |
} |
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
public void writeLink(final LinkSet linkSet) throws IOException { |
| 662 |
final Writer w = bw; |
| 663 |
|
| 664 |
SavotLink link; |
| 665 |
|
| 666 |
for (int i = 0, len = linkSet.getItemCount(); i < len; i++) { |
| 667 |
link = linkSet.getItemAt(i); |
| 668 |
|
| 669 |
writeComment(link.getAbove()); |
| 670 |
|
| 671 |
w.write("\n<LINK"); |
| 672 |
|
| 673 |
if (link.getId().length() != 0) { |
| 674 |
w.append(" ID=\"").append(encodeAttribute(link.getId())).append('"'); |
| 675 |
} |
| 676 |
|
| 677 |
if (link.getContentRole().length() != 0) { |
| 678 |
w.append(" content-role=\"").append(encodeAttribute(link.getContentRole())).append('"'); |
| 679 |
} |
| 680 |
|
| 681 |
if (link.getContentType().length() != 0) { |
| 682 |
w.append(" content-type=\"").append(encodeAttribute(link.getContentType())).append('"'); |
| 683 |
} |
| 684 |
|
| 685 |
if (link.getTitle().length() != 0) { |
| 686 |
w.append(" title=\"").append(encodeAttribute(link.getTitle())).append('"'); |
| 687 |
} |
| 688 |
|
| 689 |
if (link.getValue().length() != 0) { |
| 690 |
w.append(" value=\"").append(encodeAttribute(link.getValue())).append('"'); |
| 691 |
} |
| 692 |
|
| 693 |
if (link.getHref().length() != 0) { |
| 694 |
w.append(" href=\"").append(encodeAttribute(link.getHref()) + '"'); |
| 695 |
} |
| 696 |
|
| 697 |
if (link.getGref().length() != 0) { |
| 698 |
w.append(" gref=\"").append(encodeAttribute(link.getGref()) + '"'); |
| 699 |
} |
| 700 |
|
| 701 |
if (link.getAction().length() != 0) { |
| 702 |
w.append(" action=\"").append(encodeAttribute(link.getAction()) + '"'); |
| 703 |
} |
| 704 |
|
| 705 |
if (link.getContent().length() != 0) { |
| 706 |
w.write(">"); |
| 707 |
|
| 708 |
writeComment(link.getBelow()); |
| 709 |
|
| 710 |
w.write(link.getContent()); |
| 711 |
|
| 712 |
w.write(linkend); |
| 713 |
} else { |
| 714 |
|
| 715 |
w.write("/>"); |
| 716 |
|
| 717 |
writeComment(link.getBelow()); |
| 718 |
} |
| 719 |
} |
| 720 |
} |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
public void writeInfo(final InfoSet infoSet) throws IOException { |
| 729 |
if (infoSet != null) { |
| 730 |
final Writer w = bw; |
| 731 |
|
| 732 |
SavotInfo info; |
| 733 |
|
| 734 |
for (int i = 0, len = infoSet.getItemCount(); i < len; i++) { |
| 735 |
info = infoSet.getItemAt(i); |
| 736 |
|
| 737 |
|
| 738 |
writeComment(info.getAbove()); |
| 739 |
|
| 740 |
w.write("\n<INFO"); |
| 741 |
|
| 742 |
if (info.getId().length() != 0) { |
| 743 |
w.append(" ID=\"").append(encodeAttribute(info.getId())).append('"'); |
| 744 |
} |
| 745 |
|
| 746 |
if (info.getName().length() != 0) { |
| 747 |
w.append(" name=\"").append(encodeAttribute(info.getName())).append('"'); |
| 748 |
} |
| 749 |
|
| 750 |
if (info.getValue().length() != 0) { |
| 751 |
w.append(" value=\"").append(encodeAttribute(info.getValue())).append('"'); |
| 752 |
} |
| 753 |
|
| 754 |
|
| 755 |
if (info.getXtype().length() != 0) { |
| 756 |
w.append(" xtype=\"").append(encodeAttribute(info.getXtype())).append('"'); |
| 757 |
} |
| 758 |
|
| 759 |
|
| 760 |
if (info.getRef().length() != 0) { |
| 761 |
w.append(" ref=\"").append(encodeAttribute(info.getRef())).append('"'); |
| 762 |
} |
| 763 |
|
| 764 |
|
| 765 |
if (info.getUnit().length() != 0) { |
| 766 |
w.append(" unit=\"").append(encodeAttribute(info.getUnit())).append('"'); |
| 767 |
} |
| 768 |
|
| 769 |
|
| 770 |
if (info.getUcd().length() != 0) { |
| 771 |
w.append(" ucd=\"").append(encodeAttribute(info.getUcd())).append('"'); |
| 772 |
} |
| 773 |
|
| 774 |
|
| 775 |
if (info.getUtype().length() != 0) { |
| 776 |
w.append(" utype=\"").append(encodeAttribute(info.getUtype())).append('"'); |
| 777 |
} |
| 778 |
|
| 779 |
|
| 780 |
if (info.getContent().length() != 0) { |
| 781 |
w.write(">"); |
| 782 |
|
| 783 |
writeComment(info.getBelow()); |
| 784 |
|
| 785 |
w.append(encodeElement(info.getContent())).append("</INFO>"); |
| 786 |
|
| 787 |
} else { |
| 788 |
|
| 789 |
if (info.getDescription().length() != 0 || info.getValues() != null || info.getLinks().getItemCount() != 0) { |
| 790 |
w.write(">"); |
| 791 |
|
| 792 |
writeComment(info.getBelow()); |
| 793 |
|
| 794 |
|
| 795 |
writeDescription(info.getDescription()); |
| 796 |
|
| 797 |
|
| 798 |
writeValues(info.getValues()); |
| 799 |
|
| 800 |
|
| 801 |
writeLink(info.getLinks()); |
| 802 |
|
| 803 |
w.write("</INFO>"); |
| 804 |
} else { |
| 805 |
w.write("/>"); |
| 806 |
} |
| 807 |
} |
| 808 |
} |
| 809 |
} |
| 810 |
} |
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
public void writeField(final FieldSet fieldSet) throws IOException { |
| 819 |
final Writer w = bw; |
| 820 |
|
| 821 |
SavotField field; |
| 822 |
|
| 823 |
for (int i = 0, len = fieldSet.getItemCount(); i < len; i++) { |
| 824 |
field = fieldSet.getItemAt(i); |
| 825 |
|
| 826 |
writeComment(field.getAbove()); |
| 827 |
|
| 828 |
w.write("\n<FIELD"); |
| 829 |
|
| 830 |
if (field.getName().length() != 0) { |
| 831 |
w.append(" name=\"").append(encodeAttribute(field.getName())).append('"'); |
| 832 |
} |
| 833 |
|
| 834 |
if (field.getId().length() != 0) { |
| 835 |
w.append(" ID=\"").append(encodeAttribute(field.getId())).append('"'); |
| 836 |
} |
| 837 |
|
| 838 |
if (field.getDataType().length() != 0) { |
| 839 |
w.append(" datatype=\"").append(encodeAttribute(field.getDataType())).append('"'); |
| 840 |
} |
| 841 |
|
| 842 |
if (field.getArraySize().length() != 0) { |
| 843 |
w.append(" arraysize=\"").append(encodeAttribute(field.getArraySize())).append('"'); |
| 844 |
} |
| 845 |
|
| 846 |
if (field.getPrecision().length() != 0) { |
| 847 |
w.append(" precision=\"").append(encodeAttribute(field.getPrecision())).append('"'); |
| 848 |
} |
| 849 |
|
| 850 |
if (field.getWidth().length() != 0) { |
| 851 |
w.append(" width=\"").append(encodeAttribute(field.getWidth())).append('"'); |
| 852 |
} |
| 853 |
|
| 854 |
|
| 855 |
if (field.getXtype().length() != 0) { |
| 856 |
w.append(" xtype=\"").append(encodeAttribute(field.getXtype())).append('"'); |
| 857 |
} |
| 858 |
|
| 859 |
if (field.getRef().length() != 0) { |
| 860 |
w.append(" ref=\"").append(encodeAttribute(field.getRef())).append('"'); |
| 861 |
} |
| 862 |
|
| 863 |
if (field.getUcd().length() != 0) { |
| 864 |
w.append(" ucd=\"").append(encodeAttribute(field.getUcd())).append('"'); |
| 865 |
} |
| 866 |
|
| 867 |
if (field.getUtype().length() != 0) { |
| 868 |
w.append(" utype=\"").append(encodeAttribute(field.getUtype())).append('"'); |
| 869 |
} |
| 870 |
|
| 871 |
if (field.getType().length() != 0) { |
| 872 |
w.append(" type=\"").append(encodeAttribute(field.getType())).append('"'); |
| 873 |
} |
| 874 |
|
| 875 |
if (field.getUnit().length() != 0) { |
| 876 |
w.append(" unit=\"").append(encodeAttribute(field.getUnit())).append('"'); |
| 877 |
} |
| 878 |
|
| 879 |
if (field.getDescription().length() != 0 || field.getValues() != null || field.getLinks().getItemCount() != 0) { |
| 880 |
w.write(">"); |
| 881 |
|
| 882 |
writeComment(field.getBelow()); |
| 883 |
|
| 884 |
|
| 885 |
writeDescription(field.getDescription()); |
| 886 |
|
| 887 |
|
| 888 |
writeValues(field.getValues()); |
| 889 |
|
| 890 |
|
| 891 |
writeLink(field.getLinks()); |
| 892 |
|
| 893 |
w.write(fieldend); |
| 894 |
} else { |
| 895 |
w.write("/>"); |
| 896 |
} |
| 897 |
} |
| 898 |
} |
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
public void writeFieldRef(final FieldRefSet fieldRefSet) throws IOException { |
| 907 |
final Writer w = bw; |
| 908 |
|
| 909 |
SavotFieldRef fieldref; |
| 910 |
|
| 911 |
for (int i = 0, len = fieldRefSet.getItemCount(); i < len; i++) { |
| 912 |
fieldref = fieldRefSet.getItemAt(i); |
| 913 |
|
| 914 |
writeComment(fieldref.getAbove()); |
| 915 |
|
| 916 |
w.write("\n<FIELDref"); |
| 917 |
|
| 918 |
if (fieldref.getRef().length() != 0) { |
| 919 |
w.append(" ref=\"").append(encodeAttribute(fieldref.getRef())).append('"'); |
| 920 |
} |
| 921 |
|
| 922 |
if (fieldref.getUcd().length() != 0) { |
| 923 |
w.append(" ucd=\"").append(encodeAttribute(fieldref.getUcd())).append('"'); |
| 924 |
} |
| 925 |
|
| 926 |
if (fieldref.getUtype().length() != 0) { |
| 927 |
w.append(" utype=\"").append(encodeAttribute(fieldref.getUtype())).append('"'); |
| 928 |
} |
| 929 |
|
| 930 |
w.write("/>"); |
| 931 |
} |
| 932 |
} |
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
public void writeStream(final SavotStream stream) throws IOException { |
| 941 |
final Writer w = bw; |
| 942 |
|
| 943 |
writeComment(stream.getAbove()); |
| 944 |
|
| 945 |
w.write("\n<STREAM"); |
| 946 |
|
| 947 |
if (stream.getType().length() != 0) { |
| 948 |
w.append(" type=\"").append(encodeAttribute(stream.getType())).append('"'); |
| 949 |
} |
| 950 |
|
| 951 |
if (stream.getHref().length() != 0) { |
| 952 |
w.append(" href=\"").append(encodeAttribute(stream.getHref())).append('"'); |
| 953 |
} |
| 954 |
|
| 955 |
if (stream.getActuate().length() != 0) { |
| 956 |
w.append(" actuate=\"").append(encodeAttribute(stream.getActuate())).append('"'); |
| 957 |
} |
| 958 |
|
| 959 |
if (stream.getEncoding().length() != 0) { |
| 960 |
w.append(" encoding=\"").append(encodeAttribute(stream.getEncoding())).append('"'); |
| 961 |
} |
| 962 |
|
| 963 |
if (stream.getExpires().length() != 0) { |
| 964 |
w.append(" expires=\"").append(encodeAttribute(stream.getExpires())).append('"'); |
| 965 |
} |
| 966 |
|
| 967 |
if (stream.getRights().length() != 0) { |
| 968 |
w.append(" rights=\"").append(encodeAttribute(stream.getRights())).append('"'); |
| 969 |
} |
| 970 |
|
| 971 |
w.write(">"); |
| 972 |
|
| 973 |
writeComment(stream.getBelow()); |
| 974 |
|
| 975 |
if (stream.getContent().length() != 0) { |
| 976 |
w.write(stream.getContent()); |
| 977 |
} |
| 978 |
|
| 979 |
w.write(streamend); |
| 980 |
} |
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
public void writeBinary(final SavotBinary binary) throws IOException { |
| 989 |
if (binary.getStream() != null) { |
| 990 |
final Writer w = bw; |
| 991 |
|
| 992 |
writeComment(binary.getAbove()); |
| 993 |
|
| 994 |
w.write(binarybegin); |
| 995 |
|
| 996 |
writeComment(binary.getBelow()); |
| 997 |
|
| 998 |
writeStream(binary.getStream()); |
| 999 |
|
| 1000 |
w.write(binaryend); |
| 1001 |
} |
| 1002 |
} |
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
public void writeValues(final SavotValues values) throws IOException { |
| 1011 |
if (values != null) { |
| 1012 |
final Writer w = bw; |
| 1013 |
|
| 1014 |
writeComment(values.getAbove()); |
| 1015 |
|
| 1016 |
w.write("\n<VALUES"); |
| 1017 |
|
| 1018 |
if (values.getId().length() != 0) { |
| 1019 |
w.append(" ID=\"").append(encodeAttribute(values.getId())).append('"'); |
| 1020 |
} |
| 1021 |
|
| 1022 |
if (values.getType().length() != 0) { |
| 1023 |
w.append(" type=\"").append(encodeAttribute(values.getType())).append('"'); |
| 1024 |
} |
| 1025 |
|
| 1026 |
if (values.getNull().length() != 0) { |
| 1027 |
w.append(" null=\"").append(encodeAttribute(values.getNull())).append('"'); |
| 1028 |
} |
| 1029 |
|
| 1030 |
if (values.getRef().length() != 0) { |
| 1031 |
w.append(" ref=\"").append(encodeAttribute(values.getRef())).append('"'); |
| 1032 |
} |
| 1033 |
|
| 1034 |
if (values.getInvalid().length() != 0) { |
| 1035 |
w.append(" invalid=\"").append(encodeAttribute(values.getInvalid())).append('"'); |
| 1036 |
} |
| 1037 |
|
| 1038 |
w.write(">"); |
| 1039 |
|
| 1040 |
writeComment(values.getBelow()); |
| 1041 |
|
| 1042 |
|
| 1043 |
if (values.getMin() != null) { |
| 1044 |
SavotMin min = values.getMin(); |
| 1045 |
writeMin(min); |
| 1046 |
} |
| 1047 |
|
| 1048 |
|
| 1049 |
if (values.getMax() != null) { |
| 1050 |
SavotMax max = values.getMax(); |
| 1051 |
writeMax(max); |
| 1052 |
} |
| 1053 |
|
| 1054 |
|
| 1055 |
writeOption(values.getOptions()); |
| 1056 |
|
| 1057 |
w.write(valuesend); |
| 1058 |
} |
| 1059 |
} |
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
public void writeFits(final SavotFits fits) throws IOException { |
| 1068 |
final Writer w = bw; |
| 1069 |
|
| 1070 |
writeComment(fits.getAbove()); |
| 1071 |
|
| 1072 |
w.write("\n<FITS"); |
| 1073 |
|
| 1074 |
if (fits.getExtnum().length() != 0) { |
| 1075 |
w.append(" extnum=\"").append(encodeAttribute(fits.getExtnum())).append('"'); |
| 1076 |
} |
| 1077 |
|
| 1078 |
w.write(">"); |
| 1079 |
|
| 1080 |
writeComment(fits.getBelow()); |
| 1081 |
|
| 1082 |
|
| 1083 |
if (fits.getStream() != null) { |
| 1084 |
|
| 1085 |
writeStream(fits.getStream()); |
| 1086 |
} |
| 1087 |
|
| 1088 |
w.write(fitsend); |
| 1089 |
} |
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
public void writeMin(final SavotMin min) throws IOException { |
| 1098 |
final Writer w = bw; |
| 1099 |
|
| 1100 |
writeComment(min.getAbove()); |
| 1101 |
|
| 1102 |
w.write("\n<MIN"); |
| 1103 |
|
| 1104 |
if (min.getValue().length() != 0) { |
| 1105 |
w.append(" value=\"").append(encodeAttribute(min.getValue())).append('"'); |
| 1106 |
} |
| 1107 |
|
| 1108 |
if (min.getInclusive().length() != 0) { |
| 1109 |
w.append(" inclusive=\"").append(encodeAttribute(min.getInclusive())).append('"'); |
| 1110 |
} |
| 1111 |
|
| 1112 |
if (min.getContent().length() != 0) { |
| 1113 |
w.write(">"); |
| 1114 |
|
| 1115 |
writeComment(min.getBelow()); |
| 1116 |
|
| 1117 |
w.write(min.getContent()); |
| 1118 |
|
| 1119 |
w.write(minend); |
| 1120 |
} else { |
| 1121 |
|
| 1122 |
w.write("/>"); |
| 1123 |
|
| 1124 |
writeComment(min.getBelow()); |
| 1125 |
} |
| 1126 |
} |
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
public void writeMax(final SavotMax max) throws IOException { |
| 1135 |
final Writer w = bw; |
| 1136 |
|
| 1137 |
writeComment(max.getAbove()); |
| 1138 |
|
| 1139 |
w.write("\n<MAX"); |
| 1140 |
|
| 1141 |
if (max.getValue().length() != 0) { |
| 1142 |
w.append(" value=\"").append(encodeAttribute(max.getValue())).append('"'); |
| 1143 |
} |
| 1144 |
|
| 1145 |
if (max.getInclusive().length() != 0) { |
| 1146 |
w.append(" inclusive=\"").append(encodeAttribute(max.getInclusive())).append('"'); |
| 1147 |
} |
| 1148 |
|
| 1149 |
if (max.getContent().length() != 0) { |
| 1150 |
w.write(">"); |
| 1151 |
|
| 1152 |
writeComment(max.getBelow()); |
| 1153 |
|
| 1154 |
w.write(max.getContent()); |
| 1155 |
|
| 1156 |
w.write(maxend); |
| 1157 |
} else { |
| 1158 |
|
| 1159 |
w.write("/>"); |
| 1160 |
|
| 1161 |
writeComment(max.getBelow()); |
| 1162 |
} |
| 1163 |
} |
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
public void writeOption(final OptionSet optionSet) throws IOException { |
| 1172 |
final Writer w = bw; |
| 1173 |
|
| 1174 |
SavotOption option; |
| 1175 |
|
| 1176 |
for (int i = 0, len = optionSet.getItemCount(); i < len; i++) { |
| 1177 |
option = optionSet.getItemAt(i); |
| 1178 |
|
| 1179 |
writeComment(option.getAbove()); |
| 1180 |
|
| 1181 |
w.write("\n<OPTION"); |
| 1182 |
|
| 1183 |
if (option.getName().length() != 0) { |
| 1184 |
w.append(" name=\"").append(encodeAttribute(option.getName())).append('"'); |
| 1185 |
} |
| 1186 |
|
| 1187 |
if (option.getValue().length() != 0) { |
| 1188 |
w.append(" value=\"").append(encodeAttribute(option.getValue())).append('"'); |
| 1189 |
} |
| 1190 |
|
| 1191 |
|
| 1192 |
if (option.getOptions().getItemCount() != 0) { |
| 1193 |
w.write(">"); |
| 1194 |
|
| 1195 |
writeComment(option.getBelow()); |
| 1196 |
|
| 1197 |
writeOption(option.getOptions()); |
| 1198 |
|
| 1199 |
w.write(optionend); |
| 1200 |
} else { |
| 1201 |
w.write("/>"); |
| 1202 |
|
| 1203 |
writeComment(option.getBelow()); |
| 1204 |
} |
| 1205 |
} |
| 1206 |
} |
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
public void writeGroup(final GroupSet groupSet) throws IOException { |
| 1215 |
final Writer w = bw; |
| 1216 |
|
| 1217 |
SavotGroup group; |
| 1218 |
|
| 1219 |
for (int i = 0, len = groupSet.getItemCount(); i < len; i++) { |
| 1220 |
group = groupSet.getItemAt(i); |
| 1221 |
|
| 1222 |
writeComment(group.getAbove()); |
| 1223 |
|
| 1224 |
w.write("\n<GROUP"); |
| 1225 |
|
| 1226 |
if (group.getId().length() != 0) { |
| 1227 |
w.append(" ID=\"").append(encodeAttribute(group.getId())).append('"'); |
| 1228 |
} |
| 1229 |
|
| 1230 |
if (group.getName().length() != 0) { |
| 1231 |
w.append(" name=\"").append(encodeAttribute(group.getName())).append('"'); |
| 1232 |
} |
| 1233 |
|
| 1234 |
if (group.getRef().length() != 0) { |
| 1235 |
w.append(" ref=\"").append(encodeAttribute(group.getRef())).append('"'); |
| 1236 |
} |
| 1237 |
|
| 1238 |
if (group.getUcd().length() != 0) { |
| 1239 |
w.append(" ucd=\"").append(encodeAttribute(group.getUcd())).append('"'); |
| 1240 |
} |
| 1241 |
|
| 1242 |
if (group.getUtype().length() != 0) { |
| 1243 |
w.append(" utype=\"").append(encodeAttribute(group.getUtype())).append('"'); |
| 1244 |
} |
| 1245 |
|
| 1246 |
w.write(">"); |
| 1247 |
|
| 1248 |
writeComment(group.getBelow()); |
| 1249 |
|
| 1250 |
|
| 1251 |
writeDescription(group.getDescription()); |
| 1252 |
|
| 1253 |
|
| 1254 |
writeFieldRef(group.getFieldsRef()); |
| 1255 |
|
| 1256 |
|
| 1257 |
writeParamRef(group.getParamsRef()); |
| 1258 |
|
| 1259 |
|
| 1260 |
writeParam(group.getParams()); |
| 1261 |
|
| 1262 |
|
| 1263 |
writeGroup(group.getGroups()); |
| 1264 |
|
| 1265 |
w.write(groupend); |
| 1266 |
} |
| 1267 |
} |
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
public void writeTableBegin(final SavotTable table) throws IOException { |
| 1277 |
final Writer w = bw; |
| 1278 |
|
| 1279 |
writeComment(table.getAbove()); |
| 1280 |
|
| 1281 |
|
| 1282 |
w.write("\n<TABLE"); |
| 1283 |
|
| 1284 |
if (table.getId().length() != 0) { |
| 1285 |
w.append(" ID=\"").append(encodeAttribute(table.getId())).append('"'); |
| 1286 |
} |
| 1287 |
|
| 1288 |
if (table.getName().length() != 0) { |
| 1289 |
w.append(" name=\"").append(encodeAttribute(table.getName())).append('"'); |
| 1290 |
} |
| 1291 |
|
| 1292 |
if (table.getRef().length() != 0) { |
| 1293 |
w.append(" ref=\"").append(encodeAttribute(table.getRef())).append('"'); |
| 1294 |
} |
| 1295 |
|
| 1296 |
if (table.getUcd().length() != 0) { |
| 1297 |
w.append(" ucd=\"").append(encodeAttribute(table.getUcd())).append('"'); |
| 1298 |
} |
| 1299 |
|
| 1300 |
if (table.getUtype().length() != 0) { |
| 1301 |
w.append(" utype=\"").append(encodeAttribute(table.getUtype())).append('"'); |
| 1302 |
} |
| 1303 |
|
| 1304 |
if (table.getNrows().length() != 0) { |
| 1305 |
w.append(" nrows=\"").append(encodeAttribute(table.getNrows())).append('"'); |
| 1306 |
} |
| 1307 |
|
| 1308 |
w.write(">"); |
| 1309 |
|
| 1310 |
writeComment(table.getBelow()); |
| 1311 |
|
| 1312 |
|
| 1313 |
writeDescription(table.getDescription()); |
| 1314 |
} |
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
public void writeTableEnd() throws IOException { |
| 1321 |
|
| 1322 |
bw.write(tableend); |
| 1323 |
} |
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
public void writeResourceBegin(final SavotResource resource) throws IOException { |
| 1333 |
final Writer w = bw; |
| 1334 |
|
| 1335 |
|
| 1336 |
writeComment(resource.getAbove()); |
| 1337 |
|
| 1338 |
w.write("\n<RESOURCE"); |
| 1339 |
|
| 1340 |
if (resource.getName().length() != 0) { |
| 1341 |
w.append(" name=\"").append(encodeAttribute(resource.getName())).append('"'); |
| 1342 |
} |
| 1343 |
|
| 1344 |
if (resource.getId().length() != 0) { |
| 1345 |
w.append(" ID=\"").append(encodeAttribute(resource.getId())).append('"'); |
| 1346 |
} |
| 1347 |
|
| 1348 |
if (resource.getUtype().length() != 0) { |
| 1349 |
w.append(" utype=\"").append(encodeAttribute(resource.getUtype())).append('"'); |
| 1350 |
} |
| 1351 |
|
| 1352 |
if (resource.getType().length() != 0) { |
| 1353 |
w.append(" type=\"").append(encodeAttribute(resource.getType())).append('"'); |
| 1354 |
} |
| 1355 |
|
| 1356 |
w.write(">"); |
| 1357 |
|
| 1358 |
writeComment(resource.getBelow()); |
| 1359 |
|
| 1360 |
|
| 1361 |
writeDescription(resource.getDescription()); |
| 1362 |
} |
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
public void writeResourceEnd() throws IOException { |
| 1369 |
|
| 1370 |
bw.write(resourceend); |
| 1371 |
} |
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
public void writeTableDataBegin() throws IOException { |
| 1378 |
|
| 1379 |
bw.write(tabledatabegin); |
| 1380 |
} |
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
public void writeTableDataEnd() throws IOException { |
| 1387 |
|
| 1388 |
bw.write(tabledataend); |
| 1389 |
} |
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
public void writeDataBegin() throws IOException { |
| 1396 |
|
| 1397 |
bw.write(databegin); |
| 1398 |
} |
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
public void writeDataEnd() throws IOException { |
| 1405 |
|
| 1406 |
bw.write(dataend); |
| 1407 |
} |
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
public void writeTR(final SavotTR tr) throws IOException { |
| 1415 |
final Writer w = bw; |
| 1416 |
final boolean doEncode = elementEntities; |
| 1417 |
String v; |
| 1418 |
|
| 1419 |
|
| 1420 |
w.write(trbegin); |
| 1421 |
|
| 1422 |
final List<SavotTD> tds = tr.getTDSet().getItems(); |
| 1423 |
SavotTD td; |
| 1424 |
|
| 1425 |
for (int i = 0, tdLen = tds.size(); i < tdLen; i++) { |
| 1426 |
td = tds.get(i); |
| 1427 |
|
| 1428 |
|
| 1429 |
v = td.getRawContent(); |
| 1430 |
|
| 1431 |
if (v != null) { |
| 1432 |
|
| 1433 |
w.write(tdbegin); |
| 1434 |
|
| 1435 |
w.write((doEncode) ? encodeElement(v) : v); |
| 1436 |
|
| 1437 |
|
| 1438 |
w.write(tdend); |
| 1439 |
|
| 1440 |
} else { |
| 1441 |
w.write(tdempty); |
| 1442 |
} |
| 1443 |
} |
| 1444 |
|
| 1445 |
w.write(trend); |
| 1446 |
} |
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
public void writeResource(final ResourceSet resourceset) throws IOException { |
| 1456 |
if (resourceset != null) { |
| 1457 |
SavotResource resource; |
| 1458 |
TableSet tableSet; |
| 1459 |
SavotTable table; |
| 1460 |
SavotData data; |
| 1461 |
SavotTableData tableData; |
| 1462 |
TRSet trs; |
| 1463 |
|
| 1464 |
for (int i = 0, len = resourceset.getItemCount(); i < len; i++) { |
| 1465 |
resource = resourceset.getItemAt(i); |
| 1466 |
|
| 1467 |
|
| 1468 |
writeResourceBegin(resource); |
| 1469 |
|
| 1470 |
|
| 1471 |
writeInfo(resource.getInfos()); |
| 1472 |
|
| 1473 |
|
| 1474 |
writeCoosys(resource.getCoosys()); |
| 1475 |
|
| 1476 |
|
| 1477 |
writeGroup(resource.getGroups()); |
| 1478 |
|
| 1479 |
|
| 1480 |
writeParam(resource.getParams()); |
| 1481 |
|
| 1482 |
|
| 1483 |
writeLink(resource.getLinks()); |
| 1484 |
|
| 1485 |
|
| 1486 |
tableSet = resource.getTables(); |
| 1487 |
|
| 1488 |
for (int j = 0, tableLen = tableSet.getItemCount(); j < tableLen; j++) { |
| 1489 |
table = tableSet.getItemAt(j); |
| 1490 |
|
| 1491 |
|
| 1492 |
writeTableBegin(table); |
| 1493 |
|
| 1494 |
|
| 1495 |
writeField(table.getFields()); |
| 1496 |
|
| 1497 |
|
| 1498 |
writeParam(table.getParams()); |
| 1499 |
|
| 1500 |
|
| 1501 |
writeGroup(table.getGroups()); |
| 1502 |
|
| 1503 |
|
| 1504 |
writeLink(table.getLinks()); |
| 1505 |
|
| 1506 |
data = table.getData(); |
| 1507 |
|
| 1508 |
if (data != null) { |
| 1509 |
|
| 1510 |
writeDataBegin(); |
| 1511 |
|
| 1512 |
tableData = data.getTableData(); |
| 1513 |
|
| 1514 |
if (tableData != null) { |
| 1515 |
|
| 1516 |
writeTableDataBegin(); |
| 1517 |
|
| 1518 |
trs = tableData.getTRs(); |
| 1519 |
|
| 1520 |
for (int r = 0, trLen = trs.getItemCount(); r < trLen; r++) { |
| 1521 |
|
| 1522 |
writeTR(trs.getItemAt(r)); |
| 1523 |
} |
| 1524 |
|
| 1525 |
|
| 1526 |
writeTableDataEnd(); |
| 1527 |
|
| 1528 |
} |
| 1529 |
|
| 1530 |
|
| 1531 |
if (data.getBinary() != null) { |
| 1532 |
writeBinary(data.getBinary()); |
| 1533 |
} |
| 1534 |
|
| 1535 |
|
| 1536 |
if (data.getFits() != null) { |
| 1537 |
writeFits(data.getFits()); |
| 1538 |
} |
| 1539 |
|
| 1540 |
|
| 1541 |
writeDataEnd(); |
| 1542 |
|
| 1543 |
} |
| 1544 |
|
| 1545 |
|
| 1546 |
writeInfo(table.getInfosAtEnd()); |
| 1547 |
|
| 1548 |
|
| 1549 |
writeTableEnd(); |
| 1550 |
|
| 1551 |
} |
| 1552 |
|
| 1553 |
writeResource(resource.getResources()); |
| 1554 |
|
| 1555 |
|
| 1556 |
writeInfo(resource.getInfosAtEnd()); |
| 1557 |
|
| 1558 |
|
| 1559 |
writeResourceEnd(); |
| 1560 |
} |
| 1561 |
} |
| 1562 |
} |
| 1563 |
} |