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