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

cc.owoo.godpen.content.html.extract.function.AttFunction Maven / Gradle / Ivy

package cc.owoo.godpen.content.html.extract.function;

import cc.owoo.godpen.content.html.HtmlElement;
import cc.owoo.godpen.content.html.Html;
import cc.owoo.godpen.content.html.extract.FunctionHandler;
import cc.owoo.godpen.content.html.extract.MapResult;

/**
 * Created by nimensei
 * 2022-10-20 上午 10:10
 */
public class AttFunction extends FunctionHandler {
    private final String key;// 键

    public AttFunction() {
        key = null;
    }

    public AttFunction(String key) {
        this.key = key;
    }

    @Override
    protected Object handler(String string) {
        return handler(Html.parse(string));
    }

    @Override
    protected Object handler(MapResult mapResult) {
        return mapResult.get(key);
    }

    @Override
    protected Object handler(HtmlElement htmlElement) {
        String attribute = htmlElement.getAttribute(key);
        return attribute == null ? null : attribute.strip();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy