1 19 20 package com.sslexplorer.core.stringreplacement; 21 22 import java.util.Map ; 23 import java.util.regex.Matcher ; 24 import java.util.regex.Pattern ; 25 26 import com.sslexplorer.extensions.ExtensionDescriptor; 27 28 public class ExtensionDescriptorReplacer extends AbstractReplacementVariableReplacer { 29 30 private ExtensionDescriptor extensionDescriptor; 31 private Map parameters; 32 33 public ExtensionDescriptorReplacer(ExtensionDescriptor extensionDescriptor, Map parameters) { 34 super(); 35 this.extensionDescriptor = extensionDescriptor; 36 this.parameters = parameters; 37 } 38 39 @Override 40 public String processReplacementVariable(Pattern pattern, Matcher matcher, String replacementPattern, String type, String key) throws Exception { 41 if (type.equalsIgnoreCase("shortcut")) { 42 if (parameters == null) { 43 return null; 44 } 45 String val = (String ) parameters.get(key); 46 if (val == null) { 47 throw new Exception ("Unknown key " + key + " for type " + type + "."); 48 } 49 return val; 50 } else if (type.equalsIgnoreCase("application")) { 51 if (extensionDescriptor == null) { 52 return null; 53 } 54 if (key.equals("id")) { 55 return extensionDescriptor.getId(); 56 } else if (key.equals("name")) { 57 return extensionDescriptor.getName(); 58 } else if (key.equals("description")) { 59 return extensionDescriptor.getDescription(); 60 } else if (key.equals("path")) { 61 return "/fs/apps/" + extensionDescriptor.getApplicationBundle().getId(); 62 } else { 63 throw new Exception ("Unknown key " + key + " for type " + type + "."); 64 } 65 } 66 return null; 67 } 68 69 } | Popular Tags |