<commit_before>/*
 * DomUI Java User Interface library
 * Copyright (c) 2010 by <NAME>, Itris B.V.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * See the "sponsors" file for a list of supporters.
 *
 * The latest version of DomUI and related code, support and documentation
 * can be found at http://www.domui.org/
 * The contact for the project is <NAME> <<EMAIL>>.
 */
package to.etc.domui.dom.html;

import to.etc.domui.server.*;
import to.etc.domui.util.*;

/**
 * The base tag for an Image.
 *
 * <h2>Tips and tricks</h2>
 * <p>To prevent the butt-ugly border on any image placed in an A tag add the following rule to the CSS:
 *  <pre>
 *  a img {
 *      border: medium none;
 *  }
 *  </pre>
 * </p>
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * Created on Jun 4, 2008
 */
public class Img extends NodeBase {
	private String m_alt;

	private String m_src;

	private ImgAlign m_align;

	private int m_imgBorder = -1;

	private String m_imgHeight;

	private String m_imgWidth;

	/**
	 * Creates an uninitialized image.
	 */
	public Img() {
		super("img");
	}

	/**
	 * Creates an image with the specified source. This should be an absolute web resource path.  If the name is prefixed
	 * with THEME/ it specifies an image from the current THEME's directory.
	 * @param src
	 */
	public Img(String src) {
		this();
		setSrc(src);
		setImgBorder(0);
	}

	/**
	 * Creates an image with the specified source. This should be an absolute web resource path.  If the name is prefixed
	 * with THEME/ it specifies an image from the current THEME's directory.
	 * @param src
	 */
	public Img(Class< ? > base, String src) {
		this();
		setSrc(base, src);
		setImgBorder(0);
	}

	//	/**
	//	 * Creates an image with the specified source. This can be theme-relative or it can be an
	//	 * absolute web resource path.
	//	 * @param themesrc
	//	 * @param src
	//	 */
	//	public Img(boolean themesrc, String src) {
	//		this();
	//		if(themesrc)
	//			setThemeSrc(src);
	//		else
	//			setSrc(src);
	//		setImgBorder(0);
	//	}

	@Override
	public void visit(INodeVisitor v) throws Exception {
		v.visitImg(this);
	}

	/**
	 * Return the current "alt" string of the image.
	 * @return
	 */
	public String getAlt() {
		return m_alt;
	}

	/**
	 * Set the "alt" string of the image.
	 * @param alt
	 */
	public void setAlt(String alt) {
		if(!DomUtil.isEqual(alt, m_alt))
			changed();
		m_alt = alt;
	}

	/**
	 * Get the current source for the image as an absolute web app path.
	 * @return
	 */
	public String getSrc() {
		return DomApplication.get().getThemedResourceRURL(m_src);
	}

	/**
	 * Set the source for this image as an absolute web app path. If the name is prefixed
	 * with THEME/ it specifies an image from the current THEME's directory.
	 * @param src
	 */
	public void setSrc(String src) {
		if(src.startsWith("/"))
			src = src.substring(1);
		//		src = PageContext.getRequestContext().translateResourceName(src);
		if(!DomUtil.isEqual(src, m_src))
			changed();
		m_src = src;
	}

	/**
	 * Set the source as a Java resource based off the given class.
	 * @param base
	 * @param resurl
	 */
	public void setSrc(Class< ? > base, String resurl) {
		String s = DomUtil.getJavaResourceRURL(base, resurl);
		setSrc(s);
	}

