Example usage for org.w3c.dom Node getLocalName

List of usage examples for org.w3c.dom Node getLocalName

Introduction

In this page you can find the example usage for org.w3c.dom Node getLocalName.

Prototype

public String getLocalName();

Source Link

Document

Returns the local part of the qualified name of this node.

Usage

From source file:org.adl.sequencer.ADLSeqUtilities.java

/**
 * Extracts the objectives associated with the activity from the
 * <code>&lt;objectives&gt;</code> element of the DOM.
 *
 * @param iNode The DOM node associated with the IMS SS <code>
 *              &lt;objectives&gt;</code> element.
 *
 * @param ioAct The associated activity being initialized
 *
 * @return <code>true</code> if the sequencing information extracted
 *         successfully, otherwise <code>false</code>.
 *///from w w w. j  av a2  s.  c  om
private static boolean getObjectives(Node iNode, SeqActivity ioAct) {

    if (_Debug) {
        System.out.println("  :: ADLSeqUtilities  --> BEGIN - " + "getObjectives");
    }

    boolean ok = true;
    String tempVal = null;
    List<SeqObjective> objectives = new ArrayList<SeqObjective>();

    // Get the children elements of <objectives>
    NodeList children = iNode.getChildNodes();

    // Initalize this activity's objectives
    for (int i = 0; i < children.getLength(); i++) {
        Node curNode = children.item(i);

        // Check to see if this is an element node.
        if (curNode.getNodeType() == Node.ELEMENT_NODE) {
            if (curNode.getLocalName().equals("primaryObjective")) {
                if (_Debug) {
                    System.out.println("  ::--> Found a <primaryObjective> " + "element");
                }

                SeqObjective obj = new SeqObjective();

                obj.mContributesToRollup = true;

                // Look for 'objectiveID'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "objectiveID");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        obj.mObjID = tempVal;
                    }
                }

                // Look for 'satisfiedByMeasure'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "satisfiedByMeasure");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        obj.mSatisfiedByMeasure = (Boolean.valueOf(tempVal)).booleanValue();
                    }
                }

                // Look for 'minNormalizedMeasure'
                tempVal = getElementText(curNode, "minNormalizedMeasure");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        obj.mMinMeasure = (new Double(tempVal)).doubleValue();
                    }
                }

                List<SeqObjectiveMap> maps = getObjectiveMaps(curNode);

                if (maps != null) {
                    obj.mMaps = maps;
                }

                obj.mContributesToRollup = true;
                objectives.add(obj);
            } else if (curNode.getLocalName().equals("objective")) {
                if (_Debug) {
                    System.out.println("  ::--> Found a <objective> " + "element");
                }

                SeqObjective obj = new SeqObjective();

                // Look for 'objectiveID'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "objectiveID");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        obj.mObjID = tempVal;
                    }
                }

                // Look for 'satisfiedByMeasure'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "satisfiedByMeasure");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        obj.mSatisfiedByMeasure = (Boolean.valueOf(tempVal)).booleanValue();
                    }
                }

                // Look for 'minNormalizedMeasure'
                tempVal = getElementText(curNode, "minNormalizedMeasure");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        obj.mMinMeasure = (new Double(tempVal)).doubleValue();
                    }
                }

                List<SeqObjectiveMap> maps = getObjectiveMaps(curNode);

                if (maps != null) {
                    obj.mMaps = maps;
                }

                objectives.add(obj);
            }
        }
    }

    // Set the Activity's objectives
    ioAct.setObjectives(objectives);

    if (_Debug) {
        System.out.println("  :: ADLSeqUtilities  --> END   - " + "getObjectives");
    }

    return ok;
}

From source file:org.adl.sequencer.ADLSeqUtilities.java

/**
 * Extracts the rollup rules associated with the activity from the
 * <code>&lt;sequencingRules&gt;</code> element of the DOM.
 *
 * @param iNode The DOM node associated with the IMS SS <code>
 *              &lt;sequencingRules&gt;</code> element.
 *
 * @param ioAct The associated activity being initialized
 *
 * @return <code>true</code> if the sequencing information extracted
 *         successfully, otherwise <code>false</code>.
 */// ww w . j  a  v  a  2  s .  c o  m
private static boolean getRollupRules(Node iNode, SeqActivity ioAct) {

    if (_Debug) {
        System.out.println("  :: ADLSeqUtilities  --> BEGIN - " + "getRollupRules");
    }

    boolean ok = true;
    String tempVal = null;
    List<SeqRollupRule> rollupRules = new ArrayList<SeqRollupRule>();

    // Look for 'rollupObjectiveSatisfied'
    tempVal = ADLSeqUtilities.getAttribute(iNode, "rollupObjectiveSatisfied");
    if (tempVal != null) {
        if (!isEmpty(tempVal)) {
            ioAct.setIsObjRolledUp((Boolean.valueOf(tempVal)).booleanValue());
        }
    }

    // Look for 'objectiveMeasureWeight'
    tempVal = ADLSeqUtilities.getAttribute(iNode, "objectiveMeasureWeight");
    if (tempVal != null) {
        if (!isEmpty(tempVal)) {
            ioAct.setObjMeasureWeight((new Double(tempVal)).doubleValue());
        }
    }

    // Look for 'rollupProgressCompletion'
    tempVal = ADLSeqUtilities.getAttribute(iNode, "rollupProgressCompletion");
    if (tempVal != null) {
        if (!isEmpty(tempVal)) {
            ioAct.setIsProgressRolledUp((Boolean.valueOf(tempVal)).booleanValue());
        }
    }

    // Get the children elements of <rollupRules>
    NodeList children = iNode.getChildNodes();

    // Initalize this activity's rollup rules 
    for (int i = 0; i < children.getLength(); i++) {
        Node curNode = children.item(i);

        // Check to see if this is an element node.
        if (curNode.getNodeType() == Node.ELEMENT_NODE) {
            if (curNode.getLocalName().equals("rollupRule")) {
                // Extract all of the rollup Rules
                if (_Debug) {
                    System.out.println("  ::--> Found a <rollupRule> " + "element");
                }

                SeqRollupRule rule = new SeqRollupRule();

                // Look for 'childActivitySet'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "childActivitySet");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        rule.mChildActivitySet = tempVal;
                    }
                }

                // Look for 'minimumCount'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "minimumCount");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        rule.mMinCount = (Long.valueOf(tempVal)).longValue();
                    }
                }

                // Look for 'minimumPercent'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "minimumPercent");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        rule.mMinPercent = (new Double(tempVal)).doubleValue();
                    }
                }

                rule.mConditions = new SeqConditionSet(true);
                List<SeqCondition> conditions = new ArrayList<SeqCondition>();

                NodeList ruleInfo = curNode.getChildNodes();

                // Initalize this rollup rule
                for (int j = 0; j < ruleInfo.getLength(); j++) {

                    Node curRule = ruleInfo.item(j);

                    // Check to see if this is an element node.
                    if (curRule.getNodeType() == Node.ELEMENT_NODE) {
                        if (curRule.getLocalName().equals("rollupConditions")) {

                            if (_Debug) {
                                System.out.println("  ::--> Found a " + "<rollupConditions> " + "element");
                            }

                            // Look for 'conditionCombination'
                            tempVal = ADLSeqUtilities.getAttribute(curRule, "conditionCombination");

                            if (tempVal != null) {
                                if (!isEmpty(tempVal)) {
                                    rule.mConditions.mCombination = tempVal;
                                }
                            } else {
                                // Enforce Default
                                rule.mConditions.mCombination = SeqConditionSet.COMBINATION_ANY;
                            }

                            NodeList conds = curRule.getChildNodes();

                            for (int k = 0; k < conds.getLength(); k++) {
                                Node con = conds.item(k);

                                // Check to see if this is an element node.
                                if (con.getNodeType() == Node.ELEMENT_NODE) {
                                    if (con.getLocalName().equals("rollupCondition")) {

                                        if (_Debug) {
                                            System.out.println(
                                                    "  ::--> Found a " + "<rollupCondition> " + "element");
                                        }

                                        SeqCondition cond = new SeqCondition();

                                        // Look for 'condition'
                                        tempVal = ADLSeqUtilities.getAttribute(con, "condition");
                                        if (tempVal != null) {
                                            if (!isEmpty(tempVal)) {
                                                cond.mCondition = tempVal;
                                            }
                                        }

                                        // Look for 'operator'
                                        tempVal = ADLSeqUtilities.getAttribute(con, "operator");
                                        if (tempVal != null) {
                                            if (tempVal.equals("not")) {
                                                cond.mNot = true;
                                            } else {
                                                cond.mNot = false;
                                            }
                                        }

                                        conditions.add(cond);
                                    }
                                }
                            }
                        } else if (curRule.getLocalName().equals("rollupAction")) {

                            if (_Debug) {
                                System.out.println("  ::--> Found a " + "<rollupAction> " + "element");
                            }
                            // Look for 'action'
                            tempVal = ADLSeqUtilities.getAttribute(curRule, "action");
                            if (tempVal != null) {
                                if (!isEmpty(tempVal)) {
                                    rule.setRollupAction(tempVal);
                                }
                            }
                        }
                    }
                }

                // Add the conditions to the condition set for the rule
                rule.mConditions.mConditions = conditions;

                // Add the rule to the ruleset
                rollupRules.add(rule);
            }
        }
    }

    if (rollupRules != null) {
        ISeqRollupRuleset rules = new SeqRollupRuleset(rollupRules);

        // Set the Activity's rollup rules
        ioAct.setRollupRules(rules);
    }

    if (_Debug) {
        System.out.println("  :: ADLSeqUtilities  --> END   - " + "getRollupRules");
    }

    return ok;
}

