01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: private String key;
28: private String value;
29:
30: public JSNVPElement() {
31: };
32:
33: public JSNVPElement(String key, String value) {
34: this .key = key;
35: this .value = value;
36: }
37:
38: private static final XMLFormat XML = new XMLFormat(
39: JSNVPElement.class) {
40: public boolean isReferencable() {
41: return false; // Always manipulates by value.
42: }
43:
44: public void write(Object o, OutputElement xml)
45: throws XMLStreamException {
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:
51: public void read(InputElement xml, Object o) {
52: try {
53: JSNVPElement g = (JSNVPElement) o;
54: g.key = StringEscapeUtils.unescapeHtml((String) xml
55: .get("name", String.class));
56: g.value = StringEscapeUtils.unescapeHtml((String) xml
57: .get("value", String.class));
58: } catch (Exception e) {
59: e.printStackTrace();
60: }
61: }
62: };
63:
64: public String getKey() {
65: return key;
66: }
67:
68: public void setKey(String key) {
69: this .key = key;
70: }
71:
72: public String getValue() {
73: return value;
74: }
75:
76: public void setValue(String value) {
77: this.value = value;
78: }
79: }
|