1 /**************************************************************
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
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
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.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _XSEC_CTL_PARSER_HXX
25 #define _XSEC_CTL_PARSER_HXX
26 
27 #include <xsecctl.hxx>
28 
29 #include <com/sun/star/xml/sax/XParser.hpp>
30 #include <com/sun/star/lang/XInitialization.hpp>
31 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
32 #include <com/sun/star/xml/sax/XAttributeList.hpp>
33 
34 #include <cppuhelper/implbase2.hxx>
35 
36 class XSecParser: public cppu::WeakImplHelper2
37 <
38 	com::sun::star::xml::sax::XDocumentHandler,
39 	com::sun::star::lang::XInitialization
40 >
41 /****** XSecController.hxx/CLASS XSecParser ***********************************
42  *
43  *   NAME
44  *	XSecParser -- a SAX parser that can detect security elements
45  *
46  *   FUNCTION
47  *	The XSecParser object is connected on the SAX chain and detects
48  *	security elements in the SAX event stream, then notifies
49  *	the XSecController.
50  *
51  *   HISTORY
52  *	05.01.2004 -	Interface supported: XDocumentHandler, XInitialization
53  *
54  *   NOTES
55  *	This class is used when importing a document.
56  *
57  *   AUTHOR
58  *	Michael Mi
59  *	Email: michael.mi@sun.com
60  ******************************************************************************/
61 {
62 	friend class XSecController;
63 private:
64 	/*
65 	 * the following members are used to reserve the signature information,
66 	 * including X509IssuerName, X509SerialNumber, and X509Certificate,etc.
67 	 */
68 	rtl::OUString m_ouX509IssuerName;
69 	rtl::OUString m_ouX509SerialNumber;
70 	rtl::OUString m_ouX509Certificate;
71 	rtl::OUString m_ouDigestValue;
72 	rtl::OUString m_ouSignatureValue;
73 	rtl::OUString m_ouDate;
74 	//rtl::OUString m_ouTime;
75 
76 	/*
77 	 * whether inside a particular element
78 	 */
79 	bool m_bInX509IssuerName;
80 	bool m_bInX509SerialNumber;
81 	bool m_bInX509Certificate;
82 	bool m_bInDigestValue;
83 	bool m_bInSignatureValue;
84 	bool m_bInDate;
85 	//bool m_bInTime;
86 
87 	/*
88 	 * the XSecController collaborating with XSecParser
89 	 */
90 	XSecController* m_pXSecController;
91 
92 	/*
93 	 * the next XDocumentHandler on the SAX chain
94 	 */
95 	com::sun::star::uno::Reference<
96 		com::sun::star::xml::sax::XDocumentHandler > m_xNextHandler;
97 
98 	/*
99 	 * this string is used to remember the current handled reference's URI,
100 	 *
101 	 * because it can be decided whether a stream reference is xml based or binary based
102 	 * only after the Transforms element is read in, so we have to reserve the reference's
103 	 * URI when the startElement event is met.
104 	 */
105 	rtl::OUString m_currentReferenceURI;
106 	bool m_bReferenceUnresolved;
107 
108 private:
109 	rtl::OUString getIdAttr(const com::sun::star::uno::Reference<
110 			com::sun::star::xml::sax::XAttributeList >& xAttribs );
111 
112 public:
113 	XSecParser( XSecController* pXSecController,
114 		const com::sun::star::uno::Reference<
115 			com::sun::star::xml::sax::XDocumentHandler >& xNextHandler );
~XSecParser()116 	~XSecParser(){};
117 
118 	/*
119 	 * XDocumentHandler
120 	 */
121 	virtual void SAL_CALL startDocument(  )
122 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
123 
124 	virtual void SAL_CALL endDocument(  )
125 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
126 
127 	virtual void SAL_CALL startElement(
128 		const rtl::OUString& aName,
129 		const com::sun::star::uno::Reference<
130 			com::sun::star::xml::sax::XAttributeList >& xAttribs )
131 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
132 
133 	virtual void SAL_CALL endElement( const rtl::OUString& aName )
134 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
135 
136 	virtual void SAL_CALL characters( const rtl::OUString& aChars )
137 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
138 
139 	virtual void SAL_CALL ignorableWhitespace( const rtl::OUString& aWhitespaces )
140 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
141 
142 	virtual void SAL_CALL processingInstruction(
143 		const rtl::OUString& aTarget,
144 		const rtl::OUString& aData )
145 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
146 
147 	virtual void SAL_CALL setDocumentLocator(
148 		const com::sun::star::uno::Reference<
149 			com::sun::star::xml::sax::XLocator >& xLocator )
150 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
151 
152 	/*
153 	 * XInitialization
154 	 */
155 	virtual void SAL_CALL initialize(
156 		const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArguments )
157 		throw(com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
158 };
159 
160 #endif
161 
162