// Copyright (c) 2003-2014, Jodd Team (jodd.org). All Rights Reserved.

package jodd.lagarto.dom;

import jodd.util.HtmlDecoder;
import jodd.util.StringUtil;

/**
 * Elements attribute.
 */
public class Attribute implements Cloneable {

	protected final String rawName;
	protected final String name;
	protected String value;
	protected String[] splits;

	public Attribute(String rawName, String name, String value, boolean decode) {
		this.rawName = rawName;
		this.name = name;
		this.value = value != null ? (decode ? HtmlDecoder.decode(value) : value) : null;
	}
	
	@Override
	public Attribute clone() {
		return new Attribute(rawName, name, value, false);
	}

	/**
	 * Returns attributes raw name.
	 */
	public String getRawName() {
		return rawName;
	}

	/**
	 * Returns attributes name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns attribute value.
	 */
	public String getValue() {
		return value;
	}

	/**
	 * Sets attribute value.
	 */
	public void setValue(String value) {
		this.value = value;
	}

	// ---------------------------------------------------------------- splits

	/**
	 * Returns true if attribute is containing some value.
	 */
	public boolean isContaining(String include) {
		if (value == null) {
			return false;
		}
		if (splits == null) {
			splits = StringUtil.splitc(value, ' ');
		}

		for (String s: splits) {
			if (s.equals(include)) {
				return true;
			}
		}
		return false;
	}
}

@@ -100,39 +100,8 @@
 %0D%0A%0D%0A
-import jodd.util.HtmlDecoder;%0D%0A
 impo
@@ -396,24 +396,8 @@
 alue
-, boolean decode
 ) %7B%0D
@@ -469,70 +469,8 @@
 alue
- != null ? (decode ? HtmlDecoder.decode(value) : value) : null
 ;%0D%0A%09
@@ -563,15 +563,8 @@
 alue
-, false
 );%0D%0A

remove decoding flag