INode now extends the pretty simple IPathElement interface.
getUrl is now handled in Application where it belongs.
This commit is contained in:
parent
3eb484b9a0
commit
1b0c4329e5
3 changed files with 46 additions and 17 deletions
|
@ -5,6 +5,7 @@ package helma.objectmodel;
|
|||
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import helma.framework.IPathElement;
|
||||
|
||||
/**
|
||||
* Interface that all Nodes implement. Currently, there are two implementations:
|
||||
|
@ -12,7 +13,7 @@ import java.io.*;
|
|||
* stored in a database (either the internal Object DB or an external relational DB).
|
||||
*/
|
||||
|
||||
public interface INode extends INodeState {
|
||||
public interface INode extends INodeState, IPathElement {
|
||||
|
||||
|
||||
/**
|
||||
|
@ -21,7 +22,7 @@ public interface INode extends INodeState {
|
|||
|
||||
public String getID ();
|
||||
public String getName ();
|
||||
public String getNameOrID (); // get name or id depending if it's a named or an anonymous node.
|
||||
// public String get (); // get name or id depending if it's a named or an anonymous node.
|
||||
public void setDbMapping (DbMapping dbmap);
|
||||
public DbMapping getDbMapping ();
|
||||
public int getState ();
|
||||
|
@ -36,8 +37,8 @@ public interface INode extends INodeState {
|
|||
|
||||
public String getFullName ();
|
||||
public String getFullName (INode root);
|
||||
public INode[] getPath ();
|
||||
public String getUrl (INode root, INode users, String tmpname, String rootproto);
|
||||
// public INode[] getPath ();
|
||||
// public String getUrl (INode root, INode users, String tmpname, String rootproto);
|
||||
|
||||
/**
|
||||
* node-related methods
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.util.Date;
|
|||
import java.util.StringTokenizer;
|
||||
import java.io.*;
|
||||
import helma.util.*;
|
||||
import helma.framework.IPathElement;
|
||||
|
||||
/**
|
||||
* A transient implementation of INode. An instance of this class can't be
|
||||
|
@ -91,7 +92,7 @@ public class Node implements INode, Serializable {
|
|||
return name;
|
||||
}
|
||||
|
||||
public String getNameOrID () {
|
||||
public String getElementName () {
|
||||
return anonymous ? id : name;
|
||||
}
|
||||
|
||||
|
@ -117,13 +118,13 @@ public class Node implements INode, Serializable {
|
|||
b.insert (0, divider);
|
||||
else
|
||||
divider = "/";
|
||||
b.insert (0, p.getNameOrID ());
|
||||
b.insert (0, p.getElementName ());
|
||||
p = p.parent;
|
||||
}
|
||||
return b.toString ();
|
||||
}
|
||||
|
||||
public INode[] getPath () {
|
||||
/* public INode[] getPath () {
|
||||
int pathSize = 1;
|
||||
INode p = getParent ();
|
||||
while (p != null) {
|
||||
|
@ -137,7 +138,7 @@ public class Node implements INode, Serializable {
|
|||
p = p.getParent ();
|
||||
}
|
||||
return path;
|
||||
}
|
||||
} */
|
||||
|
||||
public void setName (String name) {
|
||||
if (name.indexOf('/') > -1)
|
||||
|
@ -253,6 +254,14 @@ public class Node implements INode, Serializable {
|
|||
links.addElement (from);
|
||||
} */
|
||||
|
||||
public IPathElement getParentElement () {
|
||||
return getParent ();
|
||||
}
|
||||
|
||||
public IPathElement getChildElement (String name) {
|
||||
return getNode (name, false);
|
||||
}
|
||||
|
||||
public INode getSubnode (String name) {
|
||||
return getSubnode (name, false);
|
||||
}
|
||||
|
@ -571,9 +580,9 @@ public class Node implements INode, Serializable {
|
|||
}
|
||||
|
||||
|
||||
public String getUrl (INode root, INode users, String tmpname, String rootproto) {
|
||||
/* public String getUrl (INode root, INode users, String tmpname, String rootproto) {
|
||||
throw new RuntimeException ("HREFs on transient (non-db based) Nodes not supported");
|
||||
}
|
||||
} */
|
||||
|
||||
|
||||
public long lastModified () {
|
||||
|
|
|
@ -15,6 +15,7 @@ import java.io.*;
|
|||
import java.sql.Types;
|
||||
import helma.objectmodel.*;
|
||||
import helma.util.*;
|
||||
import helma.framework.IPathElement;
|
||||
import com.workingdogs.village.*;
|
||||
|
||||
|
||||
|
@ -431,7 +432,7 @@ public final class Node implements INode, Serializable {
|
|||
* Get something to identify this node within a URL. This is the ID for anonymous nodes
|
||||
* and a property value for named properties.
|
||||
*/
|
||||
public String getNameOrID () {
|
||||
public String getElementName () {
|
||||
// if subnodes are also mounted as properties, try to get the "nice" prop value
|
||||
// instead of the id by turning the anonymous flag off.
|
||||
// Work around this for user objects to alsways return a URL like /users/username
|
||||
|
@ -477,7 +478,7 @@ public final class Node implements INode, Serializable {
|
|||
b.insert (0, divider);
|
||||
else
|
||||
divider = "/";
|
||||
b.insert (0, p.getNameOrID ());
|
||||
b.insert (0, p.getElementName ());
|
||||
p = p.getParent ();
|
||||
|
||||
loopWatch++;
|
||||
|
@ -489,7 +490,7 @@ public final class Node implements INode, Serializable {
|
|||
return b.toString ();
|
||||
}
|
||||
|
||||
public INode[] getPath () {
|
||||
/* public INode[] getPath () {
|
||||
int pathSize = 1;
|
||||
INode p = getParent ();
|
||||
|
||||
|
@ -506,7 +507,7 @@ public final class Node implements INode, Serializable {
|
|||
p = p.getParent ();
|
||||
}
|
||||
return path;
|
||||
}
|
||||
} */
|
||||
|
||||
public String getPrototype () {
|
||||
if (prototype == null && propMap != null) {
|
||||
|
@ -870,6 +871,24 @@ public final class Node implements INode, Serializable {
|
|||
links.add (fromHandle);
|
||||
}
|
||||
|
||||
/**
|
||||
* This implements the getChild() method of the IPathElement interface
|
||||
*/
|
||||
public IPathElement getChildElement (String name) {
|
||||
IPathElement child = (IPathElement) getSubnode (name);
|
||||
if (child == null)
|
||||
child = (IPathElement) getNode (name, false);
|
||||
return child;
|
||||
}
|
||||
|
||||
/**
|
||||
* This implements the getParentElement() method of the IPathElement interface
|
||||
*/
|
||||
public IPathElement getParentElement () {
|
||||
return getParent ();
|
||||
}
|
||||
|
||||
|
||||
public INode getSubnode (String subid) {
|
||||
// System.err.println ("GETSUBNODE : "+this+" > "+subid);
|
||||
Node retval = null;
|
||||
|
@ -1689,7 +1708,7 @@ public final class Node implements INode, Serializable {
|
|||
* Get the path to eiter the general data-root or the user root, depending on
|
||||
* where this node is located.
|
||||
*/
|
||||
public String getUrl (INode root, INode users, String tmpname, String rootproto) {
|
||||
/* public String getUrl (INode root, INode users, String tmpname, String rootproto) {
|
||||
|
||||
if (state == TRANSIENT)
|
||||
throw new RuntimeException ("Can't get URL for transient Object");
|
||||
|
@ -1713,7 +1732,7 @@ public final class Node implements INode, Serializable {
|
|||
break;
|
||||
}
|
||||
|
||||
b.insert (0, UrlEncoder.encode (p.getNameOrID ()));
|
||||
b.insert (0, UrlEncoder.encode (p.getElementName ()));
|
||||
|
||||
p = p.getParent ();
|
||||
|
||||
|
@ -1726,7 +1745,7 @@ public final class Node implements INode, Serializable {
|
|||
b.insert (0, "users");
|
||||
}
|
||||
return b.toString()+UrlEncoder.encode (tmpname);
|
||||
}
|
||||
} */
|
||||
|
||||
public long lastModified () {
|
||||
return lastmodified;
|
||||
|
|
Loading…
Add table
Reference in a new issue