	//	/**
	//	 * Set the image source to come from the current theme.
	//	 * @param src
	//	 */
	//	public void setThemeSrc(String src) {
	//		String nw = PageContext.getRequestContext().getRelativeThemePath(src);
	//		if(! DomUtil.isEqual(nw, m_src))
	//			changed();<commit_msg>Blunder fix: Img removed first / from it's src url, rendering all host-relative urls invalid.<commit_after>/*
 * DomUI Java User Interface library
 * Copyright (c) 2010 by <NAME>, Itris B.V.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * See the "sponsors" file for a list of supporters.
 *
 * The latest version of DomUI and related code, support and documentation
 * can be found at http://www.domui.org/
 * The contact for the project is <NAME> <<EMAIL>>.
 */
package to.etc.domui.dom.html;

import to.etc.domui.server.*;
import to.etc.domui.util.*;

/**
 * The base tag for an Image.
 *
 * <h2>Tips and tricks</h2>
 * <p>To prevent the butt-ugly border on any image placed in an A tag add the following rule to the CSS:
 *  <pre>
 *  a img {
 *      border: medium none;
 *  }
 *  </pre>
 * </p>
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * Created on Jun 4, 2008
 */
public class Img extends NodeBase {
	private String m_alt;

	private String m_src;

	private ImgAlign m_align;

	private int m_imgBorder = -1;

	private String m_imgHeight;

	private String m_imgWidth;

	/**
	 * Creates an uninitialized image.
	 */
	public Img() {
		super("img");
	}

	/**
	 * Creates an image with the specified source. This should be an absolute web resource path.  If the name is prefixed
	 * with THEME/ it specifies an image from the current THEME's directory.
	 * @param src
	 */
	public Img(String src) {
		this();
		setSrc(src);
		setImgBorder(0);
	}

	/**
	 * Creates an image with the specified source. This should be an absolute web resource path.  If the name is prefixed
	 * with THEME/ it specifies an image from the current THEME's directory.
	 * @param src
	 */
	public Img(Class< ? > base, String src) {
		this();
		setSrc(base, src);
		setImgBorder(0);
	}

	//	/**
	//	 * Creates an image with the specified source. This can be theme-relative or it can be an
	//	 * absolute web resource path.
	//	 * @param themesrc
	//	 * @param src
	//	 */
	//	public Img(boolean themesrc, String src) {
	//		this();
	//		if(themesrc)
	//			setThemeSrc(src);
	//		else
	//			setSrc(src);
	//		setImgBorder(0);
	//	}

	@Override
	public void visit(INodeVisitor v) throws Exception {
		v.visitImg(this);
	}

	/**
	 * Return the current "alt" string of the image.
	 * @return
	 */
	public String getAlt() {
		return m_alt;
	}

	/**
	 * Set the "alt" string of the image.
	 * @param alt
	 */
	public void setAlt(String alt) {
		if(!DomUtil.isEqual(alt, m_alt))
			changed();
		m_alt = alt;
	}

	/**
	 * Get the current source for the image as an absolute web app path.
	 * @return
	 */
	public String getSrc() {
		return DomApplication.get().getThemedResourceRURL(m_src);
	}

	/**
	 * Set the source for this image as an absolute web app path. If the name is prefixed
	 * with THEME/ it specifies an image from the current THEME's directory.
	 * @param src
	 */
	public void setSrc(String src) {
		//		if(src.startsWith("/"))							// jal 20120904 WTF?! This cannot be done, because host-relative URLs are invalid this way.
		//			src = src.substring(1);
		//		src = PageContext.getRequestContext().translateResourceName(src);
		if(!DomUtil.isEqual(src, m_src))
			changed();
		m_src = src;
	}

	/**
	 * Set the source as a Java resource based off the given class.
	 * @param base
	 * @param resurl
	 */
	public void setSrc(Class< ? > base, String resurl) {
		String s = DomUtil.getJavaResourceRURL(base, resurl);
		setSrc(s);
	}

	//	/**
	//	 * Set the image source to come from the current theme.
	//	 * @param src
	//	 */
	//	public void setThemeSrc(String src) {
	//		String nw = PageContext.getRequestContext().getRelativeThemePath(src);
	//		if(! DomUtil.isEqual(nw, m_src))
	//			changed();
{'fraction_non_alphanumeric': 0.11559014869888476, 'fraction_numerical': 0.00766728624535316, 'mean_word_length': 3.0551106924163918, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, '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': '2394816', 'n_tokens_mistral': 2942, 'n_tokens_neox': 2734, 'n_words': 1053}