Package org.jahia.utils.zip

Examples of org.jahia.utils.zip.ZipEntry


            throws IOException {
        NoCloseZipInputStream zis = new NoCloseZipInputStream(new BufferedInputStream(new FileInputStream(file)));
        List<String[]> userProps = null;
        try {
            while (true) {
                ZipEntry zipentry = zis.getNextEntry();
                if (zipentry == null)
                    break;
                String name = zipentry.getName();
                if (name.equals("users.xml")) {
                    userProps = importUsers(zis, usersImportHandler);
                    break;
                }
                zis.closeEntry();
View Full Code Here


//        if (sizes.containsKey(REPOSITORY_XML)) {
        // Import repository content
        zis = new NoCloseZipInputStream(new BufferedInputStream(new FileInputStream(file)));
        try {
            while (true) {
                ZipEntry zipentry = zis.getNextEntry();
                if (zipentry == null) break;
                String name = zipentry.getName();
                if (name.equals(REPOSITORY_XML)) {
                    DocumentViewImportHandler documentViewImportHandler = new DocumentViewImportHandler(session, parentNodePath, file, fileList, null);

                    documentViewImportHandler.setReferences(references);
                    documentViewImportHandler.setNoRoot(noRoot);
View Full Code Here

    private void getFileList(File file, Map<String, Long> sizes, List<String> fileList) throws IOException {
        NoCloseZipInputStream zis = new NoCloseZipInputStream(new BufferedInputStream(new FileInputStream(file)));
        try {
            while (true) {
                ZipEntry zipentry = zis.getNextEntry();
                if (zipentry == null) break;
                String name = zipentry.getName().replace('\\', '/');
                if (name.endsWith(".xml")) {
                    BufferedReader br = new BufferedReader(new InputStreamReader(zis));
                    long i = 0;
                    while (br.readLine() != null) {
                        i++;
                    }
                    sizes.put(name, i);
                } else {
                    sizes.put(name, zipentry.getSize());
                }
                if (name.contains("/")) {
                    fileList.add("/" + name);
                }
                zis.closeEntry();
View Full Code Here

        }
        return missedPaths;
    }

    private void zipFileEntry(final JCRNodeWrapper file, final ZipOutputStream zout, final byte[] buffer, String rootDir) throws IOException {
        ZipEntry anEntry;
        String relativePath = file.getPath().replace(rootDir, "");
        if (!file.isFile()) {
            anEntry = new org.jahia.utils.zip.ZipEntry(relativePath + "/");
            zout.putNextEntry(anEntry);
            try {
View Full Code Here

        List<String> errorFiles = new ArrayList<String>();
        boolean result = false;
        NoCloseZipInputStream zis = null;
        try {
            zis = new NoCloseZipInputStream(in);
            ZipEntry zipentry;

            while ((zipentry = zis.getNextEntry()) != null) {
                String filename = null;
                try {
                    filename = zipentry.getName().replace('\\', '/');
                    if (logger.isDebugEnabled()) {
                        logger.debug("Unzip file (" + zipentry.getMethod() + ")" + filename);
                    }
                    if (filename.endsWith("/")) {
                        filename = filename.substring(0, filename.length() - 1);
                    }
                    int endIndex = filename.lastIndexOf('/');
                    String parentName = dest;
                    if (endIndex > -1) {
                        parentName += "/" + filename.substring(0, endIndex);
                        filename = filename.substring(endIndex + 1);
                    }
                    JCRNodeWrapper target = ensureDir(parentName, currentUserSession);

                    if (zipentry.isDirectory()) {
                        target.createCollection(JCRContentUtils.escapeLocalNodeName(filename));
                    } else {
                        String contentType = JahiaContextLoaderListener.getServletContext().getMimeType(filename);
                        target.uploadFile(filename, zis, contentType);
                    }
View Full Code Here

    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);
View Full Code Here

    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>();
View Full Code Here

            public int compare(JCRNodeWrapper o1, JCRNodeWrapper o2) {
                return o1.getPath().compareTo(o2.getPath());
            }
        });
        sortedNodes.addAll(nodes);
        zout.putNextEntry(new ZipEntry(REPOSITORY_XML));

        OutputStream outputStream = zout;
//        final String xsl = (String) params.get(XSL_PATH);
        exportNodes(rootNode, sortedNodes, outputStream, typesToIgnore, params);
        zout.closeEntry();
View Full Code Here

                            String name = child.getName().replace(":", "_");
                            if (child.getName().equals("jcr:content")) {
                                name = node.getName();
                            }
                            path += "/" + name;
                            zout.putNextEntry(new ZipEntry(path.substring(1)));
                            while ((bytesIn = is.read(buffer)) != -1) {
                                zout.write(buffer, 0, bytesIn);
                            }
                        } finally {
                            IOUtils.closeQuietly(is);
View Full Code Here

        if (sizes.containsKey(USERS_XML)) {
            // Import users first
            zis = new NoCloseZipInputStream(new BufferedInputStream(new FileInputStream(file)));
            try {
                while (true) {
                    ZipEntry zipentry = zis.getNextEntry();
                    if (zipentry == null) break;
                    String name = zipentry.getName();
                    if (name.equals(USERS_XML)) {
                        userProps = importUsers(zis, usersImportHandler);
                        break;
                    }
                    zis.closeEntry();
                }
            } finally {
                zis.reallyClose();
            }
        }

        // Check if it is an 5.x or 6.1 import :
        for (Map.Entry<String, Long> entry : sizes.entrySet()) {
            if (entry.getKey().startsWith("export_")) {
                legacyImport = true;
                break;
            }
        }

        if (sizes.containsKey(SITE_PROPERTIES)) {
            zis = new NoCloseZipInputStream(new BufferedInputStream(new FileInputStream(file)));
            try {
                while (true) {
                    ZipEntry zipentry = zis.getNextEntry();
                    if (zipentry == null) break;
                    String name = zipentry.getName();
                    if (name.equals(SITE_PROPERTIES)) {
                        importSiteProperties(zis, site);
                        break;
                    }
                    zis.closeEntry();
                }
            } finally {
                zis.reallyClose();
            }
        }

        if (sizes.containsKey(REPOSITORY_XML)) {
            // Import repository content
            zis = new NoCloseZipInputStream(new BufferedInputStream(new FileInputStream(file)));
            try {
                while (true) {
                    ZipEntry zipentry = zis.getNextEntry();
                    if (zipentry == null) break;
                    String name = zipentry.getName();
                    if (name.equals(REPOSITORY_XML)) {
                        DocumentViewImportHandler documentViewImportHandler = new DocumentViewImportHandler(session, null, file, fileList, (site != null ? site.getSiteKey(): null));

                        documentViewImportHandler.setReferences(references);
                        documentViewImportHandler.setNoRoot(true);

                        handleImport(zis, documentViewImportHandler);
                        session.save(JCRObservationManager.IMPORT);
                        break;
                    }
                    zis.closeEntry();
                }
            } catch (Exception e) {
                logger.error("Cannot import", e);
            } finally {
                zis.reallyClose();
            }
        } else {
            // No repository descriptor - prepare to import files directly
            pathMapping = session.getPathMapping();
            pathMapping.put("/", "/sites/"+site.getSiteKey()+"/files/");
        }

        NodeTypeRegistry reg = NodeTypeRegistry.getInstance();
        DefinitionsMapping mapping = null;

        // Import additional files - site.properties, old cateogries.xml , sitepermissions.xml
        // and eventual plain file from 5.x imports
        if (!sizes.containsKey(REPOSITORY_XML) || sizes.containsKey(SITE_PROPERTIES) ||
                sizes.containsKey(CATEGORIES_XML)|| sizes.containsKey(SITE_PERMISSIONS_XML) ||
                sizes.containsKey(DEFINITIONS_CND)|| sizes.containsKey(DEFINITIONS_MAP)
                ) {
            zis = new NoCloseZipInputStream(new BufferedInputStream(new FileInputStream(file)));
            try {
                while (true) {
                    ZipEntry zipentry = zis.getNextEntry();
                    if (zipentry == null) break;
                    String name = zipentry.getName();
          if (name.indexOf('\\') > -1) {
            name = name.replace('\\', '/');
          }
                    if (name.indexOf('/') > -1) {
                        if (!sizes.containsKey(REPOSITORY_XML) && !sizes.containsKey(FILESACL_XML)) {
                            // No repository descriptor - Old import format only
                            name = "/" + name;
                            if (name.startsWith("/content/sites")) {
                                name = pathMapping.get("/")
                                        + StringUtils.stripStart(name
                                                .replaceFirst("/content/sites/[^/]+/files/", ""),
                                                "/");
                            } else if (name.startsWith("/users")) {
                                Matcher m = Pattern.compile("/users/([^/]+)(/.*)?").matcher(name);
                                if (m.matches()) {
                                    name = ServicesRegistry.getInstance().getJahiaUserManagerService().getUserSplittingRule().getPathForUsername(m.group(1));
                                    name = name + "/files" + ((m.group(2) != null) ? m.group(2) : "");
                                }
                            } else if (name.startsWith("/content/users")) {
                                Matcher m = Pattern.compile("/content/users/([^/]+)(/.*)?").matcher(name);
                                if (m.matches()) {
                                    name = ServicesRegistry.getInstance().getJahiaUserManagerService().getUserSplittingRule().getPathForUsername(m.group(1));
                                    name = name + ((m.group(2) != null) ? m.group(2) : "");
                                }
                            } else {
                                name = pathMapping.get("/")
                                        + StringUtils.stripStart(name, "/");
                            }
                            if (!zipentry.isDirectory()) {
                                try {
                                    String filename = name.substring(name.lastIndexOf('/') + 1);
                                    String contentType = JahiaContextLoaderListener.getServletContext().getMimeType(filename);
                                    ensureFile(jcrStoreService.getSessionFactory().getCurrentUserSession(), name, zis, contentType, site);
                                } catch (Exception e) {
                                    logger.error("Cannot upload file " + zipentry.getName(), e);
                                }
                            } else {
                                ensureDir(jcrStoreService.getSessionFactory().getCurrentUserSession(), name, site);
                            }
                        }
                    } else if (name.equals(CATEGORIES_XML)) {
                        catProps = importCategoriesAndGetUuidProps(zis, categoriesImportHandler);
                    } else if (name.equals(DEFINITIONS_CND)) {
                        reg = new NodeTypeRegistry();
                        try {
                            if (legacyImport) {
                                JahiaCndReaderLegacy r = new JahiaCndReaderLegacy(new InputStreamReader(zis, "UTF-8"),zipentry.getName(), file.getName(), reg);
                                r.parse();
                            } else {
                                JahiaCndReader r = new JahiaCndReader(new InputStreamReader(zis, "UTF-8"),zipentry.getName(), file.getName(), reg);
                                r.parse();
                            }
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                    } else if (name.equals(DEFINITIONS_MAP)) {
                        mapping = new DefinitionsMapping();
                        mapping.load(zis);

                    }
                    zis.closeEntry();
                }
            } finally {
                zis.reallyClose();
            }
        }

        // Import legacy content from 5.x and 6.x
        if (legacyImport) {
            // Old import
            JCRNodeWrapper siteFolder = jcrStoreService.getSessionFactory().getCurrentUserSession().getNode("/sites/" + site.getSiteKey());

            zis = new NoCloseZipInputStream(new BufferedInputStream(new FileInputStream(file)));
            try {
                while (true) {
                    ZipEntry zipentry = zis.getNextEntry();
                    if (zipentry == null) break;
                    String name = zipentry.getName();
                    if (name.equals(FILESACL_XML)) {
                        importFilesAcl(site, file, zis, mapping, fileList);
                    } else if (name.startsWith("export")) {
                        String languageCode;
                        if (name.indexOf("_") != -1) {
                            languageCode = name.substring(7, name.lastIndexOf("."));
                        } else {
                            languageCode = site.getLanguagesAsLocales().iterator().next().toString();
                        }
                        zipentry.getSize();

                        LegacyImportHandler importHandler = new LegacyImportHandler(session,
                                siteFolder, reg, mapping, LanguageCodeConverters
                                        .languageCodeToLocale(languageCode),
                                infos != null ? (String)infos.get("originatingJahiaRelease")
View Full Code Here

TOP

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

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.