mirror of
https://github.com/Mibew/java.git
synced 2024-11-15 09:24:12 +03:00
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:
parent
b865c21688
commit
46f4e47510
@ -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(':', '.');
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
20
src/converter/net.sf.webim.converter/templates/conv.ltp
Normal file
20
src/converter/net.sf.webim.converter/templates/conv.ltp
Normal 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}
|
8
src/converter/net.sf.webim.converter/templates/php.ltp
Normal file
8
src/converter/net.sf.webim.converter/templates/php.ltp
Normal 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}
|
9
src/converter/net.sf.webim.converter/templates/x.ltp
Normal file
9
src/converter/net.sf.webim.converter/templates/x.ltp
Normal 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}
|
||||
|
||||
|
8
src/converter/net.sf.webim.converter/test/index.xml
Normal file
8
src/converter/net.sf.webim.converter/test/index.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<x:html>
|
||||
<head>
|
||||
A
|
||||
</head>
|
||||
<body>
|
||||
B
|
||||
</body>
|
||||
</x:html>
|
Loading…
Reference in New Issue
Block a user