X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fwotns%2Ftemplate%2FHttpRequestAccessor.java;fp=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fwotns%2Ftemplate%2FHttpRequestAccessor.java;h=d8b44ee399c6d5b8bfe708483fa197a2a8ee6a2d;hb=e17750852b6d02aeb6270f6a7e2619ced1f4f9b7;hp=0000000000000000000000000000000000000000;hpb=231a7fce4ed6828b3731fa93b8adc1cdda813092;p=WoTNS.git diff --git a/src/main/java/net/pterodactylus/wotns/template/HttpRequestAccessor.java b/src/main/java/net/pterodactylus/wotns/template/HttpRequestAccessor.java new file mode 100644 index 0000000..d8b44ee --- /dev/null +++ b/src/main/java/net/pterodactylus/wotns/template/HttpRequestAccessor.java @@ -0,0 +1,47 @@ +/* + * Sone - HttpRequestAccessor.java - Copyright © 2011 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.wotns.template; + +import net.pterodactylus.util.template.Accessor; +import net.pterodactylus.util.template.ReflectionAccessor; +import net.pterodactylus.util.template.TemplateContext; +import freenet.support.api.HTTPRequest; + +/** + * {@link Accessor} implementation that can parse headers from + * {@link HTTPRequest}s. + * + * @see HTTPRequest#getHeader(String) + * @author David ‘Bombe’ Roden + */ +public class HttpRequestAccessor extends ReflectionAccessor { + + /** + * {@inheritDoc} + */ + @Override + public Object get(TemplateContext templateContext, Object object, String member) { + Object parentValue = super.get(templateContext, object, member); + if (parentValue != null) { + return parentValue; + } + HTTPRequest httpRequest = (HTTPRequest) object; + return httpRequest.getHeader(member); + } + +}