1 18 package org.apache.beehive.netui.tags.html; 19 20 import org.apache.beehive.netui.util.internal.InternalStringBuilder; 21 22 import org.apache.beehive.netui.pageflow.internal.InternalConstants; 23 import org.apache.beehive.netui.pageflow.scoping.ScopedRequest; 24 import org.apache.beehive.netui.pageflow.scoping.ScopedServletUtils; 25 import org.apache.beehive.netui.tags.internal.ReturnActionViewRenderer; 26 import org.apache.beehive.netui.tags.javascript.CoreScriptFeature; 27 import org.apache.beehive.netui.tags.javascript.IScriptReporter; 28 import org.apache.beehive.netui.tags.javascript.ScriptRequestState; 29 import org.apache.beehive.netui.tags.rendering.AbstractRenderAppender; 30 31 import javax.servlet.ServletRequest ; 32 import javax.servlet.jsp.JspException ; 33 import java.util.HashMap ; 34 import java.util.Map ; 35 import java.util.Iterator ; 36 37 class PopupSupport 38 { 39 private static final String VIEW_RENDERER_CLASS_NAME = ReturnActionViewRenderer.class.getName(); 40 private static final String ON_POPUP_DONE_FUNC = "Netui_OnPopupDone"; 41 private static final String POPUP_FUNC = "Netui_Popup"; 42 43 private String _name = ""; 44 private HashMap _features; 45 private boolean _replace = false; 46 private String _onPopupDone; 47 private String _popupFunc; 48 49 public void setName(String name) 50 { 51 _name = name; 52 } 53 54 public void setToolbar(boolean toolbar) 55 { 56 putFeature("toolbar", toolbar); 57 } 58 59 public void setLocation(boolean location) 60 { 61 putFeature("location", location); 62 } 63 64 public void setDirectories(boolean directories) 65 { 66 putFeature("directories", directories); 67 } 68 69 public void setStatus(boolean status) 70 { 71 putFeature("status", status); 72 } 73 74 public void setMenubar(boolean menubar) 75 { 76 putFeature("menubar", menubar); 77 } 78 79 public void setScrollbars(boolean scrollbars) 80 { 81 putFeature("scrollbars", scrollbars); 82 } 83 84 public void setResizable(boolean resizable) 85 { 86 putFeature("resizable", resizable); 87 } 88 89 public void setWidth(int width) 90 { 91 putFeature("width", new Integer (width)); 92 } 93 94 public void setHeight(int height) 95 { 96 putFeature("height", new Integer (height)); 97 } 98 99 public void setLeft(int left) 100 { 101 putFeature("left", new Integer (left)); 102 } 103 104 public void setTop(int top) 105 { 106 putFeature("top", new Integer (top)); 107 } 108 109 public void setReplace(boolean replace) 110 { 111 _replace = replace; 112 } 113 114 public void setOnPopupDone(String onPopupDone) 115 { 116 _onPopupDone = onPopupDone; 117 } 118 119 public void setPopupFunc(String popupFunc) 120 { 121 _popupFunc = popupFunc; 122 } 123 124 public String getOnClick(ServletRequest req, String url) 125 { 126 InternalStringBuilder features = new InternalStringBuilder(); 128 129 if (_features != null) { 130 boolean firstOne = true; 131 for (Iterator i = _features.entrySet().iterator(); i.hasNext();) 132 { 133 Map.Entry entry = (Map.Entry ) i.next(); 134 if (!firstOne) { 135 features.append(','); 136 } 137 features.append(entry.getKey()); 138 features.append('='); 139 features.append(entry.getValue()); 140 firstOne = false; 141 } 142 } 143 144 String popupFunc = (_popupFunc != null ? _popupFunc : getScopedFunctionName(req, POPUP_FUNC)); 145 Object [] args = new Object []{popupFunc, url, _name, features.toString(), Boolean.valueOf(_replace)}; 146 return ScriptRequestState.getString("popupSupportOnClick", args); 147 } 148 149 public void addParams(IUrlParams urlParams, ServletRequest request) 150 throws JspException  151 { 152 urlParams.addParameter(InternalConstants.RETURN_ACTION_VIEW_RENDERER_PARAM, VIEW_RENDERER_CLASS_NAME, null); 153 String onPopupDone = (_onPopupDone != null ? _onPopupDone : ON_POPUP_DONE_FUNC); 154 urlParams.addParameter(ReturnActionViewRenderer.getCallbackParamName(), onPopupDone, null); 155 156 ScopedRequest scopedRequest = ScopedServletUtils.unwrapRequest(request); 157 if (scopedRequest != null) { 158 urlParams.addParameter(ScopedServletUtils.SCOPE_ID_PARAM, scopedRequest.getScopeKey().toString(), null); 159 } 160 } 161 162 public void writeScript(ServletRequest req, ScriptRequestState srs, IScriptReporter scriptReporter, AbstractRenderAppender results) 163 { 164 String popupFunc = getScopedFunctionName(req, POPUP_FUNC); 166 srs.writeFeature(scriptReporter, results, "popupSupportPopupWindow", new Object []{popupFunc}); 167 168 srs.writeFeature(scriptReporter, results, CoreScriptFeature.POPUP_DONE, true, false, new Object []{ON_POPUP_DONE_FUNC}); 170 } 171 172 private static String getScopedFunctionName(ServletRequest req, String funcName) 173 { 174 ScopedRequest scopedRequest = ScopedServletUtils.unwrapRequest(req); 175 return (scopedRequest != null ? funcName + '_' + scopedRequest.getScopeKey() : funcName); 176 } 177 178 private void putFeature(String featureName, boolean val) 179 { 180 putFeature(featureName, val ? new Integer (1) : new Integer (0)); 181 } 182 183 private void putFeature(String featureName, Object val) 184 { 185 if (_features == null) { 186 _features = new HashMap (); 187 } 188 _features.put(featureName, val); 189 } 190 } 191 192 | Popular Tags |