KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > modules > admin > users > PropertyContainerManipulator


1 /*
2 Copyright (c) 2003 eInnovation Inc. All rights reserved
3
4 This library is free software; you can redistribute it and/or modify it under the terms
5 of the GNU Lesser General Public License as published by the Free Software Foundation;
6 either version 2.1 of the License, or (at your option) any later version.
7
8 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the GNU Lesser General Public License for more details.
11 */

12
13 package com.openedit.modules.admin.users;
14
15 import java.util.Iterator JavaDoc;
16 import java.util.Map JavaDoc;
17
18 import com.openedit.WebPageRequest;
19 import com.openedit.users.UserManagerException;
20
21
22 /**
23  * This class helps commands to manipulate property containers.
24  *
25  * @author Eric Galluzzo
26  */

27 public class PropertyContainerManipulator
28 {
29     /**
30      * Constructor for PropertyContainerHelper.
31      */

32     public PropertyContainerManipulator()
33     {
34         super();
35     }
36
37     /**
38      * DOCUMENT ME!
39      *
40      * @param inParameters
41      * @param inPropertyContainer
42      *
43      * @throws UserManagerException
44      */

45     public void createProperties(Map JavaDoc inParameters, Map JavaDoc inPropertyContainer)
46         throws UserManagerException
47     {
48         // Find all parameters starting with "propertyName", find their
49
// corresponding "propertyValue" parameter, and create the property.
50
for (Iterator JavaDoc iter = inParameters.entrySet().iterator(); iter.hasNext();)
51         {
52             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) iter.next();
53
54             if (entry.getKey().toString().startsWith("propertyName"))
55             {
56                 String JavaDoc propertyName = entry.getValue().toString().trim();
57
58                 // Do not add properties with empty property names.
59
if (propertyName.length() > 0)
60                 {
61                     int propertyIndex = Integer.parseInt(entry.getKey().toString().substring(12));
62                     Object JavaDoc propertyValue = inParameters.get("propertyValue" + propertyIndex);
63
64                     if (propertyValue != null)
65                     {
66                         inPropertyContainer.put(propertyName, propertyValue.toString());
67                     }
68                 }
69             }
70         }
71     }
72
73     /**
74      * DOCUMENT ME!
75      *
76      * @param inParameters
77      * @param inPropertyContainer
78      *
79      * @throws UserManagerException
80      */

81     public void deleteProperties(WebPageRequest inContext, Map JavaDoc inPropertyContainer)
82         throws UserManagerException
83     {
84         String JavaDoc[] propertyNames = inContext.getRequestParameters("deletePropertyNames");
85
86         for (int i = 0; i < propertyNames.length; i++)
87         {
88             inPropertyContainer.remove(propertyNames[i]);
89         }
90         
91     }
92
93     /**
94      * DOCUMENT ME!
95      *
96      * @param inParameters
97      * @param inPropertyContainer
98      *
99      * @throws UserManagerException
100      */

101     public void updateProperties(Map JavaDoc inParameters, Map JavaDoc inPropertyContainer)
102         throws UserManagerException
103     {
104         for (Iterator JavaDoc iter = inParameters.entrySet().iterator(); iter.hasNext();)
105         {
106             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) iter.next();
107
108             if (entry.getKey().toString().startsWith("value-"))
109             {
110                 String JavaDoc propertyName = entry.getKey().toString().substring(6);
111                 String JavaDoc propertyValue = entry.getValue().toString();
112                 if (propertyValue.length() > 0)
113                 {
114                     inPropertyContainer.put(propertyName, propertyValue);
115                 }
116                 else
117                 {
118                     inPropertyContainer.remove(propertyName);
119                 }
120             }
121         }
122     }
123 }
124
Popular Tags