001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.builder; 018 019import java.nio.charset.Charset; 020import java.util.List; 021import java.util.Map; 022 023import org.w3c.dom.Node; 024 025import org.apache.camel.model.DataFormatDefinition; 026import org.apache.camel.model.ProcessorDefinition; 027import org.apache.camel.model.dataformat.ASN1DataFormat; 028import org.apache.camel.model.dataformat.Any23DataFormat; 029import org.apache.camel.model.dataformat.Any23Type; 030import org.apache.camel.model.dataformat.AvroDataFormat; 031import org.apache.camel.model.dataformat.Base64DataFormat; 032import org.apache.camel.model.dataformat.BeanioDataFormat; 033import org.apache.camel.model.dataformat.BindyDataFormat; 034import org.apache.camel.model.dataformat.BindyType; 035import org.apache.camel.model.dataformat.CBORDataFormat; 036import org.apache.camel.model.dataformat.CsvDataFormat; 037import org.apache.camel.model.dataformat.CustomDataFormat; 038import org.apache.camel.model.dataformat.FhirJsonDataFormat; 039import org.apache.camel.model.dataformat.FhirXmlDataFormat; 040import org.apache.camel.model.dataformat.GrokDataFormat; 041import org.apache.camel.model.dataformat.GzipDataFormat; 042import org.apache.camel.model.dataformat.HL7DataFormat; 043import org.apache.camel.model.dataformat.IcalDataFormat; 044import org.apache.camel.model.dataformat.JacksonXMLDataFormat; 045import org.apache.camel.model.dataformat.JaxbDataFormat; 046import org.apache.camel.model.dataformat.JsonApiDataFormat; 047import org.apache.camel.model.dataformat.JsonDataFormat; 048import org.apache.camel.model.dataformat.JsonLibrary; 049import org.apache.camel.model.dataformat.LZFDataFormat; 050import org.apache.camel.model.dataformat.MimeMultipartDataFormat; 051import org.apache.camel.model.dataformat.PGPDataFormat; 052import org.apache.camel.model.dataformat.ProtobufDataFormat; 053import org.apache.camel.model.dataformat.RssDataFormat; 054import org.apache.camel.model.dataformat.SoapJaxbDataFormat; 055import org.apache.camel.model.dataformat.SyslogDataFormat; 056import org.apache.camel.model.dataformat.TarFileDataFormat; 057import org.apache.camel.model.dataformat.ThriftDataFormat; 058import org.apache.camel.model.dataformat.TidyMarkupDataFormat; 059import org.apache.camel.model.dataformat.XMLSecurityDataFormat; 060import org.apache.camel.model.dataformat.XStreamDataFormat; 061import org.apache.camel.model.dataformat.YAMLDataFormat; 062import org.apache.camel.model.dataformat.YAMLLibrary; 063import org.apache.camel.model.dataformat.ZipDeflaterDataFormat; 064import org.apache.camel.model.dataformat.ZipFileDataFormat; 065import org.apache.camel.support.jsse.KeyStoreParameters; 066import org.apache.camel.util.CollectionStringBuffer; 067 068/** 069 * An expression for constructing the different possible 070 * {@link org.apache.camel.spi.DataFormat} options. 071 */ 072public class DataFormatClause<T extends ProcessorDefinition<?>> { 073 private final T processorType; 074 private final Operation operation; 075 076 /** 077 * {@link org.apache.camel.spi.DataFormat} operations. 078 */ 079 public enum Operation { 080 Marshal, Unmarshal 081 } 082 083 public DataFormatClause(T processorType, Operation operation) { 084 this.processorType = processorType; 085 this.operation = operation; 086 } 087 088 /** 089 * Uses the Any23 data format 090 */ 091 public T any23(String baseuri) { 092 return dataFormat(new Any23DataFormat(baseuri)); 093 } 094 095 public T any23(String baseuri, Any23Type outputformat) { 096 return dataFormat(new Any23DataFormat(baseuri, outputformat)); 097 } 098 099 public T any23(String baseuri, Any23Type outputformat, Map<String, String> configurations) { 100 return dataFormat(new Any23DataFormat(baseuri, outputformat, configurations)); 101 } 102 103 public T any23(String baseuri, Any23Type outputformat, Map<String, String> configurations, List<String> extractors) { 104 return dataFormat(new Any23DataFormat(baseuri, outputformat, configurations, extractors)); 105 } 106 107 /** 108 * Uses the Avro data format 109 */ 110 public T avro() { 111 return dataFormat(new AvroDataFormat()); 112 } 113 114 public T avro(Object schema) { 115 AvroDataFormat dataFormat = new AvroDataFormat(); 116 dataFormat.setSchema(schema); 117 return dataFormat(dataFormat); 118 } 119 120 public T avro(String instanceClassName) { 121 return dataFormat(new AvroDataFormat(instanceClassName)); 122 } 123 124 /** 125 * Uses the base64 data format 126 */ 127 public T base64() { 128 Base64DataFormat dataFormat = new Base64DataFormat(); 129 return dataFormat(dataFormat); 130 } 131 132 /** 133 * Uses the base64 data format 134 */ 135 public T base64(int lineLength, String lineSeparator, boolean urlSafe) { 136 Base64DataFormat dataFormat = new Base64DataFormat(); 137 dataFormat.setLineLength(lineLength); 138 dataFormat.setLineSeparator(lineSeparator); 139 dataFormat.setUrlSafe(urlSafe); 140 return dataFormat(dataFormat); 141 } 142 143 /** 144 * Uses the beanio data format 145 */ 146 public T beanio(String mapping, String streamName) { 147 BeanioDataFormat dataFormat = new BeanioDataFormat(); 148 dataFormat.setMapping(mapping); 149 dataFormat.setStreamName(streamName); 150 return dataFormat(dataFormat); 151 } 152 153 /** 154 * Uses the beanio data format 155 */ 156 public T beanio(String mapping, String streamName, String encoding) { 157 BeanioDataFormat dataFormat = new BeanioDataFormat(); 158 dataFormat.setMapping(mapping); 159 dataFormat.setStreamName(streamName); 160 dataFormat.setEncoding(encoding); 161 return dataFormat(dataFormat); 162 } 163 164 /** 165 * Uses the beanio data format 166 */ 167 public T beanio(String mapping, String streamName, String encoding, boolean ignoreUnidentifiedRecords, boolean ignoreUnexpectedRecords, boolean ignoreInvalidRecords) { 168 BeanioDataFormat dataFormat = new BeanioDataFormat(); 169 dataFormat.setMapping(mapping); 170 dataFormat.setStreamName(streamName); 171 dataFormat.setEncoding(encoding); 172 dataFormat.setIgnoreUnidentifiedRecords(ignoreUnidentifiedRecords); 173 dataFormat.setIgnoreUnexpectedRecords(ignoreUnexpectedRecords); 174 dataFormat.setIgnoreInvalidRecords(ignoreInvalidRecords); 175 return dataFormat(dataFormat); 176 } 177 178 /** 179 * Uses the beanio data format 180 */ 181 public T beanio(String mapping, String streamName, String encoding, String beanReaderErrorHandlerType) { 182 BeanioDataFormat dataFormat = new BeanioDataFormat(); 183 dataFormat.setMapping(mapping); 184 dataFormat.setStreamName(streamName); 185 dataFormat.setEncoding(encoding); 186 dataFormat.setBeanReaderErrorHandlerType(beanReaderErrorHandlerType); 187 return dataFormat(dataFormat); 188 } 189 190 /** 191 * Uses the Bindy data format 192 * 193 * @param type the type of bindy data format to use 194 * @param classType the POJO class type 195 */ 196 public T bindy(BindyType type, Class<?> classType) { 197 BindyDataFormat bindy = new BindyDataFormat(); 198 bindy.setType(type); 199 bindy.setClassType(classType); 200 return dataFormat(bindy); 201 } 202 203 /** 204 * Uses the Bindy data format 205 * 206 * @param type the type of bindy data format to use 207 * @param classType the POJO class type 208 * @param unwrapSingleInstance whether unmarshal should unwrap if there is a 209 * single instance in the result 210 */ 211 public T bindy(BindyType type, Class<?> classType, boolean unwrapSingleInstance) { 212 BindyDataFormat bindy = new BindyDataFormat(); 213 bindy.setType(type); 214 bindy.setClassType(classType); 215 bindy.setUnwrapSingleInstance(unwrapSingleInstance); 216 return dataFormat(bindy); 217 } 218 219 /** 220 * Uses the CBOR data format 221 */ 222 public T cbor() { 223 return dataFormat(new CBORDataFormat()); 224 } 225 226 /** 227 * Uses the CBOR data format 228 * 229 * @param unmarshalType unmarshal type for cbor type 230 */ 231 public T cbor(Class<?> unmarshalType) { 232 CBORDataFormat cborDataFormat = new CBORDataFormat(); 233 cborDataFormat.setUnmarshalType(unmarshalType); 234 return dataFormat(cborDataFormat); 235 } 236 237 /** 238 * Uses the CSV data format 239 */ 240 public T csv() { 241 return dataFormat(new CsvDataFormat()); 242 } 243 244 /** 245 * Uses the CSV data format for a huge file. Sequential access through an 246 * iterator. 247 */ 248 public T csvLazyLoad() { 249 return dataFormat(new CsvDataFormat(true)); 250 } 251 252 /** 253 * Uses the custom data format 254 */ 255 public T custom(String ref) { 256 return dataFormat(new CustomDataFormat(ref)); 257 } 258 259 /** 260 * Uses the Grok data format 261 */ 262 public T grok(String pattern) { 263 GrokDataFormat grokDataFormat = new GrokDataFormat(); 264 grokDataFormat.setPattern(pattern); 265 return dataFormat(grokDataFormat); 266 } 267 268 /** 269 * Uses the GZIP deflater data format 270 */ 271 public T gzipDeflater() { 272 GzipDataFormat gzdf = new GzipDataFormat(); 273 return dataFormat(gzdf); 274 } 275 276 /** 277 * Uses the HL7 data format 278 */ 279 public T hl7() { 280 return dataFormat(new HL7DataFormat()); 281 } 282 283 /** 284 * Uses the HL7 data format 285 */ 286 public T hl7(boolean validate) { 287 HL7DataFormat hl7 = new HL7DataFormat(); 288 hl7.setValidate(validate); 289 return dataFormat(hl7); 290 } 291 292 /** 293 * Uses the HL7 data format 294 */ 295 public T hl7(Object parser) { 296 HL7DataFormat hl7 = new HL7DataFormat(); 297 hl7.setParser(parser); 298 return dataFormat(hl7); 299 } 300 301 /** 302 * Uses the iCal data format 303 */ 304 public T ical(boolean validating) { 305 IcalDataFormat ical = new IcalDataFormat(); 306 ical.setValidating(validating); 307 return dataFormat(ical); 308 } 309 310 /** 311 * Uses the LZF deflater data format 312 */ 313 public T lzf() { 314 LZFDataFormat lzfdf = new LZFDataFormat(); 315 return dataFormat(lzfdf); 316 } 317 318 /** 319 * Uses the MIME Multipart data format 320 */ 321 public T mimeMultipart() { 322 MimeMultipartDataFormat mm = new MimeMultipartDataFormat(); 323 return dataFormat(mm); 324 } 325 326 /** 327 * Uses the MIME Multipart data format 328 * 329 * @param multipartSubType Specifies the subtype of the MIME Multipart 330 */ 331 public T mimeMultipart(String multipartSubType) { 332 MimeMultipartDataFormat mm = new MimeMultipartDataFormat(); 333 mm.setMultipartSubType(multipartSubType); 334 return dataFormat(mm); 335 } 336 337 /** 338 * Uses the MIME Multipart data format 339 * 340 * @param multipartSubType the subtype of the MIME Multipart 341 * @param multipartWithoutAttachment defines whether a message without 342 * attachment is also marshaled into a MIME Multipart (with only 343 * one body part). 344 * @param headersInline define the MIME Multipart headers as part of the 345 * message body or as Camel headers 346 * @param binaryContent have binary encoding for binary content (true) or 347 * use Base-64 encoding for binary content (false) 348 */ 349 public T mimeMultipart(String multipartSubType, boolean multipartWithoutAttachment, boolean headersInline, boolean binaryContent) { 350 MimeMultipartDataFormat mm = new MimeMultipartDataFormat(); 351 mm.setMultipartSubType(multipartSubType); 352 mm.setMultipartWithoutAttachment(multipartWithoutAttachment); 353 mm.setHeadersInline(headersInline); 354 mm.setBinaryContent(binaryContent); 355 return dataFormat(mm); 356 } 357 358 /** 359 * Uses the MIME Multipart data format 360 * 361 * @param multipartSubType the subtype of the MIME Multipart 362 * @param multipartWithoutAttachment defines whether a message without 363 * attachment is also marshaled into a MIME Multipart (with only 364 * one body part). 365 * @param headersInline define the MIME Multipart headers as part of the 366 * message body or as Camel headers 367 * @param includeHeaders if headersInline is set to true all camel headers 368 * matching this regex are also stored as MIME headers on the 369 * Multipart 370 * @param binaryContent have binary encoding for binary content (true) or 371 * use Base-64 encoding for binary content (false) 372 */ 373 public T mimeMultipart(String multipartSubType, boolean multipartWithoutAttachment, boolean headersInline, String includeHeaders, boolean binaryContent) { 374 MimeMultipartDataFormat mm = new MimeMultipartDataFormat(); 375 mm.setMultipartSubType(multipartSubType); 376 mm.setMultipartWithoutAttachment(multipartWithoutAttachment); 377 mm.setHeadersInline(headersInline); 378 mm.setIncludeHeaders(includeHeaders); 379 mm.setBinaryContent(binaryContent); 380 return dataFormat(mm); 381 } 382 383 /** 384 * Uses the MIME Multipart data format 385 * 386 * @param multipartWithoutAttachment defines whether a message without 387 * attachment is also marshaled into a MIME Multipart (with only 388 * one body part). 389 * @param headersInline define the MIME Multipart headers as part of the 390 * message body or as Camel headers 391 * @param binaryContent have binary encoding for binary content (true) or 392 * use Base-64 encoding for binary content (false) 393 */ 394 public T mimeMultipart(boolean multipartWithoutAttachment, boolean headersInline, boolean binaryContent) { 395 MimeMultipartDataFormat mm = new MimeMultipartDataFormat(); 396 mm.setMultipartWithoutAttachment(multipartWithoutAttachment); 397 mm.setHeadersInline(headersInline); 398 mm.setBinaryContent(binaryContent); 399 return dataFormat(mm); 400 } 401 402 /** 403 * Uses the PGP data format 404 */ 405 public T pgp(String keyFileName, String keyUserid) { 406 PGPDataFormat pgp = new PGPDataFormat(); 407 pgp.setKeyFileName(keyFileName); 408 pgp.setKeyUserid(keyUserid); 409 return dataFormat(pgp); 410 } 411 412 /** 413 * Uses the PGP data format 414 */ 415 public T pgp(String keyFileName, String keyUserid, String password) { 416 PGPDataFormat pgp = new PGPDataFormat(); 417 pgp.setKeyFileName(keyFileName); 418 pgp.setKeyUserid(keyUserid); 419 pgp.setPassword(password); 420 return dataFormat(pgp); 421 } 422 423 /** 424 * Uses the PGP data format 425 */ 426 public T pgp(String keyFileName, String keyUserid, String password, boolean armored, boolean integrity) { 427 PGPDataFormat pgp = new PGPDataFormat(); 428 pgp.setKeyFileName(keyFileName); 429 pgp.setKeyUserid(keyUserid); 430 pgp.setPassword(password); 431 pgp.setArmored(armored); 432 pgp.setIntegrity(integrity); 433 return dataFormat(pgp); 434 } 435 436 /** 437 * Uses the Jackson XML data format 438 */ 439 public T jacksonxml() { 440 return dataFormat(new JacksonXMLDataFormat()); 441 } 442 443 /** 444 * Uses the Jackson XML data format 445 * 446 * @param unmarshalType unmarshal type for xml jackson type 447 */ 448 public T jacksonxml(Class<?> unmarshalType) { 449 JacksonXMLDataFormat jacksonXMLDataFormat = new JacksonXMLDataFormat(); 450 jacksonXMLDataFormat.setUnmarshalType(unmarshalType); 451 return dataFormat(jacksonXMLDataFormat); 452 } 453 454 /** 455 * Uses the Jackson XML data format 456 * 457 * @param unmarshalType unmarshal type for xml jackson type 458 * @param jsonView the view type for xml jackson type 459 */ 460 public T jacksonxml(Class<?> unmarshalType, Class<?> jsonView) { 461 JacksonXMLDataFormat jacksonXMLDataFormat = new JacksonXMLDataFormat(); 462 jacksonXMLDataFormat.setUnmarshalType(unmarshalType); 463 jacksonXMLDataFormat.setJsonView(jsonView); 464 return dataFormat(jacksonXMLDataFormat); 465 } 466 467 /** 468 * Uses the Jackson XML data format using the Jackson library turning pretty 469 * printing on or off 470 * 471 * @param prettyPrint turn pretty printing on or off 472 */ 473 public T jacksonxml(boolean prettyPrint) { 474 JacksonXMLDataFormat jacksonXMLDataFormat = new JacksonXMLDataFormat(); 475 jacksonXMLDataFormat.setPrettyPrint(prettyPrint); 476 return dataFormat(jacksonXMLDataFormat); 477 } 478 479 /** 480 * Uses the Jackson XML data format 481 * 482 * @param unmarshalType unmarshal type for xml jackson type 483 * @param prettyPrint turn pretty printing on or off 484 */ 485 public T jacksonxml(Class<?> unmarshalType, boolean prettyPrint) { 486 JacksonXMLDataFormat jacksonXMLDataFormat = new JacksonXMLDataFormat(); 487 jacksonXMLDataFormat.setUnmarshalType(unmarshalType); 488 jacksonXMLDataFormat.setPrettyPrint(prettyPrint); 489 return dataFormat(jacksonXMLDataFormat); 490 } 491 492 /** 493 * Uses the Jackson XML data format 494 * 495 * @param unmarshalType unmarshal type for xml jackson type 496 * @param jsonView the view type for xml jackson type 497 * @param prettyPrint turn pretty printing on or off 498 */ 499 public T jacksonxml(Class<?> unmarshalType, Class<?> jsonView, boolean prettyPrint) { 500 JacksonXMLDataFormat jacksonXMLDataFormat = new JacksonXMLDataFormat(); 501 jacksonXMLDataFormat.setUnmarshalType(unmarshalType); 502 jacksonXMLDataFormat.setJsonView(jsonView); 503 jacksonXMLDataFormat.setPrettyPrint(prettyPrint); 504 return dataFormat(jacksonXMLDataFormat); 505 } 506 507 /** 508 * Uses the Jackson XML data format 509 * 510 * @param unmarshalType unmarshal type for xml jackson type 511 * @param jsonView the view type for xml jackson type 512 * @param include include such as <tt>ALWAYS</tt>, <tt>NON_NULL</tt>, etc. 513 */ 514 public T jacksonxml(Class<?> unmarshalType, Class<?> jsonView, String include) { 515 JacksonXMLDataFormat jacksonXMLDataFormat = new JacksonXMLDataFormat(); 516 jacksonXMLDataFormat.setUnmarshalType(unmarshalType); 517 jacksonXMLDataFormat.setJsonView(jsonView); 518 jacksonXMLDataFormat.setInclude(include); 519 return dataFormat(jacksonXMLDataFormat); 520 } 521 522 /** 523 * Uses the Jackson XML data format 524 * 525 * @param unmarshalType unmarshal type for xml jackson type 526 * @param jsonView the view type for xml jackson type 527 * @param include include such as <tt>ALWAYS</tt>, <tt>NON_NULL</tt>, etc. 528 * @param prettyPrint turn pretty printing on or off 529 */ 530 public T jacksonxml(Class<?> unmarshalType, Class<?> jsonView, String include, boolean prettyPrint) { 531 JacksonXMLDataFormat jacksonXMLDataFormat = new JacksonXMLDataFormat(); 532 jacksonXMLDataFormat.setUnmarshalType(unmarshalType); 533 jacksonXMLDataFormat.setJsonView(jsonView); 534 jacksonXMLDataFormat.setInclude(include); 535 jacksonXMLDataFormat.setPrettyPrint(prettyPrint); 536 return dataFormat(jacksonXMLDataFormat); 537 } 538 539 /** 540 * Uses the JAXB data format 541 */ 542 public T jaxb() { 543 return dataFormat(new JaxbDataFormat()); 544 } 545 546 /** 547 * Uses the JAXB data format with context path 548 */ 549 public T jaxb(String contextPath) { 550 JaxbDataFormat dataFormat = new JaxbDataFormat(); 551 dataFormat.setContextPath(contextPath); 552 return dataFormat(dataFormat); 553 } 554 555 /** 556 * Uses the JAXB data format turning pretty printing on or off 557 */ 558 public T jaxb(boolean prettyPrint) { 559 return dataFormat(new JaxbDataFormat(prettyPrint)); 560 } 561 562 /** 563 * Uses the JSON data format using the XStream json library 564 */ 565 public T json() { 566 return dataFormat(new JsonDataFormat()); 567 } 568 569 /** 570 * Uses the JSON data format using the XStream json library turning pretty 571 * printing on or off 572 * 573 * @param prettyPrint turn pretty printing on or off 574 */ 575 public T json(boolean prettyPrint) { 576 JsonDataFormat json = new JsonDataFormat(); 577 json.setPrettyPrint(prettyPrint); 578 return dataFormat(json); 579 } 580 581 /** 582 * Uses the JSON data format 583 * 584 * @param library the json library to use 585 */ 586 public T json(JsonLibrary library) { 587 return dataFormat(new JsonDataFormat(library)); 588 } 589 590 /** 591 * Uses the JSON data format 592 * 593 * @param library the json library to use 594 * @param prettyPrint turn pretty printing on or off 595 */ 596 public T json(JsonLibrary library, boolean prettyPrint) { 597 JsonDataFormat json = new JsonDataFormat(library); 598 json.setPrettyPrint(prettyPrint); 599 return dataFormat(json); 600 } 601 602 /** 603 * Uses the JSON data format 604 * 605 * @param type the json type to use 606 * @param unmarshalType unmarshal type for json jackson type 607 */ 608 public T json(JsonLibrary type, Class<?> unmarshalType) { 609 JsonDataFormat json = new JsonDataFormat(type); 610 json.setUnmarshalType(unmarshalType); 611 return dataFormat(json); 612 } 613 614 /** 615 * Uses the JSON data format 616 * 617 * @param type the json type to use 618 * @param unmarshalType unmarshal type for json jackson type 619 * @param prettyPrint turn pretty printing on or off 620 */ 621 public T json(JsonLibrary type, Class<?> unmarshalType, boolean prettyPrint) { 622 JsonDataFormat json = new JsonDataFormat(type); 623 json.setUnmarshalType(unmarshalType); 624 json.setPrettyPrint(prettyPrint); 625 return dataFormat(json); 626 } 627 628 /** 629 * Uses the Jackson JSON data format 630 * 631 * @param unmarshalType unmarshal type for json jackson type 632 * @param jsonView the view type for json jackson type 633 */ 634 public T json(Class<?> unmarshalType, Class<?> jsonView) { 635 JsonDataFormat json = new JsonDataFormat(JsonLibrary.Jackson); 636 json.setUnmarshalType(unmarshalType); 637 json.setJsonView(jsonView); 638 return dataFormat(json); 639 } 640 641 /** 642 * Uses the Jackson JSON data format 643 * 644 * @param unmarshalType unmarshal type for json jackson type 645 * @param jsonView the view type for json jackson type 646 * @param prettyPrint turn pretty printing on or off 647 */ 648 public T json(Class<?> unmarshalType, Class<?> jsonView, boolean prettyPrint) { 649 JsonDataFormat json = new JsonDataFormat(JsonLibrary.Jackson); 650 json.setUnmarshalType(unmarshalType); 651 json.setJsonView(jsonView); 652 json.setPrettyPrint(prettyPrint); 653 return dataFormat(json); 654 } 655 656 /** 657 * Uses the Jackson JSON data format 658 * 659 * @param unmarshalType unmarshal type for json jackson type 660 * @param jsonView the view type for json jackson type 661 * @param include include such as <tt>ALWAYS</tt>, <tt>NON_NULL</tt>, etc. 662 */ 663 public T json(Class<?> unmarshalType, Class<?> jsonView, String include) { 664 JsonDataFormat json = new JsonDataFormat(JsonLibrary.Jackson); 665 json.setUnmarshalType(unmarshalType); 666 json.setJsonView(jsonView); 667 json.setInclude(include); 668 return dataFormat(json); 669 } 670 671 /** 672 * Uses the Jackson JSON data format 673 * 674 * @param unmarshalType unmarshal type for json jackson type 675 * @param jsonView the view type for json jackson type 676 * @param include include such as <tt>ALWAYS</tt>, <tt>NON_NULL</tt>, etc. 677 * @param prettyPrint turn pretty printing on or off 678 */ 679 public T json(Class<?> unmarshalType, Class<?> jsonView, String include, boolean prettyPrint) { 680 JsonDataFormat json = new JsonDataFormat(JsonLibrary.Jackson); 681 json.setUnmarshalType(unmarshalType); 682 json.setJsonView(jsonView); 683 json.setInclude(include); 684 json.setPrettyPrint(prettyPrint); 685 return dataFormat(json); 686 } 687 688 /** 689 * Uses the JSON API data format 690 */ 691 public T jsonApi() { 692 return dataFormat(new JsonApiDataFormat()); 693 } 694 695 /** 696 * Uses the protobuf data format 697 */ 698 public T protobuf() { 699 return dataFormat(new ProtobufDataFormat()); 700 } 701 702 public T protobuf(Object defaultInstance) { 703 ProtobufDataFormat dataFormat = new ProtobufDataFormat(); 704 dataFormat.setDefaultInstance(defaultInstance); 705 return dataFormat(dataFormat); 706 } 707 708 public T protobuf(Object defaultInstance, String contentTypeFormat) { 709 ProtobufDataFormat dataFormat = new ProtobufDataFormat(); 710 dataFormat.setDefaultInstance(defaultInstance); 711 dataFormat.setContentTypeFormat(contentTypeFormat); 712 return dataFormat(dataFormat); 713 } 714 715 public T protobuf(String instanceClassName) { 716 return dataFormat(new ProtobufDataFormat(instanceClassName)); 717 } 718 719 public T protobuf(String instanceClassName, String contentTypeFormat) { 720 return dataFormat(new ProtobufDataFormat(instanceClassName, contentTypeFormat)); 721 } 722 723 /** 724 * Uses the RSS data format 725 */ 726 public T rss() { 727 return dataFormat(new RssDataFormat()); 728 } 729 730 /** 731 * Uses the Soap 1.1 JAXB data format 732 */ 733 public T soapjaxb() { 734 return dataFormat(new SoapJaxbDataFormat()); 735 } 736 737 /** 738 * Uses the Soap 1.1 JAXB data format 739 */ 740 public T soapjaxb(String contextPath) { 741 return dataFormat(new SoapJaxbDataFormat(contextPath)); 742 } 743 744 /** 745 * Uses the Soap 1.1 JAXB data format 746 */ 747 public T soapjaxb(String contextPath, String elementNameStrategyRef) { 748 return dataFormat(new SoapJaxbDataFormat(contextPath, elementNameStrategyRef)); 749 } 750 751 /** 752 * Uses the Soap 1.1 JAXB data format 753 */ 754 public T soapjaxb(String contextPath, Object elementNameStrategy) { 755 return dataFormat(new SoapJaxbDataFormat(contextPath, elementNameStrategy)); 756 } 757 758 /** 759 * Uses the Soap 1.2 JAXB data format 760 */ 761 public T soapjaxb12() { 762 SoapJaxbDataFormat soap = new SoapJaxbDataFormat(); 763 soap.setVersion("1.2"); 764 return dataFormat(soap); 765 } 766 767 /** 768 * Uses the Soap 1.2 JAXB data format 769 */ 770 public T soapjaxb12(String contextPath) { 771 SoapJaxbDataFormat soap = new SoapJaxbDataFormat(contextPath); 772 soap.setVersion("1.2"); 773 return dataFormat(soap); 774 } 775 776 /** 777 * Uses the Soap 1.2 JAXB data format 778 */ 779 public T soapjaxb12(String contextPath, String elementNameStrategyRef) { 780 SoapJaxbDataFormat soap = new SoapJaxbDataFormat(contextPath, elementNameStrategyRef); 781 soap.setVersion("1.2"); 782 return dataFormat(soap); 783 } 784 785 /** 786 * Uses the Soap JAXB data format 787 */ 788 public T soapjaxb12(String contextPath, Object elementNameStrategy) { 789 SoapJaxbDataFormat soap = new SoapJaxbDataFormat(contextPath, elementNameStrategy); 790 soap.setVersion("1.2"); 791 return dataFormat(soap); 792 } 793 794 /** 795 * Uses the Syslog data format 796 */ 797 public T syslog() { 798 return dataFormat(new SyslogDataFormat()); 799 } 800 801 /** 802 * Uses the Thrift data format 803 */ 804 public T thrift() { 805 return dataFormat(new ThriftDataFormat()); 806 } 807 808 public T thrift(Object defaultInstance) { 809 ThriftDataFormat dataFormat = new ThriftDataFormat(); 810 dataFormat.setDefaultInstance(defaultInstance); 811 return dataFormat(dataFormat); 812 } 813 814 public T thrift(Object defaultInstance, String contentTypeFormat) { 815 ThriftDataFormat dataFormat = new ThriftDataFormat(); 816 dataFormat.setDefaultInstance(defaultInstance); 817 dataFormat.setContentTypeFormat(contentTypeFormat); 818 return dataFormat(dataFormat); 819 } 820 821 public T thrift(String instanceClassName) { 822 return dataFormat(new ThriftDataFormat(instanceClassName)); 823 } 824 825 public T thrift(String instanceClassName, String contentTypeFormat) { 826 return dataFormat(new ThriftDataFormat(instanceClassName, contentTypeFormat)); 827 } 828 829 /** 830 * Return WellFormed HTML (an XML Document) either {@link java.lang.String} 831 * or {@link org.w3c.dom.Node} 832 */ 833 public T tidyMarkup(Class<?> dataObjectType) { 834 return dataFormat(new TidyMarkupDataFormat(dataObjectType)); 835 } 836 837 /** 838 * Return TidyMarkup in the default format as {@link org.w3c.dom.Node} 839 */ 840 public T tidyMarkup() { 841 return dataFormat(new TidyMarkupDataFormat(Node.class)); 842 } 843 844 /** 845 * Uses the XStream data format. 846 * <p/> 847 * Favor using {@link #xstream(String)} to pass in a permission 848 */ 849 public T xstream() { 850 return dataFormat(new XStreamDataFormat()); 851 } 852 853 /** 854 * Uses the xstream by setting the encoding or permission 855 * 856 * @param encodingOrPermission is either an encoding or permission syntax 857 */ 858 public T xstream(String encodingOrPermission) { 859 // is it an encoding? if not we assume its a permission 860 if (Charset.isSupported(encodingOrPermission)) { 861 return xstream(encodingOrPermission, (String)null); 862 } else { 863 return xstream(null, encodingOrPermission); 864 } 865 } 866 867 /** 868 * Uses the xstream by setting the encoding 869 */ 870 public T xstream(String encoding, String permission) { 871 XStreamDataFormat xdf = new XStreamDataFormat(); 872 xdf.setPermissions(permission); 873 xdf.setEncoding(encoding); 874 return dataFormat(xdf); 875 } 876 877 /** 878 * Uses the xstream by permitting the java type 879 * 880 * @param type the pojo xstream should use as allowed permission 881 */ 882 public T xstream(Class<?> type) { 883 return xstream(null, type); 884 } 885 886 /** 887 * Uses the xstream by permitting the java type 888 * 889 * @param encoding encoding to use 890 * @param type the pojo class(es) xstream should use as allowed permission 891 */ 892 public T xstream(String encoding, Class<?>... type) { 893 CollectionStringBuffer csb = new CollectionStringBuffer(","); 894 for (Class<?> clazz : type) { 895 csb.append("+"); 896 csb.append(clazz.getName()); 897 } 898 return xstream(encoding, csb.toString()); 899 } 900 901 /** 902 * Uses the YAML data format 903 * 904 * @param library the yaml library to use 905 */ 906 public T yaml(YAMLLibrary library) { 907 return dataFormat(new YAMLDataFormat(library)); 908 } 909 910 /** 911 * Uses the YAML data format 912 * 913 * @param library the yaml type to use 914 * @param type the type for json snakeyaml type 915 */ 916 public T yaml(YAMLLibrary library, Class<?> type) { 917 return dataFormat(new YAMLDataFormat(library, type)); 918 } 919 920 /** 921 * Uses the XML Security data format 922 */ 923 public T secureXML() { 924 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 925 return dataFormat(xsdf); 926 } 927 928 /** 929 * Uses the XML Security data format 930 */ 931 public T secureXML(String secureTag, boolean secureTagContents) { 932 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 933 xsdf.setSecureTag(secureTag); 934 xsdf.setSecureTagContents(secureTagContents); 935 return dataFormat(xsdf); 936 } 937 938 /** 939 * Uses the XML Security data format 940 */ 941 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents) { 942 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 943 xsdf.setSecureTag(secureTag); 944 xsdf.setSecureTagContents(secureTagContents); 945 xsdf.setNamespaces(namespaces); 946 return dataFormat(xsdf); 947 } 948 949 /** 950 * Uses the XML Security data format 951 */ 952 public T secureXML(String secureTag, boolean secureTagContents, String passPhrase) { 953 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 954 xsdf.setSecureTag(secureTag); 955 xsdf.setSecureTagContents(secureTagContents); 956 xsdf.setPassPhrase(passPhrase); 957 return dataFormat(xsdf); 958 } 959 960 /** 961 * Uses the XML Security data format 962 */ 963 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String passPhrase) { 964 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 965 xsdf.setSecureTag(secureTag); 966 xsdf.setNamespaces(namespaces); 967 xsdf.setSecureTagContents(secureTagContents); 968 xsdf.setPassPhrase(passPhrase); 969 return dataFormat(xsdf); 970 } 971 972 /** 973 * Uses the XML Security data format 974 */ 975 public T secureXML(String secureTag, boolean secureTagContents, String passPhrase, String xmlCipherAlgorithm) { 976 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 977 xsdf.setSecureTag(secureTag); 978 xsdf.setSecureTagContents(secureTagContents); 979 xsdf.setPassPhrase(passPhrase); 980 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 981 return dataFormat(xsdf); 982 } 983 984 /** 985 * Uses the XML Security data format 986 */ 987 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String passPhrase, String xmlCipherAlgorithm) { 988 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 989 xsdf.setSecureTag(secureTag); 990 xsdf.setNamespaces(namespaces); 991 xsdf.setSecureTagContents(secureTagContents); 992 xsdf.setPassPhrase(passPhrase); 993 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 994 return dataFormat(xsdf); 995 } 996 997 /** 998 * Uses the XML Security data format 999 */ 1000 public T secureXML(String secureTag, boolean secureTagContents, byte[] passPhraseByte) { 1001 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1002 xsdf.setSecureTag(secureTag); 1003 xsdf.setSecureTagContents(secureTagContents); 1004 xsdf.setPassPhraseByte(passPhraseByte); 1005 return dataFormat(xsdf); 1006 } 1007 1008 /** 1009 * Uses the XML Security data format 1010 */ 1011 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, byte[] passPhraseByte) { 1012 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1013 xsdf.setSecureTag(secureTag); 1014 xsdf.setNamespaces(namespaces); 1015 xsdf.setSecureTagContents(secureTagContents); 1016 xsdf.setPassPhraseByte(passPhraseByte); 1017 return dataFormat(xsdf); 1018 } 1019 1020 /** 1021 * Uses the XML Security data format 1022 */ 1023 public T secureXML(String secureTag, boolean secureTagContents, byte[] passPhraseByte, String xmlCipherAlgorithm) { 1024 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1025 xsdf.setSecureTag(secureTag); 1026 xsdf.setSecureTagContents(secureTagContents); 1027 xsdf.setPassPhraseByte(passPhraseByte); 1028 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1029 return dataFormat(xsdf); 1030 } 1031 1032 /** 1033 * Uses the XML Security data format 1034 */ 1035 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, byte[] passPhraseByte, String xmlCipherAlgorithm) { 1036 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1037 xsdf.setSecureTag(secureTag); 1038 xsdf.setNamespaces(namespaces); 1039 xsdf.setSecureTagContents(secureTagContents); 1040 xsdf.setPassPhraseByte(passPhraseByte); 1041 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1042 return dataFormat(xsdf); 1043 } 1044 1045 /** 1046 * Uses the XML Security data format 1047 */ 1048 public T secureXML(String secureTag, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, String keyCipherAlgorithm, 1049 String keyOrTrustStoreParametersId) { 1050 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1051 xsdf.setSecureTag(secureTag); 1052 xsdf.setSecureTagContents(secureTagContents); 1053 xsdf.setRecipientKeyAlias(recipientKeyAlias); 1054 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1055 xsdf.setKeyCipherAlgorithm(keyCipherAlgorithm); 1056 xsdf.setKeyOrTrustStoreParametersRef(keyOrTrustStoreParametersId); 1057 return dataFormat(xsdf); 1058 } 1059 1060 /** 1061 * Uses the XML Security data format 1062 */ 1063 public T secureXML(String secureTag, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, String keyCipherAlgorithm, 1064 String keyOrTrustStoreParametersId, String keyPassword) { 1065 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1066 xsdf.setSecureTag(secureTag); 1067 xsdf.setSecureTagContents(secureTagContents); 1068 xsdf.setRecipientKeyAlias(recipientKeyAlias); 1069 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1070 xsdf.setKeyCipherAlgorithm(keyCipherAlgorithm); 1071 xsdf.setKeyOrTrustStoreParametersRef(keyOrTrustStoreParametersId); 1072 xsdf.setKeyPassword(keyPassword); 1073 return dataFormat(xsdf); 1074 } 1075 1076 /** 1077 * Uses the XML Security data format 1078 */ 1079 public T secureXML(String secureTag, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, String keyCipherAlgorithm, 1080 KeyStoreParameters keyOrTrustStoreParameters) { 1081 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1082 xsdf.setSecureTag(secureTag); 1083 xsdf.setSecureTagContents(secureTagContents); 1084 xsdf.setRecipientKeyAlias(recipientKeyAlias); 1085 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1086 xsdf.setKeyCipherAlgorithm(keyCipherAlgorithm); 1087 xsdf.setKeyOrTrustStoreParameters(keyOrTrustStoreParameters); 1088 return dataFormat(xsdf); 1089 } 1090 1091 /** 1092 * Uses the XML Security data format 1093 */ 1094 public T secureXML(String secureTag, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, String keyCipherAlgorithm, 1095 KeyStoreParameters keyOrTrustStoreParameters, String keyPassword) { 1096 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1097 xsdf.setSecureTag(secureTag); 1098 xsdf.setSecureTagContents(secureTagContents); 1099 xsdf.setRecipientKeyAlias(recipientKeyAlias); 1100 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1101 xsdf.setKeyCipherAlgorithm(keyCipherAlgorithm); 1102 xsdf.setKeyOrTrustStoreParameters(keyOrTrustStoreParameters); 1103 xsdf.setKeyPassword(keyPassword); 1104 return dataFormat(xsdf); 1105 } 1106 1107 /** 1108 * Uses the XML Security data format 1109 */ 1110 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, String keyCipherAlgorithm, 1111 String keyOrTrustStoreParametersId) { 1112 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1113 xsdf.setSecureTag(secureTag); 1114 xsdf.setSecureTagContents(secureTagContents); 1115 xsdf.setRecipientKeyAlias(recipientKeyAlias); 1116 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1117 xsdf.setKeyCipherAlgorithm(keyCipherAlgorithm); 1118 xsdf.setKeyOrTrustStoreParametersRef(keyOrTrustStoreParametersId); 1119 return dataFormat(xsdf); 1120 } 1121 1122 /** 1123 * Uses the XML Security data format 1124 */ 1125 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, String keyCipherAlgorithm, 1126 String keyOrTrustStoreParametersId, String keyPassword) { 1127 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1128 xsdf.setSecureTag(secureTag); 1129 xsdf.setSecureTagContents(secureTagContents); 1130 xsdf.setRecipientKeyAlias(recipientKeyAlias); 1131 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1132 xsdf.setKeyCipherAlgorithm(keyCipherAlgorithm); 1133 xsdf.setKeyOrTrustStoreParametersRef(keyOrTrustStoreParametersId); 1134 xsdf.setKeyPassword(keyPassword); 1135 return dataFormat(xsdf); 1136 } 1137 1138 /** 1139 * Uses the XML Security data format 1140 */ 1141 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, String keyCipherAlgorithm, 1142 KeyStoreParameters keyOrTrustStoreParameters) { 1143 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1144 xsdf.setSecureTag(secureTag); 1145 xsdf.setNamespaces(namespaces); 1146 xsdf.setSecureTagContents(secureTagContents); 1147 xsdf.setRecipientKeyAlias(recipientKeyAlias); 1148 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1149 xsdf.setKeyCipherAlgorithm(keyCipherAlgorithm); 1150 xsdf.setKeyOrTrustStoreParameters(keyOrTrustStoreParameters); 1151 return dataFormat(xsdf); 1152 } 1153 1154 /** 1155 * Uses the XML Security data format 1156 */ 1157 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, String keyCipherAlgorithm, 1158 KeyStoreParameters keyOrTrustStoreParameters, String keyPassword) { 1159 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1160 xsdf.setSecureTag(secureTag); 1161 xsdf.setNamespaces(namespaces); 1162 xsdf.setSecureTagContents(secureTagContents); 1163 xsdf.setRecipientKeyAlias(recipientKeyAlias); 1164 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1165 xsdf.setKeyCipherAlgorithm(keyCipherAlgorithm); 1166 xsdf.setKeyOrTrustStoreParameters(keyOrTrustStoreParameters); 1167 xsdf.setKeyPassword(keyPassword); 1168 return dataFormat(xsdf); 1169 } 1170 1171 /** 1172 * Uses the XML Security data format 1173 */ 1174 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, String keyCipherAlgorithm, 1175 KeyStoreParameters keyOrTrustStoreParameters, String keyPassword, String digestAlgorithm) { 1176 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1177 xsdf.setSecureTag(secureTag); 1178 xsdf.setNamespaces(namespaces); 1179 xsdf.setSecureTagContents(secureTagContents); 1180 xsdf.setRecipientKeyAlias(recipientKeyAlias); 1181 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1182 xsdf.setKeyCipherAlgorithm(keyCipherAlgorithm); 1183 xsdf.setKeyOrTrustStoreParameters(keyOrTrustStoreParameters); 1184 xsdf.setDigestAlgorithm(digestAlgorithm); 1185 xsdf.setKeyPassword(keyPassword); 1186 return dataFormat(xsdf); 1187 } 1188 1189 /** 1190 * Uses the Tar file data format 1191 */ 1192 public T tarFile() { 1193 TarFileDataFormat tfdf = new TarFileDataFormat(); 1194 return dataFormat(tfdf); 1195 } 1196 1197 /** 1198 * Uses the ZIP deflater data format 1199 */ 1200 public T zipDeflater() { 1201 ZipDeflaterDataFormat zdf = new ZipDeflaterDataFormat(); 1202 return dataFormat(zdf); 1203 } 1204 1205 /** 1206 * Uses the ZIP deflater data format 1207 */ 1208 public T zipDeflater(int compressionLevel) { 1209 ZipDeflaterDataFormat zdf = new ZipDeflaterDataFormat(); 1210 zdf.setCompressionLevel(compressionLevel); 1211 return dataFormat(zdf); 1212 } 1213 1214 /** 1215 * Uses the ZIP file data format 1216 */ 1217 public T zipFile() { 1218 ZipFileDataFormat zfdf = new ZipFileDataFormat(); 1219 return dataFormat(zfdf); 1220 } 1221 1222 /** 1223 * Uses the ASN.1 file data format 1224 */ 1225 public T asn1() { 1226 ASN1DataFormat asn1Df = new ASN1DataFormat(); 1227 return dataFormat(asn1Df); 1228 } 1229 1230 public T asn1(String clazzName) { 1231 return dataFormat(new ASN1DataFormat(clazzName)); 1232 } 1233 1234 public T asn1(Boolean usingIterator) { 1235 return dataFormat(new ASN1DataFormat(usingIterator)); 1236 } 1237 1238 /** 1239 * Uses the FHIR JSON data format 1240 */ 1241 public T fhirJson() { 1242 FhirJsonDataFormat jsonDataFormat = new FhirJsonDataFormat(); 1243 return dataFormat(jsonDataFormat); 1244 } 1245 1246 public T fhirJson(String version) { 1247 FhirJsonDataFormat jsonDataFormat = new FhirJsonDataFormat(); 1248 jsonDataFormat.setFhirVersion(version); 1249 return dataFormat(jsonDataFormat); 1250 } 1251 1252 public T fhirJson(boolean prettyPrint) { 1253 FhirJsonDataFormat jsonDataFormat = new FhirJsonDataFormat(); 1254 jsonDataFormat.setPrettyPrint(prettyPrint); 1255 return dataFormat(jsonDataFormat); 1256 } 1257 1258 public T fhirJson(String version, boolean prettyPrint) { 1259 FhirJsonDataFormat jsonDataFormat = new FhirJsonDataFormat(); 1260 jsonDataFormat.setPrettyPrint(prettyPrint); 1261 jsonDataFormat.setFhirVersion(version); 1262 return dataFormat(jsonDataFormat); 1263 } 1264 1265 /** 1266 * Uses the FHIR XML data format 1267 */ 1268 public T fhirXml() { 1269 FhirXmlDataFormat fhirXmlDataFormat = new FhirXmlDataFormat(); 1270 return dataFormat(fhirXmlDataFormat); 1271 } 1272 1273 public T fhirXml(String version) { 1274 FhirXmlDataFormat fhirXmlDataFormat = new FhirXmlDataFormat(); 1275 fhirXmlDataFormat.setFhirVersion(version); 1276 return dataFormat(fhirXmlDataFormat); 1277 } 1278 1279 public T fhirXml(boolean prettyPrint) { 1280 FhirXmlDataFormat fhirXmlDataFormat = new FhirXmlDataFormat(); 1281 fhirXmlDataFormat.setPrettyPrint(prettyPrint); 1282 return dataFormat(fhirXmlDataFormat); 1283 } 1284 1285 public T fhirXml(String version, boolean prettyPrint) { 1286 FhirXmlDataFormat fhirXmlDataFormat = new FhirXmlDataFormat(); 1287 fhirXmlDataFormat.setFhirVersion(version); 1288 fhirXmlDataFormat.setPrettyPrint(prettyPrint); 1289 return dataFormat(fhirXmlDataFormat); 1290 } 1291 1292 @SuppressWarnings("unchecked") 1293 private T dataFormat(DataFormatDefinition dataFormatType) { 1294 switch (operation) { 1295 case Unmarshal: 1296 return (T)processorType.unmarshal(dataFormatType); 1297 case Marshal: 1298 return (T)processorType.marshal(dataFormatType); 1299 default: 1300 throw new IllegalArgumentException("Unknown DataFormat operation: " + operation); 1301 } 1302 } 1303}