| 1 | |
package org.webslinger.rules; |
| 2 | |
|
| 3 | |
import java.io.IOException; |
| 4 | |
import javax.servlet.ServletRequest; |
| 5 | |
|
| 6 | |
import org.webslinger.Webslinger; |
| 7 | |
import org.webslinger.PathContext; |
| 8 | |
import org.webslinger.container.WebslingerContainer; |
| 9 | |
|
| 10 | 527 | public class CSSResolveValue extends AbstractListValue<PathContext> { |
| 11 | |
private AbstractPathValue dir; |
| 12 | |
private AbstractValue<String> value; |
| 13 | |
private PathContext dirConstant; |
| 14 | |
|
| 15 | |
public CSSResolveValue(int id) { |
| 16 | 0 | super(id); |
| 17 | 0 | } |
| 18 | |
|
| 19 | |
public CSSResolveValue(Rules p, int id) { |
| 20 | 43 | super(p, id); |
| 21 | 43 | } |
| 22 | |
|
| 23 | |
|
| 24 | |
public Object jjtAccept(RulesVisitor visitor, Object data) { |
| 25 | 0 | return visitor.visit(this, data); |
| 26 | |
} |
| 27 | |
|
| 28 | |
protected PathContext getDir(ServletRequest request, Webslinger top) throws IOException { |
| 29 | 527 | if (dirConstant == null) return dir.getValue(request, top); |
| 30 | 0 | System.err.println("returning constant"); |
| 31 | 0 | return dirConstant; |
| 32 | |
} |
| 33 | |
|
| 34 | |
public PathContext[] getValue(ServletRequest request, Webslinger top) throws IOException { |
| 35 | 527 | PathContext dir = getDir(request, top); |
| 36 | 527 | WebslingerContainer container = top.getPathContext().getInfo().getContainer(); |
| 37 | 527 | if (value instanceof AbstractSingleValue) { |
| 38 | 499 | String value = AbstractSingleValue.class.cast(this.value).getValue(request, top); |
| 39 | 499 | if (value == null) return null; |
| 40 | 126 | if (value.startsWith("./")) return new PathContext[] {top.resolvePath(value)}; |
| 41 | 103 | return new PathContext[] {container.resolve(dir, top.getPathContext(), value, true)}; |
| 42 | |
} |
| 43 | 28 | String[] values = (String[]) AbstractListValue.class.cast(value).getValue(request, top); |
| 44 | 28 | if (values == null) return null; |
| 45 | 1 | PathContext[] pcValues = new PathContext[values.length]; |
| 46 | 2 | for (int i = 0; i < values.length; i++) { |
| 47 | 1 | pcValues[i] = container.resolve(dir, top.getPathContext(), values[i], true); |
| 48 | |
} |
| 49 | 1 | return pcValues; |
| 50 | |
} |
| 51 | |
|
| 52 | |
public void compile(WebslingerContainer container) throws IOException { |
| 53 | 43 | dir = (AbstractPathValue) jjtGetChild(0); |
| 54 | 43 | dir.compile(container); |
| 55 | 43 | if (dir instanceof ConstantValue) dirConstant = container.resolve(((ConstantValue) dir).getConstantValue()); |
| 56 | 43 | value = (AbstractValue<String>) jjtGetChild(1); |
| 57 | 43 | value.compile(container); |
| 58 | 43 | } |
| 59 | |
} |