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 JSEntity {
031:
032: private String id;
033:
034: private JSEntityPreferences entityPreferences = null;
035:
036: public JSEntity() {
037: }
038:
039: public void setId(String id) {
040: this .id = id;
041: }
042:
043: public String getId() {
044: return id;
045: }
046:
047: /**
048: * @param entityPreferences
049: * The entityPreferences to set.
050: */
051: public void setEntityPreferences(
052: JSEntityPreferences entityPreferences) {
053: this .entityPreferences = entityPreferences;
054: }
055:
056: /**
057: * @return Returns the entityPreferences.
058: */
059: public JSEntityPreferences getEntityPreferences() {
060: return entityPreferences;
061: }
062:
063: /***************************************************************************
064: * SERIALIZER
065: */
066: private static final XMLFormat XML = new XMLFormat(JSEntity.class) {
067:
068: public void write(Object o, OutputElement xml)
069: throws XMLStreamException {
070: try {
071: JSEntity g = (JSEntity) o;
072: String s = g.getId();
073: if ((s != null) && (s.length() > 0))
074: xml.setAttribute("id", s);
075: if ((g.entityPreferences != null)
076: && (g.entityPreferences.size() > 0))
077: xml.add(g.entityPreferences);
078:
079: } catch (Exception e) {
080: e.printStackTrace();
081: }
082: }
083:
084: public void read(InputElement xml, Object o) {
085: try {
086: JSEntity g = (JSEntity) o;
087: g.id = StringEscapeUtils.unescapeHtml(xml.getAttribute(
088: "id", "unknown"));
089:
090: Object o1 = null;
091:
092: while (xml.hasNext()) {
093: o1 = xml.getNext(); // mime
094:
095: if (o1 instanceof JSEntityPreferences)
096: g.entityPreferences = (JSEntityPreferences) o1;
097: }
098:
099: } catch (Exception e) {
100: e.printStackTrace();
101: }
102: }
103:
104: };
105:
106: }
|