Skip to content

Package: ResourceFileNetBeansPlatform

ResourceFileNetBeansPlatform

nameinstructionbranchcomplexitylinemethod
ResourceFileNetBeansPlatform(ResourceFileSystemNetBeansPlatform, FileObject)
M: 6 C: 83
93%
M: 11 C: 11
50%
M: 11 C: 1
8%
M: 0 C: 6
100%
M: 0 C: 1
100%
copyTo(ResourceFile)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
createFolder(String)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
findChildren()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getLatestModificationTime()
M: 19 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getMimeType()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getName()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getParent()
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getPath()
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$findChildren$0(ResourceFile.Finder)
M: 15 C: 36
71%
M: 3 C: 3
50%
M: 2 C: 2
50%
M: 4 C: 8
67%
M: 0 C: 1
100%
static {...}
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
toFile()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 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.frontend.filesystem.impl;
27:
28: import javax.annotation.Nonnull;
29: import javax.inject.Inject;
30: import javax.inject.Provider;
31: import java.time.Instant;
32: import java.time.ZoneId;
33: import java.time.ZonedDateTime;
34: import java.util.ArrayList;
35: import java.util.Collection;
36: import java.util.Collections;
37: import java.util.Date;
38: import java.util.List;
39: import java.io.File;
40: import java.io.IOException;
41: import org.springframework.beans.factory.annotation.Configurable;
42: import org.openide.filesystems.FileObject;
43: import org.openide.filesystems.FileUtil;
44: import it.tidalwave.util.As;
45: import it.tidalwave.northernwind.core.model.MimeTypeResolver;
46: import it.tidalwave.northernwind.core.model.ResourceFile;
47: import it.tidalwave.northernwind.core.model.ResourceFileSystem;
48: import it.tidalwave.northernwind.core.model.ResourcePath;
49: import it.tidalwave.northernwind.core.model.spi.ResourceFileFinderSupport;
50: import lombok.Getter;
51: import lombok.ToString;
52: import lombok.experimental.Delegate;
53: import lombok.extern.slf4j.Slf4j;
54:
55: /***************************************************************************************************************************************************************
56: *
57: * @author Fabrizio Giudici
58: *
59: **************************************************************************************************************************************************************/
60: @Configurable @Slf4j @ToString(of = "delegate")
61: public class ResourceFileNetBeansPlatform implements ResourceFile
62: {
63: interface Exclusions
64: {
65: public String getName();
66: public ResourcePath getPath();
67: public ResourceFile getParent();
68: public ResourceFile getFileObject (String fileName);
69: public Collection<ResourceFile> getChildren();
70: public Collection<ResourceFile> getChildren (boolean b);
71: public String getMIMEType();
72: public File toFile();
73: public ResourceFile createFolder (String name);
74: public void copyTo (ResourceFile targetFolder);
75: public ResourceFileSystem getFileSystem();
76: public Date lastModified();
77: }
78:
79: @Inject
80: private Provider<MimeTypeResolver> mimeTypeResolver;
81:
82: @Getter @Nonnull
83: private final ResourceFileSystemNetBeansPlatform fileSystem;
84:
85: @Getter @Delegate(excludes = Exclusions.class) @Nonnull
86: private final FileObject delegate;
87:
88: @Delegate
89: private final As asSupport = As.forObject(this);
90:
91: public ResourceFileNetBeansPlatform (@Nonnull final ResourceFileSystemNetBeansPlatform fileSystem,
92: @Nonnull final FileObject delegate)
93:• {
94: this.fileSystem = fileSystem;
95: this.delegate = delegate;
96:• }
97:
98: @Override @Nonnull
99: public ResourcePath getPath()
100: {
101: return ResourcePath.of(delegate.getPath());
102: }
103:
104: @Override @Nonnull
105: public String getName()
106: {
107: return delegate.getNameExt();
108: }
109:
110: @Override
111: public ResourceFile getParent()
112: {
113: return fileSystem.createResourceFile(delegate.getParent());
114: }
115:
116: @Override @Nonnull
117: public ResourceFile createFolder (@Nonnull final String name)
118: throws IOException
119: {
120: return fileSystem.createResourceFile(delegate.createFolder(name));
121: }
122:
123: @Override @Nonnull
124: public Finder findChildren()
125: {
126: return ResourceFileFinderSupport.withComputeResults(getClass().getSimpleName(), f ->
127: {
128: final var name = f.getName();
129: final var recursive = f.isRecursive();
130:
131: final List<ResourceFile> result = new ArrayList<>();
132:
133:• if (name != null)
134: {
135: final var child = delegate.getFileObject(name);
136:
137:• if (child != null)
138: {
139: result.add(fileSystem.createResourceFile(child));
140: }
141: }
142: else
143: {
144:• for (final FileObject child : Collections.list(delegate.getChildren(recursive)))
145: {
146: result.add(fileSystem.createResourceFile(child));
147: }
148: }
149:
150: return result;
151: });
152: }
153:
154: @Override @Nonnull
155: public String getMimeType()
156: {
157: return mimeTypeResolver.get().getMimeType(delegate.getNameExt());
158: }
159:
160: @Override @Nonnull
161: public ZonedDateTime getLatestModificationTime()
162: {
163: // See NW-154
164: final var file = toFile();
165:
166:• final var millis = (file != null) ? file.lastModified() : delegate.lastModified().getTime();
167: return Instant.ofEpochMilli(millis).atZone(ZoneId.of("GMT"));
168: }
169:
170: @Nonnull
171: @Override
172: public File toFile()
173: {
174: return FileUtil.toFile(delegate);
175: }
176:
177: @Override
178: public void copyTo (@Nonnull final ResourceFile targetFolder)
179: throws IOException
180: {
181: FileUtil.copyFile(delegate, ((ResourceFileNetBeansPlatform)targetFolder).delegate, delegate.getName());
182: }
183:
184: // TODO: equals and hashcode
185: }