01: package org.objectweb.celtix.tools.utils;
02:
03: import org.w3c.dom.Element;
04:
05: import org.xml.sax.SAXNotRecognizedException;
06: import org.xml.sax.SAXNotSupportedException;
07:
08: import com.sun.org.apache.xerces.internal.parsers.DOMParser;
09: import com.sun.org.apache.xerces.internal.util.SymbolTable;
10: import com.sun.org.apache.xerces.internal.xni.Augmentations;
11: import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
12: import com.sun.org.apache.xerces.internal.xni.QName;
13: import com.sun.org.apache.xerces.internal.xni.XMLAttributes;
14: import com.sun.org.apache.xerces.internal.xni.XMLLocator;
15: import com.sun.org.apache.xerces.internal.xni.XNIException;
16: import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
17: import com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration;
18:
19: import org.objectweb.celtix.tools.common.ToolException;
20: import org.objectweb.celtix.tools.common.WSDLConstants;
21:
22: public class LineNumDOMParser extends DOMParser {
23: private XMLLocator locator;
24:
25: public LineNumDOMParser() throws SAXNotSupportedException,
26: SAXNotRecognizedException {
27: super ();
28:
29: setFeature(DEFER_NODE_EXPANSION, false);
30:
31: }
32:
33: public LineNumDOMParser(XMLParserConfiguration arg0)
34: throws ToolException {
35: super (arg0);
36: try {
37: setFeature(DEFER_NODE_EXPANSION, false);
38: } catch (SAXNotSupportedException e) {
39: throw new ToolException(e);
40: } catch (SAXNotRecognizedException e) {
41: throw new ToolException(e);
42: }
43: }
44:
45: public LineNumDOMParser(SymbolTable st) {
46: super (st);
47: }
48:
49: public LineNumDOMParser(SymbolTable st, XMLGrammarPool xp) {
50: super (st, xp);
51: }
52:
53: public void startElement(QName qn, XMLAttributes xmlAtr,
54: Augmentations aug) throws XNIException {
55: Element element;
56: /*
57: * String ns = qn.uri; if (ns != null &&
58: * (ns.equals(Constants.NS_URI_XSD_2001) ||
59: * ns.equals(Constants.NS_URI_XSD_1999) || ns
60: * .equals(Constants.NS_URI_XSD_2000))) { int numatts =
61: * xmlAtr.getLength(); System.out.println("---arg1--- " + xmlAtr); for
62: * (int i = 0; i < numatts; i++) { String nonNormalizedValue =
63: * xmlAtr.getNonNormalizedValue(i);
64: * System.out.println("---nonNormalizedValue--- " + nonNormalizedValue);
65: * xmlAtr.setValue(i, nonNormalizedValue); } }
66: */
67: super .startElement(qn, xmlAtr, aug);
68: try {
69: element = (Element) getProperty(CURRENT_ELEMENT_NODE);
70: element.setUserData(WSDLConstants.NODE_LOCATION,
71: new ElementLocator(locator.getLineNumber(), locator
72: .getColumnNumber()), null);
73:
74: } catch (ClassCastException e) {
75: // System.out.println(e);
76: } catch (SAXNotRecognizedException e) {
77: // System.out.println(e);
78: } catch (SAXNotSupportedException e) {
79: // System.out.println(e);
80: }
81:
82: }
83:
84: public void startDocument(XMLLocator xmlLoc, String str,
85: NamespaceContext nsCxt, Augmentations aug)
86: throws XNIException {
87: locator = xmlLoc;
88: super.startDocument(xmlLoc, str, nsCxt, aug);
89:
90: }
91:
92: }
|