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 SecurityRoleRefDescriptor {
028: // Portlet Descriptor Element Names
029: public static final String ROLE_NAME = "role-name";
030: public static final String ROLE_LINK = "role-link";
031:
032: // Global variable
033: private String _roleName;
034: private String _roleLink;
035: private List _descriptions = new ArrayList();
036: private Map _descriptionMap = new HashMap();
037:
038: public SecurityRoleRefDescriptor(Logger logger) {
039: }
040:
041: public void load(Element element, Namespace namespace) {
042: _roleName = element.getChildTextTrim(ROLE_NAME, namespace);
043: _roleLink = element.getChildTextTrim(ROLE_LINK, namespace);
044:
045: List descriptionElements = element.getChildren(
046: PortletAppDescriptor.DESCRIPTION, namespace);
047: for (Iterator i = descriptionElements.iterator(); i.hasNext();) {
048: Element descriptionElement = (Element) i.next();
049: _descriptions.add(descriptionElement.getTextTrim());
050:
051: List descList = descriptionElement.getAttributes();
052: int j = descList
053: .indexOf(PortletAppDescriptor.XML_LANG_ATTR);
054: if (j == -1) {
055: String lang = Locale.getDefault().toString().replace(
056: '_', '-');
057: _descriptionMap.put(lang, descriptionElement
058: .getTextTrim());
059: } else {
060: Attribute dAttr = (Attribute) descList.get(j);
061: _descriptionMap.put(dAttr.getValue(),
062: descriptionElement.getTextTrim());
063: }
064: }
065: }
066:
067: public String getRoleName() {
068: return _roleName;
069: }
070:
071: public String getRoleLink() {
072: return _roleLink;
073: }
074:
075: public String getDescription() {
076: String description = null;
077: if (!_descriptions.isEmpty()) {
078: description = (String) _descriptions.get(0);
079: }
080: return description;
081: }
082:
083: public List getDescriptions() {
084: return _descriptions;
085: }
086:
087: /**
088: * Returns descriptions in a Map.
089: * <P>
090: * @return <code>Map</code> of lang/description pairs of the
091: * descriptions. Empty <code>Map</code> will be returned
092: * if not defined.
093: */
094: public Map getDescriptionMap() {
095: return _descriptionMap;
096: }
097:
098: public String toString() {
099: StringBuffer sb = new StringBuffer("SecurityRoleDescriptor ");
100:
101: sb.append(" role name [");
102: if (_roleName != null) {
103: sb.append(_roleName);
104: } else {
105: sb.append("NULL");
106: }
107: sb.append("]");
108:
109: sb.append(" role link [");
110: if (_roleLink != null) {
111: sb.append(_roleLink);
112: } else {
113: sb.append("NULL");
114: }
115: sb.append("]");
116:
117: sb.append(" description [");
118: if (!_descriptions.isEmpty()) {
119: sb.append((String) _descriptions.get(0));
120: } else {
121: sb.append("NULL");
122: }
123: sb.append("]");
124:
125: return sb.toString();
126: }
127:
128: }
|