From source file:org.adl.sequencer.ADLSeqUtilities.java

/**
 * Extracts the sequencing rules associated with the activity from the
 * <code>&lt;sequencingRules&gt;</code> element of the DOM.
 * /*from  ww w . j av  a 2 s .  c o  m*/
 * @param iNode The DOM node associated with the IMS SS <code>
 *              &lt;sequencingRules&gt;</code> element.
 * 
 * @param ioAct The associated activity being initialized
 * 
 * @return <code>true</code> if the sequencing information extracted
 *         successfully, otherwise <code>false</code>.
 */
private static boolean getSequencingRules(Node iNode, SeqActivity ioAct) {

    if (_Debug) {
        System.out.println("  :: ADLSeqUtilities  --> BEGIN - " + "getSequencingRules");
    }

    boolean ok = true;
    String tempVal = null;

    List<ISeqRule> preRules = new ArrayList<ISeqRule>();
    List<ISeqRule> exitRules = new ArrayList<ISeqRule>();
    List<ISeqRule> postRules = new ArrayList<ISeqRule>();

    // Get the children elements of <sequencingRules>
    NodeList children = iNode.getChildNodes();

    // Initalize this activity's sequencing rules 
    for (int i = 0; i < children.getLength(); i++) {
        Node curNode = children.item(i);

        // Check to see if this is an element node.
        if (curNode.getNodeType() == Node.ELEMENT_NODE) {
            if (curNode.getLocalName().equals("preConditionRule")) {
                // Extract all of the precondition rules
                if (_Debug) {
                    System.out.println("  ::--> Found a <preConditionRule> " + "element");
                }

                SeqRule rule = new SeqRule();

                NodeList ruleInfo = curNode.getChildNodes();

                for (int j = 0; j < ruleInfo.getLength(); j++) {

                    Node curRule = ruleInfo.item(j);

                    // Check to see if this is an element node.
                    if (curRule.getNodeType() == Node.ELEMENT_NODE) {
                        if (curRule.getLocalName().equals("ruleConditions")) {

                            if (_Debug) {
                                System.out.println("  ::--> Found a " + "<ruleConditions> element");
                            }

                            // Extract the condition set
                            rule.mConditions = extractSeqRuleConditions(curRule);

                        } else if (curRule.getLocalName().equals("ruleAction")) {

                            if (_Debug) {
                                System.out.println("  ::--> Found a <ruleAction> " + "element");
                            }

                            // Look for 'action'
                            tempVal = ADLSeqUtilities.getAttribute(curRule, "action");

                            if (tempVal != null) {
                                if (!isEmpty(tempVal)) {
                                    rule.mAction = tempVal;
                                }
                            }
                        }
                    }
                }

                if (rule.mConditions != null && rule.mAction != null) {
                    preRules.add(rule);
                } else {
                    if (_Debug) {
                        System.out.println("  ::--> ERROR : Invaild Pre SeqRule");
                    }
                }
            } else if (curNode.getLocalName().equals("exitConditionRule")) {
                // Extract all of the exit action rules
                if (_Debug) {
                    System.out.println("  ::--> Found a " + "<exitConditionRule> element");
                }

                SeqRule rule = new SeqRule();

                NodeList ruleInfo = curNode.getChildNodes();

                for (int k = 0; k < ruleInfo.getLength(); k++) {

                    Node curRule = ruleInfo.item(k);

                    // Check to see if this is an element node.
                    if (curRule.getNodeType() == Node.ELEMENT_NODE) {
                        if (curRule.getLocalName().equals("ruleConditions")) {

                            if (_Debug) {
                                System.out.println("  ::--> Found a " + "<ruleConditions> element");
                            }

                            // Extract the condition set
                            rule.mConditions = extractSeqRuleConditions(curRule);

                        } else if (curRule.getLocalName().equals("ruleAction")) {

                            if (_Debug) {
                                System.out.println("  ::--> Found a <ruleAction> " + "element");
                            }

                            // Look for 'action'
                            tempVal = ADLSeqUtilities.getAttribute(curRule, "action");

                            if (tempVal != null) {
                                rule.mAction = tempVal;
                            }
                        }
                    }
                }

                if (rule.mConditions != null && rule.mAction != null) {
                    exitRules.add(rule);
                } else {
                    if (_Debug) {
                        System.out.println("  ::--> ERROR : Invaild Exit SeqRule");
                    }
                }
            } else if (curNode.getLocalName().equals("postConditionRule")) {
                // Extract all of the post condition action rules
                if (_Debug) {
                    System.out.println("  ::--> Found a " + "<postConditionRule> element");
                }

                SeqRule rule = new SeqRule();

                NodeList ruleInfo = curNode.getChildNodes();

                for (int j = 0; j < ruleInfo.getLength(); j++) {

                    Node curRule = ruleInfo.item(j);

                    // Check to see if this is an element node.
                    if (curRule.getNodeType() == Node.ELEMENT_NODE) {
                        if (curRule.getLocalName().equals("ruleConditions")) {

                            if (_Debug) {
                                System.out.println("  ::--> Found a " + "<ruleConditions> element");
                            }

                            // Extract the condition set
                            rule.mConditions = extractSeqRuleConditions(curRule);

                        } else if (curRule.getLocalName().equals("ruleAction")) {

                            if (_Debug) {
                                System.out.println("  ::--> Found a <ruleAction> " + "element");
                            }

                            // Look for 'action'
                            tempVal = ADLSeqUtilities.getAttribute(curRule, "action");

                            if (tempVal != null) {
                                rule.mAction = tempVal;
                            }
                        }
                    }
                }

                if (rule.mConditions != null && rule.mAction != null) {
                    postRules.add(rule);
                } else {
                    if (_Debug) {
                        System.out.println("  ::--> ERROR : Invaild Post SeqRule");
                    }
                }
            }
        }
    }

    if (preRules.size() > 0) {
        ISeqRuleset rules = new SeqRuleset(preRules);

        ioAct.setPreSeqRules(rules);
    }

    if (exitRules.size() > 0) {
        ISeqRuleset rules = new SeqRuleset(exitRules);

        ioAct.setExitSeqRules(rules);
    }

    if (postRules.size() > 0) {
        ISeqRuleset rules = new SeqRuleset(postRules);

        ioAct.setPostSeqRules(rules);
    }

    if (_Debug) {
        System.out.println("  :: ADLSeqUtilities  --> END   - " + "getSequencingRules");
    }

    return ok;
}

From source file:org.adl.validator.contentpackage.CPValidator.java

/**
 * This method assists with the application profile check for the validation
 * of the bucket attributes. <br>/*from   w w  w. j a  v  a2  s . c  o m*/
 * 
 * @param iResourceNode
 *            The resources node <br>
 */
private void checkBucketUniqueness(Node iResourceNode) {
    mLogger.debug("CPValidator checkBucketUniqueness");

    String msgText;
    List<String> idList = new ArrayList<String>();

    NodeList childrenOfItem = iResourceNode.getChildNodes();

    if (childrenOfItem != null) {
        Node currentChild;
        String currentChildName;
        int len = childrenOfItem.getLength();

        for (int k = 0; k < len; k++) {
            currentChild = childrenOfItem.item(k);
            currentChildName = currentChild.getLocalName();

            if (currentChildName.equals("bucket")) {
                // Get the bucketID attribute

                String bucketId = DOMTreeUtility.getAttributeValue(currentChild, "bucketID");
                // Check if id already exists in the list: if it does set
                // the
                // flag
                if (idList.contains(bucketId)) {
                    // ERROR, duplicate ID exists in resource
                    msgText = "BucketID \"" + bucketId + "\" must be unqiue" + " for a <resource>.";
                    mLogger.debug("SSP: " + msgText);
                    DetailedLogMessageCollection.getInstance()
                            .addMessage(new LogMessage(MessageType.FAILED, msgText));

                } else {
                    idList.add(bucketId);
                }
            }

        }

    }
}

From source file:org.adl.validator.contentpackage.CPValidator.java

