XMLParser.cxx (9d1279ec) | XMLParser.cxx (1784980f) |
---|---|
1/************************************************************** | 1/************************************************************** |
2 * | 2 * |
3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at | 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at |
10 * | 10 * |
11 * http://www.apache.org/licenses/LICENSE-2.0 | 11 * http://www.apache.org/licenses/LICENSE-2.0 |
12 * | 12 * |
13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. | 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. |
19 * | 19 * |
20 *************************************************************/ 21 22 23 24// MARKER(update_precomp.py): autogen include statement, do not remove 25#include "precompiled_automation.hxx" 26#include <tools/stream.hxx> 27#include "statemnt.hxx" --- 18 unchanged lines hidden (view full) --- 46using namespace com::sun::star::xml::sax; 47using namespace com::sun::star::io; 48using namespace com::sun::star::uno; 49using namespace com::sun::star::util; 50using namespace rtl; 51 52class SVInputStream : public cppu::WeakImplHelper1< XInputStream > 53{ | 20 *************************************************************/ 21 22 23 24// MARKER(update_precomp.py): autogen include statement, do not remove 25#include "precompiled_automation.hxx" 26#include <tools/stream.hxx> 27#include "statemnt.hxx" --- 18 unchanged lines hidden (view full) --- 46using namespace com::sun::star::xml::sax; 47using namespace com::sun::star::io; 48using namespace com::sun::star::uno; 49using namespace com::sun::star::util; 50using namespace rtl; 51 52class SVInputStream : public cppu::WeakImplHelper1< XInputStream > 53{ |
54 SvStream* pStream; | 54 SvStream* pStream; |
55public: | 55public: |
56 SVInputStream( SvStream* pSt ):pStream( pSt ){}; 57 ~SVInputStream(){ delete pStream; pStream=NULL; } | 56 SVInputStream( SvStream* pSt ):pStream( pSt ){}; 57 ~SVInputStream(){ delete pStream; pStream=NULL; } |
58 | 58 |
59 // Methods XInputStream 60 virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 61 virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 62 virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 63 virtual sal_Int32 SAL_CALL available( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 64 virtual void SAL_CALL closeInput( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); | 59 // Methods XInputStream 60 virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 61 virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 62 virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 63 virtual sal_Int32 SAL_CALL available( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 64 virtual void SAL_CALL closeInput( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); |
65}; 66 67 68sal_Int32 SAL_CALL SVInputStream::readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 69{ | 65}; 66 67 68sal_Int32 SAL_CALL SVInputStream::readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 69{ |
70 aData.realloc( nBytesToRead ); 71 sal_Int32 nRead = pStream->Read( aData.getArray(), nBytesToRead ); 72 aData.realloc( nRead ); 73 return nRead; | 70 aData.realloc( nBytesToRead ); 71 sal_Int32 nRead = pStream->Read( aData.getArray(), nBytesToRead ); 72 aData.realloc( nRead ); 73 return nRead; |
74} 75 76sal_Int32 SAL_CALL SVInputStream::readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 77{ | 74} 75 76sal_Int32 SAL_CALL SVInputStream::readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 77{ |
78 return readBytes( aData, nMaxBytesToRead ); | 78 return readBytes( aData, nMaxBytesToRead ); |
79} 80 81void SAL_CALL SVInputStream::skipBytes( sal_Int32 nBytesToSkip ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 82{ | 79} 80 81void SAL_CALL SVInputStream::skipBytes( sal_Int32 nBytesToSkip ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 82{ |
83 if ( nBytesToSkip > 0 ) 84 pStream->SeekRel( nBytesToSkip ); | 83 if ( nBytesToSkip > 0 ) 84 pStream->SeekRel( nBytesToSkip ); |
85} 86 87sal_Int32 SAL_CALL SVInputStream::available( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 88{ | 85} 86 87sal_Int32 SAL_CALL SVInputStream::available( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 88{ |
89 sal_uLong nCurrent = pStream->Tell(); 90 sal_uLong nSize = pStream->Seek( STREAM_SEEK_TO_END ); 91 sal_uLong nAvailable = nSize - nCurrent; 92 pStream->Seek( nCurrent ); 93 return nAvailable; | 89 sal_uLong nCurrent = pStream->Tell(); 90 sal_uLong nSize = pStream->Seek( STREAM_SEEK_TO_END ); 91 sal_uLong nAvailable = nSize - nCurrent; 92 pStream->Seek( nCurrent ); 93 return nAvailable; |
94} 95 96void SAL_CALL SVInputStream::closeInput( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 97{ | 94} 95 96void SAL_CALL SVInputStream::closeInput( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 97{ |
98// pStream->Close(); // automatically done in destructor 99 delete pStream; 100 pStream = NULL; | 98// pStream->Close(); // automatically done in destructor 99 delete pStream; 100 pStream = NULL; |
101} 102 103class Node; 104SV_DECL_REF(Node) 105 106enum NodeType { NODE_CHARACTER = CONST_NodeTypeCharacter, 107 NODE_ELEMENT = CONST_NodeTypeElement, 108 NODE_COMMENT = CONST_NodeTypeComment }; 109 110class Node : public SvRefBase 111{ | 101} 102 103class Node; 104SV_DECL_REF(Node) 105 106enum NodeType { NODE_CHARACTER = CONST_NodeTypeCharacter, 107 NODE_ELEMENT = CONST_NodeTypeElement, 108 NODE_COMMENT = CONST_NodeTypeComment }; 109 110class Node : public SvRefBase 111{ |
112 NodeType aNodeType; 113 Node* pParent; // Use pointer to prevent cyclic references resulting in undeleted objects | 112 NodeType aNodeType; 113 Node* pParent; // Use pointer to prevent cyclic references resulting in undeleted objects |
114 115protected: | 114 115protected: |
116 Node( NodeType aType ): aNodeType( aType ), pParent( NULL ){}; 117 virtual ~Node(); | 116 Node( NodeType aType ): aNodeType( aType ), pParent( NULL ){}; 117 virtual ~Node(); |
118 119public: | 118 119public: |
120 NodeType GetNodeType() { return aNodeType; } 121 void SetParent( NodeRef xNewParent ); 122 NodeRef GetParent(); | 120 NodeType GetNodeType() { return aNodeType; } 121 void SetParent( NodeRef xNewParent ); 122 NodeRef GetParent(); |
123}; 124 125SV_IMPL_REF(Node) 126// generate NodeRefMemberList 127SV_DECL_IMPL_REF_LIST( NodeRef, Node* ) 128 129Node::~Node() 130{ 131} 132 133void Node::SetParent( NodeRef xNewParent ) 134{ | 123}; 124 125SV_IMPL_REF(Node) 126// generate NodeRefMemberList 127SV_DECL_IMPL_REF_LIST( NodeRef, Node* ) 128 129Node::~Node() 130{ 131} 132 133void Node::SetParent( NodeRef xNewParent ) 134{ |
135 pParent = &xNewParent; | 135 pParent = &xNewParent; |
136} 137 138NodeRef Node::GetParent() 139{ | 136} 137 138NodeRef Node::GetParent() 139{ |
140 return NodeRef( pParent ); | 140 return NodeRef( pParent ); |
141} 142 143class CharacterNode : public Node 144{ | 141} 142 143class CharacterNode : public Node 144{ |
145 String aCharacters; | 145 String aCharacters; |
146public: | 146public: |
147 CharacterNode( const String& aChars ): Node( NODE_CHARACTER ), aCharacters( aChars ){}; | 147 CharacterNode( const String& aChars ): Node( NODE_CHARACTER ), aCharacters( aChars ){}; |
148 | 148 |
149 String GetCharacters() { return aCharacters; } | 149 String GetCharacters() { return aCharacters; } |
150}; 151 152class ElementNode : public Node 153{ | 150}; 151 152class ElementNode : public Node 153{ |
154 String aNodeName; 155 Reference < XAttributeList > xAttributeList; 156 NodeRefMemberList aDocumentNodeList; | 154 String aNodeName; 155 Reference < XAttributeList > xAttributeList; 156 NodeRefMemberList aDocumentNodeList; |
157public: | 157public: |
158 ElementNode( const String& aName, Reference < XAttributeList > xAttributes ); 159 void AppendNode( NodeRef xNewNode ); 160 sal_uLong GetChildCount(){ return aDocumentNodeList.Count(); } 161 NodeRef GetChild( sal_uInt16 nIndex ){ return aDocumentNodeList.GetObject( nIndex ); } 162 Reference < XAttributeList > GetAttributes(){ return xAttributeList; } | 158 ElementNode( const String& aName, Reference < XAttributeList > xAttributes ); 159 void AppendNode( NodeRef xNewNode ); 160 sal_uLong GetChildCount(){ return aDocumentNodeList.Count(); } 161 NodeRef GetChild( sal_uInt16 nIndex ){ return aDocumentNodeList.GetObject( nIndex ); } 162 Reference < XAttributeList > GetAttributes(){ return xAttributeList; } |
163 | 163 |
164 String GetNodeName() { return aNodeName; } | 164 String GetNodeName() { return aNodeName; } |
165}; 166 167ElementNode::ElementNode( const String& aName, Reference < XAttributeList > xAttributes ) 168: Node( NODE_ELEMENT ) 169, aNodeName( aName ) 170{ | 165}; 166 167ElementNode::ElementNode( const String& aName, Reference < XAttributeList > xAttributes ) 168: Node( NODE_ELEMENT ) 169, aNodeName( aName ) 170{ |
171 if ( xAttributes.is() ) 172 { 173 Reference < XCloneable > xAttributeCloner( xAttributes, UNO_QUERY ); 174 if ( xAttributeCloner.is() ) 175 xAttributeList = Reference < XAttributeList > ( xAttributeCloner->createClone() , UNO_QUERY ); 176 else 177 { 178 DBG_ERROR("Unable to clone AttributeList"); 179 } 180 } | 171 if ( xAttributes.is() ) 172 { 173 Reference < XCloneable > xAttributeCloner( xAttributes, UNO_QUERY ); 174 if ( xAttributeCloner.is() ) 175 xAttributeList = Reference < XAttributeList > ( xAttributeCloner->createClone() , UNO_QUERY ); 176 else 177 { 178 DBG_ERROR("Unable to clone AttributeList"); 179 } 180 } |
181}; 182 183void ElementNode::AppendNode( NodeRef xNewNode ) 184{ | 181}; 182 183void ElementNode::AppendNode( NodeRef xNewNode ) 184{ |
185 aDocumentNodeList.Insert ( xNewNode, LIST_APPEND ); 186 xNewNode->SetParent( this ); | 185 aDocumentNodeList.Insert ( xNewNode, LIST_APPEND ); 186 xNewNode->SetParent( this ); |
187} 188 | 187} 188 |
189// XIndexAccess | 189// XIndexAccess |
190 191 192 193 194 195enum ParseAction { COLLECT_DATA, COLLECT_DATA_IGNORE_WHITESPACE, PARSE_ONLY }; 196 197class SAXParser : public cppu::WeakImplHelper2< XErrorHandler, XDocumentHandler > 198{ | 190 191 192 193 194 195enum ParseAction { COLLECT_DATA, COLLECT_DATA_IGNORE_WHITESPACE, PARSE_ONLY }; 196 197class SAXParser : public cppu::WeakImplHelper2< XErrorHandler, XDocumentHandler > 198{ |
199 String aFilename; 200 Reference < XParser > xParser; | 199 String aFilename; 200 Reference < XParser > xParser; |
201 | 201 |
202 // XErrorHandler 203 void AddToList( const sal_Char* cuType, const ::com::sun::star::uno::Any& aSAXParseException ); 204 String aErrors; | 202 // XErrorHandler 203 void AddToList( const sal_Char* cuType, const ::com::sun::star::uno::Any& aSAXParseException ); 204 String aErrors; |
205 | 205 |
206 NodeRef xTreeRoot; 207 NodeRef xCurrentNode; 208 sal_uLong nTimestamp; 209 ParseAction aAction; | 206 NodeRef xTreeRoot; 207 NodeRef xCurrentNode; 208 sal_uLong nTimestamp; 209 ParseAction aAction; |
210 211public: | 210 211public: |
212 SAXParser( const String &rFilename ); 213 ~SAXParser(); | 212 SAXParser( const String &rFilename ); 213 ~SAXParser(); |
214 | 214 |
215 // Access Methods 216 NodeRef GetCurrentNode(){ return xCurrentNode; } 217 void SetCurrentNode( NodeRef xCurrent ){ xCurrentNode = xCurrent; } 218 NodeRef GetRootNode(){ return xTreeRoot; } 219 sal_uLong GetTimestamp(){ return nTimestamp; } 220 void Touch(){ nTimestamp = Time::GetSystemTicks(); } | 215 // Access Methods 216 NodeRef GetCurrentNode(){ return xCurrentNode; } 217 void SetCurrentNode( NodeRef xCurrent ){ xCurrentNode = xCurrent; } 218 NodeRef GetRootNode(){ return xTreeRoot; } 219 sal_uLong GetTimestamp(){ return nTimestamp; } 220 void Touch(){ nTimestamp = Time::GetSystemTicks(); } |
221 | 221 |
222 // Methods SAXParser 223 sal_Bool Parse( ParseAction aAct ); 224 String GetErrors(){ return aErrors; } | 222 // Methods SAXParser 223 sal_Bool Parse( ParseAction aAct ); 224 String GetErrors(){ return aErrors; } |
225 | 225 |
226 // Methods XErrorHandler 227 virtual void SAL_CALL error( const ::com::sun::star::uno::Any& aSAXParseException ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); 228 virtual void SAL_CALL fatalError( const ::com::sun::star::uno::Any& aSAXParseException ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); 229 virtual void SAL_CALL warning( const ::com::sun::star::uno::Any& aSAXParseException ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); | 226 // Methods XErrorHandler 227 virtual void SAL_CALL error( const ::com::sun::star::uno::Any& aSAXParseException ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); 228 virtual void SAL_CALL fatalError( const ::com::sun::star::uno::Any& aSAXParseException ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); 229 virtual void SAL_CALL warning( const ::com::sun::star::uno::Any& aSAXParseException ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); |
230 | 230 |
231 // Methods XDocumentHandler 232 virtual void SAL_CALL startDocument( ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); 233 virtual void SAL_CALL endDocument( ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); 234 virtual void SAL_CALL startElement( const ::rtl::OUString& aName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); 235 virtual void SAL_CALL endElement( const ::rtl::OUString& aName ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); 236 virtual void SAL_CALL characters( const ::rtl::OUString& aChars ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); 237 virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& aWhitespaces ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); 238 virtual void SAL_CALL processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::OUString& aData ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); 239 virtual void SAL_CALL setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& xLocator ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); | 231 // Methods XDocumentHandler 232 virtual void SAL_CALL startDocument( ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); 233 virtual void SAL_CALL endDocument( ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); 234 virtual void SAL_CALL startElement( const ::rtl::OUString& aName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); 235 virtual void SAL_CALL endElement( const ::rtl::OUString& aName ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); 236 virtual void SAL_CALL characters( const ::rtl::OUString& aChars ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); 237 virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& aWhitespaces ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); 238 virtual void SAL_CALL processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::OUString& aData ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); 239 virtual void SAL_CALL setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& xLocator ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); |
240}; 241 242 243SAXParser::SAXParser( const String &rFilename ) 244: aFilename( rFilename ) 245{ | 240}; 241 242 243SAXParser::SAXParser( const String &rFilename ) 244: aFilename( rFilename ) 245{ |
246 Touch(); | 246 Touch(); |
247} 248 249SAXParser::~SAXParser() 250{ | 247} 248 249SAXParser::~SAXParser() 250{ |
251 xParser.clear(); | 251 xParser.clear(); |
252} 253 254sal_Bool SAXParser::Parse( ParseAction aAct ) 255{ | 252} 253 254sal_Bool SAXParser::Parse( ParseAction aAct ) 255{ |
256 aAction = aAct; 257 Touch(); 258 SvStream* pStream = new SvFileStream( aFilename, STREAM_STD_READ ); 259 if ( pStream->GetError() ) 260 return sal_False; | 256 aAction = aAct; 257 Touch(); 258 SvStream* pStream = new SvFileStream( aFilename, STREAM_STD_READ ); 259 if ( pStream->GetError() ) 260 return sal_False; |
261 | 261 |
262 InputSource sSource; 263 sSource.aInputStream = new SVInputStream( pStream ); // is refcounted and hence deletet appropriately 264 sSource.sPublicId = OUString( aFilename ); | 262 InputSource sSource; 263 sSource.aInputStream = new SVInputStream( pStream ); // is refcounted and hence deleted appropriately 264 sSource.sPublicId = OUString( aFilename ); |
265 | 265 |
266 xParser = Reference < XParser > ( ::comphelper::getProcessServiceFactory()->createInstance( CUniString("com.sun.star.xml.sax.Parser") ), UNO_QUERY ); 267 if ( xParser.is() ) 268 { 269 xParser->setErrorHandler( ( XErrorHandler*) this ); 270 if ( aAction == COLLECT_DATA || aAction == COLLECT_DATA_IGNORE_WHITESPACE ) 271 xParser->setDocumentHandler( ( XDocumentHandler*) this ); | 266 xParser = Reference < XParser > ( ::comphelper::getProcessServiceFactory()->createInstance( CUniString("com.sun.star.xml.sax.Parser") ), UNO_QUERY ); 267 if ( xParser.is() ) 268 { 269 xParser->setErrorHandler( ( XErrorHandler*) this ); 270 if ( aAction == COLLECT_DATA || aAction == COLLECT_DATA_IGNORE_WHITESPACE ) 271 xParser->setDocumentHandler( ( XDocumentHandler*) this ); |
272 | 272 |
273 try 274 { 275 xParser->parseStream ( sSource ); 276 } 277 catch( class SAXParseException & rPEx) 278 { | 273 try 274 { 275 xParser->parseStream ( sSource ); 276 } 277 catch( class SAXParseException & rPEx) 278 { |
279#ifdef DBG_ERROR | 279#ifdef DBG_ERROR |
280 String aMemo( rPEx.Message ); 281 aMemo = String( aMemo ); | 280 String aMemo( rPEx.Message ); 281 aMemo = String( aMemo ); |
282#endif | 282#endif |
283 } 284 catch( class Exception & rEx) 285 { | 283 } 284 catch( class Exception & rEx) 285 { |
286#ifdef DBG_ERROR | 286#ifdef DBG_ERROR |
287 String aMemo( rEx.Message ); 288 aMemo = String( aMemo ); | 287 String aMemo( rEx.Message ); 288 aMemo = String( aMemo ); |
289#endif | 289#endif |
290 } 291 xParser->setErrorHandler( NULL ); // otherwile Object holds itself 292 if ( aAction == COLLECT_DATA || aAction == COLLECT_DATA_IGNORE_WHITESPACE ) 293 xParser->setDocumentHandler( NULL ); // otherwile Object holds itself 294 } 295 else 296 return sal_False; 297 return sal_True; | 290 } 291 xParser->setErrorHandler( NULL ); // otherwise Object holds itself 292 if ( aAction == COLLECT_DATA || aAction == COLLECT_DATA_IGNORE_WHITESPACE ) 293 xParser->setDocumentHandler( NULL ); // otherwise Object holds itself 294 } 295 else 296 return sal_False; 297 return sal_True; |
298} 299 300 301// Helper Methods XErrorHandler 302void SAXParser::AddToList( const sal_Char* cuType, const ::com::sun::star::uno::Any& aSAXParseException ) 303{ | 298} 299 300 301// Helper Methods XErrorHandler 302void SAXParser::AddToList( const sal_Char* cuType, const ::com::sun::star::uno::Any& aSAXParseException ) 303{ |
304 SAXParseException aException; 305 aSAXParseException >>= aException; | 304 SAXParseException aException; 305 aSAXParseException >>= aException; |
306 | 306 |
307 aErrors.Append( String( aException.PublicId ) ); 308 aErrors.AppendAscii( "(" ); 309 aErrors.Append( String::CreateFromInt64( aException.LineNumber ) ); 310 aErrors.AppendAscii( ":" ); 311 aErrors.Append( String::CreateFromInt64( aException.ColumnNumber ) ); 312 aErrors.AppendAscii( ") : " ); 313 aErrors.AppendAscii( cuType ); 314 aErrors.AppendAscii( ": " ); 315 aErrors.Append( String( aException.Message ) ); 316 aErrors.AppendAscii( "\n" ); | 307 aErrors.Append( String( aException.PublicId ) ); 308 aErrors.AppendAscii( "(" ); 309 aErrors.Append( String::CreateFromInt64( aException.LineNumber ) ); 310 aErrors.AppendAscii( ":" ); 311 aErrors.Append( String::CreateFromInt64( aException.ColumnNumber ) ); 312 aErrors.AppendAscii( ") : " ); 313 aErrors.AppendAscii( cuType ); 314 aErrors.AppendAscii( ": " ); 315 aErrors.Append( String( aException.Message ) ); 316 aErrors.AppendAscii( "\n" ); |
317} 318 319// Methods XErrorHandler 320void SAL_CALL SAXParser::error( const ::com::sun::star::uno::Any& aSAXParseException ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 321{ | 317} 318 319// Methods XErrorHandler 320void SAL_CALL SAXParser::error( const ::com::sun::star::uno::Any& aSAXParseException ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 321{ |
322 AddToList( "error", aSAXParseException ); | 322 AddToList( "error", aSAXParseException ); |
323} 324 325void SAL_CALL SAXParser::fatalError( const ::com::sun::star::uno::Any& aSAXParseException ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 326{ | 323} 324 325void SAL_CALL SAXParser::fatalError( const ::com::sun::star::uno::Any& aSAXParseException ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 326{ |
327 AddToList( "fatal error", aSAXParseException ); | 327 AddToList( "fatal error", aSAXParseException ); |
328} 329 330void SAL_CALL SAXParser::warning( const ::com::sun::star::uno::Any& aSAXParseException ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 331{ | 328} 329 330void SAL_CALL SAXParser::warning( const ::com::sun::star::uno::Any& aSAXParseException ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 331{ |
332 AddToList( "warning", aSAXParseException ); | 332 AddToList( "warning", aSAXParseException ); |
333} 334 335 336// Methods XDocumentHandler 337void SAXParser::startDocument( ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 338{ | 333} 334 335 336// Methods XDocumentHandler 337void SAXParser::startDocument( ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 338{ |
339 xTreeRoot = new ElementNode( CUniString("/"), Reference < XAttributeList > (NULL) ); 340 xCurrentNode = xTreeRoot; 341 Touch(); | 339 xTreeRoot = new ElementNode( CUniString("/"), Reference < XAttributeList > (NULL) ); 340 xCurrentNode = xTreeRoot; 341 Touch(); |
342} 343 344void SAXParser::endDocument( ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 345{ 346} 347 348void SAXParser::startElement( const ::rtl::OUString& aName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 349{ | 342} 343 344void SAXParser::endDocument( ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 345{ 346} 347 348void SAXParser::startElement( const ::rtl::OUString& aName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 349{ |
350 NodeRef xNewNode = new ElementNode ( String(aName), xAttribs ); 351 ((ElementNode*)(&xCurrentNode))->AppendNode( xNewNode ); 352 xCurrentNode = xNewNode; | 350 NodeRef xNewNode = new ElementNode ( String(aName), xAttribs ); 351 ((ElementNode*)(&xCurrentNode))->AppendNode( xNewNode ); 352 xCurrentNode = xNewNode; |
353} 354 355void SAXParser::endElement( const ::rtl::OUString& aName ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 356{ | 353} 354 355void SAXParser::endElement( const ::rtl::OUString& aName ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 356{ |
357 (void) aName; /* avoid warning about unused parameter */ 358 xCurrentNode = xCurrentNode->GetParent(); | 357 (void) aName; /* avoid warning about unused parameter */ 358 xCurrentNode = xCurrentNode->GetParent(); |
359} 360 361void SAXParser::characters( const ::rtl::OUString& aChars ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 362{ | 359} 360 361void SAXParser::characters( const ::rtl::OUString& aChars ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 362{ |
363 if ( aAction == COLLECT_DATA_IGNORE_WHITESPACE ) 364 { // check for whitespace 365 sal_Bool bAllWhitespace = sal_True; 366 for ( int i = 0 ; bAllWhitespace && i < aChars.getLength() ; i++ ) | 363 if ( aAction == COLLECT_DATA_IGNORE_WHITESPACE ) 364 { // check for whitespace 365 sal_Bool bAllWhitespace = sal_True; 366 for ( int i = 0 ; bAllWhitespace && i < aChars.getLength() ; i++ ) |
367 if ( aChars[i] != 10 // LF 368 && aChars[i] != 13 // CR 369 && aChars[i] != ' ' // Blank 370 && aChars[i] != '\t' ) // Tab 371 bAllWhitespace = sal_False; 372 if ( bAllWhitespace ) 373 return; | 367 if ( aChars[i] != 10 // LF 368 && aChars[i] != 13 // CR 369 && aChars[i] != ' ' // Blank 370 && aChars[i] != '\t' ) // Tab 371 bAllWhitespace = sal_False; 372 if ( bAllWhitespace ) 373 return; |
374 } 375 NodeRef xNewNode = new CharacterNode ( String(aChars) ); 376 ((ElementNode*)(&xCurrentNode))->AppendNode( xNewNode ); | 374 } 375 NodeRef xNewNode = new CharacterNode ( String(aChars) ); 376 ((ElementNode*)(&xCurrentNode))->AppendNode( xNewNode ); |
377} 378 379void SAXParser::ignorableWhitespace( const ::rtl::OUString& aWhitespaces ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 380{ | 377} 378 379void SAXParser::ignorableWhitespace( const ::rtl::OUString& aWhitespaces ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 380{ |
381 (void) aWhitespaces; /* avoid warning about unused parameter */ | 381 (void) aWhitespaces; /* avoid warning about unused parameter */ |
382} 383 384void SAXParser::processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::OUString& aData ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 385{ | 382} 383 384void SAXParser::processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::OUString& aData ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 385{ |
386 (void) aTarget; /* avoid warning about unused parameter */ 387 (void) aData; /* avoid warning about unused parameter */ | 386 (void) aTarget; /* avoid warning about unused parameter */ 387 (void) aData; /* avoid warning about unused parameter */ |
388} 389 390void SAXParser::setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& xLocator ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 391{ | 388} 389 390void SAXParser::setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& xLocator ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) 391{ |
392 (void) xLocator; /* avoid warning about unused parameter */ | 392 (void) xLocator; /* avoid warning about unused parameter */ |
393#if OSL_DEBUG_LEVEL > 1 | 393#if OSL_DEBUG_LEVEL > 1 |
394 ::rtl::OUString aTester; 395 aTester = xLocator->getPublicId(); 396 aTester = xLocator->getSystemId(); | 394 ::rtl::OUString aTester; 395 aTester = xLocator->getPublicId(); 396 aTester = xLocator->getSystemId(); |
397#endif 398} 399 400 401 402 403void StatementCommand::HandleSAXParser() 404{ | 397#endif 398} 399 400 401 402 403void StatementCommand::HandleSAXParser() 404{ |
405 static Reference < XReference > xParserKeepaliveReference; // this is to keep the Object alive only 406 static SAXParser* pSAXParser; | 405 static Reference < XReference > xParserKeepaliveReference; // this is to keep the Object alive only 406 static SAXParser* pSAXParser; |
407 | 407 |
408 // We need spechial prerequisites for these! | 408 // We need special prerequisites for these! |
409 | 409 |
410 ElementNode* pElementNode = NULL; | 410 ElementNode* pElementNode = NULL; |
411 switch ( nMethodId ) 412 { | 411 switch ( nMethodId ) 412 { |
413 case RC_SAXGetNodeType: | 413 case RC_SAXGetNodeType: |
414 case RC_SAXGetAttributeCount: 415 case RC_SAXGetAttributeName: 416 case RC_SAXGetAttributeValue: 417 case RC_SAXGetChildCount: 418 case RC_SAXGetElementName: 419 case RC_SAXGetChars: 420 | 414 case RC_SAXGetAttributeCount: 415 case RC_SAXGetAttributeName: 416 case RC_SAXGetAttributeValue: 417 case RC_SAXGetChildCount: 418 case RC_SAXGetElementName: 419 case RC_SAXGetChars: 420 |
421 case RC_SAXSeekElement: | 421 case RC_SAXSeekElement: |
422 case RC_SAXHasElement: 423 case RC_SAXGetElementPath: 424 { 425 if ( xParserKeepaliveReference.is() && pSAXParser->GetCurrentNode().Is() ) 426 { 427 if ( pSAXParser->GetCurrentNode()->GetNodeType() == NODE_ELEMENT ) 428 { 429 NodeRef xNode=pSAXParser->GetCurrentNode(); --- 251 unchanged lines hidden (view full) --- 681 682 case RC_SAXRelease: 683 { 684 xParserKeepaliveReference.clear(); 685 } 686 break; 687 default: 688 ReportError( GEN_RES_STR1( S_INTERNAL_ERROR, RcString( nMethodId ) ) ); | 422 case RC_SAXHasElement: 423 case RC_SAXGetElementPath: 424 { 425 if ( xParserKeepaliveReference.is() && pSAXParser->GetCurrentNode().Is() ) 426 { 427 if ( pSAXParser->GetCurrentNode()->GetNodeType() == NODE_ELEMENT ) 428 { 429 NodeRef xNode=pSAXParser->GetCurrentNode(); --- 251 unchanged lines hidden (view full) --- 681 682 case RC_SAXRelease: 683 { 684 xParserKeepaliveReference.clear(); 685 } 686 break; 687 default: 688 ReportError( GEN_RES_STR1( S_INTERNAL_ERROR, RcString( nMethodId ) ) ); |
689 } | 689 } |
690} 691 | 690} 691 |
692/* vim: set noet sw=4 ts=4: */ |
|