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

📄 ifconstraintspanelsimple.java

📁 一个完整的XACML工程,学习XACML技术的好例子!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if (ae.getActionCommand().intern().equals("ADD_ROW"))
        {
            condTable.addRow(condTable.column1Store.size());
        }
    }
    
    public boolean writeToPolicy() 
    {
        if (xmlED.DOM == null) return false;
        
        NodeList nodesInPolicy = xmlED.DOM.getElementsByTagName("TargetAccessPolicy");
        Element root = ((Element)nodesInPolicy.item(0));
        
        Node parentTargetAccess = root.getElementsByTagName("TargetAccess").item(this.index);
        Node nodeToModify = ((Element)parentTargetAccess).getElementsByTagName("IF").item(0);
        
        Element child = xmlED.DOM.createElement("IF");
        Element typeElement = null;
        
        if (orSelected.isSelected()) 
        {
            typeElement = createElement("OR");
        } 
        else if (andSelected.isSelected()) 
        {
            typeElement = createElement("AND");
        }
        if (child == null || typeElement == null) return false;
        child.appendChild((Node)typeElement);        
        
        if (condTable.column1Store.size() == 0)
        {
            if (nodeToModify == null) return true;
            xmlED.deleteItem(((Element)nodeToModify), (Element)parentTargetAccess);
            return true;
        }      
        
        if (nodeToModify == null) 
        {
            xmlED.addItem(child, (Element)parentTargetAccess);
        } 
        else 
        {
            //change node from one to the other....
            xmlED.replaceNode((Element)parentTargetAccess, ((Element)nodeToModify), child);
        }
        return true;
    }
    
    public Element createElement(String type) 
    {
        Element createdElement = xmlED.DOM.createElement(type);
        
        for (int i = 0; i < condTable.table.getRowCount(); i++) 
        {            
            Element notElement = null;
            
            String operator = ((String)((JComboBox)condTable.column2Store.get(i)).getSelectedItem());
            
            String tmpType = ((ConditionOnComboBox)condTable.column1Store.get(i)).types[((JComboBox)condTable.column1Store.get(i)).getSelectedIndex()];
            
            //String tmpName = ((String)((JComboBox)condTable.column1Store.get(i)).getSelectedItem());
            String tmpName = ((ConditionOnComboBox)condTable.column1Store.get(i)).getParams()[((JComboBox)condTable.column1Store.get(i)).getSelectedIndex()];
            
            String tmpValue = ((String)((JTextField)condTable.column3Store.get(i)).getText());
            if (operator == null || tmpName == null || tmpValue == null || tmpValue.intern().equals("")
                || tmpValue.intern().equals("hh:mm") || tmpValue.intern().equals("ccyy-mm-ddThh:mm:ss") 
                || tmpValue.intern().equals("YYYY-MM-DD") || tmpValue.intern().equals("True || False"))
            {
                JOptionPane.showMessageDialog(xmlED, errorMSG1+" "+tmpName+" "+operator, errorHeader, JOptionPane.ERROR_MESSAGE);
                return null;
            }
            operator = getXMLOperator(operator, tmpType);
            if (operator.charAt(0) == '!') {
                operator = operator.substring(1);
                notElement = xmlED.DOM.createElement("NOT");
                notElement.appendChild(createElementSection(operator, tmpType, tmpName, tmpValue, i));
                createdElement.appendChild((Node)notElement);
            } else {
                createdElement.appendChild(createElementSection(operator, tmpType, tmpName, tmpValue, i));
            }
        }
        return createdElement;
    }
    
    public Element createElementSection(String operator, String tmpType, String tmpName, String tmpValue, int i)
    {        
        Element newOperator = xmlED.DOM.createElement(operator);
        
        Element newArg = null;
        String srcString = ((ConditionOnComboBox)condTable.column1Store.get(i)).variable[((JComboBox)condTable.column1Store.get(i)).getSelectedIndex()];
        if (srcString.intern().equalsIgnoreCase(rbl.getString("ConditionsTable_DropDown_Source1"))) 
        {
            newArg = xmlED.DOM.createElement("Environment");
        } 
        else if (srcString.intern().equalsIgnoreCase(rbl.getString("ConditionsTable_DropDown_Source2"))) 
        {
            newArg = xmlED.DOM.createElement("Arg");
        }
        newOperator.appendChild((Node)newArg);
        Element newConstant = xmlED.DOM.createElement("Constant");
        newOperator.appendChild((Node)newConstant);

        newArg.setAttribute("Name", tmpName);
        newArg.setAttribute("Type", tmpType);
        newConstant.setAttribute("Type", tmpType);
        newConstant.setAttribute("Value", tmpValue);
        
        if (tmpType.equalsIgnoreCase(rb.getString("type1")) || tmpType.equalsIgnoreCase(rb.getString("type2")) ||
            tmpType.equalsIgnoreCase(rb.getString("type7")) || tmpType.equalsIgnoreCase(rb.getString("type9"))) {
            newArg.setAttribute("Type", rb.getString("type1"));
            newConstant.setAttribute("Type", rb.getString("type1"));
            newConstant.setAttribute("Value", getAbsoluteTime(tmpValue));
        }
        
        return newOperator;
    }
    
    public String getAbsoluteTime(String s) {
        if (s.indexOf(":") == -1) { //it is a date
            return s+"T**:**:**";
        } else if (s.indexOf("-") == -1) { //it is a time
            return "****-**-**T"+s;
        } else return s; //it is an absolute
    }
    
    /**
     * This method, changes the descriptive part of the operator, that is
     * seen in the table, and returns it into a Tag that can be
     * inserted in the XML.
     *
     * @param row       the row the descriptive operator is on.
     * @param operator  the descriptive value as obtained in String form.
     * @return the relevant XML tag, that describes the operation done.
     */
    public String getXMLOperator(String operator, String type) {
        Vector tmpItems = (Vector)condTable.varTypeLinks.get(type);
        for (int y = 0; y < tmpItems.size(); y++) {
            String tmpString[] = ((String[])tmpItems.get(y));
            if (tmpString[0].intern().equalsIgnoreCase(operator)) {
                operator = tmpString[1];
            }
        }
        return operator;
    }
    
    /**
     * This method, changes the XML Tag of the operator, in a more readable
     * human form. The Value is obtained from the hash table that is
     * populater in Conditions Table.
     *
     * @param operator  the descriptive value as obtained in String form.
     * @param type      the Variable Type (String/Integer/Time/Boolean/Real)
     * @return the relevant XML tag, that describes the operation done.
     */
    public String getOperatorDescription(String operator, String type) 
    {
        Vector tmpItems = (Vector)condTable.varTypeLinks.get(type);
        for (int y = 0; y < tmpItems.size(); y++) {
            String tmpString[] = ((String[])tmpItems.get(y));
            if (tmpString[1].intern().equalsIgnoreCase(operator)) {
                operator = tmpString[0];
            }
        }
        return operator;
    }
    
    public void refresh() 
    {
        if (xmlED.DOM == null) return;
        
        NodeList nodesInPolicy = xmlED.DOM.getElementsByTagName("TargetAccessPolicy");
        Element root = ((Element)nodesInPolicy.item(0));
        NodeList targetAccess = DomainPolicyEditor.getChildElements(root);
        Node sectionalRoot = targetAccess.item(index);
        NodeList section = DomainPolicyEditor.getChildElements(sectionalRoot);
        
        if (section.getLength() < 3 ) {
            condTable.addRow(0);
            return;
        }    
        
        NodeList types = DomainPolicyEditor.getChildElements(section.item(2));
        Element typeAndOr = ((Element)types.item(0));
        
        if (typeAndOr.getTagName() == "OR")
            orSelected.setSelected(true);
        else if (typeAndOr.getTagName() == "AND")
            andSelected.setSelected(true);
        
        NodeList operators = DomainPolicyEditor.getChildElements(typeAndOr);
        try
        {
            for (int i = 0; i < operators.getLength(); i++) 
            {
                String operator = ((Element)operators.item(i)).getTagName();
                NodeList argsConstant = DomainPolicyEditor.getChildElements((Element)operators.item(i));
                
                if (operator.equals("NOT")) {
                    Element notElement = (Element)DomainPolicyEditor.getChildElements((Element)operators.item(i)).item(0);
                    operator = "!"+notElement.getTagName();
                    argsConstant = DomainPolicyEditor.getChildElements(notElement);
                }                

                String sourceType = ((Element)argsConstant.item(0)).getTagName();
                String argName = ((Element)argsConstant.item(0)).getAttribute("Name");
                String argType = ((Element)argsConstant.item(0)).getAttribute("Type");
                operator = getOperatorDescription(operator, argType);
                String constantType = ((Element)argsConstant.item(1)).getAttribute("Type");
                String constantValue = ((Element)argsConstant.item(1)).getAttribute("Value");

                if (constantValue.indexOf("****-**-**T") > -1) { //it is a time
                    argType = rb.getString("type1");
                    constantValue = constantValue.substring(constantValue.indexOf("T")+1);
                } else if (constantValue.indexOf("T**:**:**") > -1) { //it is a date 
                    argType = rb.getString("type2");
                    constantValue = constantValue.substring(0, constantValue.indexOf("T"));
                } else { //its an absolute time
                    argType = rb.getString("type7");
                }
                
                condTable.addRow(i);
                condTable.table.setEditingRow(i);
                ((JComboBox)condTable.column1Store.get(i)).setSelectedItem(argName);
                ((JComboBox)condTable.column2Store.get(i)).setSelectedItem(operator);
                ((JTextField)condTable.column3Store.get(i)).setText(constantValue);
            }
        }
        catch(NullPointerException e)
        {
            return;
        }
    }
}

⌨️ 快捷键说明

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