001: /*
002: * Copyright 2002 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */
013: package com.sun.portal.portletcontainercommon.descriptor;
014:
015: import java.util.List;
016: import java.util.ArrayList;
017: import java.util.Iterator;
018: import java.util.Map;
019: import java.util.HashMap;
020: import java.util.Locale;
021: import java.util.logging.Logger;
022:
023: import org.jdom.Element;
024: import org.jdom.Namespace;
025: import org.jdom.Attribute;
026:
027: public class UserAttributeDescriptor {
028: // Portlet Descriptor Element Names
029: public static final String NAME = "name";
030:
031: // Global variable
032: private String _name;
033: private List _descriptions = new ArrayList();
034: private Map _descriptionMap = new HashMap();
035:
036: public UserAttributeDescriptor(Logger logger) {
037: }
038:
039: public void load(Element element, Namespace namespace) {
040: _name = element.getChildTextTrim(NAME, namespace);
041:
042: List descriptionElements = element.getChildren(
043: PortletAppDescriptor.DESCRIPTION, namespace);
044: for (Iterator i = descriptionElements.iterator(); i.hasNext();) {
045: Element descriptionElement = (Element) i.next();
046: _descriptions.add(descriptionElement.getTextTrim());
047:
048: List descList = descriptionElement.getAttributes();
049: int j = descList
050: .indexOf(PortletAppDescriptor.XML_LANG_ATTR);
051: if (j == -1) {
052: String lang = Locale.getDefault().toString().replace(
053: '_', '-');
054: _descriptionMap.put(lang, descriptionElement
055: .getTextTrim());
056: } else {
057: Attribute dAttr = (Attribute) descList.get(j);
058: _descriptionMap.put(dAttr.getValue(),
059: descriptionElement.getTextTrim());
060: }
061: }
062: }
063:
064: public String getName() {
065: return _name;
066: }
067:
068: public String getDescription() {
069: String description = null;
070: if (!_descriptions.isEmpty()) {
071: description = (String) _descriptions.get(0);
072: }
073: return description;
074: }
075:
076: public List getDescriptions() {
077: return _descriptions;
078: }
079:
080: /**
081: * Returns descriptions in a Map.
082: * <P>
083: * @return <code>Map</code> of lang/description pairs of the
084: * descriptions. Empty <code>Map</code> will be returned
085: * if not defined.
086: */
087: public Map getDescriptionMap() {
088: return _descriptionMap;
089: }
090:
091: public String toString() {
092: StringBuffer sb = new StringBuffer("UserAttributeDescriptor ");
093:
094: sb.append(" attribute name [");
095: if (_name != null) {
096: sb.append(_name);
097: } else {
098: sb.append("NULL");
099: }
100: sb.append("]");
101:
102: sb.append(" description [");
103: if (!_descriptions.isEmpty()) {
104: sb.append((String) _descriptions.get(0));
105: } else {
106: sb.append("NULL");
107: }
108: sb.append("]");
109:
110: return sb.toString();
111: }
112:
113: }
|