1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
package nokogiri;
import static org.jruby.runtime.Helpers.invoke;
import org.cyberneko.html.HTMLEntities;
import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.RubyObject;
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
/**
* Class for Nokogiri::HTML4::EntityLookup.
*
* @author Patrick Mahoney <pat@polycrystal.org>
*/
@JRubyClass(name = "Nokogiri::HTML4::EntityLookup")
public class Html4EntityLookup extends RubyObject
{
public
Html4EntityLookup(Ruby runtime, RubyClass rubyClass)
{
super(runtime, rubyClass);
}
/**
* Looks up an HTML entity <code>key</code>.
*
* The description is a bit lacking.
*/
@JRubyMethod()
public IRubyObject
get(ThreadContext context, IRubyObject key)
{
Ruby ruby = context.getRuntime();
String name = key.toString();
int val = HTMLEntities.get(name);
if (val == -1) { return ruby.getNil(); }
IRubyObject edClass =
ruby.getClassFromPath("Nokogiri::HTML4::EntityDescription");
IRubyObject edObj = invoke(context, edClass, "new",
ruby.newFixnum(val), ruby.newString(name),
ruby.newString(name + " entity"));
return edObj;
}
}
|