All Downloads are FREE. Search and download functionalities are using the official Maven repository.

stalkr.html.parser.AttributeElementSetter Maven / Gradle / Ivy

There is a newer version: 0.3.1
Show newest version
package stalkr.html.parser;

import java.lang.reflect.Field;

import lombok.RequiredArgsConstructor;
import lombok.val;

import org.jsoup.nodes.Element;

@RequiredArgsConstructor
public class AttributeElementSetter implements Setter {

	final Field field;
	final String selector;
	final String attribute;

	@Override
	public void bind( final Element document, final Object instance ) {
		try {
			val element = document.select( selector ).first();
			if ( element != null )
				field.set( instance, element.attr( attribute ) );
		} catch ( IllegalArgumentException | IllegalAccessException e ) {
			throw new RuntimeException( e );
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy