Skip to content

Package: DefaultRequest

DefaultRequest

nameinstructionbranchcomplexitylinemethod
DefaultRequest()
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
DefaultRequest(String, String, String, Map, Map, List)
M: 45 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getBaseUrl()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getHeader(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getHeadersMap()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getMultiValuedHeader(String)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getMultiValuedParameter(String)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getOriginalRelativeUri()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getParameter(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getParametersMap()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getPathParams(SiteNode)
M: 19 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getPreferredLocales()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getRelativeUri()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
toString()
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
withBaseUrl(String)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
withHeaderMap(Map)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
withParameterMap(Map)
M: 41 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
withPreferredLocales(List)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
withRelativeUri(String)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%L
3: * *********************************************************************************************************************
4: *
5: * NorthernWind - lightweight CMS
6: * http://northernwind.tidalwave.it - git clone https://bitbucket.org/tidalwave/northernwind-src.git
7: * %%
8: * Copyright (C) 2011 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
9: * %%
10: * *********************************************************************************************************************
11: *
12: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
13: * the License. You may obtain a copy of the License at
14: *
15: * http://www.apache.org/licenses/LICENSE-2.0
16: *
17: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
18: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
19: * specific language governing permissions and limitations under the License.
20: *
21: * *********************************************************************************************************************
22: *
23: *
24: * *********************************************************************************************************************
25: * #L%
26: */
27: package it.tidalwave.northernwind.core.impl.model;
28:
29: import javax.annotation.Nonnull;
30: import javax.annotation.concurrent.Immutable;
31: import java.util.ArrayList;
32: import java.util.HashMap;
33: import java.util.List;
34: import java.util.Locale;
35: import java.util.Map;
36: import java.util.Optional;
37: import it.tidalwave.northernwind.core.model.Request;
38: import it.tidalwave.northernwind.core.model.ResourcePath;
39: import it.tidalwave.northernwind.core.model.SiteNode;
40: import lombok.AllArgsConstructor;
41: import lombok.Getter;
42: import lombok.ToString;
43: import static java.util.Collections.emptyList;
44: import static lombok.AccessLevel.PRIVATE;
45:
46: /***********************************************************************************************************************
47: *
48: * The default implementation of {@link Request}
49: *
50: * @author Fabrizio Giudici
51: *
52: **********************************************************************************************************************/
53: @Immutable @AllArgsConstructor(access = PRIVATE) @Getter @ToString
54: /* package */ class DefaultRequest implements Request
55: {
56: @Nonnull
57: private final String baseUrl;
58:
59: @Nonnull
60: private final String relativeUri;
61:
62: @Nonnull
63: private final String originalRelativeUri;
64:
65: @Nonnull
66: private final Map<String, List<String>> parametersMap;
67:
68: @Nonnull
69: private final Map<String, List<String>> headersMap;
70:
71: @Nonnull
72: private final List<Locale> preferredLocales;
73:
74: /*******************************************************************************************************************
75: *
76: *
77: ******************************************************************************************************************/
78: public DefaultRequest()
79: {
80: this("", "", "", new HashMap<>(), new HashMap<>(), new ArrayList<>());
81: }
82:
83: /*******************************************************************************************************************
84: *
85: * {@inheritDoc}
86: *
87: ******************************************************************************************************************/
88: @Override @Nonnull
89: public Optional<String> getHeader (@Nonnull final String parameterName)
90: {
91: return getMultiValuedHeader(parameterName).stream().findFirst();
92: }
93:
94: /*******************************************************************************************************************
95: *
96: * {@inheritDoc}
97: *
98: ******************************************************************************************************************/
99: @Override @Nonnull
100: public List<String> getMultiValuedHeader (@Nonnull final String headerName)
101: {
102: return headersMap.getOrDefault(headerName, emptyList());
103: }
104:
105: /*******************************************************************************************************************
106: *
107: * {@inheritDoc}
108: *
109: ******************************************************************************************************************/
110: @Override @Nonnull
111: public Optional<String> getParameter (@Nonnull final String headerName)
112: {
113: return getMultiValuedParameter(headerName).stream().findFirst();
114: }
115:
116: /*******************************************************************************************************************
117: *
118: * {@inheritDoc}
119: *
120: ******************************************************************************************************************/
121: @Override @Nonnull
122: public List<String> getMultiValuedParameter (@Nonnull final String parameterName)
123: {
124: return parametersMap.getOrDefault(parameterName, emptyList());
125: }
126:
127: /*******************************************************************************************************************
128: *
129: * {@inheritDoc}
130: *
131: ******************************************************************************************************************/
132: @Override @Nonnull
133: public DefaultRequest withRelativeUri (@Nonnull final String relativeUri)
134: {
135: return new DefaultRequest(baseUrl,
136: ResourcePath.of(relativeUri).urlDecoded().asString(),
137: relativeUri,
138: parametersMap,
139: headersMap,
140: preferredLocales);
141: }
142:
143: /*******************************************************************************************************************
144: *
145: * {@inheritDoc}
146: *
147: ******************************************************************************************************************/
148: @Nonnull
149: public DefaultRequest withBaseUrl (@Nonnull final String baseUrl)
150: {
151: return new DefaultRequest(baseUrl, relativeUri, originalRelativeUri, parametersMap, headersMap, preferredLocales);
152: }
153:
154: /*******************************************************************************************************************
155: *
156: * {@inheritDoc}
157: *
158: ******************************************************************************************************************/
159: @Override @Nonnull
160: public ResourcePath getPathParams (@Nonnull final SiteNode siteNode)
161: {
162: final var siteNodeRelativeUri = siteNode.getRelativeUri().asString();
163:• return (relativeUri.length() <= siteNodeRelativeUri.length())
164: ? ResourcePath.EMPTY
165: : ResourcePath.of(relativeUri.substring(siteNodeRelativeUri.length()));
166: }
167:
168: /*******************************************************************************************************************
169: *
170: *
171: ******************************************************************************************************************/
172: @Nonnull
173: public DefaultRequest withParameterMap (@Nonnull final Map<String, String[]> httpParameterMap)
174: {
175: final Map<String, List<String>> parameterMap = new HashMap<>();
176:
177:• for (final var entry : httpParameterMap.entrySet())
178: {
179: parameterMap.put(entry.getKey(), List.of(entry.getValue()));
180: }
181:
182: return new DefaultRequest(baseUrl, relativeUri, originalRelativeUri, parameterMap, headersMap, preferredLocales);
183: }
184:
185: /*******************************************************************************************************************
186: *
187: *
188: ******************************************************************************************************************/
189: @Nonnull
190: public DefaultRequest withHeaderMap (@Nonnull final Map<String, List<String>> headersMap)
191: {
192: return new DefaultRequest(baseUrl, relativeUri, originalRelativeUri, parametersMap, headersMap, preferredLocales);
193: }
194:
195: /*******************************************************************************************************************
196: *
197: *
198: ******************************************************************************************************************/
199: @Nonnull
200: public DefaultRequest withPreferredLocales (@Nonnull final List<Locale> preferredLocales)
201: {
202: return new DefaultRequest(baseUrl, relativeUri, originalRelativeUri, parametersMap, headersMap, preferredLocales);
203: }
204: }