001/* 002 * Copyright 2021 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.workspaces.project.notification; 017 018import java.util.ArrayList; 019import java.util.Arrays; 020import java.util.List; 021 022import org.apache.commons.lang3.StringUtils; 023 024/** 025 * Helper providing some method to facilitate the creation of HTML mail template 026 */ 027public final class NotificationXSLTHelper 028{ 029 private NotificationXSLTHelper() 030 { 031 // nothing here 032 } 033 /** 034 * Concatenate two string value of style attribute. 035 * If a value is present in the two string, the value in the second string will be ignored. 036 * 037 * @param newStyles a string of style attribute value 038 * @param defaultStyles a string of style attribute to override if necessary 039 * @return the concatenation of the two string without double entries 040 */ 041 public static String concatStyle(String newStyles, String defaultStyles) 042 { 043 List<String> newStylesArr = new ArrayList<>(Arrays.asList(StringUtils.split(newStyles, ';'))); 044 List<String> defaultStylesArr = new ArrayList<>(Arrays.asList(StringUtils.split(defaultStyles, ';'))); 045 for (String defaultStyle: defaultStylesArr) 046 { 047 boolean overriden = false; 048 String name = StringUtils.substringBefore(defaultStyle, ':').trim().toLowerCase(); 049 for (String newStyle : newStylesArr) 050 { 051 if (name.equals(StringUtils.substringBefore(newStyle, ':').trim().toLowerCase())) 052 { 053 overriden = true; 054 break; 055 } 056 } 057 if (!overriden) 058 { 059 newStylesArr.add(defaultStyle); 060 } 061 } 062 return StringUtils.join(newStylesArr, ';'); 063 } 064}