KickJava   Java API By Example, From Geeks To Geeks.

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


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.Map JavaDoc;
23 import java.util.regex.Matcher JavaDoc;
24 import java.util.regex.Pattern JavaDoc;
25
26 import com.sslexplorer.extensions.ExtensionDescriptor;
27
28 public class ExtensionDescriptorReplacer extends AbstractReplacementVariableReplacer {
29     
30     private ExtensionDescriptor extensionDescriptor;
31     private Map JavaDoc parameters;
32     
33     public ExtensionDescriptorReplacer(ExtensionDescriptor extensionDescriptor, Map JavaDoc parameters) {
34         super();
35         this.extensionDescriptor = extensionDescriptor;
36         this.parameters = parameters;
37     }
38
39     @Override JavaDoc
40     public String JavaDoc processReplacementVariable(Pattern JavaDoc pattern, Matcher JavaDoc matcher, String JavaDoc replacementPattern, String JavaDoc type, String JavaDoc key) throws Exception JavaDoc {
41         if (type.equalsIgnoreCase("shortcut")) {
42             if (parameters == null) {
43                 return null;
44             }
45             String JavaDoc val = (String JavaDoc) parameters.get(key);
46             if (val == null) {
47                 throw new Exception JavaDoc("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 JavaDoc("Unknown key " + key + " for type " + type + ".");
64             }
65         }
66         return null;
67     }
68     
69 }
Popular Tags