CCM NG: Renders for some assets

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@6157 8810af33-2d31-482b-a856-94f89814c4df
jensp 2019-07-30 13:07:34 +00:00
parent d38679237d
commit d2bdaca455
4 changed files with 284 additions and 0 deletions

View File

@ -0,0 +1,89 @@
/*
* Copyright (C) 2019 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.librecms.pagemodel.assets;
import org.librecms.assets.ContactEntry;
import org.librecms.assets.ContactableEntity;
import org.librecms.assets.Organization;
import org.librecms.assets.PostalAddress;
import org.librecms.contentsection.Asset;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
public class ContactableEntityRenderer extends AbstractAssetRenderer {
@Inject
private AssetRenderers assetRenderers;
@Override
protected void renderAsset(final Asset asset,
final Locale language,
final Map<String, Object> result) {
final ContactableEntity contactable;
if (asset instanceof ContactableEntity) {
contactable = (ContactableEntity) asset;
} else {
return;
}
final Map<String, String> contactEntries = buildContactEntries(
contactable);
result.put("contactEntries", contactEntries);
if (contactable.getPostalAddress() != null) {
final AbstractAssetRenderer postalAddressRenderer = assetRenderers
.findRenderer(PostalAddress.class);
final PostalAddress postalAddress = contactable.getPostalAddress();
result.put("postalAddress",
postalAddressRenderer.render(postalAddress, language));
}
}
private Map<String, String> buildContactEntries(
final ContactableEntity contactable) {
return contactable
.getContactEntries()
.stream()
.map(this::buildContactEntry)
.collect(Collectors.toMap(entry -> entry[0], entry -> entry[1]));
}
private String[] buildContactEntry(final ContactEntry entry) {
final String key = entry.getKey().getEntryKey();
final String value = entry.getValue();
return new String[]{key, value};
}
}

View File

@ -0,0 +1,54 @@
/*
* Copyright (C) 2019 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.librecms.pagemodel.assets;
import org.librecms.assets.Organization;
import org.librecms.contentsection.Asset;
import java.util.Locale;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@AssetRenderer(renders = Organization.class)
public class OrganizationRenderer extends ContactableEntityRenderer {
@Override
protected void renderAsset(final Asset asset,
final Locale language,
final Map<String, Object> result) {
super.renderAsset(asset, language, result);
final Organization organization;
if (asset instanceof Organization) {
organization = (Organization) asset;
} else {
return;
}
result.put("organizationName", organization.getName());
}
}

View File

@ -0,0 +1,85 @@
/*
* Copyright (C) 2019 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.librecms.pagemodel.assets;
import org.librecms.assets.Person;
import org.librecms.assets.PersonName;
import org.librecms.contentsection.Asset;
import java.util.Locale;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@AssetRenderer(renders = Person.class)
public class PersonRenderer extends ContactableEntityRenderer {
@Override
protected void renderAsset(final Asset asset,
final Locale language,
final Map<String, Object> result) {
super.renderAsset(asset, language, result);
final Person person;
if (asset instanceof Person) {
person = (Person) asset;
} else {
return;
}
final PersonName personName = person.getPersonName();
if (personName != null) {
if (personName.getSurname() != null
&& !personName.getSurname().isEmpty()) {
result.put("surname", personName.getSurname());
}
if (personName.getGivenName() != null
&& !personName.getGivenName().isEmpty()) {
result.put("givenName", personName.getGivenName());
}
if (personName.getPrefix() != null
&& !personName.getPrefix().isEmpty()) {
result.put("prefix", personName.getPrefix());
}
if (personName.getSuffix() != null
&& !personName.getSuffix().isEmpty()) {
result.put("suffix", personName.getSuffix());
}
}
if (person.getBirthdate() != null) {
result.put("birthdate", person.getBirthdate());
}
}
}

View File

@ -0,0 +1,56 @@
/*
* Copyright (C) 2019 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.librecms.pagemodel.assets;
import org.librecms.assets.PostalAddress;
import org.librecms.contentsection.Asset;
import java.util.Locale;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@AssetRenderer(renders = PostalAddress.class)
public class PostalAddressRenderer extends AbstractAssetRenderer {
@Override
protected void renderAsset(final Asset asset,
final Locale language,
final Map<String, Object> result) {
final PostalAddress postalAddress;
if (asset instanceof PostalAddress) {
postalAddress = (PostalAddress) asset;
} else {
return;
}
result.put("address", postalAddress.getAddress());
result.put("city", postalAddress.getCity());
result.put("isoCountryCode", postalAddress.getIsoCountryCode());
result.put("postalCode", postalAddress.getPostalCode());
result.put("state", postalAddress.getState());
}
}