01: /*
02: * argun 1.0
03: * Web 2.0 delivery framework
04: * Copyright (C) 2007 Hammurapi Group
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: *
20: * URL: http://www.hammurapi.biz
21: * e-Mail: support@hammurapi.biz
22: */
23: package biz.hammurapi.web.menu;
24:
25: import java.io.IOException;
26: import java.io.StringReader;
27: import java.io.StringWriter;
28:
29: import org.apache.log4j.Logger;
30:
31: import antlr.TokenStreamException;
32: import biz.hammurapi.web.util.HtmlParser;
33:
34: /**
35: * This class represents top level HTML structure. Menu uses this class to put header and body to appropriate parts of the
36: * "decorated" page.
37: * @author Pavel Vlasov
38: * @version $Revision$
39: */
40: public class HTML {
41: private static final Logger logger = Logger.getLogger(HTML.class);
42:
43: private String head;
44: private String body;
45:
46: public HTML(String head, String body) {
47: this .head = head;
48: this .body = body;
49: }
50:
51: public HTML(String html) {
52: StringWriter bodyWriter = new StringWriter();
53: StringWriter headWriter = new StringWriter();
54: try {
55: if (HtmlParser.parse(new StringReader(html), headWriter,
56: bodyWriter, null)) {
57: ;
58: bodyWriter.close();
59: String newBody = bodyWriter.toString();
60: if (newBody.length() == 0) {
61: head = null;
62: body = html;
63: }
64:
65: headWriter.close();
66: head = headWriter.toString();
67: body = newBody;
68: } else {
69: body = html;
70: }
71: } catch (TokenStreamException e) {
72: logger.debug("Token stream exception in parsing " + html
73: + "\n passing unparsed text to body", e);
74: head = null;
75: body = html;
76: } catch (IOException e) {
77: logger.debug("I/O exception in parsing " + html
78: + "\n passing unparsed text to body", e);
79: head = null;
80: body = html;
81: }
82: }
83:
84: public String getBody() {
85: return body;
86: }
87:
88: public void setBody(String body) {
89: this .body = body;
90: }
91:
92: public String getHead() {
93: return head;
94: }
95:
96: public void setHead(String head) {
97: this.head = head;
98: }
99: }
|