Revision: 2002
http://svn.sourceforge.net/vexi/?rev=2002&view=rev
Author: mkpg2
Date: 2007-07-19 10:15:43 -0700 (Thu, 19 Jul 2007)
Log Message:
-----------
Small refactoring. Preparing for ui:apply (essentially a generalisation).
Modified Paths:
--------------
core/trunk/org.vexi.core/src/org/vexi/core/Template.java
core/trunk/org.vexi.core/src/org/vexi/core/TemplateBuilder.java
core/trunk/org.vexi.devl/src/org/vexi/core/DevlTemplateBuilder.jpp
Modified: core/trunk/org.vexi.core/src/org/vexi/core/Template.java
===================================================================
--- core/trunk/org.vexi.core/src/org/vexi/core/Template.java 2007-07-19
16:46:43 UTC (rev 2001)
+++ core/trunk/org.vexi.core/src/org/vexi/core/Template.java 2007-07-19
17:15:43 UTC (rev 2002)
@@ -83,8 +83,6 @@
//String redirect = null; ///< the id of the redirect target;
only meaningful on a root node
JS[] keys; ///< keys to be "put" to instances of this
template; elements correspond to those of vals
JS[] vals; ///< values to be "put" to instances of this
template; elements correspond to those of keys
-
- Prefixes uriPrefixes; // Uri prefixes->Blessings
Vec children = new Vec(); ///< during XML parsing, this holds the list
of currently-parsed children; null otherwise
JS script = null; ///< the script on this node
@@ -232,80 +230,6 @@
}
- /**
- * Contains list of xml namespace prefixes. The <vexi/> and
- * each template node has its xml namespace converted into JS objects
- * (blessings) giving them an equivalent sense in JS code.
- * <p>
- * Initially stores a string for the value. Resolves and converts it to
- * a blessing on first access.
- *
- * @author mike
- *
- */
- static class Prefixes /*<JSString, String|Blessing>*/ {
- static final Object NULL_PLACEHOLDER = new Object();
- private Basket.Hash map = new Basket.Hash();
- Prefixes parent;
- JS vexi;
- Prefixes(JS vexi, Prefixes parent, Tree.Element e){
- this.parent = parent;
- this.vexi = vexi;
- Tree.Prefixes prefixes = e.getPrefixes();
- for (int i=0; i < prefixes.pfxSize(); i++) {
- String key = prefixes.getPrefixKey(i);
- String val = prefixes.getPrefixVal(i);
- if (val.equals("vexi://ui")) continue;
- if (val.equals("vexi://meta")) continue;
- if (val.length() > 0 && val.charAt(0) == '.') val =
val.substring(1);
- map.put(JSU.S(key),val);
- }
- }
-
-
- public boolean isPrefix(String key){
- try {
- return get(JSU.S(key),false)!=null;
- } catch (JSExn e) {
- e.printStackTrace();
- return false;
- }
- }
-
- // Used at two different stages
- // - parsing, resolved == false
- // - js execution, resolved == true
- // In org.vexi.devl we inspect the prefixes as part of the checking
- // for undeclared globals. We do not want to resolve as this will
- // change the order in which templates are resolved, giving a
- // different behaviour to the non-devl code, which is very
undesirable.hout
- public Object get(JS key, boolean resolve) throws JSExn {
- Object r =map.get(key);
- if(r==NULL_PLACEHOLDER)
- return null;
- // Resolve on demand (each prefix resolved once per template
file)
- if(resolve && r instanceof String){
- // TODO convert to Blessing
- r = Vexi.resolveString(vexi,(String)r, true);
- map.put(key, r);
- }
-
- if(r == null && parent!=null){
- r = parent.get(key, resolve);
- if(r==null){
- // Default to root namespace
- if("".equals(JSU.toString(key)))
- r = vexi.get(key);
- else // Remember nulls
- map.put(key, NULL_PLACEHOLDER);
- }
- }
- return r;
- }
-
- }
-
-
///////////
// GLOBAL SCOPES
///
@@ -429,6 +353,83 @@
StringBuffer content = null; ///< during XML parsing, this holds
partially-read character data; null otherwise
int content_start = 0; ///< line number of the first line of
<tt>content</tt>
int startLine = -1; ///< the line number that this element
starts on
+
+ Prefixes uriPrefixes; // Uri prefixes->Blessings
+
+
+ /**
+ * Contains list of xml namespace prefixes. The <vexi/> and
+ * each template node has its xml namespace converted into JS objects
+ * (blessings) giving them an equivalent sense in JS code.
+ * <p>
+ * Initially stores a string for the value. Resolves and converts it to
+ * a blessing on first access.
+ *
+ * @author mike
+ *
+ */
+ static class Prefixes /*<JSString, String|Blessing>*/ {
+ static final Object NULL_PLACEHOLDER = new Object();
+ private Basket.Hash map = new Basket.Hash();
+ Prefixes parent;
+ JS vexi;
+ Prefixes(JS vexi, Prefixes parent, Tree.Element e){
+ this.parent = parent;
+ this.vexi = vexi;
+ Tree.Prefixes prefixes = e.getPrefixes();
+ for (int i=0; i < prefixes.pfxSize(); i++) {
+ String key = prefixes.getPrefixKey(i);
+ String val = prefixes.getPrefixVal(i);
+ if (val.equals("vexi://ui")) continue;
+ if (val.equals("vexi://meta")) continue;
+ if (val.length() > 0 && val.charAt(0) == '.') val =
val.substring(1);
+ map.put(JSU.S(key),val);
+ }
+ }
+
+
+ public boolean isPrefix(String key){
+ try {
+ return get(JSU.S(key),false)!=null;
+ } catch (JSExn e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ // Used at two different stages
+ // - parsing, resolved == false
+ // - js execution, resolved == true
+ // In org.vexi.devl we inspect the prefixes as part of the
checking
+ // for undeclared globals. We do not want to resolve as this
will
+ // change the order in which templates are resolved, giving a
+ // different behaviour to the non-devl code, which is very
undesirable.hout
+ public Object get(JS key, boolean resolve) throws JSExn {
+ Object r =map.get(key);
+ if(r==NULL_PLACEHOLDER)
+ return null;
+ // Resolve on demand (each prefix resolved once per
template file)
+ if(resolve && r instanceof String){
+ // TODO convert to Blessing
+ r = Vexi.resolveString(vexi,(String)r, true);
+ map.put(key, r);
+ }
+
+ if(r == null && parent!=null){
+ r = parent.get(key, resolve);
+ if(r==null){
+ // Default to root namespace
+ if("".equals(JSU.toString(key)))
+ r = vexi.get(key);
+ else // Remember nulls
+ map.put(key, NULL_PLACEHOLDER);
+ }
+ }
+ return r;
+ }
+
+ }
+
}
Modified: core/trunk/org.vexi.core/src/org/vexi/core/TemplateBuilder.java
===================================================================
--- core/trunk/org.vexi.core/src/org/vexi/core/TemplateBuilder.java
2007-07-19 16:46:43 UTC (rev 2001)
+++ core/trunk/org.vexi.core/src/org/vexi/core/TemplateBuilder.java
2007-07-19 17:15:43 UTC (rev 2002)
@@ -18,7 +18,7 @@
import org.ibex.util.Tree;
import org.ibex.util.Vec;
import org.ibex.util.XML;
-import org.vexi.core.Template.Prefixes;
+import org.vexi.core.CodeBlock.Prefixes;
import org.vexi.core.Template.Static;
@@ -74,7 +74,6 @@
private int state = STATE_INITIAL;
CodeBlock staticCode = new CodeBlock();
- Prefixes staticPrefixes;
int meta_start = -1; // Used in calculating endLines to add to
static_content
@@ -92,7 +91,7 @@
if (is != null) {
parse(new InputStreamReader(is));
if(Log.sLevel==Log.DEBUG)Log.uDebug(TemplateHelper.class, "Parsing template: "
+ sourceName());
- JS staticScript =
parseScript(staticCode.content, staticCode.content_start, sourceName(),
createStaticChecker(staticPrefixes));
+ JS staticScript =
parseScript(staticCode.content, staticCode.content_start, sourceName(),
createStaticChecker(staticCode.uriPrefixes));
if (t != null) {
initStatic();
JS staticScope = t.new StaticScope();
@@ -128,7 +127,7 @@
private void initStatic(){
Static staticPart = unresolved.staticPart;
- staticPart.init(staticPrefixes);
+ staticPart.init(staticCode.uriPrefixes);
// Share static part with preapplies
Template t2 = t;
while(t2!=null){
@@ -142,7 +141,7 @@
/** @param c - current element */
public void startElement(Tree.Element c) throws XML.Exn {
- Prefixes parentPrefixes = null;
+ CodeBlock lastCb = cb;
Tree.Attributes a = c.getAttributes();
switch(state) {
case STATE_IN_META_NODE: { meta++; return; }
@@ -152,7 +151,7 @@
if (a.attrSize() != 0)
throw new XML.Exn("root element must not have
attributes", XML.Exn.SCHEMA, getLine(), getCol());
state = STATE_IN_ROOT_NODE;
- staticPrefixes = new Prefixes(vexi(),null, c);
+ staticCode.uriPrefixes = new Prefixes(vexi(),null, c);
cb = staticCode;
// Check uri declarations. Warn if no default namespace
created
// TODO improve feedback from resultant mistakes so
that this
@@ -176,18 +175,16 @@
return;
}
state = STATE_IN_TEMPLATE_NODE;
- parentPrefixes = staticPrefixes;
cb = t = (t == null) ?
unresolved.init(getLine())
: new Template(t, getLine());
break;
case STATE_IN_TEMPLATE_NODE:
- nodeStack.addElement(t);
- parentPrefixes = t.uriPrefixes;
cb = t = new Template(vexi(), getLine(),t);
break;
}
-
+ nodeStack.addElement(lastCb);
+
// // FIXME: This is all wrong
// Hopefully less wrong now.
if (!("vexi://ui".equals(c.getUri()) &&
"box".equals(c.getLocalName()))) {
@@ -197,7 +194,7 @@
}
// JS Code has access to namespace objects
- t.uriPrefixes = new Prefixes(vexi(), parentPrefixes, c);
+ t.uriPrefixes = new CodeBlock.Prefixes(vexi(), lastCb.uriPrefixes,
c);
// FIXME: 2-value Array
Basket.Array keys = new Basket.Array(a.attrSize());
@@ -267,22 +264,18 @@
case STATE_IN_ROOT_NODE:
return;
case STATE_IN_TEMPLATE_NODE: {
+ Template oldt = t;
+ cb = (CodeBlock) nodeStack.lastElement();
+ nodeStack.setSize(nodeStack.size() - 1);
+ if (cb.content != null){
+ insertNewLines(cb.content, getLine() - oldt.startLine);
+ }
if (nodeStack.size() == 0) {
state = STATE_IN_ROOT_NODE;
- if (staticCode.content != null) {
- insertNewLines(staticCode.content,
getLine()-t.startLine);
- }
- cb = staticCode;
- return;
+ }else{
+ t = (Template)cb;
+ t.children.addElement(oldt);
}
- Template oldt = t;
- cb = t = (Template)nodeStack.lastElement();
- nodeStack.setSize(nodeStack.size() - 1);
- t.children.addElement(oldt);
-
- if (t.content != null){
- insertNewLines(t.content, getLine() - oldt.startLine);
- }
}
}
}
Modified: core/trunk/org.vexi.devl/src/org/vexi/core/DevlTemplateBuilder.jpp
===================================================================
--- core/trunk/org.vexi.devl/src/org/vexi/core/DevlTemplateBuilder.jpp
2007-07-19 16:46:43 UTC (rev 2001)
+++ core/trunk/org.vexi.devl/src/org/vexi/core/DevlTemplateBuilder.jpp
2007-07-19 17:15:43 UTC (rev 2002)
@@ -8,12 +8,12 @@
import org.ibex.js.JSU;
import org.ibex.js.Parser.GlobalsChecker;
import org.vexi.core.Template;
-import org.vexi.core.Template.Prefixes;
+import org.vexi.core.CodeBlock.Prefixes;
public class DevlTemplateBuilder extends org.vexi.core.TemplateBuilder {
- protected GlobalsChecker createStaticChecker(Prefixes prefixes){return
new StaticChecker(prefixes);}
- protected GlobalsChecker createPIChecker(Prefixes prefixes, Template
t){return new PIChecker(prefixes, t);}
+ protected GlobalsChecker createStaticChecker(CodeBlock.Prefixes
prefixes){return new StaticChecker(prefixes);}
+ protected GlobalsChecker createPIChecker(CodeBlock.Prefixes prefixes,
Template t){return new PIChecker(prefixes, t);}
/** Static globals checker*/
@@ -25,8 +25,8 @@
// Contains properties defined by static.foo,
Set customStaticProps = new HashSet();
- Template.Prefixes prefixes;
- StaticChecker(Template.Prefixes prefixes){ this.prefixes =
prefixes; }
+ CodeBlock.Prefixes prefixes;
+ StaticChecker(CodeBlock.Prefixes prefixes){ this.prefixes =
prefixes; }
// FIXME - take JS in argument
public boolean acceptGlobal(String name) {
@@ -75,11 +75,11 @@
// by the template or one of the preapplications.
Set customBoxProps = new HashSet();
- Template.Prefixes prefixes;
+ CodeBlock.Prefixes prefixes;
Template t;
// For case of preapply
- PIChecker(Template.Prefixes prefixes, Template t){
+ PIChecker(CodeBlock.Prefixes prefixes, Template t){
this.prefixes = prefixes;
this.t =t;
if(t.keys!=null){
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn