View Javadoc

1   package net.sourceforge.blogentis.utils.tools;
2   
3   //-----------------------------------------------------------------------
4   //Blogentis - a blog publishing platform.
5   //Copyright (C) 2004 Tassos Bassoukos <abassouk@gmail.com>
6   //
7   //This library is free software; you can redistribute it and/or
8   //modify it under the terms of the GNU Lesser General Public
9   //License as published by the Free Software Foundation; either
10  //version 2.1 of the License, or (at your option) any later version.
11  //
12  //This library is distributed in the hope that it will be useful,
13  //but WITHOUT ANY WARRANTY; without even the implied warranty of
14  //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  //Lesser General Public License for more details.
16  //
17  //You should have received a copy of the GNU Lesser General Public
18  //License along with this library; if not, write to the Free Software
19  //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  //-----------------------------------------------------------------------
21  //
22  //$Id: PageAttributes.java,v 1.1 2004/10/22 17:34:15 tassos Exp $
23  //
24  
25  import java.util.ArrayList;
26  import java.util.List;
27  
28  import org.apache.turbine.util.RunData;
29  import org.apache.turbine.util.template.HtmlPageAttributes;
30  
31  /***
32   * @author abas
33   *  
34   */
35  public class PageAttributes extends HtmlPageAttributes {
36      public static class Link {
37          protected String relation;
38  
39          protected String type;
40  
41          protected String title;
42  
43          protected String href;
44  
45          public Link(String relation, String type, String href, String title) {
46              this.relation = relation;
47              this.type = type;
48              this.href = href;
49              this.title = title;
50          }
51  
52          private static void addAttribute(String name, String value,
53                                           StringBuffer sb) {
54              if (value == null)
55                  return;
56              sb.append(name);
57              sb.append("=\"");
58              sb.append(value);
59              sb.append("\" ");
60          }
61  
62          public String toString() {
63              StringBuffer sb = new StringBuffer("<link ");
64              addAttribute("rel", relation, sb);
65              addAttribute("type", type, sb);
66              addAttribute("href", href, sb);
67              addAttribute("title", title, sb);
68              sb.append("/>");
69              return sb.toString();
70          }
71      }
72  
73      protected List list = new ArrayList();
74  
75      public PageAttributes() {
76          super();
77      }
78  
79      public PageAttributes(RunData data) {
80          super(data);
81      }
82  
83      public String addLink(String rel, String href) {
84          list.add(new Link(rel, null, href, null));
85          return "";
86      }
87  
88      public String addLink(String rel, String type, String href) {
89          list.add(new Link(rel, type, href, null));
90          return "";
91      }
92  
93      public String addLink(String rel, String type, String href, String title) {
94          list.add(new Link(rel, type, href, title));
95          return "";
96      }
97  
98      public void init(Object data) {
99          super.init(data);
100         list.clear();
101     }
102 
103     public List getLinks() {
104         return list;
105     }
106 }