Package: Resource$Builder
Resource$Builder
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Resource.Builder(ModelFactory, Resource.Builder.CallBack) |
|
|
|
|
|
||||||||||||||||||||
Resource.Builder(ModelFactory, Resource.Builder.CallBack, ResourceFile) |
|
|
|
|
|
||||||||||||||||||||
build() |
|
|
|
|
|
||||||||||||||||||||
getCallBack() |
|
|
|
|
|
||||||||||||||||||||
getFile() |
|
|
|
|
|
||||||||||||||||||||
getModelFactory() |
|
|
|
|
|
||||||||||||||||||||
toString() |
|
|
|
|
|
||||||||||||||||||||
withFile(ResourceFile) |
|
|
|
|
|
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.model;
28:
29: import javax.annotation.Nonnull;
30: import java.util.List;
31: import java.util.Optional;
32: import it.tidalwave.util.As;
33: import it.tidalwave.util.Id;
34: import it.tidalwave.util.Key;
35: import lombok.AccessLevel;
36: import lombok.AllArgsConstructor;
37: import lombok.Getter;
38: import lombok.RequiredArgsConstructor;
39: import lombok.ToString;
40: import lombok.With;
41:
42: /***********************************************************************************************************************
43: *
44: * A resource is the basic entity of NorthernWind. It's something located in the filesystem and represented by a file
45: * or a folder, with a bag of properties.
46: *
47: * @author Fabrizio Giudici
48: *
49: **********************************************************************************************************************/
50: public interface Resource extends As
51: {
52: public static final Class<Resource> _Resource_ = Resource.class;
53:
54: /*******************************************************************************************************************
55: *
56: * A builder of a {@link Resource}.
57: *
58: ******************************************************************************************************************/
59: @AllArgsConstructor(access = AccessLevel.PRIVATE) @RequiredArgsConstructor
60: @Getter @ToString(exclude = "callBack")
61: public final class Builder
62: {
63: // Workaround for a Lombok limitation with Wither and subclasses
64: @FunctionalInterface
65: public static interface CallBack
66: {
67: @Nonnull
68: public Resource build (@Nonnull Builder builder);
69: }
70:
71: @Nonnull
72: private final ModelFactory modelFactory;
73:
74: @Nonnull
75: private final CallBack callBack;
76:
77:• @With
78: private ResourceFile file;
79:
80: @Nonnull
81: public Resource build()
82: {
83: return callBack.build(this);
84: }
85: }
86:
87: /** The local portion of relativeUri by which a resource is exposed to the web. If this property is not
88: * defined, the resource uses a reasonable default. */
89: public static final Key<String> P_EXPOSED_URI = Key.of("exposedUri", String.class);
90:
91: /** This property, controls whether this resource is a placeholder. See {@link #isPlaceHolder} for more information
92: */
93: public static final Key<Boolean> P_PLACE_HOLDER = Key.of("placeHolder", Boolean.class);
94:
95: /*******************************************************************************************************************
96: *
97: * Returns the file backing this resource. It can be a plain file or a directory in function of the resource type.
98: *
99: * @return the file
100: *
101: ******************************************************************************************************************/
102: @Nonnull
103: public ResourceFile getFile();
104:
105: /*******************************************************************************************************************
106: *
107: * Returns the properties of this resource.
108: *
109: * @return the properties
110: *
111: ******************************************************************************************************************/
112: @Nonnull
113: public ResourceProperties getProperties();
114:
115: /*******************************************************************************************************************
116: *
117: * Shortcut for {@code getProperties().getProperty(key)}.
118: *
119: * @param key the key
120: * @return the property
121: *
122: ******************************************************************************************************************/
123: @Nonnull
124: public default <T> Optional<T> getProperty (@Nonnull final Key<T> key)
125: {
126: return getProperties().getProperty(key);
127: }
128:
129: /*******************************************************************************************************************
130: *
131: * Shortcut for {@code getProperties().getProperty(keys)}.
132: *
133: * @param keys the keys
134: * @return the property
135: *
136: ******************************************************************************************************************/
137: @Nonnull
138: public default <T> Optional<T> getProperty (@Nonnull final List<Key<T>> keys)
139: {
140: return getProperties().getProperty(keys);
141: }
142:
143: /*******************************************************************************************************************
144: *
145: * Returns the property group of this resources with the given id. Empty properties are returned when id doesn't
146: * match.
147: *
148: * @param id the id of the property group
149: * @return the properties
150: *
151: ******************************************************************************************************************/
152: @Nonnull
153: public ResourceProperties getPropertyGroup (@Nonnull Id id);
154:
155: /*******************************************************************************************************************
156: *
157: * A placeholder resource doesn't contain anything, it just provides a placeholder for a path element. For instance,
158: * if in the pair parent/child child is a placeholder, the relative URI /parent/child will be mapped to parent
159: * (which supposedly manages path params). This is useful for processing REST path params, for instance.
160: *
161: * @return {@code true} if this resource is a placeholder
162: *
163: ******************************************************************************************************************/
164: public boolean isPlaceHolder();
165: }