removed old setContent/getContent garbage from Node.

Some reformatting in ESNode.
This commit is contained in:
hns 2001-08-01 00:04:04 +00:00
parent 878dbf644f
commit 829ce545b7
2 changed files with 51 additions and 128 deletions

View file

@ -48,7 +48,7 @@ public class ESNode extends ObjectPrototype {
// 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)
@ -70,7 +70,7 @@ 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) {}
} }
@ -120,50 +120,6 @@ public class ESNode extends ObjectPrototype {
} }
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 ();

View file

@ -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) {}
} }