001    /*
002     * Copyright (c) 2007 Henri Sivonen
003     * Copyright (c) 2007-2008 Mozilla Foundation
004     *
005     * Permission is hereby granted, free of charge, to any person obtaining a 
006     * copy of this software and associated documentation files (the "Software"), 
007     * to deal in the Software without restriction, including without limitation 
008     * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
009     * and/or sell copies of the Software, and to permit persons to whom the 
010     * Software is furnished to do so, subject to the following conditions:
011     *
012     * The above copyright notice and this permission notice shall be included in 
013     * all copies or substantial portions of the Software.
014     *
015     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
016     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
017     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
018     * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
019     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
020     * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
021     * DEALINGS IN THE SOFTWARE.
022     */
023    
024    package nu.validator.saxtree;
025    
026    import org.xml.sax.Locator;
027    
028    /**
029     * A locator implementation.
030     * @version $Id$
031     * @author hsivonen
032     */
033    public final class LocatorImpl implements Locator {
034    
035        /**
036         * The system id.
037         */
038        private final String systemId;
039        
040        /**
041         * The public id.
042         */
043        private final String publicId;
044        
045        /**
046         * The column.
047         */
048        private final int column;
049        
050        /**
051         * The line.
052         */
053        private final int line;
054        
055        /**
056         * The constructor.
057         * @param locator the locator
058         */
059        public LocatorImpl(Locator locator) {
060            if (locator == null) {
061                this.systemId = null;
062                this.publicId = null;
063                this.column = -1;
064                this.line = -1;
065            } else {
066                this.systemId = locator.getSystemId();
067                this.publicId = locator.getPublicId();
068                this.column = locator.getColumnNumber();
069                this.line = locator.getLineNumber();
070            }
071        }
072        
073        /**
074         * 
075         * @see org.xml.sax.Locator#getColumnNumber()
076         */
077        public int getColumnNumber() {
078            return column;
079        }
080    
081        /**
082         * 
083         * @see org.xml.sax.Locator#getLineNumber()
084         */
085        public int getLineNumber() {
086            return line;
087        }
088    
089        /**
090         * 
091         * @see org.xml.sax.Locator#getPublicId()
092         */
093        public String getPublicId() {
094            return publicId;
095        }
096    
097        /**
098         * 
099         * @see org.xml.sax.Locator#getSystemId()
100         */
101        public String getSystemId() {
102            return systemId;
103        }
104    }