r1084 - in trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication: . engine
Author: mfortun Date: 2011-07-22 18:22:08 +0200 (Fri, 22 Jul 2011) New Revision: 1084 Url: http://nuiton.org/repositories/revision/wikitty/1084 Log: * first step to build a script engine for html Added: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngineFactory.java Added: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java (rev 0) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java 2011-07-22 16:22:08 UTC (rev 1084) @@ -0,0 +1,194 @@ +package org.nuiton.wikitty.publication.engine; + +import java.io.Reader; +import java.util.Map; +import java.util.StringTokenizer; + +import javax.script.Bindings; +import javax.script.ScriptContext; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineFactory; +import javax.script.ScriptException; +import javax.script.SimpleBindings; + + +public class HtmlScriptEngine implements ScriptEngine{ + + /* + * algo super simple en fait. + * + * On lit le code. + * pour tout ce qui est dans les clés des bindings on fait l'invocation + * java qui va avec. + * + */ + + + + /** + * usefull to match element contained inside the binding map that on which + * method are called. like : + * objectName.getName() + * objectName.setName("truc") + */ + static public String REGEX_BIND_ELEMENT_METHOD = "\\..*\\(.*\\)"; + static public String REGEX_END="$"; + static public String REGEX_EMPTY_END=" *"+REGEX_END; + + + protected ScriptEngineFactory factory; + protected ScriptContext context; + protected Map<String, Object> attributes; + + + + + + @Override + public Object eval(String script, ScriptContext context) + throws ScriptException { + // TODO mfortun + throw new UnsupportedOperationException("not yet implemented"); + //return null; + + } + + @Override + public Object eval(Reader reader, ScriptContext context) + throws ScriptException { + // TODO mfortun + throw new UnsupportedOperationException("not yet implemented"); + //return null; + + } + + @Override + public Object eval(String script) throws ScriptException { + // TODO mfortun + throw new UnsupportedOperationException("not yet implemented"); + //return null; + + } + + @Override + public Object eval(Reader reader) throws ScriptException { + // TODO mfortun + throw new UnsupportedOperationException("not yet implemented"); + //return null; + + } + + @Override + public Object eval(String script, Bindings n) throws ScriptException { + // TODO mfortun + throw new UnsupportedOperationException("not yet implemented"); + //return null; + + } + + @Override + public Object eval(Reader reader, Bindings n) throws ScriptException { + // TODO mfortun + throw new UnsupportedOperationException("not yet implemented"); + //return null; + + } + + @Override + public void put(String key, Object value) { + attributes.put(key, value); + } + + @Override + public Object get(String key) { + return attributes.get(key); + } + + @Override + public Bindings getBindings(int scope) { + return context.getBindings(scope); + } + + @Override + public void setBindings(Bindings bindings, int scope) { + context.setBindings(bindings, scope); + } + + @Override + public Bindings createBindings() { + return new SimpleBindings(); + } + + @Override + public ScriptContext getContext() { + return context; + } + + @Override + public void setContext(ScriptContext context) { + this.context=context; + } + + @Override + public ScriptEngineFactory getFactory() { + if (factory==null){ + factory = new HtmlScriptEngineFactory(); + } + return factory; + } + + + protected String evaluateCodeInsideHtml(String code, Bindings binds){ + String result = new String (code); + + for (String key: binds.keySet()){ + + Object oo = binds.get(key); + + String [] hmtl = code.split(key+REGEX_BIND_ELEMENT_METHOD); + + + for(int i=0; i<hmtl.length-1; i++){ + int begin = code.indexOf(hmtl[i]); + begin = begin+hmtl[i].length()+1; + + int end = code.indexOf(hmtl[i+1]); + end=end-1; + + String codeToExecude = code.substring(begin, end); + + String resultCode=""; + + // replace at position by result + + + + + } + code.replaceAll(key+REGEX_END, oo.toString()); + code.replaceAll(key+REGEX_EMPTY_END, oo.toString()+" "); + + + + /* + * Voir si on match aussi les trucs plus générique avec + * déclaration de classe et tout le tintouint + * + * Si ça match le nom et avec le nom associé à la regex method + * cette derniuère est prioritaire. + * Et on éxécute la méthode sur l'objet. + * + * Si ça match seulement avec le nom alors on fait + * getValue().tostring + * + * + * + */ + + + + } + return result; + } + +} Property changes on: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngine.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngineFactory.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngineFactory.java (rev 0) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngineFactory.java 2011-07-22 16:22:08 UTC (rev 1084) @@ -0,0 +1,103 @@ +package org.nuiton.wikitty.publication.engine; + +import java.util.List; + +import javax.script.ScriptEngine; +import javax.script.ScriptEngineFactory; + + +public class HtmlScriptEngineFactory implements ScriptEngineFactory{ + + @Override + public String getEngineName() { + return "HTML"; + + } + + @Override + public String getEngineVersion() { + return "0.1"; + } + + @Override + public List<String> getExtensions() { + // TODO mfortun + throw new UnsupportedOperationException("not yet implemented"); + //return null; + + } + + @Override + public List<String> getMimeTypes() { + // TODO mfortun + throw new UnsupportedOperationException("not yet implemented"); + //return null; + + } + + @Override + public List<String> getNames() { + // TODO mfortun + throw new UnsupportedOperationException("not yet implemented"); + //return null; + + } + + @Override + public String getLanguageName() { + return "HTML"; + } + + @Override + public String getLanguageVersion() { + // TODO mfortun + throw new UnsupportedOperationException("not yet implemented"); + //return null; + + } + + @Override + public Object getParameter(String key) { + // TODO mfortun + throw new UnsupportedOperationException("not yet implemented"); + //return null; + + } + + @Override + public String getMethodCallSyntax(String obj, String m, String... args) { + // TODO mfortun + throw new UnsupportedOperationException("not yet implemented"); + //return null; + + } + + @Override + public String getOutputStatement(String toDisplay) { + // TODO mfortun + throw new UnsupportedOperationException("not yet implemented"); + //return null; + + } + + @Override + public String getProgram(String... statements) { + // TODO mfortun + throw new UnsupportedOperationException("not yet implemented"); + //return null; + + } + + @Override + public ScriptEngine getScriptEngine() { + // TODO mfortun + throw new UnsupportedOperationException("not yet implemented"); + //return null; + + } + + + + + +} Property changes on: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/engine/HtmlScriptEngineFactory.java ___________________________________________________________________ Added: svn:mime-type + text/plain
participants (1)
-
mfortun@users.nuiton.org