/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

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