package fr.mantal.wcdl;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

class Property
{
	private String selector = null;
	private String attribute = null;
	private String regex = null;


	Property(String selector, String attribute, String regex)
	{
		this.selector = selector;
		this.attribute = attribute;
		this.regex = regex;
	}

	Property(String selector, String attribute)
	{
		this(selector, attribute, null);
	}

	Property(String selector)
	{
		this(selector, null, null);
	}

	Property()
	{
	}

	String get(Document document)
	{
		if (selector == null)//TODO check if this should happen
			return "";

		Element element = document.select(selector).first();

		String text = attribute == null ? element.text() : element.attr(attribute);

		if (regex == null)
			return text;

		Matcher matcher = Pattern.compile(regex).matcher(text);

		if (!matcher.find())
			return null;
		return matcher.group(1);
	}
}

@@ -263,16 +263,51 @@
 = null;%0A
+%09private boolean keepHtml = false;%0A
 %0A%0A%09Prope
@@ -779,16 +779,56 @@
 rst();%0A%0A
+%09%09if (element == null)%0A%09%09%09return null;%0A%0A
 %09%09String
@@ -835,16 +835,29 @@
  text = 
+null;%0A%0A%09%09if (
 attribut
@@ -869,27 +869,84 @@
 null
- ? element.text() :
+)%0A%09%09%09text = keepHtml ? element.toString() : element.text();%0A%09%09else%0A%09%09%09text =
  ele

Add an option for Property to keep html