Skip to content

Package: DefaultRequestContext

DefaultRequestContext

nameinstructionbranchcomplexitylinemethod
DefaultRequestContext()
M: 88 C: 0
0%
M: 22 C: 0
0%
M: 12 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
clearContent()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
clearNode()
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getContentProperties()
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%
getNodeProperties()
M: 24 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
requestReset()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setContent(Content)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setDynamicNodeProperty(Key, Object)
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setNode(SiteNode)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 5 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: 21 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
toString(Resource)
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * NorthernWind - lightweight CMS
5: * http://tidalwave.it/projects/northernwind
6: *
7: * Copyright (C) 2011 - 2025 Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/northernwind-src
22: * git clone https://github.com/tidalwave-it/northernwind-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.northernwind.core.impl.model;
27:
28: import javax.annotation.CheckForNull;
29: import javax.annotation.Nonnull;
30: import javax.inject.Inject;
31: import org.springframework.beans.factory.annotation.Configurable;
32: import it.tidalwave.util.Key;
33: import it.tidalwave.northernwind.core.model.Content;
34: import it.tidalwave.northernwind.core.model.ModelFactory;
35: import it.tidalwave.northernwind.core.model.RequestContext;
36: import it.tidalwave.northernwind.core.model.Resource;
37: import it.tidalwave.northernwind.core.model.ResourceProperties;
38: import it.tidalwave.northernwind.core.model.SiteNode;
39: import lombok.extern.slf4j.Slf4j;
40:
41: /***************************************************************************************************************************************************************
42: *
43: * A default implementation of {@link FilterContext}.
44: *
45: * @author Fabrizio Giudici
46: *
47: **************************************************************************************************************************************************************/
48: @Configurable @Slf4j
49:•public class DefaultRequestContext implements RequestContext
50: {
51: @Inject
52: private ModelFactory modelFactory;
53:
54: private final ThreadLocal<Content> contentHolder = new ThreadLocal<>();
55:
56: private final ThreadLocal<SiteNode> nodeHolder = new ThreadLocal<>();
57:
58:• private final ThreadLocal<ResourceProperties> dynamicNodePropertiesHolder = new ThreadLocal<>();
59:
60: @Override @Nonnull
61: public ResourceProperties getContentProperties()
62: {
63:• if (contentHolder.get() == null) // FIXME: should never occur
64: {
65: log.warn("No Content Properties in RequestContext ({})", this);
66: return modelFactory.createProperties().build();
67: }
68:
69: return contentHolder.get().getProperties();
70: }
71:
72: @Override @Nonnull
73: public ResourceProperties getNodeProperties()
74: {
75:• if (contentHolder.get() == null) // FIXME: should never occur
76: {
77: log.warn("No Node Properties in RequestContext ({})", this);
78: return dynamicNodePropertiesHolder.get();
79: }
80:
81: return nodeHolder.get().getProperties().merged(dynamicNodePropertiesHolder.get());
82: }
83:
84: @Override
85: public void setContent (@Nonnull final Content content)
86: {
87: contentHolder.set(content);
88: }
89:
90: @Override
91: public void setNode (@Nonnull final SiteNode node)
92: {
93: nodeHolder.set(node);
94: dynamicNodePropertiesHolder.set(modelFactory.createProperties().build());
95: }
96:
97: @Override
98: public void clearContent()
99: {
100: contentHolder.remove();
101: }
102:
103: @Override
104: public void clearNode()
105: {
106: nodeHolder.remove();
107: dynamicNodePropertiesHolder.remove();
108: }
109:
110: @Override
111: public void requestReset()
112: {
113: clearNode();
114: clearContent();
115: }
116:
117: @Override
118: public <Type> void setDynamicNodeProperty (@Nonnull final Key<Type> key, @Nonnull final Type value)
119: {
120: final var properties = dynamicNodePropertiesHolder.get();
121: dynamicNodePropertiesHolder.set(properties.withProperty(key, value));
122: }
123:
124: @Override @Nonnull
125: public String toString()
126: {
127: return String.format("RequestContext(content: %s, node: %s)", toString(contentHolder.get()), toString(nodeHolder.get()));
128: }
129:
130: @Nonnull
131: private static String toString (@CheckForNull final Resource resource)
132: {
133:• return (resource == null) ? "null" : resource.getFile().getPath().asString();
134: }
135: }