001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.serializer.objects;
018:
019: import javolution.xml.XMLFormat;
020: import javolution.xml.stream.XMLStreamException;
021:
022: import org.apache.commons.lang.StringEscapeUtils;
023:
024: /**
025: * Jetspeed Serialized (JS) User
026: *
027: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
028: * @version $Id: $
029: */
030: public class JSApplication {
031:
032: private String name;
033:
034: private String id;
035:
036: private JSPortlets portlets = null;
037:
038: public JSApplication() {
039: }
040:
041: public String getID() {
042: return id;
043: }
044:
045: public void setID(String id) {
046: this .id = id;
047: }
048:
049: public void setName(String name) {
050: this .name = name;
051: }
052:
053: public String getName() {
054: return name;
055: }
056:
057: /***************************************************************************
058: * SERIALIZER
059: */
060: private static final XMLFormat XML = new XMLFormat(
061: JSApplication.class) {
062:
063: public void write(Object o, OutputElement xml)
064: throws XMLStreamException {
065: try {
066: JSApplication g = (JSApplication) o;
067: String s = g.getName();
068: if ((s != null) && (s.length() > 0))
069: xml.setAttribute("name", s);
070:
071: xml.add(g.id, "ID", String.class);
072: xml.add(g.portlets);
073:
074: } catch (Exception e) {
075: e.printStackTrace();
076: }
077: }
078:
079: public void read(InputElement xml, Object o) {
080: try {
081: JSApplication g = (JSApplication) o;
082: g.name = StringEscapeUtils.unescapeHtml(xml
083: .getAttribute("name", "unknown"));
084:
085: Object o1 = xml.get("ID", String.class);
086: if (o1 instanceof String)
087: g.id = StringEscapeUtils.unescapeHtml((String) o1);
088:
089: while (xml.hasNext()) {
090: o1 = xml.getNext(); // mime
091:
092: if (o1 instanceof JSPortlets) {
093: g.portlets = (JSPortlets) o1;
094: }
095: }
096:
097: } catch (Exception e) {
098: e.printStackTrace();
099: }
100: }
101:
102: };
103:
104: public JSPortlets getPortlets() {
105: return portlets;
106: }
107:
108: public void setPortlets(JSPortlets portlets) {
109: this.portlets = portlets;
110: }
111:
112: }
|