diff --git a/src/fr/devinsy/statoolinfos/core/Organization.java b/src/fr/devinsy/statoolinfos/core/Organization.java index ac79356..6b04274 100644 --- a/src/fr/devinsy/statoolinfos/core/Organization.java +++ b/src/fr/devinsy/statoolinfos/core/Organization.java @@ -123,6 +123,21 @@ public class Organization extends PathPropertyList return result; } + /** + * Gets the diaspora page. + * + * @return the diaspora page + */ + public String getDiasporaWebpage() + { + String result; + + result = get("organization.socialnetworks.diaspora"); + + // + return result; + } + /** * Gets the end date. * @@ -203,6 +218,21 @@ public class Organization extends PathPropertyList return result; } + /** + * Gets the mastodon page. + * + * @return the mastodon page + */ + public String getMastodonWebpage() + { + String result; + + result = get("organization.socialnetworks.mastodon"); + + // + return result; + } + /** * Gets the name. * @@ -332,6 +362,65 @@ public class Organization extends PathPropertyList return result; } + /** + * Checks for social network. + * + * @return true, if successful + */ + public boolean hasSocialNetwork() + { + boolean result; + + if (StringUtils.isAllBlank(getDiasporaWebpage(), getMastodonWebpage())) + { + result = false; + } + else + { + result = true; + } + + // + return result; + } + + /** + * Checks for social network. + * + * @param value + * the value + * @return true, if successful + */ + public boolean hasSocialNetwork(final SocialNetworks value) + { + boolean result; + + String link; + switch (value) + { + case DIASPORA: + link = getDiasporaWebpage(); + break; + case MASTODON: + link = getMastodonWebpage(); + break; + default: + link = null; + } + + if (StringUtils.isBlank(link)) + { + result = false; + } + else + { + result = true; + } + + // + return result; + } + public void setFederation(final Federation federation) { this.federation = federation; diff --git a/src/fr/devinsy/statoolinfos/core/Organizations.java b/src/fr/devinsy/statoolinfos/core/Organizations.java index 8af871a..ccdcc58 100644 --- a/src/fr/devinsy/statoolinfos/core/Organizations.java +++ b/src/fr/devinsy/statoolinfos/core/Organizations.java @@ -36,6 +36,54 @@ public class Organizations extends ArrayList super(); } + /** + * Filter by social network. + * + * @return the organizations + */ + public Organizations filterBySocialNetworks() + { + Organizations result; + + result = new Organizations(); + + for (Organization organization : this) + { + if (organization.hasSocialNetwork()) + { + result.add(organization); + } + } + + // + return result; + } + + /** + * Filter by social network. + * + * @param value + * the value + * @return the organizations + */ + public Organizations filterBySocialNetwork(final SocialNetworks value) + { + Organizations result; + + result = new Organizations(); + + for (Organization organization : this) + { + if (organization.hasSocialNetwork(value)) + { + result.add(organization); + } + } + + // + return result; + } + /** * Reverse. * diff --git a/src/fr/devinsy/statoolinfos/core/SocialNetworks.java b/src/fr/devinsy/statoolinfos/core/SocialNetworks.java new file mode 100644 index 0000000..2775a1a --- /dev/null +++ b/src/fr/devinsy/statoolinfos/core/SocialNetworks.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2020 Christian Pierre MOMON + * + * This file is part of StatoolInfos, simple service statistics tool. + * + * StatoolInfos is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * StatoolInfos 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with StatoolInfos. If not, see . + */ +package fr.devinsy.statoolinfos.core; + +/** + * The Enum SocialNetworks. + */ +public enum SocialNetworks +{ + DIASPORA, + MASTODON +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java index 313c344..193d1e4 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java +++ b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java @@ -33,8 +33,10 @@ import fr.devinsy.statoolinfos.core.Configuration; import fr.devinsy.statoolinfos.core.Factory; import fr.devinsy.statoolinfos.core.Federation; import fr.devinsy.statoolinfos.core.Organization; +import fr.devinsy.statoolinfos.core.Organizations; import fr.devinsy.statoolinfos.core.Service; import fr.devinsy.statoolinfos.core.Services; +import fr.devinsy.statoolinfos.core.SocialNetworks; import fr.devinsy.statoolinfos.core.Software; import fr.devinsy.statoolinfos.core.Softwares; import fr.devinsy.statoolinfos.core.StatoolInfosException; @@ -129,6 +131,10 @@ public class Htmlizer StatoolInfosUtils.copyRessource(source + "status-over.png", targetDirectory); StatoolInfosUtils.copyRessource(source + "status-void.png", targetDirectory); + // + StatoolInfosUtils.copyRessource(source + "diaspora-logo.png", targetDirectory); + StatoolInfosUtils.copyRessource(source + "mastodon-logo.png", targetDirectory); + // File color = new File(targetDirectory, "circle-icons/color"); color.mkdirs(); @@ -401,6 +407,22 @@ public class Htmlizer FileUtils.write(new File(htmlizeDirectory, "software-" + software.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8); } } + + // + { + logger.info("Htmlize social networks pages."); + Organizations organizations = federation.getOrganizations().filterBySocialNetworks(); + page = SocialNetworksPage.build("Tous", organizations); + FileUtils.write(new File(htmlizeDirectory, "socialNetworks.xhtml"), page, StandardCharsets.UTF_8); + + organizations = federation.getOrganizations().filterBySocialNetwork(SocialNetworks.DIASPORA); + page = SocialNetworksPage.build("Disapora*", organizations); + FileUtils.write(new File(htmlizeDirectory, "socialNetworks-diaspora.xhtml"), page, StandardCharsets.UTF_8); + + organizations = federation.getOrganizations().filterBySocialNetwork(SocialNetworks.MASTODON); + page = SocialNetworksPage.build("Mastodon", organizations); + FileUtils.write(new File(htmlizeDirectory, "socialNetworks-mastodon.xhtml"), page, StandardCharsets.UTF_8); + } } /** diff --git a/src/fr/devinsy/statoolinfos/htmlize/SocialNetworksPage.java b/src/fr/devinsy/statoolinfos/htmlize/SocialNetworksPage.java new file mode 100644 index 0000000..70baa6d --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/SocialNetworksPage.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2020 Christian Pierre MOMON + * + * This file is part of StatoolInfos, simple service statistics tool. + * + * StatoolInfos is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * StatoolInfos 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with StatoolInfos. If not, see . + */ +package fr.devinsy.statoolinfos.htmlize; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.statoolinfos.core.Organization; +import fr.devinsy.statoolinfos.core.Organizations; +import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.data.DisplayMode; +import fr.devinsy.xidyn.data.TagDataManager; +import fr.devinsy.xidyn.presenters.PresenterUtils; + +/** + * The Class SocialNetworks. + */ +public class SocialNetworksPage +{ + private static Logger logger = LoggerFactory.getLogger(SocialNetworksPage.class); + + /** + * Builds the. + * + * @param federation + * the federation + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String build(final String title, final Organizations organizations) throws StatoolInfosException + { + String result; + + try + { + logger.debug("Building social networks page {}…"); + + TagDataManager data = new TagDataManager(); + + data.setEscapedContent("title", title); + data.setContent("organizationCount", organizations.size()); + + int index = 0; + for (Organization organization : organizations) + { + data.setAttribute("organizationListLine", index, "organizationListLineNameLink", "href", organization.getTechnicalName() + ".xhtml"); + data.setAttribute("organizationListLine", index, "organizationListLineLogo", "src", organization.getTechnicalName() + "-logo.png"); + data.setAttribute("organizationListLine", index, "organizationListLineLogo", "alt", organization.getName()); + data.setEscapedContent("organizationListLine", index, "organizationListLineNameValue", organization.getName()); + + data.setEscapedContent("organizationListLine", index, "organizationListLineUrlLink", organization.getWebsite()); + data.setAttribute("organizationListLine", index, "organizationListLineUrlLink", "href", organization.getWebsite()); + + if (StringUtils.isNotBlank(organization.getDiasporaWebpage())) + { + data.setAttribute("organizationListLine", index, "organizationListLineDiasporaImg", "class", ""); + data.getIdData("organizationListLine", index, "organizationListLineDiasporaImg").getAttribute("class").setMode(DisplayMode.REPLACE); + data.setAttribute("organizationListLine", index, "organizationListLineDiasporaLink", "href", organization.getDiasporaWebpage()); + } + + if (StringUtils.isNotBlank(organization.getMastodonWebpage())) + { + data.setAttribute("organizationListLine", index, "organizationListLineMastodonImg", "class", ""); + data.getIdData("organizationListLine", index, "organizationListLineMastodonImg").getAttribute("class").setMode(DisplayMode.REPLACE); + data.setAttribute("organizationListLine", index, "organizationListLineMastodonLink", "href", organization.getMastodonWebpage()); + } + + index += 1; + } + + String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/socialNetworks.xhtml", data).toString(); + + BreadcrumbTrail trail = new BreadcrumbTrail(); + result = WebCharterView.build(content, trail); + } + catch (XidynException exception) + { + throw new StatoolInfosException("Error building social networks page: " + exception.getMessage(), exception); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/socialNetworks.xhtml b/src/fr/devinsy/statoolinfos/htmlize/socialNetworks.xhtml new file mode 100644 index 0000000..23b2539 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/socialNetworks.xhtml @@ -0,0 +1,98 @@ + + + + + StatoolInfos + + + + + + + +
+ + + +
+

n/a

+
Nombre de membres : n/a
+
+ +
+
+
+ Diaspora*
+ Mastodon
+
+
+ + + + + + + + + + + + + + + + +
Nom du membreURLRéseaux sociaux
+ + +  n/a + + n/a
+
+
+ + + diff --git a/src/fr/devinsy/statoolinfos/htmlize/stuff/diaspora-logo.png b/src/fr/devinsy/statoolinfos/htmlize/stuff/diaspora-logo.png new file mode 100644 index 0000000..2192afb Binary files /dev/null and b/src/fr/devinsy/statoolinfos/htmlize/stuff/diaspora-logo.png differ diff --git a/src/fr/devinsy/statoolinfos/htmlize/stuff/mastodon-logo.png b/src/fr/devinsy/statoolinfos/htmlize/stuff/mastodon-logo.png new file mode 100644 index 0000000..87cd7ef Binary files /dev/null and b/src/fr/devinsy/statoolinfos/htmlize/stuff/mastodon-logo.png differ diff --git a/src/fr/devinsy/statoolinfos/htmlize/webCharterView.xhtml b/src/fr/devinsy/statoolinfos/htmlize/webCharterView.xhtml index 242d6c9..9a42f2e 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/webCharterView.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/webCharterView.xhtml @@ -23,6 +23,7 @@ Services Catégories Logiciels + Réseaux sociaux