KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > lazydom > LazyText


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: LazyText.java,v 1.3 2005/01/26 08:29:24 jkjome Exp $
22  */

23
24 package org.enhydra.xml.lazydom;
25
26 import org.enhydra.apache.xerces.dom.TextImpl;
27 import org.enhydra.xml.io.PreFormattedText;
28 import org.w3c.dom.Document JavaDoc;
29 import org.w3c.dom.Node JavaDoc;
30
31 /**
32  * Lazy text node.
33  */

34 public class LazyText extends TextImpl implements LazyNode, PreFormattedText {
35     /**
36      * Constructor.
37      * @param ownerDoc The document that owns this node.
38      * @param template If not-null, get the parameters from this template.
39      * @param data The node data. Will be ignored if template is not-null.
40      */

41     protected LazyText(LazyDocument ownerDoc,
42                        LazyText template,
43                        String JavaDoc data) {
44         super(ownerDoc,
45               (template != null) ? template.getData() : data);
46         if (template != null) {
47             fTemplateNode = template;
48             fNodeId = template.getNodeId();
49         }
50     }
51
52     //-------------------------------------------------------------------------
53
// LazyText specific
54
//-------------------------------------------------------------------------
55

56     /**
57      * Template for this Text.
58      */

59     private LazyText fTemplateNode = null;
60
61     /**
62      * Get the template for this node.
63      * @see LazyNode#getTemplateNode
64      */

65     public LazyText getTemplateText() {
66         return fTemplateNode;
67     }
68
69     /**
70      * @see Node#cloneNode
71      */

72     public Node JavaDoc cloneNode(boolean deep) {
73         // Just creats a new node with the same value
74
return super.cloneNode(deep);
75     }
76
77     //-------------------------------------------------------------------------
78
// LazyNode support
79
//-------------------------------------------------------------------------
80

81     /*
82      * Node id for this element.
83      */

84     private int fNodeId = NULL_NODE_ID;
85
86     /**
87      * Is this a template node?
88      */

89     private boolean fIsTemplateNode;
90
91     /**
92      * Mark the node as a template node and associated preformatted text.
93      * @see LazyNode#makeTemplateNode
94      * @see PreFormattedText#setPreFormattedText
95      */

96     public void makeTemplateNode(int nodeId,
97                                  String JavaDoc text) {
98         fNodeId = nodeId;
99         fIsTemplateNode = true;
100         fPreFormattedText = text;
101     }
102
103     /*
104      * @see LazyNode#makeTemplateNode
105      */

106     public void makeTemplateNode(int nodeId) {
107         fNodeId = nodeId;
108         fIsTemplateNode = true;
109     }
110
111     /**
112      * @see LazyNode#getNodeId
113      */

114     public int getNodeId() {
115         return fNodeId;
116     }
117
118     /**
119      * @see LazyNode#isTemplateNode
120      */

121     public boolean isTemplateNode() {
122         return fIsTemplateNode;
123     }
124
125     /**
126      * @see LazyNode#getTemplateNode
127      */

128     public LazyNode getTemplateNode() {
129         return fTemplateNode;
130     }
131
132     /**
133      * @see LazyNode#templateClone
134      */

135     public LazyNode templateClone(Document JavaDoc ownerDocument) {
136         return new LazyText((LazyDocument)ownerDocument, this, null);
137     }
138
139     /**
140      * Set the node value, invalidating the id. All node data is modified
141      * by this routine.
142      * @see org.w3c.dom.Node#setNodeValue
143      */

144     public void setNodeValue(String JavaDoc value) {
145         fNodeId = NULL_NODE_ID;
146         super.setNodeValue(value);
147     }
148
149     //-------------------------------------------------------------------------
150
// PreFormattedText specific
151
//-------------------------------------------------------------------------
152

153     /**
154      * Pre-formatted text associated with the node.
155      */

156     private String JavaDoc fPreFormattedText;
157
158     /**
159      * @see PreFormattedText#getPreFormattedText
160      */

161     public String JavaDoc getPreFormattedText() {
162         return fPreFormattedText;
163     }
164
165     /**
166      * @see PreFormattedText#setPreFormattedText
167      */

168     public void setPreFormattedText(String JavaDoc text) {
169         fPreFormattedText = text;
170     }
171
172 }
173
Popular Tags