1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 2005 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 package com.sun.org.apache.xerces.internal.util; 22 23 import org.xml.sax.Locator; 24 import org.xml.sax.ext.Locator2; 25 26 import com.sun.org.apache.xerces.internal.xni.XMLLocator; 27 28 /** 29 * <p>A light wrapper around a SAX locator. This is useful 30 * when bridging between SAX and XNI components.</p> 31 * 32 * @author Michael Glavassevich, IBM 33 * 34 */ 35 public final class SAXLocatorWrapper implements XMLLocator { 36 37 private Locator fLocator = null; 38 private Locator2 fLocator2 = null; 39 40 public SAXLocatorWrapper() {} 41 42 public void setLocator(Locator locator) { 43 fLocator = locator; 44 if (locator instanceof Locator2 || locator == null) { 45 fLocator2 = (Locator2) locator; 46 } 47 } 48 49 public Locator getLocator() { 50 return fLocator; 51 } 52 53 /* 54 * XMLLocator methods 55 */ 56 57 public String getPublicId() { 58 if (fLocator != null) { 59 return fLocator.getPublicId(); 60 } 61 return null; 62 } 63 64 public String getLiteralSystemId() { 65 if (fLocator != null) { 66 return fLocator.getSystemId(); 67 } 68 return null; 69 } 70 71 public String getBaseSystemId() { 72 return null; 73 } 74 75 public String getExpandedSystemId() { 76 return getLiteralSystemId(); 77 } 78 79 public int getLineNumber() { 80 if (fLocator != null) { 81 return fLocator.getLineNumber(); 82 } 83 return -1; 84 } 85 86 public int getColumnNumber() { 87 if (fLocator != null) { 88 return fLocator.getColumnNumber(); 89 } 90 return -1; 91 } 92 93 public int getCharacterOffset() { 94 return -1; 95 } 96 97 public String getEncoding() { 98 if (fLocator2 != null) { 99 return fLocator2.getEncoding(); 100 } 101 return null; 102 } 103 104 public String getXMLVersion() { 105 if (fLocator2 != null) { 106 return fLocator2.getXMLVersion(); 107 } 108 return null; 109 } 110 111 } // SAXLocatorWrapper