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(Integer.toString(lineLength)); 138 dataFormat.setLineSeparator(lineSeparator); 139 dataFormat.setUrlSafe(Boolean.toString(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(Boolean.toString(ignoreUnidentifiedRecords)); 173 dataFormat.setIgnoreUnexpectedRecords(Boolean.toString(ignoreUnexpectedRecords)); 174 dataFormat.setIgnoreInvalidRecords(Boolean.toString(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.name()); 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.name()); 214 bindy.setClassType(classType); 215 bindy.setUnwrapSingleInstance(Boolean.toString(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(Boolean.toString(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(Boolean.toString(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(Boolean.toString(multipartWithoutAttachment)); 353 mm.setHeadersInline(Boolean.toString(headersInline)); 354 mm.setBinaryContent(Boolean.toString(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(Boolean.toString(multipartWithoutAttachment)); 377 mm.setHeadersInline(Boolean.toString(headersInline)); 378 mm.setIncludeHeaders(includeHeaders); 379 mm.setBinaryContent(Boolean.toString(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(Boolean.toString(multipartWithoutAttachment)); 397 mm.setHeadersInline(Boolean.toString(headersInline)); 398 mm.setBinaryContent(Boolean.toString(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(Boolean.toString(armored)); 432 pgp.setIntegrity(Boolean.toString(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(Boolean.toString(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(Boolean.toString(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(Boolean.toString(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(Boolean.toString(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 Jackson library 564 */ 565 public T json() { 566 return dataFormat(new JsonDataFormat()); 567 } 568 569 /** 570 * Uses the JSON data format using the Jackson 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(Boolean.toString(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(Boolean.toString(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(Boolean.toString(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(Boolean.toString(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(Boolean.toString(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(byte[] passPhraseByte) { 924 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 925 xsdf.setPassPhraseByte(passPhraseByte); 926 return dataFormat(xsdf); 927 } 928 929 /** 930 * Uses the XML Security data format 931 */ 932 public T secureXML(String secureTag, boolean secureTagContents, String passPhrase) { 933 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 934 xsdf.setSecureTag(secureTag); 935 xsdf.setSecureTagContents(Boolean.toString(secureTagContents)); 936 xsdf.setPassPhrase(passPhrase); 937 return dataFormat(xsdf); 938 } 939 940 /** 941 * Uses the XML Security data format 942 */ 943 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String passPhrase) { 944 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 945 xsdf.setSecureTag(secureTag); 946 xsdf.setNamespaces(namespaces); 947 xsdf.setSecureTagContents(Boolean.toString(secureTagContents)); 948 xsdf.setPassPhrase(passPhrase); 949 return dataFormat(xsdf); 950 } 951 952 /** 953 * Uses the XML Security data format 954 */ 955 public T secureXML(String secureTag, boolean secureTagContents, String passPhrase, String xmlCipherAlgorithm) { 956 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 957 xsdf.setSecureTag(secureTag); 958 xsdf.setSecureTagContents(Boolean.toString(secureTagContents)); 959 xsdf.setPassPhrase(passPhrase); 960 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 961 return dataFormat(xsdf); 962 } 963 964 /** 965 * Uses the XML Security data format 966 */ 967 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String passPhrase, String xmlCipherAlgorithm) { 968 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 969 xsdf.setSecureTag(secureTag); 970 xsdf.setNamespaces(namespaces); 971 xsdf.setSecureTagContents(Boolean.toString(secureTagContents)); 972 xsdf.setPassPhrase(passPhrase); 973 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 974 return dataFormat(xsdf); 975 } 976 977 /** 978 * Uses the XML Security data format 979 */ 980 public T secureXML(String secureTag, boolean secureTagContents, byte[] passPhraseByte) { 981 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 982 xsdf.setSecureTag(secureTag); 983 xsdf.setSecureTagContents(Boolean.toString(secureTagContents)); 984 xsdf.setPassPhraseByte(passPhraseByte); 985 return dataFormat(xsdf); 986 } 987 988 /** 989 * Uses the XML Security data format 990 */ 991 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, byte[] passPhraseByte) { 992 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 993 xsdf.setSecureTag(secureTag); 994 xsdf.setNamespaces(namespaces); 995 xsdf.setSecureTagContents(Boolean.toString(secureTagContents)); 996 xsdf.setPassPhraseByte(passPhraseByte); 997 return dataFormat(xsdf); 998 } 999 1000 /** 1001 * Uses the XML Security data format 1002 */ 1003 public T secureXML(String secureTag, boolean secureTagContents, byte[] passPhraseByte, String xmlCipherAlgorithm) { 1004 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1005 xsdf.setSecureTag(secureTag); 1006 xsdf.setSecureTagContents(Boolean.toString(secureTagContents)); 1007 xsdf.setPassPhraseByte(passPhraseByte); 1008 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1009 return dataFormat(xsdf); 1010 } 1011 1012 /** 1013 * Uses the XML Security data format 1014 */ 1015 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, byte[] passPhraseByte, String xmlCipherAlgorithm) { 1016 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1017 xsdf.setSecureTag(secureTag); 1018 xsdf.setNamespaces(namespaces); 1019 xsdf.setSecureTagContents(Boolean.toString(secureTagContents)); 1020 xsdf.setPassPhraseByte(passPhraseByte); 1021 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1022 return dataFormat(xsdf); 1023 } 1024 1025 /** 1026 * Uses the XML Security data format 1027 */ 1028 public T secureXML(String secureTag, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, String keyCipherAlgorithm, 1029 String keyOrTrustStoreParametersId) { 1030 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1031 xsdf.setSecureTag(secureTag); 1032 xsdf.setSecureTagContents(Boolean.toString(secureTagContents)); 1033 xsdf.setRecipientKeyAlias(recipientKeyAlias); 1034 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1035 xsdf.setKeyCipherAlgorithm(keyCipherAlgorithm); 1036 xsdf.setKeyOrTrustStoreParametersRef(keyOrTrustStoreParametersId); 1037 return dataFormat(xsdf); 1038 } 1039 1040 /** 1041 * Uses the XML Security data format 1042 */ 1043 public T secureXML(String secureTag, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, String keyCipherAlgorithm, 1044 String keyOrTrustStoreParametersId, String keyPassword) { 1045 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1046 xsdf.setSecureTag(secureTag); 1047 xsdf.setSecureTagContents(Boolean.toString(secureTagContents)); 1048 xsdf.setRecipientKeyAlias(recipientKeyAlias); 1049 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1050 xsdf.setKeyCipherAlgorithm(keyCipherAlgorithm); 1051 xsdf.setKeyOrTrustStoreParametersRef(keyOrTrustStoreParametersId); 1052 xsdf.setKeyPassword(keyPassword); 1053 return dataFormat(xsdf); 1054 } 1055 1056 /** 1057 * Uses the XML Security data format 1058 */ 1059 public T secureXML(String secureTag, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, String keyCipherAlgorithm, 1060 KeyStoreParameters keyOrTrustStoreParameters) { 1061 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1062 xsdf.setSecureTag(secureTag); 1063 xsdf.setSecureTagContents(Boolean.toString(secureTagContents)); 1064 xsdf.setRecipientKeyAlias(recipientKeyAlias); 1065 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1066 xsdf.setKeyCipherAlgorithm(keyCipherAlgorithm); 1067 xsdf.setKeyOrTrustStoreParameters(keyOrTrustStoreParameters); 1068 return dataFormat(xsdf); 1069 } 1070 1071 /** 1072 * Uses the XML Security data format 1073 */ 1074 public T secureXML(String secureTag, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, String keyCipherAlgorithm, 1075 KeyStoreParameters keyOrTrustStoreParameters, String keyPassword) { 1076 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1077 xsdf.setSecureTag(secureTag); 1078 xsdf.setSecureTagContents(Boolean.toString(secureTagContents)); 1079 xsdf.setRecipientKeyAlias(recipientKeyAlias); 1080 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1081 xsdf.setKeyCipherAlgorithm(keyCipherAlgorithm); 1082 xsdf.setKeyOrTrustStoreParameters(keyOrTrustStoreParameters); 1083 xsdf.setKeyPassword(keyPassword); 1084 return dataFormat(xsdf); 1085 } 1086 1087 /** 1088 * Uses the XML Security data format 1089 */ 1090 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, String keyCipherAlgorithm, 1091 String keyOrTrustStoreParametersId) { 1092 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1093 xsdf.setSecureTag(secureTag); 1094 xsdf.setSecureTagContents(Boolean.toString(secureTagContents)); 1095 xsdf.setRecipientKeyAlias(recipientKeyAlias); 1096 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1097 xsdf.setKeyCipherAlgorithm(keyCipherAlgorithm); 1098 xsdf.setKeyOrTrustStoreParametersRef(keyOrTrustStoreParametersId); 1099 return dataFormat(xsdf); 1100 } 1101 1102 /** 1103 * Uses the XML Security data format 1104 */ 1105 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, String keyCipherAlgorithm, 1106 String keyOrTrustStoreParametersId, String keyPassword) { 1107 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1108 xsdf.setSecureTag(secureTag); 1109 xsdf.setSecureTagContents(Boolean.toString(secureTagContents)); 1110 xsdf.setRecipientKeyAlias(recipientKeyAlias); 1111 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1112 xsdf.setKeyCipherAlgorithm(keyCipherAlgorithm); 1113 xsdf.setKeyOrTrustStoreParametersRef(keyOrTrustStoreParametersId); 1114 xsdf.setKeyPassword(keyPassword); 1115 return dataFormat(xsdf); 1116 } 1117 1118 /** 1119 * Uses the XML Security data format 1120 */ 1121 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, String keyCipherAlgorithm, 1122 KeyStoreParameters keyOrTrustStoreParameters) { 1123 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1124 xsdf.setSecureTag(secureTag); 1125 xsdf.setNamespaces(namespaces); 1126 xsdf.setSecureTagContents(Boolean.toString(secureTagContents)); 1127 xsdf.setRecipientKeyAlias(recipientKeyAlias); 1128 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1129 xsdf.setKeyCipherAlgorithm(keyCipherAlgorithm); 1130 xsdf.setKeyOrTrustStoreParameters(keyOrTrustStoreParameters); 1131 return dataFormat(xsdf); 1132 } 1133 1134 /** 1135 * Uses the XML Security data format 1136 */ 1137 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, String keyCipherAlgorithm, 1138 KeyStoreParameters keyOrTrustStoreParameters, String keyPassword) { 1139 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1140 xsdf.setSecureTag(secureTag); 1141 xsdf.setNamespaces(namespaces); 1142 xsdf.setSecureTagContents(Boolean.toString(secureTagContents)); 1143 xsdf.setRecipientKeyAlias(recipientKeyAlias); 1144 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1145 xsdf.setKeyCipherAlgorithm(keyCipherAlgorithm); 1146 xsdf.setKeyOrTrustStoreParameters(keyOrTrustStoreParameters); 1147 xsdf.setKeyPassword(keyPassword); 1148 return dataFormat(xsdf); 1149 } 1150 1151 /** 1152 * Uses the XML Security data format 1153 */ 1154 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, String keyCipherAlgorithm, 1155 KeyStoreParameters keyOrTrustStoreParameters, String keyPassword, String digestAlgorithm) { 1156 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 1157 xsdf.setSecureTag(secureTag); 1158 xsdf.setNamespaces(namespaces); 1159 xsdf.setSecureTagContents(Boolean.toString(secureTagContents)); 1160 xsdf.setRecipientKeyAlias(recipientKeyAlias); 1161 xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm); 1162 xsdf.setKeyCipherAlgorithm(keyCipherAlgorithm); 1163 xsdf.setKeyOrTrustStoreParameters(keyOrTrustStoreParameters); 1164 xsdf.setDigestAlgorithm(digestAlgorithm); 1165 xsdf.setKeyPassword(keyPassword); 1166 return dataFormat(xsdf); 1167 } 1168 1169 /** 1170 * Uses the Tar file data format 1171 */ 1172 public T tarFile() { 1173 TarFileDataFormat tfdf = new TarFileDataFormat(); 1174 return dataFormat(tfdf); 1175 } 1176 1177 /** 1178 * Uses the ZIP deflater data format 1179 */ 1180 public T zipDeflater() { 1181 ZipDeflaterDataFormat zdf = new ZipDeflaterDataFormat(); 1182 return dataFormat(zdf); 1183 } 1184 1185 /** 1186 * Uses the ZIP deflater data format 1187 */ 1188 public T zipDeflater(int compressionLevel) { 1189 ZipDeflaterDataFormat zdf = new ZipDeflaterDataFormat(); 1190 zdf.setCompressionLevel(Integer.toString(compressionLevel)); 1191 return dataFormat(zdf); 1192 } 1193 1194 /** 1195 * Uses the ZIP file data format 1196 */ 1197 public T zipFile() { 1198 ZipFileDataFormat zfdf = new ZipFileDataFormat(); 1199 return dataFormat(zfdf); 1200 } 1201 1202 /** 1203 * Uses the ASN.1 file data format 1204 */ 1205 public T asn1() { 1206 ASN1DataFormat asn1Df = new ASN1DataFormat(); 1207 return dataFormat(asn1Df); 1208 } 1209 1210 public T asn1(String clazzName) { 1211 return dataFormat(new ASN1DataFormat(clazzName)); 1212 } 1213 1214 public T asn1(Boolean usingIterator) { 1215 return dataFormat(new ASN1DataFormat(usingIterator)); 1216 } 1217 1218 /** 1219 * Uses the FHIR JSON data format 1220 */ 1221 public T fhirJson() { 1222 FhirJsonDataFormat jsonDataFormat = new FhirJsonDataFormat(); 1223 return dataFormat(jsonDataFormat); 1224 } 1225 1226 public T fhirJson(String version) { 1227 FhirJsonDataFormat jsonDataFormat = new FhirJsonDataFormat(); 1228 jsonDataFormat.setFhirVersion(version); 1229 return dataFormat(jsonDataFormat); 1230 } 1231 1232 public T fhirJson(boolean prettyPrint) { 1233 FhirJsonDataFormat jsonDataFormat = new FhirJsonDataFormat(); 1234 jsonDataFormat.setPrettyPrint(Boolean.toString(prettyPrint)); 1235 return dataFormat(jsonDataFormat); 1236 } 1237 1238 public T fhirJson(String version, boolean prettyPrint) { 1239 FhirJsonDataFormat jsonDataFormat = new FhirJsonDataFormat(); 1240 jsonDataFormat.setPrettyPrint(Boolean.toString(prettyPrint)); 1241 jsonDataFormat.setFhirVersion(version); 1242 return dataFormat(jsonDataFormat); 1243 } 1244 1245 /** 1246 * Uses the FHIR XML data format 1247 */ 1248 public T fhirXml() { 1249 FhirXmlDataFormat fhirXmlDataFormat = new FhirXmlDataFormat(); 1250 return dataFormat(fhirXmlDataFormat); 1251 } 1252 1253 public T fhirXml(String version) { 1254 FhirXmlDataFormat fhirXmlDataFormat = new FhirXmlDataFormat(); 1255 fhirXmlDataFormat.setFhirVersion(version); 1256 return dataFormat(fhirXmlDataFormat); 1257 } 1258 1259 public T fhirXml(boolean prettyPrint) { 1260 FhirXmlDataFormat fhirXmlDataFormat = new FhirXmlDataFormat(); 1261 fhirXmlDataFormat.setPrettyPrint(Boolean.toString(prettyPrint)); 1262 return dataFormat(fhirXmlDataFormat); 1263 } 1264 1265 public T fhirXml(String version, boolean prettyPrint) { 1266 FhirXmlDataFormat fhirXmlDataFormat = new FhirXmlDataFormat(); 1267 fhirXmlDataFormat.setFhirVersion(version); 1268 fhirXmlDataFormat.setPrettyPrint(Boolean.toString(prettyPrint)); 1269 return dataFormat(fhirXmlDataFormat); 1270 } 1271 1272 @SuppressWarnings("unchecked") 1273 private T dataFormat(DataFormatDefinition dataFormatType) { 1274 switch (operation) { 1275 case Unmarshal: 1276 return (T)processorType.unmarshal(dataFormatType); 1277 case Marshal: 1278 return (T)processorType.marshal(dataFormatType); 1279 default: 1280 throw new IllegalArgumentException("Unknown DataFormat operation: " + operation); 1281 } 1282 } 1283}