Skip to contentPackage: Site
Site
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.model;
27:
28: import javax.annotation.Nonnull;
29: import java.util.List;
30: import java.util.Locale;
31: import java.util.Optional;
32: import java.nio.file.spi.FileSystemProvider;
33: import it.tidalwave.util.Finder;
34: import lombok.AccessLevel;
35: import lombok.AllArgsConstructor;
36: import lombok.Getter;
37: import lombok.RequiredArgsConstructor;
38: import lombok.ToString;
39: import lombok.With;
40:
41: /***************************************************************************************************************************************************************
42: *
43: * The model for the container of the whole site, it contains a collection of {@link Content}s, {@link Media} items and
44: * {@link SiteNode}s.
45: *
46: * @author Fabrizio Giudici
47: *
48: **************************************************************************************************************************************************************/
49: public interface Site
50: {
51: /***********************************************************************************************************************************************************
52: * A builder of a {@link Site}.
53: **********************************************************************************************************************************************************/
54: @AllArgsConstructor(access = AccessLevel.PRIVATE) @RequiredArgsConstructor
55: @Getter @ToString(exclude = "callBack")
56: public final class Builder
57: {
58: // Workaround for a Lombok limitation with Wither and subclasses
59: @FunctionalInterface
60: public static interface CallBack
61: {
62: @Nonnull
63: public Site build (@Nonnull Builder builder);
64: }
65:
66: @Nonnull
67: private final ModelFactory modelFactory;
68:
69: @Nonnull
70: private final CallBack callBack;
71:
72: @With
73: private String contextPath;
74:
75: @With
76: private String documentPath;
77:
78: @With
79: private String mediaPath;
80:
81: @With
82: private String libraryPath;
83:
84: @With
85: private String nodePath;
86:
87: @With
88: private boolean logConfigurationEnabled;
89:
90: @With
91: private List<Locale> configuredLocales;
92:
93: @With
94: private List<String> ignoredFolders;
95:
96: @Nonnull
97: public Site build()
98: {
99: return callBack.build(this);
100: }
101: }
102:
103: /***********************************************************************************************************************************************************
104: * Returns the context path for this web site.
105: **********************************************************************************************************************************************************/
106: @Nonnull
107: public String getContextPath();
108:
109: /***********************************************************************************************************************************************************
110: * Creates an HTML link to the node mapped to the given URI.
111: *
112: * @param relativeUri the target URI
113: * @return the link
114: **********************************************************************************************************************************************************/
115: @Nonnull
116: public String createLink (@Nonnull ResourcePath relativeUri);
117:
118: /***********************************************************************************************************************************************************
119: * Finds something.
120: *
121: * @param <TYPE> the static type of the thing to find
122: * @param type the dynamic type of thing to find
123: * @return the {@link Finder} for that thing.
124: **********************************************************************************************************************************************************/
125: @Nonnull
126: public <TYPE> SiteFinder<TYPE> find (@Nonnull Class<TYPE> type);
127:
128: /***********************************************************************************************************************************************************
129: * Returns the {@link FileSystemProvider} used by this {@code Site}.
130: *
131: * @return the {@code FileSystemProvider}
132: **********************************************************************************************************************************************************/
133: @Nonnull
134: public ResourceFileSystemProvider getFileSystemProvider();
135:
136: /***********************************************************************************************************************************************************
137: * Returns the {@link Locale}s configured for this site.
138: *
139: * @return the {@code Locale}s.
140: **********************************************************************************************************************************************************/
141: @Nonnull
142: public List<Locale> getConfiguredLocales();
143:
144: /***********************************************************************************************************************************************************
145: * Gets a template from a {@link Content}, whose relative path is provided; the template is retrieved through the
146: * property {@code P_TEMPLATE} of the {@code Content}. If nothing is found, a default template with the given name
147: * is loaded from the embedded resources.
148: *
149: * @param clazz the class used as starting point for resolving the embedded resource path
150: * @param templatePath the path of the {@code Content}
151: * @param embeddedResourceName the name of the default embedded resource
152: * @return the template contents
153: **********************************************************************************************************************************************************/
154: @Nonnull
155: public Template getTemplate (@Nonnull Class<?> clazz,
156: @Nonnull Optional<? extends ResourcePath> templatePath,
157: @Nonnull String embeddedResourceName);
158:
159: /***********************************************************************************************************************************************************
160: * Gets a template from a {@link Content}, whose relative path is provided. The template is retrieved through the
161: * property {@code P_TEMPLATE} of the {@code Content}.
162: *
163: * @param clazz the class used as starting point for resolving the embedded resource path
164: * @param templatePath the path of the {@code Content}
165: * @return the template contents
166: **********************************************************************************************************************************************************/
167: @Deprecated
168: @Nonnull
169: public Optional<String> getTemplate (@Nonnull Class<?> clazz, @Nonnull ResourcePath templatePath);
170: }