Package: AdminResource
AdminResource
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AdminResource(Resource.Builder) |
|
|
|
|
|
||||||||||||||||||||
getProperties() |
|
|
|
|
|
||||||||||||||||||||
isPlaceHolder() |
|
|
|
|
|
||||||||||||||||||||
loadProperties() |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
Coverage
1: /*
2: * #%L
3: * *********************************************************************************************************************
4: *
5: * NorthernWind - lightweight CMS
6: * http://northernwind.tidalwave.it - git clone git@bitbucket.org:tidalwave/northernwind-rca-src.git
7: * %%
8: * Copyright (C) 2013 - 2021 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.model.impl.admin;
28:
29: import javax.annotation.Nonnull;
30: import java.io.IOException;
31: import java.io.InputStream;
32: import it.tidalwave.util.NotFoundException;
33: import it.tidalwave.northernwind.core.model.Resource;
34: import it.tidalwave.northernwind.core.model.ResourceFile;
35: import it.tidalwave.northernwind.core.model.ResourceProperties;
36: import it.tidalwave.northernwind.core.model.spi.ResourceSupport;
37: import lombok.Cleanup;
38: import lombok.extern.slf4j.Slf4j;
39: import static it.tidalwave.role.io.Unmarshallable.*;
40:
41: /***********************************************************************************************************************
42: *
43: * @author Fabrizio Giudici
44: *
45: **********************************************************************************************************************/
46: @Slf4j
47: public class AdminResource extends ResourceSupport
48: {
49: @Nonnull
50: private final PatchedTextResourcePropertyResolver propertyResolver;
51:
52: public AdminResource (@Nonnull final Resource.Builder builder)
53: {
54: super(builder);
55: propertyResolver = new PatchedTextResourcePropertyResolver(getFile());
56: }
57:
58: /*******************************************************************************************************************
59: *
60: * {@inheritDoc}
61: *
62: ******************************************************************************************************************/
63: @Override @Nonnull
64: public ResourceProperties getProperties()
65: {
66: try
67: {
68: return loadProperties();
69: }
70: catch (IOException e)
71: {
72: throw new RuntimeException(e);
73: }
74: }
75:
76: @Override
77: public boolean isPlaceHolder()
78: {
79: throw new UnsupportedOperationException("Not supported yet.");
80: }
81:
82: /*******************************************************************************************************************
83: *
84: *
85: ******************************************************************************************************************/
86: @Nonnull
87: private ResourceProperties loadProperties()
88: throws IOException
89: {
90: final ResourceFile file = getFile();
91: log.debug("loadProperties() for {}", file.getPath().asString());
92:
93: ResourceProperties properties = modelFactory.createProperties().withPropertyResolver(propertyResolver).build();
94:
95: try
96: {
97: final ResourceFile propertyFile = file.findChildren().withName("Properties.xml").result(); // FIXME reuse the inheritance helper
98: // log.trace(">>>> reading properties from {} ({})...", propertyFile.getPath().asString(), locale);
99:• @Cleanup final InputStream is = propertyFile.getInputStream();
100: final ResourceProperties tempProperties =
101: // modelFactory.createProperties().build().as(_Unmarshallable_).unmarshal(is);
102: modelFactory.createProperties().withPropertyResolver(propertyResolver).build().as(_Unmarshallable_).unmarshal(is);
103: // log.trace(">>>>>>>> read properties: {} ({})", tempProperties, locale);
104: properties = properties.merged(tempProperties);
105: }
106: catch (NotFoundException e)
107: {
108: // ok, no properties
109: }
110:
111: return properties;
112: }
113: }