KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > bridge > jsp > taglib > util > Referids


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10
11 package org.mmbase.bridge.jsp.taglib.util;
12
13 import java.util.*;
14
15 import javax.servlet.jsp.JspTagException JavaDoc;
16
17 import org.mmbase.bridge.jsp.taglib.ContextReferrerTag;
18 import org.mmbase.util.logging.*;
19
20 /**
21  * A helper class to implement referids attribute.
22  *
23  * @author Michiel Meeuwissen
24  * @version $Id: Referids.java,v 1.5 2006/01/25 19:38:44 michiel Exp $
25  * @since MMBase-1.7
26  */

27 public abstract class Referids {
28     private static final Logger log = Logging.getLoggerInstance(Referids.class);
29
30     public static Map getReferids(Attribute referids, ContextReferrerTag tag) throws JspTagException JavaDoc {
31         Map result = new LinkedHashMap(); // using a 'linked' hash map ensures that the key/value pairs are added in the same order as there are in the referids attribute
32
// log.info("" + referids + " : " + referids.getList(this));
33
Iterator i = referids.getList(tag).iterator();
34         while (i.hasNext()) {
35             String JavaDoc key = (String JavaDoc) i.next();
36             if (key.equals("")) continue;
37             int at = key.indexOf('@');
38             String JavaDoc urlKey;
39             if (at > -1) {
40                 urlKey = key.substring(at + 1, key.length());
41                 key = key.substring(0, at);
42             } else {
43                 urlKey = key;
44             }
45
46             boolean mayBeMissing;
47             if (key.endsWith("?")) {
48                 mayBeMissing = true;
49                 boolean keyIsUrlKey = key.equals(urlKey);
50                 key = key.substring(0, key.length() - 1);
51                 if (keyIsUrlKey) urlKey = key;
52             } else {
53                 mayBeMissing = false;
54             }
55             if (key.equals("_")) {
56                 if (urlKey.equals("_")) throw new JspTagException JavaDoc("Should use '@' when using '_' in referids");
57                 Object JavaDoc value = tag.findWriter().getWriterValue();
58                 result.put(urlKey, value);
59             } else if ((! mayBeMissing) || tag.getContextProvider().getContextContainer().isPresent(key)) {
60                 Object JavaDoc value = tag.getObject(key);
61                 if (value != null) {
62                     if (log.isDebugEnabled()) {
63                         log.debug("adding parameter (with referids) " + key + "/" + value);
64                     }
65                     result.put(urlKey, value);
66                 }
67             } else {
68                 log.debug("No key '" + key + "' in context, not adding to referids");
69             }
70         }
71         return result;
72     }
73
74 }
75
Popular Tags