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 java.util.prefs.Preferences;
020:
021: import javolution.xml.XMLFormat;
022: import javolution.xml.stream.XMLStreamException;
023:
024: import org.apache.commons.lang.StringEscapeUtils;
025:
026: /**
027: * Jetspeed Serialized (JS) User
028: *
029: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
030: * @version $Id: $
031: */
032: public class JSEntityPreference {
033:
034: private String principalName;
035:
036: private JSNVPElements preferences = null;
037:
038: public JSEntityPreference() {
039: }
040:
041: public void setName(String principalName) {
042: this .principalName = principalName;
043: }
044:
045: public String getName() {
046: return principalName;
047: }
048:
049: /**
050: * @return Returns the preferences.
051: */
052: public JSNVPElements getPreferences() {
053: return preferences;
054: }
055:
056: /**
057: * @param preferences
058: * The preferences to set.
059: */
060: public void setPreferences(Preferences preferences) {
061: this .preferences = new JSNVPElements(preferences);
062: }
063:
064: /**
065: * @param preferences
066: * The preferences to set.
067: */
068: public void setPreferences(JSNVPElements preferences) {
069: this .preferences = preferences;
070: }
071:
072: /***************************************************************************
073: * SERIALIZER
074: */
075: private static final XMLFormat XML = new XMLFormat(
076: JSEntityPreference.class) {
077:
078: public void write(Object o, OutputElement xml)
079: throws XMLStreamException {
080: try {
081: JSEntityPreference g = (JSEntityPreference) o;
082: String s = g.getName();
083: if ((s == null) || (s.length() == 0))
084: s = "no-principal";
085: xml.setAttribute("name", s);
086: if ((g.preferences != null)
087: && (g.preferences.size() > 0))
088: xml.add(g.preferences);
089:
090: } catch (Exception e) {
091: e.printStackTrace();
092: }
093: }
094:
095: public void read(InputElement xml, Object o) {
096: try {
097: JSEntityPreference g = (JSEntityPreference) o;
098: g.principalName = StringEscapeUtils.unescapeHtml(xml
099: .getAttribute("name", "no-principal"));
100:
101: Object o1 = null;
102:
103: while (xml.hasNext()) {
104: o1 = xml.getNext(); // mime
105:
106: if (o1 instanceof JSNVPElements)
107: g.preferences = (JSNVPElements) o1;
108: }
109:
110: } catch (Exception e) {
111: e.printStackTrace();
112: }
113: }
114:
115: };
116:
117: }
|