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.wml;
016
017 import org.apache.hivemind.ApplicationRuntimeException;
018 import org.apache.hivemind.HiveMind;
019 import org.apache.tapestry.AbstractComponent;
020 import org.apache.tapestry.IMarkupWriter;
021 import org.apache.tapestry.IRequestCycle;
022 import org.apache.tapestry.Tapestry;
023
024 /**
025 * A deck contains a collection of cards. There is a variety of card types, each specifying a
026 * different mode of user interaction.
027 *
028 * @author David Solis
029 * @since 3.0
030 */
031
032 public abstract class Card extends AbstractComponent
033 {
034 private static final String ATTRIBUTE_NAME = "org.apache.tapestry.wml.Card";
035
036 /**
037 * @see AbstractComponent#renderComponent(IMarkupWriter, IRequestCycle)
038 */
039
040 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
041 {
042 if (cycle.getAttribute(ATTRIBUTE_NAME) != null)
043 throw new ApplicationRuntimeException(Tapestry.getMessage("Card.cards-may-not-nest"),
044 this, null, null);
045
046 cycle.setAttribute(ATTRIBUTE_NAME, this);
047
048 writer.begin("card");
049
050 String title = getTitle();
051 if (HiveMind.isNonBlank(title))
052 writer.attribute("title", title);
053
054 renderInformalParameters(writer, cycle);
055
056 IMarkupWriter nestedWriter = writer.getNestedWriter();
057
058 renderBody(nestedWriter, cycle);
059
060 nestedWriter.close();
061
062 writer.end();
063
064 cycle.removeAttribute(ATTRIBUTE_NAME);
065 }
066
067 public abstract String getTitle();
068 }