initial idea to generate site from templates

git-svn-id: https://webim.svn.sourceforge.net/svnroot/webim/trunk@44 c66351dc-e62f-0410-b875-e3a5c0b9693f
This commit is contained in:
Evgeny Gryaznov 2008-01-25 14:39:09 +00:00
parent b865c21688
commit 46f4e47510
6 changed files with 84 additions and 3 deletions

View File

@ -0,0 +1,26 @@
package net.sf.webim.converter;
import net.sf.lapg.templates.api.impl.DefaultStaticMethods;
import net.sf.lapg.templates.model.xml.XmlData;
import net.sf.lapg.templates.model.xml.XmlNode;
public class ConverterHelper extends DefaultStaticMethods {
public boolean isNode(XmlNode element) {
return true;
}
public boolean isNode(XmlData element) {
return false;
}
public boolean containsColon(String s) {
return s.indexOf(":") >= 0;
}
public String replaceColon(String s) {
return s.replace(':', '.');
}
}

View File

@ -1,22 +1,32 @@
package net.sf.webim.converter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import net.sf.lapg.templates.api.EvaluationContext;
import net.sf.lapg.templates.api.impl.FolderTemplateLoader;
import net.sf.lapg.templates.api.impl.TemplateEnvironment;
import net.sf.lapg.templates.model.xml.XmlModel;
import net.sf.lapg.templates.model.xml.XmlNavigationFactory;
import net.sf.lapg.templates.model.xml.XmlNode;
public class JspConverter {
public static void main(String[] args) {
String toProcess = getFileContents("../test.xml");
String toProcess = getFileContents("test/index.xml");
XmlNode root = XmlModel.load(toProcess);
System.out.println(">>>\n" + root.toString() + "<<<");
ConverterHelper helper = new ConverterHelper();
TemplateEnvironment env = new TemplateEnvironment(
new XmlNavigationFactory(),
new FolderTemplateLoader(new File("templates")));
EvaluationContext context = new EvaluationContext(root.getChildren());
context.setVariable("helper", helper);
System.out.println(env.executeTemplate("conv.convertList", context, null));
}
private static String getFileContents(String file) {

View File

@ -0,0 +1,20 @@
${template convert-}
${if helper.isNode(this)-}
${if helper.containsColon(tagName)-}
${call(`helper.replaceColon(tagName)`) this-}
${else-}
${this.getNodeDeclaration()-}
${call(convertList) children-}
</${tagName}>${end-}
${else-}
${this-}
${end-}
${end}
${template convertList-}
${foreach child in this-}
${call(convert) child-}
${end-}
${end}

View File

@ -0,0 +1,8 @@
${template hidden-}
${if attrs.value-}
<input type="hidden" name="${attrs.name}" value="${attrs.value}"/>
${else-}
<input type="hidden" name="${attrs.property}" value="<?php echo ${attrs.property} ?>"\/>
${end-}
${end}

View File

@ -0,0 +1,9 @@
${template html-}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
${call(conv.convertList)children-}
</html>
${end}

View File

@ -0,0 +1,8 @@
<x:html>
<head>
A
</head>
<body>
B
</body>
</x:html>