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  
18  package org.apache.jetspeed.serializer.objects;
19  
20  import javolution.xml.XMLFormat;
21  import javolution.xml.stream.XMLStreamException;
22  
23  import org.apache.commons.lang.StringEscapeUtils;
24  
25  public class JSNVPElement
26  {
27  
28  	
29      private String key;
30      private String value;
31      public JSNVPElement() {};
32      public JSNVPElement(String key, String value)
33      {
34      	this.key = key;
35      	this.value = value;
36      }
37  
38           private static final XMLFormat XML = new XMLFormat(JSNVPElement.class)
39          {
40              public boolean isReferencable() {
41                  return false; // Always manipulates by value.
42              }
43              public void write(Object o, OutputElement xml)
44              throws XMLStreamException
45              {
46                  // xml.add((String) g.get(_key), _key, String.class);
47              	xml.add(((JSNVPElement)o).key,"name",String.class);
48              	xml.add(((JSNVPElement)o).value,"value",String.class);
49              }
50              public void read(InputElement xml, Object o)
51              {
52                  try
53                  {
54                      JSNVPElement g = (JSNVPElement) o;
55                      g.key = StringEscapeUtils.unescapeHtml((String)xml.get("name", String.class));
56                      g.value = StringEscapeUtils.unescapeHtml((String)xml.get("value", String.class));
57                  } catch (Exception e)
58                  {
59                      e.printStackTrace();
60                  }
61              }
62          };
63  		public String getKey()
64  		{
65  			return key;
66  		}
67  		public void setKey(String key)
68  		{
69  			this.key = key;
70  		}
71  		public String getValue()
72  		{
73  			return value;
74  		}
75  		public void setValue(String value)
76  		{
77  			this.value = value;
78  		}
79      }
80      
81