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 JSPortlet
31  {
32  
33      private String name;
34  
35  
36      private JSEntities entities = null;
37  
38  
39      public JSPortlet()
40      {
41      }
42  
43      
44      public void setName(String name)
45      {
46          this.name = name;
47      }
48  
49      
50      public String getName()
51      {
52          return name;
53      }
54  
55          /***
56       * @param entities
57       *            The entities to set.
58       */
59      public void setEntities(JSEntities entities)
60      {
61          this.entities = entities;
62      }
63  
64      /***
65       * @return Returns the entities.
66       */
67      public JSEntities getEntities()
68      {
69          return entities;
70      }
71  
72      /****************************************************************************
73       * SERIALIZER
74       */
75      private static final XMLFormat XML = new XMLFormat(JSPortlet.class)
76      {
77  
78          public void write(Object o, OutputElement xml)
79                  throws XMLStreamException
80          {
81              try
82              {
83                  JSPortlet g = (JSPortlet) o;
84                  String s = g.getName();
85                  if ((s != null) && (s.length() > 0))
86                  	xml.setAttribute("name", s);
87                  xml.add(g.entities);
88  
89              } catch (Exception e)
90              {
91                  e.printStackTrace();
92              }
93          }
94  
95          public void read(InputElement xml, Object o)
96          {
97              try
98              {
99                  JSPortlet g = (JSPortlet) o;
100                 g.name = StringEscapeUtils.unescapeHtml(xml.getAttribute("name", "unknown"));
101                 
102                 
103                 Object o1 = null;
104  
105 
106 				while (xml.hasNext())
107 				{
108 					o1 = xml.getNext(); // mime
109 					
110 	                           if (o1 instanceof JSEntities)
111 	                            g.entities  = (JSEntities) o1;
112 	            }
113                 
114  
115             } catch (Exception e)
116             {
117                 e.printStackTrace();
118             }
119         }
120 
121     };
122 
123 
124 }