@Test
  public void testValidateMissingReferences() throws Exception {
    String xml = replaceParameters(getContent("missing_references.txt"), _fileEntry);

    ZipWriter zipWriter = ZipWriterFactoryUtil.getZipWriter();

    zipWriter.addEntry("/manifest.xml", xml);

    MissingReferences missingReferences =
        ExportImportHelperUtil.validateMissingReferences(
            TestPropsValues.getUserId(),
            _stagingGroup.getGroupId(),
            new HashMap<String, String[]>(),
            zipWriter.getFile());

    Map<String, MissingReference> dependencyMissingReferences =
        missingReferences.getDependencyMissingReferences();

    Map<String, MissingReference> weakMissingReferences =
        missingReferences.getWeakMissingReferences();

    Assert.assertEquals(2, dependencyMissingReferences.size());
    Assert.assertEquals(1, weakMissingReferences.size());

    FileUtil.delete(zipWriter.getFile());
  }
  @Test
  public void testValidateMissingReferences() throws Exception {
    String xml = replaceParameters(getContent("missing_references.txt"), _fileEntry);

    ZipWriter zipWriter = ZipWriterFactoryUtil.getZipWriter();

    zipWriter.addEntry("/manifest.xml", xml);

    ZipReader zipReader = ZipReaderFactoryUtil.getZipReader(zipWriter.getFile());

    _portletDataContextImport.setZipReader(zipReader);

    MissingReferences missingReferences =
        ExportImportHelperUtil.validateMissingReferences(_portletDataContextImport);

    Map<String, MissingReference> dependencyMissingReferences =
        missingReferences.getDependencyMissingReferences();

    Map<String, MissingReference> weakMissingReferences =
        missingReferences.getWeakMissingReferences();

    Assert.assertEquals(2, dependencyMissingReferences.size());
    Assert.assertEquals(1, weakMissingReferences.size());

    FileUtil.delete(zipWriter.getFile());

    zipReader.close();
  }
 private void exportConfig(PortletDataContext context, String portletId, long communityId)
     throws IOException {
   String configString = configurationService.readConfigAsString(portletId, communityId);
   if (configString != null) {
     ZipWriter zipWriter = context.getZipWriter();
     String filePath = portletId + "/portletConfiguration.xml";
     zipWriter.addEntry(filePath, configString);
   }
 }
  public void addZipEntry(String path, String s) throws SystemException {
    if (_portletDataContextListener != null) {
      _portletDataContextListener.onAddZipEntry(path);
    }

    try {
      ZipWriter zipWriter = getZipWriter();

      zipWriter.addEntry(path, s);
    } catch (IOException ioe) {
      throw new SystemException(ioe);
    }
  }
  protected void exportThemeFiles(String path, File dir, ZipWriter zipWriter) throws Exception {

    if ((dir == null) || !dir.exists()) {
      return;
    }

    File[] files = dir.listFiles();

    for (File file : files) {
      if (file.isDirectory()) {
        exportThemeFiles(path + StringPool.SLASH + file.getName(), file, zipWriter);
      } else {
        zipWriter.addEntry(path + StringPool.SLASH + file.getName(), FileUtil.getBytes(file));
      }
    }
  }
  protected void exportTheme(LayoutSet layoutSet, ZipWriter zipWriter) throws Exception {

    Theme theme = layoutSet.getTheme();

    String lookAndFeelXML =
        ContentUtil.get("com/liferay/portal/dependencies/liferay-look-and-feel.xml.tmpl");

    lookAndFeelXML =
        StringUtil.replace(
            lookAndFeelXML,
            new String[] {"[$TEMPLATE_EXTENSION$]", "[$VIRTUAL_PATH$]"},
            new String[] {theme.getTemplateExtension(), theme.getVirtualPath()});

    String servletContextName = theme.getServletContextName();

    ServletContext servletContext = ServletContextPool.get(servletContextName);

    if (servletContext == null) {
      if (_log.isWarnEnabled()) {
        _log.warn("Servlet context not found for theme " + theme.getThemeId());
      }

      return;
    }

    File themeZip = new File(zipWriter.getPath() + "/theme.zip");

    ZipWriter themeZipWriter = ZipWriterFactoryUtil.getZipWriter(themeZip);

    themeZipWriter.addEntry("liferay-look-and-feel.xml", lookAndFeelXML);

    File cssPath = null;
    File imagesPath = null;
    File javaScriptPath = null;
    File templatesPath = null;

    if (!theme.isLoadFromServletContext()) {
      ThemeLoader themeLoader = ThemeLoaderFactory.getThemeLoader(servletContextName);

      if (themeLoader == null) {
        _log.error(servletContextName + " does not map to a theme loader");
      } else {
        String realPath =
            themeLoader.getFileStorage().getPath() + StringPool.SLASH + theme.getName();

        cssPath = new File(realPath + "/css");
        imagesPath = new File(realPath + "/images");
        javaScriptPath = new File(realPath + "/javascript");
        templatesPath = new File(realPath + "/templates");
      }
    } else {
      cssPath = new File(servletContext.getRealPath(theme.getCssPath()));
      imagesPath = new File(servletContext.getRealPath(theme.getImagesPath()));
      javaScriptPath = new File(servletContext.getRealPath(theme.getJavaScriptPath()));
      templatesPath = new File(servletContext.getRealPath(theme.getTemplatesPath()));
    }

    exportThemeFiles("css", cssPath, themeZipWriter);
    exportThemeFiles("images", imagesPath, themeZipWriter);
    exportThemeFiles("javascript", javaScriptPath, themeZipWriter);
    exportThemeFiles("templates", templatesPath, themeZipWriter);
  }