<commit_before>package org.openntf.domino.xsp;

/*

 <!--
 Copyright 2011 <NAME>, <NAME> & <NAME>
 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
 -->

 */

/*
 * <NAME>, Intec March 2013
 * Some significant enhancements here since the version Nathan cleaned up for XPages Help Application.
 * Consequently, I've renamed the package completely, so there is no conflict
 *
 * 1. Everything is now static, so no need to create an OpenLog object
 *
 * 2. Everything now uses ExtLibUtil instead of Tim Tripcony's code (sorry, Tim! ;-) )
 *
 * 3. _logDbName and olDebugLevel are set using getXspPropertyAsString(String, String). 
 *
 * 4. setThisAgent(boolean) method has been added. By default it gets the current page.
 * Otherwise it gets the previous page. Why? Because if we've been redirected to an error page,
 * we want to know which page the ACTUAL error occurred on.
 *
 * 5. logErrorEx has been fixed. It didn't work before.
 *
 * 6. _eventTime and _startTime recycled after creating logDoc. Nathan, I'll sleep a little less tonight,
 * but it's best practice ;-)
 */

/*
 * <NAME>, GBS Jun 20, 2011
 * Developers notes...
 *
 * There's more than I'd like to do here, but I think the entry points are much more sensible now.
 *
 * Because the log methods are static, one simply needs to call..
 *
 * OpenLogItem.logError(session, throwable)
 *
 * or...
 *
 * OpenLogItem.logError(session, throwable, message, level, document)
 *
 * or...
 *
 * OpenLogItem.logEvent(session, message, level, document)
 *
 * All Domino objects have been made recycle-proof. All the nonsense about "init" and "reset"
 * and overloading constructors to do all the work is gone.
 *
 * There really SHOULD be an OpenLogManager that tracks settings like the java.util.Logging package does
 * but that is well beyond the scope of this little update
 *
 * Honestly, knowing that Julian does so much more Java work now, I can completely
 * sympathize with his occasional statement that OpenLog could use a major refactor.
 *
 * I wouldn't call this "major" but certainly "significant."
 *
 * One thing that would be SUPER useful is if the logEvent traced the caller automatically
 * even without a Throwable object passed. The problem is that the most likely use for this
 * entire class is from SSJS, which won't pass a contextual call stack by default.
 *
 * We'd need a LOT more infrastructure for that!
 */

import java.util.logging.Level;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import lotus.domino.NotesException;

import org.openntf.domino.Database;
import org.openntf.domino.Document;
import org.openntf.domino.RichTextItem;
import org.openntf.domino.logging.BaseOpenLogItem;
import org.openntf.domino.utils.DominoUtils;
import org.openntf.domino.utils.Factory;
import org.openntf.domino.utils.XSPUtil;

import com.ibm.commons.util.StringUtil;
import com.ibm.icu.util.Calendar;
import com.ibm.xsp.extlib.util.ExtLibUtil;

public class XspOpenLogItem extends BaseOpenLogItem {

	private transient String logEmail_;
	private transient static String _logExpireDate;
	private transient String currXPage_;
	private transient String logDbName_;
	private transient Boolean displayError_;
	private transient String displayErrorGeneric_;
	private transient Boolean suppressEventStack_;
	// this variable sets the "debug level" of all the methods
	public String olDebugLevel = getDefaultDebugLevel();

	/*
	 * Use this constructor when you're creating an instance of the class within the confines of an Agent. It will automatically pick up the
	 * agent name, the current database, and the server.
	 */
	public XspOpenLogItem() {

	}

	/**
	 * @return the thisAgent
	 */
	@Override
	public String getThisAgent() {
		if (currXPage_ == null) {
			setThisAgent(true);
		}
		return super.getThisAgent();
	}

	public void setThisAgent(final boolean currPage) {
		try {
			String fromPage = "";
			String[] historyUrls = ExtLibUtil.getXspContext().getHistoryUrls();
			if (StringUtil.isEmpty(historyUrls)) {
				fromPage = ExtLibUtil.getXspContext().getUrl().toSiteRelativeString(ExtLibUtil.getXspContext());
			} else {
				if (currPage) {
					fromPage = historyUrls[0];
				} else {
					if (historyUrls.length > 1) {
						fromPage = historyUrls[1];
					} else {
						fromPage = historyUrls[0];
					}
				}
			}
			if (fromPage.indexOf("?") > -1) {
				super.setThisAgent(fromPage.substring(1, fromPage.indexOf("?")));
			} else {
				super.setThisAgent(fromPage);
			}
		} catch (Throwable t) {
			DominoUtils.handleException(t);
		}
	}

	public void reinitialiseSettings() {
		logEmail_ = null;
		logDbName_ = null;
		displayError_ = null;
		displayErrorGeneric_ = null;
		olDebugLevel = getDefaultDebugLevel();
	}

	/**
	 * @return the expire date
	 */
	public static String getLogExpireDate() {
		if (StringUtil.isEmpty(_logExpireDate)) {
			_logExpireDate = Activator.getXspPropertyAsString("xsp.openlog.email");
		}
		return _logExpireDate;
	}

