001: package org.apache.turbine.util.template;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024:
025: import org.apache.ecs.ConcreteElement;
026:
027: import org.apache.turbine.modules.ScreenLoader;
028: import org.apache.turbine.util.RunData;
029:
030: /**
031: * Returns output of a Screen module. An instance of this is
032: * placed in the Velocity context by the VelocityDirectLayout. This
033: * allows the screen to be executed only at rendering.
034: * Here's how it's used in a template:
035: *
036: * <p>
037: * <code>
038: * $screen_placeholder
039: * </code>
040: * <p>
041: * <code>
042: * $screen_placeholder.setScreen("Test")
043: * </code>
044: * </p>
045: *
046: * @author <a href="raphael@apache.org">Raphaƫl Luta</a>
047: * @version $Id: TemplateScreen.java 534527 2007-05-02 16:10:59Z tv $
048: */
049: public class TemplateScreen {
050: /** Logging */
051: private static Log log = LogFactory.getLog(TemplateScreen.class);
052:
053: /* The RunData object. */
054: private RunData data;
055:
056: /* The name of the screen template. */
057: private String screen;
058:
059: /**
060: * Constructor
061: *
062: * @param data A Turbine RunData object.
063: */
064: public TemplateScreen(RunData data) {
065: this .data = data;
066: this .screen = data.getScreen();
067: }
068:
069: /**
070: * Set the screen.
071: *
072: * @param screen A String with the name of the screen module
073: * @return A TemplateScreen (self).
074: */
075: public TemplateScreen setScreen(String screen) {
076: this .screen = screen;
077: return this ;
078: }
079:
080: /**
081: * Builds the output of the navigation template.
082: *
083: * @return A String.
084: */
085: public String toString() {
086: String returnValue = "";
087:
088: try {
089: ConcreteElement results = ScreenLoader.getInstance().eval(
090: data, this .screen);
091:
092: if (results != null) {
093: returnValue = results.toString();
094: }
095: } catch (Exception e) {
096: log.error(e);
097: }
098:
099: return returnValue;
100: }
101: }
|