<commit_before>/*
 * Copyright (c) 2008, <NAME> (Ph.D. Thesis), University of Konstanz
 * 
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 * 
 * $Id$
 */

package org.treetank.service;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mortbay.jetty.handler.AbstractHandler;

public class TreeTankHandler extends AbstractHandler {

  private static final String FAVICON = "/favicon.ico";

  private static final String CROSSDOMAIN = "/crossdomain.xml";

  private static final String POST = "POST";

  private static final String GET = "GET";

  private final HelperFavicon mHelperFavicon;

  private final HelperCrossdomain mHelperCrossdomain;

  private final HelperGet mHelperGet;

  private final HelperPost mHelperPost;

  private final HelperPut mHelperPut;

  private final HelperDelete mHelperDelete;

  public TreeTankHandler(final Map<String, TreeTankWrapper> map) {
    mHelperFavicon = new HelperFavicon();
    mHelperCrossdomain = new HelperCrossdomain();
    mHelperGet = new HelperGet(map);
    mHelperPost = new HelperPost(map);
    mHelperPut = new HelperPut(map);
    mHelperDelete = new HelperDelete(map);
  }

  public void handle(
      String target,
      HttpServletRequest request,
      HttpServletResponse response,
      int dispatch) throws IOException, ServletException {

    try {

      if (request.getRequestURI().equalsIgnoreCase(FAVICON)) {
        mHelperFavicon.handle(request, response);
      } else if (request.getRequestURI().equalsIgnoreCase(CROSSDOMAIN)) {
        mHelperCrossdomain.handle(request, response);
      } else if (request.getMethod().equalsIgnoreCase(GET)) {
        mHelperGet.handle(request, response);
      } else if (request.getMethod().equalsIgnoreCase(POST)) {
        if (request.getQueryString().equalsIgnoreCase("delete")) {
          mHelperDelete.handle(request, response);
        } else if (request.getQueryString().equalsIgnoreCase("insert")) {
          mHelperPost.handle(request, response);
        } else if (request.getQueryString().equalsIgnoreCase("update")) {
          mHelperPut.handle(request, response);
        } else {
          throw new TreeTankException(501, "Unknown operation.");
        }
      } else {
        throw new TreeTankException(501, "Unknown operation.");
      }

    } catch (TreeTankException e) {
      response.sendError(e.getErrorCode(), e.getErrorMessage());
    }

  }

}
<commit_msg>Adapted names to comply with rest names.<commit_after>/*
 * Copyright (c) 2008, <NAME> (Ph.D. Thesis), University of Konstanz
 * 
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 * 
 * $Id$
 */

package org.treetank.service;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mortbay.jetty.handler.AbstractHandler;

public class TreeTankHandler extends AbstractHandler {

  private static final String FAVICON = "/favicon.ico";

  private static final String CROSSDOMAIN = "/crossdomain.xml";

  private static final String POST = "POST";

  private static final String PUT = "PUT";

  private static final String DELETE = "DELETE";

  private static final String GET = "GET";

  private final HelperFavicon mHelperFavicon;

  private final HelperCrossdomain mHelperCrossdomain;

  private final HelperGet mHelperGet;

  private final HelperPost mHelperPost;

  private final HelperPut mHelperPut;

  private final HelperDelete mHelperDelete;

  public TreeTankHandler(final Map<String, TreeTankWrapper> map) {
    mHelperFavicon = new HelperFavicon();
    mHelperCrossdomain = new HelperCrossdomain();
    mHelperGet = new HelperGet(map);
    mHelperPost = new HelperPost(map);
    mHelperPut = new HelperPut(map);
    mHelperDelete = new HelperDelete(map);
  }

  public void handle(
      String target,
      HttpServletRequest request,
      HttpServletResponse response,
      int dispatch) throws IOException, ServletException {

    try {

      if (request.getRequestURI().equalsIgnoreCase(FAVICON)) {
        mHelperFavicon.handle(request, response);
      } else if (request.getRequestURI().equalsIgnoreCase(CROSSDOMAIN)) {
        mHelperCrossdomain.handle(request, response);
      } else if (request.getMethod().equalsIgnoreCase(GET)) {
        mHelperGet.handle(request, response);
      } else if (request.getMethod().equalsIgnoreCase(POST)) {
        if (request.getQueryString().equalsIgnoreCase(DELETE)) {
          mHelperDelete.handle(request, response);
        } else if (request.getQueryString().equalsIgnoreCase(POST)) {
          mHelperPost.handle(request, response);
        } else if (request.getQueryString().equalsIgnoreCase(PUT)) {
          mHelperPut.handle(request, response);
        } else {
          throw new TreeTankException(501, "Unknown operation.");
        }
      } else {
        throw new TreeTankException(501, "Unknown operation.");
      }

    } catch (TreeTankException e) {
      response.sendError(e.getErrorCode(), e.getErrorMessage());
    }

  }

}

{'fraction_non_alphanumeric': 0.08704268292682926, 'fraction_numerical': 0.003048780487804878, 'mean_word_length': 3.817180616740088, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4936268', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1766, 'n_words': 568}