01: // @@
02: // @@
03: /*
04: * Wi.Ser Framework
05: *
06: * Version: 1.8.1, 20-September-2007
07: * Copyright (C) 2005 Dirk von der Weiden <dvdw@imail.de>
08: *
09: * This library is free software; you can redistribute it and/or
10: * modify it under the terms of the GNU Lesser General Public
11: * License as published by the Free Software Foundation; either
12: * version 2 of the License, or (at your option) any later version.
13: *
14: * This library is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17: * Lesser General Public License for more details.
18: *
19: * You should have received a copy of the GNU Lesser General Public
20: * License along with this library located in LGPL.txt in the
21: * license directory; if not, write to the
22: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23: * Boston, MA 02111-1307, USA.
24: *
25: * If this agreement does not cover your requirements, please contact us
26: * via email to get detailed information about the commercial license
27: * or our service offerings!
28: *
29: */
30: // @@
31: package de.ug2t.channel.markup.generic;
32:
33: import java.util.*;
34: import java.util.regex.*;
35:
36: import de.ug2t.kernel.*;
37:
38: public final class MuGenericTemplateKitSelector {
39: public static final String TPLSEL_REGEXP_MARKER = "[RegExp]:";
40:
41: private HashMap pem_map = new LinkedHashMap();
42: private MuGenericTemplateKit pem_defKit = null;
43:
44: public MuGenericTemplateKitSelector(MuGenericTemplateKit xDef) {
45: this .pem_defKit = xDef;
46: }
47:
48: public synchronized void pcmf_addTplKit(String xMap,
49: MuGenericTemplateKit xKit) {
50: this .pem_map.put(xMap, xKit);
51: }
52:
53: public synchronized MuGenericTemplateKit pcmf_getKit(
54: String xUserAgent) {
55: return (this .pcmf_getKit(xUserAgent, true));
56: }
57:
58: public synchronized MuGenericTemplateKit pcmf_getKit(
59: String xUserAgent, boolean xUseDef) {
60: Iterator l_it = this .pem_map.keySet().iterator();
61: String l_key = null;
62: while (l_it.hasNext()) {
63: l_key = (String) l_it.next();
64:
65: if (l_key.startsWith(TPLSEL_REGEXP_MARKER)) {
66: String l_regexp = KeTools.pcmf_stringSingleSubst(l_key,
67: TPLSEL_REGEXP_MARKER, "");
68: if (Pattern.matches(l_regexp, xUserAgent)) {
69: KeLog.pcmf_log("ug2t",
70: "assign special template-kit found for user-agent: "
71: + xUserAgent + " matches: "
72: + l_regexp, this , KeLog.MESSAGE);
73: return ((MuGenericTemplateKit) this .pem_map
74: .get(l_key));
75: }
76: ;
77: } else if (xUserAgent.indexOf(l_key) >= 0) {
78: KeLog.pcmf_log("ug2t",
79: "assign special template-kit found for user-agent: "
80: + xUserAgent, this , KeLog.MESSAGE);
81: return ((MuGenericTemplateKit) this .pem_map.get(l_key));
82: }
83: ;
84: }
85: KeLog.pcmf_log("ug2t",
86: "assign default template-kit, no special kit found for user-agent: "
87: + xUserAgent + " contains " + l_key, this,
88: KeLog.MESSAGE);
89:
90: if (xUseDef)
91: return (this.pem_defKit);
92: else
93: return (null);
94: };
95: }
|