List of usage examples for com.liferay.portal.kernel.exception PortletIdException PortletIdException
public PortletIdException(Throwable cause)
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 . j a va 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); } // 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; } } } }