Package: DefaultRequestContext
DefaultRequestContext
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
DefaultRequestContext() |
|
|
|
|
|
||||||||||||||||||||
clearContent() |
|
|
|
|
|
||||||||||||||||||||
clearNode() |
|
|
|
|
|
||||||||||||||||||||
getContentProperties() |
|
|
|
|
|
||||||||||||||||||||
getNodeProperties() |
|
|
|
|
|
||||||||||||||||||||
requestReset() |
|
|
|
|
|
||||||||||||||||||||
setContent(Content) |
|
|
|
|
|
||||||||||||||||||||
setDynamicNodeProperty(Key, Object) |
|
|
|
|
|
||||||||||||||||||||
setNode(SiteNode) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
||||||||||||||||||||
toString() |
|
|
|
|
|
||||||||||||||||||||
toString(Resource) |
|
|
|
|
|
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.CheckForNull;
30: import javax.annotation.Nonnull;
31: import javax.inject.Inject;
32: import org.springframework.beans.factory.annotation.Configurable;
33: import it.tidalwave.util.Key;
34: import it.tidalwave.northernwind.core.model.Content;
35: import it.tidalwave.northernwind.core.model.ModelFactory;
36: import it.tidalwave.northernwind.core.model.RequestContext;
37: import it.tidalwave.northernwind.core.model.Resource;
38: import it.tidalwave.northernwind.core.model.ResourceProperties;
39: import it.tidalwave.northernwind.core.model.SiteNode;
40: import lombok.extern.slf4j.Slf4j;
41:
42: /***********************************************************************************************************************
43: *
44: * A default implementation of {@link FilterContext}.
45: *
46: * @author Fabrizio Giudici
47: *
48: **********************************************************************************************************************/
49: @Configurable @Slf4j
50:•public class DefaultRequestContext implements RequestContext
51: {
52: @Inject
53: private ModelFactory modelFactory;
54:
55: private final ThreadLocal<Content> contentHolder = new ThreadLocal<>();
56:
57: private final ThreadLocal<SiteNode> nodeHolder = new ThreadLocal<>();
58:
59:• private final ThreadLocal<ResourceProperties> dynamicNodePropertiesHolder = new ThreadLocal<>();
60:
61: @Override @Nonnull
62: public ResourceProperties getContentProperties()
63: {
64:• if (contentHolder.get() == null) // FIXME: should never occur
65: {
66: log.warn("No Content Properties in RequestContext ({})", this);
67: return modelFactory.createProperties().build();
68: }
69:
70: return contentHolder.get().getProperties();
71: }
72:
73: @Override @Nonnull
74: public ResourceProperties getNodeProperties()
75: {
76:• if (contentHolder.get() == null) // FIXME: should never occur
77: {
78: log.warn("No Node Properties in RequestContext ({})", this);
79: return dynamicNodePropertiesHolder.get();
80: }
81:
82: return nodeHolder.get().getProperties().merged(dynamicNodePropertiesHolder.get());
83: }
84:
85: @Override
86: public void setContent (@Nonnull final Content content)
87: {
88: contentHolder.set(content);
89: }
90:
91: @Override
92: public void setNode (@Nonnull final SiteNode node)
93: {
94: nodeHolder.set(node);
95: dynamicNodePropertiesHolder.set(modelFactory.createProperties().build());
96: }
97:
98: @Override
99: public void clearContent()
100: {
101: contentHolder.remove();
102: }
103:
104: @Override
105: public void clearNode()
106: {
107: nodeHolder.remove();
108: dynamicNodePropertiesHolder.remove();
109: }
110:
111: @Override
112: public void requestReset()
113: {
114: clearNode();
115: clearContent();
116: }
117:
118: @Override
119: public <Type> void setDynamicNodeProperty (@Nonnull final Key<Type> key, @Nonnull final Type value)
120: {
121: final var properties = dynamicNodePropertiesHolder.get();
122: dynamicNodePropertiesHolder.set(properties.withProperty(key, value));
123: }
124:
125: @Override @Nonnull
126: public String toString()
127: {
128: return String.format("RequestContext(content: %s, node: %s)", toString(contentHolder.get()), toString(nodeHolder.get()));
129: }
130:
131: @Nonnull
132: private static String toString (@CheckForNull final Resource resource)
133: {
134:• return (resource == null) ? "null" : resource.getFile().getPath().asString();
135: }
136: }