View Javadoc

    1   /*
    2    * $Id: Template.java 471756 2006-11-06 15:01:43Z husted $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
    10   * with the License.  You may obtain a copy of the License at
    11   *
    12   *  http://www.apache.org/licenses/LICENSE-2.0
    13   *
    14   * Unless required by applicable law or agreed to in writing,
    15   * software distributed under the License is distributed on an
    16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    17   * KIND, either express or implied.  See the License for the
    18   * specific language governing permissions and limitations
    19   * under the License.
    20   */
    21  package org.apache.struts2.components.template;
    22
    23  import java.util.ArrayList;
    24  import java.util.List;
    25
    26  /***
    27   * A template.
    28   * <p/>
    29   * A template is used as a model for rendering output.
    30   * This object contains basic common template information
    31   */
    32  public class Template implements Cloneable {
    33      String dir;
    34      String theme;
    35      String name;
    36
    37      /***
    38       * Constructor.
    39       *
    40       * @param dir  base folder where the template is stored.
    41       * @param theme  the theme of the template
    42       * @param name   the name of the template.
    43       */
    44      public Template(String dir, String theme, String name) {
    45          this.dir = dir;
    46          this.theme = theme;
    47          this.name = name;
    48      }
    49
    50      public String getDir() {
    51          return dir;
    52      }
    53
    54      public String getTheme() {
    55          return theme;
    56      }
    57
    58      public String getName() {
    59          return name;
    60      }
    61
    62      public List getPossibleTemplates(TemplateEngine engine) {
    63          List list = new ArrayList(3);
    64          Template template = this;
    65          String parentTheme;
    66          list.add(template);
    67          while ((parentTheme = (String) engine.getThemeProps(template).get("parent")) != null) {
    68              try {
    69                  template = (Template) template.clone();
    70                  template.theme = parentTheme;
    71                  list.add(template);
    72              } catch (CloneNotSupportedException e) {
    73                  // do nothing
    74              }
    75          }
    76
    77          return list;
    78      }
    79
    80      /***
    81       * Constructs a string in the format <code>/dir/theme/name</code>.
    82       * @return a string in the format <code>/dir/theme/name</code>.
    83       */
    84      public String toString() {
    85          return "/" + dir + "/" + theme + "/" + name;
    86      }
    87
    88      protected Object clone() throws CloneNotSupportedException {
    89          return super.clone();
    90      }
    91  }