<commit_before>/*
 * Copyright 2013
 * 
 * Licensed 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.openntf.domino.utils;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.security.AccessControlException;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.ServiceLoader;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;

import org.openntf.domino.Base;
import org.openntf.domino.Database;
import org.openntf.domino.Document;
import org.openntf.domino.DocumentCollection;
import org.openntf.domino.Session;
import org.openntf.domino.Session.RunContext;
import org.openntf.domino.WrapperFactory;
import org.openntf.domino.exceptions.DataNotCompatibleException;
import org.openntf.domino.exceptions.UndefinedDelegateTypeException;
import org.openntf.domino.graph.DominoGraph;
import org.openntf.domino.logging.ConsoleFormatter;
import org.openntf.domino.logging.DefaultConsoleHandler;
import org.openntf.domino.logging.DefaultFileHandler;
import org.openntf.domino.logging.FileFormatter;
import org.openntf.domino.logging.OpenLogHandler;
import org.openntf.domino.types.DatabaseDescendant;
import org.openntf.domino.types.FactorySchema;
import org.openntf.domino.types.SessionDescendant;

/**
 * The Enum Factory. Does the Mapping lotusObject <=> OpenNTF-Object
 */
public enum Factory {
	;

	/**
	 * Holder for the wrapper-factory that converts lotus.domino objects to org.openntf.domino objects
	 */
	private static ThreadLocal<WrapperFactory> currentWrapperFactory = new ThreadLocal<WrapperFactory>();

	private static ThreadLocal<ClassLoader> currentClassLoader_ = new ThreadLocal<ClassLoader>();

	private static ThreadLocal<Session> currentSessionHolder_ = new ThreadLocal<Session>();

	private static List<Terminatable> onTerminate_ = new ArrayList<Terminatable>();

	/**
	 * setup the environment and loggers
	 * 
	 * @author praml
	 * 
	 */
	private static class SetupJob implements Runnable {
		@Override
		public void run() {
			try {
				AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
					@Override
					public Object run() throws Exception {
						String progpath = System.getProperty("notes.binary");
						File iniFile = new File(progpath + System.getProperty("file.separator") + "notes.ini");
						Scanner scanner = new Scanner(iniFile);
						scanner.useDelimiter(System.getProperty("line.separator"));
						//						while (scanner.hasNextLine()) {
						//							String nextLine = scanner.nextLine();
						//							System.out.println("DEBUG " + nextLine);
						//						}

						lotus.domino.Session session = null;
						//								NotesFactory.createSession();
						try {
							loadEnvironment(/*session, */scanner);
						} finally {
							//							session.recycle();
						}
						scanner.close();
						return null;
					}
				});
			} catch (AccessControlException e) {
				e.printStackTrace();
			} catch (PrivilegedActionException e) {
				e.printStackTrace();
			}

			try {
				AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
					@Override
					// TODO RPr: read config from notes.ini / env
					public Object run() throws Exception {
						String pattern = getDataPath() + "/IBM_TECHNICAL_SUPPORT/org.openntf.%u.%g.log";
						Logger oodLogger = Logger.getLogger("org.openntf.domino");<commit_msg>Tweaked the Session-less environment code in Factory to work on Linux and with mixed-line-terminator files<commit_after>/*
 * Copyright 2013
 * 
 * Licensed 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.openntf.domino.utils;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.security.AccessControlException;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.ServiceLoader;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;

import org.openntf.domino.Base;
import org.openntf.domino.Database;
import org.openntf.domino.Document;
import org.openntf.domino.DocumentCollection;
import org.openntf.domino.Session;
import org.openntf.domino.Session.RunContext;
import org.openntf.domino.WrapperFactory;
import org.openntf.domino.exceptions.DataNotCompatibleException;
import org.openntf.domino.exceptions.UndefinedDelegateTypeException;
import org.openntf.domino.graph.DominoGraph;
import org.openntf.domino.logging.ConsoleFormatter;
import org.openntf.domino.logging.DefaultConsoleHandler;
import org.openntf.domino.logging.DefaultFileHandler;
import org.openntf.domino.logging.FileFormatter;
import org.openntf.domino.logging.OpenLogHandler;
import org.openntf.domino.types.DatabaseDescendant;
import org.openntf.domino.types.FactorySchema;
import org.openntf.domino.types.SessionDescendant;

/**
 * The Enum Factory. Does the Mapping lotusObject <=> OpenNTF-Object
 */
public enum Factory {
	;

	/**
	 * Holder for the wrapper-factory that converts lotus.domino objects to org.openntf.domino objects
	 */
	private static ThreadLocal<WrapperFactory> currentWrapperFactory = new ThreadLocal<WrapperFactory>();

	private static ThreadLocal<ClassLoader> currentClassLoader_ = new ThreadLocal<ClassLoader>();

	private static ThreadLocal<Session> currentSessionHolder_ = new ThreadLocal<Session>();

	private static List<Terminatable> onTerminate_ = new ArrayList<Terminatable>();

	/**
	 * setup the environment and loggers
	 * 
	 * @author praml
	 * 
	 */
	private static class SetupJob implements Runnable {
		@Override
		public void run() {
			try {
				AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
					@Override
					public Object run() throws Exception {
						// Windows stores the notes.ini in the program directory; Linux stores it in the data directory
						String os = String.valueOf(System.getProperty("os.name")).toLowerCase();
						String progpath = System.getProperty(os.contains("windows") ? "notes.binary" : "user.dir");
						File iniFile = new File(progpath + System.getProperty("file.separator") + "notes.ini");

						Scanner scanner = new Scanner(iniFile);
						scanner.useDelimiter("\n|\r\n");
						//						while (scanner.hasNextLine()) {
						//							String nextLine = scanner.nextLine();
						//							System.out.println("DEBUG " + nextLine);
						//						}

						lotus.domino.Session session = null;
						//								NotesFactory.createSession();
						try {
							loadEnvironment(/*session, */scanner);
						} finally {
							//							session.recycle();
						}
						scanner.close();
						return null;
					}
				});
			} catch (AccessControlException e) {
				e.printStackTrace();
			} catch (PrivilegedActionException e) {
				e.printStackTrace();
			}

			try {
				AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
					@Override
					// TODO RPr: read config from notes.ini / env
					public Object run() throws Exception {
						String pattern = getDataPath() + "/IBM_TECHNICAL_SUPPORT/org.openntf.%u.%g.log";
						Logger oodLogger = Logger.getLogger("org.openntf.domino");
{'fraction_non_alphanumeric': 0.10419924056287692, 'fraction_numerical': 0.0017869108778199687, 'mean_word_length': 4.073654390934844, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '4331215', 'n_tokens_mistral': 2999, 'n_tokens_neox': 2565, 'n_words': 635}