portletId;
}
portletIds.add(portletId);
Portlet portletModel = (Portlet)portletsPool.get(portletId);
if (portletModel == null) {
portletModel = new Portlet(
new PortletPK(portletId, _SHARED_KEY, _SHARED_KEY));
portletsPool.put(portletId, portletModel);
}
if (servletContextName != null) {
portletModel.setWARFile(true);
}
portletModel.setPortletClass(portlet.elementText("portlet-class"));
Iterator itr2 = portlet.elements("init-param").iterator();
while (itr2.hasNext()) {
Element initParam = (Element)itr2.next();
portletModel.getInitParams().put(
initParam.elementText("name"),
initParam.elementText("value"));
}
Element expirationCache = portlet.element("expiration-cache");
if (expirationCache != null) {
portletModel.setExpCache(new Integer(GetterUtil.getInteger(
expirationCache.getText())));
}
itr2 = portlet.elements("supports").iterator();
while (itr2.hasNext()) {
Element supports = (Element)itr2.next();
String mimeType = supports.elementText("mime-type");
Iterator itr3 = supports.elements("portlet-mode").iterator();
while (itr3.hasNext()) {
Element portletMode = (Element)itr3.next();
Set mimeTypeModes =
(Set)portletModel.getPortletModes().get(mimeType);
if (mimeTypeModes == null) {
mimeTypeModes = new HashSet();
portletModel.getPortletModes().put(
mimeType, mimeTypeModes);
}
mimeTypeModes.add(portletMode.getTextTrim().toLowerCase());
}
}
Set supportedLocales = portletModel.getSupportedLocales();
supportedLocales.add(Locale.getDefault().getLanguage());
itr2 = portlet.elements("supported-locale").iterator();
while (itr2.hasNext()) {
Element supportedLocaleEl = (Element)itr2.next();
String supportedLocale = supportedLocaleEl.getText();
supportedLocales.add(supportedLocale);
}
portletModel.setResourceBundle(
portlet.elementText("resource-bundle"));
Element portletInfo = portlet.element("portlet-info");
String portletInfoTitle = null;
String portletInfoShortTitle = null;
String portletInfoKeyWords = null;
if (portletInfo != null) {
portletInfoTitle = portletInfo.elementText("title");
portletInfoShortTitle = portletInfo.elementText("short-title");
portletInfoKeyWords = portletInfo.elementText("keywords");
}
portletModel.setPortletInfo(new PortletInfo(
portletInfoTitle, portletInfoShortTitle, portletInfoKeyWords));
Element portletPreferences = portlet.element("portlet-preferences");
String defaultPreferences = null;
String prefsValidator = null;
if (portletPreferences != null) {
Element prefsValidatorEl =
portletPreferences.element("preferences-validator");
String prefsValidatorName = null;
if (prefsValidatorEl != null) {
prefsValidator = prefsValidatorEl.getText();
portletPreferences.remove(prefsValidatorEl);
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLWriter writer = new XMLWriter(
baos, OutputFormat.createCompactFormat());
writer.write(portletPreferences);
defaultPreferences = baos.toString();
}
portletModel.setDefaultPreferences(defaultPreferences);
portletModel.setPreferencesValidator(prefsValidator);
if (!portletModel.isWARFile() &&
Validator.isNotNull(prefsValidator) &&
GetterUtil.getBoolean(PropsUtil.get(
PropsUtil.PREFERENCE_VALIDATE_ON_STARTUP))) {
try {
PreferencesValidator prefsValidatorObj =
PortalUtil.getPreferencesValidator(portletModel);
prefsValidatorObj.validate(
PortletPreferencesSerializer.fromDefaultXML(
defaultPreferences));
}
catch (Exception e) {
_log.warn(
"Portlet with the name " + portletId +
" does not have valid default preferences");
}
}
List roles = new ArrayList();
itr2 = portlet.elements("security-role-ref").iterator();
while (itr2.hasNext()) {
Element role = (Element)itr2.next();
roles.add(role.elementText("role-name"));
}
portletModel.setRolesArray((String[])roles.toArray(new String[0]));
portletModel.getUserAttributes().addAll(userAttributes);
}
return portletIds;
}