001: /*
002: * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.portlet.admin.mbeans.tasks;
007:
008: import com.sun.portal.desktop.dp.xml.XMLDPTags;
009: import com.sun.portal.log.common.PortalLogger;
010: import com.sun.portal.portletcontainercommon.PortletContainerConstants;
011: import com.sun.portal.portletcontainercommon.PortletPreferencesUtility;
012: import com.sun.portal.portletcontainercommon.descriptor.DeploymentDescriptorException;
013: import com.sun.portal.portletcontainercommon.descriptor.DeploymentDescriptorReader;
014: import com.sun.portal.portletcontainercommon.descriptor.PortletAppDescriptor;
015: import com.sun.portal.portletcontainercommon.descriptor.PortletDescriptor;
016: import com.sun.portal.portletcontainercommon.descriptor.PortletInfoDescriptor;
017: import com.sun.portal.portletcontainercommon.descriptor.PortletPreferencesDescriptor;
018: import com.sun.portal.portletcontainercommon.descriptor.PortletsDescriptor;
019: import com.sun.portal.portletcontainercommon.descriptor.PreferenceDescriptor;
020: import com.sun.portal.portletcontainercommon.descriptor.SecurityConstraintDescriptor;
021: import com.sun.portal.portletcontainercommon.descriptor.SecurityRoleRefDescriptor;
022: import com.sun.portal.portletcontainercommon.descriptor.SupportsDescriptor;
023: import com.sun.portal.portletcontainercommon.descriptor.UserAttributeDescriptor;
024: import org.w3c.dom.DOMException;
025: import org.w3c.dom.Document;
026: import org.w3c.dom.Element;
027:
028: import javax.xml.parsers.DocumentBuilder;
029: import javax.xml.parsers.DocumentBuilderFactory;
030: import java.io.InputStream;
031: import java.util.ArrayList;
032: import java.util.Collection;
033: import java.util.HashMap;
034: import java.util.Iterator;
035: import java.util.List;
036: import java.util.Map;
037: import java.util.Properties;
038: import java.util.Set;
039: import java.util.logging.Logger;
040:
041: /**
042: * PDProviderEntryGenerator is responsible for parsing the portlet.xml
043: * using the DeploymentDescriptorReader and creating a provider entry for
044: * each portlet entry
045: */
046: public class PDProviderEntryGenerator {
047:
048: public static final String PortletWindowClassName = "com.sun.portal.providers.portletwindow.PortletWindowProvider";
049: public static final String defaultProperties[][] = {
050: { "width", "thick" }, { "fontFace1", "Sans-serif" },
051: { "productName", "Sun JavaTM System Portal Server" } };
052: public static final String advancedProperties[][] = {
053: { "refreshTime", "0" }, { "editType", "edit_complete" },
054: { "contentPage", "PortletHelp.jsp" },
055: { "editPage", "PortletEdit.jsp" }, { "processPage", "" } };
056: public static final String mimeType = "text/html";
057: public static final String PORTLET_PREFIX = "__Portlet__";
058: public static final String PREF_PROPS_NAME = PORTLET_PREFIX
059: + "PreferenceProperties";
060: public static final String ADDL_PREF_NAME = PORTLET_PREFIX
061: + "AdditionalPreferences";
062: public static final String DOT_SEPARATOR = ".";
063: public static final String ENTITY_ID_PREFIX_NAME = "entityIDPrefix";
064: public static final String TITLE_NAME = "title";
065: public static final String SHORT_TITLE_NAME = "shortTitle";
066: public static final String KEYWORDS_NAME = "keywords";
067: public static final String CONTENT_TYPE_NAME = "supportedContentTypes";
068: public static final String TRANSPORT_GUARANTEE_NAME = "transportGuarantee";
069: public static final String IS_EDITABLE_COLLECTION = "isEditableByMimeType";
070: public static final String HAS_HELP_COLLECTION = "hasHelpByMimeType";
071: public static final String ROLE_MAP_NAME = "roleMap";
072: public static final String ROLE_DESCRIPTIONS_NAME = "roleDescriptions";
073: public static final String SUPPORTS_MAP_NAME = "supportsMap";
074: public static final String SUPPORTED_LOCALES_MAP_NAME = "supportedLocalesMap";
075: public static final String DISPLAY_NAME_MAP_NAME = "displayNameMap";
076: public static final String DESCRIPTION_MAP_NAME = "descriptionMap";
077: public static final String UI_MAP_NAME = "userInfoMap";
078: public static final String UI_DESCRIPTIONS_NAME = "userInfoDescriptions";
079: public static final String NAME_STRING = "name";
080: public static final String VALUE_STRING = "value";
081: public static final String ADVANCED_STRING = "advanced";
082: public static final String CLASS_STRING = "class";
083: public static final String TRUE = "true";
084: public static final String FALSE = "false";
085: public static final String HELP_URL = "helpURL";
086: private PortletsDescriptor psd = null;
087: private PortletAppDescriptor pad = null;
088: private String portletAppName = null;
089: private Properties configProps = null;
090:
091: public PDProviderEntryGenerator(InputStream in,
092: InputStream extStream, Properties props, String appName)
093: throws PortletDeployerException {
094: configProps = props;
095: String DDSchemaLocation = System
096: .getProperty(DeploymentDescriptorReader.PORTLET_SCHEMA_LOCATION);
097: DeploymentDescriptorReader ddReader = new DeploymentDescriptorReader(
098: getLogger(), DDSchemaLocation);
099: String validateProp = configProps
100: .getProperty(DeploymentDescriptorReader.VALIDATE_SCHEMA);
101:
102: try {
103: if (validateProp != null
104: && validateProp.toLowerCase().equals("true")) {
105: System.setProperty(
106: DeploymentDescriptorReader.VALIDATE_SCHEMA,
107: "true");
108: }
109:
110: pad = ddReader.loadPortletAppDescriptor(in, extStream);
111: } catch (DeploymentDescriptorException dde) {
112: Object[] tokens = { dde.toString() };
113: throw new PortletDeployerException("errorReadingPortletDD",
114: tokens);
115: }
116: portletAppName = appName;
117: psd = pad.getPortletsDescriptor();
118: }
119:
120: public String getPortletAppName() {
121: return portletAppName;
122: }
123:
124: public List createProviderElements(Properties roleProps,
125: Properties uiProps, List webAppRoles)
126: throws PortletDeployerException {
127: List providerElements = new ArrayList();
128: DocumentBuilderFactory dbf = DocumentBuilderFactory
129: .newInstance();
130: DocumentBuilder db = null;
131: try {
132: db = dbf.newDocumentBuilder();
133: } catch (Exception ex) {
134:
135: throw new PortletDeployerException("errorDocumentBuilder",
136: ex);
137: }
138: Document d = null;
139: try {
140:
141: d = db.newDocument();
142: } catch (Exception e) {
143: throw new PortletDeployerException("errorNewDocument", e);
144: }
145:
146: List portletDescriptors = psd.getPortletDescriptors();
147: for (int i = 0; i < portletDescriptors.size(); i++) {
148: PortletDescriptor pd = (PortletDescriptor) portletDescriptors
149: .get(i);
150: String portletName = pd.getPortletName();
151: String providerName = PORTLET_PREFIX + portletAppName
152: + DOT_SEPARATOR + portletName;
153: String entityIDPrefix = portletAppName
154: + PortletContainerConstants.ENTITY_ID_DELIMITER
155: + portletName;
156: PortletInfoDescriptor pInfo = pd.getPortletInfoDescriptor();
157: String title = portletName;
158: String shortTitle = null;
159: List keywords = null;
160:
161: if (pInfo != null) {
162: title = pInfo.getTitle();
163: shortTitle = pInfo.getShortTitle();
164: keywords = pInfo.getKeywords();
165: }
166:
167: String description = "";
168: if (pd.getDescription() != null) {
169: description = pd.getDescription();
170: }
171:
172: String isEditable = FALSE;
173: String helpUrl = "";
174:
175: List supportedPortletModes = pd
176: .getSupportedPortletModes(mimeType);
177: if (supportedPortletModes != null) {
178: for (int k = 0; k < supportedPortletModes.size(); k++) {
179: String mode = (String) supportedPortletModes.get(k);
180: if (mode.equalsIgnoreCase("EDIT")) {
181: isEditable = TRUE;
182: } else if (mode.equalsIgnoreCase("HELP")) {
183: helpUrl = HELP_URL;
184: }
185: }
186: }
187:
188: boolean sessionEnabled = pd.sessionEnabled();
189:
190: // check if saving preferences is allowed in render.
191: boolean allowSavePref = pad.isSavePreferencesAllowed();
192:
193: // create properties
194: Element propertiesElement = null;
195: try {
196: propertiesElement = d
197: .createElement(XMLDPTags.PROPERTIES_TAG);
198: propertiesElement = addDefaultProperties(
199: propertiesElement, d);
200: propertiesElement.appendChild(createPropertyElement(
201: XMLDPTags.STRING_TAG, d, TITLE_NAME, title,
202: FALSE));
203: if (shortTitle != null) {
204: propertiesElement
205: .appendChild(createPropertyElement(
206: XMLDPTags.STRING_TAG, d,
207: SHORT_TITLE_NAME, shortTitle, TRUE));
208: }
209:
210: if (keywords != null) {
211: Element keywordsElement = d
212: .createElement(XMLDPTags.COLLECTION_TAG);
213: keywordsElement.setAttribute(NAME_STRING,
214: KEYWORDS_NAME);
215: keywordsElement.setAttribute(ADVANCED_STRING, TRUE);
216: for (Iterator j = keywords.iterator(); j.hasNext();) {
217: String keyword = (String) j.next();
218: Element keywordElement = createPropertyElement(
219: XMLDPTags.STRING_TAG, d, null, keyword,
220: FALSE);
221: keywordsElement.appendChild(keywordElement);
222: }
223: propertiesElement.appendChild(keywordsElement);
224: }
225:
226: propertiesElement.appendChild(createPropertyElement(
227: XMLDPTags.STRING_TAG, d, "description",
228: description, TRUE));
229: propertiesElement.appendChild(createPropertyElement(
230: XMLDPTags.STRING_TAG, d, "entityIDPrefix",
231: entityIDPrefix, TRUE));
232: propertiesElement.appendChild(createPropertyElement(
233: XMLDPTags.BOOLEAN_TAG, d, "isEditable",
234: isEditable, TRUE));
235: propertiesElement.appendChild(createPropertyElement(
236: XMLDPTags.BOOLEAN_TAG, d, "showExceptions",
237: "false", FALSE));
238: propertiesElement.appendChild(createPropertyElement(
239: XMLDPTags.STRING_TAG, d, HELP_URL, helpUrl,
240: TRUE));
241: propertiesElement
242: .appendChild(createPropertyElement(
243: XMLDPTags.BOOLEAN_TAG, d,
244: "sessionEnabled", (new Boolean(
245: sessionEnabled)).toString(),
246: TRUE));
247: propertiesElement.appendChild(createPropertyElement(
248: XMLDPTags.BOOLEAN_TAG, d, "allowSavePref",
249: (new Boolean(allowSavePref)).toString(), TRUE));
250:
251: // create empty collection for additional preferences
252: Element emptyPref = d
253: .createElement(XMLDPTags.COLLECTION_TAG);
254: emptyPref.setAttribute(NAME_STRING, ADDL_PREF_NAME);
255: emptyPref.setAttribute(ADVANCED_STRING, TRUE);
256: propertiesElement.appendChild(emptyPref);
257: } catch (DOMException de) {
258: Object[] tokens = { providerName };
259: throw new PortletDeployerException(
260: "errorCreatePropertiesElement", de, tokens);
261: }
262:
263: PortletPreferencesDescriptor ppd = pd
264: .getPortletPreferencesDescriptor();
265: List preferenceDescriptors = null;
266: if (ppd != null) {
267: preferenceDescriptors = ppd.getPreferenceDescriptors();
268: }
269: try {
270: Element prefPropsElement = d
271: .createElement(XMLDPTags.COLLECTION_TAG);
272: prefPropsElement.setAttribute(NAME_STRING,
273: PREF_PROPS_NAME);
274: Element defaultElement = d
275: .createElement(XMLDPTags.COLLECTION_TAG);
276: defaultElement.setAttribute(NAME_STRING, "default");
277: Element isReadOnlyElement = d
278: .createElement(XMLDPTags.COLLECTION_TAG);
279: isReadOnlyElement.setAttribute(NAME_STRING,
280: "isReadOnly");
281: if (preferenceDescriptors != null
282: && !preferenceDescriptors.isEmpty()) {
283: for (int j = 0; j < preferenceDescriptors.size(); j++) {
284: PreferenceDescriptor prd = (PreferenceDescriptor) preferenceDescriptors
285: .get(j);
286: String name = prd.getPrefName();
287: List values = prd.getPrefValues();
288: String value = PortletPreferencesUtility
289: .getPreferenceString(values);
290: defaultElement
291: .appendChild(createPropertyElement(
292: XMLDPTags.STRING_TAG, d, name,
293: value, FALSE));
294: String isReadOnly = String.valueOf(prd
295: .getReadOnly());
296: isReadOnlyElement
297: .appendChild(createPropertyElement(
298: XMLDPTags.BOOLEAN_TAG, d, name,
299: isReadOnly, FALSE));
300:
301: propertiesElement
302: .appendChild(createPropertyElement(
303: XMLDPTags.STRING_TAG, d,
304: PORTLET_PREFIX + name, value,
305: FALSE));
306: }
307: }
308: prefPropsElement.appendChild(defaultElement);
309: prefPropsElement.appendChild(isReadOnlyElement);
310: propertiesElement.appendChild(prefPropsElement);
311: } catch (DOMException de) {
312: throw new PortletDeployerException(
313: "errorCreatePreferenceElement", de);
314: }
315:
316: // create a collection for supportedContentTypes
317: List supportDescriptors = pd.getSupportsDescriptors();
318: if (!supportDescriptors.isEmpty()) {
319: //System.out.println("support is not empty for provider=" + providerName);
320: try {
321: Element contentTypeElement = d
322: .createElement(XMLDPTags.COLLECTION_TAG);
323: contentTypeElement.setAttribute(NAME_STRING,
324: CONTENT_TYPE_NAME);
325: contentTypeElement.setAttribute(ADVANCED_STRING,
326: TRUE);
327:
328: //create a collection for isEdiatbleByMimeType
329: Element isEditableCollection = d
330: .createElement(XMLDPTags.COLLECTION_TAG);
331: isEditableCollection.setAttribute(NAME_STRING,
332: IS_EDITABLE_COLLECTION);
333: isEditableCollection.setAttribute(ADVANCED_STRING,
334: TRUE);
335:
336: //create a collection for hasHelpByMimeType
337:
338: Element hasHelpCollection = d
339: .createElement(XMLDPTags.COLLECTION_TAG);
340: hasHelpCollection.setAttribute(NAME_STRING,
341: HAS_HELP_COLLECTION);
342: hasHelpCollection.setAttribute(ADVANCED_STRING,
343: TRUE);
344:
345: for (int j = 0; j < supportDescriptors.size(); j++) {
346: SupportsDescriptor sd = (SupportsDescriptor) supportDescriptors
347: .get(j);
348: String contentType = sd.getMimeType();
349: Element property = d
350: .createElement(XMLDPTags.STRING_TAG);
351: property
352: .setAttribute(VALUE_STRING, contentType);
353: contentTypeElement.appendChild(property);
354:
355: // check for isEditable and help
356: String editable = FALSE;
357: String helpLink = "";
358:
359: List supportedModes = pd
360: .getSupportedPortletModes(contentType);
361: if (supportedModes != null) {
362: for (int k = 0; k < supportedModes.size(); k++) {
363: String mode = (String) supportedModes
364: .get(k);
365: if (mode.equalsIgnoreCase("EDIT")) {
366: editable = TRUE;
367: } else if (mode
368: .equalsIgnoreCase("HELP")) {
369: helpLink = HELP_URL;
370: }
371: }
372: }
373:
374: //add editable element
375: Element editableElement = d
376: .createElement(XMLDPTags.BOOLEAN_TAG);
377: editableElement.setAttribute(NAME_STRING,
378: contentType);
379: editableElement.setAttribute(VALUE_STRING,
380: editable);
381: isEditableCollection
382: .appendChild(editableElement);
383:
384: // add help element
385: Element helpElement = d
386: .createElement(XMLDPTags.STRING_TAG);
387: helpElement.setAttribute(NAME_STRING,
388: contentType);
389: helpElement
390: .setAttribute(VALUE_STRING, helpLink);
391: hasHelpCollection.appendChild(helpElement);
392: }
393:
394: propertiesElement.appendChild(contentTypeElement);
395: propertiesElement.appendChild(isEditableCollection);
396: propertiesElement.appendChild(hasHelpCollection);
397: } catch (DOMException de) {
398: throw new PortletDeployerException(
399: "errorCreatecontentTypeElement", de);
400: }
401: }
402:
403: //Create roleMapping collection
404: // validate roles
405: List securityRoleRefDescriptors = pd
406: .getSecurityRoleRefDescriptors();
407: if (securityRoleRefDescriptors.size() > 0) {
408: Collection roleValues = roleProps.values();
409: //System.out.println("roleValues=" + roleValues);
410: for (int k = 0; k < securityRoleRefDescriptors.size(); k++) {
411: SecurityRoleRefDescriptor srd = (SecurityRoleRefDescriptor) securityRoleRefDescriptors
412: .get(k);
413: String roleLink = srd.getRoleLink();
414: String portletRole = srd.getRoleName();
415: if (webAppRoles.contains(roleLink)) {
416: if (!roleValues.contains(roleLink)) {
417: Object[] tokens = { roleLink };
418: throw new PortletDeployerException(
419: "errorRoleMapping", tokens);
420: }
421: } else if (webAppRoles.contains(portletRole)) {
422: if (!roleValues.contains(portletRole)) {
423: Object[] tokens = { portletRole };
424: throw new PortletDeployerException(
425: "errorRoleMapping", tokens);
426: }
427: } else {
428: Object[] tokens = { portletRole };
429: throw new PortletDeployerException(
430: "errorRoleValidation", tokens);
431: }
432: }
433:
434: Set roleKeys = roleProps.keySet();
435: Map reverseMap = new HashMap();
436:
437: if (!roleKeys.isEmpty()) {
438: try {
439: Element roleMapElement = d
440: .createElement(XMLDPTags.COLLECTION_TAG);
441: roleMapElement.setAttribute(NAME_STRING,
442: ROLE_MAP_NAME);
443: roleMapElement.setAttribute(ADVANCED_STRING,
444: TRUE);
445: for (Iterator j = roleKeys.iterator(); j
446: .hasNext();) {
447: String key = (String) j.next();
448: String value = roleProps.getProperty(key);
449: reverseMap.put(value, key);
450: roleMapElement
451: .appendChild(createPropertyElement(
452: XMLDPTags.STRING_TAG, d,
453: key, value, FALSE));
454: }
455: propertiesElement.appendChild(roleMapElement);
456: } catch (DOMException de) {
457: throw new PortletDeployerException(
458: "errorCreateRoleMapElement", de);
459: }
460:
461: }
462:
463: //create role descriptions
464: try {
465: boolean hasRoleDescriptions = false;
466:
467: Element roleDescElement = d
468: .createElement(XMLDPTags.COLLECTION_TAG);
469: roleDescElement.setAttribute(NAME_STRING,
470: ROLE_DESCRIPTIONS_NAME);
471: roleDescElement.setAttribute(ADVANCED_STRING, TRUE);
472:
473: for (int k = 0; k < securityRoleRefDescriptors
474: .size(); k++) {
475: SecurityRoleRefDescriptor srd = (SecurityRoleRefDescriptor) securityRoleRefDescriptors
476: .get(k);
477: Map roleDescMap = srd.getDescriptionMap();
478: if (roleDescMap != null
479: && roleDescMap.size() > 0) {
480: hasRoleDescriptions = true;
481:
482: String name = (String) reverseMap.get(srd
483: .getRoleName());
484: if (name == null) {
485: String[] tokens = { srd.getRoleName() };
486: throw new PortletDeployerException(
487: "errorReverseRoleMapping",
488: tokens);
489: }
490:
491: Element roleDescSubElement = d
492: .createElement(XMLDPTags.COLLECTION_TAG);
493: roleDescSubElement.setAttribute(
494: NAME_STRING, name);
495: roleDescSubElement.setAttribute(
496: ADVANCED_STRING, TRUE);
497:
498: for (Iterator j = roleDescMap.keySet()
499: .iterator(); j.hasNext();) {
500: String lang = (String) j.next();
501: String desc = (String) roleDescMap
502: .get(lang);
503: roleDescSubElement
504: .appendChild(createPropertyElement(
505: XMLDPTags.STRING_TAG,
506: d, lang, desc, FALSE));
507: }
508:
509: roleDescElement
510: .appendChild(roleDescSubElement);
511: }
512: }
513:
514: if (hasRoleDescriptions) {
515: propertiesElement.appendChild(roleDescElement);
516: }
517: } catch (DOMException de) {
518: throw new PortletDeployerException(
519: "errorCreateRoleDescElement", de);
520: }
521: }
522:
523: //create user info collection
524: if (!uiProps.isEmpty()) {
525: try {
526: Element uiMapElement = d
527: .createElement(XMLDPTags.COLLECTION_TAG);
528: uiMapElement.setAttribute(NAME_STRING, UI_MAP_NAME);
529: uiMapElement.setAttribute(ADVANCED_STRING, TRUE);
530: Set keys = uiProps.keySet();
531: for (Iterator j = keys.iterator(); j.hasNext();) {
532: String key = (String) j.next();
533: String value = uiProps.getProperty(key);
534: uiMapElement.appendChild(createPropertyElement(
535: XMLDPTags.STRING_TAG, d, key, value,
536: FALSE));
537: }
538: propertiesElement.appendChild(uiMapElement);
539: } catch (DOMException de) {
540: throw new PortletDeployerException(
541: "errorCreateUIMapElement", de);
542: }
543:
544: }
545:
546: //create user info descriptions
547: boolean hasUserAttrDescriptions = false;
548: List userAttrDescriptors = pad
549: .getUserAttributeDescriptors();
550: if (userAttrDescriptors.size() > 0) {
551: try {
552: Element userAttrDescElement = d
553: .createElement(XMLDPTags.COLLECTION_TAG);
554: userAttrDescElement.setAttribute(NAME_STRING,
555: UI_DESCRIPTIONS_NAME);
556: userAttrDescElement.setAttribute(ADVANCED_STRING,
557: TRUE);
558:
559: for (Iterator di = userAttrDescriptors.iterator(); di
560: .hasNext();) {
561: UserAttributeDescriptor uad = (UserAttributeDescriptor) di
562: .next();
563: Map userAttrDescMap = uad.getDescriptionMap();
564: if (userAttrDescMap.size() > 0) {
565: hasUserAttrDescriptions = true;
566: Element userAttrDescSubElement = d
567: .createElement(XMLDPTags.COLLECTION_TAG);
568: userAttrDescSubElement.setAttribute(
569: NAME_STRING, uad.getName());
570: userAttrDescSubElement.setAttribute(
571: ADVANCED_STRING, TRUE);
572:
573: for (Iterator j = userAttrDescMap.keySet()
574: .iterator(); j.hasNext();) {
575: String lang = (String) j.next();
576: String desc = (String) userAttrDescMap
577: .get(lang);
578: userAttrDescSubElement
579: .appendChild(createPropertyElement(
580: XMLDPTags.STRING_TAG,
581: d, lang, desc, FALSE));
582: }
583: userAttrDescElement
584: .appendChild(userAttrDescSubElement);
585: }
586: }
587:
588: if (hasUserAttrDescriptions) {
589: propertiesElement
590: .appendChild(userAttrDescElement);
591: }
592: } catch (DOMException de) {
593: throw new PortletDeployerException(
594: "errorCreateUIDescElement", de);
595: }
596:
597: }
598:
599: //create supports collection
600: List supportsDescriptors = pd.getSupportsDescriptors();
601: if (supportsDescriptors != null) {
602: Element supportsElement = d
603: .createElement(XMLDPTags.COLLECTION_TAG);
604: supportsElement.setAttribute(NAME_STRING,
605: SUPPORTS_MAP_NAME);
606: supportsElement.setAttribute(ADVANCED_STRING, TRUE);
607:
608: for (Iterator j = supportsDescriptors.iterator(); j
609: .hasNext();) {
610: SupportsDescriptor sd = (SupportsDescriptor) j
611: .next();
612: String mimeType = sd.getMimeType();
613: List portletModes = sd.getPortletModes();
614:
615: Element mimeTypeElement = d
616: .createElement(XMLDPTags.COLLECTION_TAG);
617: mimeTypeElement.setAttribute(NAME_STRING, mimeType);
618:
619: for (Iterator k = portletModes.iterator(); k
620: .hasNext();) {
621: String mode = (String) k.next();
622: Element modeElement = createPropertyElement(
623: XMLDPTags.STRING_TAG, d, null, mode,
624: FALSE);
625: mimeTypeElement.appendChild(modeElement);
626: }
627: supportsElement.appendChild(mimeTypeElement);
628: }
629: propertiesElement.appendChild(supportsElement);
630: }
631:
632: //create display name properties
633: Map displayNameMap = pd.getDisplayNameMap();
634:
635: if (displayNameMap != null) {
636: Element dnMapElement = d
637: .createElement(XMLDPTags.COLLECTION_TAG);
638: dnMapElement.setAttribute(NAME_STRING,
639: DISPLAY_NAME_MAP_NAME);
640: dnMapElement.setAttribute(ADVANCED_STRING, TRUE);
641:
642: for (Iterator j = displayNameMap.keySet().iterator(); j
643: .hasNext();) {
644: String lang = (String) j.next();
645: String dn = (String) displayNameMap.get(lang);
646: Element dnElement = createPropertyElement(
647: XMLDPTags.STRING_TAG, d, lang, dn, FALSE);
648: dnMapElement.appendChild(dnElement);
649: }
650:
651: propertiesElement.appendChild(dnMapElement);
652: }
653:
654: //create display name properties
655: Map descriptionMap = pd.getDescriptionMap();
656:
657: if (descriptionMap != null) {
658: Element descMapElement = d
659: .createElement(XMLDPTags.COLLECTION_TAG);
660: descMapElement.setAttribute(NAME_STRING,
661: DESCRIPTION_MAP_NAME);
662: descMapElement.setAttribute(ADVANCED_STRING, TRUE);
663:
664: for (Iterator j = descriptionMap.keySet().iterator(); j
665: .hasNext();) {
666: String lang = (String) j.next();
667: String desc = (String) descriptionMap.get(lang);
668: Element descElement = createPropertyElement(
669: XMLDPTags.STRING_TAG, d, lang, desc, FALSE);
670: descMapElement.appendChild(descElement);
671: }
672:
673: propertiesElement.appendChild(descMapElement);
674: }
675:
676: //create supported locales collection
677: List supportedLocales = pd.getSupportedLocales();
678: if (supportedLocales != null) {
679: Element supportedLocalesElement = d
680: .createElement(XMLDPTags.COLLECTION_TAG);
681: supportedLocalesElement.setAttribute(NAME_STRING,
682: SUPPORTED_LOCALES_MAP_NAME);
683: supportedLocalesElement.setAttribute(ADVANCED_STRING,
684: TRUE);
685:
686: for (Iterator j = supportedLocales.iterator(); j
687: .hasNext();) {
688: String supportedLocale = (String) j.next();
689: Element supportedLocaleElement = createPropertyElement(
690: XMLDPTags.STRING_TAG, d, null,
691: supportedLocale, FALSE);
692: supportedLocalesElement
693: .appendChild(supportedLocaleElement);
694: }
695: propertiesElement.appendChild(supportedLocalesElement);
696: }
697:
698: //create transport-guarantee property, if required
699: SecurityConstraintDescriptor scd = pad
700: .getSecurityConstraintDescriptor();
701: if (scd != null) {
702: List constrainedPortlets = scd.getConstrainedPortlets();
703: if (constrainedPortlets != null
704: && constrainedPortlets.contains(portletName)) {
705: String tgType = scd.getTransportGuaranteeType();
706: if (tgType != null && tgType.length() > 0) {
707: Element tgElement = createPropertyElement(
708: XMLDPTags.STRING_TAG, d,
709: TRANSPORT_GUARANTEE_NAME, tgType, FALSE);
710: propertiesElement.appendChild(tgElement);
711: }
712: }
713: }
714:
715: // create provider
716: Element providerElement = null;
717: try {
718: providerElement = d
719: .createElement(XMLDPTags.PROVIDER_TAG);
720: } catch (DOMException de) {
721: throw new PortletDeployerException(
722: "errorCreateProviderElement", de);
723: }
724: providerElement.setAttribute(NAME_STRING, providerName);
725: providerElement.setAttribute(CLASS_STRING,
726: PortletWindowClassName);
727: providerElement.appendChild(propertiesElement);
728: //System.out.println("done creating provider element");
729:
730: providerElements.add(providerElement);
731:
732: }
733: return providerElements;
734:
735: }
736:
737: public List getProviderNames() {
738: List providerNames = new ArrayList();
739: List portletNames = psd.getPortletNames();
740: for (int i = 0; i < portletNames.size(); i++) {
741: String portletName = (String) portletNames.get(i);
742: String providerName = PORTLET_PREFIX + portletAppName
743: + DOT_SEPARATOR + portletName;
744: providerNames.add(providerName);
745: }
746: return providerNames;
747: }
748:
749: private Element addDefaultProperties(Element propertiesElement,
750: Document d) throws DOMException {
751: for (int i = 0; i < defaultProperties.length; i++) {
752: Element property = createPropertyElement(
753: XMLDPTags.STRING_TAG, d, defaultProperties[i][0],
754: defaultProperties[i][1], FALSE);
755: propertiesElement.appendChild(property);
756: }
757: for (int i = 0; i < advancedProperties.length; i++) {
758: Element property = createPropertyElement(
759: XMLDPTags.STRING_TAG, d, advancedProperties[i][0],
760: advancedProperties[i][1], TRUE);
761: propertiesElement.appendChild(property);
762: }
763: return propertiesElement;
764: }
765:
766: private Element createPropertyElement(String tagname, Document d,
767: String name, String value, String advanced)
768: throws DOMException {
769: Element property = d.createElement(tagname);
770: if (name != null) {
771: property.setAttribute(NAME_STRING, name);
772: }
773: property.setAttribute(VALUE_STRING, value);
774: if (advanced.equals(TRUE)) {
775: property.setAttribute(ADVANCED_STRING, advanced);
776: }
777: return property;
778: }
779:
780: public Logger getLogger() {
781: //LoggerImpl logger = new LoggerImpl();
782: //logger.init("PortletSample", configProps);
783:
784: return PortalLogger.getLogger(PDProviderEntryGenerator.class);
785: }
786:
787: }
|