19f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/*
29f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one
39f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or more contributor license agreements. See the NOTICE file
49f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed with this work for additional information
59f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * regarding copyright ownership. The ASF licenses this file
69f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to you under the Apache License, Version 2.0 (the  "License");
79f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * you may not use this file except in compliance with the License.
89f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * You may obtain a copy of the License at
99f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *     http://www.apache.org/licenses/LICENSE-2.0
119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Unless required by applicable law or agreed to in writing, software
139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS,
149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * See the License for the specific language governing permissions and
169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * limitations under the License.
179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/*
199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * $Id: SAXSourceLocator.java 468655 2006-10-28 07:12:06Z minchau $
209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpackage org.apache.xml.utils;
229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.io.Serializable;
249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.SourceLocator;
269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.Locator;
289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.SAXParseException;
299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.helpers.LocatorImpl;
309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/**
329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Class SAXSourceLocator extends org.xml.sax.helpers.LocatorImpl
339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * for the purpose of implementing the SourceLocator interface,
349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * and thus can be both a SourceLocator and a SAX Locator.
359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpublic class SAXSourceLocator extends LocatorImpl
379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        implements SourceLocator, Serializable
389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson{
399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    static final long serialVersionUID = 3181680946321164112L;
409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /** The SAX Locator object.
419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *  @serial
429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  Locator m_locator;
449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Constructor SAXSourceLocator
479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public SAXSourceLocator(){}
509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Constructor SAXSourceLocator
539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param locator Source locator
569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public SAXSourceLocator(Locator locator)
589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_locator = locator;
609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    this.setColumnNumber(locator.getColumnNumber());
619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    this.setLineNumber(locator.getLineNumber());
629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    this.setPublicId(locator.getPublicId());
639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    this.setSystemId(locator.getSystemId());
649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Constructor SAXSourceLocator
689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param locator Source locator
719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public SAXSourceLocator(javax.xml.transform.SourceLocator locator)
739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_locator = null;
759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    this.setColumnNumber(locator.getColumnNumber());
769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    this.setLineNumber(locator.getLineNumber());
779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    this.setPublicId(locator.getPublicId());
789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    this.setSystemId(locator.getSystemId());
799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Constructor SAXSourceLocator
849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param spe SAXParseException exception.
879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public SAXSourceLocator(SAXParseException spe)
899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    this.setLineNumber( spe.getLineNumber() );
919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    this.setColumnNumber( spe.getColumnNumber() );
929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    this.setPublicId( spe.getPublicId() );
939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    this.setSystemId( spe.getSystemId() );
949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Return the public identifier for the current document event.
989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>The return value is the public identifier of the document
1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * entity or of the external parsed entity in which the markup
1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * triggering the event appears.</p>
1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return A string containing the public identifier, or
1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *         null if none is available.
1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see #getSystemId
1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public String getPublicId()
1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return (null == m_locator) ? super.getPublicId() : m_locator.getPublicId();
1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Return the system identifier for the current document event.
1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>The return value is the system identifier of the document
1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * entity or of the external parsed entity in which the markup
1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * triggering the event appears.</p>
1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>If the system identifier is a URL, the parser must resolve it
1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * fully before passing it to the application.</p>
1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return A string containing the system identifier, or null
1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *         if none is available.
1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see #getPublicId
1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public String getSystemId()
1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return (null == m_locator) ? super.getSystemId() : m_locator.getSystemId();
1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Return the line number where the current document event ends.
1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p><strong>Warning:</strong> The return value from the method
1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * is intended only as an approximation for the sake of error
1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * reporting; it is not intended to provide sufficient information
1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * to edit the character content of the original XML document.</p>
1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>The return value is an approximation of the line number
1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * in the document entity or external parsed entity where the
1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * markup triggering the event appears.</p>
1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return The line number, or -1 if none is available.
1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see #getColumnNumber
1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public int getLineNumber()
1479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return (null == m_locator) ? super.getLineNumber() : m_locator.getLineNumber();
1499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Return the column number where the current document event ends.
1539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p><strong>Warning:</strong> The return value from the method
1559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * is intended only as an approximation for the sake of error
1569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * reporting; it is not intended to provide sufficient information
1579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * to edit the character content of the original XML document.</p>
1589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>The return value is an approximation of the column number
1609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * in the document entity or external parsed entity where the
1619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * markup triggering the event appears.</p>
1629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return The column number, or -1 if none is available.
1649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see #getLineNumber
1659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public int getColumnNumber()
1679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return (null == m_locator) ? super.getColumnNumber() : m_locator.getColumnNumber();
1699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson}
171