1 19 20 package com.sslexplorer.core.stringreplacement; 21 22 import java.util.regex.Matcher ; 23 import java.util.regex.Pattern ; 24 25 import com.sslexplorer.boot.ContextHolder; 26 import com.sslexplorer.boot.ContextKey; 27 import com.sslexplorer.boot.KeyStoreManager; 28 import com.sslexplorer.properties.Property; 29 30 public class GlobalReplacer extends AbstractReplacementVariableReplacer { 31 32 @Override 33 public String processReplacementVariable(Pattern pattern, Matcher matcher, String replacementPattern, String type, String key) throws Exception { 34 if (type.equalsIgnoreCase(KeyStoreManager.DEFAULT_KEY_STORE)) { 35 if (key.equals("untrustedCertificate")) { 36 return String.valueOf(!KeyStoreManager.getInstance(KeyStoreManager.DEFAULT_KEY_STORE) 37 .isCertificateTrusted(Property.getProperty(new ContextKey("webServer.alias")))); 38 } else { 39 throw new Exception ("Unknown key " + key + " for type " + type + "."); 40 } 41 } else if (type.equalsIgnoreCase("server")) { 42 if (key.equals("untrustedCertificate")) { 45 return String.valueOf(!KeyStoreManager.getInstance(KeyStoreManager.DEFAULT_KEY_STORE) 46 .isCertificateTrusted(Property.getProperty(new ContextKey("webServer.alias")))); 47 } else { 48 throw new Exception ("Unknown key " + key + " for type " + type + "."); 49 } 50 } else if (type.equalsIgnoreCase("context")) { 51 if (key.equals("conf.dir")) { 52 return ContextHolder.getContext().getConfDirectory().getAbsolutePath(); 53 } else if (key.equals("log.dir")) { 54 return ContextHolder.getContext().getLogDirectory().getAbsolutePath(); 55 } else if (key.equals("db.dir")) { 56 return ContextHolder.getContext().getDBDirectory().getAbsolutePath(); 57 } else if (key.equals("temp.dir")) { 58 return ContextHolder.getContext().getTempDirectory().getAbsolutePath(); 59 } else if (key.equals("version")) { 60 return ContextHolder.getContext().getVersion().toString(); 61 } else { 62 throw new Exception ("Unknown key " + key + " for type " + type + "."); 63 } 64 } 65 return null; 66 } 67 } | Popular Tags |