<commit_before>/*
 *  eXist Open Source Native XML Database
 *  Copyright (C) 2006 The eXist Project
 *  http://exist-db.org
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; er version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software Foundation
 *  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *  $Id$
 */
package org.exist.xmldb;

import org.apache.log4j.Logger;

import org.exist.xquery.Constants;
import org.exist.xquery.util.URIUtils;
import org.exist.xquery.value.AnyURIValue;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;

import java.util.regex.Pattern;

/**
 * A utility class for xmldb URis. Since, java.net.URI is <strong>final</strong> this class acts as a wrapper.
 *
 * @author  <NAME> <<EMAIL>>
 */
/*
 * This base class implementation only provides a path.  FullXmldbURI provides
 * full uri support.  The create method creates a minimal object to keep memory
 * usage low.
 */
public class XmldbURI implements Comparable<Object>, Serializable {

    protected final static Logger LOG = Logger.getLogger(XmldbURI.class);
    public static final int NO_PORT = -1;
    //Should be provided by org.xmldb.api package !!!
    public static final String XMLDB_SCHEME = "xmldb";
    public static final String XMLDB_URI_PREFIX = "xmldb:";
    public static final String DEFAULT_INSTANCE_NAME = "exist";
    public static final String EMBEDDED_SERVER_AUTHORITY = "embedded-eXist-server";
    public static final String EMBEDDED_SERVER_URI_PREFIX = XMLDB_URI_PREFIX + DEFAULT_INSTANCE_NAME + "://";
    /** 'db' collection name */
    public final static String ROOT_COLLECTION_NAME = "db";
    /** '/db' collection name */
    public final static String ROOT_COLLECTION = "/" + ROOT_COLLECTION_NAME;
    /** 'system' collection name */
    public final static String SYSTEM_COLLECTION_NAME = "system";
    /** '/db/system' collection name */
    public final static String SYSTEM_COLLECTION = ROOT_COLLECTION + "/" + SYSTEM_COLLECTION_NAME;
    /** 'temp' collection name */
    public final static String TEMP_COLLECTION_NAME = "temp";
    /** '/db/system/temp' collection name */
    public final static String TEMP_COLLECTION = SYSTEM_COLLECTION + "/" + TEMP_COLLECTION_NAME;
    /** '/db/system/config' collection name */
    public final static String CONFIG_COLLECTION = SYSTEM_COLLECTION + "/config";
    public final static XmldbURI ROOT_COLLECTION_URI = create(ROOT_COLLECTION);
    public final static XmldbURI RELATIVE_ROOT_COLLECTION_URI = create(ROOT_COLLECTION_NAME);
    public final static XmldbURI SYSTEM_COLLECTION_URI = create(SYSTEM_COLLECTION);
    /** /db/etc */
    public final static XmldbURI ETC_COLLECTION_URI = SYSTEM_COLLECTION_URI.append("/etc");
    public final static XmldbURI CONFIG_COLLECTION_URI = create(CONFIG_COLLECTION);
    //TODO : create using resolve()
    public final static XmldbURI ROOT_COLLECTION_CONFIG_URI = create(CONFIG_COLLECTION + "/" + ROOT_COLLECTION_NAME);
    public final static XmldbURI METADATA_COLLECTION_URI = create(SYSTEM_COLLECTION + "/metadata");
    public final static XmldbURI TEMP_COLLECTION_URI = create(TEMP_COLLECTION);
    public final static XmldbURI EMPTY_URI = createInternal("");
    public static final XmldbURI EMBEDDED_SERVER_URI = XmldbURI.create(EMBEDDED_SERVER_URI_PREFIX + EMBEDDED_SERVER_AUTHORITY);
    /** 'xmldb:exist///db' */
    public static final String LOCAL_DB = EMBEDDED_SERVER_URI_PREFIX + ROOT_COLLECTION;
    /** 'xmldb:exist///db' XmldbURI */
    public static final XmldbURI LOCAL_DB_URI = XmldbURI.create(EMBEDDED_SERVER_URI_PREFIX + ROOT_COLLECTION);
    //TODO : deprecate when we split at root collection
    public final static String API_XMLRPC = "xmlrpc";
    public final static String API_WEBDAV = "webdav";
    public final static String API_REST = "rest-style";
    public final static String API_LOCAL = "local";
    
    private String encodedCollectionPath;
    protected boolean hadXmldbPrefix = false;

    protected XmldbURI(URI xmldbURI) throws URISyntaxException {
    	this(xmldbURI, true);
    }

