MapPlaceholder.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.protocol.sdk.archive;

  21. import java.io.Serializable;
  22. import java.util.HashMap;
  23. import java.util.Map;

  24. /**
  25.  * MapPlaceholder
  26.  *
  27.  * @author Andrea Poli (apoli@link.it)
  28.  * @author $Author$
  29.  * @version $Rev$, $Date$
  30.  */
  31. public class MapPlaceholder implements Serializable {

  32.     /**
  33.      *
  34.      */
  35.     private static final long serialVersionUID = 1L;
  36.    
  37.     private Map<String, String> map = new HashMap<>();

  38.     public Map<String, String> getMap() {
  39.         return this.map;
  40.     }
  41.    
  42.     public void put(String key,String value){
  43.         if(this.map.containsKey(key)){
  44.             this.map.remove(key);
  45.         }
  46.         this.map.put(key, value);
  47.     }
  48.    
  49.     public void putAll(MapPlaceholder map){
  50.         for (String key : map.map.keySet()) {
  51.             this.put(key,map.map.get(key));
  52.         }
  53.     }
  54.    
  55.     public int size(){
  56.         return this.map.size();
  57.     }
  58.    
  59.     public byte[] replace(byte[]xml){
  60.         String xmlAsString = new String(xml);
  61.         for (String key : this.map.keySet()) {
  62.            
  63.             while(xmlAsString.contains("@"+key+"@")){
  64.                 xmlAsString = xmlAsString.replace("@"+key+"@", this.map.get(key));
  65.             }
  66.         }
  67.         return xmlAsString.getBytes();
  68.     }
  69. }