/**
 * This method validates the multiplicity of the children of the item
 * element. The title element is required to be present.
 * /*from   w  w  w .jav  a  2s .c o m*/
 * @param iNode
 *            - the organization element
 * @param iManifestInfo
 *            - the populated ManifestMap object
 * @return boolean - result of the title multiplicity check. True implies
 *         that the title multiplicity was properly adhered to, false
 *         implies otherwise.
 */
private boolean checkItemChildMultiplicity(Node iNode, ManifestMap iManifestInfo) {
    mLogger.debug("CPValidator checkItemChildMultiplicity");

    String msgText = "";
    boolean result = true;

    String iNodeName = iNode.getLocalName();

    if (iNodeName.equals("organization")) {
        NodeList iNodeChildren = iNode.getChildNodes();
        int iNodeChildSize = iNodeChildren.getLength();

        Node currentNode;
        String currentName;

        for (int j = 0; j < iNodeChildSize; j++) {
            currentNode = iNodeChildren.item(j);
            currentName = currentNode.getLocalName();

            if (currentName.equals("item")) {
                // search for item element and recurse
                result = checkItemChildMultiplicity(currentNode, iManifestInfo) && result;
            }
        }
    }

    if (iNodeName.equals("item")) {

        NodeList itemChild = iNode.getChildNodes();
        int itemSize = itemChild.getLength();
        String currentItemChildName = "";
        boolean titleFound = false;

        for (int v = 0; v < itemSize; v++) {
            Node currentItemChild = itemChild.item(v);
            currentItemChildName = currentItemChild.getLocalName();

            if (currentItemChildName != null) {
                if (currentItemChildName.equals("title")) {
                    titleFound = true;
                } else if (currentItemChildName.equals("item")) {
                    result = checkItemChildMultiplicity(currentItemChild, iManifestInfo) && result;
                }
            }
        }
        // title is mandatory
        if (!titleFound) {
            msgText = Messages.getString("CPValidator.287", "title");
            mLogger.debug("FAILED: " + msgText);
            DetailedLogMessageCollection.getInstance().addMessage(new LogMessage(MessageType.FAILED, msgText));

            result = false;
        }
    }

    return result;
}

From source file:org.adl.validator.contentpackage.CPValidator.java

/**
 * This method checks the item to ensure that the identifierref attribute is
 * not used on a non-leaf item. This method also checks to ensure that a
 * leaf item shall reference a resource. A leaf item fails if it contains no
 * identifierref attribute at all, or if it contains an identifierref
 * attribute that is set to an empty string.
 * /*w  w  w  .  j a  v  a 2 s  .  c  o  m*/
 * @param iOrgNode
 *            - the organization node containing the item element(s)
 * @return boolean - result of the check for the item identifierref
 *         attribute True if the identifierref passes, false otherwise.
 */
private boolean checkItemIdentifierRef(Node iOrgNode) {

    mLogger.debug("CPValidator checkItemIdentifierRef");

    String msgText = "";
    NodeList orgChildren = iOrgNode.getChildNodes();
    int orgChildSize = orgChildren.getLength();
    Node currentNode;
    String currentName;
    boolean result = true;

    for (int j = 0; j < orgChildSize; j++) {
        currentNode = orgChildren.item(j);
        currentName = currentNode.getLocalName();

        if (currentName.equals("item")) {
            NodeList itemChildren = currentNode.getChildNodes();
            int itemChildrenSize = itemChildren.getLength();
            boolean itemHasItemChildren = false;

            for (int k = 0; k < itemChildrenSize; k++) {

                // see if we have a child item of item
                // if so, this signals that the currentNode is not a leaf
                // and
                // should not have an identifierref

                Node currentItemChild = itemChildren.item(k);
                String currentItemChildName = currentItemChild.getLocalName();

                if (currentItemChildName != null) {

                    if (currentItemChildName.equals("item")) {

                        NamedNodeMap attrList = currentNode.getAttributes();
                        int numAttr = attrList.getLength();
                        Attr currentAttrNode = null;
                        String currentNodeName = "";

                        for (int i = 0; i < numAttr; i++) {
                            currentAttrNode = (Attr) attrList.item(i);
                            currentNodeName = currentAttrNode.getLocalName();

                            if (currentNodeName.equals("identifierref")) {
                                result = result && false;
                                msgText = Messages.getString("CPValidator.461");
                                mLogger.debug("FAILED: " + msgText);
                                DetailedLogMessageCollection.getInstance()
                                        .addMessage(new LogMessage(MessageType.FAILED, msgText));

                            } // end if (
                              // currentNodeName.equals("identifierref") )

                        } // end for
                          // set the flag that signals that the item is
                          // NOT a leaf
                          // item
                        itemHasItemChildren = true;
                    } // end if ( currentItemChildName.equals("item") )
                }
            }
            // need to check if we are dealing with a leaf item
            if (!itemHasItemChildren) {
                // Verify that a leaf item references a resource
                Attr identifierRef = DOMTreeUtility.getAttribute(currentNode, "identifierref");
                if (identifierRef == null) {
                    // ERROR, must reference a resource therefore it must
                    // contain
                    // an identifierref attribute
                    result = result && false;
                    msgText = Messages.getString("CPValidator.464");
                    mLogger.debug("FAILED: " + msgText);
                    DetailedLogMessageCollection.getInstance()
                            .addMessage(new LogMessage(MessageType.FAILED, msgText));
                } else {
                    String identifierRefValue = identifierRef.getValue();
                    if (identifierRefValue.equals("")) {
                        // ERROR, must reference a resource therefore it
                        // cannot
                        // contain an identifierref attibute that is set to
                        // an
                        // empty string
                        result = result && false;
                        msgText = Messages.getString("CPValidator.467");
                        mLogger.debug("FAILED: " + msgText);
                        DetailedLogMessageCollection.getInstance()
                                .addMessage(new LogMessage(MessageType.FAILED, msgText));
                    }
                }

            }
        }
    }
    return result;
}

From source file:org.adl.validator.contentpackage.CPValidator.java

/**
 * This method performs the meat of the application profile checks. The
 * application profiles are described in XML format. Each application
 * profile has its own XML representation. These XML rules are parsed in
 * order to form a document object. The test subject manifest is also
 * available in document format. This method compares the manifest to the
 * rules described in the XML dom. This recursive method is driven by the
 * test subject dom./*from  w  w  w  .  j a  va  2s . c om*/
 * 
 * @param iTestSubjectNode
 *            Test Subject DOM
 * @param iPath
 *            Path of the rule to compare to
 * @return - boolean result of the checks performed. True if the check was
 *         conformant, false otherwise.
 */
