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.StringTokenizer;
018: import java.util.logging.Logger;
019:
020: import org.jdom.Element;
021: import org.jdom.Namespace;
022:
023: /**
024: * The portlet info descriptor is the descriptor for the specific
025: * portlet information. For example, the resource bundle definition.
026: * <P>
027: * There are two ways to specify the resource bundle in the
028: * descriptor, the first way is to define in the descriptor directly, the
029: * second way is to reference to a resource bundle in the descriptor.
030: * <P>
031: * While getting the resource bundle descriptor information, clients
032: * need to first use the <code>getType</code>() method to figure out
033: * which way the resource bundle is defined.
034: */
035: public class PortletInfoDescriptor {
036:
037: // Portlet info descriptor element names
038: public static final String TITLE = "title";
039: public static final String SHORT_TITLE = "short-title";
040: public static final String KEYWORDS = "keywords";
041:
042: // Global variables
043: private String _title;
044: private String _shortTitle;
045: private List _keywords = new ArrayList();
046:
047: public PortletInfoDescriptor(Logger logger) {
048: }
049:
050: /**
051: * Loads the portlet info descriptor into memory.
052: * <P>
053: * @param The portlet info descriptor Element
054: */
055: public void load(Element element, Namespace namespace) {
056: _title = element.getChildTextTrim(TITLE, namespace);
057: _shortTitle = element.getChildTextTrim(SHORT_TITLE, namespace);
058: String keywordsStr = element.getChildTextTrim(KEYWORDS,
059: namespace);
060: if (keywordsStr != null) {
061: loadKeywords(keywordsStr);
062: }
063:
064: }
065:
066: /**
067: * Returns the title.
068: * <P>
069: * @return <code>String</code> of the title.
070: */
071: public String getTitle() {
072: return _title;
073: }
074:
075: /**
076: * Returns the short title.
077: * <P>
078: * @return <code>String</code> of the title.
079: */
080: public String getShortTitle() {
081: return _shortTitle;
082: }
083:
084: /**
085: * Returns the keywords.
086: * <P>
087: * @return <code>List</code> of <code>String</code>s represent the
088: * keywords.
089: */
090: public List getKeywords() {
091: return _keywords;
092: }
093:
094: /*
095: * Loads the keywords into a <code>List</code>
096: */
097: private void loadKeywords(String keywordsStr) {
098: StringTokenizer st = new StringTokenizer(keywordsStr, ",",
099: false);
100: while (st.hasMoreTokens()) {
101: String kw = st.nextToken().trim();
102: _keywords.add(kw);
103: }
104:
105: }
106:
107: /**
108: * The toString method.
109: * <P>
110: * @return the <code>String</code> representation of the portlet
111: * info descriptor.
112: */
113: public String toString() {
114: StringBuffer sb = new StringBuffer("PortletInfoDescriptor ");
115:
116: if (_title != null) {
117: sb.append(" title [");
118: sb.append(_title);
119: sb.append("]");
120: }
121:
122: if (_shortTitle != null) {
123: sb.append(" short title [");
124: sb.append(_shortTitle);
125: sb.append("]");
126: }
127:
128: sb.append(" keywords [");
129: for (int i = 0; i < _keywords.size(); i++) {
130: sb.append((String) _keywords.get(i));
131: sb.append(", ");
132: }
133: sb.append("]");
134:
135: return sb.toString();
136:
137: }
138:
139: }
|