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