Skip to content

Package: LocalFileSystemProvider

LocalFileSystemProvider

nameinstructionbranchcomplexitylinemethod
LocalFileSystemProvider()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getFileSystem()
M: 13 C: 33
72%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 3 C: 8
73%
M: 0 C: 1
100%

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.basic;
27:
28: import javax.annotation.Nonnull;
29: import javax.annotation.Nullable;
30: import java.beans.PropertyVetoException;
31: import java.io.File;
32: import java.io.FileNotFoundException;
33: import java.io.IOException;
34: import org.openide.filesystems.LocalFileSystem;
35: import it.tidalwave.northernwind.core.model.ResourceFileSystem;
36: import it.tidalwave.northernwind.core.model.ResourceFileSystemProvider;
37: import it.tidalwave.northernwind.frontend.filesystem.impl.ResourceFileSystemNetBeansPlatform;
38: import lombok.Getter;
39: import lombok.Setter;
40: import lombok.ToString;
41:
42: /***************************************************************************************************************************************************************
43: *
44: * A provider for a {@link ResourceFileSystemProvider} implemented on Netbeans' {@code LocalFileSystem}.
45: *
46: * @author Fabrizio Giudici
47: *
48: **************************************************************************************************************************************************************/
49: @ToString(of = "rootPath")
50: public class LocalFileSystemProvider implements ResourceFileSystemProvider
51: {
52: @Getter @Setter @Nonnull
53: private String rootPath = "";
54:
55: @Nullable
56: private ResourceFileSystem fileSystem;
57:
58: @Nullable
59: private LocalFileSystem fileSystemDelegate;
60:
61: /***********************************************************************************************************************************************************
62: * {@inheritDoc}
63: **********************************************************************************************************************************************************/
64: @Override @Nonnull
65: public synchronized ResourceFileSystem getFileSystem()
66: throws IOException
67: {
68:• if (fileSystem == null)
69: {
70: try
71: {
72: fileSystemDelegate = new LocalFileSystem();
73: fileSystemDelegate.setRootDirectory(new File(rootPath));
74:
75: final var rootFolder = fileSystemDelegate.getRoot();
76:
77:• if (rootFolder == null)
78: {
79: throw new FileNotFoundException(rootPath);
80: }
81:
82: fileSystem = new ResourceFileSystemNetBeansPlatform(fileSystemDelegate);
83: }
84: catch (PropertyVetoException e)
85: {
86: throw new FileNotFoundException(e.toString());
87: }
88: }
89:
90: return fileSystem;
91: }
92: }