Package org.jahia.utils.zip

Examples of org.jahia.utils.zip.ZipOutputStream


        exportSites(outputStream, params, l);
    }

    public void exportSites(OutputStream outputStream, Map<String, Object> params, List<JahiaSite> sites)
            throws JahiaException, RepositoryException, IOException, SAXException, JDOMException {
        ZipOutputStream zout = new ZipOutputStream(outputStream);

        ZipEntry anEntry = new ZipEntry(EXPORT_PROPERTIES);
        zout.putNextEntry(anEntry);
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(zout));
        bw.write("JahiaRelease = " + Jahia.getReleaseNumber() + "\n");
        bw.write("Patch = " + Jahia.getPatchNumber() + "\n");
        bw.write("BuildNumber = " + Jahia.getBuildNumber() + "\n");
        bw.write("ExportDate = " + new SimpleDateFormat(ImportExportService.DATE_FORMAT).format(new Date()) + "\n");
        bw.flush();

        // Add system site for export
        boolean systemFound = false;
        for (JahiaSite jahiaSite : sites) {
            if (jahiaSite.getSiteKey().equals("systemsite")) {
                systemFound = true;
                break;
            }
        }
        if (!systemFound) {
            anEntry = new ZipEntry("systemsite.zip");
            zout.putNextEntry(anEntry);
            exportSystemSite(zout, params);
        }

        for (JahiaSite jahiaSite : sites) {
            anEntry = new ZipEntry(jahiaSite.getSiteKey() + ".zip");
            zout.putNextEntry(anEntry);
            exportSite(jahiaSite, zout, params);
        }

        JCRSessionWrapper session = jcrStoreService.getSessionFactory().getCurrentUserSession();

        // export shared files -->
        Set<JCRNodeWrapper> files = new HashSet<JCRNodeWrapper>();
        try {
            files.add(session.getNode("/users"));
        } catch (RepositoryException e) {
            e.printStackTrace();
            throw new IOException(e.getMessage());
        }

        zout.putNextEntry(new ZipEntry("users.zip"));
        ZipOutputStream zzout = new ZipOutputStream(zout);
        Set<String> tti = new HashSet<String>();
        tti.add(Constants.JAHIANT_VIRTUALSITE);
        try {
            exportNodesWithBinaries(session.getRootNode(), files, zzout, tti, params);
        } catch (Exception e) {
            e.printStackTrace()//To change body of catch statement use File | Settings | File Templates.
        }
        zzout.finish();
        zout.finish();
    }
View Full Code Here


        zout.finish();
    }

    private void exportSite(final JahiaSite site, OutputStream out, Map<String, Object> params)
            throws JahiaException, RepositoryException, SAXException, IOException, JDOMException {
        ZipOutputStream zout = new ZipOutputStream(out);

        zout.putNextEntry(new ZipEntry(SITE_PROPERTIES));
        exportSiteInfos(zout, site);
        final JCRSessionWrapper session = jcrStoreService.getSessionFactory().getCurrentUserSession();
        Set<JCRNodeWrapper> nodes = Collections.singleton(session.getNode("/sites/"+
                site.getSiteKey()));
        final HashSet<String> tti = new HashSet<String>();
        tti.add("jnt:templatesFolder");
        exportNodesWithBinaries(session.getRootNode(), nodes, zout, tti,
                params);
        zout.finish();
    }
View Full Code Here

    private void exportSystemSite(OutputStream out, Map<String, Object> params)
            throws JahiaException, RepositoryException, SAXException, IOException, JDOMException {
        JahiaSite site = ServicesRegistry.getInstance().getJahiaSitesService().getSiteByKey(JahiaSitesBaseService.SYSTEM_SITE_KEY);

        ZipOutputStream zout = new ZipOutputStream(out);

        final JCRSessionWrapper session = jcrStoreService.getSessionFactory().getCurrentUserSession();
        Set<JCRNodeWrapper> nodes = new HashSet<JCRNodeWrapper>();
        nodes.add(session.getNode("/sites/" + site.getSiteKey() + "/files"));
        nodes.add(session.getNode("/sites/" + site.getSiteKey() + "/contents"));
        nodes.add(session.getNode("/sites/" + site.getSiteKey() + "/portlets"));
        nodes.add(session.getNode("/sites/" + site.getSiteKey() + "/categories"));

        final HashSet<String> tti = new HashSet<String>();
        tti.add("jnt:templatesFolder");
        exportNodesWithBinaries(session.getRootNode(), nodes, zout, tti, params);
        zout.finish();
    }
View Full Code Here

        exportNodesWithBinaries(session.getRootNode(), nodes, zout, tti, params);
        zout.finish();
    }

    public void exportZip(JCRNodeWrapper node, JCRNodeWrapper exportRoot, OutputStream out, Map<String, Object> params) throws JahiaException, RepositoryException, SAXException, IOException, JDOMException {
        ZipOutputStream zout = new ZipOutputStream(out);
        Set<JCRNodeWrapper> nodes = new HashSet<JCRNodeWrapper>();
        nodes.add(node);
        exportNodesWithBinaries(exportRoot == null ? node : exportRoot, nodes, zout, new HashSet<String>(),params);
        zout.finish();
    }
View Full Code Here

    public List<String> zipFiles(final JCRNodeWrapper parentDirectory, final String zipname, final List<JCRNodeWrapper> files) {
        List<String> missedPaths = null;
        File tmp = null;
        try {
            tmp = File.createTempFile("jahiazip", null);
            final ZipOutputStream zout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(tmp)));
            final byte[] buffer = new byte[4096];
            String parentDir = parentDirectory.getPath();
            if (!parentDir.endsWith("/")) {
                parentDir = new StringBuilder(parentDir).append("/").toString();
            }
            for (JCRNodeWrapper file : files) {
                try {
                    zipFileEntry(file, zout, buffer, parentDir);
                } catch (IOException e) {
                    logger.error("Error zipping file " + file.getPath(), e);
                    if (missedPaths == null) {
                        missedPaths = new ArrayList<String>();
                    }
                    missedPaths.add(file.getPath());
                }
            }
            InputStream is = new BufferedInputStream(new FileInputStream(tmp));
            try {
                zout.close();
                JCRNodeWrapper result = parentDirectory.uploadFile(zipname, is, "application/zip");
                result.saveSession();
            } catch (IOException e) {
                logger.error("Error writing resulting zipped file", e);
                missedPaths = new ArrayList<String>();
View Full Code Here

TOP

Related Classes of org.jahia.utils.zip.ZipOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.