private void _doPreparePortlet(HttpServletRequest request, Portlet portlet) throws Exception { User user = PortalUtil.getUser(request); Layout layout = (Layout) request.getAttribute(WebKeys.LAYOUT); ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); long scopeGroupId = PortalUtil.getScopeGroupId(request, portlet.getPortletId()); themeDisplay.setScopeGroupId(scopeGroupId); long siteGroupId = 0; if (layout.isTypeControlPanel()) { siteGroupId = PortalUtil.getSiteGroupId(scopeGroupId); } else { siteGroupId = PortalUtil.getSiteGroupId(layout.getGroupId()); } themeDisplay.setSiteGroupId(siteGroupId); if (user != null) { HttpSession session = request.getSession(); InvokerPortletImpl.clearResponse( session, layout.getPrimaryKey(), portlet.getPortletId(), LanguageUtil.getLanguageId(request)); } processPublicRenderParameters(request, layout, portlet); if (themeDisplay.isLifecycleRender() || themeDisplay.isLifecycleResource()) { WindowState windowState = WindowStateFactory.getWindowState(ParamUtil.getString(request, "p_p_state")); if (layout.isTypeControlPanel() && ((windowState == null) || windowState.equals(WindowState.NORMAL) || Validator.isNull(windowState.toString()))) { windowState = WindowState.MAXIMIZED; } PortletMode portletMode = PortletModeFactory.getPortletMode(ParamUtil.getString(request, "p_p_mode")); PortalUtil.updateWindowState(portlet.getPortletId(), user, layout, windowState, request); PortalUtil.updatePortletMode(portlet.getPortletId(), user, layout, portletMode, request); } }
/** * Derive default permissions based on the logic found in * portal-web/docroot/html/taglib/ui/input_permissions/page.jsp. Do not update this logic updating * the logic in the JSP. */ public void deriveDefaultPermissions(long repositoryId, String modelName) throws PortalException { long siteGroupId = PortalUtil.getSiteGroupId(repositoryId); Group siteGroup = GroupLocalServiceUtil.getGroup(siteGroupId); Role defaultGroupRole = RoleLocalServiceUtil.getDefaultGroupRole(siteGroupId); List<String> groupPermissions = new ArrayList<String>(); List<String> guestPermissions = new ArrayList<String>(); String[] roleNames = {RoleConstants.GUEST, defaultGroupRole.getName()}; List<String> supportedActions = ResourceActionsUtil.getModelResourceActions(modelName); List<String> groupDefaultActions = ResourceActionsUtil.getModelResourceGroupDefaultActions(modelName); List<String> guestDefaultActions = ResourceActionsUtil.getModelResourceGuestDefaultActions(modelName); List<String> guestUnsupportedActions = ResourceActionsUtil.getModelResourceGuestUnsupportedActions(modelName); for (String roleName : roleNames) { for (String action : supportedActions) { if (roleName.equals(RoleConstants.GUEST) && !guestUnsupportedActions.contains(action) && guestDefaultActions.contains(action) && siteGroup.hasPublicLayouts()) { guestPermissions.add(action); } else if (roleName.equals(defaultGroupRole.getName()) && groupDefaultActions.contains(action)) { groupPermissions.add(action); } } } setGroupPermissions(groupPermissions.toArray(new String[groupPermissions.size()])); setGuestPermissions(guestPermissions.toArray(new String[guestPermissions.size()])); }
protected void validateFile(long companyId, long groupId, String portletId, ZipReader zipReader) throws Exception { // XML String xml = zipReader.getEntryAsString("/manifest.xml"); if (xml == null) { throw new LARFileException("manifest.xml not found in the LAR"); } Element rootElement = null; try { Document document = SAXReaderUtil.read(xml); rootElement = document.getRootElement(); } catch (Exception e) { throw new LARFileException(e); } // Build compatibility int buildNumber = ReleaseInfo.getBuildNumber(); Element headerElement = rootElement.element("header"); int importBuildNumber = GetterUtil.getInteger(headerElement.attributeValue("build-number")); if (buildNumber != importBuildNumber) { throw new LayoutImportException( "LAR build number " + importBuildNumber + " does not match " + "portal build number " + buildNumber); } // Type String larType = headerElement.attributeValue("type"); if (!larType.equals("portlet")) { throw new LARTypeException(larType); } // Portlet compatibility String rootPortletId = headerElement.attributeValue("root-portlet-id"); if (!PortletConstants.getRootPortletId(portletId).equals(rootPortletId)) { throw new PortletIdException("Invalid portlet id " + rootPortletId); } // Available locales Portlet portlet = _portletLocalService.getPortletById(companyId, portletId); PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance(); if (portletDataHandler.isDataLocalized()) { List<Locale> sourceAvailableLocales = Arrays.asList( LocaleUtil.fromLanguageIds( StringUtil.split(headerElement.attributeValue("available-locales")))); for (Locale sourceAvailableLocale : sourceAvailableLocales) { if (!LanguageUtil.isAvailableLocale( PortalUtil.getSiteGroupId(groupId), sourceAvailableLocale)) { LocaleException le = new LocaleException( LocaleException.TYPE_EXPORT_IMPORT, "Locale " + sourceAvailableLocale + " is not " + "available in company " + companyId); le.setSourceAvailableLocales(sourceAvailableLocales); le.setTargetAvailableLocales( LanguageUtil.getAvailableLocales(PortalUtil.getSiteGroupId(groupId))); throw le; } } } }
public void updateArticle(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { UploadException uploadException = (UploadException) actionRequest.getAttribute(WebKeys.UPLOAD_EXCEPTION); if (uploadException != null) { if (uploadException.isExceededLiferayFileItemSizeLimit()) { throw new LiferayFileItemException(); } else if (uploadException.isExceededSizeLimit()) { throw new ArticleContentSizeException(); } throw new PortalException(uploadException.getCause()); } UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest); if (_log.isDebugEnabled()) { _log.debug("Updating article " + MapUtil.toString(uploadPortletRequest.getParameterMap())); } String actionName = ParamUtil.getString(actionRequest, ActionRequest.ACTION_NAME); long groupId = ParamUtil.getLong(uploadPortletRequest, "groupId"); long folderId = ParamUtil.getLong(uploadPortletRequest, "folderId"); long classNameId = ParamUtil.getLong(uploadPortletRequest, "classNameId"); long classPK = ParamUtil.getLong(uploadPortletRequest, "classPK"); String articleId = ParamUtil.getString(uploadPortletRequest, "articleId"); boolean autoArticleId = ParamUtil.getBoolean(uploadPortletRequest, "autoArticleId"); double version = ParamUtil.getDouble(uploadPortletRequest, "version"); Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(actionRequest, "title"); Map<Locale, String> descriptionMap = LocalizationUtil.getLocalizationMap(actionRequest, "description"); ServiceContext serviceContext = ServiceContextFactory.getInstance(JournalArticle.class.getName(), uploadPortletRequest); String ddmStructureKey = ParamUtil.getString(uploadPortletRequest, "ddmStructureKey"); DDMStructure ddmStructure = _ddmStructureLocalService.getStructure( PortalUtil.getSiteGroupId(groupId), PortalUtil.getClassNameId(JournalArticle.class), ddmStructureKey, true); Object[] contentAndImages = ActionUtil.getContentAndImages(ddmStructure, serviceContext); String content = (String) contentAndImages[0]; Map<String, byte[]> images = (HashMap<String, byte[]>) contentAndImages[1]; Boolean fileItemThresholdSizeExceeded = (Boolean) uploadPortletRequest.getAttribute(WebKeys.FILE_ITEM_THRESHOLD_SIZE_EXCEEDED); if ((fileItemThresholdSizeExceeded != null) && fileItemThresholdSizeExceeded.booleanValue()) { throw new ArticleContentSizeException(); } String ddmTemplateKey = ParamUtil.getString(uploadPortletRequest, "ddmTemplateKey"); String layoutUuid = ParamUtil.getString(uploadPortletRequest, "layoutUuid"); Layout targetLayout = JournalUtil.getArticleLayout(layoutUuid, groupId); if (targetLayout == null) { layoutUuid = null; } int displayDateMonth = ParamUtil.getInteger(uploadPortletRequest, "displayDateMonth"); int displayDateDay = ParamUtil.getInteger(uploadPortletRequest, "displayDateDay"); int displayDateYear = ParamUtil.getInteger(uploadPortletRequest, "displayDateYear"); int displayDateHour = ParamUtil.getInteger(uploadPortletRequest, "displayDateHour"); int displayDateMinute = ParamUtil.getInteger(uploadPortletRequest, "displayDateMinute"); int displayDateAmPm = ParamUtil.getInteger(uploadPortletRequest, "displayDateAmPm"); if (displayDateAmPm == Calendar.PM) { displayDateHour += 12; } int expirationDateMonth = ParamUtil.getInteger(uploadPortletRequest, "expirationDateMonth"); int expirationDateDay = ParamUtil.getInteger(uploadPortletRequest, "expirationDateDay"); int expirationDateYear = ParamUtil.getInteger(uploadPortletRequest, "expirationDateYear"); int expirationDateHour = ParamUtil.getInteger(uploadPortletRequest, "expirationDateHour"); int expirationDateMinute = ParamUtil.getInteger(uploadPortletRequest, "expirationDateMinute"); int expirationDateAmPm = ParamUtil.getInteger(uploadPortletRequest, "expirationDateAmPm"); boolean neverExpire = ParamUtil.getBoolean(uploadPortletRequest, "neverExpire"); if (expirationDateAmPm == Calendar.PM) { expirationDateHour += 12; } int reviewDateMonth = ParamUtil.getInteger(uploadPortletRequest, "reviewDateMonth"); int reviewDateDay = ParamUtil.getInteger(uploadPortletRequest, "reviewDateDay"); int reviewDateYear = ParamUtil.getInteger(uploadPortletRequest, "reviewDateYear"); int reviewDateHour = ParamUtil.getInteger(uploadPortletRequest, "reviewDateHour"); int reviewDateMinute = ParamUtil.getInteger(uploadPortletRequest, "reviewDateMinute"); int reviewDateAmPm = ParamUtil.getInteger(uploadPortletRequest, "reviewDateAmPm"); boolean neverReview = ParamUtil.getBoolean(uploadPortletRequest, "neverReview"); if (reviewDateAmPm == Calendar.PM) { reviewDateHour += 12; } boolean indexable = ParamUtil.getBoolean(uploadPortletRequest, "indexable"); boolean smallImage = ParamUtil.getBoolean(uploadPortletRequest, "smallImage"); String smallImageURL = ParamUtil.getString(uploadPortletRequest, "smallImageURL"); File smallFile = uploadPortletRequest.getFile("smallFile"); String articleURL = ParamUtil.getString(uploadPortletRequest, "articleURL"); JournalArticle article = null; String oldUrlTitle = StringPool.BLANK; if (actionName.equals("addArticle")) { // Add article article = _journalArticleService.addArticle( groupId, folderId, classNameId, classPK, articleId, autoArticleId, titleMap, descriptionMap, content, ddmStructureKey, ddmTemplateKey, layoutUuid, displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, expirationDateMonth, expirationDateDay, expirationDateYear, expirationDateHour, expirationDateMinute, neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour, reviewDateMinute, neverReview, indexable, smallImage, smallImageURL, smallFile, images, articleURL, serviceContext); } else { // Update article article = _journalArticleService.getArticle(groupId, articleId, version); String tempOldUrlTitle = article.getUrlTitle(); if (actionName.equals("previewArticle") || actionName.equals("updateArticle")) { article = _journalArticleService.updateArticle( groupId, folderId, articleId, version, titleMap, descriptionMap, content, ddmStructureKey, ddmTemplateKey, layoutUuid, displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, expirationDateMonth, expirationDateDay, expirationDateYear, expirationDateHour, expirationDateMinute, neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour, reviewDateMinute, neverReview, indexable, smallImage, smallImageURL, smallFile, images, articleURL, serviceContext); } if (!tempOldUrlTitle.equals(article.getUrlTitle())) { oldUrlTitle = tempOldUrlTitle; } } // Recent articles JournalUtil.addRecentArticle(actionRequest, article); // Journal content String portletResource = ParamUtil.getString(actionRequest, "portletResource"); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup( themeDisplay.getLayout(), portletResource); if (portletPreferences != null) { portletPreferences.setValue("groupId", String.valueOf(article.getGroupId())); portletPreferences.setValue("articleId", article.getArticleId()); portletPreferences.store(); updateContentSearch(actionRequest, portletResource, article.getArticleId()); } sendEditArticleRedirect(actionRequest, actionResponse, article, oldUrlTitle); }
protected File doExport(PortletDataContext portletDataContext) throws Exception { boolean exportPermissions = MapUtil.getBoolean( portletDataContext.getParameterMap(), PortletDataHandlerKeys.PERMISSIONS); if (_log.isDebugEnabled()) { _log.debug("Export permissions " + exportPermissions); } StopWatch stopWatch = new StopWatch(); stopWatch.start(); Layout layout = _layoutLocalService.getLayout(portletDataContext.getPlid()); if (!layout.isTypeControlPanel() && !layout.isTypePanel() && !layout.isTypePortlet()) { throw new LayoutImportException("Layout type " + layout.getType() + " is not valid"); } ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); if (serviceContext == null) { serviceContext = new ServiceContext(); serviceContext.setCompanyId(layout.getCompanyId()); serviceContext.setSignedIn(false); long defaultUserId = _userLocalService.getDefaultUserId(layout.getCompanyId()); serviceContext.setUserId(defaultUserId); ServiceContextThreadLocal.pushServiceContext(serviceContext); } long layoutSetBranchId = MapUtil.getLong(portletDataContext.getParameterMap(), "layoutSetBranchId"); serviceContext.setAttribute("layoutSetBranchId", layoutSetBranchId); long scopeGroupId = portletDataContext.getGroupId(); javax.portlet.PortletPreferences jxPortletPreferences = PortletPreferencesFactoryUtil.getLayoutPortletSetup( layout, portletDataContext.getPortletId()); String scopeType = GetterUtil.getString(jxPortletPreferences.getValue("lfrScopeType", null)); String scopeLayoutUuid = GetterUtil.getString(jxPortletPreferences.getValue("lfrScopeLayoutUuid", null)); if (Validator.isNotNull(scopeType)) { Group scopeGroup = null; if (scopeType.equals("company")) { scopeGroup = _groupLocalService.getCompanyGroup(layout.getCompanyId()); } else if (Validator.isNotNull(scopeLayoutUuid)) { scopeGroup = layout.getScopeGroup(); } if (scopeGroup != null) { scopeGroupId = scopeGroup.getGroupId(); } } portletDataContext.setScopeType(scopeType); portletDataContext.setScopeLayoutUuid(scopeLayoutUuid); Document document = SAXReaderUtil.createDocument(); Element rootElement = document.addElement("root"); portletDataContext.setExportDataRootElement(rootElement); Element headerElement = rootElement.addElement("header"); headerElement.addAttribute( "available-locales", StringUtil.merge( LanguageUtil.getAvailableLocales( PortalUtil.getSiteGroupId(portletDataContext.getScopeGroupId())))); headerElement.addAttribute("build-number", String.valueOf(ReleaseInfo.getBuildNumber())); headerElement.addAttribute("export-date", Time.getRFC822()); if (portletDataContext.hasDateRange()) { headerElement.addAttribute("start-date", String.valueOf(portletDataContext.getStartDate())); headerElement.addAttribute("end-date", String.valueOf(portletDataContext.getEndDate())); } headerElement.addAttribute("type", "portlet"); headerElement.addAttribute("company-id", String.valueOf(portletDataContext.getCompanyId())); headerElement.addAttribute( "company-group-id", String.valueOf(portletDataContext.getCompanyGroupId())); headerElement.addAttribute("group-id", String.valueOf(scopeGroupId)); headerElement.addAttribute( "user-personal-site-group-id", String.valueOf(portletDataContext.getUserPersonalSiteGroupId())); headerElement.addAttribute("private-layout", String.valueOf(layout.isPrivateLayout())); headerElement.addAttribute("root-portlet-id", portletDataContext.getRootPortletId()); Element missingReferencesElement = rootElement.addElement("missing-references"); portletDataContext.setMissingReferencesElement(missingReferencesElement); Map<String, Boolean> exportPortletControlsMap = ExportImportHelperUtil.getExportPortletControlsMap( layout.getCompanyId(), portletDataContext.getPortletId(), portletDataContext.getParameterMap()); exportPortlet( portletDataContext, layout, rootElement, exportPermissions, exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS), exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_DATA), exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_SETUP), exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_USER_PREFERENCES)); exportService( portletDataContext, rootElement, exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_SETUP)); exportAssetLinks(portletDataContext); exportExpandoTables(portletDataContext); exportLocks(portletDataContext); _deletionSystemEventExporter.exportDeletionSystemEvents(portletDataContext); if (exportPermissions) { _permissionExporter.exportPortletDataPermissions(portletDataContext); } ExportImportHelperUtil.writeManifestSummary(document, portletDataContext.getManifestSummary()); if (_log.isInfoEnabled()) { _log.info("Exporting portlet took " + stopWatch.getTime() + " ms"); } try { portletDataContext.addZipEntry("/manifest.xml", document.formattedString()); } catch (IOException ioe) { throw new SystemException(ioe); } ZipWriter zipWriter = portletDataContext.getZipWriter(); return zipWriter.getFile(); }
public AssetEntry updateEntry( long userId, long groupId, Date createDate, Date modifiedDate, String className, long classPK, String classUuid, long classTypeId, long[] categoryIds, String[] tagNames, boolean visible, Date startDate, Date endDate, Date expirationDate, String mimeType, String title, String description, String summary, String url, String layoutUuid, int height, int width, Integer priority, boolean sync) throws PortalException, SystemException { // Entry User user = userPersistence.findByPrimaryKey(userId); long classNameId = PortalUtil.getClassNameId(className); validate(groupId, className, categoryIds, tagNames); AssetEntry entry = assetEntryPersistence.fetchByC_C(classNameId, classPK); boolean oldVisible = false; if (entry != null) { oldVisible = entry.isVisible(); } if (modifiedDate == null) { modifiedDate = new Date(); } if (entry == null) { long entryId = counterLocalService.increment(); entry = assetEntryPersistence.create(entryId); entry.setCompanyId(user.getCompanyId()); entry.setUserId(user.getUserId()); entry.setUserName(user.getFullName()); if (createDate == null) { createDate = new Date(); } entry.setCreateDate(createDate); entry.setModifiedDate(modifiedDate); entry.setClassNameId(classNameId); entry.setClassPK(classPK); entry.setClassUuid(classUuid); entry.setVisible(visible); entry.setExpirationDate(expirationDate); if (priority == null) { entry.setPriority(0); } entry.setViewCount(0); } entry.setGroupId(groupId); entry.setModifiedDate(modifiedDate); entry.setClassTypeId(classTypeId); entry.setVisible(visible); entry.setStartDate(startDate); entry.setEndDate(endDate); entry.setExpirationDate(expirationDate); entry.setMimeType(mimeType); entry.setTitle(title); entry.setDescription(description); entry.setSummary(summary); entry.setUrl(url); entry.setLayoutUuid(layoutUuid); entry.setHeight(height); entry.setWidth(width); if (priority != null) { entry.setPriority(priority.intValue()); } // Categories if (categoryIds != null) { assetEntryPersistence.setAssetCategories(entry.getEntryId(), categoryIds); } // Tags if (tagNames != null) { long siteGroupId = PortalUtil.getSiteGroupId(groupId); List<AssetTag> tags = new ArrayList<AssetTag>(tagNames.length); for (String tagName : tagNames) { AssetTag tag = null; try { tag = assetTagLocalService.getTag(siteGroupId, tagName); } catch (NoSuchTagException nste) { ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); serviceContext.setScopeGroupId(siteGroupId); tag = assetTagLocalService.addTag( user.getUserId(), tagName, PropsValues.ASSET_TAG_PROPERTIES_DEFAULT, serviceContext); } if (tag != null) { tags.add(tag); } } List<AssetTag> oldTags = assetEntryPersistence.getAssetTags(entry.getEntryId()); assetEntryPersistence.setAssetTags(entry.getEntryId(), tags); if (entry.isVisible()) { boolean isNew = entry.isNew(); assetEntryPersistence.updateImpl(entry); if (isNew) { for (AssetTag tag : tags) { assetTagLocalService.incrementAssetCount(tag.getTagId(), classNameId); } } else { for (AssetTag oldTag : oldTags) { if (!tags.contains(oldTag)) { assetTagLocalService.decrementAssetCount(oldTag.getTagId(), classNameId); } } for (AssetTag tag : tags) { if (!oldTags.contains(tag)) { assetTagLocalService.incrementAssetCount(tag.getTagId(), classNameId); } } } } else if (oldVisible) { for (AssetTag oldTag : oldTags) { assetTagLocalService.decrementAssetCount(oldTag.getTagId(), classNameId); } } } // Update entry after tags so that entry listeners have access to the // saved categories and tags assetEntryPersistence.update(entry); // Synchronize if (!sync) { return entry; } if (className.equals(BlogsEntry.class.getName())) { BlogsEntry blogsEntry = blogsEntryPersistence.findByPrimaryKey(classPK); blogsEntry.setTitle(title); blogsEntryPersistence.update(blogsEntry); } else if (className.equals(BookmarksEntry.class.getName())) { BookmarksEntry bookmarksEntry = bookmarksEntryPersistence.findByPrimaryKey(classPK); bookmarksEntry.setName(title); bookmarksEntry.setDescription(description); bookmarksEntry.setUrl(url); bookmarksEntryPersistence.update(bookmarksEntry); } else if (className.equals(DLFileEntry.class.getName())) { DLFileEntry dlFileEntry = dlFileEntryPersistence.findByPrimaryKey(classPK); dlFileEntry.setTitle(title); dlFileEntry.setDescription(description); dlFileEntryPersistence.update(dlFileEntry); } else if (className.equals(JournalArticle.class.getName())) { JournalArticle journalArticle = journalArticlePersistence.findByPrimaryKey(classPK); journalArticle.setTitle(title); journalArticle.setDescription(description); journalArticlePersistence.update(journalArticle); } else if (className.equals(MBMessage.class.getName())) { MBMessage mbMessage = mbMessagePersistence.findByPrimaryKey(classPK); mbMessage.setSubject(title); mbMessagePersistence.update(mbMessage); } else if (className.equals(WikiPage.class.getName())) { WikiPage wikiPage = wikiPagePersistence.findByPrimaryKey(classPK); wikiPage.setTitle(title); wikiPagePersistence.update(wikiPage); } return entry; }