<commit_before>/**
 * The contents of this file are subject to the OpenMRS Public License
 * Version 1.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://license.openmrs.org
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) OpenMRS, LLC.  All Rights Reserved.
 */
package org.openmrs.web.taglib.fieldgen;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.web.taglib.FieldGenTag;
import org.openmrs.web.taglib.HtmlIncludeTag;

public abstract class AbstractFieldGenHandler {
	
	protected final Log log = LogFactory.getLog(getClass());
	
	protected FieldGenTag fieldGenTag;
	
	public void setFieldGenTag(FieldGenTag fieldGenTag) {
		this.fieldGenTag = fieldGenTag;
	}
	
	protected void setParameter(String s, Object o) {
		if (this.fieldGenTag != null) {
			//HashMap<String,Object> hmParams = (HashMap<String,Object>)getRequest().getAttribute("org.openmrs.fieldGen.parameterMap");
			HashMap<String, Object> hmParams = (HashMap<String, Object>) this.fieldGenTag.getParameterMap();
			if (hmParams == null)
				hmParams = new HashMap<String, Object>();
			hmParams.put(s, o);
			this.fieldGenTag.setParameterMap(hmParams);
		}
	}
	
	protected void setUrl(String s) {
		if (this.fieldGenTag != null) {
			this.fieldGenTag.setUrl(s);
		}
	}
	
	protected void setVal(Object o) {
		if (this.fieldGenTag != null) {
			this.fieldGenTag.setVal(o);
		}
	}
	
	protected void checkEmptyVal(Object o) {
		if (this.fieldGenTag.getVal() != null) {
			if (this.fieldGenTag.getVal() instanceof String && !(o instanceof String)) {
				if ("".equals(this.fieldGenTag.getVal())) {
					setVal(o);
				}
			}
		}
	}
	
	protected void htmlInclude(String fileToInclude) {
		HtmlIncludeTag hit = new HtmlIncludeTag();
		hit.setPageContext(this.fieldGenTag.getPageContext());
		hit.setFile(fileToInclude);
		try {
			@SuppressWarnings("unused")
			int i = hit.doStartTag();
		}
		catch (JspException e) {
			log.error("Unable to execute doStartTag() method of HtmlIncludeTag from FieldGenHandler");
		}
	}
	
	protected HttpServletRequest getRequest() {
		if (this.fieldGenTag != null) {
			//HttpSession session = this.fieldGenTag.getPageContext().getSession();
			return (HttpServletRequest) this.fieldGenTag.getPageContext().getRequest();
			//return (Context)session.getAttribute(WebConstants.OPENMRS_CONTEXT_HTTPSESSION_ATTR);
		} else
			return null;
	}
}
<commit_msg>AbstractFieldGenHandler should implement FieldGenHandler.  See ticket #1631<commit_after>/**
 * The contents of this file are subject to the OpenMRS Public License
 * Version 1.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://license.openmrs.org
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) OpenMRS, LLC.  All Rights Reserved.
 */
package org.openmrs.web.taglib.fieldgen;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.web.taglib.FieldGenTag;
import org.openmrs.web.taglib.HtmlIncludeTag;

public abstract class AbstractFieldGenHandler implements FieldGenHandler {
	
	protected final Log log = LogFactory.getLog(getClass());
	
	protected FieldGenTag fieldGenTag;
	
	public void setFieldGenTag(FieldGenTag fieldGenTag) {
		this.fieldGenTag = fieldGenTag;
	}
	
	protected void setParameter(String s, Object o) {
		if (this.fieldGenTag != null) {
			//HashMap<String,Object> hmParams = (HashMap<String,Object>)getRequest().getAttribute("org.openmrs.fieldGen.parameterMap");
			HashMap<String, Object> hmParams = (HashMap<String, Object>) this.fieldGenTag.getParameterMap();
			if (hmParams == null)
				hmParams = new HashMap<String, Object>();
			hmParams.put(s, o);
			this.fieldGenTag.setParameterMap(hmParams);
		}
	}
	
	protected void setUrl(String s) {
		if (this.fieldGenTag != null) {
			this.fieldGenTag.setUrl(s);
		}
	}
	
	protected void setVal(Object o) {
		if (this.fieldGenTag != null) {
			this.fieldGenTag.setVal(o);
		}
	}
	
	protected void checkEmptyVal(Object o) {
		if (this.fieldGenTag.getVal() != null) {
			if (this.fieldGenTag.getVal() instanceof String && !(o instanceof String)) {
				if ("".equals(this.fieldGenTag.getVal())) {
					setVal(o);
				}
			}
		}
	}
	
	protected void htmlInclude(String fileToInclude) {
		HtmlIncludeTag hit = new HtmlIncludeTag();
		hit.setPageContext(this.fieldGenTag.getPageContext());
		hit.setFile(fileToInclude);
		try {
			@SuppressWarnings("unused")
			int i = hit.doStartTag();
		}
		catch (JspException e) {
			log.error("Unable to execute doStartTag() method of HtmlIncludeTag from FieldGenHandler");
		}
	}
	
	protected HttpServletRequest getRequest() {
		if (this.fieldGenTag != null) {
			//HttpSession session = this.fieldGenTag.getPageContext().getSession();
			return (HttpServletRequest) this.fieldGenTag.getPageContext().getRequest();
			//return (Context)session.getAttribute(WebConstants.OPENMRS_CONTEXT_HTTPSESSION_ATTR);
		} else
			return null;
	}
}

{'fraction_non_alphanumeric': 0.11060220525869381, 'fraction_numerical': 0.0013570822731128074, 'mean_word_length': 3.7973962571196096, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6615482', 'n_tokens_mistral': 1958, 'n_tokens_neox': 1806, 'n_words': 448}