    /**
     * Contructs an XmldbURI from given URI. The provided URI must have the XMLDB_SCHEME ("xmldb")<commit_msg>[ignore] cleanup<commit_after>/*
 *  eXist Open Source Native XML Database
 *  Copyright (C) 2006 The eXist Project
 *  http://exist-db.org
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; er version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software Foundation
 *  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *  $Id$
 */
package org.exist.xmldb;

import org.apache.log4j.Logger;

import org.exist.xquery.Constants;
import org.exist.xquery.util.URIUtils;
import org.exist.xquery.value.AnyURIValue;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;

import java.util.regex.Pattern;

/**
 * A utility class for xmldb URis. Since, java.net.URI is <strong>final</strong> this class acts as a wrapper.
 *
 * @author  <NAME> <<EMAIL>>
 */
/*
 * This base class implementation only provides a path.  FullXmldbURI provides
 * full uri support.  The create method creates a minimal object to keep memory
 * usage low.
 */
public class XmldbURI implements Comparable<Object>, Serializable {

    protected final static Logger LOG = Logger.getLogger(XmldbURI.class);
    public static final int NO_PORT = -1;
    //Should be provided by org.xmldb.api package !!!
    public static final String XMLDB_SCHEME = "xmldb";
    public static final String XMLDB_URI_PREFIX = "xmldb:";
    public static final String DEFAULT_INSTANCE_NAME = "exist";
    public static final String EMBEDDED_SERVER_AUTHORITY = "embedded-eXist-server";
    public static final String EMBEDDED_SERVER_URI_PREFIX = XMLDB_URI_PREFIX + DEFAULT_INSTANCE_NAME + "://";
    /** 'db' collection name */
    public final static String ROOT_COLLECTION_NAME = "db";
    /** '/db' collection name */
    public final static String ROOT_COLLECTION = "/" + ROOT_COLLECTION_NAME;
    /** 'system' collection name */
    public final static String SYSTEM_COLLECTION_NAME = "system";
    /** '/db/system' collection name */
    public final static String SYSTEM_COLLECTION = ROOT_COLLECTION + "/" + SYSTEM_COLLECTION_NAME;
    /** 'temp' collection name */
    public final static String TEMP_COLLECTION_NAME = "temp";
    /** '/db/system/temp' collection name */
    public final static String TEMP_COLLECTION = SYSTEM_COLLECTION + "/" + TEMP_COLLECTION_NAME;
    /** '/db/system/config' collection name */
    public final static String CONFIG_COLLECTION = SYSTEM_COLLECTION + "/config";
    public final static XmldbURI ROOT_COLLECTION_URI = create(ROOT_COLLECTION);
    public final static XmldbURI RELATIVE_ROOT_COLLECTION_URI = create(ROOT_COLLECTION_NAME);
    public final static XmldbURI SYSTEM_COLLECTION_URI = create(SYSTEM_COLLECTION);
    @Deprecated
    public final static XmldbURI CONFIG_COLLECTION_URI = create(CONFIG_COLLECTION);
    //TODO : create using resolve()
    public final static XmldbURI ROOT_COLLECTION_CONFIG_URI = create(CONFIG_COLLECTION + "/" + ROOT_COLLECTION_NAME);
    public final static XmldbURI TEMP_COLLECTION_URI = create(TEMP_COLLECTION);
    public final static XmldbURI EMPTY_URI = createInternal("");
    public static final XmldbURI EMBEDDED_SERVER_URI = XmldbURI.create(EMBEDDED_SERVER_URI_PREFIX + EMBEDDED_SERVER_AUTHORITY);
    /** 'xmldb:exist///db' */
    public static final String LOCAL_DB = EMBEDDED_SERVER_URI_PREFIX + ROOT_COLLECTION;
    /** 'xmldb:exist///db' XmldbURI */
    public static final XmldbURI LOCAL_DB_URI = XmldbURI.create(EMBEDDED_SERVER_URI_PREFIX + ROOT_COLLECTION);
    //TODO : deprecate when we split at root collection
    public final static String API_XMLRPC = "xmlrpc";
    public final static String API_WEBDAV = "webdav";
    public final static String API_REST = "rest-style";
    public final static String API_LOCAL = "local";
    
    private String encodedCollectionPath;
    protected boolean hadXmldbPrefix = false;

    protected XmldbURI(URI xmldbURI) throws URISyntaxException {
    	this(xmldbURI, true);
    }

    /**
     * Contructs an XmldbURI from given URI. The provided URI must have the XMLDB_SCHEME ("xmldb")
{'fraction_non_alphanumeric': 0.08572030328559394, 'fraction_numerical': 0.0035804549283909013, 'mean_word_length': 4.103170338527673, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3608710', 'n_tokens_mistral': 2961, 'n_tokens_neox': 2924, 'n_words': 899}