BrightSide Workbench Full Report + Source Code
StandardFolder.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.entities;
20 
21 import java.nio.file.Path;
22 import org.turro.elephant.context.ElephantContext;
23 import org.turro.file.Folder;
24 import org.turro.plugin.contacts.IContact;
25 
30 public class StandardFolder {
31 
32  private static final String
33  PUBLISHABLE = "/_internal/files",
34  INTERNAL = "/WEB-INF/files";
35 
36  public static Folder publishable(String entityPath) {
37  return Folder.from(Path.of(ElephantContext.getRealPath(PUBLISHABLE), entityPath));
38  }
39 
40  public static Folder internal(String entityPath) {
41  return Folder.from(Path.of(ElephantContext.getRealPath(INTERNAL), entityPath));
42  }
43 
44  public static Folder publishable(String entityPath, String folder) {
45  return Folder.from(Path.of(ElephantContext.getRealPath(PUBLISHABLE), entityPath, folder));
46  }
47 
48  public static Folder internal(String entityPath, String folder) {
49  return Folder.from(Path.of(ElephantContext.getRealPath(INTERNAL), entityPath, folder));
50  }
51 
52  /* Getters */
53 
54  public String asString() {
55  return path;
56  }
57 
58  public Path asPath() {
59  return Path.of(path);
60  }
61 
62  public Folder asFolder() {
63  return Folder.from(path);
64  }
65 
66  /* Modifiers */
67 
68  public StandardFolder real() {
69  path = ElephantContext.getRealPath(path);
70  return this;
71  }
72 
73  public StandardFolder entity(Object entity) {
74  if(entity instanceof IContact contact) entity = contact.getContact();
75  path = path + Entities.getController(entity).getPath();
76  return this;
77  }
78 
80  path = path + entityPath;
81  return this;
82  }
83 
84  public StandardFolder folder(String folder) {
85  path = path + "/" + folder;
86  return this;
87  }
88 
89  /* Factory */
90 
91  public static StandardFolder publishable() {
92  return new StandardFolder("/_internal/files");
93  }
94 
95  public static StandardFolder internal() {
96  return new StandardFolder("/WEB-INF/files");
97  }
98 
99  private String path;
100 
101  private StandardFolder(String path) {
102  this.path = path;
103  }
104 
105 }
static IElephantEntity getController(String path)
Definition: Entities.java:78
StandardFolder entityPath(String entityPath)
StandardFolder entity(Object entity)
static StandardFolder publishable()
static Folder publishable(String entityPath)
StandardFolder folder(String folder)
static Folder publishable(String entityPath, String folder)