KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > core > stringreplacement > GlobalReplacer


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.core.stringreplacement;
21
22 import java.util.regex.Matcher JavaDoc;
23 import java.util.regex.Pattern JavaDoc;
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 JavaDoc
33     public String JavaDoc processReplacementVariable(Pattern JavaDoc pattern, Matcher JavaDoc matcher, String JavaDoc replacementPattern, String JavaDoc type, String JavaDoc key) throws Exception JavaDoc {
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 JavaDoc("Unknown key " + key + " for type " + type + ".");
40             }
41         } else if (type.equalsIgnoreCase("server")) {
42             // NOTE 29/1/06 - BPS - This is here to maintain
43
// compatibility with current extension descriptors
44
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 JavaDoc("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 JavaDoc("Unknown key " + key + " for type " + type + ".");
63             }
64         }
65         return null;
66     }
67 }
Popular Tags