1 10 package org.mmbase.bridge.jsp.taglib; 11 12 import java.util.Locale ; 13 14 import org.mmbase.bridge.jsp.taglib.util.Attribute; 15 import org.mmbase.bridge.Cloud; 16 import org.mmbase.bridge.Node; 17 import org.mmbase.bridge.CloudContext; 18 import org.mmbase.bridge.ContextProvider; 19 20 import org.mmbase.util.functions.Parameter; 21 import org.mmbase.util.functions.Parameters; 22 23 24 import javax.servlet.jsp.JspTagException ; 25 26 import org.mmbase.util.logging.Logger; 27 import org.mmbase.util.logging.Logging; 28 29 30 37 38 public abstract class CloudReferrerTag extends ContextReferrerTag { 39 40 private static final Logger log = Logging.getLoggerInstance(CloudReferrerTag.class); 41 42 43 private static CloudContext cloudContext; 44 45 46 private Attribute cloudId = Attribute.NULL; 47 50 51 56 public void setCloud(String c) throws JspTagException { 57 cloudId = getAttribute(c); 58 } 59 60 61 66 67 protected CloudProvider findCloudProvider() throws JspTagException { 68 return (CloudProvider) findParentTag(CloudProvider.class, (String ) cloudId.getValue(this)); 69 } 70 71 77 public CloudProvider findCloudProvider(boolean throwexception) throws JspTagException { 78 return (CloudProvider) findParentTag(CloudProvider.class, (String ) cloudId.getValue(this), throwexception); 79 } 80 81 82 90 public Cloud getCloudVar() throws JspTagException { 91 return findCloudProvider().getCloudVar(); 92 } 93 94 95 96 99 protected CloudContext getCloudContext(){ 100 if (cloudContext == null){ 101 cloudContext = ContextProvider.getDefaultCloudContext(); 102 } 103 return cloudContext; 104 } 105 106 protected Node getNode(String key) throws JspTagException { 107 Node n = getNodeOrNull(key); 108 if (n == null) getCloudVar().getNode((String ) getObject(key)); return n; 110 } 111 114 115 protected Node getNodeOrNull(String key) throws JspTagException { 116 Object n = getObject(key); 117 if (n instanceof Node) { 118 log.debug("found a Node in Context"); 119 return (Node) n; 120 } else if ((n instanceof String ) || (n instanceof Number )) { 121 log.debug("found a Node Number in Context"); 122 if (! getCloudVar().hasNode(n.toString())) return null; 123 return getCloudVar().getNode(n.toString()); 124 } else { 125 throw new JspTagException ("Element " + referid + " from context " + contextId + " cannot be converted to node (because it is a " + n.getClass().getName() + " now)"); 126 } 127 } 128 129 130 protected void fillStandardParameters(Parameters p) throws JspTagException { 131 super.fillStandardParameters(p); 132 CloudProvider prov = findCloudProvider(false); 133 if (prov != null) { 134 Cloud cloud = prov.getCloudVar(); 135 if (cloud != null) { 136 p.setIfDefined(Parameter.CLOUD, cloud); 137 p.setIfDefined(Parameter.USER, cloud.getUser()); 138 } 139 } 140 } 141 142 145 public Locale getLocale() throws JspTagException { 146 LocaleTag localeTag = (LocaleTag)findParentTag(LocaleTag.class, null, false); 147 if (localeTag != null) { 148 Locale locale = localeTag.getLocale(); 149 if (locale != null) { 150 return locale; 151 } 152 } 153 return getCloudVar().getLocale(); 154 } 155 156 } 157 | Popular Tags |