CCM NG: Themes system part 1
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5076 8810af33-2d31-482b-a856-94f89814c4df
parent
1905aaefea
commit
dfdddb11c2
|
|
@ -23,13 +23,13 @@ import org.hibernate.annotations.Type;
|
||||||
import org.hibernate.search.annotations.Field;
|
import org.hibernate.search.annotations.Field;
|
||||||
|
|
||||||
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 java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import static org.libreccm.l10n.L10NConstants.L10N_XML_NS;
|
import static org.libreccm.l10n.L10NConstants.L10N_XML_NS;
|
||||||
|
|
||||||
|
import org.libreccm.l10n.jaxb.LocalizedStringValuesAdapter;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
@ -44,6 +44,9 @@ import javax.persistence.Embeddable;
|
||||||
import javax.persistence.FetchType;
|
import javax.persistence.FetchType;
|
||||||
import javax.persistence.Lob;
|
import javax.persistence.Lob;
|
||||||
import javax.persistence.MapKeyColumn;
|
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
|
* A helper class for localisable string properties. This class is declared as
|
||||||
|
|
@ -54,7 +57,8 @@ import javax.persistence.MapKeyColumn;
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@Embeddable
|
@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 {
|
public class LocalizedString implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 7378282657084330425L;
|
private static final long serialVersionUID = 7378282657084330425L;
|
||||||
|
|
@ -69,8 +73,9 @@ public class LocalizedString implements Serializable {
|
||||||
@Lob
|
@Lob
|
||||||
@Type(type = "org.hibernate.type.TextType")
|
@Type(type = "org.hibernate.type.TextType")
|
||||||
@Field
|
@Field
|
||||||
@XmlElementWrapper(name = "values", namespace = L10N_XML_NS)
|
// @XmlElementWrapper(name = "values", namespace = L10N_XML_NS)
|
||||||
@XmlElement(name = "values", namespace = L10N_XML_NS)
|
@XmlElement(name = "values", namespace = L10N_XML_NS)
|
||||||
|
@XmlJavaTypeAdapter(LocalizedStringValuesAdapter.class)
|
||||||
private Map<Locale, String> values;
|
private Map<Locale, String> values;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -101,7 +106,7 @@ public class LocalizedString implements Serializable {
|
||||||
* @param values The new map of values.
|
* @param values The new map of values.
|
||||||
*/
|
*/
|
||||||
protected void setValues(final Map<Locale, String> values) {
|
protected void setValues(final Map<Locale, String> values) {
|
||||||
this.values = values;
|
this.values = new HashMap<>(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@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<LocalizedStringValue> values;
|
||||||
|
|
||||||
|
public List<LocalizedStringValue> getValues() {
|
||||||
|
return new ArrayList<>(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValues(final List<LocalizedStringValue> 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class LocalizedStringValuesAdapter
|
||||||
|
extends XmlAdapter<LocalizedStringValues, Map<Locale, String>> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<Locale, String> 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<Locale, String> values)
|
||||||
|
throws Exception {
|
||||||
|
|
||||||
|
final List<LocalizedStringValue> 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<Locale, String> entry) {
|
||||||
|
|
||||||
|
final LocalizedStringValue value = new LocalizedStringValue();
|
||||||
|
value.setLocale(entry.getKey().toString());
|
||||||
|
value.setValue(entry.getValue());
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@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();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public final class ThemeConstants {
|
||||||
|
|
||||||
|
private ThemeConstants() {
|
||||||
|
//Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
public final static String THEMES_XML_NS = "http://themes.libreccm.org";
|
||||||
|
}
|
||||||
|
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.libreccm.theming;
|
package org.libreccm.theming;
|
||||||
|
|
||||||
|
import org.libreccm.theming.manifest.ThemeManifest;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -26,22 +28,35 @@ import java.util.Objects;
|
||||||
*/
|
*/
|
||||||
public class ThemeInfo {
|
public class ThemeInfo {
|
||||||
|
|
||||||
private String name;
|
private ThemeManifest manifest;
|
||||||
|
|
||||||
|
// private String name;
|
||||||
private ThemeVersion version;
|
private ThemeVersion version;
|
||||||
|
|
||||||
private String type;
|
// private String type;
|
||||||
|
|
||||||
private Class<ThemeProvider> provider;
|
private Class<ThemeProvider> 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() {
|
public String getName() {
|
||||||
return name;
|
// return name;
|
||||||
}
|
return manifest.getName();
|
||||||
|
|
||||||
public void setName(final String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public void setName(final String name) {
|
||||||
|
// this.name = name;
|
||||||
|
// }
|
||||||
public ThemeVersion getVersion() {
|
public ThemeVersion getVersion() {
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
@ -50,14 +65,19 @@ public class ThemeInfo {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenient getter for type of theme.
|
||||||
|
*
|
||||||
|
* @return {@link ThemeManifest#getType()}
|
||||||
|
*/
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type;
|
// return type;
|
||||||
}
|
return manifest.getType();
|
||||||
|
|
||||||
public void setType(final String type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public void setType(final String type) {
|
||||||
|
// this.type = type;
|
||||||
|
// }
|
||||||
public Class<ThemeProvider> getProvider() {
|
public Class<ThemeProvider> getProvider() {
|
||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
@ -69,14 +89,18 @@ public class ThemeInfo {
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hash = 5;
|
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(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;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(final Object obj) {
|
||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -90,12 +114,25 @@ public class ThemeInfo {
|
||||||
if (!other.canEqual(this)) {
|
if (!other.canEqual(this)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Objects.equals(name, other.getName())) {
|
if (!Objects.equals(manifest, other.getManifest())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Objects.equals(type, other.getType())) {
|
if (provider != null && other.getProvider() == null) {
|
||||||
return false;
|
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();
|
return version == other.getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,15 +146,27 @@ public class ThemeInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString(final String data) {
|
public String toString(final String data) {
|
||||||
|
|
||||||
|
final String providerClassName;
|
||||||
|
if (provider == null) {
|
||||||
|
providerClassName = "";
|
||||||
|
} else {
|
||||||
|
providerClassName = provider.getName();
|
||||||
|
}
|
||||||
|
|
||||||
return String.format("%s{ "
|
return String.format("%s{ "
|
||||||
+ "name = \"%s\", "
|
+ "mainfest = %s, "
|
||||||
|
// + "name = \"%s\", "
|
||||||
+ "version = %s, "
|
+ "version = %s, "
|
||||||
+ "type = \"%s\"%s"
|
+ "provider = %s, "
|
||||||
+ " }",
|
// + "type = \"%s\"%s"
|
||||||
|
+ "%s }",
|
||||||
super.toString(),
|
super.toString(),
|
||||||
name,
|
Objects.toString(manifest),
|
||||||
|
// name,
|
||||||
Objects.toString(version),
|
Objects.toString(version),
|
||||||
type,
|
providerClassName,
|
||||||
|
// type,
|
||||||
data);
|
data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
public class ThemeProcessors implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -2019759931022734946L;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Instance<ThemeProcessor> processors;
|
||||||
|
|
||||||
|
public Optional<ThemeProcessor> findThemeProcessorForType(final String type) {
|
||||||
|
|
||||||
|
final ProcessesThemeLiteral literal = new ProcessesThemeLiteral(type);
|
||||||
|
|
||||||
|
final Instance<ThemeProcessor> 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<ProcessesThemes>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -67,7 +67,8 @@ public class Themes {
|
||||||
return themes;
|
return themes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<ThemeInfo> getTheme(final String name, final ThemeVersion version) {
|
public Optional<ThemeInfo> getTheme(final String name,
|
||||||
|
final ThemeVersion version) {
|
||||||
|
|
||||||
for(final ThemeProvider provider : providers) {
|
for(final ThemeProvider provider : providers) {
|
||||||
if (provider.providesTheme(name, version)) {
|
if (provider.providesTheme(name, version)) {
|
||||||
|
|
|
||||||
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@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<ThemeTemplate> 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<ThemeTemplate> getTemplates() {
|
||||||
|
return Collections.unmodifiableList(templates);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTemplates(final List<ThemeTemplate> 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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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 <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;
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue