List of usage examples for com.liferay.portal.kernel.language LanguageUtil getAvailableLocales
public static Set<Locale> getAvailableLocales(long groupId)
From source file:com.liferay.document.library.internal.instance.lifecycle.AddDefaultDocumentLibraryStructuresPortalInstanceLifecycleListener.java
License:Open Source License
protected void addDLFileEntryType(long userId, long groupId, String languageKey, String dlFileEntryTypeKey, List<String> ddmStructureNames, ServiceContext serviceContext) throws Exception { List<Long> ddmStructureIds = new ArrayList<>(); for (String ddmStructureName : ddmStructureNames) { String ddmStructureKey = ddmStructureName; DDMStructure ddmStructure = _ddmStructureLocalService.fetchStructure(groupId, _portal.getClassNameId(DLFileEntryMetadata.class), ddmStructureKey); if (ddmStructure == null) { continue; }//w w w .ja va 2 s .c om ddmStructureIds.add(ddmStructure.getStructureId()); } Locale locale = _portal.getSiteDefaultLocale(groupId); String definition = _defaultDDMStructureHelper.getDynamicDDMStructureDefinition(getClassLoader(), "com/liferay/document/library/events/dependencies" + "/document-library-structures.xml", languageKey, locale); DDMForm ddmForm = _ddmFormXSDDeserializer.deserialize(definition); serviceContext.setAttribute("ddmForm", _ddmBeanTranslator.translate(ddmForm)); DLFileEntryType dlFileEntryType = _dlFileEntryTypeLocalService.fetchFileEntryType(groupId, dlFileEntryTypeKey); if (dlFileEntryType == null) { Map<Locale, String> localizationMap = new HashMap<>(); for (Locale curLocale : LanguageUtil.getAvailableLocales(groupId)) { localizationMap.put(curLocale, LanguageUtil.get(curLocale, languageKey)); } _dlFileEntryTypeLocalService.addFileEntryType(userId, groupId, dlFileEntryTypeKey, localizationMap, localizationMap, ArrayUtil.toArray(ddmStructureIds.toArray(new Long[ddmStructureIds.size()])), serviceContext); } }
From source file:com.liferay.dynamic.data.mapping.internal.util.DefaultDDMStructureHelperImpl.java
License:Open Source License
@Override public void addDDMStructures(long userId, long groupId, long classNameId, ClassLoader classLoader, String fileName, ServiceContext serviceContext) throws Exception { Locale locale = _portal.getSiteDefaultLocale(groupId); List<Element> structureElements = getDDMStructures(classLoader, fileName, locale); for (Element structureElement : structureElements) { boolean dynamicStructure = GetterUtil.getBoolean(structureElement.elementText("dynamic-structure")); if (dynamicStructure) { continue; }//from w w w .j a v a 2 s. co m String name = structureElement.elementText("name"); String description = structureElement.elementText("description"); String ddmStructureKey = name; DDMStructure ddmStructure = _ddmStructureLocalService.fetchStructure(groupId, classNameId, ddmStructureKey); if (ddmStructure != null) { continue; } if (name.equals(DLFileEntryTypeConstants.NAME_IG_IMAGE) && !UpgradeProcessUtil.isCreateIGImageDocumentType()) { continue; } String ddmTemplateKey = name; Map<Locale, String> nameMap = new HashMap<>(); Map<Locale, String> descriptionMap = new HashMap<>(); for (Locale curLocale : LanguageUtil.getAvailableLocales(groupId)) { nameMap.put(curLocale, LanguageUtil.get(curLocale, name)); descriptionMap.put(curLocale, LanguageUtil.get(curLocale, description)); } DDMForm ddmForm = getDDMForm(structureElement, locale); DDMFormLayout ddmFormLayout = getDDMFormLayout(structureElement, ddmForm); serviceContext.setAttribute("status", WorkflowConstants.STATUS_APPROVED); ddmStructure = _ddmStructureLocalService.addStructure(userId, groupId, DDMStructureConstants.DEFAULT_PARENT_STRUCTURE_ID, classNameId, ddmStructureKey, nameMap, descriptionMap, ddmForm, ddmFormLayout, StorageType.JSON.toString(), DDMStructureConstants.TYPE_DEFAULT, serviceContext); Element templateElement = structureElement.element("template"); if (templateElement == null) { continue; } String templateFileName = templateElement.elementText("file-name"); String script = StringUtil.read(classLoader, FileUtil.getPath(fileName) + StringPool.SLASH + templateFileName); boolean cacheable = GetterUtil.getBoolean(templateElement.elementText("cacheable")); _ddmTemplateLocalService.addTemplate(userId, groupId, _portal.getClassNameId(DDMStructure.class), ddmStructure.getStructureId(), ddmStructure.getClassNameId(), ddmTemplateKey, nameMap, null, DDMTemplateConstants.TEMPLATE_TYPE_DISPLAY, DDMTemplateConstants.TEMPLATE_MODE_CREATE, TemplateConstants.LANG_TYPE_FTL, script, cacheable, false, StringPool.BLANK, null, serviceContext); } }
From source file:com.liferay.exportimport.controller.LayoutExportController.java
License:Open Source License
protected File doExport(PortletDataContext portletDataContext) throws Exception { Map<String, String[]> parameterMap = portletDataContext.getParameterMap(); boolean ignoreLastPublishDate = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.IGNORE_LAST_PUBLISH_DATE); boolean permissions = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PERMISSIONS); if (_log.isDebugEnabled()) { _log.debug("Export permissions " + permissions); }/*from w w w .j a va 2 s .c o m*/ long companyId = portletDataContext.getCompanyId(); long defaultUserId = _userLocalService.getDefaultUserId(companyId); ServiceContext serviceContext = ServiceContextThreadLocal.popServiceContext(); if (serviceContext == null) { serviceContext = new ServiceContext(); } serviceContext.setCompanyId(companyId); serviceContext.setSignedIn(true); if (BackgroundTaskThreadLocal.hasBackgroundTask()) { BackgroundTask backgroundTask = _backgroundTaskLocalService .getBackgroundTask(BackgroundTaskThreadLocal.getBackgroundTaskId()); serviceContext.setUserId(backgroundTask.getUserId()); } else { serviceContext.setUserId(defaultUserId); } serviceContext.setAttribute("exporting", Boolean.TRUE); long layoutSetBranchId = MapUtil.getLong(parameterMap, "layoutSetBranchId"); serviceContext.setAttribute("layoutSetBranchId", layoutSetBranchId); ServiceContextThreadLocal.pushServiceContext(serviceContext); if (ignoreLastPublishDate) { portletDataContext.setEndDate(null); portletDataContext.setStartDate(null); } StopWatch stopWatch = new StopWatch(); stopWatch.start(); 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(portletDataContext.getScopeGroupId()))); headerElement.addAttribute("build-number", String.valueOf(ReleaseInfo.getBuildNumber())); headerElement.addAttribute("schema-version", ExportImportConstants.EXPORT_IMPORT_SCHEMA_VERSION); 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("company-id", String.valueOf(portletDataContext.getCompanyId())); headerElement.addAttribute("company-group-id", String.valueOf(portletDataContext.getCompanyGroupId())); headerElement.addAttribute("group-id", String.valueOf(portletDataContext.getGroupId())); headerElement.addAttribute("user-personal-site-group-id", String.valueOf(portletDataContext.getUserPersonalSiteGroupId())); headerElement.addAttribute("private-layout", String.valueOf(portletDataContext.isPrivateLayout())); Group group = _groupLocalService.fetchGroup(portletDataContext.getGroupId()); String type = "layout-set"; if (group.isLayoutPrototype()) { type = "layout-prototype"; LayoutPrototype layoutPrototype = _layoutPrototypeLocalService.getLayoutPrototype(group.getClassPK()); headerElement.addAttribute("type-uuid", layoutPrototype.getUuid()); } else if (group.isLayoutSetPrototype()) { type = "layout-set-prototype"; LayoutSetPrototype layoutSetPrototype = _layoutSetPrototypeLocalService .getLayoutSetPrototype(group.getClassPK()); headerElement.addAttribute("type-uuid", layoutSetPrototype.getUuid()); } headerElement.addAttribute("type", type); portletDataContext.setType(type); Element missingReferencesElement = rootElement.addElement("missing-references"); portletDataContext.setMissingReferencesElement(missingReferencesElement); rootElement.addElement("site-portlets"); rootElement.addElement("site-services"); // Export the group LayoutSet layoutSet = _layoutSetLocalService.getLayoutSet(portletDataContext.getGroupId(), portletDataContext.isPrivateLayout()); String layoutSetPrototypeUuid = layoutSet.getLayoutSetPrototypeUuid(); boolean layoutSetPrototypeSettings = MapUtil.getBoolean(portletDataContext.getParameterMap(), PortletDataHandlerKeys.LAYOUT_SET_PROTOTYPE_SETTINGS); if (!group.isStaged() && Validator.isNotNull(layoutSetPrototypeUuid) && layoutSetPrototypeSettings) { LayoutSetPrototype layoutSetPrototype = _layoutSetPrototypeLocalService .getLayoutSetPrototypeByUuidAndCompanyId(layoutSetPrototypeUuid, companyId); headerElement.addAttribute("layout-set-prototype-uuid", layoutSetPrototypeUuid); headerElement.addAttribute("layout-set-prototype-name", layoutSetPrototype.getName(LocaleUtil.getDefault())); } StagedGroup stagedGroup = ModelAdapterUtil.adapt(group, Group.class, StagedGroup.class); StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, stagedGroup); // Export other models _portletExportController.exportAssetLinks(portletDataContext); _portletExportController.exportExpandoTables(portletDataContext); _portletExportController.exportLocks(portletDataContext); portletDataContext.addDeletionSystemEventStagedModelTypes(new StagedModelType(StagedAssetLink.class)); _deletionSystemEventExporter.exportDeletionSystemEvents(portletDataContext); if (permissions) { _permissionExporter.exportPortletDataPermissions(portletDataContext); } _exportImportHelper.writeManifestSummary(document, portletDataContext.getManifestSummary()); if (_log.isInfoEnabled()) { _log.info("Exporting layouts takes " + stopWatch.getTime() + " ms"); } portletDataContext.addZipEntry("/manifest.xml", document.formattedString()); ZipWriter zipWriter = portletDataContext.getZipWriter(); return zipWriter.getFile(); }
From source file:com.liferay.exportimport.controller.LayoutImportController.java
License:Open Source License
protected void validateFile(long companyId, long groupId, Map<String, String[]> parameterMap, ZipReader zipReader) throws Exception { // XML//w ww . j av a 2 s. c o m String xml = zipReader.getEntryAsString("/manifest.xml"); if (xml == null) { throw new LARFileException(LARFileException.TYPE_MISSING_MANIFEST); } Element rootElement = null; try { Document document = SAXReaderUtil.read(xml); rootElement = document.getRootElement(); } catch (Exception e) { throw new LARFileException(LARFileException.TYPE_INVALID_MANIFEST, e); } // Bundle compatibility Element headerElement = rootElement.element("header"); int importBuildNumber = GetterUtil.getInteger(headerElement.attributeValue("build-number")); if (importBuildNumber < ReleaseInfo.RELEASE_7_0_0_BUILD_NUMBER) { int buildNumber = ReleaseInfo.getBuildNumber(); if (buildNumber != importBuildNumber) { throw new LayoutImportException(LayoutImportException.TYPE_WRONG_BUILD_NUMBER, new Object[] { importBuildNumber, buildNumber }); } } else { BiPredicate<Version, Version> majorVersionBiPredicate = (currentVersion, importVersion) -> Objects .equals(currentVersion.getMajor(), importVersion.getMajor()); BiPredicate<Version, Version> minorVersionBiPredicate = (currentVersion, importVersion) -> { int currentMinorVersion = GetterUtil.getInteger(currentVersion.getMinor(), -1); int importedMinorVersion = GetterUtil.getInteger(importVersion.getMinor(), -1); if (((currentMinorVersion == -1) && (importedMinorVersion == -1)) || (currentMinorVersion < importedMinorVersion)) { return false; } return true; }; BiPredicate<Version, Version> manifestVersionBiPredicate = (currentVersion, importVersion) -> { BiPredicate<Version, Version> versionBiPredicate = majorVersionBiPredicate .and(minorVersionBiPredicate); return versionBiPredicate.test(currentVersion, importVersion); }; String importSchemaVersion = GetterUtil.getString(headerElement.attributeValue("schema-version"), "1.0.0"); if (!manifestVersionBiPredicate.test( Version.getInstance(ExportImportConstants.EXPORT_IMPORT_SCHEMA_VERSION), Version.getInstance(importSchemaVersion))) { throw new LayoutImportException(LayoutImportException.TYPE_WRONG_LAR_SCHEMA_VERSION, new Object[] { importSchemaVersion, ExportImportConstants.EXPORT_IMPORT_SCHEMA_VERSION }); } } // Type String larType = headerElement.attributeValue("type"); String[] expectedLARTypes = { "layout-prototype", "layout-set", "layout-set-prototype" }; Stream<String> stream = Stream.of(expectedLARTypes); if (stream.noneMatch(lt -> lt.equals(larType))) { throw new LARTypeException(larType, expectedLARTypes); } Group group = _groupLocalService.fetchGroup(groupId); String layoutsImportMode = MapUtil.getString(parameterMap, PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE); if (larType.equals("layout-prototype") && !group.isLayoutPrototype() && !layoutsImportMode.equals(PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_CREATED_FROM_PROTOTYPE)) { throw new LARTypeException(LARTypeException.TYPE_LAYOUT_PROTOTYPE); } if (larType.equals("layout-set")) { if (group.isLayoutPrototype() || group.isLayoutSetPrototype()) { throw new LARTypeException(LARTypeException.TYPE_LAYOUT_SET); } long sourceCompanyGroupId = GetterUtil.getLong(headerElement.attributeValue("company-group-id")); long sourceGroupId = GetterUtil.getLong(headerElement.attributeValue("group-id")); boolean companySourceGroup = false; if (sourceCompanyGroupId == sourceGroupId) { companySourceGroup = true; } if (group.isCompany() ^ companySourceGroup) { throw new LARTypeException(LARTypeException.TYPE_COMPANY_GROUP); } } if (larType.equals("layout-set-prototype") && !group.isLayoutSetPrototype() && !layoutsImportMode.equals(PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_CREATED_FROM_PROTOTYPE)) { throw new LARTypeException(LARTypeException.TYPE_LAYOUT_SET_PROTOTYPE); } // Portlets compatibility List<Element> portletElements = fetchPortletElements(rootElement); for (Element portletElement : portletElements) { String portletId = GetterUtil.getString(portletElement.attributeValue("portlet-id")); if (Validator.isNull(portletId)) { continue; } String schemaVersion = GetterUtil.getString(portletElement.attributeValue("schema-version")); PortletDataHandler portletDataHandler = _portletDataHandlerProvider.provide(companyId, portletId); if (portletDataHandler == null) { continue; } if (!portletDataHandler.validateSchemaVersion(schemaVersion)) { throw new LayoutImportException(LayoutImportException.TYPE_WRONG_PORTLET_SCHEMA_VERSION, new Object[] { schemaVersion, portletId, portletDataHandler.getSchemaVersion() }); } } // Available locales List<Locale> sourceAvailableLocales = Arrays.asList( LocaleUtil.fromLanguageIds(StringUtil.split(headerElement.attributeValue("available-locales")))); for (Locale sourceAvailableLocale : sourceAvailableLocales) { if (!LanguageUtil.isAvailableLocale(groupId, sourceAvailableLocale)) { LocaleException le = new LocaleException(LocaleException.TYPE_EXPORT_IMPORT); le.setSourceAvailableLocales(sourceAvailableLocales); le.setTargetAvailableLocales(LanguageUtil.getAvailableLocales(groupId)); throw le; } } // Layout prototypes validity Element layoutsElement = rootElement.element(Layout.class.getSimpleName()); validateLayoutPrototypes(companyId, headerElement, layoutsElement); }
From source file:com.liferay.exportimport.controller.PortletExportController.java
License:Open Source License
protected File doExport(PortletDataContext portletDataContext) throws Exception { boolean exportPermissions = MapUtil.getBoolean(portletDataContext.getParameterMap(), PortletDataHandlerKeys.PERMISSIONS); if (_log.isDebugEnabled()) { _log.debug("Export permissions " + exportPermissions); }/*from ww w . j ava2s .c om*/ StopWatch stopWatch = new StopWatch(); stopWatch.start(); Layout layout = _layoutLocalService.getLayout(portletDataContext.getPlid()); if (!layout.isTypeControlPanel() && !layout.isTypePanel() && !layout.isTypePortlet()) { StringBundler sb = new StringBundler(4); sb.append("Unable to export layout "); sb.append(layout.getPlid()); sb.append(" because it has an invalid type: "); sb.append(layout.getType()); throw new LayoutImportException(sb.toString()); } 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(_portal.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", portletDataContext.getType()); 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()); headerElement.addAttribute("schema-version", ExportImportConstants.EXPORT_IMPORT_SCHEMA_VERSION); Element missingReferencesElement = rootElement.addElement("missing-references"); portletDataContext.setMissingReferencesElement(missingReferencesElement); Map<String, Boolean> exportPortletControlsMap = _exportImportHelper.getExportPortletControlsMap( layout.getCompanyId(), portletDataContext.getPortletId(), portletDataContext.getParameterMap()); exportPortlet(portletDataContext, layout.getPlid(), 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); portletDataContext.addDeletionSystemEventStagedModelTypes(new StagedModelType(StagedAssetLink.class)); _deletionSystemEventExporter.exportDeletionSystemEvents(portletDataContext); if (exportPermissions) { _permissionExporter.exportPortletDataPermissions(portletDataContext); } _exportImportHelper.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("Unable to create the export LAR manifest file for portlet " + portletDataContext.getPortletId(), ioe); } ZipWriter zipWriter = portletDataContext.getZipWriter(); return zipWriter.getFile(); }
From source file:com.liferay.exportimport.controller.PortletImportController.java
License:Open Source License
protected void validateFile(long companyId, long groupId, String portletId, ZipReader zipReader) throws Exception { // XML/*from ww w. ja v a 2 s .co m*/ String xml = zipReader.getEntryAsString("/manifest.xml"); if (xml == null) { throw new LARFileException(LARFileException.TYPE_MISSING_MANIFEST); } Element rootElement = null; try { Document document = SAXReaderUtil.read(xml); rootElement = document.getRootElement(); } catch (Exception e) { throw new LARFileException(LARFileException.TYPE_INVALID_MANIFEST, e); } // Build compatibility Element headerElement = rootElement.element("header"); Element portletElement = rootElement.element("portlet"); int importBuildNumber = GetterUtil.getInteger(headerElement.attributeValue("build-number")); if (importBuildNumber < ReleaseInfo.RELEASE_7_0_0_BUILD_NUMBER) { int buildNumber = ReleaseInfo.getBuildNumber(); throw new LayoutImportException(LayoutImportException.TYPE_WRONG_BUILD_NUMBER, new Object[] { importBuildNumber, buildNumber }); } else { BiPredicate<Version, Version> majorVersionBiPredicate = (currentVersion, importVersion) -> Objects .equals(currentVersion.getMajor(), importVersion.getMajor()); BiPredicate<Version, Version> minorVersionBiPredicate = (currentVersion, importVersion) -> { int currentMinorVersion = GetterUtil.getInteger(currentVersion.getMinor(), -1); int importedMinorVersion = GetterUtil.getInteger(importVersion.getMinor(), -1); if (((currentMinorVersion == -1) && (importedMinorVersion == -1)) || (currentMinorVersion < importedMinorVersion)) { return false; } return true; }; BiPredicate<Version, Version> manifestVersionBiPredicate = (currentVersion, importVersion) -> { BiPredicate<Version, Version> versionBiPredicate = majorVersionBiPredicate .and(minorVersionBiPredicate); return versionBiPredicate.test(currentVersion, importVersion); }; String importSchemaVersion = GetterUtil.getString(headerElement.attributeValue("schema-version"), "1.0.0"); if (!manifestVersionBiPredicate.test( Version.getInstance(ExportImportConstants.EXPORT_IMPORT_SCHEMA_VERSION), Version.getInstance(importSchemaVersion))) { throw new LayoutImportException(LayoutImportException.TYPE_WRONG_LAR_SCHEMA_VERSION, new Object[] { importSchemaVersion, ExportImportConstants.EXPORT_IMPORT_SCHEMA_VERSION }); } } // Type String larType = headerElement.attributeValue("type"); if (!larType.equals("portlet")) { throw new LARTypeException(larType, new String[] { "portlet" }); } // Portlet compatibility String rootPortletId = headerElement.attributeValue("root-portlet-id"); String expectedRootPortletId = PortletIdCodec.decodePortletName(portletId); if (!expectedRootPortletId.equals(rootPortletId)) { throw new PortletIdException(expectedRootPortletId); } String schemaVersion = GetterUtil.getString(portletElement.attributeValue("schema-version"), "1.0.0"); PortletDataHandler portletDataHandler = _portletDataHandlerProvider.provide(companyId, portletId); if (!portletDataHandler.validateSchemaVersion(schemaVersion)) { throw new LayoutImportException(LayoutImportException.TYPE_WRONG_PORTLET_SCHEMA_VERSION, new Object[] { schemaVersion, portletId, portletDataHandler.getSchemaVersion() }); } // Available locales if (portletDataHandler.isDataLocalized()) { List<Locale> sourceAvailableLocales = Arrays.asList(LocaleUtil .fromLanguageIds(StringUtil.split(headerElement.attributeValue("available-locales")))); for (Locale sourceAvailableLocale : sourceAvailableLocales) { if (!LanguageUtil.isAvailableLocale(_portal.getSiteGroupId(groupId), sourceAvailableLocale)) { LocaleException le = new LocaleException(LocaleException.TYPE_EXPORT_IMPORT); le.setSourceAvailableLocales(sourceAvailableLocales); le.setTargetAvailableLocales(LanguageUtil.getAvailableLocales(_portal.getSiteGroupId(groupId))); throw le; } } } }
From source file:com.liferay.frontend.taglib.servlet.taglib.soy.TranslationManagerTag.java
License:Open Source License
@Override public int doStartTag() { JSONArray availableLocalesJSONArray = JSONFactoryUtil.createJSONArray(); JSONObject localesJSONObject = JSONFactoryUtil.createJSONObject(); ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); Set<Locale> locales = LanguageUtil.getAvailableLocales(themeDisplay.getSiteGroupId()); for (Locale locale : locales) { String languageId = LocaleUtil.toLanguageId(locale); if (ArrayUtil.contains(_availableLocales, locale)) { availableLocalesJSONArray.put(languageId); }/*from w ww . j a va2 s.c o m*/ JSONObject localeJSONObject = JSONFactoryUtil.createJSONObject(); String w3cLanguageId = LocaleUtil.toW3cLanguageId(locale); localeJSONObject.put("code", w3cLanguageId); localeJSONObject.put("icon", StringUtil.toLowerCase(w3cLanguageId)); localeJSONObject.put("id", languageId); localeJSONObject.put("name", locale.getDisplayName(themeDisplay.getLocale())); localesJSONObject.put(languageId, localeJSONObject); } putValue("availableLocales", availableLocalesJSONArray); putValue("locales", localesJSONObject); putValue("pathThemeImages", themeDisplay.getPathThemeImages()); setTemplateNamespace("TranslationManager.render"); return super.doStartTag(); }
From source file:com.liferay.hook.indexer.MBMessageIndexerPostProcessor.java
License:Open Source License
@Override public void postProcessDocument(Document document, Object object) throws Exception { MBMessage mbMessage = (MBMessage) object; Map<Locale, String> contentsMap = new HashMap<Locale, String>(); Map<Locale, String> titleMap = new HashMap<Locale, String>(); // Get all avilable languages of this site to create indexs for all of // them./*from w ww . j av a 2s. c o m*/ // // To get Site Language, use LocaleThreadLocal.getSiteDefaultLocale() // To get Display language, use // LocaleThreadLocal.getThemeDisplayLocale() Long groupId = mbMessage.getGroupId(); Locale locales[] = LanguageUtil.getAvailableLocales(groupId); String content = document.get(Field.CONTENT); String title = document.get(Field.TITLE); if (content.length() <= 0) { return; } for (int i = 0; i < locales.length; i++) { contentsMap.put(locales[i], content); titleMap.put(locales[i], title); } document.addLocalizedText(Field.TITLE, titleMap); document.addLocalizedText(Field.CONTENT, contentsMap); }
From source file:com.liferay.journal.internal.upgrade.v0_0_3.UpgradeJournalArticleType.java
License:Open Source License
protected void updateArticleType() throws Exception { try (LoggingTimer loggingTimer = new LoggingTimer()) { if (!hasSelectedArticleTypes()) { return; }// w ww. j a v a 2s . c o m List<String> types = getArticleTypes(); if (types.size() <= 0) { return; } Locale localeThreadLocalDefaultLocale = LocaleThreadLocal.getDefaultLocale(); try { List<Company> companies = _companyLocalService.getCompanies(); for (Company company : companies) { LocaleThreadLocal.setDefaultLocale(company.getLocale()); Set<Locale> locales = LanguageUtil.getAvailableLocales(company.getGroupId()); Locale defaultLocale = LocaleUtil .fromLanguageId(UpgradeProcessUtil.getDefaultLanguageId(company.getCompanyId())); Map<Locale, String> nameMap = LocalizationUtil.getLocalizationMap(locales, defaultLocale, "type"); AssetVocabulary assetVocabulary = addAssetVocabulary(company.getGroupId(), company.getCompanyId(), "type", nameMap, new HashMap<Locale, String>()); Map<String, Long> journalArticleTypesToAssetCategoryIds = new HashMap<>(); for (String type : types) { AssetCategory assetCategory = addAssetCategory(company.getGroupId(), company.getCompanyId(), type, assetVocabulary.getVocabularyId()); journalArticleTypesToAssetCategoryIds.put(type, assetCategory.getCategoryId()); } updateArticles(company.getCompanyId(), journalArticleTypesToAssetCategoryIds); } } finally { LocaleThreadLocal.setDefaultLocale(localeThreadLocalDefaultLocale); } } }
From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
protected void validate(long companyId, long groupId, long classNameId, Map<Locale, String> titleMap, String content, String ddmStructureKey, String ddmTemplateKey, Date displayDate, Date expirationDate, boolean smallImage, String smallImageURL, File smallImageFile, byte[] smallImageBytes, ServiceContext serviceContext) throws PortalException { Locale articleDefaultLocale = LocaleUtil.fromLanguageId(LocalizationUtil.getDefaultLanguageId(content)); if (!ExportImportThreadLocal.isImportInProcess()) { if (!LanguageUtil.isAvailableLocale(groupId, articleDefaultLocale)) { LocaleException le = new LocaleException(LocaleException.TYPE_CONTENT, "The locale " + articleDefaultLocale + " is not available in site with groupId" + groupId); le.setSourceAvailableLocales(Collections.singleton(articleDefaultLocale)); le.setTargetAvailableLocales(LanguageUtil.getAvailableLocales(groupId)); throw le; }//from w ww.j a v a 2s . c o m if ((expirationDate != null) && (expirationDate.before(new Date()) || ((displayDate != null) && expirationDate.before(displayDate)))) { throw new ArticleExpirationDateException("Expiration date " + expirationDate + " is in the past"); } } if ((classNameId == JournalArticleConstants.CLASSNAME_ID_DEFAULT) && (titleMap.isEmpty() || Validator.isNull(titleMap.get(articleDefaultLocale)))) { throw new ArticleTitleException("Title is null"); } validateContent(content); DDMStructure ddmStructure = ddmStructureLocalService.getStructure(PortalUtil.getSiteGroupId(groupId), classNameLocalService.getClassNameId(JournalArticle.class), ddmStructureKey, true); validateDDMStructureFields(ddmStructure, classNameId, content, articleDefaultLocale); if (Validator.isNotNull(ddmTemplateKey)) { DDMTemplate ddmTemplate = ddmTemplateLocalService.getTemplate(PortalUtil.getSiteGroupId(groupId), classNameLocalService.getClassNameId(DDMStructure.class), ddmTemplateKey, true); if (ddmTemplate.getClassPK() != ddmStructure.getStructureId()) { throw new NoSuchTemplateException("{templateKey=" + ddmTemplateKey + "}"); } } else if (classNameId == JournalArticleConstants.CLASSNAME_ID_DEFAULT) { throw new NoSuchTemplateException("DDM template key is null"); } if (!smallImage || Validator.isNotNull(smallImageURL) || (smallImageFile == null) || (smallImageBytes == null)) { return; } String smallImageName = smallImageFile.getName(); boolean validSmallImageExtension = false; for (String imageExtension : _journalFileUploadsConfiguration.imageExtensions()) { if (StringPool.STAR.equals(imageExtension) || StringUtil.endsWith(smallImageName, imageExtension)) { validSmallImageExtension = true; break; } } if (!validSmallImageExtension) { throw new ArticleSmallImageNameException(smallImageName); } long smallImageMaxSize = _journalFileUploadsConfiguration.smallImageMaxSize(); if ((smallImageMaxSize > 0) && (smallImageBytes.length > smallImageMaxSize)) { throw new ArticleSmallImageSizeException(smallImageBytes.length + " exceeds " + smallImageMaxSize); } }