KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > module > sitemesh > parser > FastPage


1 /*
2  * Title: FastPage
3  * Description:
4  *
5  * This software is published under the terms of the OpenSymphony Software
6  * License version 1.1, of which a copy has been included with this
7  * distribution in the LICENSE.txt file.
8  */

9
10 package com.opensymphony.module.sitemesh.parser;
11
12 import java.io.IOException JavaDoc;
13 import java.io.Writer JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.Map JavaDoc;
16
17 /**
18  * HTMLPage implementation produced by FastPageParser.
19  *
20  * @author <a HREF="mailto:salaman@qoretech.com">Victor Salaman</a>
21  * @version $Revision: 1.5 $
22  */

23 public final class FastPage extends AbstractHTMLPage
24 {
25    private String JavaDoc head;
26    private String JavaDoc body;
27
28    public FastPage(Map JavaDoc sitemeshProps, Map JavaDoc htmlProps, Map JavaDoc metaProps, Map JavaDoc bodyProps,
29                    String JavaDoc title, String JavaDoc head, String JavaDoc body, boolean frameSet)
30    {
31       this.head = head;
32       this.body = body;
33       setFrameSet(frameSet);
34       addAttributeList("", htmlProps);
35       addAttributeList("page.", sitemeshProps);
36       addAttributeList("body.", bodyProps);
37       addAttributeList("meta.", metaProps);
38       addProperty("title", title);
39    }
40
41    public void writeHead(Writer JavaDoc out) throws IOException JavaDoc
42    {
43       out.write(head);
44    }
45
46    public void writeBody(Writer JavaDoc out) throws IOException JavaDoc
47    {
48       out.write(body);
49    }
50
51    private void addAttributeList(String JavaDoc prefix, Map JavaDoc attributes)
52    {
53       if(attributes == null || attributes.isEmpty()) return;
54
55       String JavaDoc name, value;
56       Iterator JavaDoc i = attributes.entrySet().iterator();
57
58       while (i.hasNext())
59       {
60          Map.Entry JavaDoc entry = (Map.Entry JavaDoc) i.next();
61          name = (String JavaDoc) entry.getKey();
62          value = (String JavaDoc) entry.getValue();
63
64          if(value != null && value.trim().length() > 0)
65          {
66             addProperty(prefix + name, value);
67          }
68       }
69    }
70
71    public void setVerbatimPage(char[] v)
72    {
73       this.pageData = v;
74    }
75
76    public String JavaDoc getBody()
77    {
78       return body;
79    }
80
81    public String JavaDoc getHead()
82    {
83       return head;
84    }
85 }
86
Popular Tags