<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.
*/

/* Helper method to add all request parameters to a usecase */
function passRequestParameters(flowHelper, usecase) {
    var names = cocoon.request.getParameterNames();
    while (names.hasMoreElements()) {
        var name = names.nextElement();
        if (!name.equals("lenya.usecase")
            && !name.equals("lenya.continuation")
            && !name.equals("submit")) {
            
            var value = flowHelper.getRequest(cocoon).get(name);
            
            var string = new Packages.java.lang.String();
            if (string.getClass().isInstance(value)) {
                usecase.setParameter(name, value);
            }
            else {
                usecase.setPart(name, value);
            }
            
        }
    }
}

/* Helper method to add all request headers to a usecase */
function passRequestHeaders(flowHelper, usecase) {
    var names = cocoon.request.getHeaderNames();
    while (names.hasMoreElements()) {
        var name = names.nextElement();
        var value = flowHelper.getRequest(cocoon).getHeader(name);
            
        var string = new Packages.java.lang.String();
        if (string.getClass().isInstance(value)) {
            usecase.setParameter("header-"+name, value);
        }
        else {
            usecase.setPart("header-"+name, value);
        }
    }
}

function selectMethod() {
  var page = cocoon.parameters["page"];
  var requestURI = cocoon.parameters["requestURI"];
  var method = cocoon.request.getMethod();
  cocoon.sendPage(method+"/"+page, {"requestURI":requestURI});
}

function sendStatus(sc) {
  cocoon.sendStatus(sc);
}
 
function mkcol() {
  var status = executeUsecase("webdav.mkcol");
  if(status)
    sendStatus(201);
  else
    sendStatus(403);
}
 
function put() {
  var status = executeUsecase("webdav.put");
  if(status)
    sendStatus(204);
  else {
    sendStatus(415);
  }
}

function remove() {
  var status = executeUsecase("webdav.delete");
  sendStatus(200);
}

function get() {
  var uri = new java.lang.String(cocoon.parameters["forward"]);
  var uri = uri.substring(8, uri.length());
  cocoon.sendPage(uri);
}

function filePropfind() {
  var status = executeUsecase("webdav.filePropfind");
  sendStatus(500);
}

function propfind() {
  var status = executeUsecase("webdav.propfind");
  sendStatus(500);
}

function options(type) {
  cocoon.response.setHeader("DAV","1");
  var options = "";
  if (type == "file") {
    options = "OPTIONS,GET,HEAD,POST,DELETE,TRACE,PROPFIND,PROPPATCH,COPY,MOVE,PUT,LOCK,UNLOCK";
  } else {
    options = "OPTIONS,GET,HEAD,POST,DELETE,TRACE,PROPFIND,PROPPATCH,COPY,MOVE,LOCK,UNLOCK";
  }
  cocoon.response.setHeader("Allow",options);

  //interoperability with Windows 2000
  var w2kDAVDiscoverAgent = "Microsoft Data Access Internet"
                          + " Publishing Provider Protocol Discovery";
  if (cocoon.request.getHeader("User-Agent") == w2kDAVDiscoverAgent) {
      cocoon.response.setHeader("MS-Author-Via","DAV");
  }

  sendStatus(200);
}

/*
 * parse the depth header to find out if recursion
 * take place. (used by MOVE and COPY)
 */
function isRecurse(depth) {
  var recurse;
  if (depth == null || depth == '') {
    recurse = true;
  }
  else if (depth == 'Infinity') {
    recurse = true;
  }
  else {
    recurse = false;
  }
  return recurse;
}

/*
 * convert the overwrite header into a boolean type
 */
function isOverwrite(header) {
  var overwrite = true;
  if (header == 'F') {
    overwrite = false;
  }
  return overwrite;
}

