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