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.Arrays; 024import java.util.HashMap; 025import java.util.List; 026import java.util.Map; 027 028import org.nuxeo.common.xmap.annotation.XNode; 029import org.nuxeo.common.xmap.annotation.XNodeList; 030import org.nuxeo.common.xmap.annotation.XNodeMap; 031import org.nuxeo.common.xmap.annotation.XObject; 032 033/** 034 * Descriptor for a servlet. For convenience, we follow the official syntax of web.xml. 035 */ 036@XObject("servlet") 037public class ServletDescriptor { 038 039 @XNode("@context") 040 protected String context; 041 042 /** 043 * @since 10.2 044 */ 045 @XNode("servlet-name") 046 protected String name; 047 048 // compat 049 @XNode("@name") 050 public void setName(String name) { 051 this.name = name; 052 } 053 054 /** 055 * @since 10.2 056 */ 057 @XNode("servlet-class") 058 protected Class<?> clazz; 059 060 // compat 061 @XNode("@class") 062 public void setClass(Class<?> clazz) { 063 this.clazz = clazz; 064 } 065 066 /** 067 * @since 10.2 068 */ 069 @XNodeList(value = "url-pattern", type = ArrayList.class, componentType = String.class) 070 protected List<String> urlPatterns; 071 072 // compat 073 @XNode("@path") 074 public void setUrlPattern(String urlPattern) { 075 this.urlPatterns = new ArrayList<>(Arrays.asList(urlPattern)); 076 } 077 078 protected Map<String, String> initParams = new HashMap<>(); 079 080 @XNodeList(value = "init-param", type = ArrayList.class, componentType = InitParamDescriptor.class) 081 public void setInitParams(List<InitParamDescriptor> descriptors) { 082 for (InitParamDescriptor d : descriptors) { 083 initParams.put(d.getName(), d.getValue()); 084 } 085 } 086 087 // compat 088 @XNodeMap(value = "init-params/param", key = "@name", type = HashMap.class, componentType = String.class, trim = true, nullByDefault = true) 089 public void setInitParams(Map<String, String> initParams) { 090 this.initParams.putAll(initParams); 091 } 092 093 /** 094 * @since 10.2 095 */ 096 @XNode("display-name") 097 protected String displayName; 098 099 // compat 100 @XNode("description") 101 public void setDisplayName(String displayName) { 102 this.displayName = displayName; 103 } 104 105 public String getContext() { 106 return context; 107 } 108 109 public String getName() { 110 return name; 111 } 112 113 public Class<?> getClazz() { 114 return clazz; 115 } 116 117 public List<String> getUrlPatterns() { 118 return urlPatterns; 119 } 120 121 public Map<String, String> getInitParams() { 122 return initParams; 123 } 124 125 public String getDisplayName() { 126 return displayName; 127 } 128 129}