function executeUsecase(usecaseName) {
    var view;
    var proxy;
    var menu = "nomenu";
    
    var usecaseResolver;
    var usecase;
    var sourceUrl;
    
    if (cocoon.log.isDebugEnabled())
       cocoon.log.debug("usecases.js::executeUsecase() called, parameter lenya.usecase = [" + usecaseName + "]");
    
    try {

        var flowHelper = cocoon.getComponent("org.apache.lenya.cms.cocoon.flow.FlowHelper");
        var request = flowHelper.getRequest(cocoon);
        sourceUrl = Packages.org.apache.lenya.util.ServletHelper.getWebappURI(request);
        
        usecaseResolver = cocoon.getComponent("org.apache.lenya.cms.usecase.UsecaseResolver");
        usecase = usecaseResolver.resolve(sourceUrl, usecaseName);
        usecase.setSourceURL(sourceUrl);
        usecase.setName(usecaseName);
        view = usecase.getView();

        passRequestParameters(flowHelper, usecase);
        passRequestHeaders(flowHelper, usecase);
        usecase.checkPreconditions();
        usecase.lockInvolvedObjects();
        proxy = new Packages.org.apache.lenya.cms.usecase.UsecaseProxy(usecase);
    }
    finally {<commit_msg>Updated UsecaseProxy package name in webdav.js<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.
*/

/* Helper method to add all request parameters to a usecase */
function passRequestParameters(flowHelper, usecase) {
    var names = cocoon.request.getParameterNames();
    while (names.hasMoreElements()) {
        var name = names.nextElement();
        if (!name.equals("lenya.usecase")
            && !name.equals("lenya.continuation")
            && !name.equals("submit")) {
            
            var value = flowHelper.getRequest(cocoon).get(name);
            
            var string = new Packages.java.lang.String();
            if (string.getClass().isInstance(value)) {
                usecase.setParameter(name, value);
            }
            else {
                usecase.setPart(name, value);
            }
            
        }
    }
}

/* Helper method to add all request headers to a usecase */
function passRequestHeaders(flowHelper, usecase) {
    var names = cocoon.request.getHeaderNames();
    while (names.hasMoreElements()) {
        var name = names.nextElement();
        var value = flowHelper.getRequest(cocoon).getHeader(name);
            
        var string = new Packages.java.lang.String();
        if (string.getClass().isInstance(value)) {
            usecase.setParameter("header-"+name, value);
        }
        else {
            usecase.setPart("header-"+name, value);
        }
    }
}

function selectMethod() {
  var page = cocoon.parameters["page"];
  var requestURI = cocoon.parameters["requestURI"];
  var method = cocoon.request.getMethod();
  cocoon.sendPage(method+"/"+page, {"requestURI":requestURI});
}

function sendStatus(sc) {
  cocoon.sendStatus(sc);
}
 
function mkcol() {
  var status = executeUsecase("webdav.mkcol");
  if(status)
    sendStatus(201);
  else
    sendStatus(403);
}
 
function put() {
  var status = executeUsecase("webdav.put");
  if(status)
    sendStatus(204);
  else {
    sendStatus(415);
  }
}

function remove() {
  var status = executeUsecase("webdav.delete");
  sendStatus(200);
}

function get() {
  var uri = new java.lang.String(cocoon.parameters["forward"]);
  var uri = uri.substring(8, uri.length());
  cocoon.sendPage(uri);
}

function filePropfind() {
  var status = executeUsecase("webdav.filePropfind");
  sendStatus(500);
}

function propfind() {
  var status = executeUsecase("webdav.propfind");
  sendStatus(500);
}

function options(type) {
  cocoon.response.setHeader("DAV","1");
  var options = "";
  if (type == "file") {
    options = "OPTIONS,GET,HEAD,POST,DELETE,TRACE,PROPFIND,PROPPATCH,COPY,MOVE,PUT,LOCK,UNLOCK";
  } else {
    options = "OPTIONS,GET,HEAD,POST,DELETE,TRACE,PROPFIND,PROPPATCH,COPY,MOVE,LOCK,UNLOCK";
  }
  cocoon.response.setHeader("Allow",options);

  //interoperability with Windows 2000
  var w2kDAVDiscoverAgent = "Microsoft Data Access Internet"
                          + " Publishing Provider Protocol Discovery";
  if (cocoon.request.getHeader("User-Agent") == w2kDAVDiscoverAgent) {
      cocoon.response.setHeader("MS-Author-Via","DAV");
  }

  sendStatus(200);
}

/*
 * parse the depth header to find out if recursion
 * take place. (used by MOVE and COPY)
 */
function isRecurse(depth) {
  var recurse;
  if (depth == null || depth == '') {
    recurse = true;
  }
  else if (depth == 'Infinity') {
    recurse = true;
  }
  else {
    recurse = false;
  }
  return recurse;
}

/*
 * convert the overwrite header into a boolean type
 */
function isOverwrite(header) {
  var overwrite = true;
  if (header == 'F') {
    overwrite = false;
  }
  return overwrite;
}

function executeUsecase(usecaseName) {
    var view;
    var proxy;
    var menu = "nomenu";
    
    var usecaseResolver;
    var usecase;
    var sourceUrl;
    
    if (cocoon.log.isDebugEnabled())
       cocoon.log.debug("usecases.js::executeUsecase() called, parameter lenya.usecase = [" + usecaseName + "]");
    
    try {

        var flowHelper = cocoon.getComponent("org.apache.lenya.cms.cocoon.flow.FlowHelper");
        var request = flowHelper.getRequest(cocoon);
        sourceUrl = Packages.org.apache.lenya.util.ServletHelper.getWebappURI(request);
        
        usecaseResolver = cocoon.getComponent("org.apache.lenya.cms.usecase.UsecaseResolver");
        usecase = usecaseResolver.resolve(sourceUrl, usecaseName);
        usecase.setSourceURL(sourceUrl);
        usecase.setName(usecaseName);
        view = usecase.getView();

        passRequestParameters(flowHelper, usecase);
        passRequestHeaders(flowHelper, usecase);
        usecase.checkPreconditions();
        usecase.lockInvolvedObjects();
        proxy = new Packages.org.apache.lenya.cms.usecase.impl.UsecaseProxy(usecase);
    }
    finally {
{'fraction_non_alphanumeric': 0.12191555474319138, 'fraction_numerical': 0.006580149881191738, 'mean_word_length': 3.104651162790698, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '3839704', 'n_tokens_mistral': 3346, 'n_tokens_neox': 3335, 'n_words': 785}