001/*
002 * Stallion Core: A Modern Web Framework
003 *
004 * Copyright (C) 2015 - 2016 Stallion Software LLC.
005 *
006 * This program is free software: you can redistribute it and/or modify it under the terms of the
007 * GNU General Public License as published by the Free Software Foundation, either version 2 of
008 * the License, or (at your option) any later version. This program is distributed in the hope that
009 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
011 * License for more details. You should have received a copy of the GNU General Public License
012 * along with this program.  If not, see <http://www.gnu.org/licenses/gpl-2.0.html>.
013 *
014 *
015 *
016 */
017
018package io.stallion.settings;
019
020import io.stallion.Context;
021import org.apache.commons.lang3.StringUtils;
022
023import java.io.File;
024
025
026public class ContentFolder {
027    private String type = "";
028    private String path = "";
029    private String itemTemplate = "";
030    private String className = "";
031    private String relativePath = "";
032    private String fullPath = "";
033    private Boolean writable = false;
034    private boolean listingEnabled = false;
035    private String listingRootUrl = "";
036    private String listingTemplate = "";
037    private String listingTitle = "";
038    private String listingMetaDescription = "";
039    private int itemsPerPage = 10;
040    private String bucket;
041
042
043    public String getType() {
044        return type;
045    }
046
047    public ContentFolder setType(String type) {
048        this.type = type;
049        return this;
050    }
051
052    public String getPath() {
053        return path;
054    }
055
056    public ContentFolder setPath(String path) {
057        this.path = path;
058        return this;
059    }
060
061    public String getItemTemplate() {
062        return itemTemplate;
063    }
064
065    public ContentFolder setItemTemplate(String itemTemplate) {
066        this.itemTemplate = itemTemplate;
067        return this;
068    }
069
070    public String getClassName() {
071        return className;
072    }
073
074    public ContentFolder setClassName(String className) {
075        this.className = className;
076        return this;
077    }
078
079    public ContentFolder hydratePaths() {
080        if (StringUtils.isEmpty(path)) {
081            return this;
082        }
083        if (path.startsWith("/")) {
084            setFullPath(path);
085            setRelativePath(new File(path).getName());
086        } else {
087            if (StringUtils.isEmpty(getFullPath())) {
088                setFullPath(Context.settings().getTargetFolder() + "/" + path);
089            }
090            setRelativePath(path);
091        }
092        return this;
093    }
094
095
096    public String getRelativePath() {
097        return relativePath;
098    }
099
100    public ContentFolder setRelativePath(String relativePath) {
101        this.relativePath = relativePath;
102        return this;
103    }
104
105    public String getFullPath() {
106        return fullPath;
107    }
108
109    public ContentFolder setFullPath(String fullPath) {
110        this.fullPath = fullPath;
111        return this;
112    }
113
114    public Boolean getWritable() {
115        return writable;
116    }
117
118    public ContentFolder setWritable(Boolean writable) {
119        this.writable = writable;
120        return this;
121    }
122
123    public boolean isListingEnabled() {
124        return listingEnabled;
125    }
126
127    public ContentFolder setListingEnabled(boolean listingEnabled) {
128        this.listingEnabled = listingEnabled;
129        return this;
130    }
131
132    public String getListingRootUrl() {
133        return listingRootUrl;
134    }
135
136    public ContentFolder setListingRootUrl(String listingRootUrl) {
137        this.listingRootUrl = listingRootUrl;
138        return this;
139    }
140
141    public String getListingTemplate() {
142        return listingTemplate;
143    }
144
145    public ContentFolder setListingTemplate(String listingTemplate) {
146        this.listingTemplate = listingTemplate;
147        return this;
148    }
149
150    public String getListingTitle() {
151        return listingTitle;
152    }
153
154    public ContentFolder setListingTitle(String listingTitle) {
155        this.listingTitle = listingTitle;
156        return this;
157    }
158
159    public String getListingMetaDescription() {
160        return listingMetaDescription;
161    }
162
163    public ContentFolder setListingMetaDescription(String listingMetaDescription) {
164        this.listingMetaDescription = listingMetaDescription;
165        return this;
166    }
167
168    public int getItemsPerPage() {
169        return itemsPerPage;
170    }
171
172    public ContentFolder setItemsPerPage(int itemsPerPage) {
173        this.itemsPerPage = itemsPerPage;
174        return this;
175    }
176
177    public String getBucket() {
178        if (bucket == null) {
179            return new File(path).getName();
180        }
181        return bucket;
182    }
183
184    public ContentFolder setBucket(String bucket) {
185        this.bucket = bucket;
186        return this;
187    }
188}