From 5c2387d4b34933ce20473afb19a37c47d48d5226 Mon Sep 17 00:00:00 2001 From: jensp Date: Tue, 24 Oct 2017 14:32:10 +0000 Subject: [PATCH] CCM NG: Themes system part 1 git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5076 8810af33-2d31-482b-a856-94f89814c4df --- .../org/libreccm/l10n/LocalizedString.java | 15 +- .../l10n/jaxb/LocalizedStringValue.java | 112 +++++++++++ .../l10n/jaxb/LocalizedStringValues.java | 98 ++++++++++ .../jaxb/LocalizedStringValuesAdapter.java | 77 ++++++++ .../org/libreccm/theming/ProcessesThemes.java | 50 +++++ .../org/libreccm/theming/ThemeConstants.java | 32 ++++ .../java/org/libreccm/theming/ThemeInfo.java | 95 +++++++--- .../org/libreccm/theming/ThemeProcessors.java | 80 ++++++++ .../java/org/libreccm/theming/Themes.java | 3 +- .../theming/manifest/ThemeManifest.java | 178 ++++++++++++++++++ .../theming/manifest/ThemeTemplate.java | 147 +++++++++++++++ 11 files changed, 858 insertions(+), 29 deletions(-) create mode 100644 ccm-core/src/main/java/org/libreccm/l10n/jaxb/LocalizedStringValue.java create mode 100644 ccm-core/src/main/java/org/libreccm/l10n/jaxb/LocalizedStringValues.java create mode 100644 ccm-core/src/main/java/org/libreccm/l10n/jaxb/LocalizedStringValuesAdapter.java create mode 100644 ccm-core/src/main/java/org/libreccm/theming/ProcessesThemes.java create mode 100644 ccm-core/src/main/java/org/libreccm/theming/ThemeConstants.java create mode 100644 ccm-core/src/main/java/org/libreccm/theming/ThemeProcessors.java create mode 100644 ccm-core/src/main/java/org/libreccm/theming/manifest/ThemeManifest.java create mode 100644 ccm-core/src/main/java/org/libreccm/theming/manifest/ThemeTemplate.java diff --git a/ccm-core/src/main/java/org/libreccm/l10n/LocalizedString.java b/ccm-core/src/main/java/org/libreccm/l10n/LocalizedString.java index 4dee13c29..53455b78b 100644 --- a/ccm-core/src/main/java/org/libreccm/l10n/LocalizedString.java +++ b/ccm-core/src/main/java/org/libreccm/l10n/LocalizedString.java @@ -23,13 +23,13 @@ import org.hibernate.annotations.Type; import org.hibernate.search.annotations.Field; import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; -import javax.xml.bind.annotation.XmlRootElement; import java.io.Serializable; import static org.libreccm.l10n.L10NConstants.L10N_XML_NS; +import org.libreccm.l10n.jaxb.LocalizedStringValuesAdapter; + import java.util.Collections; import java.util.HashMap; import java.util.Locale; @@ -44,6 +44,9 @@ import javax.persistence.Embeddable; import javax.persistence.FetchType; import javax.persistence.Lob; import javax.persistence.MapKeyColumn; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; /** * A helper class for localisable string properties. This class is declared as @@ -54,7 +57,8 @@ import javax.persistence.MapKeyColumn; * @author Jens Pelzetter */ @Embeddable -@XmlRootElement(name = "localized-string", namespace = L10N_XML_NS) +//@XmlRootElement(name = "localized-string", namespace = L10N_XML_NS) +@XmlAccessorType(XmlAccessType.FIELD) public class LocalizedString implements Serializable { private static final long serialVersionUID = 7378282657084330425L; @@ -69,8 +73,9 @@ public class LocalizedString implements Serializable { @Lob @Type(type = "org.hibernate.type.TextType") @Field - @XmlElementWrapper(name = "values", namespace = L10N_XML_NS) +// @XmlElementWrapper(name = "values", namespace = L10N_XML_NS) @XmlElement(name = "values", namespace = L10N_XML_NS) + @XmlJavaTypeAdapter(LocalizedStringValuesAdapter.class) private Map values; /** @@ -101,7 +106,7 @@ public class LocalizedString implements Serializable { * @param values The new map of values. */ protected void setValues(final Map values) { - this.values = values; + this.values = new HashMap<>(values); } /** diff --git a/ccm-core/src/main/java/org/libreccm/l10n/jaxb/LocalizedStringValue.java b/ccm-core/src/main/java/org/libreccm/l10n/jaxb/LocalizedStringValue.java new file mode 100644 index 000000000..260a45dd6 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/l10n/jaxb/LocalizedStringValue.java @@ -0,0 +1,112 @@ +/* + * 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.l10n.jaxb; + +import static org.libreccm.l10n.L10NConstants.*; + +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.XmlAttribute; +import javax.xml.bind.annotation.XmlValue; + +/** + * + * @author Jens Pelzetter + */ +@XmlAccessorType(XmlAccessType.FIELD) +public class LocalizedStringValue implements Serializable { + + private static final long serialVersionUID = 8435485565736441379L; + + @XmlAttribute(name = "lang", namespace = L10N_XML_NS) + private String locale; + + @XmlValue + private String value; + + public String getLocale() { + return locale; + } + + public void setLocale(final String locale) { + this.locale = locale; + } + + public String getValue() { + return value; + } + + public void setValue(final String value) { + this.value = value; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 97 * hash + Objects.hashCode(locale); + hash = 97 * hash + Objects.hashCode(value); + return hash; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof LocalizedStringValue)) { + return false; + } + final LocalizedStringValue other = (LocalizedStringValue) obj; + if (!other.canEqual(this)) { + return false; + } + if (!Objects.equals(locale, other.getLocale())) { + return false; + } + return Objects.equals(value, other.getValue()); + } + + public boolean canEqual(final Object obj) { + return obj instanceof LocalizedStringValue; + } + + @Override + public final String toString() { + return toString(""); + } + + public String toString(final String data) { + + return String.format("%s{ " + + "locale = %s, " + + "value = \"%s\"%s" + + " }", + super.toString(), + Objects.toString(locale), + value, + data); + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/l10n/jaxb/LocalizedStringValues.java b/ccm-core/src/main/java/org/libreccm/l10n/jaxb/LocalizedStringValues.java new file mode 100644 index 000000000..ee74ccc20 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/l10n/jaxb/LocalizedStringValues.java @@ -0,0 +1,98 @@ +/* + * 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.l10n.jaxb; + +import static org.libreccm.l10n.L10NConstants.*; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; + +/** + * + * @author Jens Pelzetter + */ +@XmlAccessorType(XmlAccessType.FIELD) +public class LocalizedStringValues implements Serializable { + + private static final long serialVersionUID = 1L; + + @JacksonXmlElementWrapper(useWrapping = false) + @XmlElement(name = "value", namespace = L10N_XML_NS) + private List values; + + public List getValues() { + return new ArrayList<>(values); + } + + public void setValues(final List values) { + this.values = new ArrayList<>(values); + } + + @Override + public int hashCode() { + int hash = 3; + hash = 41 * hash + Objects.hashCode(values); + return hash; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof LocalizedStringValues)) { + return false; + } + final LocalizedStringValues other = (LocalizedStringValues) obj; + if (!other.canEqual(this)) { + return false; + } + return Objects.equals(values, other.getValues()); + } + + public boolean canEqual(final Object obj) { + return obj instanceof LocalizedStringValues; + } + + @Override + public final String toString() { + return toString(""); + } + + public String toString(final String data) { + return String.format("%s{ " + + "values = %s%s" + + " }", + super.toString(), + Objects.toString(values), + data); + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/l10n/jaxb/LocalizedStringValuesAdapter.java b/ccm-core/src/main/java/org/libreccm/l10n/jaxb/LocalizedStringValuesAdapter.java new file mode 100644 index 000000000..bb472b1af --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/l10n/jaxb/LocalizedStringValuesAdapter.java @@ -0,0 +1,77 @@ +/* + * 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.l10n.jaxb; + +import org.libreccm.l10n.LocalizedString; + +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.stream.Collectors; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +/** + * JAXB adapter for {@link LocalizedString#values} to produce a more compact XML + * for the values map. + * + * @author Jens Pelzetter + */ +public class LocalizedStringValuesAdapter + extends XmlAdapter> { + + @Override + public Map unmarshal(final LocalizedStringValues values) + throws Exception { + + return values + .getValues() + .stream() + .collect(Collectors.toMap(value -> new Locale(value.getLocale()), + value -> value.getValue())); + + } + + @Override + public LocalizedStringValues marshal(final Map values) + throws Exception { + + final List list = values + .entrySet() + .stream() + .map(this::generateValue) + .collect(Collectors.toList()); + + final LocalizedStringValues result = new LocalizedStringValues(); + result.setValues(list); + + return result; + } + + private LocalizedStringValue generateValue( + final Map.Entry entry) { + + final LocalizedStringValue value = new LocalizedStringValue(); + value.setLocale(entry.getKey().toString()); + value.setValue(entry.getValue()); + + return value; + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/theming/ProcessesThemes.java b/ccm-core/src/main/java/org/libreccm/theming/ProcessesThemes.java new file mode 100644 index 000000000..8e071a4e6 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/theming/ProcessesThemes.java @@ -0,0 +1,50 @@ +/* + * 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; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * Qualifier annotation for implementations of {@link ThemeProcessor} defining + * which type of theme the implementation processes. + * + * @author Jens Pelzetter + */ +@Qualifier +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD, + ElementType.METHOD, + ElementType.PARAMETER, + ElementType.TYPE}) +public @interface ProcessesThemes { + + /** + * The type of theme which is processed by the annotated implementation of + * {@link ThemeProcessor}. + * + * @return Type of theme which is processed. + */ + String value(); + +} diff --git a/ccm-core/src/main/java/org/libreccm/theming/ThemeConstants.java b/ccm-core/src/main/java/org/libreccm/theming/ThemeConstants.java new file mode 100644 index 000000000..f027318db --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/theming/ThemeConstants.java @@ -0,0 +1,32 @@ +/* + * 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; + +/** + * + * @author Jens Pelzetter + */ +public final class ThemeConstants { + + private ThemeConstants() { + //Nothing + } + + public final static String THEMES_XML_NS = "http://themes.libreccm.org"; +} diff --git a/ccm-core/src/main/java/org/libreccm/theming/ThemeInfo.java b/ccm-core/src/main/java/org/libreccm/theming/ThemeInfo.java index d1d99f8e2..9ca338fd7 100644 --- a/ccm-core/src/main/java/org/libreccm/theming/ThemeInfo.java +++ b/ccm-core/src/main/java/org/libreccm/theming/ThemeInfo.java @@ -18,6 +18,8 @@ */ package org.libreccm.theming; +import org.libreccm.theming.manifest.ThemeManifest; + import java.util.Objects; /** @@ -26,22 +28,35 @@ import java.util.Objects; */ public class ThemeInfo { - private String name; + private ThemeManifest manifest; +// private String name; private ThemeVersion version; - private String type; - +// private String type; private Class provider; + public ThemeManifest getManifest() { + return manifest; + } + + public void setManifest(final ThemeManifest manifest) { + this.manifest = manifest; + } + + /** + * Convenient getter for name of theme. + * + * @return {@link ThemeManifest#getName()} + */ public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; +// return name; + return manifest.getName(); } +// public void setName(final String name) { +// this.name = name; +// } public ThemeVersion getVersion() { return version; } @@ -50,14 +65,19 @@ public class ThemeInfo { this.version = version; } + /** + * Convenient getter for type of theme. + * + * @return {@link ThemeManifest#getType()} + */ public String getType() { - return type; - } - - public void setType(final String type) { - this.type = type; +// return type; + return manifest.getType(); } +// public void setType(final String type) { +// this.type = type; +// } public Class getProvider() { return provider; } @@ -69,14 +89,18 @@ public class ThemeInfo { @Override public int hashCode() { int hash = 5; - hash = 73 * hash + Objects.hashCode(name); + hash = 73 * hash + Objects.hashCode(manifest); +// hash = 73 * hash + Objects.hashCode(name); hash = 73 * hash + Objects.hashCode(version); - hash = 73 * hash + Objects.hashCode(type); +// hash = 73 * hash + Objects.hashCode(type); + if (provider != null) { + hash = 73 * hash + Objects.hashCode(provider.getName()); + } return hash; } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (this == obj) { return true; } @@ -90,12 +114,25 @@ public class ThemeInfo { if (!other.canEqual(this)) { return false; } - if (!Objects.equals(name, other.getName())) { + if (!Objects.equals(manifest, other.getManifest())) { return false; } - if (!Objects.equals(type, other.getType())) { + if (provider != null && other.getProvider() == null) { return false; + } else if (provider == null && other.getProvider() != null) { + return false; + } else { + if (!Objects.equals(provider.getName(), + other.getProvider().getName())) { + return false; + } } +// if (!Objects.equals(name, other.getName())) { +// return false; +// } +// if (!Objects.equals(type, other.getType())) { +// return false; +// } return version == other.getVersion(); } @@ -109,15 +146,27 @@ public class ThemeInfo { } public String toString(final String data) { + + final String providerClassName; + if (provider == null) { + providerClassName = ""; + } else { + providerClassName = provider.getName(); + } + return String.format("%s{ " - + "name = \"%s\", " + + "mainfest = %s, " + // + "name = \"%s\", " + "version = %s, " - + "type = \"%s\"%s" - + " }", + + "provider = %s, " + // + "type = \"%s\"%s" + + "%s }", super.toString(), - name, + Objects.toString(manifest), + // name, Objects.toString(version), - type, + providerClassName, + // type, data); } diff --git a/ccm-core/src/main/java/org/libreccm/theming/ThemeProcessors.java b/ccm-core/src/main/java/org/libreccm/theming/ThemeProcessors.java new file mode 100644 index 000000000..d31c04781 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/theming/ThemeProcessors.java @@ -0,0 +1,80 @@ +/* + * 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; + +import org.libreccm.core.UnexpectedErrorException; + +import java.io.Serializable; +import java.util.Optional; + +import javax.enterprise.context.RequestScoped; +import javax.enterprise.inject.Instance; +import javax.enterprise.util.AnnotationLiteral; +import javax.inject.Inject; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +public class ThemeProcessors implements Serializable { + + private static final long serialVersionUID = -2019759931022734946L; + + @Inject + private Instance processors; + + public Optional findThemeProcessorForType(final String type) { + + final ProcessesThemeLiteral literal = new ProcessesThemeLiteral(type); + + final Instance instance = processors + .select(literal); + + if (instance.isUnsatisfied()) { + return Optional.empty(); + } else if (instance.isAmbiguous()) { + throw new UnexpectedErrorException(String + .format("Multiple implementations of ThemeProcessor found for" + + " type \"%s\".", type)); + } else { + return Optional.of(instance.get()); + } + } + + private static class ProcessesThemeLiteral + extends AnnotationLiteral + implements ProcessesThemes { + + private static final long serialVersionUID = -7367770572916053117L; + + private final String value; + + public ProcessesThemeLiteral(final String value) { + this.value = value; + } + + @Override + public String value() { + return value; + } + + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/theming/Themes.java b/ccm-core/src/main/java/org/libreccm/theming/Themes.java index 648a55a17..7850ff50c 100644 --- a/ccm-core/src/main/java/org/libreccm/theming/Themes.java +++ b/ccm-core/src/main/java/org/libreccm/theming/Themes.java @@ -67,7 +67,8 @@ public class Themes { return themes; } - public Optional getTheme(final String name, final ThemeVersion version) { + public Optional getTheme(final String name, + final ThemeVersion version) { for(final ThemeProvider provider : providers) { if (provider.providesTheme(name, version)) { diff --git a/ccm-core/src/main/java/org/libreccm/theming/manifest/ThemeManifest.java b/ccm-core/src/main/java/org/libreccm/theming/manifest/ThemeManifest.java new file mode 100644 index 000000000..ca44830d3 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/theming/manifest/ThemeManifest.java @@ -0,0 +1,178 @@ +/* + * 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.util.ArrayList; +import java.util.Collections; +import java.util.List; +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.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; + +import static org.libreccm.theming.ThemeConstants.*; + +/** + * + * @author Jens Pelzetter + */ +@XmlRootElement(name = "theme", namespace = THEMES_XML_NS) +@XmlAccessorType(XmlAccessType.FIELD) +public class ThemeManifest { + + @XmlElement(name = "name", namespace = THEMES_XML_NS) + private String name; + + @XmlElement(name = "type", namespace = THEMES_XML_NS) + private String type; + + @XmlElement(name = "title", namespace = THEMES_XML_NS) + private LocalizedString title; + + @XmlElement(name = "description", namespace = THEMES_XML_NS) + private LocalizedString description; + + @XmlElementWrapper(name = "templates", namespace = THEMES_XML_NS) + @XmlElement(name = "template", namespace = THEMES_XML_NS) + private List templates; + + public ThemeManifest() { + templates = new ArrayList<>(); + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(final String type) { + this.type =type; + } + 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 List getTemplates() { + return Collections.unmodifiableList(templates); + } + + public void setTemplates(final List templates) { + this.templates = new ArrayList<>(templates); + } + + public void addThemeTemplate(final ThemeTemplate template) { + templates.add(template); + } + + public void removeThemeTemplate(final ThemeTemplate template) { + templates.remove(template); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 83 * hash + Objects.hashCode(name); + hash = 83 * hash + Objects.hashCode(type); + hash = 83 * hash + Objects.hashCode(title); + hash = 83 * hash + Objects.hashCode(description); + hash = 83 * hash + Objects.hashCode(templates); + return hash; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof ThemeManifest)) { + return false; + } + final ThemeManifest other = (ThemeManifest) obj; + if (!other.canEqual(this)) { + return false; + } + if (!Objects.equals(name, other.getName())) { + return false; + } + if (!Objects.equals(type, other.getType())) { + return false; + } + if (!Objects.equals(title, other.getTitle())) { + return false; + } + if (!Objects.equals(description, other.getDescription())) { + return false; + } + return Objects.equals(templates, other.getTemplates()); + } + + public boolean canEqual(final Object obj) { + return obj instanceof ThemeManifest; + } + + @Override + public String toString() { + return toString(""); + } + + public String toString(final String data) { + + return String.format("%s{ " + + "name = \"%s\", " + + "title = \"%s\", " + + "description = \"%s\", " + + "templates = %s%s" + + " }", + super.toString(), + name, + Objects.toString(title), + Objects.toString(description), + Objects.toString(templates), + data); + + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/theming/manifest/ThemeTemplate.java b/ccm-core/src/main/java/org/libreccm/theming/manifest/ThemeTemplate.java new file mode 100644 index 000000000..3deb7be58 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/theming/manifest/ThemeTemplate.java @@ -0,0 +1,147 @@ +/* + * 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; + +/** + * + * @author Jens Pelzetter + */ +@XmlRootElement(name = "template", namespace = "http://themes.libreccm.org") +@XmlAccessorType(XmlAccessType.FIELD) +public class ThemeTemplate implements Serializable { + + private static final long serialVersionUID = -9034588759798295569L; + + @XmlElement(name = "name", namespace = "http://themes.libreccm.org") + private String name; + + @XmlElement(name = "title", namespace = "http://themes.libreccm.org") + private LocalizedString title; + + @XmlElement(name = "description", namespace = "http://themes.libreccm.org") + private LocalizedString description; + + @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); + } + +}