1 | /*
|
---|
2 | * Copyright 1999-2000,2004 The Apache Software Foundation.
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | */
|
---|
16 |
|
---|
17 | /*
|
---|
18 | * $Log: SAX2CountHandlers.cpp,v $
|
---|
19 | * Revision 1.6 2004/09/08 13:55:33 peiyongz
|
---|
20 | * Apache License Version 2.0
|
---|
21 | *
|
---|
22 | * Revision 1.5 2003/05/30 09:36:36 gareth
|
---|
23 | * Use new macros for iostream.h and std:: issues.
|
---|
24 | *
|
---|
25 | * Revision 1.4 2002/02/01 22:38:52 peiyongz
|
---|
26 | * sane_include
|
---|
27 | *
|
---|
28 | * Revision 1.3 2001/08/02 17:10:29 tng
|
---|
29 | * Allow DOMCount/SAXCount/IDOMCount/SAX2Count to take a file that has a list of xml file as input.
|
---|
30 | *
|
---|
31 | * Revision 1.2 2000/08/09 22:40:15 jpolast
|
---|
32 | * updates for changes to sax2 core functionality.
|
---|
33 | *
|
---|
34 | * Revision 1.1 2000/08/08 17:17:20 jpolast
|
---|
35 | * initial checkin of SAX2Count
|
---|
36 | *
|
---|
37 | *
|
---|
38 | */
|
---|
39 |
|
---|
40 | // ---------------------------------------------------------------------------
|
---|
41 | // Includes
|
---|
42 | // ---------------------------------------------------------------------------
|
---|
43 | #include "SAX2Count.hpp"
|
---|
44 | #include <xercesc/sax2/Attributes.hpp>
|
---|
45 | #include <xercesc/sax/SAXParseException.hpp>
|
---|
46 | #include <xercesc/sax/SAXException.hpp>
|
---|
47 |
|
---|
48 |
|
---|
49 |
|
---|
50 | // ---------------------------------------------------------------------------
|
---|
51 | // SAX2CountHandlers: Constructors and Destructor
|
---|
52 | // ---------------------------------------------------------------------------
|
---|
53 | SAX2CountHandlers::SAX2CountHandlers() :
|
---|
54 |
|
---|
55 | fElementCount(0)
|
---|
56 | , fAttrCount(0)
|
---|
57 | , fCharacterCount(0)
|
---|
58 | , fSpaceCount(0)
|
---|
59 | , fSawErrors(false)
|
---|
60 | {
|
---|
61 | }
|
---|
62 |
|
---|
63 | SAX2CountHandlers::~SAX2CountHandlers()
|
---|
64 | {
|
---|
65 | }
|
---|
66 |
|
---|
67 | // ---------------------------------------------------------------------------
|
---|
68 | // SAX2CountHandlers: Implementation of the SAX DocumentHandler interface
|
---|
69 | // ---------------------------------------------------------------------------
|
---|
70 | void SAX2CountHandlers::startElement(const XMLCh* const uri
|
---|
71 | , const XMLCh* const localname
|
---|
72 | , const XMLCh* const qname
|
---|
73 | , const Attributes& attrs)
|
---|
74 | {
|
---|
75 | fElementCount++;
|
---|
76 | fAttrCount += attrs.getLength();
|
---|
77 | }
|
---|
78 |
|
---|
79 | void SAX2CountHandlers::characters( const XMLCh* const chars
|
---|
80 | , const unsigned int length)
|
---|
81 | {
|
---|
82 | fCharacterCount += length;
|
---|
83 | }
|
---|
84 |
|
---|
85 | void SAX2CountHandlers::ignorableWhitespace( const XMLCh* const chars
|
---|
86 | , const unsigned int length)
|
---|
87 | {
|
---|
88 | fSpaceCount += length;
|
---|
89 | }
|
---|
90 |
|
---|
91 | void SAX2CountHandlers::resetDocument()
|
---|
92 | {
|
---|
93 | fAttrCount = 0;
|
---|
94 | fCharacterCount = 0;
|
---|
95 | fElementCount = 0;
|
---|
96 | fSpaceCount = 0;
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 | // ---------------------------------------------------------------------------
|
---|
101 | // SAX2CountHandlers: Overrides of the SAX ErrorHandler interface
|
---|
102 | // ---------------------------------------------------------------------------
|
---|
103 | void SAX2CountHandlers::error(const SAXParseException& e)
|
---|
104 | {
|
---|
105 | fSawErrors = true;
|
---|
106 | XERCES_STD_QUALIFIER cerr << "\nError at file " << StrX(e.getSystemId())
|
---|
107 | << ", line " << e.getLineNumber()
|
---|
108 | << ", char " << e.getColumnNumber()
|
---|
109 | << "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
---|
110 | }
|
---|
111 |
|
---|
112 | void SAX2CountHandlers::fatalError(const SAXParseException& e)
|
---|
113 | {
|
---|
114 | fSawErrors = true;
|
---|
115 | XERCES_STD_QUALIFIER cerr << "\nFatal Error at file " << StrX(e.getSystemId())
|
---|
116 | << ", line " << e.getLineNumber()
|
---|
117 | << ", char " << e.getColumnNumber()
|
---|
118 | << "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
---|
119 | }
|
---|
120 |
|
---|
121 | void SAX2CountHandlers::warning(const SAXParseException& e)
|
---|
122 | {
|
---|
123 | XERCES_STD_QUALIFIER cerr << "\nWarning at file " << StrX(e.getSystemId())
|
---|
124 | << ", line " << e.getLineNumber()
|
---|
125 | << ", char " << e.getColumnNumber()
|
---|
126 | << "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
---|
127 | }
|
---|
128 |
|
---|
129 | void SAX2CountHandlers::resetErrors()
|
---|
130 | {
|
---|
131 | fSawErrors = false;
|
---|
132 | }
|
---|