removed old setContent/getContent garbage from Node.
Some reformatting in ESNode.
This commit is contained in:
parent
878dbf644f
commit
829ce545b7
2 changed files with 51 additions and 128 deletions
|
@ -33,35 +33,35 @@ public class ESNode extends ObjectPrototype {
|
||||||
|
|
||||||
// used to create cache nodes
|
// used to create cache nodes
|
||||||
protected ESNode (INode node, RequestEvaluator eval) {
|
protected ESNode (INode node, RequestEvaluator eval) {
|
||||||
super (eval.esNodePrototype, eval.evaluator);
|
super (eval.esNodePrototype, eval.evaluator);
|
||||||
this.eval = eval;
|
this.eval = eval;
|
||||||
this.node = node;
|
this.node = node;
|
||||||
cache = null;
|
cache = null;
|
||||||
|
|
||||||
cacheWrapper = null;
|
cacheWrapper = null;
|
||||||
nodeID = node.getID ();
|
nodeID = node.getID ();
|
||||||
dbmap = node.getDbMapping ();
|
dbmap = node.getDbMapping ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ESNode (ESObject prototype, Evaluator evaluator, Object obj, RequestEvaluator eval) {
|
public ESNode (ESObject prototype, Evaluator evaluator, Object obj, RequestEvaluator eval) {
|
||||||
super (prototype, evaluator);
|
super (prototype, evaluator);
|
||||||
// eval.app.logEvent ("in ESNode constructor: "+o.getClass ());
|
// eval.app.logEvent ("in ESNode constructor: "+o.getClass ());
|
||||||
this.eval = eval;
|
this.eval = eval;
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
node = new Node ();
|
node = new Node (null);
|
||||||
else if (obj instanceof ESWrapper)
|
else if (obj instanceof ESWrapper)
|
||||||
node = (INode) ((ESWrapper) obj).getJavaObject ();
|
node = (INode) ((ESWrapper) obj).getJavaObject ();
|
||||||
else if (obj instanceof INode)
|
else if (obj instanceof INode)
|
||||||
node = (INode) obj;
|
node = (INode) obj;
|
||||||
else
|
else
|
||||||
node = new Node (obj.toString ());
|
node = new Node (obj.toString ());
|
||||||
// set nodeID to id of wrapped node
|
// set nodeID to id of wrapped node
|
||||||
nodeID = node.getID ();
|
nodeID = node.getID ();
|
||||||
dbmap = node.getDbMapping ();
|
dbmap = node.getDbMapping ();
|
||||||
|
|
||||||
// get transient cache Node
|
// get transient cache Node
|
||||||
cache = node.getCacheNode ();
|
cache = node.getCacheNode ();
|
||||||
cacheWrapper = new ESNode (cache, eval);
|
cacheWrapper = new ESNode (cache, eval);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,100 +70,56 @@ public class ESNode extends ObjectPrototype {
|
||||||
*/
|
*/
|
||||||
private void checkNode () {
|
private void checkNode () {
|
||||||
if (node.getState () == INode.INVALID) try {
|
if (node.getState () == INode.INVALID) try {
|
||||||
setNode (eval.app.nmgr.getNode (node.getID (), node.getDbMapping ()));
|
setNode (eval.app.nmgr.getNode (new Key (node.getDbMapping (), node.getID ())));
|
||||||
} catch (Exception nx) {}
|
} catch (Exception nx) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
public INode getNode () {
|
public INode getNode () {
|
||||||
checkNode ();
|
checkNode ();
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNode (INode node) {
|
public void setNode (INode node) {
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
this.node = node;
|
this.node = node;
|
||||||
nodeID = node.getID ();
|
nodeID = node.getID ();
|
||||||
dbmap = node.getDbMapping ();
|
dbmap = node.getDbMapping ();
|
||||||
eval.objectcache.put (node, this);
|
eval.objectcache.put (node, this);
|
||||||
// get transient cache Node
|
// get transient cache Node
|
||||||
cache = node.getCacheNode ();
|
cache = node.getCacheNode ();
|
||||||
cacheWrapper = new ESNode (cache, eval);
|
cacheWrapper = new ESNode (cache, eval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPrototype (String protoName) {
|
public void setPrototype (String protoName) {
|
||||||
checkNode ();
|
checkNode ();
|
||||||
node.setPrototype (protoName);
|
node.setPrototype (protoName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPrototypeName () {
|
public String getPrototypeName () {
|
||||||
return node.getPrototype ();
|
return node.getPrototype ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getESClassName () {
|
public String getESClassName () {
|
||||||
return "HopObject";
|
return "HopObject";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString () {
|
public String toString () {
|
||||||
if (node == null)
|
if (node == null)
|
||||||
return "<null>";
|
return "<null>";
|
||||||
return node.toString ();
|
return node.toString ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toDetailString () {
|
public String toDetailString () {
|
||||||
return "ES:[Object: builtin " + this.getClass().getName() + ":" +
|
return "ES:[Object: builtin " + this.getClass().getName() + ":" +
|
||||||
((node == null) ? "null" : node.toString()) + "]";
|
((node == null) ? "null" : node.toString()) + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setError (Throwable e) {
|
protected void setError (Throwable e) {
|
||||||
lastError = e;
|
lastError = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean setContent (ESValue what[]) {
|
|
||||||
checkNode ();
|
|
||||||
if (what.length > 0) {
|
|
||||||
if (what[0] instanceof ESString) {
|
|
||||||
node.setContent (what[0].toString ());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (what[0] instanceof ESWrapper) {
|
|
||||||
Object o = ((ESWrapper) what[0]).toJavaObject ();
|
|
||||||
if (o instanceof INode) {
|
|
||||||
try {
|
|
||||||
INode p = (INode) o;
|
|
||||||
node.setContent (p.getContent (), p.getContentType ());
|
|
||||||
return true;
|
|
||||||
} catch (Exception x) {
|
|
||||||
eval.app.logEvent ("error in ESNode.setContent: "+x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (what[0] instanceof ESNode) {
|
|
||||||
INode i = ((ESNode) what[0]).getNode ();
|
|
||||||
try {
|
|
||||||
node.setContent (i.getContent (), i.getContentType ());
|
|
||||||
return true;
|
|
||||||
} catch (Exception x) {
|
|
||||||
eval.app.logEvent ("error in ESNode.setContent: "+x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getContent () {
|
|
||||||
checkNode ();
|
|
||||||
if (node.getContentLength () == 0)
|
|
||||||
return null;
|
|
||||||
String contentType = node.getContentType ();
|
|
||||||
if (contentType != null && contentType.startsWith ("text/")) {
|
|
||||||
return node.getText ();
|
|
||||||
} else {
|
|
||||||
return node.getContent ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean add (ESValue what[]) {
|
public boolean add (ESValue what[]) {
|
||||||
checkNode ();
|
checkNode ();
|
||||||
for (int i=0; i<what.length; i++)
|
for (int i=0; i<what.length; i++)
|
||||||
|
@ -215,7 +171,7 @@ public class ESNode extends ObjectPrototype {
|
||||||
* when they go from transient to persistent state.
|
* when they go from transient to persistent state.
|
||||||
*/
|
*/
|
||||||
protected void rewrap (INode newnode) {
|
protected void rewrap (INode newnode) {
|
||||||
// eval.app.logEvent ("rewrapping "+this+" from "+node+" to "+newnode);
|
eval.app.logEvent ("##### rewrapping "+this+" from "+node+" to "+newnode);
|
||||||
if (newnode == null)
|
if (newnode == null)
|
||||||
throw new RuntimeException ("Non-consistent check-in detected in rewrap ()");
|
throw new RuntimeException ("Non-consistent check-in detected in rewrap ()");
|
||||||
INode oldnode = node;
|
INode oldnode = node;
|
||||||
|
@ -318,7 +274,7 @@ public class ESNode extends ObjectPrototype {
|
||||||
checkNode ();
|
checkNode ();
|
||||||
// eval.app.logEvent ("put property called: "+propertyName+", "+propertyValue.getClass());
|
// eval.app.logEvent ("put property called: "+propertyName+", "+propertyValue.getClass());
|
||||||
if ("lastmodified".equalsIgnoreCase (propertyName) || "created".equalsIgnoreCase (propertyName) ||
|
if ("lastmodified".equalsIgnoreCase (propertyName) || "created".equalsIgnoreCase (propertyName) ||
|
||||||
"contentlength".equalsIgnoreCase (propertyName) || "cache".equalsIgnoreCase (propertyName))
|
"cache".equalsIgnoreCase (propertyName))
|
||||||
throw new EcmaScriptException ("Can't modify read-only property \""+propertyName+"\".");
|
throw new EcmaScriptException ("Can't modify read-only property \""+propertyName+"\".");
|
||||||
|
|
||||||
if ("subnodeRelation".equalsIgnoreCase (propertyName)) {
|
if ("subnodeRelation".equalsIgnoreCase (propertyName)) {
|
||||||
|
@ -326,9 +282,7 @@ public class ESNode extends ObjectPrototype {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("contenttype".equalsIgnoreCase (propertyName))
|
if (propertyValue instanceof ESNull)
|
||||||
node.setContentType (propertyValue.toString ());
|
|
||||||
else if (propertyValue instanceof ESNull)
|
|
||||||
node.unset (propertyName);
|
node.unset (propertyName);
|
||||||
else if (propertyValue instanceof ESString)
|
else if (propertyValue instanceof ESString)
|
||||||
node.setString (propertyName, propertyValue.toString ());
|
node.setString (propertyName, propertyValue.toString ());
|
||||||
|
@ -397,10 +351,6 @@ public class ESNode extends ObjectPrototype {
|
||||||
return new DatePrototype (evaluator, node.created ());
|
return new DatePrototype (evaluator, node.created ());
|
||||||
if ("lastmodified".equalsIgnoreCase (propertyName))
|
if ("lastmodified".equalsIgnoreCase (propertyName))
|
||||||
return new DatePrototype (evaluator, node.lastModified ());
|
return new DatePrototype (evaluator, node.lastModified ());
|
||||||
if ("contenttype".equalsIgnoreCase (propertyName))
|
|
||||||
return new ESString (node.getContentType ());
|
|
||||||
if ("contentlength".equalsIgnoreCase (propertyName))
|
|
||||||
return new ESNumber (node.getContentLength ());
|
|
||||||
|
|
||||||
if ("subnodeRelation".equalsIgnoreCase (propertyName)) {
|
if ("subnodeRelation".equalsIgnoreCase (propertyName)) {
|
||||||
String rel = node.getSubnodeRelation ();
|
String rel = node.getSubnodeRelation ();
|
||||||
|
|
|
@ -76,8 +76,6 @@ public class HopExtension {
|
||||||
reval.esNodePrototype.putHiddenProperty ("editor", new NodeEditor ("editor", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("editor", new NodeEditor ("editor", evaluator, fp));
|
||||||
reval.esNodePrototype.putHiddenProperty ("chooser", new NodeChooser ("chooser", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("chooser", new NodeChooser ("chooser", evaluator, fp));
|
||||||
reval.esNodePrototype.putHiddenProperty ("multiChooser", new MultiNodeChooser ("multiChooser", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("multiChooser", new MultiNodeChooser ("multiChooser", evaluator, fp));
|
||||||
reval.esNodePrototype.putHiddenProperty ("getContent", new NodeGetContent ("getContent", evaluator, fp));
|
|
||||||
reval.esNodePrototype.putHiddenProperty ("setContent", new NodeSetContent ("setContent", evaluator, fp));
|
|
||||||
reval.esNodePrototype.putHiddenProperty ("path", new NodePath ("path", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("path", new NodePath ("path", evaluator, fp));
|
||||||
reval.esNodePrototype.putHiddenProperty ("href", new NodeHref ("href", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("href", new NodeHref ("href", evaluator, fp));
|
||||||
reval.esNodePrototype.putHiddenProperty ("setParent", new NodeSetParent ("setParent", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("setParent", new NodeSetParent ("setParent", evaluator, fp));
|
||||||
|
@ -124,31 +122,6 @@ public class HopExtension {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class NodeSetContent extends BuiltinFunctionObject {
|
|
||||||
NodeSetContent (String name, Evaluator evaluator, FunctionPrototype fp) {
|
|
||||||
super (fp, evaluator, name, 1);
|
|
||||||
}
|
|
||||||
public ESValue callFunction (ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
|
|
||||||
ESNode node = (ESNode) thisObject;
|
|
||||||
return ESBoolean.makeBoolean (node.setContent (arguments));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class NodeGetContent extends BuiltinFunctionObject {
|
|
||||||
NodeGetContent (String name, Evaluator evaluator, FunctionPrototype fp) {
|
|
||||||
super (fp, evaluator, name, 1);
|
|
||||||
}
|
|
||||||
public ESValue callFunction (ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
|
|
||||||
ESNode node = (ESNode) thisObject;
|
|
||||||
Object content = node.getContent ();
|
|
||||||
if (content == null)
|
|
||||||
return ESNull.theNull;
|
|
||||||
else
|
|
||||||
return ESLoader.normalizeValue (content, this.evaluator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class NodeAdd extends BuiltinFunctionObject {
|
class NodeAdd extends BuiltinFunctionObject {
|
||||||
NodeAdd (String name, Evaluator evaluator, FunctionPrototype fp) {
|
NodeAdd (String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||||
super (fp, evaluator, name, 1);
|
super (fp, evaluator, name, 1);
|
||||||
|
@ -264,7 +237,7 @@ public class HopExtension {
|
||||||
if (node instanceof helma.objectmodel.db.Node) {
|
if (node instanceof helma.objectmodel.db.Node) {
|
||||||
((helma.objectmodel.db.Node) node).invalidate ();
|
((helma.objectmodel.db.Node) node).invalidate ();
|
||||||
try {
|
try {
|
||||||
node = app.nmgr.getNode (node.getID (), node.getDbMapping ());
|
node = app.nmgr.getNode (new Key (node.getDbMapping (), node.getID ()));
|
||||||
esn.setNode (node);
|
esn.setNode (node);
|
||||||
} catch (Exception x) {}
|
} catch (Exception x) {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue