~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to ext/src/xerces-2_9_1/src/org/apache/xerces/impl/xs/opti/TextImpl.java

  • Committer: matthewoliver
  • Date: 2009-12-10 03:18:07 UTC
  • Revision ID: vcs-imports@canonical.com-20091210031807-l086qguzdlljtkl9
Merged Xena Testing into Xena Stable for the Xena 5 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
 
3
 * contributor license agreements.  See the NOTICE file distributed with
 
4
 * this work for additional information regarding copyright ownership.
 
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
 
6
 * (the "License"); you may not use this file except in compliance with
 
7
 * the License.  You may obtain a copy of the License at
 
8
 * 
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
 
10
 * 
 
11
 * Unless required by applicable law or agreed to in writing, software
 
12
 * distributed under the License is distributed on an "AS IS" BASIS,
 
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
14
 * See the License for the specific language governing permissions and
 
15
 * limitations under the License.
 
16
 */
 
17
 
 
18
package org.apache.xerces.impl.xs.opti;
 
19
 
 
20
import org.w3c.dom.DOMException;
 
21
import org.w3c.dom.Node;
 
22
 
 
23
/**
 
24
 * @xerces.internal  
 
25
 * 
 
26
 * @author Neil Graham, IBM
 
27
 * @version $Id: TextImpl.java,v 1.2 2009/12/10 03:18:27 matthewoliver Exp $
 
28
 */
 
29
 
 
30
public class TextImpl extends DefaultText {
 
31
 
 
32
    // Data
 
33
    String fData = null;
 
34
    SchemaDOM fSchemaDOM = null;
 
35
    int fRow;
 
36
    int fCol;
 
37
 
 
38
    public TextImpl(StringBuffer str, SchemaDOM sDOM, int row, int col) {
 
39
        fData = str.toString();
 
40
        fSchemaDOM = sDOM;
 
41
        fRow = row;
 
42
        fCol = col;
 
43
        rawname = prefix = localpart = uri = null;
 
44
        nodeType = Node.TEXT_NODE;
 
45
    }
 
46
 
 
47
    //
 
48
    // org.w3c.dom.Node methods
 
49
    //
 
50
    
 
51
    public Node getParentNode() {
 
52
        return fSchemaDOM.relations[fRow][0];
 
53
    }
 
54
 
 
55
    public Node getPreviousSibling() {
 
56
        if (fCol == 1) {
 
57
            return null;
 
58
        }
 
59
        return fSchemaDOM.relations[fRow][fCol-1];
 
60
    }
 
61
 
 
62
 
 
63
    public Node getNextSibling() {
 
64
        if (fCol == fSchemaDOM.relations[fRow].length-1) {
 
65
            return null;
 
66
        }
 
67
        return fSchemaDOM.relations[fRow][fCol+1];
 
68
    }
 
69
 
 
70
    // CharacterData methods
 
71
 
 
72
    /**
 
73
     * The character data of the node that implements this interface. The DOM 
 
74
     * implementation may not put arbitrary limits on the amount of data 
 
75
     * that may be stored in a <code>CharacterData</code> node. However, 
 
76
     * implementation limits may mean that the entirety of a node's data may 
 
77
     * not fit into a single <code>DOMString</code>. In such cases, the user 
 
78
     * may call <code>substringData</code> to retrieve the data in 
 
79
     * appropriately sized pieces.
 
80
     * @exception DOMException
 
81
     *   NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
 
82
     * @exception DOMException
 
83
     *   DOMSTRING_SIZE_ERR: Raised when it would return more characters than 
 
84
     *   fit in a <code>DOMString</code> variable on the implementation 
 
85
     *   platform.
 
86
     */
 
87
    public String getData()
 
88
                            throws DOMException {
 
89
        return fData;
 
90
    }
 
91
 
 
92
    /**
 
93
     * The number of 16-bit units that are available through <code>data</code> 
 
94
     * and the <code>substringData</code> method below. This may have the 
 
95
     * value zero, i.e., <code>CharacterData</code> nodes may be empty.
 
96
     */
 
97
    public int getLength() {
 
98
        if(fData == null) return 0;
 
99
        return fData.length();
 
100
    }
 
101
 
 
102
    /**
 
103
     * Extracts a range of data from the node.
 
104
     * @param offset Start offset of substring to extract.
 
105
     * @param count The number of 16-bit units to extract.
 
106
     * @return The specified substring. If the sum of <code>offset</code> and 
 
107
     *   <code>count</code> exceeds the <code>length</code>, then all 16-bit 
 
108
     *   units to the end of the data are returned.
 
109
     * @exception DOMException
 
110
     *   INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is 
 
111
     *   negative or greater than the number of 16-bit units in 
 
112
     *   <code>data</code>, or if the specified <code>count</code> is 
 
113
     *   negative.
 
114
     *   <br>DOMSTRING_SIZE_ERR: Raised if the specified range of text does 
 
115
     *   not fit into a <code>DOMString</code>.
 
116
     */
 
117
    public String substringData(int offset, 
 
118
                                int count)
 
119
                                throws DOMException {
 
120
        if(fData == null) return null;
 
121
        if(count < 0 || offset < 0 || offset > fData.length()) 
 
122
            throw new DOMException(DOMException.INDEX_SIZE_ERR, "parameter error");
 
123
        if(offset+count >= fData.length()) 
 
124
            return fData.substring(offset);
 
125
        return fData.substring(offset, offset+count);
 
126
    }
 
127
 
 
128
}