1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.serializer.objects;
18
19 import javolution.xml.XMLFormat;
20 import javolution.xml.stream.XMLStreamException;
21
22 import org.apache.commons.lang.StringEscapeUtils;
23
24 /***
25 * Jetspeed Serialized (JS) User
26 *
27 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
28 * @version $Id: $
29 */
30 public class JSEntity
31 {
32
33 private String id;
34
35
36 private JSEntityPreferences entityPreferences = null;
37
38
39 public JSEntity()
40 {
41 }
42
43
44 public void setId(String id)
45 {
46 this.id = id;
47 }
48
49
50 public String getId()
51 {
52 return id;
53 }
54
55 /***
56 * @param entityPreferences
57 * The entityPreferences to set.
58 */
59 public void setEntityPreferences(JSEntityPreferences entityPreferences)
60 {
61 this.entityPreferences = entityPreferences;
62 }
63
64 /***
65 * @return Returns the entityPreferences.
66 */
67 public JSEntityPreferences getEntityPreferences()
68 {
69 return entityPreferences;
70 }
71
72 /****************************************************************************
73 * SERIALIZER
74 */
75 private static final XMLFormat XML = new XMLFormat(JSEntity.class)
76 {
77
78 public void write(Object o, OutputElement xml)
79 throws XMLStreamException
80 {
81 try
82 {
83 JSEntity g = (JSEntity) o;
84 String s = g.getId();
85 if ((s != null) && (s.length() > 0))
86 xml.setAttribute("id", s);
87 if ((g.entityPreferences != null) && (g.entityPreferences .size()>0))
88 xml.add(g.entityPreferences);
89
90 } catch (Exception e)
91 {
92 e.printStackTrace();
93 }
94 }
95
96 public void read(InputElement xml, Object o)
97 {
98 try
99 {
100 JSEntity g = (JSEntity) o;
101 g.id = StringEscapeUtils.unescapeHtml(xml.getAttribute("id", "unknown"));
102
103
104 Object o1 = null;
105
106
107 while (xml.hasNext())
108 {
109 o1 = xml.getNext();
110
111 if (o1 instanceof JSEntityPreferences)
112 g.entityPreferences = (JSEntityPreferences) o1;
113 }
114
115
116 } catch (Exception e)
117 {
118 e.printStackTrace();
119 }
120 }
121
122 };
123
124
125 }