private boolean compareToRules(Node iTestSubjectNode, String iPath) {
    // is there anything to do?
    if (iTestSubjectNode == null)
        return false;

    mLogger.debug("CPValidator compareToRules");
    mLogger.debug("Node: " + iTestSubjectNode.getLocalName());
    mLogger.debug("Namespace: " + iTestSubjectNode.getNamespaceURI());
    mLogger.debug("Path: " + iPath);

    boolean result = true;
    String msgText = "";

    // Determine which type of DOM Tree Node we are dealing with
    switch (iTestSubjectNode.getNodeType()) {
    case Node.PROCESSING_INSTRUCTION_NODE: {
        // Skip any processing instructions, nothing for us to do
        break;
    }
    case Node.DOCUMENT_NODE: {
        // Found the root document node
        Node rootNode = ((Document) iTestSubjectNode).getDocumentElement();
        String rootNodeName = rootNode.getLocalName();

        mLogger.debug("DOCUMENT_NODE found");
        mLogger.debug("Namespace: " + rootNode.getNamespaceURI());
        mLogger.debug("Node Name: " + rootNodeName);

        mLogger.debug("INFO: Testing element <" + rootNodeName + "> for minimum conformance");
        DetailedLogMessageCollection.getInstance().addMessage(
                new LogMessage(MessageType.INFO, Messages.getString("CPValidator.131", rootNodeName)));

        mLogger.debug("PASSED: Multiplicity for element <" + rootNodeName + "> has been verified");
        DetailedLogMessageCollection.getInstance().addMessage(
                new LogMessage(MessageType.PASSED, Messages.getString("CPValidator.135", rootNodeName)));

        result = compareToRules(rootNode, "") && result;

        break;
    }
    case Node.ELEMENT_NODE: {
        // Found an Element Node
        String parentNodeName = iTestSubjectNode.getLocalName();

        if (parentNodeName.equals("manifest")) {
            // retrieve resources nodes for sco reference validation
            Node resourcesNode = DOMTreeUtility.getNode(iTestSubjectNode, "resources");

            if (resourcesNode != null) {
                // retrieve resource nodes for sco reference validation
                mResourceNodes = DOMTreeUtility.getNodes(resourcesNode, "resource");
                // Must also track resource identifier values for
                // dependency identifierref scope validation

                trackResourceIdentifiers(resourcesNode);
            }
        }

        String dataType = null;
        int multiplicityUsed = -1;
        int minRule = -1;
        int maxRule = -1;
        int spmRule = -1;

        mLogger.debug("Looping through attributes for the input " + "element <" + parentNodeName + ">");

        // Look for the attributes of this element
        NamedNodeMap attrList = iTestSubjectNode.getAttributes();
        int numAttr = attrList.getLength();
        mLogger.debug("There are " + numAttr + " attributes of <" + parentNodeName + "> elememt to test");

        Attr currentAttrNode = null;
        String currentNodeName = "";
        String attributeValue = "";

        // Loop throught attributes
        for (int i = 0; i < numAttr; i++) {
            currentAttrNode = (Attr) attrList.item(i);
            currentNodeName = currentAttrNode.getLocalName();

            mLogger.debug("Processing the [" + currentAttrNode.getNamespaceURI() + "] " + currentNodeName
                    + " attribute of the <" + parentNodeName + "> element.");

            // If the current attribute is persistState then additional
            // checks may be necessary
            if (currentNodeName.equalsIgnoreCase("persistState")) {
                // we must fail. SCORM 3rd Edition Addendum has removed the
                // persistState attribute from the adlcp namespaced schema
                msgText = Messages.getString("CPValidator.274", currentNodeName);
                mLogger.debug("FAILED: " + msgText);
                DetailedLogMessageCollection.getInstance()
                        .addMessage(new LogMessage(MessageType.FAILED, msgText));

                result = false;
            }

            // If the current attribute is scormType then additional
            // checks may be necessary
            if (currentNodeName.equalsIgnoreCase("scormType")) {
                // Application Profile Check: Check to make sure that the
                // adlcp:scormType attribute can only appear on an
                // <imscp:resource> element

                result = checkSCORMTypeReq(currentAttrNode, iTestSubjectNode) && result;

            }

            // If the current attribute is objectivesGlobalToSystem then
            // additional checks may be necessary
            if (currentNodeName.equalsIgnoreCase("objectivesGlobalToSystem")) {
                // Application Profile Check: Check that the
                // adlseq:objectivesGlobalToSystem attribute can only appear
                // on an <imscp:organization> element.
                result = checkObjGlobalToSystemReq(currentAttrNode, iTestSubjectNode) && result;
            }

            // Retrieve the application profile rules only if the the
            // current
            // attribute being processed has SCORM application profile
            // requirements
            mLogger.debug("Additional checks needed for attribute [" + currentNodeName + "].\r\n");

            // Retreive the data type rules
            dataType = mRulesValidator.getRuleValue(parentNodeName, iPath, "datatype", currentNodeName);

            // If the data type rules are for an xml:base, then there is
            // more processing that needs to take place.
            if (dataType.equalsIgnoreCase("xmlbase")) {
                // This is a xml:base data type
                msgText = Messages.getString("CPValidator.164", currentNodeName);
                mLogger.debug("INFO: " + msgText);
                DetailedLogMessageCollection.getInstance()
                        .addMessage(new LogMessage(MessageType.INFO, msgText));

                multiplicityUsed = getMultiplicityUsed(attrList, currentNodeName);

                // We will assume that no attribute can exist more than
                // once (ever). According to W3C. Therefore, min and max
                // rules must exist.

                // Get the min rule and convert to an int
                minRule = Integer
                        .parseInt(mRulesValidator.getRuleValue(parentNodeName, iPath, "min", currentNodeName));

                // Get the max rule and convert to an int
                maxRule = Integer
                        .parseInt(mRulesValidator.getRuleValue(parentNodeName, iPath, "max", currentNodeName));

                if ((minRule != -1) || (maxRule != -1)) {
                    if (multiplicityUsed >= minRule && multiplicityUsed <= maxRule) {
                        msgText = Messages.getString("CPValidator.169", currentNodeName);
                        mLogger.debug("PASSED: " + msgText);
                        DetailedLogMessageCollection.getInstance()
                                .addMessage(new LogMessage(MessageType.PASSED, msgText));
                    } else {
                        msgText = Messages.getString("CPValidator.175", currentNodeName);
                        mLogger.debug("FAILED: " + msgText);
                        DetailedLogMessageCollection.getInstance()
                                .addMessage(new LogMessage(MessageType.FAILED, msgText));

                        result = false;

                    } // mult used >= minRule && mult used <= maxRule
                } // end minRule != -1, maxRule != -1

                // Get the spm rule and convert to an int
                spmRule = Integer
                        .parseInt(mRulesValidator.getRuleValue(parentNodeName, iPath, "spm", currentNodeName));

                attributeValue = currentAttrNode.getValue();

                // Check the attributes for smallest permitted maximum(spm)
                // conformance.

                result = checkSPMConformance(currentNodeName, attributeValue, spmRule, true) && result;

                // Check to make sure slashes are correct
                result = checkForSlashes("xml:base", attributeValue) && result;

                if (parentNodeName.equals("manifest")) {
                    mXMLBase[0][1] = attributeValue;
                    mLogger.debug(" XML:base found in manifest, value is " + attributeValue);
                } else if (parentNodeName.equals("resources")) {
                    mXMLBase[1][1] = attributeValue;
                    mLogger.debug(" XML:base found in resources, value is " + attributeValue);
                } else if (parentNodeName.equals("resource")) {
                    mXMLBase[2][1] = attributeValue;
                    mLogger.debug(" XML:base found in resource, value is " + attributeValue);
                }
            } // end if xml:base
        } // end looping over set of attributes for the element

        // If we are processing an <imscp:manifest> element, then there
        // are special cases application profile checks needed.
        if (parentNodeName.equalsIgnoreCase("manifest")) {
            mLogger.debug("Manifest node, additional check's being done.");
            mLogger.debug("Determining how many times the " + "identifier attribute is present.");

            multiplicityUsed = getMultiplicityUsed(attrList, "identifier");

            if (multiplicityUsed < 1) {
                mLogger.debug("FAILED: Mandatory attribute \"identifier\"" + " could not be found");
                DetailedLogMessageCollection.getInstance().addMessage(new LogMessage(MessageType.FAILED,
                        Messages.getString("CPValidator.198", "identifier")));

                result = false;
            }
        } else if (parentNodeName.equalsIgnoreCase("organizations")
                && (mRulesValidator.getApplicationProfile()).equals("contentaggregation")) {
            // multiple <organization> elements exist, but there is no
            // default attribute.
            // not a conformance check, warning only
            multiplicityUsed = getMultiplicityUsed(attrList, "default");

            if (multiplicityUsed < 1) {
                mLogger.debug("ERROR: Mandatory attribute \"default\" " + "could not be found");
                DetailedLogMessageCollection.getInstance().addMessage(
                        new LogMessage(MessageType.FAILED, Messages.getString("CPValidator.198", "default")));

                result = false;
            }
        } else if (parentNodeName.equalsIgnoreCase("organization")
                && (mRulesValidator.getApplicationProfile()).equals("contentaggregation")) {
            multiplicityUsed = getMultiplicityUsed(attrList, "identifier");
            if (multiplicityUsed < 1) {
                mLogger.debug("FAILED: Mandatory attribute \"identifier\" " + "could not be found");
                DetailedLogMessageCollection.getInstance().addMessage(new LogMessage(MessageType.FAILED,
                        Messages.getString("CPValidator.198", "identifier")));

                result = false;
            }
        } else if (parentNodeName.equalsIgnoreCase("item")
                && (mRulesValidator.getApplicationProfile()).equals("contentaggregation")) {
            multiplicityUsed = getMultiplicityUsed(attrList, "identifier");
            if (multiplicityUsed < 1) {
                mLogger.debug("FAILED: Mandatory attribute \"identifier\" " + "could not be found");
                DetailedLogMessageCollection.getInstance().addMessage(new LogMessage(MessageType.FAILED,
                        Messages.getString("CPValidator.198", "identifier")));

                result = false;
            }

            // need to perform a special check to warn when parameters
            // are present but no identifierref is
            int idrefMult = -1;
            int paramMult = -1;

            idrefMult = getMultiplicityUsed(attrList, "identifierref");
            paramMult = getMultiplicityUsed(attrList, "parameters");

            if ((idrefMult < 1) && !(paramMult < 1)) {
                // we have a parameters but no identifierref - warning
                msgText = Messages.getString("CPValidator.220");

                mLogger.debug("WARNING: " + msgText);

                DetailedLogMessageCollection.getInstance()
                        .addMessage(new LogMessage(MessageType.WARNING, msgText));

            }
            // have to store the idref values in a List for future
            // app profile checking of resource attributes

            if (idrefMult >= 1) {
                String iDREFValue = DOMTreeUtility.getAttributeValue(iTestSubjectNode, "identifierref");

                boolean validIdref = mResourceIdentifierList.contains(iDREFValue);

                if (validIdref) {
                    mValidIdrefs.add(iDREFValue);
                }

                // Whether or not it is true we need to keep track of ALL of
                // the idrefs so we can look for dangling references after
                // the entire list of refs, including those on sub-manifests
                // have been inventoried.
                mAllIdrefsList.add(iDREFValue);

            }

            // Perform a special check to ensure that initialization data
            // only exists on items that reference SCOs
            NodeList childrenOfItem = iTestSubjectNode.getChildNodes();
            if (childrenOfItem != null) {
                Node currentItemChild;
                String currentItemChildName;
                int len = childrenOfItem.getLength();
                for (int k = 0; k < len; k++) {
                    currentItemChild = childrenOfItem.item(k);
                    currentItemChildName = currentItemChild.getLocalName();

                    if (currentItemChildName.equals("timeLimitAction")
                            || currentItemChildName.equals("dataFromLMS")
                            || currentItemChildName.equals("completionThreshold")) {
                        if (idrefMult < 1) {
                            // we have an item that contains initialization
                            // data
                            // and does not reference a resource at all

                            result = false;

                            msgText = Messages.getString("CPValidator.226", currentItemChildName);

                            mLogger.debug("FAILED: " + msgText);
                            DetailedLogMessageCollection.getInstance()
                                    .addMessage(new LogMessage(MessageType.FAILED, msgText));

                        } else {
                            // we must verify that the resource it is
                            // referencing
                            // is a sco

                            String idrefValue = DOMTreeUtility.getAttributeValue(iTestSubjectNode,
                                    "identifierref");

                            result = result && checkForReferenceToSco(idrefValue);

                        }
                    }
                }
            }
        } else if (parentNodeName.equalsIgnoreCase("resource")) {
            checkBucketUniqueness(iTestSubjectNode);
            boolean resourceResult = checkResourceAttributes(iTestSubjectNode, attrList);

            result = result && resourceResult;
        } else if (parentNodeName.equalsIgnoreCase("bucket")) {
            checkBucketAttributes(iTestSubjectNode);
        } else if (parentNodeName.equalsIgnoreCase("size")) {
            checkSizeAttributes(iTestSubjectNode);
        }

        // test the attributes

        for (int j = 0; j < numAttr; j++) {
            currentAttrNode = (Attr) attrList.item(j);
            currentNodeName = currentAttrNode.getLocalName();

            dataType = mRulesValidator.getRuleValue(parentNodeName, iPath, "datatype", currentNodeName);

            // we do not want to test for xml namespaces or extensions

            if (dataType.equalsIgnoreCase("idref") || dataType.equalsIgnoreCase("id")
                    || dataType.equalsIgnoreCase("vocabulary") || dataType.equalsIgnoreCase("text")
                    || dataType.equalsIgnoreCase("uri")) {
                msgText = Messages.getString("CPValidator.164", currentNodeName);
                mLogger.debug("INFO: " + msgText);
                DetailedLogMessageCollection.getInstance()
                        .addMessage(new LogMessage(MessageType.INFO, msgText));

                multiplicityUsed = getMultiplicityUsed(attrList, currentNodeName);

                // We will assume that no attribute can exist more than
                // once (ever). According to W3C. Therefore, min and max
                // rules must exist.

                // get the min rule and convert to an int

                minRule = Integer
                        .parseInt(mRulesValidator.getRuleValue(parentNodeName, iPath, "min", currentNodeName));

                // get the max rule and convert to an int

                maxRule = Integer
                        .parseInt(mRulesValidator.getRuleValue(parentNodeName, iPath, "max", currentNodeName));

                if ((minRule != -1) || (maxRule != -1)) {
                    if (multiplicityUsed >= minRule && multiplicityUsed <= maxRule) {
                        msgText = Messages.getString("CPValidator.169", currentNodeName);
                        mLogger.debug("PASSED: " + msgText);

                        DetailedLogMessageCollection.getInstance()
                                .addMessage(new LogMessage(MessageType.PASSED, msgText));
                    } else {
                        msgText = Messages.getString("CPValidator.175", currentNodeName);
                        mLogger.debug("FAILED: " + msgText);
                        DetailedLogMessageCollection.getInstance()
                                .addMessage(new LogMessage(MessageType.FAILED, msgText));

                        result = false;
                    }
                }

                // get the spm rule and convert to an int
                spmRule = Integer
                        .parseInt(mRulesValidator.getRuleValue(parentNodeName, iPath, "spm", currentNodeName));

                attributeValue = currentAttrNode.getValue();

                if (dataType.equalsIgnoreCase("idref")) {
                    // This is a IDREF data type
                    // check the attributes for smallest permitted maximum
                    // (spm) conformance.

                    result = checkSPMConformance(currentNodeName, attributeValue, spmRule, true) && result;

                    // check the Default Idref to make sure it points to an
                    // valid identifier.

                    if (currentNodeName.equalsIgnoreCase("default")) {
                        boolean foundDefaultIdentifier = false;
                        // check for this identifer in the organization list
                        int numOrganizationIdentifiers = mOrganizationIdentifierList.size();

                        for (int i = 0; i < numOrganizationIdentifiers; i++) {
                            String identifier = (mOrganizationIdentifierList.get(i));

                            if (identifier.equals(attributeValue)) {
                                foundDefaultIdentifier = true;

                                break;
                            }
                        }
                        if (foundDefaultIdentifier) {
                            msgText = Messages.getString("CPValidator.251", currentNodeName);
                            mLogger.debug("PASSED: " + msgText);
                            DetailedLogMessageCollection.getInstance()
                                    .addMessage(new LogMessage(MessageType.PASSED, msgText));
                        } else {
                            msgText = Messages.getString("CPValidator.254", currentNodeName);
                            mLogger.debug("FAILED: " + msgText);
                            DetailedLogMessageCollection.getInstance()
                                    .addMessage(new LogMessage(MessageType.FAILED, msgText));

                            result = false;
                        }
                    }
                    if (currentNodeName.equalsIgnoreCase("identifierref")
                            && parentNodeName.equalsIgnoreCase("dependency")) {
                        mAllIdrefsList.add(currentAttrNode.getValue());
                    }

                } else if (dataType.equalsIgnoreCase("id")) {
                    // This is a id data type
                    // check the attributes for smallest permitted maximum
                    // (spm) conformance.

                    result = checkSPMConformance(currentNodeName, attributeValue, spmRule, true) && result;

                    if (parentNodeName.equals("manifest")) {
                        mManifestID = currentAttrNode.getValue();
                        mLogger.debug("mManifestID is " + mManifestID);
                    }

                    // imsssp id attributes here
                } else if (dataType.equalsIgnoreCase("uri")) {
                    // This is a URI data type
                    // check the attributes for smallest permitted maximum
                    // (spm) conformance. Only perform these checks if
                    // the value is not an empty string

                    String myAttributeValue = currentAttrNode.getValue();
                    if (!myAttributeValue.equals("")) {
                        // check to ensure there are no leading slashes
                        result = checkForSlashes("href", myAttributeValue) && result;

                        // check if the file exists
                        // apply xml:base on href value before href checks
                        if (doesXMLBaseExist()) {
                            mLogger.debug("APPLYING XML BASE");
                            myAttributeValue = applyXMLBase(myAttributeValue);
                        }

                        if (myAttributeValue.indexOf('\\') != -1) {
                            msgText = Messages.getString("CPValidator.265", myAttributeValue);

                            mLogger.debug("FAILED: " + msgText);
                            DetailedLogMessageCollection.getInstance()
                                    .addMessage(new LogMessage(MessageType.FAILED, msgText));

                            result &= false;
                        }

                        // check href spm after it is pre-appended with
                        // xml:base
                        result = checkSPMConformance(currentNodeName, myAttributeValue, spmRule, true)
                                && result;

                        result = checkHref(myAttributeValue) && result;

                    }
                } else if (dataType.equalsIgnoreCase("vocabulary")) {
                    // This is a VOCAB data type
                    // retrieve the vocab rule values and check against the
                    // vocab values that exist within the test subject

                    msgText = "Testing attribute \"" + currentNodeName + "\" for valid vocabulary";
                    mLogger.debug("INFO: " + msgText);

                    List<String> vocabAttribValues = mRulesValidator.getAttribVocabRuleValues(parentNodeName,
                            iPath, currentNodeName);
                    // we are assuming that only 1 vocabulary value may
                    // exist for an attribute

                    result = checkVocabulary(currentNodeName, attributeValue, vocabAttribValues, true)
                            && result;
                } else if (dataType.equalsIgnoreCase("text")) {
                    // This is a TEXT data type
                    // check the attributes for smallest permitted maximum
                    // (spm) conformance.

                    result = checkSPMConformance(currentNodeName, attributeValue, spmRule, true) && result;

                    // test the parameter attribute for valid syntax
                    if (currentNodeName.equalsIgnoreCase("parameters")) {
                        ParameterChecker pc = new ParameterChecker();
                        result = pc.checkParameters(attributeValue) && result;
                    }
                }
            }
        } // done with attributes

        // Test the child Nodes

        NodeList children = iTestSubjectNode.getChildNodes();

        if (children != null) {
            int numChildren = children.getLength();

            // update the path for this child element

            String path;

            if (iPath.equals("")) {
                // the node is a DOCUMENT or a root <manifest>
                path = parentNodeName;
            } else if ((iPath.equals("manifest.manifest")) && (parentNodeName.equals("manifest"))) {
                path = iPath;
            } else if (parentNodeName.equalsIgnoreCase("item")) {
                // the Node is an <imscp:item>
                if (iPath.equals("manifest.organizations.organization.item")) {
                    path = iPath;
                } else {
                    path = iPath + "." + parentNodeName;
                }
            } else {
                path = iPath + "." + parentNodeName;
            }

            // SPECIAL CASE: check for mandatory elements

            if (parentNodeName.equalsIgnoreCase("manifest")) {

                // check for mandatory metadata element at package level
                multiplicityUsed = getMultiplicityUsed(iTestSubjectNode, "metadata");
                if (multiplicityUsed < 1) {
                    msgText = Messages.getString("CPValidator.287", "metadata");
                    mLogger.debug("FAILED: " + msgText);
                    DetailedLogMessageCollection.getInstance()
                            .addMessage(new LogMessage(MessageType.FAILED, msgText));

                    result = false;
                } else
                // check for mandatory children
                {
                    Node caMetadataNode = DOMTreeUtility.getNode(iTestSubjectNode, "metadata");

                    // check for mandatory <imscp:schema> element
                    multiplicityUsed = getMultiplicityUsed(caMetadataNode, "schema");

                    if (multiplicityUsed < 1) {
                        msgText = Messages.getString("CPValidator.287", "schema");
                        mLogger.debug("FAILED: " + msgText);
                        DetailedLogMessageCollection.getInstance()
                                .addMessage(new LogMessage(MessageType.FAILED, msgText));

                        result = false;
                    }

                    // check for mandatory <imscp:schemaversion> element
                    multiplicityUsed = getMultiplicityUsed(caMetadataNode, "schemaversion");

                    if (multiplicityUsed < 1) {
                        msgText = Messages.getString("CPValidator.287", "schemaversion");
                        mLogger.debug("FAILED: " + msgText);
                        DetailedLogMessageCollection.getInstance()
                                .addMessage(new LogMessage(MessageType.FAILED, msgText));

                        result = false;
                    }
                }

                multiplicityUsed = getMultiplicityUsed(iTestSubjectNode, "organizations");
                if (multiplicityUsed < 1) {
                    msgText = Messages.getString("CPValidator.287", "organizations");
                    mLogger.debug("FAILED: " + msgText);
                    DetailedLogMessageCollection.getInstance()
                            .addMessage(new LogMessage(MessageType.FAILED, msgText));

                    result = false;
                }

                multiplicityUsed = getMultiplicityUsed(iTestSubjectNode, "resources");
                if (multiplicityUsed < 1) {
                    msgText = Messages.getString("CPValidator.287", "resources");
                    mLogger.debug("FAILED: " + msgText);
                    DetailedLogMessageCollection.getInstance()
                            .addMessage(new LogMessage(MessageType.FAILED, msgText));

                    result = false;
                }
            } else if (parentNodeName.equalsIgnoreCase("organizations")
                    && (mRulesValidator.getApplicationProfile()).equals("contentaggregation")) {
                multiplicityUsed = getMultiplicityUsed(iTestSubjectNode, "organization");

                if (multiplicityUsed < 1) {
                    msgText = Messages.getString("CPValidator.287", "organization");

                    mLogger.debug("FAILED: " + msgText);
                    DetailedLogMessageCollection.getInstance()
                            .addMessage(new LogMessage(MessageType.FAILED, msgText));

                    result = false;
                }

            }
            // have to check to ensure that empty organizations exist
            // for resource package

            else if (parentNodeName.equalsIgnoreCase("organizations")
                    && (mRulesValidator.getApplicationProfile()).equals("resource")) {
                multiplicityUsed = getMultiplicityUsed(iTestSubjectNode, "organization");
                if (multiplicityUsed > 0) {
                    msgText = Messages.getString("CPValidator.311");
                    mLogger.debug("FAILED: " + msgText);
                    DetailedLogMessageCollection.getInstance()
                            .addMessage(new LogMessage(MessageType.FAILED, msgText));

                    result = false;
                } else {
                    msgText = Messages.getString("CPValidator.312");
                    // we have an empty <orgs> element, display a valid msg
                    mLogger.debug("PASSED: " + msgText);
                    DetailedLogMessageCollection.getInstance()
                            .addMessage(new LogMessage(MessageType.PASSED, msgText));

                }
            } else if (parentNodeName.equalsIgnoreCase("organization")
                    && (mRulesValidator.getApplicationProfile()).equals("contentaggregation")) {
                multiplicityUsed = getMultiplicityUsed(iTestSubjectNode, "title");
                if (multiplicityUsed < 1) {
                    msgText = Messages.getString("CPValidator.287", "title");
                    mLogger.debug("FAILED: " + msgText);
                    DetailedLogMessageCollection.getInstance()
                            .addMessage(new LogMessage(MessageType.FAILED, msgText));

                    result = false;
                }

                multiplicityUsed = getMultiplicityUsed(iTestSubjectNode, "item");
                if (multiplicityUsed < 1) {
                    msgText = Messages.getString("CPValidator.287", "item");
                    mLogger.debug("FAILED: " + msgText);
                    DetailedLogMessageCollection.getInstance()
                            .addMessage(new LogMessage(MessageType.FAILED, msgText));

                    result = false;
                }

                // special checks for item
                result = checkItem(iTestSubjectNode, mManifestInfo) && result;

            }

            for (int z = 0; z < numChildren; z++) {

                Node currentChild = children.item(z);
                String currentChildName = currentChild.getLocalName();

                msgText = "Currentchild is " + currentChildName + " and path is " + path;

                mLogger.debug(msgText);

                if (currentChildName != null) {

                    if (((currentChildName.equals("timeLimitAction"))
                            || (currentChildName.equals("dataFromLMS"))
                            || (currentChildName.equals("completionThreshold"))
                            || (currentChildName.equals("presentation"))) && (!parentNodeName.equals("item"))) {
                        result = false;

                        msgText = Messages.getString("CPValidator.328", currentChildName, "item");

                        mLogger.debug("FAILED: " + msgText);
                        DetailedLogMessageCollection.getInstance()
                                .addMessage(new LogMessage(MessageType.FAILED, msgText));
                    }

                    if (((currentChildName.equals("constrainedChoiceConsiderations"))
                            || (currentChildName.equals("rollupConsiderations")))
                            && (!parentNodeName.equals("sequencing"))) {

                        result = false;

                        msgText = Messages.getString("CPValidator.328", currentChildName, "sequencing");

                        mLogger.debug("FAILED: " + msgText);
                        DetailedLogMessageCollection.getInstance()
                                .addMessage(new LogMessage(MessageType.FAILED, msgText));
                    }

                    // must enforce that the adlcp:location exist
                    // as a child of metadata only - warning for best
                    // practice.

                    if ((currentChildName.equals("location")) && (!parentNodeName.equals("metadata"))) {

                        result = false;

                        msgText = Messages.getString("CPValidator.328", currentChildName, "metadata");

                        mLogger.debug("WARNING: " + msgText);
                        DetailedLogMessageCollection.getInstance()
                                .addMessage(new LogMessage(MessageType.WARNING, msgText));
                    }

                    if ((currentChildName.equals("sequencing")) && (!parentNodeName.equals("item"))
                            && (!parentNodeName.equals("organization"))) {

                        result = false;

                        msgText = Messages.getString("CPValidator.345", currentChildName);

                        mLogger.debug("FAILED: " + msgText);
                        DetailedLogMessageCollection.getInstance()
                                .addMessage(new LogMessage(MessageType.FAILED, msgText));
                    }

                    dataType = mRulesValidator.getRuleValue(currentChildName, path, "datatype");
                    // must enforce that the imsssp:bucket exist
                    // as a child of a resource only.

                    if ((currentChildName.equals("bucket")) && (!parentNodeName.equals("resource"))) {
                        // Check to enforce that bucket is a child of a
                        // resource
                        msgText = "<" + currentChildName + "> can only " + "exist as a child of a <resource>";

                        mLogger.debug("SSP: " + msgText);
                        DetailedLogMessageCollection.getInstance()
                                .addMessage(new LogMessage(MessageType.FAILED, msgText));

                    }

                    // must enforce that the imsssp:size exist
                    // as a child of a bucket only.

                    if ((currentChildName.equals("size")) && (!parentNodeName.equals("bucket"))) {

                        msgText = "<" + currentChildName + "> can only " + "exist as a child of a <bucket>";

                        mLogger.debug("SSP: " + msgText);
                        DetailedLogMessageCollection.getInstance()
                                .addMessage(new LogMessage(MessageType.FAILED, msgText));
                    }

                    // Check the SCORMType of the resource; it must be sco
                    if ((currentChildName.equals("bucket")) && (parentNodeName.equals("resource"))) {
                        // Now check to ensure that the resource type is SCO
                        String typeS = DOMTreeUtility.getAttributeValue(iTestSubjectNode, "scormType");

                        if (!typeS.equalsIgnoreCase("sco")) {
                            // result = false;

                            msgText = "The <" + currentChildName + "> shall"
                                    + " only exist in a resource that is " + " scormType = \"sco\".";

                            mLogger.debug("SSP: " + msgText);
                            DetailedLogMessageCollection.getInstance()
                                    .addMessage(new LogMessage(MessageType.FAILED, msgText));
                        }

                    }

                    // we do not want to test for extensions here

                    if (dataType.equalsIgnoreCase("parent") || dataType.equalsIgnoreCase("vocabulary")
                            || dataType.equalsIgnoreCase("text") || dataType.equalsIgnoreCase("sequencing")
                            || dataType.equalsIgnoreCase("metadata") || dataType.equalsIgnoreCase("decimal")) {
                        // SCORM 3rd edition -- we need to ignore
                        // (sub)manifest
                        // and warn only

                        if (currentChildName.equals("manifest") && path.equals("manifest")) {
                            msgText = Messages.getString("CPValidator.100");
                            mLogger.debug("WARNING: " + msgText);
                            DetailedLogMessageCollection.getInstance()
                                    .addMessage(new LogMessage(MessageType.WARNING, msgText));

                            // Make cleansing call for excess baggage here
                            // pass (sub)manifest node into a new function

                            // retrieve all adlcp:location uri's contained
                            // in the
                            // (sub)manifest
                            List<String> submanifestURIList = mManifestHandler.getLocationMD(currentChild);
                            trackSubManifest(currentChild, submanifestURIList);
                        } else
                        // we are not dealing with (sub)manifest
                        {
                            msgText = Messages.getString("CPValidator.131", currentChildName);

                            mLogger.debug("INFO: " + msgText);
                            DetailedLogMessageCollection.getInstance()
                                    .addMessage(new LogMessage(MessageType.INFO, msgText));

                            multiplicityUsed = getMultiplicityUsed(iTestSubjectNode, currentChildName);

                            // get the min rule and convert to an int

                            minRule = Integer
                                    .parseInt(mRulesValidator.getRuleValue(currentChildName, path, "min"));

                            // get the max rule and convert to an int

                            maxRule = Integer
                                    .parseInt(mRulesValidator.getRuleValue(currentChildName, path, "max"));

                            if ((minRule != -1) && (maxRule != -1)) {
                                if (multiplicityUsed >= minRule && multiplicityUsed <= maxRule) {
                                    msgText = Messages.getString("CPValidator.135", currentChildName);
                                    mLogger.debug("PASSED: " + msgText);
                                    DetailedLogMessageCollection.getInstance()
                                            .addMessage(new LogMessage(MessageType.PASSED, msgText));
                                } else {
                                    msgText = Messages.getString("CPValidator.364", currentChildName);
                                    mLogger.debug("FAILED: " + msgText);
                                    DetailedLogMessageCollection.getInstance()
                                            .addMessage(new LogMessage(MessageType.FAILED, msgText));

                                    result = false;
                                }
                            } else if ((minRule != -1) && (maxRule == -1)) {
                                if (multiplicityUsed >= minRule) {
                                    msgText = Messages.getString("CPValidator.135", currentChildName);
                                    mLogger.debug("PASSED: " + msgText);
                                    DetailedLogMessageCollection.getInstance()
                                            .addMessage(new LogMessage(MessageType.PASSED, msgText));
                                } else {
                                    msgText = Messages.getString("CPValidator.364", currentChildName);
                                    mLogger.debug("FAILED: " + msgText);
                                    DetailedLogMessageCollection.getInstance()
                                            .addMessage(new LogMessage(MessageType.FAILED, msgText));

                                    result = false;
                                }
                            }
                            // test for each particular data type

                            if (dataType.equalsIgnoreCase("parent")) {
                                // need to populate the files that belong to
                                // each resource
                                if (currentChildName.equals("resources")) {
                                    populateResourceTable(currentChild);
                                }

                                // Verify that if the resource href matches
                                // the file href if the resource is local
                                if (currentChildName.equals("resource")) {
                                    result = checkResourceFileHref(currentChild) && result;
                                }

                                // This is a parent element, need to recurse
                                result = compareToRules(currentChild, path) && result;

                            } else if (dataType.equalsIgnoreCase("sequencing")) {
                                // This is a sequencing data type

                                SequenceValidator sequenceValidator = new SequenceValidator();

                                result = sequenceValidator.validate(currentChild) && result;
                            } else if (dataType.equalsIgnoreCase("metadata")) {
                                // This is a metadata data type - no longer
                                // need
                                // to
                                // check for lom and location to coexist
                                // must detect that the metadata exists in
                                // location
                                if (currentChildName.equals("location")) {
                                    String currentLocationValue = mRulesValidator.getTaggedData(currentChild);

                                    // check to ensure there are no leading
                                    // slashes
                                    result = checkForSlashes("location", currentLocationValue) && result;

                                    currentLocationValue = applyXMLBase(currentLocationValue);

                                    result = result && checkHref(currentLocationValue);
                                }
                            } else if (dataType.equalsIgnoreCase("text")) {
                                // This is a text data type
                                // check spm

                                // first must retrieve the value of this
                                // child
                                // element

                                String currentChildValue = mRulesValidator.getTaggedData(currentChild);

                                // get the spm rule and convert to an int

                                spmRule = Integer
                                        .parseInt(mRulesValidator.getRuleValue(currentChildName, path, "spm"));

                                result = checkSPMConformance(currentChildName, currentChildValue, spmRule,
                                        false) && result;
                            } else if (dataType.equalsIgnoreCase("vocabulary")) {
                                // This is a vocabulary data type
                                // more than one vocabulary token may exist

                                msgText = Messages.getString("CPValidator.383", currentChildName);
                                mLogger.debug("INFO: " + msgText);
                                DetailedLogMessageCollection.getInstance()
                                        .addMessage(new LogMessage(MessageType.INFO, msgText));

                                // retrieve the value of this element

                                String currentChildValue = mRulesValidator.getTaggedData(currentChild);

                                List<String> vocabValues = mRulesValidator.getVocabRuleValues(currentChildName,
                                        path);

                                result = checkVocabulary(currentChildName, currentChildValue, vocabValues,
                                        false) && result;

                            } else if (dataType.equalsIgnoreCase("decimal")) {
                                // This is a decimal data type
                                // only adlcp:completionThreshold is of this
                                // type
                                // and currently all checks are enforced by
                                // the schema. No additional checks needed
                                // at
                                // this time.
                                result = true && result;
                            }
                        }
                    } // end ignorning and warning (sub)manifest
                } // end something
            }

        }
        // remove the xml:base value for this particular element

        if (parentNodeName.equals("manifest")) {
            mXMLBase[0][1] = "";
        } else if (parentNodeName.equals("resources")) {
            mXMLBase[1][1] = "";
        } else if (parentNodeName.equals("resource")) {
            mXMLBase[2][1] = "";
        }

        break;
    }

    // handle entity reference nodes
    case Node.ENTITY_REFERENCE_NODE: {
        break;
    }

    // text
    case Node.COMMENT_NODE: {
        break;
    }

    case Node.CDATA_SECTION_NODE: {
        break;
    }

    case Node.TEXT_NODE: {
        break;
    }
    default: {
        // Do nothing - no defined requirements to process any other
        // type of node type
        break;
    }
    }// end switch statement

    mLogger.debug("CPValidator compareToRules()");
    return result;
}

