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 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(); // mime
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 }