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