From source file:org.adl.validator.contentpackage.CPValidator.java

/**
 * This method assists with the application profile check for the
 * multiplicity of elements. This method returns the number of times the
 * element was detected based on the given element name and the given parent
 * node of that element name.//from w ww.  j  av a 2 s . com
 * 
 * @param iParentNode
 *            The parent node of the element being searched
 * @param iNodeName
 *            The name of the element being searched for
 * @return - int: number of instances of a given element
 */
public int getMultiplicityUsed(Node iParentNode, String iNodeName) {
    mLogger.debug("CPValidator getMultiplicityUsed() - Elements");
    mLogger.debug("Input Parent Node: " + iParentNode.getLocalName());
    mLogger.debug("Input Node we are looking for: " + iNodeName);

    // Need a list to find how many kids to cycle through
    NodeList kids = iParentNode.getChildNodes();
    int count = 0;

    int kidsLength = kids.getLength();
    for (int i = 0; i < kidsLength; i++) {
        if (kids.item(i).getNodeType() == Node.ELEMENT_NODE) {
            String currentNodeName = kids.item(i).getLocalName();
            // String currentNodeNamespace = kids.item(i).getNamespaceURI();

            if (currentNodeName.equals(iNodeName)) {
                count++;
            } // end if the current node name equals the name we are looking
              // for
        } // end of the node type is ELEMENT_NODE
    } // end looping over children

    mLogger.debug("The " + iNodeName + ", appeared " + count + " times.");

    return count;
}

