<commit_before>/*
 * Copyright 2017 Datalogics, Inc.
 */

package com.datalogics.pdf.samples.forms;

import com.adobe.internal.io.ByteReader;
import com.adobe.internal.io.InputStreamByteReader;
import com.adobe.pdfjt.core.exceptions.PDFConfigurationException;
import com.adobe.pdfjt.core.exceptions.PDFFontException;
import com.adobe.pdfjt.core.exceptions.PDFIOException;
import com.adobe.pdfjt.core.exceptions.PDFInvalidDocumentException;
import com.adobe.pdfjt.core.exceptions.PDFInvalidParameterException;
import com.adobe.pdfjt.core.exceptions.PDFInvalidXMLException;
import com.adobe.pdfjt.core.exceptions.PDFSecurityException;
import com.adobe.pdfjt.core.exceptions.PDFUnableToCompleteOperationException;
import com.adobe.pdfjt.pdf.document.PDFDocument;
import com.adobe.pdfjt.services.ap.AppearanceService;
import com.adobe.pdfjt.services.fdf.FDFDocument;
import com.adobe.pdfjt.services.fdf.FDFService;
import com.adobe.pdfjt.services.forms.FormFieldService;
import com.adobe.pdfjt.services.xfa.XFAService;
import com.adobe.pdfjt.services.xfa.XFAService.XFAElement;
import com.adobe.pdfjt.services.xfdf.XFDFService;

import com.datalogics.pdf.document.DocumentHelper;
import com.datalogics.pdf.samples.util.DocumentUtils;
import com.datalogics.pdf.samples.util.IoUtils;
import com.datalogics.pdf.samples.util.VersionUtils;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Locale;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

/**
 * Provide support for importing forms.
 */
public final class FormImporter {

    public enum FormType {
        FDF,
        XFDF,
        XML,
        UNKNOWN;

        /**
         * Determine the form type from a file extension.
         *
         * @param fileUrl the URL from which to determine the form type
         * @return the form type
         */
        public static FormType valueOf(final URL fileUrl) {
            if (fileUrl == null) {
                throw new IllegalArgumentException("fileUrl must not be null");
            }

            final String format;
            try {
                format = IoUtils.getFileExtensionFromUrl(fileUrl);
            } catch (final URISyntaxException e) {
                throw new IllegalArgumentException(e);
            }

            try {
                // The desired file extensions map directly onto the enum names
                return valueOf(format.toUpperCase(Locale.US));
            } catch (final IllegalArgumentException e) {
                return UNKNOWN;
            }
        }

    }

    // Some XML constants
    private static final String XFA_DATA_ROOT_NODE = "xfa:datasets";
    private static final String XFA_DATA_NS_URI = "http://www.xfa.org/schema/xfa-data/1.0/";
    private static final String XFA_DATA_CHILD_NODE = "xfa:data";


    /**
     * This is a utility class, and won't be instantiated.
     */<commit_msg>No need to catch an exception that isn't thrown.<commit_after>/*
 * Copyright 2017 Datalogics, Inc.
 */

package com.datalogics.pdf.samples.forms;

import com.adobe.internal.io.ByteReader;
import com.adobe.internal.io.InputStreamByteReader;
import com.adobe.pdfjt.core.exceptions.PDFConfigurationException;
import com.adobe.pdfjt.core.exceptions.PDFFontException;
import com.adobe.pdfjt.core.exceptions.PDFIOException;
import com.adobe.pdfjt.core.exceptions.PDFInvalidDocumentException;
import com.adobe.pdfjt.core.exceptions.PDFInvalidParameterException;
import com.adobe.pdfjt.core.exceptions.PDFInvalidXMLException;
import com.adobe.pdfjt.core.exceptions.PDFSecurityException;
import com.adobe.pdfjt.core.exceptions.PDFUnableToCompleteOperationException;
import com.adobe.pdfjt.pdf.document.PDFDocument;
import com.adobe.pdfjt.services.ap.AppearanceService;
import com.adobe.pdfjt.services.fdf.FDFDocument;
import com.adobe.pdfjt.services.fdf.FDFService;
import com.adobe.pdfjt.services.forms.FormFieldService;
import com.adobe.pdfjt.services.xfa.XFAService;
import com.adobe.pdfjt.services.xfa.XFAService.XFAElement;
import com.adobe.pdfjt.services.xfdf.XFDFService;

import com.datalogics.pdf.document.DocumentHelper;
import com.datalogics.pdf.samples.util.DocumentUtils;
import com.datalogics.pdf.samples.util.IoUtils;
import com.datalogics.pdf.samples.util.VersionUtils;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Locale;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

/**
 * Provide support for importing forms.
 */
public final class FormImporter {

    public enum FormType {
        FDF,
        XFDF,
        XML,
        UNKNOWN;

        /**
         * Determine the form type from a file extension.
         *
         * @param fileUrl the URL from which to determine the form type
         * @return the form type
         */
        public static FormType valueOf(final URL fileUrl) {
            if (fileUrl == null) {
                throw new IllegalArgumentException("fileUrl must not be null");
            }

            final String format = IoUtils.getFileExtensionFromUrl(fileUrl);

            try {
                // The desired file extensions map directly onto the enum names
                return valueOf(format.toUpperCase(Locale.US));
            } catch (final IllegalArgumentException e) {
                return UNKNOWN;
            }
        }

    }

    // Some XML constants
    private static final String XFA_DATA_ROOT_NODE = "xfa:datasets";
    private static final String XFA_DATA_NS_URI = "http://www.xfa.org/schema/xfa-data/1.0/";
    private static final String XFA_DATA_CHILD_NODE = "xfa:data";


    /**
     * This is a utility class, and won't be instantiated.
     */
{'fraction_non_alphanumeric': 0.09540584177308087, 'fraction_numerical': 0.002642007926023778, 'mean_word_length': 3.4448793215916504, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 22}, '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': '4740024', 'n_tokens_mistral': 2110, 'n_tokens_neox': 2039, 'n_words': 415}