01: //WebOnSwing - Web Application Framework
02: //Copyright (C) 2003 Fernando Damian Petrola
03: //
04: //This library is free software; you can redistribute it and/or
05: //modify it under the terms of the GNU Lesser General Public
06: //License as published by the Free Software Foundation; either
07: //version 2.1 of the License, or (at your option) any later version.
08: //
09: //This library is distributed in the hope that it will be useful,
10: //but WITHOUT ANY WARRANTY; without even the implied warranty of
11: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: //Lesser General Public License for more details.
13: //
14: //You should have received a copy of the GNU Lesser General Public
15: //License along with this library; if not, write to the Free Software
16: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17:
18: package net.ar.webonswing.render.markup;
19:
20: import net.ar.webonswing.visitor.*;
21:
22: public class TextMarkupRenderer implements MarkupVisitor {
23: StringBuffer theResult;
24: boolean concatNewLine;
25:
26: public TextMarkupRenderer(MarkupElement anElement) {
27: theResult = new StringBuffer();
28: visit(anElement);
29: concatNewLine = false;
30: }
31:
32: public TextMarkupRenderer(MarkupElement anElement,
33: boolean doConcatNewLine) {
34: theResult = new StringBuffer();
35: concatNewLine = doConcatNewLine;
36: visit(anElement);
37: }
38:
39: public TextMarkupRenderer(StringBuffer anExternalResult,
40: boolean doConcatNewLine) {
41: theResult = anExternalResult;
42: concatNewLine = doConcatNewLine;
43: }
44:
45: public void tagVisit(Tag aTag) {
46: }
47:
48: public void visitTagContent(TagContent aContent) {
49: theResult.append(aContent.getTheContent().toString());
50: }
51:
52: public String getResult() {
53: return theResult.toString();
54: }
55:
56: public void setResult(StringBuffer aResult) {
57: this .theResult = aResult;
58: }
59:
60: public void visit(Visitable aRendereable) {
61: if (aRendereable != null)
62: aRendereable.accept(this );
63: }
64:
65: public void visitTagBegin(Tag aTag) {
66: theResult.append("<" + aTag.getTheName());
67: }
68:
69: public void visitAttribute(TagAttribute anAttribute) {
70: theResult.append(" ");
71: theResult.append(anAttribute.getKey());
72:
73: if (anAttribute.getValue().length() > 0)
74: theResult.append("=\"" + anAttribute.getValue() + "\"");
75: }
76:
77: public void visitAllTagAttributesEnd(Tag tag) {
78: theResult.append(">" + (concatNewLine ? "\n" : ""));
79: }
80:
81: public void visitMarkupContainerBegin(MarkupContainer anAttribute) {
82: }
83:
84: public void visitMarkupContainerEnd(MarkupContainer anAttribute) {
85: }
86:
87: public void visitTagEnd(Tag aTag) {
88: if (aTag.isNeedsClosure())
89: theResult.append("</" + aTag.getTheName() + ">"
90: + (concatNewLine ? "\n" : ""));
91: }
92: }
|