From source file:org.adl.validator.contentpackage.CPValidator.java

/**
 * This method tracks all identifier values found in the manifest for the
 * organization elements only. Tracking of organization identifiers is
 * performed in order to verify that default attribute points to valid
 * organization identifier value. These identifers are tracked recursively
 * by walking through test subject dom and adding the identifier elements
 * found to a list.//from w  w w.j  a  v  a  2 s. com
 * 
 * @param iParentNode
 *            Root node of the test subject
 */
private void trackOrgIdentifiers(Node iParentNode) {
    // recursively find the organization ids and add them to the List

    mLogger.debug("CPValidator trackOrgIdentifiers()");
    String msgText = "";

    if (iParentNode != null) {
        int type = iParentNode.getNodeType();

        switch (type) {
        case Node.DOCUMENT_NODE: {
            Node rootNode = ((Document) iParentNode).getDocumentElement();

            trackOrgIdentifiers(rootNode);

            break;
        }

        case Node.ELEMENT_NODE: {
            String nodeName = iParentNode.getLocalName();

            if (nodeName.equals("manifest")) {
                Node orgsNode = DOMTreeUtility.getNode(iParentNode, "organizations");

                if (orgsNode != null) {
                    List<Node> orgNodes = DOMTreeUtility.getNodes(orgsNode, "organization");

                    // Loop through the oganization elements to retrieve the
                    // identifier attribute values

                    int orgNodesSize = orgNodes.size();
                    for (int i = 0; i < orgNodesSize; i++) {
                        Node currentChild = orgNodes.get(i);
                        String orgIdentifier = DOMTreeUtility.getAttributeValue(currentChild, "identifier");

                        mOrganizationIdentifierList.add(orgIdentifier);
                        msgText = "Just added " + orgIdentifier + "to the org List";
                        mLogger.debug(msgText);
                    }
                }
            }

            // Get (sub)manifests and make call recursively
            List<Node> subManifestList = DOMTreeUtility.getNodes(iParentNode, "manifest");

            int subManifestListSize = subManifestList.size();
            for (int j = 0; j < subManifestListSize; j++) {
                Node currentSubManifest = subManifestList.get(j);
                trackOrgIdentifiers(currentSubManifest);
            }
            break;
        }
        default: {
            // Do nothing - no defined requirements to process any other
            // type of node type
            break;
        }
        }
    }

    mLogger.debug("CPValidator trackOrgIdentifiers()");
}

