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.util.Map; 020import java.util.zip.Deflater; 021 022import org.w3c.dom.Node; 023 024import org.apache.camel.model.DataFormatDefinition; 025import org.apache.camel.model.ProcessorDefinition; 026import org.apache.camel.model.dataformat.AvroDataFormat; 027import org.apache.camel.model.dataformat.Base64DataFormat; 028import org.apache.camel.model.dataformat.BeanioDataFormat; 029import org.apache.camel.model.dataformat.BindyDataFormat; 030import org.apache.camel.model.dataformat.BindyType; 031import org.apache.camel.model.dataformat.CastorDataFormat; 032import org.apache.camel.model.dataformat.CsvDataFormat; 033import org.apache.camel.model.dataformat.CustomDataFormat; 034import org.apache.camel.model.dataformat.GzipDataFormat; 035import org.apache.camel.model.dataformat.HL7DataFormat; 036import org.apache.camel.model.dataformat.IcalDataFormat; 037import org.apache.camel.model.dataformat.JaxbDataFormat; 038import org.apache.camel.model.dataformat.JibxDataFormat; 039import org.apache.camel.model.dataformat.JsonDataFormat; 040import org.apache.camel.model.dataformat.JsonLibrary; 041import org.apache.camel.model.dataformat.PGPDataFormat; 042import org.apache.camel.model.dataformat.ProtobufDataFormat; 043import org.apache.camel.model.dataformat.RssDataFormat; 044import org.apache.camel.model.dataformat.SerializationDataFormat; 045import org.apache.camel.model.dataformat.SoapJaxbDataFormat; 046import org.apache.camel.model.dataformat.StringDataFormat; 047import org.apache.camel.model.dataformat.SyslogDataFormat; 048import org.apache.camel.model.dataformat.TidyMarkupDataFormat; 049import org.apache.camel.model.dataformat.XMLBeansDataFormat; 050import org.apache.camel.model.dataformat.XMLSecurityDataFormat; 051import org.apache.camel.model.dataformat.XStreamDataFormat; 052import org.apache.camel.model.dataformat.XmlJsonDataFormat; 053import org.apache.camel.model.dataformat.ZipDataFormat; 054import org.apache.camel.model.dataformat.ZipFileDataFormat; 055import org.apache.camel.util.jsse.KeyStoreParameters; 056 057/** 058 * An expression for constructing the different possible {@link org.apache.camel.spi.DataFormat} 059 * options. 060 * 061 * @version 062 */ 063public class DataFormatClause<T extends ProcessorDefinition<?>> { 064 private final T processorType; 065 private final Operation operation; 066 067 /** 068 * {@link org.apache.camel.spi.DataFormat} operations. 069 */ 070 public enum Operation { 071 Marshal, Unmarshal 072 } 073 074 public DataFormatClause(T processorType, Operation operation) { 075 this.processorType = processorType; 076 this.operation = operation; 077 } 078 079 /** 080 * Uses the Avro data format 081 */ 082 public T avro() { 083 return dataFormat(new AvroDataFormat()); 084 } 085 086 public T avro(Object schema) { 087 AvroDataFormat dataFormat = new AvroDataFormat(); 088 dataFormat.setSchema(schema); 089 return dataFormat(dataFormat); 090 } 091 092 public T avro(String instanceClassName) { 093 return dataFormat(new AvroDataFormat(instanceClassName)); 094 } 095 096 /** 097 * Uses the base64 data format 098 */ 099 public T base64() { 100 Base64DataFormat dataFormat = new Base64DataFormat(); 101 return dataFormat(dataFormat); 102 } 103 104 /** 105 * Uses the base64 data format 106 */ 107 public T base64(int lineLength, String lineSeparator, boolean urlSafe) { 108 Base64DataFormat dataFormat = new Base64DataFormat(); 109 dataFormat.setLineLength(lineLength); 110 dataFormat.setLineSeparator(lineSeparator); 111 dataFormat.setUrlSafe(urlSafe); 112 return dataFormat(dataFormat); 113 } 114 115 /** 116 * Uses the beanio data format 117 */ 118 public T beanio(String mapping, String streamName) { 119 BeanioDataFormat dataFormat = new BeanioDataFormat(); 120 dataFormat.setMapping(mapping); 121 dataFormat.setStreamName(streamName); 122 return dataFormat(dataFormat); 123 } 124 125 /** 126 * Uses the beanio data format 127 */ 128 public T beanio(String mapping, String streamName, String encoding) { 129 BeanioDataFormat dataFormat = new BeanioDataFormat(); 130 dataFormat.setMapping(mapping); 131 dataFormat.setStreamName(streamName); 132 dataFormat.setEncoding(encoding); 133 return dataFormat(dataFormat); 134 } 135 136 /** 137 * Uses the beanio data format 138 */ 139 public T beanio(String mapping, String streamName, String encoding, 140 boolean ignoreUnidentifiedRecords, boolean ignoreUnexpectedRecords, boolean ignoreInvalidRecords) { 141 BeanioDataFormat dataFormat = new BeanioDataFormat(); 142 dataFormat.setMapping(mapping); 143 dataFormat.setStreamName(streamName); 144 dataFormat.setEncoding(encoding); 145 dataFormat.setIgnoreUnidentifiedRecords(ignoreUnidentifiedRecords); 146 dataFormat.setIgnoreUnexpectedRecords(ignoreUnexpectedRecords); 147 dataFormat.setIgnoreInvalidRecords(ignoreInvalidRecords); 148 return dataFormat(dataFormat); 149 } 150 151 /** 152 * Uses the Bindy data format 153 * 154 * @param type the type of bindy data format to use 155 * @param packages packages to scan for Bindy annotated POJO classes 156 */ 157 public T bindy(BindyType type, String... packages) { 158 BindyDataFormat bindy = new BindyDataFormat(); 159 bindy.setType(type); 160 bindy.setPackages(packages); 161 return dataFormat(bindy); 162 } 163 164 /** 165 * Uses the Bindy data format 166 * 167 * @param type the type of bindy data format to use 168 * @param classType the POJO class type 169 */ 170 public T bindy(BindyType type, Class<?> classType) { 171 BindyDataFormat bindy = new BindyDataFormat(); 172 bindy.setType(type); 173 bindy.setClassType(classType); 174 return dataFormat(bindy); 175 } 176 177 /** 178 * Uses the CSV data format 179 */ 180 public T csv() { 181 return dataFormat(new CsvDataFormat()); 182 } 183 184 /** 185 * Uses the CSV data format for a huge file. 186 * Sequential access through an iterator. 187 */ 188 public T csvLazyLoad() { 189 return dataFormat(new CsvDataFormat(true)); 190 } 191 192 /** 193 * Uses the custom data format 194 */ 195 public T custom(String ref) { 196 return dataFormat(new CustomDataFormat(ref)); 197 } 198 199 /** 200 * Uses the Castor data format 201 */ 202 public T castor() { 203 return dataFormat(new CastorDataFormat()); 204 } 205 206 /** 207 * Uses the Castor data format 208 * 209 * @param mappingFile name of mapping file to locate in classpath 210 */ 211 public T castor(String mappingFile) { 212 CastorDataFormat castor = new CastorDataFormat(); 213 castor.setMappingFile(mappingFile); 214 return dataFormat(castor); 215 } 216 217 /** 218 * Uses the Castor data format 219 * 220 * @param mappingFile name of mapping file to locate in classpath 221 * @param validation whether validation is enabled or not 222 */ 223 public T castor(String mappingFile, boolean validation) { 224 CastorDataFormat castor = new CastorDataFormat(); 225 castor.setMappingFile(mappingFile); 226 castor.setValidation(validation); 227 return dataFormat(castor); 228 } 229 230 /** 231 * Uses the GZIP deflater data format 232 */ 233 public T gzip() { 234 GzipDataFormat gzdf = new GzipDataFormat(); 235 return dataFormat(gzdf); 236 } 237 238 /** 239 * Uses the HL7 data format 240 */ 241 public T hl7() { 242 return dataFormat(new HL7DataFormat()); 243 } 244 245 /** 246 * Uses the HL7 data format 247 */ 248 public T hl7(boolean validate) { 249 HL7DataFormat hl7 = new HL7DataFormat(); 250 hl7.setValidate(validate); 251 return dataFormat(hl7); 252 } 253 254 /** 255 * Uses the HL7 data format 256 */ 257 public T hl7(Object parser) { 258 HL7DataFormat hl7 = new HL7DataFormat(); 259 hl7.setParser(parser); 260 return dataFormat(hl7); 261 } 262 263 /** 264 * Uses the iCal data format 265 */ 266 public T ical(boolean validating) { 267 IcalDataFormat ical = new IcalDataFormat(); 268 ical.setValidating(validating); 269 return dataFormat(ical); 270 } 271 272 /** 273 * Uses the PGP data format 274 */ 275 public T pgp(String keyFileName, String keyUserid) { 276 PGPDataFormat pgp = new PGPDataFormat(); 277 pgp.setKeyFileName(keyFileName); 278 pgp.setKeyUserid(keyUserid); 279 return dataFormat(pgp); 280 } 281 282 /** 283 * Uses the PGP data format 284 */ 285 public T pgp(String keyFileName, String keyUserid, String password) { 286 PGPDataFormat pgp = new PGPDataFormat(); 287 pgp.setKeyFileName(keyFileName); 288 pgp.setKeyUserid(keyUserid); 289 pgp.setPassword(password); 290 return dataFormat(pgp); 291 } 292 293 /** 294 * Uses the PGP data format 295 */ 296 public T pgp(String keyFileName, String keyUserid, String password, boolean armored, boolean integrity) { 297 PGPDataFormat pgp = new PGPDataFormat(); 298 pgp.setKeyFileName(keyFileName); 299 pgp.setKeyUserid(keyUserid); 300 pgp.setPassword(password); 301 pgp.setArmored(armored); 302 pgp.setIntegrity(integrity); 303 return dataFormat(pgp); 304 } 305 306 /** 307 * Uses the JAXB data format 308 */ 309 public T jaxb() { 310 return dataFormat(new JaxbDataFormat()); 311 } 312 313 /** 314 * Uses the JAXB data format with context path 315 */ 316 public T jaxb(String contextPath) { 317 JaxbDataFormat dataFormat = new JaxbDataFormat(); 318 dataFormat.setContextPath(contextPath); 319 return dataFormat(dataFormat); 320 } 321 322 /** 323 * Uses the JAXB data format turning pretty printing on or off 324 */ 325 public T jaxb(boolean prettyPrint) { 326 return dataFormat(new JaxbDataFormat(prettyPrint)); 327 } 328 329 /** 330 * Uses the JiBX data format. 331 */ 332 public T jibx() { 333 return dataFormat(new JibxDataFormat()); 334 } 335 336 /** 337 * Uses the JiBX data format with unmarshall class. 338 */ 339 public T jibx(Class<?> unmarshallClass) { 340 return dataFormat(new JibxDataFormat(unmarshallClass)); 341 } 342 343 /** 344 * Uses the JSON data format using the XStream json library 345 */ 346 public T json() { 347 return dataFormat(new JsonDataFormat()); 348 } 349 350 /** 351 * Uses the JSON data format 352 * 353 * @param library the json library to use 354 */ 355 public T json(JsonLibrary library) { 356 return dataFormat(new JsonDataFormat(library)); 357 } 358 359 /** 360 * Uses the JSON data format 361 * 362 * @param type the json type to use 363 * @param unmarshalType unmarshal type for json jackson type 364 */ 365 public T json(JsonLibrary type, Class<?> unmarshalType) { 366 JsonDataFormat json = new JsonDataFormat(type); 367 json.setUnmarshalType(unmarshalType); 368 return dataFormat(json); 369 } 370 371 /** 372 * Uses the Jackson JSON data format 373 * 374 * @param unmarshalType unmarshal type for json jackson type 375 * @param jsonView the view type for json jackson type 376 */ 377 public T json(Class<?> unmarshalType, Class<?> jsonView) { 378 JsonDataFormat json = new JsonDataFormat(JsonLibrary.Jackson); 379 json.setUnmarshalType(unmarshalType); 380 json.setJsonView(jsonView); 381 return dataFormat(json); 382 } 383 384 /** 385 * Uses the Jackson JSON data format 386 * 387 * @param unmarshalType unmarshal type for json jackson type 388 * @param jsonView the view type for json jackson type 389 * @param include include such as <tt>ALWAYS</tt>, <tt>NON_NULL</tt>, etc. 390 */ 391 public T json(Class<?> unmarshalType, Class<?> jsonView, String include) { 392 JsonDataFormat json = new JsonDataFormat(JsonLibrary.Jackson); 393 json.setUnmarshalType(unmarshalType); 394 json.setJsonView(jsonView); 395 json.setInclude(include); 396 return dataFormat(json); 397 } 398 399 /** 400 * Uses the protobuf data format 401 */ 402 public T protobuf() { 403 return dataFormat(new ProtobufDataFormat()); 404 } 405 406 public T protobuf(Object defaultInstance) { 407 ProtobufDataFormat dataFormat = new ProtobufDataFormat(); 408 dataFormat.setDefaultInstance(defaultInstance); 409 return dataFormat(dataFormat); 410 } 411 412 public T protobuf(String instanceClassName) { 413 return dataFormat(new ProtobufDataFormat(instanceClassName)); 414 } 415 416 /** 417 * Uses the RSS data format 418 */ 419 public T rss() { 420 return dataFormat(new RssDataFormat()); 421 } 422 423 /** 424 * Uses the Java Serialization data format 425 */ 426 public T serialization() { 427 return dataFormat(new SerializationDataFormat()); 428 } 429 430 /** 431 * Uses the Soap 1.1 JAXB data format 432 */ 433 public T soapjaxb() { 434 return dataFormat(new SoapJaxbDataFormat()); 435 } 436 437 /** 438 * Uses the Soap 1.1 JAXB data format 439 */ 440 public T soapjaxb(String contextPath) { 441 return dataFormat(new SoapJaxbDataFormat(contextPath)); 442 } 443 444 /** 445 * Uses the Soap 1.1 JAXB data format 446 */ 447 public T soapjaxb(String contextPath, String elementNameStrategyRef) { 448 return dataFormat(new SoapJaxbDataFormat(contextPath, elementNameStrategyRef)); 449 } 450 451 /** 452 * Uses the Soap 1.1 JAXB data format 453 */ 454 public T soapjaxb(String contextPath, Object elementNameStrategy) { 455 return dataFormat(new SoapJaxbDataFormat(contextPath, elementNameStrategy)); 456 } 457 458 /** 459 * Uses the Soap 1.2 JAXB data format 460 */ 461 public T soapjaxb12() { 462 SoapJaxbDataFormat soap = new SoapJaxbDataFormat(); 463 soap.setVersion("1.2"); 464 return dataFormat(soap); 465 } 466 467 /** 468 * Uses the Soap 1.2 JAXB data format 469 */ 470 public T soapjaxb12(String contextPath) { 471 SoapJaxbDataFormat soap = new SoapJaxbDataFormat(contextPath); 472 soap.setVersion("1.2"); 473 return dataFormat(soap); 474 } 475 476 /** 477 * Uses the Soap 1.2 JAXB data format 478 */ 479 public T soapjaxb12(String contextPath, String elementNameStrategyRef) { 480 SoapJaxbDataFormat soap = new SoapJaxbDataFormat(contextPath, elementNameStrategyRef); 481 soap.setVersion("1.2"); 482 return dataFormat(soap); 483 } 484 485 /** 486 * Uses the Soap JAXB data format 487 */ 488 public T soapjaxb12(String contextPath, Object elementNameStrategy) { 489 SoapJaxbDataFormat soap = new SoapJaxbDataFormat(contextPath, elementNameStrategy); 490 soap.setVersion("1.2"); 491 return dataFormat(soap); 492 } 493 494 /** 495 * Uses the String data format 496 */ 497 public T string() { 498 return string(null); 499 } 500 501 /** 502 * Uses the String data format supporting encoding using given charset 503 */ 504 public T string(String charset) { 505 StringDataFormat sdf = new StringDataFormat(); 506 sdf.setCharset(charset); 507 return dataFormat(sdf); 508 } 509 510 /** 511 * Uses the Syslog data format 512 */ 513 public T syslog() { 514 return dataFormat(new SyslogDataFormat()); 515 } 516 517 /** 518 * Return WellFormed HTML (an XML Document) either 519 * {@link java.lang.String} or {@link org.w3c.dom.Node} 520 */ 521 public T tidyMarkup(Class<?> dataObjectType) { 522 return dataFormat(new TidyMarkupDataFormat(dataObjectType)); 523 } 524 525 /** 526 * Return TidyMarkup in the default format 527 * as {@link org.w3c.dom.Node} 528 */ 529 public T tidyMarkup() { 530 return dataFormat(new TidyMarkupDataFormat(Node.class)); 531 } 532 533 /** 534 * Uses the XStream data format 535 */ 536 public T xstream() { 537 return dataFormat(new XStreamDataFormat()); 538 } 539 540 /** 541 * Uses the xstream by setting the encoding 542 */ 543 public T xstream(String encoding) { 544 return dataFormat(new XStreamDataFormat(encoding)); 545 } 546 547 /** 548 * Uses the XML Security data format 549 */ 550 public T secureXML() { 551 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(); 552 return dataFormat(xsdf); 553 } 554 555 /** 556 * Uses the XML Security data format 557 */ 558 public T secureXML(String secureTag, boolean secureTagContents) { 559 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, secureTagContents); 560 return dataFormat(xsdf); 561 } 562 563 /** 564 * Uses the XML Security data format 565 */ 566 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents) { 567 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, namespaces, secureTagContents); 568 return dataFormat(xsdf); 569 } 570 571 /** 572 * Uses the XML Security data format 573 */ 574 public T secureXML(String secureTag, boolean secureTagContents, String passPhrase) { 575 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, secureTagContents, passPhrase); 576 return dataFormat(xsdf); 577 } 578 579 /** 580 * Uses the XML Security data format 581 */ 582 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String passPhrase) { 583 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, namespaces, secureTagContents, passPhrase); 584 return dataFormat(xsdf); 585 } 586 587 /** 588 * Uses the XML Security data format 589 */ 590 public T secureXML(String secureTag, boolean secureTagContents, String passPhrase, String xmlCipherAlgorithm) { 591 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, secureTagContents, passPhrase, xmlCipherAlgorithm); 592 return dataFormat(xsdf); 593 } 594 595 596 /** 597 * Uses the XML Security data format 598 */ 599 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String passPhrase, String xmlCipherAlgorithm) { 600 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, namespaces, secureTagContents, passPhrase, xmlCipherAlgorithm); 601 return dataFormat(xsdf); 602 } 603 604 /** 605 * @deprecated Use {@link #secureXML(String, Map, boolean, String, String, String, String)} instead. 606 * Uses the XML Security data format 607 */ 608 @Deprecated 609 public T secureXML(String secureTag, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, 610 String keyCipherAlgorithm) { 611 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, secureTagContents, recipientKeyAlias, xmlCipherAlgorithm, keyCipherAlgorithm); 612 return dataFormat(xsdf); 613 } 614 615 /** 616 * Uses the XML Security data format 617 */ 618 public T secureXML(String secureTag, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, 619 String keyCipherAlgorithm, String keyOrTrustStoreParametersId) { 620 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, secureTagContents, recipientKeyAlias, xmlCipherAlgorithm, 621 keyCipherAlgorithm, keyOrTrustStoreParametersId); 622 return dataFormat(xsdf); 623 } 624 625 /** 626 * Uses the XML Security data format 627 */ 628 public T secureXML(String secureTag, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, 629 String keyCipherAlgorithm, String keyOrTrustStoreParametersId, String keyPassword) { 630 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, secureTagContents, recipientKeyAlias, xmlCipherAlgorithm, 631 keyCipherAlgorithm, keyOrTrustStoreParametersId, keyPassword); 632 return dataFormat(xsdf); 633 } 634 635 /** 636 * Uses the XML Security data format 637 */ 638 public T secureXML(String secureTag, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, 639 String keyCipherAlgorithm, KeyStoreParameters keyOrTrustStoreParameters) { 640 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, secureTagContents, recipientKeyAlias, xmlCipherAlgorithm, 641 keyCipherAlgorithm, keyOrTrustStoreParameters); 642 return dataFormat(xsdf); 643 } 644 645 /** 646 * Uses the XML Security data format 647 */ 648 public T secureXML(String secureTag, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, 649 String keyCipherAlgorithm, KeyStoreParameters keyOrTrustStoreParameters, String keyPassword) { 650 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, secureTagContents, recipientKeyAlias, xmlCipherAlgorithm, 651 keyCipherAlgorithm, keyOrTrustStoreParameters, keyPassword); 652 return dataFormat(xsdf); 653 } 654 655 /** 656 * Uses the XML Security data format 657 */ 658 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String recipientKeyAlias, 659 String xmlCipherAlgorithm, String keyCipherAlgorithm, String keyOrTrustStoreParametersId) { 660 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, namespaces, secureTagContents, recipientKeyAlias, xmlCipherAlgorithm, 661 keyCipherAlgorithm, keyOrTrustStoreParametersId); 662 return dataFormat(xsdf); 663 } 664 665 /** 666 * Uses the XML Security data format 667 */ 668 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String recipientKeyAlias, 669 String xmlCipherAlgorithm, String keyCipherAlgorithm, String keyOrTrustStoreParametersId, String keyPassword) { 670 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, namespaces, secureTagContents, recipientKeyAlias, xmlCipherAlgorithm, 671 keyCipherAlgorithm, keyOrTrustStoreParametersId, keyPassword); 672 return dataFormat(xsdf); 673 } 674 675 /** 676 * Uses the XML Security data format 677 */ 678 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String recipientKeyAlias, 679 String xmlCipherAlgorithm, String keyCipherAlgorithm, KeyStoreParameters keyOrTrustStoreParameters) { 680 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, namespaces, secureTagContents, recipientKeyAlias, xmlCipherAlgorithm, 681 keyCipherAlgorithm, keyOrTrustStoreParameters); 682 return dataFormat(xsdf); 683 } 684 685 /** 686 * Uses the XML Security data format 687 */ 688 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String recipientKeyAlias, 689 String xmlCipherAlgorithm, String keyCipherAlgorithm, KeyStoreParameters keyOrTrustStoreParameters, String keyPassword) { 690 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, namespaces, secureTagContents, recipientKeyAlias, xmlCipherAlgorithm, 691 keyCipherAlgorithm, keyOrTrustStoreParameters, keyPassword); 692 return dataFormat(xsdf); 693 } 694 695 /** 696 * Uses the XML Security data format 697 */ 698 public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String recipientKeyAlias, 699 String xmlCipherAlgorithm, String keyCipherAlgorithm, KeyStoreParameters keyOrTrustStoreParameters, String keyPassword, 700 String digestAlgorithm) { 701 XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, namespaces, secureTagContents, recipientKeyAlias, xmlCipherAlgorithm, 702 keyCipherAlgorithm, keyOrTrustStoreParameters, keyPassword, digestAlgorithm); 703 return dataFormat(xsdf); 704 } 705 706 /** 707 * Uses the xmlBeans data format 708 */ 709 public T xmlBeans() { 710 return dataFormat(new XMLBeansDataFormat()); 711 } 712 713 /** 714 * Uses the xmljson dataformat, based on json-lib 715 */ 716 public T xmljson() { 717 return dataFormat(new XmlJsonDataFormat()); 718 } 719 720 /** 721 * Uses the xmljson dataformat, based on json-lib, initializing custom options with a Map 722 */ 723 public T xmljson(Map<String, String> options) { 724 return dataFormat(new XmlJsonDataFormat(options)); 725 } 726 727 /** 728 * Uses the ZIP deflater data format 729 */ 730 public T zip() { 731 ZipDataFormat zdf = new ZipDataFormat(Deflater.DEFAULT_COMPRESSION); 732 return dataFormat(zdf); 733 } 734 735 /** 736 * Uses the ZIP deflater data format 737 */ 738 public T zip(int compressionLevel) { 739 ZipDataFormat zdf = new ZipDataFormat(compressionLevel); 740 return dataFormat(zdf); 741 } 742 743 /** 744 * Uses the ZIP file data format 745 */ 746 public T zipFile() { 747 ZipFileDataFormat zfdf = new ZipFileDataFormat(); 748 return dataFormat(zfdf); 749 } 750 751 @SuppressWarnings("unchecked") 752 private T dataFormat(DataFormatDefinition dataFormatType) { 753 switch (operation) { 754 case Unmarshal: 755 return (T) processorType.unmarshal(dataFormatType); 756 case Marshal: 757 return (T) processorType.marshal(dataFormatType); 758 default: 759 throw new IllegalArgumentException("Unknown DataFormat operation: " + operation); 760 } 761 } 762}