EncryptionC14NAlgorithm.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.security.message.constants;

  21. import org.openspcoop2.generic_project.exception.NotFoundException;

  22. /**    
  23.  * EncryptionC14NAlgorithm
  24.  *
  25.  * @author Poli Andrea (poli@link.it)
  26.  * @author $Author$
  27.  * @version $Rev$, $Date$
  28.  */
  29. public enum EncryptionC14NAlgorithm {
  30.    
  31.     INCLUSIVE_C14N_10_OMITS_COMMENTS("http://www.w3.org/TR/2001/REC-xml-c14n-20010315","Inclusive XML Canonicalization 1.0 (omits comments)"),
  32.     INCLUSIVE_C14N_10_WITH_COMMENTS("http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments","Inclusive XML Canonicalization 1.0 (with comments)"),
  33.     INCLUSIVE_C14N_11_OMITS_COMMENTS("http://www.w3.org/2006/12/xml-c14n11","Inclusive XML Canonicalization 1.1 (omits comments)"),
  34.     INCLUSIVE_C14N_11_WITH_COMMENTS("http://www.w3.org/2006/12/xml-c14n11#WithComments","Inclusive XML Canonicalization 1.1 (with comments)"),
  35.     EXCLUSIVE_C14N_10_OMITS_COMMENTS("http://www.w3.org/2001/10/xml-exc-c14n#","Exclusive XML Canonicalization 1.0 (omits comments)"),
  36.     EXCLUSIVE_C14N_10_WITH_COMMENTS("http://www.w3.org/2001/10/xml-exc-c14n#WithComments","Exclusive XML Canonicalization 1.0 (with comments)");
  37.    
  38.     private String uri;
  39.     private String label;
  40.     EncryptionC14NAlgorithm(String uri,String label) {
  41.         this.uri = uri;
  42.         this.label = label;
  43.     }
  44.    
  45.     public String getUri() {
  46.         return this.uri;
  47.     }
  48.     public String getLabel() {
  49.         return this.label;
  50.     }
  51.    
  52.     public static EncryptionC14NAlgorithm toEnumConstant(String uri){
  53.         try{
  54.             return toEnumConstant(uri,false);
  55.         }catch(NotFoundException notFound){
  56.             return null;
  57.         }
  58.     }
  59.     public static EncryptionC14NAlgorithm toEnumConstant(String uri, boolean throwNotFoundException) throws NotFoundException{
  60.         EncryptionC14NAlgorithm res = null;
  61.         for (EncryptionC14NAlgorithm tmp : values()) {
  62.             if(tmp.getUri().equals(uri)){
  63.                 res = tmp;
  64.                 break;
  65.             }
  66.         }
  67.         if(res==null && throwNotFoundException){
  68.             throw new NotFoundException("Enum with uri ["+uri+"] not found");
  69.         }
  70.         return res;
  71.     }
  72. }