001 // Copyright May 16, 2006 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 package net.sf.tacos.components.dojo; 015 016 import java.util.HashMap; 017 import java.util.Map; 018 import net.sf.tacos.util.JSONMarkupWriter; 019 import org.apache.tapestry.IMarkupWriter; 020 import org.apache.tapestry.IRequestCycle; 021 import org.apache.tapestry.IScript; 022 import org.apache.tapestry.TapestryUtils; 023 import org.apache.tapestry.json.JSONObject; 024 025 /** 026 * Implementation of any dojo widget. 027 * 028 * @since 4.1.0 029 * 030 * TODO: figure out the correct value for isContainer based on dojoType. 031 */ 032 public abstract class DojoWidget extends GenericWidget 033 { 034 public abstract String getStyle(); 035 036 public abstract String getDojoType(); 037 038 /** 039 * {@inheritDoc} 040 */ 041 public void renderWidget(IMarkupWriter writer, IRequestCycle cycle) 042 { 043 if (!cycle.isRewinding()) { 044 writer.begin(getTemplateTagName()); // use element specified 045 renderIdAttribute(writer, cycle); // render id="" client id 046 writer.attribute("style", getStyle()); 047 //renderInformalParameters(writer, cycle); 048 } 049 050 renderBody(writer, cycle); 051 052 if (!cycle.isRewinding()) { 053 writer.end(); 054 } 055 056 if (!cycle.isRewinding()) { 057 JSONMarkupWriter jsonWriter = new JSONMarkupWriter(); 058 renderInformalParameters(jsonWriter, cycle); 059 JSONObject json = jsonWriter.getAttributes(); 060 061 Map parms = new HashMap(); 062 parms.put("component", this); 063 parms.put("type", getDojoType()); 064 parms.put("props", json.toString()); 065 066 getScript().execute(this, cycle, TapestryUtils.getPageRenderSupport(cycle, this), parms); 067 } 068 } 069 070 /** Injected script. */ 071 public abstract IScript getScript(); 072 }