<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.remoting.davex;

import org.apache.jackrabbit.webdav.DavException;
import org.apache.jackrabbit.webdav.DavLocatorFactory;
import org.apache.jackrabbit.webdav.DavMethods;
import org.apache.jackrabbit.webdav.DavResource;
import org.apache.jackrabbit.webdav.DavResourceLocator;
import org.apache.jackrabbit.webdav.DavServletResponse;
import org.apache.jackrabbit.webdav.DavSession;
import org.apache.jackrabbit.webdav.WebdavRequest;
import org.apache.jackrabbit.webdav.WebdavResponse;
import org.apache.jackrabbit.webdav.version.DeltaVConstants;
import org.apache.jackrabbit.webdav.jcr.JcrDavException;
import org.apache.jackrabbit.webdav.jcr.JcrDavSession;
import org.apache.jackrabbit.webdav.jcr.JCRWebdavServerServlet;
import org.apache.jackrabbit.util.Text;
import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.server.util.RequestData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.jcr.Item;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Workspace;
import javax.jcr.ItemNotFoundException;
import javax.jcr.NodeIterator;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;

/**
 * <code>JcrRemotingServlet</code> is an extended version of the
 * {@link org.apache.jackrabbit.webdav.jcr.JCRWebdavServerServlet JCR Remoting Servlet}
 * that provides improved
 * <ul>
 * <li><a href="#bread">Batch read</a></li>
 * <li><a href="#bwrite">Batch write</a></li>
 * </ul>
 * functionality and supports cross workspace copy and cloning.
 * </p>
 * 
 * <h3><a name="bread">Batch Read</a></h3>
 *
 * Upon RepositoryService.getItemInfos a JSON object is composed containing
 * the information for the requested node and its child items up to a
 * specified or configuration determined depth.
 * <p/>
 * Batch read is triggered by adding a '.json' extension to the resource href.
 * Optionally the client may explicitely specify the desired batch read depth
 * by appending '.depth.json' extension. If no json extension is present the
 * GET request is processed by the base servlet.
 * <p/>
 * The JSON writer applies the following rules:
 * 
 * <pre>
 * - Each Node has its properties included as JSON key/value pairs.
 *
 * - Child nodes are equally treated as long a maximal depths is not reached.
 * 
 * - Nodes without any child nodes get a special JSON member named
 *   ::NodeIteratorSize, whose value is zero.
 *
 * - If the maximal depth is reached only name, index and unique id of the
 *   direct child are included (incomplete node info). In order to obtain
 *   the complete information another GET with .json extension will be sent
 *   by the client.
 * </pre>
 * 
 * Same name sibling nodes and properties whose type cannot be unambiguously be
 * extracted from the JSON on the client side need some special handling:
 * 
 * <pre>
 * - Node with index > 1, get a JSON key consisting of
 *   Node.getName() + "[" + Node.getIndex() + "]" 
 *
 * - Binary Property
 *   JSON value = length of the JCR value.
 *   The JCR value must be retrieved separately.
 *
 * - Name, Path, Reference and Date Property
 *   The JSON member representing the Property (name, value) is preceeded by a
 *   special member consisting of
 *   JSON key = ":" + Property.getName()
 *   JSON value = PropertyType.nameFromValue(Property.getType())
 *
 * - Multi valued properties with Property.getValues().length == 0 will be
 *   treated as special property types above (extra property indicating the<commit_msg>- JCR-1958: Enhanced JCR remoting (work in progress)<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.remoting.davex;

import org.apache.jackrabbit.webdav.DavException;
import org.apache.jackrabbit.webdav.DavLocatorFactory;
import org.apache.jackrabbit.webdav.DavMethods;
import org.apache.jackrabbit.webdav.DavResource;
import org.apache.jackrabbit.webdav.DavResourceLocator;
import org.apache.jackrabbit.webdav.DavServletResponse;
import org.apache.jackrabbit.webdav.DavSession;
import org.apache.jackrabbit.webdav.WebdavRequest;
import org.apache.jackrabbit.webdav.WebdavResponse;
import org.apache.jackrabbit.webdav.version.DeltaVConstants;
import org.apache.jackrabbit.webdav.jcr.JcrDavException;
import org.apache.jackrabbit.webdav.jcr.JcrDavSession;
import org.apache.jackrabbit.webdav.jcr.JCRWebdavServerServlet;
import org.apache.jackrabbit.util.Text;
import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.server.util.RequestData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.jcr.Item;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Workspace;
import javax.jcr.ItemNotFoundException;
import javax.jcr.NodeIterator;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;

/**
 * <code>JcrRemotingServlet</code> is an extended version of the
 * {@link org.apache.jackrabbit.webdav.jcr.JCRWebdavServerServlet JCR Remoting Servlet}
 * that provides improved
 * <ul>
 * <li><a href="#bread">Batch read</a></li>
 * <li><a href="#bwrite">Batch write</a></li>
 * </ul>
 * functionality and supports cross workspace copy and cloning.
 * </p>
 * 
 * <h3><a name="bread">Batch Read</a></h3>
 *
 * Upon RepositoryService.getItemInfos a JSON object is composed containing
 * the information for the requested node and its child items up to a
 * specified or configuration determined depth.
 * <p/>
 * Batch read is triggered by adding a '.json' extension to the resource href.
 * Optionally the client may explicitely specify the desired batch read depth
 * by appending '.depth.json' extension. If no json extension is present the
 * GET request is processed by the base servlet.
 * <p/>
 * The JSON writer applies the following rules:
 * 
 * <pre>
 * - Nodes are represented as JSON objects.
 *
 * - Each Node has its properties included as JSON key/value pairs.
 *
 * - Single valued Properties are simple key/value pairs.
 *
 * - Multi valued Properties are represented as JSON array.
 *
 * - Each Node has its child nodes included as long a maximal depths is not reached.
 * 
 * - Nodes without any child nodes get a special JSON member named
 *   ::NodeIteratorSize, whose value is zero.
 *
 * - If the maximal depth is reached only name, index and unique id of the
 *   direct child are included (incomplete node info). In order to obtain
 *   the complete information the client sends another GET with .json extension.
 * </pre>
 * 
 * Same name sibling nodes and properties whose type cannot be unambiguously be
 * extracted from the JSON on the client side need some special handling:
 * 
 * <pre>
 * - Node with index > 1, get a JSON key consisting of
 *   Node.getName() + "[" + Node.getIndex() + "]" 
 *
 * - Binary Property
 *   JSON value = length of the JCR value.
 *   The JCR value must be retrieved separately.
 *
 * - Name, Path, Reference and Date Property
 *   The JSON member representing the Property (name, value) is preceeded by a
 *   special member consisting of
 *   JSON key = ":" + Property.getName()
 *   JSON value = PropertyType.nameFromValue(Property.getType())
 *
 * - Multi valued properties with Property.getValues().length == 0 will be
 *   treated as special property types above (extra property indicating the
{'fraction_non_alphanumeric': 0.08946343574210298, 'fraction_numerical': 0.0025962786672436176, 'mean_word_length': 4.313218390804598, 'pattern_counts': {'":': 2, '<': 47, '<?xml version=': 0, '>': 49, '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': '2684471', 'n_tokens_mistral': 2645, 'n_tokens_neox': 2522, 'n_words': 970}