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.requests;
019
020import io.stallion.Context;
021import io.stallion.dataAccess.MappedModel;
022import io.stallion.dataAccess.ModelBase;
023import io.stallion.utils.rss.RssLink;
024import io.stallion.settings.Settings;
025
026import java.util.HashSet;
027import java.util.LinkedHashSet;
028import java.util.List;
029import java.util.Set;
030
031import static io.stallion.utils.Literals.*;
032
033
034public class MetaInformation extends ModelBase {
035    private String title = "";
036    private String description = "";
037    private String author = "";
038    private String image = "";
039    private String siteName = "";
040    private String canonicalUrl = "";
041    private Set<RssLink> rssLinks = new HashSet<RssLink>();
042    private String ogType = "";
043    private List<String> cssClasses = list();
044    private String bodyCssId = "";
045    private Set<String> footerJavascripts = new LinkedHashSet<>();
046    private Set<String> headerStylesheets = new LinkedHashSet<>();
047    private Set<String> footerBundles = new LinkedHashSet<>();
048    private Set<String> headerBundles = new LinkedHashSet<>();
049
050
051    public String getTitle() {
052        if (empty(title)) {
053            return Context.getSettings().getDefaultTitle();
054        }
055        return title;
056    }
057
058    public void setTitle(String title) {
059        this.title = title;
060    }
061
062
063    public String getDescription() {
064        if (empty(description)) {
065            return Context.getSettings().getMetaDescription();
066        }
067        return description;
068    }
069
070    public void setDescription(String description) {
071        this.description = description;
072    }
073
074
075    public String getAuthor() {
076        if (empty(author)) {
077            return Context.getSettings().getAuthorName();
078        }
079        return author;
080    }
081
082    public void setAuthor(String author) {
083        this.author = author;
084    }
085
086    public String getImage() {
087        return image;
088    }
089
090    public void setImage(String image) {
091        this.image = image;
092    }
093
094    public String getSiteName() {
095        if (empty(siteName)) {
096            Context.getSettings().getSiteName();
097        }
098        return siteName;
099    }
100
101    public void setSiteName(String siteName) {
102        this.siteName = siteName;
103    }
104
105    public String getUrl() {
106        if (!empty(getCanonicalUrl())) {
107            return getCanonicalUrl();
108        } else {
109            return Context.getRequest().requestUrl();
110        }
111    }
112
113    public String getCanonicalUrl() {
114        return canonicalUrl;
115    }
116
117    public void setCanonicalUrl(String canonicalUrl) {
118        this.canonicalUrl = canonicalUrl;
119    }
120
121    public String getOgType() {
122        return ogType;
123    }
124
125    public void setOgType(String ogType) {
126        this.ogType = ogType;
127    }
128
129    public List<String> getCssClasses() {
130        return cssClasses;
131    }
132
133    public void setCssClasses(List<String> cssClasses) {
134        this.cssClasses = cssClasses;
135    }
136
137    public String getBodyCssId() {
138        return bodyCssId;
139    }
140
141    public void setBodyCssId(String bodyCssId) {
142        this.bodyCssId = bodyCssId;
143    }
144
145    public Set<RssLink> getRssLinks() {
146        return rssLinks;
147    }
148
149    public void setRssLinks(Set<RssLink> rssLinks) {
150        this.rssLinks = rssLinks;
151    }
152
153    public String getGenerator() {
154        return or(Settings.instance().getMetaGenerator(), "Stallion");
155    }
156
157
158}
159