update dev300-m58
[ooovba.git] / comphelper / inc / comphelper / docpasswordhelper.hxx
blob90927a3e9c6c512662f2ca6fbaa2f3a22700367a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docpasswordhelper.hxx,v $
10 * $Revision: 1.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef COMPHELPER_DOCPASSWORDHELPR_HXX
32 #define COMPHELPER_DOCPASSWORDHELPR_HXX
34 #include "comphelper/comphelperdllapi.h"
35 #include <vector>
36 #include "comphelper/docpasswordrequest.hxx"
38 namespace com { namespace sun { namespace star { namespace task { class XInteractionHandler; } } } }
40 namespace comphelper {
42 class MediaDescriptor;
44 // ============================================================================
46 enum DocPasswordVerifierResult
48 DocPasswordVerifierResult_OK,
49 DocPasswordVerifierResult_WRONG_PASSWORD,
50 DocPasswordVerifierResult_ABORT
53 // ============================================================================
55 /** Base class for a password verifier used by the DocPasswordHelper class
56 below.
58 Users have to implement the virtual function and pass an instance of the
59 verifier to one of the password request functions.
61 class COMPHELPER_DLLPUBLIC IDocPasswordVerifier
63 public:
64 virtual ~IDocPasswordVerifier();
66 /** Will be called everytime a password needs to be verified.
68 @return The result of the verification.
69 - DocPasswordVerifierResult_OK, if and only if the passed password
70 is valid and can be used to process the related document.
71 - DocPasswordVerifierResult_WRONG_PASSWORD, if the password is
72 wrong. The user may be asked again for a new password.
73 - DocPasswordVerifierResult_ABORT, if an unrecoverable error
74 occured while password verification. The password request loop
75 will be aborted.
77 virtual DocPasswordVerifierResult verifyPassword( const ::rtl::OUString& rPassword ) = 0;
81 // ============================================================================
83 /** Helper that asks for a document password and checks its validity.
85 class COMPHELPER_DLLPUBLIC DocPasswordHelper
87 public:
88 // ------------------------------------------------------------------------
90 /** This helper function tries to request and verify a password to load a
91 protected document.
93 First, the list of default passwords will be tried if provided. This is
94 needed by import filters for external file formats that have to check a
95 predefined password in some cases without asking the user for a
96 password. Every password is checked using the passed password verifier.
98 If not successful, the passed password of a medium is tried, that has
99 been set e.g. by an API call to load a document. If existing, the
100 password is checked using the passed password verifier.
102 If still not successful, the passed interaction handler is used to
103 request a password from the user. This will be repeated until the
104 passed password verifier validates the entered password, or if the user
105 chooses to cancel password input.
107 @param rVerifier
108 The password verifier used to check every processed password.
110 @param rMediaPassword
111 If not empty, will be passed to the password validator before
112 requesting a password from the user. This password usually should
113 be querried from a media descriptor.
115 @param rxInteractHandler
116 The interaction handler that will be used to request a password
117 from the user, e.g. by showing a password input dialog.
119 @param rDocumentName
120 The name of the related document that will be shown in the password
121 input dialog.
123 @param eRequestType
124 The password request type that will be passed to the
125 DocPasswordRequest object created internally. See
126 docpasswordrequest.hxx for more details.
128 @param pDefaultPasswords
129 If not null, contains default passwords that will be tried before a
130 password will be requested from the media descriptor or the user.
132 @param pbIsDefaultPassword
133 (output parameter) If not null, the type of the found password will
134 be returned. True means the password has been found in the passed
135 list of default passwords. False means the password has been taken
136 from the rMediaPassword parameter or has been entered by the user.
138 @return
139 If not empty, contains the password that has been validated by the
140 passed password verifier. If empty, no valid password has been
141 found, or the user has chossen to cancel password input.
143 static ::rtl::OUString requestAndVerifyDocPassword(
144 IDocPasswordVerifier& rVerifier,
145 const ::rtl::OUString& rMediaPassword,
146 const ::com::sun::star::uno::Reference<
147 ::com::sun::star::task::XInteractionHandler >& rxInteractHandler,
148 const ::rtl::OUString& rDocumentName,
149 DocPasswordRequestType eRequestType,
150 const ::std::vector< ::rtl::OUString >* pDefaultPasswords = 0,
151 bool* pbIsDefaultPassword = 0 );
153 // ------------------------------------------------------------------------
155 /** This helper function tries to find a password for the document
156 described by the passed media descriptor.
158 First, the list of default passwords will be tried if provided. This is
159 needed by import filters for external file formats that have to check a
160 predefined password in some cases without asking the user for a
161 password. Every password is checked using the passed password verifier.
163 If not successful, the passed media descriptor is asked for a password,
164 that has been set e.g. by an API call to load a document. If existing,
165 the password is checked using the passed password verifier.
167 If still not successful, the interaction handler contained in the
168 passed nmedia descriptor is used to request a password from the user.
169 This will be repeated until the passed password verifier validates the
170 entered password, or if the user chooses to cancel password input.
172 @param rVerifier
173 The password verifier used to check every processed password.
175 @param rMediaDesc
176 The media descriptor of the document that needs to be opened with
177 a password. If a valid password (that is not contained in the
178 passed list of default passwords) was found, it will be inserted
179 into the "Password" property of this descriptor.
181 @param eRequestType
182 The password request type that will be passed to the
183 DocPasswordRequest object created internally. See
184 docpasswordrequest.hxx for more details.
186 @param pDefaultPasswords
187 If not null, contains default passwords that will be tried before a
188 password will be requested from the media descriptor or the user.
190 @return
191 If not empty, contains the password that has been validated by the
192 passed password verifier. If empty, no valid password has been
193 found, or the user has chossen to cancel password input.
195 static ::rtl::OUString requestAndVerifyDocPassword(
196 IDocPasswordVerifier& rVerifier,
197 MediaDescriptor& rMediaDesc,
198 DocPasswordRequestType eRequestType,
199 const ::std::vector< ::rtl::OUString >* pDefaultPasswords = 0 );
201 // ------------------------------------------------------------------------
203 private:
204 ~DocPasswordHelper();
207 // ============================================================================
209 } // namespace comphelper
211 #endif