001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.contrib.ajax; 016 017 import java.util.HashMap; 018 import java.util.Map; 019 020 import org.apache.tapestry.BaseComponent; 021 import org.apache.tapestry.IActionListener; 022 import org.apache.tapestry.IRequestCycle; 023 import org.apache.tapestry.Tapestry; 024 import org.apache.tapestry.engine.ILink; 025 import org.apache.tapestry.services.LinkFactory; 026 import org.apache.tapestry.services.ServiceConstants; 027 028 /** 029 * @author mindbridge 030 * @author Paul Green 031 * @since 4.0 032 */ 033 public abstract class XTile extends BaseComponent implements IXTile 034 { 035 public abstract LinkFactory getLinkFactory(); 036 037 public abstract IActionListener getListener(); 038 public abstract String getSendName(); 039 public abstract String getReceiveName(); 040 public abstract String getErrorName(); 041 public abstract boolean getDisableCaching(); 042 043 public void trigger(IRequestCycle cycle) { 044 IActionListener listener = getListener(); 045 046 if (listener == null) 047 throw Tapestry.createRequiredParameterException(this, "listener"); 048 049 listener.actionTriggered(this, cycle); 050 } 051 052 public Map getScriptSymbols() 053 { 054 Map ret = new HashMap(); 055 ret.put("sendFunctionName", getSendName()); 056 ret.put("receiveFunctionName", getReceiveName()); 057 ret.put("errorFunctionName", getErrorName()); 058 ret.put("disableCaching", getDisableCaching() ? "true" : null); 059 060 Map parameters = new HashMap(); 061 parameters.put(ServiceConstants.SERVICE, XTileService.SERVICE_NAME); 062 parameters.put(ServiceConstants.PAGE, getPage().getPageName()); 063 parameters.put(ServiceConstants.COMPONENT, getIdPath()); 064 065 ILink link = getLinkFactory().constructLink(getPage().getRequestCycle(), 066 false, parameters, false); 067 068 ret.put("url", link.getURL()); 069 070 return ret; 071 } 072 073 }