1 10 package org.mmbase.bridge.jsp.taglib; 11 12 import org.mmbase.util.functions.*; 13 import org.mmbase.util.Casting; 14 import javax.servlet.jsp.JspTagException ; 15 import javax.servlet.jsp.JspException ; 16 17 import org.mmbase.bridge.jsp.taglib.util.Attribute; 18 19 import org.mmbase.bridge.*; 20 21 28 29 public class NodeInfoTag extends NodeReferrerTag implements Writer { 30 31 private static final int TYPE_NODEMANAGER = 0; 32 private static final int TYPE_GUINODEMANAGER = 1; 33 private static final int TYPE_GUINODEMANAGER_PLURAL = 2; 34 private static final int TYPE_NODENUMBER = 3; 35 private static final int TYPE_GUI = 4; 36 private static final int TYPE_DESCRIPTION = 5; 37 private static final int TYPE_CONTEXT = 6; 38 private static final int TYPE_QUERY = 50; 40 41 private Attribute type = Attribute.NULL; 42 43 public void setType(String tu) throws JspTagException { 44 type = getAttribute(tu); 45 } 46 47 private int getType() throws JspTagException { 48 String t = type.getString(this).toLowerCase(); 49 if ("nodemanager".equals(t) || "type".equals(t)) { 52 return TYPE_NODEMANAGER; 53 } else if ("guinodemanager".equals(t) || "guitype".equals(t)) { 54 return TYPE_GUINODEMANAGER; 55 } else if ("plural_guinodemanager".equals(t) || "plural_guitype".equals(t)) { 56 return TYPE_GUINODEMANAGER_PLURAL; 57 } else if ("description".equals(t)) { 58 return TYPE_DESCRIPTION; 59 } else if ("context".equals(t)) { 60 return TYPE_CONTEXT; 61 } else if ("number".equals(t)) { 62 return TYPE_NODENUMBER; 63 } else if ("gui".equals(t)) { 64 return TYPE_GUI; 65 } else if ("query".equals(t)) { 66 return TYPE_QUERY; 67 } else { 68 throw new JspTagException ("Unknown value for attribute type (" + t + ")"); 69 } 70 } 71 72 private Attribute nodeManagerAtt = Attribute.NULL; 73 public void setNodetype(String t) throws JspTagException { 74 nodeManagerAtt = getAttribute(t); 75 } 76 77 public int doStartTag() throws JspTagException { 78 79 NodeManager nodeManager = null; 80 if (nodeManagerAtt == Attribute.NULL) { nodeManager = getNode().getNodeManager(); 82 } else { 83 nodeManager = getCloudVar().getNodeManager(nodeManagerAtt.getString(this)); 84 } 85 Object show = ""; 86 87 int t = getType(); 89 switch(t) { 90 case TYPE_NODENUMBER: 91 if (nodeManagerAtt == Attribute.NULL) { show = new Integer (getNode().getNumber()); 93 } else { 94 show = new Integer (nodeManager.getNumber()); 95 } 96 break; 97 case TYPE_CONTEXT: 98 if (nodeManagerAtt == Attribute.NULL) { show = getNode().getContext(); 100 } else { 101 show = nodeManager.getContext(); 102 } 103 break; 104 case TYPE_NODEMANAGER: 105 show = nodeManager.getName(); 106 break; 107 case TYPE_DESCRIPTION: 108 show = nodeManager.getDescription(); 109 break; 110 case TYPE_GUINODEMANAGER: 111 show = nodeManager.getGUIName(); 112 break; 113 case TYPE_GUINODEMANAGER_PLURAL: 114 show = nodeManager.getGUIName(10); 115 break; 116 case TYPE_GUI: { 117 if (nodeManagerAtt == Attribute.NULL) { helper.useEscaper(false); String sessionName = ""; 120 CloudTag ct = (CloudTag) findParentTag(CloudTag.class, null, false); 121 if (ct != null) { 122 sessionName = ct.getSessionName(); 123 } 124 Node node = getNode(); 125 Function guiFunction = node.getFunction("gui"); 126 Parameters args = guiFunction.createParameters(); 127 if (args.containsParameter(Parameter.FIELD)) { 128 args.set(Parameter.FIELD, ""); } 130 if (args.containsParameter("session")) { 131 args.set("session", sessionName); 132 } 133 fillStandardParameters(args); 134 show = Casting.toString(guiFunction.getFunctionValue(args)); 135 } else { 136 show = nodeManager.getGUIName(); 137 } 138 break; 139 } 140 case TYPE_QUERY: 141 show = findNodeProvider().getGeneratingQuery(); 142 break; 143 default: 144 } 145 146 147 helper.setValue(show); 148 if (getId() != null) { 149 getContextProvider().getContextContainer().register(getId(), helper.getValue()); 150 } 151 return EVAL_BODY_BUFFERED; 152 } 153 154 public int doAfterBody() throws JspException { 155 return helper.doAfterBody(); 156 } 157 158 161 public int doEndTag() throws JspTagException { 162 helper.doEndTag(); 163 return super.doEndTag(); 164 165 } 166 } 167 | Popular Tags |