PageRenderTime 17ms CodeModel.GetById 9ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/razpub/src/com/razie/pub/webui/PageMaker.java

http://razpub.googlecode.com/
Java | 46 lines | 26 code | 8 blank | 12 comment | 3 complexity | 4e4d8f8872367771542f9410699144db MD5 | raw file
 1package com.razie.pub.webui;
 2
 3import java.util.regex.Matcher;
 4import java.util.regex.Pattern;
 5
 6import razie.base.ScriptContext;
 7
 8import com.razie.pub.comms.Comms;
 9import com.razie.pub.comms.SedFilter;
10
11/**
12 * decouple a mutant presentation artifact
13 * 
14 *TODO this entire page filtering thing - make it like streamable and not per line but per html tags, since it's logical, eh?
15 * 
16 * @author razvanc
17 */
18public abstract class PageMaker extends ScriptContext.Impl implements SedFilter {
19    protected PageMaker(ScriptContext parent) {
20        super(parent);
21    }
22
23    public abstract String page(String name);
24
25    @Override
26    public String filter(String line) {
27        // TODO these replace only if they're alone on one line...
28
29        // this is for serving HTML files that reference scripts (for now only pages)
30        // TODO make this generic
31        if (line.matches(".*\\$page\\..*")) {
32            String a = line.substring(line.indexOf('$') + 1);
33            return page(a);
34        } else if (line.matches("<com.razie.include .*")) {
35           // TODO this doesn't work - fix it using the SampleWebServer example...
36            Matcher m = p1.matcher(line);
37            int i = m.groupCount();
38            String url = m.group(1);
39            return Comms.readUrl(url);
40        } else
41            return line;
42    }
43
44     //example <com.razie.include url="/lightsoa/webui/serveClass?name=com.razie.pub.agent.PageServices"/>
45    static Pattern p1 = Pattern.compile("<com.razie.include url=\"([^\"]*)\".*");
46}