001/* 002 * (C) Copyright 2006-2018 Nuxeo (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Bogdan Stefanescu 018 * Florent Guillaume 019 */ 020package org.nuxeo.runtime.server; 021 022import java.util.ArrayList; 023import java.util.HashMap; 024import java.util.List; 025import java.util.Map; 026 027import org.nuxeo.common.xmap.annotation.XNode; 028import org.nuxeo.common.xmap.annotation.XNodeList; 029import org.nuxeo.common.xmap.annotation.XNodeMap; 030import org.nuxeo.common.xmap.annotation.XObject; 031 032/** 033 * Descriptor for a servlet filter. For convenience, we follow the official syntax of web.xml. 034 */ 035@XObject("filter") 036public class FilterDescriptor { 037 038 @XNode("@context") 039 protected String context; 040 041 /** 042 * @since 10.2 043 */ 044 @XNode("filter-name") 045 protected String name; 046 047 // compat 048 @XNode("@name") 049 public void setName(String name) { 050 this.name = name; 051 } 052 053 /** 054 * @since 10.2 055 */ 056 @XNode("filter-class") 057 protected Class<?> clazz; 058 059 // compat 060 @XNode("@class") 061 public void setClass(Class<?> clazz) { 062 this.clazz = clazz; 063 } 064 065 /** 066 * @since 10.2 067 */ 068 @XNode("display-name") 069 protected String displayName; 070 071 // compat 072 @XNode("description") 073 public void setDisplayName(String description) { 074 this.displayName = description; 075 } 076 077 protected Map<String, String> initParams = new HashMap<>(); 078 079 /** 080 * @since 10.2 081 */ 082 @XNodeList(value = "init-param", type = ArrayList.class, componentType = InitParamDescriptor.class) 083 public void setInitParams(List<InitParamDescriptor> descriptors) { 084 for (InitParamDescriptor d : descriptors) { 085 initParams.put(d.getName(), d.getValue()); 086 } 087 } 088 089 // compat 090 @XNodeMap(value = "init-params/param", key = "@name", type = HashMap.class, componentType = String.class, trim = true, nullByDefault = true) 091 public void setInitParams(Map<String, String> initParams) { 092 this.initParams.putAll(initParams); 093 } 094 095 /** 096 * @since 10.2 097 */ 098 @XNodeList(value = "filter-mapping", type = ArrayList.class, componentType = FilterMappingDescriptor.class) 099 protected List<FilterMappingDescriptor> filterMappings; 100 101 public String getContext() { 102 return context; 103 } 104 105 public String getName() { 106 return name; 107 } 108 109 public Class<?> getClazz() { 110 return clazz; 111 } 112 113 public String getDisplayName() { 114 return displayName; 115 } 116 117 public Map<String, String> getInitParams() { 118 return initParams; 119 } 120 121 public List<FilterMappingDescriptor> getFilterMappings() { 122 return filterMappings; 123 } 124 125}