KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pdfbox > pdmodel > encryption > StandardProtectionPolicy


1 /**
2  * Copyright (c) 2003-2006, www.pdfbox.org
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. Neither the name of pdfbox; nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * http://www.pdfbox.org
29  *
30  */

31 package org.pdfbox.pdmodel.encryption;
32
33 /**
34  * This class represents the protection policy to add to a document
35  * for password-based protection.
36  *
37  * The following example shows how to protect a PDF document with password.
38  * In this example, the document will be protected so that someone opening
39  * the document with the user password <code>user_pwd</code> will not be
40  * able to modify the document.
41  *
42  * <pre>
43  * AccessPermission ap = new AccessPermission();
44  * ap.setCanModify(false);
45  * StandardProtectionPolicy policy = new StandardProtectionPolicy(owner_pwd, user_pwd, ap);
46  * doc.protect(policy);
47  * </pre>
48  *
49  * @author Benoit Guillon (benoit.guillon@snv.jussieu.fr)
50  * @version $Revision: 1.3 $
51  */

52 public class StandardProtectionPolicy extends ProtectionPolicy
53 {
54     
55     private AccessPermission permissions;
56     
57     private String JavaDoc ownerPassword = "";
58     
59     private String JavaDoc userPassword = "";
60     
61     
62     /**
63      * Creates an new instance of the standard protection policy
64      * in order to protect a PDF document with passwords.
65      *
66      * @param ownerPass The owner's password.
67      * @param userPass The users's password.
68      * @param perms The access permissions given to the user.
69      */

70     public StandardProtectionPolicy(String JavaDoc ownerPass, String JavaDoc userPass, AccessPermission perms)
71     {
72         this.permissions = perms;
73         this.userPassword = userPass;
74         this.ownerPassword = ownerPass;
75     }
76     
77     /**
78      * Getter of the property <tt>permissions</tt>.
79      *
80      * @return Returns the permissions.
81      */

82     public AccessPermission getPermissions()
83     {
84         return permissions;
85     }
86     
87     /**
88      * Setter of the property <tt>permissions</tt>.
89      *
90      * @param perms The permissions to set.
91      */

92     public void setPermissions(AccessPermission perms)
93     {
94         this.permissions = perms;
95     }
96     
97     /**
98      * Getter of the property <tt>ownerPassword</tt>.
99      *
100      * @return Returns the ownerPassword.
101      */

102     public String JavaDoc getOwnerPassword()
103     {
104         return ownerPassword;
105     }
106     
107     /**
108      * Setter of the property <tt>ownerPassword</tt>.
109      *
110      * @param ownerPass The ownerPassword to set.
111      */

112     public void setOwnerPassword(String JavaDoc ownerPass)
113     {
114         this.ownerPassword = ownerPass;
115     }
116     
117     /**
118      * Getter of the property <tt>userPassword</tt>.
119      *
120      * @return Returns the userPassword.
121      */

122     public String JavaDoc getUserPassword()
123     {
124         return userPassword;
125     }
126     
127     /**
128      * Setter of the property <tt>userPassword</tt>.
129      *
130      * @param userPass The userPassword to set.
131      */

132     public void setUserPassword(String JavaDoc userPass)
133     {
134         this.userPassword = userPass;
135     }
136 }
Popular Tags