@Override public void prepareLocalizedFieldsForImport() throws LocaleException { Locale defaultLocale = LocaleUtil.fromLanguageId(getDefaultLanguageId()); Locale[] availableLocales = LocaleUtil.fromLanguageIds(getAvailableLanguageIds()); Locale defaultImportLocale = LocalizationUtil.getDefaultImportLocale( KaleoDefinition.class.getName(), getPrimaryKey(), defaultLocale, availableLocales); prepareLocalizedFieldsForImport(defaultImportLocale); }
protected void prepareLanguagesForImport(DDMStructure structure) throws PortalException { Locale defaultLocale = LocaleUtil.fromLanguageId(structure.getDefaultLanguageId()); Locale[] availableLocales = LocaleUtil.fromLanguageIds(structure.getAvailableLanguageIds()); Locale defaultImportLocale = LocalizationUtil.getDefaultImportLocale( DDMStructure.class.getName(), structure.getPrimaryKey(), defaultLocale, availableLocales); structure.prepareLocalizedFieldsForImport(defaultImportLocale); }
protected void prepareLanguagesForImport(CalendarResource calendarResource) throws PortalException { Locale defaultLocale = LocaleUtil.fromLanguageId(calendarResource.getDefaultLanguageId()); Locale[] availableLocales = LocaleUtil.fromLanguageIds(calendarResource.getAvailableLanguageIds()); Locale defaultImportLocale = LocalizationUtil.getDefaultImportLocale( CalendarResource.class.getName(), calendarResource.getPrimaryKey(), defaultLocale, availableLocales); calendarResource.prepareLocalizedFieldsForImport(defaultImportLocale); }
@Test public void testAddFileEntryType() throws Exception { ServiceContext serviceContext = new ServiceContext(); byte[] testFileBytes = FileUtil.getBytes(getClass(), _TEST_DDM_STRUCTURE); serviceContext.setAttribute("xsd", new String(testFileBytes)); User user = TestPropsValues.getUser(); serviceContext.setLanguageId(LocaleUtil.toLanguageId(user.getLocale())); DLFileEntryType dlFileEntryType = DLFileEntryTypeLocalServiceUtil.addFileEntryType( TestPropsValues.getUserId(), _group.getGroupId(), "Test Structure", StringPool.BLANK, new long[0], serviceContext); List<DDMStructure> ddmStructures = dlFileEntryType.getDDMStructures(); Assert.assertEquals(1, ddmStructures.size()); DDMStructure ddmStructure = ddmStructures.get(0); Locale[] availableLocales = LocaleUtil.fromLanguageIds(ddmStructure.getAvailableLanguageIds()); boolean hasDefaultLocale = ArrayUtil.contains(availableLocales, LocaleUtil.getSiteDefault()); Assert.assertTrue(hasDefaultLocale); boolean hasHungarianLocale = ArrayUtil.contains(availableLocales, LocaleUtil.HUNGARY); Assert.assertTrue(hasHungarianLocale); boolean hasUserLocale = ArrayUtil.contains(availableLocales, user.getLocale()); Assert.assertTrue(hasUserLocale); DLFileEntryTypeLocalServiceUtil.deleteDLFileEntryType(dlFileEntryType); }
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; } } } }
protected long updateDDMStructure( long userId, String fileEntryTypeUuid, long fileEntryTypeId, long groupId, String name, String description, ServiceContext serviceContext) throws PortalException, SystemException { fixDDMStructureKey(fileEntryTypeUuid, fileEntryTypeId, groupId); String ddmStructureKey = DLUtil.getDDMStructureKey(fileEntryTypeUuid); Map<Locale, String> nameMap = new HashMap<Locale, String>(); Locale locale = serviceContext.getLocale(); nameMap.put(locale, name); Locale defaultLocale = LocaleUtil.getDefault(); nameMap.put(defaultLocale, name); Map<Locale, String> descriptionMap = new HashMap<Locale, String>(); descriptionMap.put(locale, description); descriptionMap.put(defaultLocale, description); String xsd = ParamUtil.getString(serviceContext, "xsd"); DDMStructure ddmStructure = ddmStructureLocalService.fetchStructure( groupId, PortalUtil.getClassNameId(DLFileEntryMetadata.class), ddmStructureKey); if ((ddmStructure != null) && Validator.isNull(xsd)) { xsd = ddmStructure.getXsd(); } Locale[] contentAvailableLocales = LocaleUtil.fromLanguageIds(LocalizationUtil.getAvailableLocales(xsd)); for (Locale contentAvailableLocale : contentAvailableLocales) { nameMap.put(contentAvailableLocale, name); descriptionMap.put(contentAvailableLocale, description); } try { if (ddmStructure == null) { ddmStructure = ddmStructureLocalService.addStructure( userId, groupId, DDMStructureConstants.DEFAULT_PARENT_STRUCTURE_ID, PortalUtil.getClassNameId(DLFileEntryMetadata.class), ddmStructureKey, nameMap, descriptionMap, xsd, "xml", DDMStructureConstants.TYPE_AUTO, serviceContext); } else { ddmStructure = ddmStructureLocalService.updateStructure( ddmStructure.getStructureId(), ddmStructure.getParentStructureId(), nameMap, descriptionMap, xsd, serviceContext); } return ddmStructure.getStructureId(); } catch (StructureXsdException sxe) { if (ddmStructure != null) { ddmStructureLocalService.deleteStructure(ddmStructure.getStructureId()); } } return 0; }