From source file:org.adl.validator.contentpackage.ManifestMap.java

/**
 * This method populates the ManifestMap object by traversing down
 * the document node and storing all information necessary for the validation
 * of (Sub) manifests.  Information stored for each manifest element includes:
 * manifest identifiers,item identifers, item identifierrefs, and
 * resource identifiers/*from   w  w w. j a va 2 s.  co  m*/
 *
 * @param iNode the node being checked. All checks will depend on the type of node
 * being evaluated
 * 
 * @return - The boolean describing if the ManifestMap object(s) has been
 * populated properly.
 */
public boolean populateManifestMap(Node iNode) {
    // looks exactly like prunetree as we walk down the tree
    log.debug("populateManifestMap");

    boolean result = true;

    // is there anything to do?
    if (iNode == null) {
        result = false;
        return result;
    }

    int type = iNode.getNodeType();

    switch (type) {
    case Node.PROCESSING_INSTRUCTION_NODE: {
        break;
    }
    case Node.DOCUMENT_NODE: {
        Node rootNode = ((Document) iNode).getDocumentElement();

        result = populateManifestMap(rootNode) && result;

        break;
    }
    case Node.ELEMENT_NODE: {
        String parentNodeName = iNode.getLocalName();

        if (parentNodeName.equalsIgnoreCase("manifest")) {
            // We are dealing with an IMS <manifest> element, get the IMS
            // CP identifier for the <manifest> elememnt
            mManifestId = DOMTreeUtility.getAttributeValue(iNode, "identifier");

            log.debug(
                    "ManifestMap:populateManifestMap, " + "Just stored a Manifest Id value of " + mManifestId);

            // Recurse to populate mItemIdrefs and mItemIds

            // Find the <organization> elements

            Node orgsNode = DOMTreeUtility.getNode(iNode, "organizations");

            if (orgsNode != null) {
                List<Node> orgElems = DOMTreeUtility.getNodes(orgsNode, "organization");

                log.debug("ManifestMap:populateManifestMap, " + "Number of <organization> elements: "
                        + orgElems.size());

                if (!orgElems.isEmpty()) {
                    int orgElemsSize = orgElems.size();
                    for (int i = 0; i < orgElemsSize; i++) {
                        List<Node> itemElems = DOMTreeUtility.getNodes(orgElems.get(i), "item");

                        log.debug("ManifestMap:populateManifestMap, " + "Number of <item> elements: "
                                + itemElems.size());

                        if (!itemElems.isEmpty()) {
                            int itemElemsSize = itemElems.size();
                            for (int j = 0; j < itemElemsSize; j++) {
                                result = populateManifestMap((itemElems.get(j))) && result;
                            }
                        }
                    }
                }
            }

            //recurse to populate mResourceIds

            Node resourcesNode = DOMTreeUtility.getNode(iNode, "resources");

            if (resourcesNode != null) {
                List<Node> resourceElems = DOMTreeUtility.getNodes(resourcesNode, "resource");

                log.debug("ManifestMap:populateManifestMap, " + "Number of <resource> elements: "
                        + resourceElems.size());

                int resourceElemsSize = resourceElems.size();
                for (int k = 0; k < resourceElemsSize; k++) {
                    result = populateManifestMap((resourceElems.get(k))) && result;

                }
            }

            //recurse to populate mManifestMaps

            //find the <manifest> elements (a.k.a sub-manifests)
            List<Node> subManifests = DOMTreeUtility.getNodes(iNode, "manifest");

            log.debug("ManifestMap:populateManifestMap, " + "Number of (Sub) manifest elements: "
                    + subManifests.size());

            if (!subManifests.isEmpty()) {
                mDoSubmanifestExist = true;
                int subManifestSize = subManifests.size();
                for (int l = 0; l < subManifestSize; l++) {
                    ManifestMap manifestMapObject = new ManifestMap();
                    result = manifestMapObject.populateManifestMap(subManifests.get(l)) && result;
                    mManifestMaps.add(manifestMapObject);
                }

            }
        } else if (parentNodeName.equalsIgnoreCase("item")) {
            //store item identifier value
            String itemId = DOMTreeUtility.getAttributeValue(iNode, "identifier");

            mItemIds.add(itemId);

            log.debug("ManifestMap:populateManifestMap, " + "Just stored an Item Id value of " + itemId);

            //store item identifier reference value
            String itemIdref = DOMTreeUtility.getAttributeValue(iNode, "identifierref");

            mItemIdrefs.add(itemIdref);

            log.debug("ManifestMap:populateManifestMap, " + "Just stored an Item Idref value of " + itemIdref);

            //recurse to populate all child item elements
            List<Node> items = DOMTreeUtility.getNodes(iNode, "item");
            if (!items.isEmpty()) {
                int itemsSize = items.size();
                for (int z = 0; z < itemsSize; z++) {
                    result = populateManifestMap(items.get(z)) && result;
                }
            }
        } else if (parentNodeName.equalsIgnoreCase("resource")) {
            //store resource identifier value
            String resourceId = DOMTreeUtility.getAttributeValue(iNode, "identifier");
            // convert to lower so case sensativity does not play a role

            mResourceIds.add(resourceId);

            log.debug("ManifestMap:populateManifestMap, " + "Just stored a Resource Id value of " + resourceId);

            // populate <dependency> element

            List<Node> dependencyElems = DOMTreeUtility.getNodes(iNode, "dependency");

            int dependencyElemsSize = dependencyElems.size();

            for (int w = 0; w < dependencyElemsSize; w++) {
                Node dependencyElem = dependencyElems.get(w);

                //store resource identifier value
                String dependencyIdref = DOMTreeUtility.getAttributeValue(dependencyElem, "identifierref");

                mDependencyIdrefs.add(dependencyIdref);

                log.debug("ManifestMap:populateManifestMap, " + "Just stored a Dependency Idref value of "
                        + mDependencyIdrefs);
            }
        }

        break;
    }
    // handle entity reference nodes
    case Node.ENTITY_REFERENCE_NODE: {
        break;
    }

    // text
    case Node.COMMENT_NODE: {
        break;
    }

    case Node.CDATA_SECTION_NODE: {
        break;
    }

    case Node.TEXT_NODE: {
        break;
    }
    }

    log.debug("populateManifestMap");

    return result;
}