RequiredAttributes.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */

  20. package org.openspcoop2.pdd.core.token.attribute_authority;

  21. import java.util.List;

  22. /**    
  23.  * RequiredAttributes
  24.  *
  25.  * @author Poli Andrea (poli@link.it)
  26.  * @author $Author$
  27.  * @version $Rev$, $Date$
  28.  */
  29. public class RequiredAttributes {

  30.     private List<String> attributes;
  31.    
  32.     public RequiredAttributes(List<String> attributes) {
  33.         this.attributes = attributes;
  34.     }
  35.    
  36.     public List<String> getList() {
  37.         return this.attributes;
  38.     }
  39.    
  40.     public String getJsonList() {
  41.         return jsonList();
  42.     }
  43.     public String jsonList() {
  44.         return this.formatList("\"", "\"", ",", "");
  45.     }
  46.     // WRAPPER per invocare con jsonList()
  47.     public String getJsonList(String unused) {
  48.         return jsonList();
  49.     }
  50.     public String jsonList(String unused) {
  51.         return jsonList();
  52.     }
  53.    
  54.     public String getFormatList(String separator) {
  55.         return this.formatList(separator);
  56.     }
  57.     public String formatList(String separator) {
  58.         return this.formatList("", "", separator, "");
  59.     }

  60.     public String getFormatList(String prefix, String suffix) {
  61.         return this.formatList(prefix, suffix);
  62.     }
  63.     public String formatList(String prefix, String suffix) {
  64.         return this.formatList(prefix, suffix, ",", "");
  65.     }
  66.    
  67.     public String getFormatList(String prefix, String suffix, String separator) {
  68.         return this.formatList(prefix, suffix, separator);
  69.     }
  70.     public String formatList(String prefix, String suffix, String separator) {
  71.         return this.formatList(prefix, suffix, separator, "");
  72.     }
  73.    
  74.     public String getFormatList(String prefix, String suffix, String separator, String emptyResultReturn) {
  75.         return this.formatList(prefix, suffix, separator, emptyResultReturn);
  76.     }
  77.     public String formatList(String prefix, String suffix, String separator, String emptyResultReturn) {
  78.         if(this.attributes==null || this.attributes.isEmpty()) {
  79.             return emptyResultReturn;
  80.         }
  81.         StringBuilder sb = new StringBuilder();
  82.         for (String attr : this.attributes) {
  83.             if(sb.length()>0) {
  84.                 sb.append(separator);
  85.             }
  86.             sb.append(prefix);
  87.             sb.append(attr);
  88.             sb.append(suffix);
  89.         }
  90.         return sb.toString();
  91.     }
  92.    
  93.     public String getAtPosition(int index) {
  94.         return atPosition(index);
  95.     }
  96.     public String atPosition(int index) {
  97.         return this.attributes.get(index);
  98.     }
  99.     // wrapper
  100.     public String getAtPosition(String index) {
  101.         return atPosition(Integer.valueOf(index));
  102.     }
  103.     public String atPosition(String index) {
  104.         return atPosition(Integer.valueOf(index));
  105.     }
  106. }