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