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