001package org.apache.turbine.services.urlmapper.model;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.util.LinkedHashMap;
023import java.util.Map;
024import java.util.Set;
025import java.util.regex.Pattern;
026
027import javax.xml.bind.annotation.XmlAccessType;
028import javax.xml.bind.annotation.XmlAccessorType;
029import javax.xml.bind.annotation.XmlElement;
030import javax.xml.bind.annotation.XmlType;
031import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
032
033import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
034import com.fasterxml.jackson.annotation.JsonProperty;
035
036/**
037 * The url map model class
038 *
039 * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
040 */
041@XmlType(name="map")
042@XmlAccessorType(XmlAccessType.NONE)
043@JsonIgnoreProperties(ignoreUnknown = true)
044public class URLMapEntry
045{
046    private Pattern urlPattern;
047    private Map<String, String> implicit = new LinkedHashMap<>();
048    private Map<String, String> ignore = new LinkedHashMap<>();
049    private Map<String, String> override = new LinkedHashMap<>();
050
051    private Map<String, Integer> groupNamesMap;
052    private Set<String> relevantKeys = null;
053
054    /**
055     * @return the urlPattern
056     */
057    @XmlElement(name="pattern")
058    @XmlJavaTypeAdapter(XmlPatternAdapter.class)
059    @JsonProperty("pattern")
060    public Pattern getUrlPattern()
061    {
062        return urlPattern;
063    }
064
065    /**
066     * @param urlPattern the urlPattern to set
067     */
068    protected void setUrlPattern(Pattern urlPattern)
069    {
070        this.urlPattern = urlPattern;
071    }
072
073    /**
074     * @return the implicit parameters
075     */
076    @XmlElement(name="implicit-parameters")
077    @XmlJavaTypeAdapter(XmlParameterAdapter.class)
078    @JsonProperty("implicit-parameters")
079    public Map<String, String> getImplicitParameters()
080    {
081        return implicit;
082    }
083
084    /**
085     * @param implicit the implicit parameters to set
086     */
087    protected void setImplicitParameters(Map<String, String> implicit)
088    {
089        this.implicit = implicit;
090    }
091
092    /**
093     * @return the ignored parameters
094     */
095    @XmlElement(name="ignore-parameters")
096    @XmlJavaTypeAdapter(XmlParameterAdapter.class)
097    @JsonProperty("ignore-parameters")
098    public Map<String, String> getIgnoreParameters()
099    {
100        return ignore;
101    }
102
103    /**
104     * @param ignore the ignored parameters to set
105     */
106    protected void setIgnoreParameters(Map<String, String> ignore)
107    {
108        this.ignore = ignore;
109    }
110
111    /**
112     * @return the override parameters
113     */
114    @XmlElement(name="override-parameters")
115    @XmlJavaTypeAdapter(XmlParameterAdapter.class)
116    @JsonProperty("override-parameters")
117    public Map<String, String> getOverrideParameters()
118    {
119        return override;
120    }
121
122    /**
123     * @param override the override parameters to set
124     */
125    protected void setOverrideParameters(Map<String, String> override)
126    {
127        this.override = override;
128    }
129
130    /**
131     * Get the map of group names to group indices for the stored Pattern
132     *
133     * @return the groupNamesMap
134     */
135    public Map<String, Integer> getGroupNamesMap()
136    {
137        return groupNamesMap;
138    }
139
140    /**
141     * Set the map of group names to group indices for the stored Pattern
142     *
143     * @param groupNamesMap the groupNamesMap to set
144     */
145    public void setGroupNamesMap(Map<String, Integer> groupNamesMap)
146    {
147        this.groupNamesMap = groupNamesMap;
148    }
149
150    /**
151     * Get the set of relevant keys for comparison (cached for performance)
152     *
153     * @return the relevantKeys
154     */
155    public Set<String> getRelevantKeys()
156    {
157        return relevantKeys;
158    }
159
160    /**
161     * Set the set of relevant keys for comparison (cached for performance)
162     *
163     * @param relevantKeys the relevantKeys to set
164     */
165    public void setRelevantKeys(Set<String> relevantKeys)
166    {
167        this.relevantKeys = relevantKeys;
168    }
169
170    @Override
171    public String toString()
172    {
173        return "URLMapEntry: [ pattern: " + urlPattern + ", implicit-parameters: " + implicit + ", override-parameters: " + override + ", ignore-parameters:" + ignore + " ]";
174    }
175}