001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.util;
019:
020: import org.xml.sax.Locator;
021: import org.xml.sax.ext.Locator2;
022:
023: import org.apache.xerces.xni.XMLLocator;
024:
025: /**
026: * <p>A light wrapper around a SAX locator. This is useful
027: * when bridging between SAX and XNI components.</p>
028: *
029: * @author Michael Glavassevich, IBM
030: *
031: * @version $Id: SAXLocatorWrapper.java 447241 2006-09-18 05:12:57Z mrglavas $
032: */
033: public final class SAXLocatorWrapper implements XMLLocator {
034:
035: private Locator fLocator = null;
036: private Locator2 fLocator2 = null;
037:
038: public SAXLocatorWrapper() {
039: }
040:
041: public void setLocator(Locator locator) {
042: fLocator = locator;
043: if (locator instanceof Locator2 || locator == null) {
044: fLocator2 = (Locator2) locator;
045: }
046: }
047:
048: public Locator getLocator() {
049: return fLocator;
050: }
051:
052: /*
053: * XMLLocator methods
054: */
055:
056: public String getPublicId() {
057: if (fLocator != null) {
058: return fLocator.getPublicId();
059: }
060: return null;
061: }
062:
063: public String getLiteralSystemId() {
064: if (fLocator != null) {
065: return fLocator.getSystemId();
066: }
067: return null;
068: }
069:
070: public String getBaseSystemId() {
071: return null;
072: }
073:
074: public String getExpandedSystemId() {
075: return getLiteralSystemId();
076: }
077:
078: public int getLineNumber() {
079: if (fLocator != null) {
080: return fLocator.getLineNumber();
081: }
082: return -1;
083: }
084:
085: public int getColumnNumber() {
086: if (fLocator != null) {
087: return fLocator.getColumnNumber();
088: }
089: return -1;
090: }
091:
092: public int getCharacterOffset() {
093: return -1;
094: }
095:
096: public String getEncoding() {
097: if (fLocator2 != null) {
098: return fLocator2.getEncoding();
099: }
100: return null;
101: }
102:
103: public String getXMLVersion() {
104: if (fLocator2 != null) {
105: return fLocator2.getXMLVersion();
106: }
107: return null;
108: }
109:
110: } // SAXLocatorWrapper
|