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