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 _MANIFEST_IMPORT_HXX
29 #define _MANIFEST_IMPORT_HXX
30 
31 #include <cppuhelper/implbase1.hxx> // helper for implementations
32 #ifndef _COM_SUN_STAR_XML_SAX_XDUCUMENTHANDLER_HPP_
33 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
34 #endif
35 #include <vector>
36 
37 #include <HashMaps.hxx>
38 
39 namespace com { namespace sun { namespace star {
40 	namespace xml { namespace sax { class XAttributeList; } }
41 	namespace beans { struct PropertyValue; }
42 } } }
43 
44 typedef ::std::hash_map< ::rtl::OUString, ::rtl::OUString, ::rtl::OUStringHash, eqFunc > StringHashMap;
45 
46 struct ManifestScopeEntry
47 {
48     ::rtl::OUString m_aConvertedName;
49     StringHashMap   m_aNamespaces;
50 
51     ManifestScopeEntry( const ::rtl::OUString& aConvertedName, const StringHashMap& aNamespaces )
52     : m_aConvertedName( aConvertedName )
53     , m_aNamespaces( aNamespaces )
54     {}
55 
56     ~ManifestScopeEntry()
57     {}
58 };
59 
60 typedef ::std::vector< ManifestScopeEntry > ManifestStack;
61 
62 class ManifestImport : public cppu::WeakImplHelper1 < com::sun::star::xml::sax::XDocumentHandler >
63 {
64 protected:
65 	com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aSequence;
66 	sal_Int16 		nNumProperty;
67 	ManifestStack aStack;
68 	sal_Bool bIgnoreEncryptData;
69     sal_Int32 nDerivedKeySize;
70 	::std::vector < ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > > & rManVector;
71 
72 	const ::rtl::OUString sFileEntryElement;
73 	const ::rtl::OUString sManifestElement;
74 	const ::rtl::OUString sEncryptionDataElement;
75 	const ::rtl::OUString sAlgorithmElement;
76 	const ::rtl::OUString sStartKeyAlgElement;
77 	const ::rtl::OUString sKeyDerivationElement;
78 
79 	const ::rtl::OUString sCdataAttribute;
80 	const ::rtl::OUString sMediaTypeAttribute;
81 	const ::rtl::OUString sVersionAttribute;
82 	const ::rtl::OUString sFullPathAttribute;
83 	const ::rtl::OUString sSizeAttribute;
84 	const ::rtl::OUString sSaltAttribute;
85 	const ::rtl::OUString sInitialisationVectorAttribute;
86 	const ::rtl::OUString sIterationCountAttribute;
87 	const ::rtl::OUString sKeySizeAttribute;
88 	const ::rtl::OUString sAlgorithmNameAttribute;
89 	const ::rtl::OUString sStartKeyAlgNameAttribute;
90 	const ::rtl::OUString sKeyDerivationNameAttribute;
91 	const ::rtl::OUString sChecksumAttribute;
92 	const ::rtl::OUString sChecksumTypeAttribute;
93 
94 	const ::rtl::OUString sFullPathProperty;
95 	const ::rtl::OUString sMediaTypeProperty;
96 	const ::rtl::OUString sVersionProperty;
97 	const ::rtl::OUString sIterationCountProperty;
98 	const ::rtl::OUString sDerivedKeySizeProperty;
99 	const ::rtl::OUString sSaltProperty;
100 	const ::rtl::OUString sInitialisationVectorProperty;
101 	const ::rtl::OUString sSizeProperty;
102 	const ::rtl::OUString sDigestProperty;
103     const ::rtl::OUString sEncryptionAlgProperty;
104     const ::rtl::OUString sStartKeyAlgProperty;
105     const ::rtl::OUString sDigestAlgProperty;
106 
107 	const ::rtl::OUString sWhiteSpace;
108 
109 	const ::rtl::OUString sSHA256_URL;
110 	const ::rtl::OUString sSHA1_Name;
111 	const ::rtl::OUString sSHA1_URL;
112 
113 	const ::rtl::OUString sSHA256_1k_URL;
114 	const ::rtl::OUString sSHA1_1k_Name;
115 	const ::rtl::OUString sSHA1_1k_URL;
116 
117 	const ::rtl::OUString sBlowfish_Name;
118 	const ::rtl::OUString sBlowfish_URL;
119 	const ::rtl::OUString sAES128_URL;
120 	const ::rtl::OUString sAES192_URL;
121 	const ::rtl::OUString sAES256_URL;
122 
123 	const ::rtl::OUString sPBKDF2_Name;
124 	const ::rtl::OUString sPBKDF2_URL;
125 
126 
127     ::rtl::OUString PushNameAndNamespaces( const ::rtl::OUString& aName,
128                                            const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttribs,
129                                            StringHashMap& o_aConvertedAttribs );
130     ::rtl::OUString ConvertNameWithNamespace( const ::rtl::OUString& aName, const StringHashMap& aNamespaces );
131     ::rtl::OUString ConvertName( const ::rtl::OUString& aName );
132 
133 public:
134 	ManifestImport( std::vector < ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > > & rNewVector );
135 	~ManifestImport( void );
136     virtual void SAL_CALL startDocument(  )
137 		throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
138     virtual void SAL_CALL endDocument(  )
139 		throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
140     virtual void SAL_CALL startElement( const ::rtl::OUString& aName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttribs )
141 		throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
142     virtual void SAL_CALL endElement( const ::rtl::OUString& aName )
143 		throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
144     virtual void SAL_CALL characters( const ::rtl::OUString& aChars )
145 		throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
146     virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& aWhitespaces )
147 		throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
148     virtual void SAL_CALL processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::OUString& aData )
149 		throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
150     virtual void SAL_CALL setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& xLocator )
151 		throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
152 };
153 #endif
154