View Javadoc

1   /*
2    * Copyright 2002 - 2007 JEuclid, http://jeuclid.sf.net
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  /* $Id: PartialTextImpl.java 310 2007-05-18 20:26:36Z maxberger $ */
18  
19  package net.sourceforge.jeuclid.dom;
20  
21  import org.w3c.dom.Node;
22  import org.w3c.dom.Text;
23  
24  /**
25   * Partial implementation of org.w3c.dom.Text.
26   * <p>
27   * This implements only the functions necessary for MathElements. Feel free to
28   * implement whatever functions you need.
29   * 
30   * @author Max Berger
31   * @version $Revision: 310 $
32   */
33  public class PartialTextImpl extends AbstractPartialNodeImpl implements Text {
34  
35      private String content;
36  
37      /**
38       * Constructor.
39       * 
40       * @param text
41       *            text content for this node.
42       */
43      public PartialTextImpl(final String text) {
44          this.content = text;
45      }
46  
47      /** {@inheritDoc} */
48      public String getWholeText() {
49          return this.content;
50      }
51  
52      /** {@inheritDoc} */
53      public boolean isElementContentWhitespace() {
54          throw new UnsupportedOperationException();
55      }
56  
57      /** {@inheritDoc} */
58      public Text replaceWholeText(final String newContent) {
59          this.content = newContent;
60          return this;
61      }
62  
63      /** {@inheritDoc} */
64      public Text splitText(final int offset) {
65          throw new UnsupportedOperationException();
66      }
67  
68      /** {@inheritDoc} */
69      public void appendData(final String arg) {
70          this.content = this.content + arg;
71      }
72  
73      /** {@inheritDoc} */
74      public void deleteData(final int offset, final int count) {
75          throw new UnsupportedOperationException();
76      }
77  
78      /** {@inheritDoc} */
79      public String getData() {
80          return this.content;
81      }
82  
83      /** {@inheritDoc} */
84      public int getLength() {
85          return this.content.length();
86      }
87  
88      /** {@inheritDoc} */
89      public void insertData(final int offset, final String arg) {
90          throw new UnsupportedOperationException();
91      }
92  
93      /** {@inheritDoc} */
94      public void replaceData(final int offset, final int count,
95              final String arg) {
96          throw new UnsupportedOperationException();
97      }
98  
99      /** {@inheritDoc} */
100     public void setData(final String data) {
101         this.content = data;
102     }
103 
104     /** {@inheritDoc} */
105     public String substringData(final int offset, final int count) {
106         throw new UnsupportedOperationException();
107     }
108 
109     /** {@inheritDoc} */
110     public String getNodeName() {
111         return "#text";
112     }
113 
114     /** {@inheritDoc} */
115     public short getNodeType() {
116         return Node.TEXT_NODE;
117     }
118 
119     /** {@inheritDoc} */
120     @Override
121     public String getNodeValue() {
122         return this.content;
123     }
124 
125     /** {@inheritDoc} */
126     @Override
127     public void setTextContent(final String newTextContent) {
128         this.content = newTextContent;
129     }
130 
131     /** {@inheritDoc} */
132     @Override
133     public String getTextContent() {
134         return this.content;
135     }
136 
137 }