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.model.dataformat; 018 019import javax.xml.bind.annotation.XmlAccessType; 020import javax.xml.bind.annotation.XmlAccessorType; 021import javax.xml.bind.annotation.XmlAttribute; 022import javax.xml.bind.annotation.XmlRootElement; 023 024import org.apache.camel.CamelContext; 025import org.apache.camel.model.DataFormatDefinition; 026import org.apache.camel.spi.DataFormat; 027import org.apache.camel.spi.Metadata; 028 029/** 030 * Castor data format is used for unmarshal a XML payload to POJO or to marshal POJO back to XML payload. 031 * 032 * @version 033 */ 034@Metadata(firstVersion = "2.1.0", label = "dataformat,transformation,xml", title = "Castor") 035@XmlRootElement(name = "castor") 036@XmlAccessorType(XmlAccessType.FIELD) 037@Deprecated 038public class CastorDataFormat extends DataFormatDefinition { 039 @XmlAttribute 040 private String mappingFile; 041 @XmlAttribute 042 @Metadata(defaultValue = "true") 043 private Boolean whitelistEnabled = true; 044 @XmlAttribute 045 private String allowedUnmarshallObjects; 046 @XmlAttribute 047 private String deniedUnmarshallObjects; 048 @XmlAttribute @Metadata(defaultValue = "true") 049 private Boolean validation; 050 @XmlAttribute @Metadata(defaultValue = "UTF-8") 051 private String encoding; 052 @XmlAttribute 053 private String[] packages; 054 @XmlAttribute 055 private String[] classes; 056 057 public CastorDataFormat() { 058 super("castor"); 059 } 060 061 public Boolean getValidation() { 062 return validation; 063 } 064 065 /** 066 * Whether validation is turned on or off. 067 * <p/> 068 * Is by default true. 069 */ 070 public void setValidation(Boolean validation) { 071 this.validation = validation; 072 } 073 074 public String getMappingFile() { 075 return mappingFile; 076 } 077 078 /** 079 * Path to a Castor mapping file to load from the classpath. 080 */ 081 public void setMappingFile(String mappingFile) { 082 this.mappingFile = mappingFile; 083 } 084 085 public String[] getPackages() { 086 return packages; 087 } 088 089 /** 090 * Add additional packages to Castor XmlContext 091 */ 092 public void setPackages(String[] packages) { 093 this.packages = packages; 094 } 095 096 public String[] getClasses() { 097 return classes; 098 } 099 100 /** 101 * Add additional class names to Castor XmlContext 102 */ 103 public void setClasses(String[] classes) { 104 this.classes = classes; 105 } 106 107 public String getEncoding() { 108 return encoding; 109 } 110 111 /** 112 * Encoding to use when marshalling an Object to XML. 113 * <p/> 114 * Is by default UTF-8 115 */ 116 public void setEncoding(String encoding) { 117 this.encoding = encoding; 118 } 119 120 public Boolean getWhitelistEnabled() { 121 return whitelistEnabled; 122 } 123 124 /** 125 * Define if Whitelist feature is enabled or not 126 */ 127 public void setWhitelistEnabled(Boolean whitelistEnabled) { 128 this.whitelistEnabled = whitelistEnabled; 129 } 130 131 public String getAllowedUnmarshallObjects() { 132 return allowedUnmarshallObjects; 133 } 134 135 /** 136 * Define the allowed objects to be unmarshalled. 137 * 138 * You can specify the FQN class name of allowed objects, and you can use comma to separate multiple entries. 139 * It is also possible to use wildcards and regular expression which is based on the pattern 140 * defined by {@link org.apache.camel.util.EndpointHelper#matchPattern(String, String)}. 141 * Denied objects takes precedence over allowed objects. 142 */ 143 public void setAllowedUnmarshallObjects(String allowedUnmarshallObjects) { 144 this.allowedUnmarshallObjects = allowedUnmarshallObjects; 145 } 146 147 public String getDeniedUnmarshallObjects() { 148 return deniedUnmarshallObjects; 149 } 150 151 /** 152 * Define the denied objects to be unmarshalled. 153 * 154 * You can specify the FQN class name of deined objects, and you can use comma to separate multiple entries. 155 * It is also possible to use wildcards and regular expression which is based on the pattern 156 * defined by {@link org.apache.camel.util.EndpointHelper#matchPattern(String, String)}. 157 * Denied objects takes precedence over allowed objects. 158 */ 159 public void setDeniedUnmarshallObjects(String deniedUnmarshallObjects) { 160 this.deniedUnmarshallObjects = deniedUnmarshallObjects; 161 } 162 163 @Override 164 protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) { 165 if (mappingFile != null) { 166 setProperty(camelContext, dataFormat, "mappingFile", mappingFile); 167 } 168 // should be true by default 169 boolean isValidation = getValidation() == null || getValidation(); 170 setProperty(camelContext, dataFormat, "validation", isValidation); 171 172 if (encoding != null) { 173 setProperty(camelContext, dataFormat, "encoding", encoding); 174 } 175 if (packages != null) { 176 setProperty(camelContext, dataFormat, "packages", packages); 177 } 178 if (classes != null) { 179 setProperty(camelContext, dataFormat, "classes", classes); 180 } 181 if (whitelistEnabled != null) { 182 setProperty(camelContext, dataFormat, "whitelistEnabled", whitelistEnabled); 183 } 184 if (allowedUnmarshallObjects != null) { 185 setProperty(camelContext, dataFormat, "allowedUnmarshallObjects", allowedUnmarshallObjects); 186 } 187 if (deniedUnmarshallObjects != null) { 188 setProperty(camelContext, dataFormat, "deniedUnmarshallObjects", deniedUnmarshallObjects); 189 } 190 } 191 192}