Integrated templates into theme manifest

git-svn-id: https://svn.libreccm.org/ccm/trunk@5848 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2019-03-05 16:21:39 +00:00
parent 077eceba52
commit d0cfc3084c
6 changed files with 24 additions and 230 deletions

View File

@ -1,5 +1,9 @@
package org.libreccm.theming; package org.libreccm.theming;
import org.libreccm.theming.manifest.ApplicationTemplate;
import org.libreccm.theming.manifest.ContentItemTemplate;
import org.libreccm.theming.manifest.Templates;
import com.arsdigita.bebop.Bebop; import com.arsdigita.bebop.Bebop;
import com.arsdigita.bebop.page.PageTransformer; import com.arsdigita.bebop.page.PageTransformer;
import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.domain.DataObjectNotFoundException;
@ -102,39 +106,6 @@ public class FreeMarkerPresentationManager implements PresentationManager {
final ServletContext servletContext = Web.getServletContext(); final ServletContext servletContext = Web.getServletContext();
// final String themeManifest = "";
// final String themeManifest = new BufferedReader(
// new InputStreamReader(
// servletContext.getResourceAsStream(themeManifestPath),
// StandardCharsets.UTF_8))
// .lines()
// .collect(Collectors.joining(System.lineSeparator()));
//
// String name = "???";
// final JsonFactory jsonFactory = new JsonFactory();
// try {
// final JsonParser parser = jsonFactory.createParser(servletContext
// .getResourceAsStream(themeManifestPath));
//
// while (!parser.isClosed()) {
//
// final JsonToken token = parser.nextToken();
// if (JsonToken.FIELD_NAME.equals(token)) {
// final String fieldName = parser.getCurrentName();
//
// if ("name".equals(fieldName)) {
//
// final JsonToken valueToken = parser.nextToken();
// final String value = parser.getValueAsString();
// name = value;
// }
// }
//
// }
//
// } catch (IOException ex) {
// throw new UncheckedWrapperException(ex);
// }
final InputStream manifestInputStream = servletContext final InputStream manifestInputStream = servletContext
.getResourceAsStream(themeManifestPath); .getResourceAsStream(themeManifestPath);
if (manifestInputStream == null) { if (manifestInputStream == null) {
@ -148,17 +119,7 @@ public class FreeMarkerPresentationManager implements PresentationManager {
.loadManifest(manifestInputStream, .loadManifest(manifestInputStream,
themeManifestPath); themeManifestPath);
final ObjectMapper objectMapper = new ObjectMapper(); final Templates templates = manifest.getTemplates();
objectMapper.registerModule(new JaxbAnnotationModule());
final Templates templates;
try {
templates = objectMapper.readValue(
servletContext.getResourceAsStream(
String.format("%stemplates.json", themePath)),
Templates.class);
} catch (IOException ex) {
throw new UncheckedWrapperException(ex);
}
// ToDo // ToDo
final NamedNodeMap pageAttrs = root.getAttributes(); final NamedNodeMap pageAttrs = root.getAttributes();

View File

@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
package org.libreccm.theming; package org.libreccm.theming.manifest;
import static org.libreccm.theming.ThemeConstants.*; import static org.libreccm.theming.ThemeConstants.*;

View File

@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
package org.libreccm.theming; package org.libreccm.theming.manifest;
import static org.libreccm.theming.ThemeConstants.*; import static org.libreccm.theming.ThemeConstants.*;
@ -14,6 +14,8 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.libreccm.theming.ContentItemViews;
/** /**
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>

View File

@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
package org.libreccm.theming; package org.libreccm.theming.manifest;
import static org.libreccm.theming.ThemeConstants.*; import static org.libreccm.theming.ThemeConstants.*;
@ -18,6 +18,7 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
/** /**
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>

View File

@ -20,15 +20,11 @@ package org.libreccm.theming.manifest;
import org.libreccm.l10n.LocalizedString; import org.libreccm.l10n.LocalizedString;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import static org.libreccm.theming.ThemeConstants.*; import static org.libreccm.theming.ThemeConstants.*;
@ -75,12 +71,14 @@ public class ThemeManifest implements Serializable {
@XmlElement(name = "description", namespace = THEMES_XML_NS) @XmlElement(name = "description", namespace = THEMES_XML_NS)
private LocalizedString description; private LocalizedString description;
/** // /**
* The templates provided by the theme. // * The templates provided by the theme.
*/ // */
@XmlElementWrapper(name = "templates", namespace = THEMES_XML_NS) // @XmlElementWrapper(name = "templates", namespace = THEMES_XML_NS)
@XmlElement(name = "template", namespace = THEMES_XML_NS) // @XmlElement(name = "template", namespace = THEMES_XML_NS)
private List<ThemeTemplate> templates; // private List<ThemeTemplate> templates;
@XmlElement(name = "templates")
private Templates templates;
/** /**
* Path of the default template. * Path of the default template.
@ -89,7 +87,7 @@ public class ThemeManifest implements Serializable {
private String defaultTemplate; private String defaultTemplate;
public ThemeManifest() { public ThemeManifest() {
templates = new ArrayList<>(); // templates = new ArrayList<>();
} }
public String getName() { public String getName() {
@ -132,20 +130,12 @@ public class ThemeManifest implements Serializable {
this.description = description; this.description = description;
} }
public List<ThemeTemplate> getTemplates() { public Templates getTemplates() {
return Collections.unmodifiableList(templates); return templates;
} }
public void setTemplates(final List<ThemeTemplate> templates) { public void setTemplates(final Templates templates) {
this.templates = new ArrayList<>(templates); this.templates = templates;
}
public void addThemeTemplate(final ThemeTemplate template) {
templates.add(template);
}
public void removeThemeTemplate(final ThemeTemplate template) {
templates.remove(template);
} }
public String getDefaultTemplate() { public String getDefaultTemplate() {

View File

@ -1,160 +0,0 @@
/*
* Copyright (C) 2017 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.libreccm.theming.manifest;
import org.libreccm.l10n.LocalizedString;
import java.io.Serializable;
import java.util.Objects;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* Informations about a template provided by a theme.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@XmlRootElement(name = "template", namespace = "http://themes.libreccm.org")
@XmlAccessorType(XmlAccessType.FIELD)
public class ThemeTemplate implements Serializable {
private static final long serialVersionUID = -9034588759798295569L;
/**
* The name of the template (usually the filename).
*/
@XmlElement(name = "name", namespace = "http://themes.libreccm.org")
private String name;
/**
* The (localised) title of the template.
*/
@XmlElement(name = "title", namespace = "http://themes.libreccm.org")
private LocalizedString title;
/**
* A (localised) description of the template.
*/
@XmlElement(name = "description", namespace = "http://themes.libreccm.org")
private LocalizedString description;
/**
* Path of template relative to the directory of the theme.
*/
@XmlElement(name = "path", namespace = "http://themes.libreccm.org")
private String path;
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public LocalizedString getTitle() {
return title;
}
public void setTitle(final LocalizedString title) {
this.title = title;
}
public LocalizedString getDescription() {
return description;
}
public void setDescription(final LocalizedString description) {
this.description = description;
}
public String getPath() {
return path;
}
public void setPath(final String path) {
this.path = path;
}
@Override
public int hashCode() {
int hash = 3;
hash = 67 * hash + Objects.hashCode(name);
hash = 67 * hash + Objects.hashCode(title);
hash = 67 * hash + Objects.hashCode(description);
hash = 67 * hash + Objects.hashCode(path);
return hash;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof ThemeTemplate)) {
return false;
}
final ThemeTemplate other = (ThemeTemplate) obj;
if (!other.canEqual(this)) {
return false;
}
if (!Objects.equals(name, other.getName())) {
return false;
}
if (!Objects.equals(path, other.getPath())) {
return false;
}
if (!Objects.equals(title, other.getTitle())) {
return false;
}
return Objects.equals(description, other.getDescription());
}
public boolean canEqual(final Object obj) {
return obj instanceof ThemeTemplate;
}
@Override
public String toString() {
return toString("");
}
public String toString(final String data) {
return String.format("%s{ "
+ "name = \"%s\", "
+ "title = %s, "
+ "description = %s, "
+ "path = \"%s\"%s"
+ " }",
super.toString(),
name,
Objects.toString(title),
Objects.toString(description),
path,
data);
}
}