|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
Class PermissionTreeOutputpublic class PermissionTreeOutput extends OutputStream { // Constructors public PermissionTreeOutput(); // Methods public void addField(); public void addNode(int level); public void addPermission(int level, IPermission perm); public void addPermission(int level, IPermission perm, boolean highRisk); public int count(); public String dump(); public void flush() throws IOException; public void increase(); public int[] nodeLevel(); public char[][] nodeValue(); public int[] riskFactor(); public void setStartLevel(int sl); public int startLevel(); public String toString(); public void writeField(String s) throws IOException; public void writeNode(String s, int level) throws IOException; public void writePermission(String s, int level, IPermission perm) throws IOException; public void writePermission(String s, int level, IPermission perm, boolean highRisk) throws IOException; } This class is used to create a tree representation of the permissions. In the security dialog boxes for Microsoft® Internet Explorer version 4.01, the permissions are displayed in the form of a tree control decorated with icons that indicate risk factors. This class is used with the IEncodablePermission.encode method and the EncodeFormats.DISPLAYTREE format. To be displayed correctly in the security dialog boxes, a permission must be able to handle the EncodeFormat.DISPLAYTREE encoding type. The method that encodes the permission in DISPLAYTREE format should ensure that the OutputStream that receives the encoding is an instance of PermissionTreeOutput. Then the writePermission, writeNode, and writeField methods can be used to display information about the permission. For instance, to add a title node for displaying the permission, you would use one of the writePermission methods. To add a sub-node heading for grouping related permission parameters, use the writeNode method. To add a leaf node that contains a specific parameter value, use the writeField method. The following code would produce the tree displayed below. For brevity, only the mapFormat and encode methods are shown. However, your class would need to implement all the methods of the IEncodablePermission and IPermission interfaces. public class MyPermission implements IPermission, IEncodablePermission { private String treedisplaytag = "someString"; private boolean param1; private int param2; private String param3; // Methods and data members are omitted for brevity. // Map the supported formats to tags. public String mapFormat(String format) { if (format == EncodeFormats.DISPLAYTREE) return treedisplaytag; // else check to see if format represents // another supported format. ... } // Encode the permission to a supported format. public boolean encode(String tag, OutputStream myStream) { if (tag.equals(treedisplaytag)) { return encodeTreeDisplay(myStream); } // else check to see if the tag indicates // another supported encoding. ... } // Encode the permission to the DISPLAYTREE format. boolean encodeTreeDisplay(OutputStream myStream) { if(myStream instanceof PermissionTreeOutput) { PermissionTreeOutput tree = (PermissionTreeOutput) myStream; treeDisplay(tree); return true; } else return false; } // Write information to the tree. void treeDisplay(PermissionTreeOutput treeDisplay) { treeDisplay.writePermission("My Sample Permission", 0, this); treeDisplay.writeNode("Parameter 1", 1); treeDisplay.writeField("this.param1"); treeDisplay.writeNode("Parameter 2", 1); treeDisplay.writeNode("Sub-Param 2", 2); treeDisplay.writeField("this.param2"); treeDisplay.writeNode("Parameter 3", 1); . . . } } The displayed tree: +--+ My Sample Permission | +--+ Parameter 1 | | | +--- X (the value of param1) | +--+ Parameter 2 | | | +--+ Sub-Param 2 | | | +--- Y (the value of sub-param2) | +--+ Parameter 3 . . . Also see com.ms.security.IEncodablePermission OutputStream | +--PermissionTreeOutput ConstructorsPermissionTreeOutputpublic PermissionTreeOutput(); MethodsaddFieldpublic void addField(); addNodepublic void addNode(int level); addPermissionpublic void addPermission(int level, IPermission perm); addPermissionpublic void addPermission(int level, IPermission perm, boolean highRisk); countpublic int count(); setStartLevelpublic void setStartLevel(int sl); startLevelpublic int startLevel(); toStringpublic String toString(); writeFieldpublic void writeField(String s) throws IOException; writeNodepublic void writeNode(String s, int level) throws IOException; writePermissionpublic void writePermission(String s, int level, IPermission perm) throws IOException; writePermissionpublic void writePermission(String s, int level, IPermission perm, boolean highRisk) throws IOException;
|