KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > util > SAXLocatorWrapper


1 /*
2  * Copyright 2005 The Apache Software Foundation.
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 package com.sun.org.apache.xerces.internal.util;
18
19 import org.xml.sax.Locator JavaDoc;
20 import org.xml.sax.ext.Locator2 JavaDoc;
21
22 import com.sun.org.apache.xerces.internal.xni.XMLLocator;
23
24 /**
25  * <p>A light wrapper around a SAX locator. This is useful
26  * when bridging between SAX and XNI components.</p>
27  *
28  * @author Michael Glavassevich, IBM
29  *
30  * @version $Id: SAXLocatorWrapper.java,v 1.1.4.1 2005/09/05 09:04:50 neerajbj Exp $
31  */

32 public final class SAXLocatorWrapper implements XMLLocator {
33     
34     private Locator JavaDoc fLocator = null;
35     private Locator2 JavaDoc fLocator2 = null;
36     
37     public SAXLocatorWrapper() {}
38     
39     public void setLocator(Locator JavaDoc locator) {
40         fLocator = locator;
41         if (locator instanceof Locator2 JavaDoc || locator == null) {
42             fLocator2 = (Locator2 JavaDoc) locator;
43         }
44     }
45     
46     public Locator JavaDoc getLocator() {
47         return fLocator;
48     }
49     
50     /*
51      * XMLLocator methods
52      */

53     
54     public String JavaDoc getPublicId() {
55         if (fLocator != null) {
56             return fLocator.getPublicId();
57         }
58         return null;
59     }
60     
61     public String JavaDoc getLiteralSystemId() {
62         if (fLocator != null) {
63             return fLocator.getSystemId();
64         }
65         return null;
66     }
67
68     public String JavaDoc getBaseSystemId() {
69         return null;
70     }
71
72     public String JavaDoc getExpandedSystemId() {
73         return getLiteralSystemId();
74     }
75
76     public int getLineNumber() {
77         if (fLocator != null) {
78             return fLocator.getLineNumber();
79         }
80         return -1;
81     }
82
83     public int getColumnNumber() {
84         if (fLocator != null) {
85             return fLocator.getColumnNumber();
86         }
87         return -1;
88     }
89
90     public int getCharacterOffset() {
91         return -1;
92     }
93
94     public String JavaDoc getEncoding() {
95         if (fLocator2 != null) {
96             return fLocator2.getEncoding();
97         }
98         return null;
99     }
100
101     public String JavaDoc getXMLVersion() {
102         if (fLocator2 != null) {
103             return fLocator2.getXMLVersion();
104         }
105         return null;
106     }
107     
108 } // SAXLocatorWrapper
109
Popular Tags