	/**
	 * @return the logEmail
	 */
	public String getLogEmail() {
		try {
			if (StringUtil.isEmpty(logEmail_)) {
				logEmail_ = Activator.getXspPropertyAsString("xsp.openlog.email");
			}
			return logEmail_;
		} catch (Throwable t) {
			DominoUtils.handleException(t);
			return "";
		}
	}
<commit_msg>ExpireDate was looking for wrong Xsp Property - fixed<commit_after>package org.openntf.domino.xsp;

/*

 <!--
 Copyright 2011 <NAME>, <NAME> & <NAME>
 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
 -->

 */

/*
 * <NAME>, Intec March 2013
 * Some significant enhancements here since the version Nathan cleaned up for XPages Help Application.
 * Consequently, I've renamed the package completely, so there is no conflict
 *
 * 1. Everything is now static, so no need to create an OpenLog object
 *
 * 2. Everything now uses ExtLibUtil instead of Tim Tripcony's code (sorry, Tim! ;-) )
 *
 * 3. _logDbName and olDebugLevel are set using getXspPropertyAsString(String, String). 
 *
 * 4. setThisAgent(boolean) method has been added. By default it gets the current page.
 * Otherwise it gets the previous page. Why? Because if we've been redirected to an error page,
 * we want to know which page the ACTUAL error occurred on.
 *
 * 5. logErrorEx has been fixed. It didn't work before.
 *
 * 6. _eventTime and _startTime recycled after creating logDoc. Nathan, I'll sleep a little less tonight,
 * but it's best practice ;-)
 */

/*
 * <NAME>, GBS Jun 20, 2011
 * Developers notes...
 *
 * There's more than I'd like to do here, but I think the entry points are much more sensible now.
 *
 * Because the log methods are static, one simply needs to call..
 *
 * OpenLogItem.logError(session, throwable)
 *
 * or...
 *
 * OpenLogItem.logError(session, throwable, message, level, document)
 *
 * or...
 *
 * OpenLogItem.logEvent(session, message, level, document)
 *
 * All Domino objects have been made recycle-proof. All the nonsense about "init" and "reset"
 * and overloading constructors to do all the work is gone.
 *
 * There really SHOULD be an OpenLogManager that tracks settings like the java.util.Logging package does
 * but that is well beyond the scope of this little update
 *
 * Honestly, knowing that Julian does so much more Java work now, I can completely
 * sympathize with his occasional statement that OpenLog could use a major refactor.
 *
 * I wouldn't call this "major" but certainly "significant."
 *
 * One thing that would be SUPER useful is if the logEvent traced the caller automatically
 * even without a Throwable object passed. The problem is that the most likely use for this
 * entire class is from SSJS, which won't pass a contextual call stack by default.
 *
 * We'd need a LOT more infrastructure for that!
 */

import java.util.logging.Level;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import lotus.domino.NotesException;

import org.openntf.domino.Database;
import org.openntf.domino.Document;
import org.openntf.domino.RichTextItem;
import org.openntf.domino.logging.BaseOpenLogItem;
import org.openntf.domino.utils.DominoUtils;
import org.openntf.domino.utils.Factory;
import org.openntf.domino.utils.XSPUtil;

import com.ibm.commons.util.StringUtil;
import com.ibm.icu.util.Calendar;
import com.ibm.xsp.extlib.util.ExtLibUtil;

public class XspOpenLogItem extends BaseOpenLogItem {

	private transient String logEmail_;
	private transient static String _logExpireDate;
	private transient String currXPage_;
	private transient String logDbName_;
	private transient Boolean displayError_;
	private transient String displayErrorGeneric_;
	private transient Boolean suppressEventStack_;
	// this variable sets the "debug level" of all the methods
	public String olDebugLevel = getDefaultDebugLevel();

	/*
	 * Use this constructor when you're creating an instance of the class within the confines of an Agent. It will automatically pick up the
	 * agent name, the current database, and the server.
	 */
	public XspOpenLogItem() {

	}

	/**
	 * @return the thisAgent
	 */
	@Override
	public String getThisAgent() {
		if (currXPage_ == null) {
			setThisAgent(true);
		}
		return super.getThisAgent();
	}

	public void setThisAgent(final boolean currPage) {
		try {
			String fromPage = "";
			String[] historyUrls = ExtLibUtil.getXspContext().getHistoryUrls();
			if (StringUtil.isEmpty(historyUrls)) {
				fromPage = ExtLibUtil.getXspContext().getUrl().toSiteRelativeString(ExtLibUtil.getXspContext());
			} else {
				if (currPage) {
					fromPage = historyUrls[0];
				} else {
					if (historyUrls.length > 1) {
						fromPage = historyUrls[1];
					} else {
						fromPage = historyUrls[0];
					}
				}
			}
			if (fromPage.indexOf("?") > -1) {
				super.setThisAgent(fromPage.substring(1, fromPage.indexOf("?")));
			} else {
				super.setThisAgent(fromPage);
			}
		} catch (Throwable t) {
			DominoUtils.handleException(t);
		}
	}

	public void reinitialiseSettings() {
		logEmail_ = null;
		logDbName_ = null;
		displayError_ = null;
		displayErrorGeneric_ = null;
		olDebugLevel = getDefaultDebugLevel();
	}

	/**
	 * @return the expire date
	 */
	public static String getLogExpireDate() {
		if (StringUtil.isEmpty(_logExpireDate)) {
			_logExpireDate = Activator.getXspPropertyAsString("xsp.openlog.expireDate");
		}
		return _logExpireDate;
	}

	/**
	 * @return the logEmail
	 */
	public String getLogEmail() {
		try {
			if (StringUtil.isEmpty(logEmail_)) {
				logEmail_ = Activator.getXspPropertyAsString("xsp.openlog.email");
			}
			return logEmail_;
		} catch (Throwable t) {
			DominoUtils.handleException(t);
			return "";
		}
	}

{'fraction_non_alphanumeric': 0.09138065185441342, 'fraction_numerical': 0.005187170398547592, 'mean_word_length': 3.9141886151231944, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5326452', 'n_tokens_mistral': 3712, 'n_tokens_neox': 3367, 'n_words': 1225}