View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.serializer.objects;
18  
19  import java.util.prefs.Preferences;
20  
21  import javolution.xml.XMLFormat;
22  import javolution.xml.stream.XMLStreamException;
23  
24  import org.apache.commons.lang.StringEscapeUtils;
25  
26  /***
27   * Jetspeed Serialized (JS) User
28   * 
29   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
30   * @version $Id: $
31   */
32  public class JSEntityPreference
33  {
34  
35      private String principalName;
36  
37  
38      private JSNVPElements preferences = null;
39  
40  
41      public JSEntityPreference()
42      {
43      }
44  
45     
46  
47      public void setName(String principalName)
48      {
49          this.principalName = principalName;
50      }
51  
52   
53      public String getName()
54      {
55          return principalName;
56      }
57  
58    
59      /***
60       * @return Returns the preferences.
61       */
62      public JSNVPElements getPreferences()
63      {
64          return preferences;
65      }
66  
67      /***
68       * @param preferences
69       *            The preferences to set.
70       */
71      public void setPreferences(Preferences preferences)
72      {
73          this.preferences = new JSNVPElements(preferences);
74      }
75  
76  
77      /***
78       * @param preferences
79       *            The preferences to set.
80       */
81      public void setPreferences(JSNVPElements preferences)
82      {
83          this.preferences = preferences;
84      }
85  
86  
87      /****************************************************************************
88       * SERIALIZER
89       */
90      private static final XMLFormat XML = new XMLFormat(JSEntityPreference.class)
91      {
92  
93          public void write(Object o, OutputElement xml)
94                  throws XMLStreamException
95          {
96              try
97              {
98                  JSEntityPreference g = (JSEntityPreference) o;
99                  String s = g.getName();
100                 if ((s == null) || (s.length() == 0)) s = "no-principal";
101                 xml.setAttribute("name", s);
102                 if ((g.preferences != null) && (g.preferences.size()>0))
103                 	xml.add(g.preferences);
104 
105             } catch (Exception e)
106             {
107                 e.printStackTrace();
108             }
109         }
110 
111         public void read(InputElement xml, Object o)
112         {
113             try
114             {
115                 JSEntityPreference g = (JSEntityPreference) o;
116                 g.principalName = StringEscapeUtils.unescapeHtml(xml.getAttribute("name", "no-principal"));
117                 
118                 
119                 Object o1 = null;
120  
121 
122 				while (xml.hasNext())
123 				{
124 					o1 = xml.getNext(); // mime
125 					
126 		                        if (o1 instanceof JSNVPElements)
127 		                        	g.preferences  = (JSNVPElements) o1;
128                 }
129                 
130  
131             } catch (Exception e)
132             {
133                 e.printStackTrace();
134             }
135         }
136 
137     };
138 
139 
140 }