<commit_before>//
// This file is part of the OpenNMS(R) Application.
//
// OpenNMS(R) is Copyright (C) 2002-2003 The OpenNMS Group, Inc.  All rights reserved.
// OpenNMS(R) is a derivative work, containing both original code, included code and modified
// code that was published under the GNU General Public License. Copyrights for modified 
// and included code are below.
//
// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
//
// Modifications:
//
// 2008 Jan 21: Use a DataSource instead of a DbConnectionFactory. - <EMAIL>
// 2008 Jan 21: Clean up init. - <EMAIL>
// 2007 Apr 05: Don't initialize log4j ourselves; let it happen in web.xml at
//              the hands of Spring's log4j initializer. - <EMAIL>
// 2003 Feb 02: Changed Log4J initialization.
//
// Original code base Copyright (C) 1999-2001 Oculan Corp.  All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// For more information contact:
//      OpenNMS Licensing       <<EMAIL>>
//      http://www.opennms.org/
//      http://www.opennms.com/
//
// Tab Size = 8
//

package org.opennms.web;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.opennms.core.resource.Vault;
import org.opennms.core.resource.db.DbConnectionFactory;
import org.opennms.core.utils.ThreadCategory;
import org.opennms.netmgt.config.DataSourceFactory;

/**
 * Encapsulates all initialization and configuration needed by the OpenNMS
 * servlets and JSPs.
 * 
 * @author <A HREF="mailto:<EMAIL>"><NAME> </A>
 * @author <A HREF="http://www.opennms.org/">OpenNMS </A>
 */
public class ServletInitializer extends Object {
    /**
     * A reference to the factory we set in {@link Vault Vault}during
     * {@link #init init}so we can destroy it in {@link #destroy destroy}.
     * 
     * <p>
     * Maybe there's a better way to do this then storing a reference? Should we
     * just add a method to <code>Vault</code>?
     * </p>
     * 
     * <p>
     * This reference also serves as a flag to determine whether or not this
     * class has been initialized yet. If it is null, the class has not yet been
     * initialized.
     * </p>
     */
    protected static DbConnectionFactory factory;

    /**
     * Private, empty constructor so that this class cannot be instantiated
     * outside of itself.
     */
    private ServletInitializer() {
    }

    /**
     * Initialize servlet and JSP configuration on the first invocation of this
     * method. All other invocations are ignored. This method is synchronized to
     * ensure only the first invocation performs the initialization.
     * 
     * <p>
     * Call this method in the <code>init</code> method of your servlet or
     * JSP. It will read the servlet initialization parameters from the
     * <code>ServletConfig</code> and <code>ServletContext</code> and
     * OpenNMS configuration files.
     * </p>
     * 
     * <p>
     * If this method finds the property <code>opennms.db.poolman</code> in
     * the <code>ServletContext</code>, it will create an instance of the
     * classname specified there to use as the <code>DbConnectionManager</code>.
     * </p>
     * 
     * @param context
     *            the <code>ServletContext</code> instance in which your
     *            servlet is running
     */
    public synchronized static void init(ServletContext context) throws ServletException {
        if (context == null) {
            throw new IllegalArgumentException("Cannot take null parameters.");
        }

        /*
         * All ThreadCategory instances in the WebUI should use this as their
         * category prefix
         */
        ThreadCategory.setPrefix("OpenNMS.WEB");

        if (factory == null) {
            Properties properties = new Properties(System.getProperties());

            try {
                /*
                 * First, check if opennms.home is set, if so, we already have properties
                 * because we're in Jetty.
                 */
                if (properties.getProperty("opennms.home") == null) {
                    // If not, load properties from configuration.properties<commit_msg>Remove an incorrect javadoc comment.<commit_after>//
// This file is part of the OpenNMS(R) Application.
//
// OpenNMS(R) is Copyright (C) 2002-2003 The OpenNMS Group, Inc.  All rights reserved.
// OpenNMS(R) is a derivative work, containing both original code, included code and modified
// code that was published under the GNU General Public License. Copyrights for modified 
// and included code are below.
//
// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
//
// Modifications:
//
// 2008 Jan 21: Use a DataSource instead of a DbConnectionFactory. - <EMAIL>
// 2008 Jan 21: Clean up init. - <EMAIL>
// 2007 Apr 05: Don't initialize log4j ourselves; let it happen in web.xml at
//              the hands of Spring's log4j initializer. - <EMAIL>.org
// 2003 Feb 02: Changed Log4J initialization.
//
// Original code base Copyright (C) 1999-2001 Oculan Corp.  All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// For more information contact:
//      OpenNMS Licensing       <<EMAIL>>
//      http://www.opennms.org/
//      http://www.opennms.com/
//
// Tab Size = 8
//

package org.opennms.web;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.opennms.core.resource.Vault;
import org.opennms.core.resource.db.DbConnectionFactory;
import org.opennms.core.utils.ThreadCategory;
import org.opennms.netmgt.config.DataSourceFactory;

/**
 * Encapsulates all initialization and configuration needed by the OpenNMS
 * servlets and JSPs.
 * 
 * @author <A HREF="mailto:<EMAIL>"><NAME> </A>
 * @author <A HREF="http://www.opennms.org/">OpenNMS </A>
 */
public class ServletInitializer extends Object {
    /**
     * A reference to the factory we set in {@link Vault Vault}during
     * {@link #init init}so we can destroy it in {@link #destroy destroy}.
     * 
     * <p>
     * Maybe there's a better way to do this then storing a reference? Should we
     * just add a method to <code>Vault</code>?
     * </p>
     * 
     * <p>
     * This reference also serves as a flag to determine whether or not this
     * class has been initialized yet. If it is null, the class has not yet been
     * initialized.
     * </p>
     */
    protected static DbConnectionFactory factory;

    /**
     * Private, empty constructor so that this class cannot be instantiated
     * outside of itself.
     */
    private ServletInitializer() {
    }

    /**
     * Initialize servlet and JSP configuration on the first invocation of this
     * method. All other invocations are ignored. This method is synchronized to
     * ensure only the first invocation performs the initialization.
     * 
     * <p>
     * Call this method in the <code>init</code> method of your servlet or
     * JSP. It will read the servlet initialization parameters from the
     * <code>ServletConfig</code> and <code>ServletContext</code> and
     * OpenNMS configuration files.
     * </p>
     * 
     * @param context
     *            the <code>ServletContext</code> instance in which your
     *            servlet is running
     */
    public synchronized static void init(ServletContext context) throws ServletException {
        if (context == null) {
            throw new IllegalArgumentException("Cannot take null parameters.");
        }

        /*
         * All ThreadCategory instances in the WebUI should use this as their
         * category prefix
         */
        ThreadCategory.setPrefix("OpenNMS.WEB");

        if (factory == null) {
            Properties properties = new Properties(System.getProperties());

            try {
                /*
                 * First, check if opennms.home is set, if so, we already have properties
                 * because we're in Jetty.
                 */
                if (properties.getProperty("opennms.home") == null) {
                    // If not, load properties from configuration.properties
{'fraction_non_alphanumeric': 0.09435688866293848, 'fraction_numerical': 0.011997966446365024, 'mean_word_length': 2.642962962962963, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '2497695', 'n_tokens_mistral': 2778, 'n_tokens_neox': 2612, 'n_words': 1082}