1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _XSEC_CTL_PARSER_HXX
29 #define _XSEC_CTL_PARSER_HXX
30 
31 #include <xsecctl.hxx>
32 
33 #include <com/sun/star/xml/sax/XParser.hpp>
34 #include <com/sun/star/lang/XInitialization.hpp>
35 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
36 #include <com/sun/star/xml/sax/XAttributeList.hpp>
37 
38 #include <cppuhelper/implbase2.hxx>
39 
40 class XSecParser: public cppu::WeakImplHelper2
41 <
42 	com::sun::star::xml::sax::XDocumentHandler,
43 	com::sun::star::lang::XInitialization
44 >
45 /****** XSecController.hxx/CLASS XSecParser ***********************************
46  *
47  *   NAME
48  *	XSecParser -- a SAX parser that can detect security elements
49  *
50  *   FUNCTION
51  *	The XSecParser object is connected on the SAX chain and detects
52  *	security elements in the SAX event stream, then notifies
53  *	the XSecController.
54  *
55  *   HISTORY
56  *	05.01.2004 -	Interface supported: XDocumentHandler, XInitialization
57  *
58  *   NOTES
59  *	This class is used when importing a document.
60  *
61  *   AUTHOR
62  *	Michael Mi
63  *	Email: michael.mi@sun.com
64  ******************************************************************************/
65 {
66 	friend class XSecController;
67 private:
68 	/*
69 	 * the following members are used to reserve the signature information,
70 	 * including X509IssuerName, X509SerialNumber, and X509Certificate,etc.
71 	 */
72 	rtl::OUString m_ouX509IssuerName;
73 	rtl::OUString m_ouX509SerialNumber;
74 	rtl::OUString m_ouX509Certificate;
75 	rtl::OUString m_ouDigestValue;
76 	rtl::OUString m_ouSignatureValue;
77 	rtl::OUString m_ouDate;
78 	//rtl::OUString m_ouTime;
79 
80 	/*
81 	 * whether inside a particular element
82 	 */
83 	bool m_bInX509IssuerName;
84 	bool m_bInX509SerialNumber;
85 	bool m_bInX509Certificate;
86 	bool m_bInDigestValue;
87 	bool m_bInSignatureValue;
88 	bool m_bInDate;
89 	//bool m_bInTime;
90 
91 	/*
92 	 * the XSecController collaborating with XSecParser
93 	 */
94 	XSecController* m_pXSecController;
95 
96 	/*
97 	 * the next XDocumentHandler on the SAX chain
98 	 */
99 	com::sun::star::uno::Reference<
100 		com::sun::star::xml::sax::XDocumentHandler > m_xNextHandler;
101 
102 	/*
103 	 * this string is used to remember the current handled reference's URI,
104 	 *
105 	 * because it can be decided whether a stream reference is xml based or binary based
106 	 * only after the Transforms element is read in, so we have to reserve the reference's
107 	 * URI when the startElement event is met.
108 	 */
109 	rtl::OUString m_currentReferenceURI;
110 	bool m_bReferenceUnresolved;
111 
112 private:
113 	rtl::OUString getIdAttr(const com::sun::star::uno::Reference<
114 			com::sun::star::xml::sax::XAttributeList >& xAttribs );
115 
116 public:
117 	XSecParser( XSecController* pXSecController,
118 		const com::sun::star::uno::Reference<
119 			com::sun::star::xml::sax::XDocumentHandler >& xNextHandler );
120 	~XSecParser(){};
121 
122 	/*
123 	 * XDocumentHandler
124 	 */
125 	virtual void SAL_CALL startDocument(  )
126 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
127 
128 	virtual void SAL_CALL endDocument(  )
129 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
130 
131 	virtual void SAL_CALL startElement(
132 		const rtl::OUString& aName,
133 		const com::sun::star::uno::Reference<
134 			com::sun::star::xml::sax::XAttributeList >& xAttribs )
135 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
136 
137 	virtual void SAL_CALL endElement( const rtl::OUString& aName )
138 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
139 
140 	virtual void SAL_CALL characters( const rtl::OUString& aChars )
141 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
142 
143 	virtual void SAL_CALL ignorableWhitespace( const rtl::OUString& aWhitespaces )
144 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
145 
146 	virtual void SAL_CALL processingInstruction(
147 		const rtl::OUString& aTarget,
148 		const rtl::OUString& aData )
149 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
150 
151 	virtual void SAL_CALL setDocumentLocator(
152 		const com::sun::star::uno::Reference<
153 			com::sun::star::xml::sax::XLocator >& xLocator )
154 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
155 
156 	/*
157 	 * XInitialization
158 	 */
159 	virtual void SAL_CALL initialize(
160 		const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArguments )
161 		throw(com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
162 };
163 
164 #endif
165 
166