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

    PortletDataHandler portletDataHandler =
        _portletDataHandlerProvider.provide(companyId, portletId);

    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;
        }
      }
    }
  }