001: /* SimpleLocator.java
002:
003: {{IS_NOTE
004:
005: Purpose:
006: Description:
007: History:
008: 2001/10/25 15:34:49, Create, Tom M. Yeh.
009: }}IS_NOTE
010:
011: Copyright (C) 2001 Potix Corporation. All Rights Reserved.
012:
013: {{IS_RIGHT
014: This program is distributed under GPL Version 2.0 in the hope that
015: it will be useful, but WITHOUT ANY WARRANTY.
016: }}IS_RIGHT
017: */
018: package org.zkoss.idom.util;
019:
020: import java.io.Serializable;
021:
022: import org.zkoss.xml.Locator;
023:
024: /**
025: * The locator implementation. Useful to assign the location information
026: * to vertices.
027: *
028: * @author tomyeh
029: * @see org.zkoss.idom.Item
030: */
031: public class SimpleLocator implements Locator, Serializable {
032: private static final long serialVersionUID = 20060622L;
033:
034: protected int _colno, _lnno;
035: protected String _pubId, _sysId;
036:
037: /**
038: * Constructor with another locator.
039: */
040: public SimpleLocator(org.xml.sax.Locator loc) {
041: _colno = loc.getColumnNumber();
042: _lnno = loc.getLineNumber();
043: _pubId = loc.getPublicId();
044: _sysId = loc.getSystemId();
045: }
046:
047: /**
048: * Constructor with another locator.
049: */
050: public SimpleLocator(javax.xml.transform.SourceLocator loc) {
051: _colno = loc.getColumnNumber();
052: _lnno = loc.getLineNumber();
053: _pubId = loc.getPublicId();
054: _sysId = loc.getSystemId();
055: }
056:
057: /**
058: * Constructor.
059: */
060: public SimpleLocator(int colno, int lnno, String pubId, String sysId) {
061: _colno = colno;
062: _lnno = lnno;
063: _pubId = pubId;
064: _sysId = sysId;
065: }
066:
067: //-- Extra utilities --//
068: public static final String toString(org.xml.sax.Locator loc) {
069: if (loc == null)
070: return "";
071:
072: StringBuffer sb = new StringBuffer().append('[');
073: String s = loc.getPublicId();
074: if (s != null && s.length() > 0)
075: sb.append("PUB ").append(s).append(' ');
076: s = loc.getSystemId();
077: if (s != null && s.length() > 0)
078: sb.append("SYS ").append(s).append(' ');
079:
080: sb.append("line ").append(loc.getLineNumber());
081: if (loc.getColumnNumber() > 0) //some parser does not support it
082: sb.append(" col ").append(loc.getColumnNumber());
083: return sb.append(']').toString();
084: }
085:
086: //-- Locator --//
087: public final int getColumnNumber() {
088: return _colno;
089: }
090:
091: public final int getLineNumber() {
092: return _lnno;
093: }
094:
095: public final String getPublicId() {
096: return _pubId;
097: }
098:
099: public final String getSystemId() {
100: return _sysId;
101: }
102:
103: //-- Object --//
104: public final String toString() {
105: return toString(this);
106: }
107: }
|