<commit_before>/*
 * Copyright 2005 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.jackrabbit.server.io;

import org.apache.log4j.Logger;
import org.apache.jackrabbit.util.Text;
import org.apache.jackrabbit.JcrConstants;

import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.NodeIterator;
import javax.jcr.Item;
import javax.jcr.Property;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
 * <code>ZipHandler</code> imports and extracts Zip files and exported nodes
 * (an their subnodes) to a Zip file. Please not that for the export the selected
 * export root must have the property {@link #ZIP_MIMETYPE} defined with its
 * content. Furthermore the content must not represent a zip-file that has
 * been imported to a binary {@link Property property}, which is properly
 * handled by the {@link DefaultHandler}.
 */
public class ZipHandler extends DefaultHandler {

    private static Logger log = Logger.getLogger(ZipHandler.class);

    /**
     * the zip mimetype
     */
    public static final String ZIP_MIMETYPE = "application/zip";

    private boolean intermediateSave;

    /**
     * Creates a new <code>ZipHandler</code> with default nodetype definitions:<br>
     * <ul>
     * <li>Nodetype for Collection: {@link JcrConstants#NT_UNSTRUCTURED nt:unstructured}</li>
     * <li>Nodetype for Non-Collection: {@link JcrConstants#NT_FILE nt:file}</li>
     * <li>Nodetype for Non-Collection content: {@link JcrConstants#NT_UNSTRUCTURED nt:unstructured}</li>
     * </ul>
     *
     * @param ioManager
     * @throws IllegalArgumentException if the specified <code>IOManager</code>
     * is <code>null</code>
     */
    public ZipHandler(IOManager ioManager) {
        this(ioManager, JcrConstants.NT_UNSTRUCTURED, JcrConstants.NT_FILE, JcrConstants.NT_UNSTRUCTURED);
    }

    /**
     * Creates a new <code>ZipHandler</code>
     *
     * @param ioManager
     * @param collectionNodetype
     * @param defaultNodetype
     * @param contentNodetype<commit_msg>- using nt:folder as node type for directories instead of nt:unstructured<commit_after>/*
 * Copyright 2005 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.jackrabbit.server.io;

import org.apache.log4j.Logger;
import org.apache.jackrabbit.util.Text;
import org.apache.jackrabbit.JcrConstants;

import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.NodeIterator;
import javax.jcr.Item;
import javax.jcr.Property;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
 * <code>ZipHandler</code> imports and extracts Zip files and exported nodes
 * (an their subnodes) to a Zip file. Please not that for the export the selected
 * export root must have the property {@link #ZIP_MIMETYPE} defined with its
 * content. Furthermore the content must not represent a zip-file that has
 * been imported to a binary {@link Property property}, which is properly
 * handled by the {@link DefaultHandler}.
 */
public class ZipHandler extends DefaultHandler {

    private static Logger log = Logger.getLogger(ZipHandler.class);

    /**
     * the zip mimetype
     */
    public static final String ZIP_MIMETYPE = "application/zip";

    private boolean intermediateSave;

    /**
     * Creates a new <code>ZipHandler</code> with default nodetype definitions:<br>
     * <ul>
     * <li>Nodetype for Collection: {@link JcrConstants#NT_UNSTRUCTURED nt:unstructured}</li>
     * <li>Nodetype for Non-Collection: {@link JcrConstants#NT_FILE nt:file}</li>
     * <li>Nodetype for Non-Collection content: {@link JcrConstants#NT_UNSTRUCTURED nt:unstructured}</li>
     * </ul>
     *
     * @param ioManager
     * @throws IllegalArgumentException if the specified <code>IOManager</code>
     * is <code>null</code>
     */
    public ZipHandler(IOManager ioManager) {
        this(ioManager, JcrConstants.NT_FOLDER, JcrConstants.NT_FILE, JcrConstants.NT_UNSTRUCTURED);
    }

    /**
     * Creates a new <code>ZipHandler</code>
     *
     * @param ioManager
     * @param collectionNodetype
     * @param defaultNodetype
     * @param contentNodetype
{'fraction_non_alphanumeric': 0.09427425237053245, 'fraction_numerical': 0.0032822757111597373, 'mean_word_length': 3.8798932384341636, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5531199', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1548, 'n_words': 523}