⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 permispolicyloader.java

📁 一个完整的XACML工程,学习XACML技术的好例子!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
* Copyright (c) 2000-2005, University of Salford
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without 
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this 
* list of conditions and the following disclaimer.
* 
* Redistributions in binary form must reproduce the above copyright notice, 
* this list of conditions and the following disclaimer in the documentation 
* and/or other materials provided with the distribution. 
*
* Neither the name of the University of Salford nor the names of its 
* contributors may be used to endorse or promote products derived from this 
* software without specific prior written permission. 
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
* POSSIBILITY OF SUCH DAMAGE.
*/

/*
 * PermisPolicyLoader.java
 *
 * Created on 11 May 2004, 10:54
 */

package issrg.editor.gui;


import java.awt.Color;
import java.util.ResourceBundle;
import javax.swing.DefaultListModel;
import javax.swing.JCheckBox;

import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.tree.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * Classname:   PermisPolicyLoader
 * 
 * Description:  This class creates the Subject Policy windows, its associated 
 *               buttons and their methods.
 *               Version 1.0.
 *
 * Copyright (c) the authors April 2004
 *
 * @author      Professor D.W.Chadwick
 *              P. Langley
 *              U. Mbanaso
 */
public class PermisPolicyLoader {
    private Document doc;
    private DefaultMutableTreeNode Include; 
    private DefaultMutableTreeNode Exclude;
    private DefaultTreeModel treeModel;
    private  DefaultMutableTreeNode top;
    
    /** Creates a new instance of PermisPolicyLoader */
    public PermisPolicyLoader() {
    
        
        
    }
    
    public JTree readPolicy( JTree tree, 
                             String compare,
                             String parent)
    {
        this.doc = PermisPolicyEditorMenu.permisXmlDom.getDoc();
        //check that the doc exists
        if(doc != null){
            Element parentElement = null;
            Element elem = null;
            Element root = doc.getDocumentElement();
            NodeList list = root.getElementsByTagName("*");
            
            for (int i = 0; i < list.getLength(); i++) {
                if (list.item(i).getNodeName() == parent) {
                    if (list.item(i).getNodeType()!=Node.ELEMENT_NODE) continue;
                    parentElement = (Element) list.item(i);
                    String value = parentElement.getAttribute("ID");
                    
                    /* Compare the attribute value with idValue, this ensures
                     * that child nodes are under the correct parent
                     */
                    if(value.equals(compare)) {
                        break;
                    }
                }
            }
            // Gets the model of the tree
            // treeModel = null;
            treeModel = (DefaultTreeModel)tree.getModel();
            top =  (DefaultMutableTreeNode)treeModel.getRoot();
            
            // If there are children remove and reload
            top.removeAllChildren();
            treeModel.reload();
            
            // Get the childnodes of the parent Node
            NodeList childList = parentElement.getChildNodes();
            
            for (int k = 0; k < childList.getLength(); k++){
		if (childList.item(k).getNodeType()!=Node.ELEMENT_NODE) continue; // skip non-nodes (e.g. #text)

                elem = (Element)childList.item(k);
                NodeList includeChildren = elem.getChildNodes();
                String includeName = elem.getAttribute("LDAPDN");
                includeName = "Include : " + includeName;
                Include =  new DefaultMutableTreeNode(includeName, true);
                treeModel.insertNodeInto(Include,top,  0); 
                tree.scrollPathToVisible(new TreePath( Include.getPath()));
                for (int t = 0; t < includeChildren.getLength(); t++){
                    if (includeChildren.item(t).getNodeType()!=Node.ELEMENT_NODE) continue;
                    Element elementA = (Element) includeChildren.item(t);
                    String elementChildName = elementA.getAttribute("LDAPDN");
                    elementChildName = "Exclude : " + elementChildName;
                    Exclude = new DefaultMutableTreeNode(elementChildName, false);
                    treeModel.insertNodeInto(Exclude, Include, 
                    Include.getChildCount());
                    tree.scrollPathToVisible(new TreePath(Exclude.getPath()));
                }
            }
        }
        
        return tree;
    }
    
    public void readTargetPolicy( JTree tree,
                                   DefaultListModel listModel,
                                   String compare,
                                   String parent)
    {
        this.doc = PermisPolicyEditorMenu.permisXmlDom.getDoc();
        
        //check that the doc exists
        if(doc != null){
            Element parentElement = null;
            Element elem = null;
            Element root = doc.getDocumentElement();
            NodeList list = root.getElementsByTagName("*");
            
            for (int i = 0; i < list.getLength(); i++) {
                if (list.item(i).getNodeName() == parent) {
                    if (list.item(i).getNodeType()!=Node.ELEMENT_NODE) continue;
                    parentElement = (Element) list.item(i);
                    String value = parentElement.getAttribute("ID");
                    
                    /* Compare the attribute value with idValue, this ensures
                     * that child nodes are under the correct parent
                     */
                    if(value.equals(compare)) {
                        break;
                    }
                }
            }
            // Gets the model of the tree
            // treeModel = null;
            treeModel = (DefaultTreeModel)tree.getModel();
            top =  (DefaultMutableTreeNode)treeModel.getRoot();
            
            // If there are children remove and reload
            top.removeAllChildren();
            treeModel.reload();
             listModel.clear();
            // Get the childnodes of the parent Node
            NodeList childList = parentElement.getChildNodes();
            
            for (int k = 0; k < childList.getLength(); k++){
                if (childList.item(k).getNodeType()!=Node.ELEMENT_NODE) continue;
                elem = (Element)childList.item(k);
                NodeList includeChildren = elem.getChildNodes();
                
                
                if(elem.hasChildNodes()){
                    
                String includeName = elem.getAttribute("URL");
                if (includeName==null || includeName.equals("")) includeName = elem.getAttribute("LDAPDN");
                else includeName = "URL:"+includeName;

                includeName = "Include: " + includeName;
                
                Include =  new DefaultMutableTreeNode(includeName, true);
                treeModel.insertNodeInto(Include,top,  0); 
                
                for (int t = 0; t < includeChildren.getLength(); t++){
                    if (includeChildren.item(t).getNodeType()!=Node.ELEMENT_NODE) continue;
                    Element elementA = (Element) includeChildren.item(t);
                    
                    String elementChildName = elementA.getAttribute("URL");
                    if (elementChildName==null || elementChildName.equals("")) elementChildName = elementA.getAttribute("LDAPDN");
                    else elementChildName = "URL:"+elementChildName;
                   
                    elementChildName = "Exclude: " + elementChildName;
                    Exclude = new DefaultMutableTreeNode(elementChildName, false);
                    treeModel.insertNodeInto(Exclude, Include, 
                    Include.getChildCount());
                    tree.scrollPathToVisible(new TreePath(Exclude.getPath()));
                }
                }
                  else{
                  if (elem.getNodeName().equals("ObjectClass")){
                      String objectName = elem.getAttribute("Name");
                      listModel.addElement(objectName);
                  }
                  else if (elem.getNodeName().equals("Include")){
                String includeName = elem.getAttribute("LDAPDN");
                includeName = "Include : " + includeName;
                 
                Include =  new DefaultMutableTreeNode(includeName, true);
                treeModel.insertNodeInto(Include,top,  0); 
                tree.scrollPathToVisible(new TreePath(Include.getPath()));
                  }
                  
                }
               
            }
        }
        
       
    }
    public void readSoaPolicy( JTextField LdapText,
                               String compare,
                               String parent)
    {    /* If there is need to populate JTree we replace the first a
          argument with JTree object and uncomment Jtree codes.
          */
        //check that the doc exists
        this.doc = PermisPolicyEditorMenu.permisXmlDom.getDoc();
        if(doc != null){
            
            Element parentElement = null;
            Element elem = null;
            String soaValue = null;
            Element root = doc.getDocumentElement();
            NodeList list = root.getElementsByTagName("*");
            
            for (int i = 0; i < list.getLength(); i++) {
                if (list.item(i).getNodeName() == parent) {
                    if (list.item(i).getNodeType()!=Node.ELEMENT_NODE) continue;
                    parentElement = (Element) list.item(i);
                    soaValue = parentElement.getAttribute("ID");
                    
                    /* Compare the attribute value with idValue, this ensures
                     * that child nodes are under the correct parent
                     */
                    if(soaValue.equals(compare)) {
                        break;
                    }
                }
            }
            LdapText.setText(parentElement.getAttribute("LDAPDN"));
        }
        
     
    }
    public void readRolesPolicy( DefaultListModel viewRoleListModel,
                                 DefaultListModel availableRoleListModel, 
                                 JComboBox supRoleComboBox,
                                 JComboBox roleViewComboBox,
                                 String parent)
    {
        this.doc = PermisPolicyEditorMenu.permisXmlDom.getDoc();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -