Example usage for org.w3c.dom Attr getValue

List of usage examples for org.w3c.dom Attr getValue

Introduction

In this page you can find the example usage for org.w3c.dom Attr getValue.

Prototype

public String getValue();

Source Link

Document

On retrieval, the value of the attribute is returned as a string.

Usage

From source file:net.sourceforge.pmd.rules.RuleFactory.java

/**
 * Parses a property definition node and returns the defined property descriptor.
 *
 * @param propertyElement Property node to parse
 *
 * @return The property descriptor//  w w w  .j a  v a 2 s .  com
 */
private static PropertyDescriptor<?> parsePropertyDefinition(Element propertyElement) {
    String typeId = propertyElement.getAttribute(PropertyDescriptorField.TYPE.attributeName());

    PropertyDescriptorExternalBuilder<?> pdFactory = PropertyTypeId.factoryFor(typeId);
    if (pdFactory == null) {
        throw new IllegalArgumentException("No property descriptor factory for type: " + typeId);
    }

    Map<PropertyDescriptorField, String> values = new HashMap<>();
    NamedNodeMap atts = propertyElement.getAttributes();

    /// populate a map of values for an individual descriptor
    for (int i = 0; i < atts.getLength(); i++) {
        Attr a = (Attr) atts.item(i);
        values.put(PropertyDescriptorField.getConstant(a.getName()), a.getValue());
    }

    if (StringUtils.isBlank(values.get(DEFAULT_VALUE))) {
        NodeList children = propertyElement.getElementsByTagName(DEFAULT_VALUE.attributeName());
        if (children.getLength() == 1) {
            values.put(DEFAULT_VALUE, children.item(0).getTextContent());
        } else {
            throw new IllegalArgumentException("No value defined!");
        }
    }

    // casting is not pretty but prevents the interface from having this method
    return pdFactory.build(values);
}

From source file:openblocks.yacodeblocks.BlockSaveFileTest.java

private void assertAttrContainsOnlyAsciiCharacters(Attr attr) throws Exception {
    assertStringContainsOnlyAsciiCharacters(attr.getName(), "name", attr);
    assertStringContainsOnlyAsciiCharacters(attr.getValue(), "value", attr);
}

From source file:org.adl.parsers.dom.ADLDOMParser.java

/**
 * This method checks to see if the node that is being processed contains
 * an xsi:schemaLocation attribute.  If it does, the method adds the name
 * value of the attribute to the list of schemaLocations.
 * /*from  w w w .ja v a2s .  c om*/
 * @param iNode The node that is being processed
 * @param iXMLFileName The name of the XML test subject
 */
private void checkForSchemaLocations(Node iNode, String iXMLFileName) {
    log.debug("checkForSchemaLocations()");
    log.debug("Processing Node: [" + iNode.getLocalName() + "]");
    log.debug("Processing Nodes Namespace: [" + iNode.getNamespaceURI() + "]");

    // Get the list of attributes of the element
    NamedNodeMap attrList = iNode.getAttributes();

    // Loop over the attributes for this element, remove any attributes
    // that are extensions
    log.debug("Processing " + attrList.getLength() + " attributes");
    for (int i = 0; i < attrList.getLength(); i++) {
        Attr currentAttribute = (Attr) attrList.item(i);
        String parentNamespace = iNode.getNamespaceURI();
        String attributeNamespace = currentAttribute.getNamespaceURI();

        log.debug("Processing attribute [" + i + "]: [" + currentAttribute.getLocalName() + "]");
        log.debug("Attributes Namespace [" + i + "]: [" + attributeNamespace + "]");
        if (!mDeclaredNamespaces.contains(attributeNamespace) && (attributeNamespace != null)) {
            mDeclaredNamespaces.add(attributeNamespace);
        }

        log.debug("Attributes Parent Node [" + i + "]: [" + iNode.getLocalName() + "]");
        log.debug("Parent Nodes Namespace [" + i + "]: [" + parentNamespace + "]");

        if (!mDeclaredNamespaces.contains(attributeNamespace) && (parentNamespace != null)) {
            mDeclaredNamespaces.add(parentNamespace);
        }

        // If one of the attributes is xsi:schemaLocation, then
        // save off the namespace and the schema location.  These
        // will be used later during the validation process
        if (currentAttribute.getLocalName().equals("schemaLocation")
                && currentAttribute.getNamespaceURI().equals("http://www.w3.org/2001/XMLSchema-instance")) {
            // A schema location has been defined in the XML, don't 
            // use the defaults
            if (mFirstTimeSchemaLocationFound) {
                // Don't use the default schema locations
                mSchemaLocation = null;
                mFirstTimeSchemaLocationFound = false;
                // flag that xsi:schemalocation attribute has been declared 
                mSchemaLocExists = true;
            }
            addSchemaLocationToList(currentAttribute.getValue(), iXMLFileName);
        }
    } // end looping over attributes

    log.debug("checkForSchemaLocations()");
}

From source file:org.adl.parsers.dom.DOMTreeUtility.java

/**
 * This method returns the value of the attribute that matches the
 * attribute name (iAttributeName) and namepace (iNamespaceForAttr) in
 * the node.  This is to cover cases where elements have multiple
 * attributes that have the same local name but come from different
 * namespaces./*from www  .  j  ava 2 s . c  om*/
 *
 * @param iNode The element containing the attribute
 * @param iAttributeName The name of the attribute being retrieved
 * 
 * @return Returns the value the attribute<br>
 */
public static String getAttributeValue(Node iNode, String iAttributeName) {
    log.debug("DOMTreeUtility getAttributeValue()");
    log.debug("Parent Node: " + iNode.getLocalName());
    log.debug("Node being searched for: " + iAttributeName);
    String result = "";
    // Get the attribute from the node matching the attribute name
    // and namespace
    Attr theAttribute = getAttribute(iNode, iAttributeName);

    // Make sure the attribute was present for the element
    if (theAttribute != null) {
        // If present, retrieve the value of the attribute
        result = theAttribute.getValue();
    }
    // return the value
    return result;
}

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>/*w  ww.j a  v a2s.  c o m*/
 * 
 * @param iBucketNode
 *            The resources node <br>
 */
private void checkBucketAttributes(Node iBucketNode) {
    mLogger.debug("CPValidator checkBucketAttributes");

    String msgText;
    boolean foundValidChar = false;

    NamedNodeMap attrList = iBucketNode.getAttributes();
    int numAttr = attrList.getLength();

    Attr currentAttrNode;
    String currentAttrName;
    String attributeValue = null;

    // find the bucketID and bucketType attributes

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

        // Check bucketID and bucketType Attribute Values for nothing but
        // white space

        if (currentAttrName.equals("bucketID") || currentAttrName.equals("bucketType")) {
            // Find the length of bucket attribute and check if its all
            // whitespace
            attributeValue = currentAttrNode.getValue();

            for (int j = 0; j < attributeValue.length(); j++) {
                char tempChar = attributeValue.charAt(j);

                if (!(Character.isWhitespace(tempChar))) {
                    foundValidChar = true;
                    break;
                }
            }
            if (!foundValidChar) {
                msgText = "Attribute \"" + currentAttrName + "\" must "
                        + "contain valid characters, all whitespace found.";
                mLogger.debug("SSP: " + msgText);
                DetailedLogMessageCollection.getInstance()
                        .addMessage(new LogMessage(MessageType.FAILED, msgText));
            }

            foundValidChar = false;

        }
    }
}

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 . ja  va  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 assists with the application profile check for the validation
 * of the bucket attributes. <br>//from  w  ww .  j  a v  a2 s  . c  o m
 * 
 * @param iSizeNode
 *            The resources node <br>
 */
private void checkSizeAttributes(Node iSizeNode) {
    mLogger.debug("CPValidator checkSizeAttributes");

    String msgText;

    NamedNodeMap attrList = iSizeNode.getAttributes();
    int numAttr = attrList.getLength();

    Attr currentAttrNode;
    String currentAttrName;
    String attributeValue = null;
    int minVal = 0;

    // find the minimum and requested attributes

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

        // Check bucketID and bucketType Attribute Values for even numbers

        if (currentAttrName.equals("minimum") || currentAttrName.equals("requested")) {
            // Get the value and check if it is a valid even integer
            attributeValue = currentAttrNode.getValue();

            // Assume the value is valid
            boolean valid = true;

            if (attributeValue == null) {
                // A null value can never be valid
                valid = false;
            }

            try {
                int value = Integer.parseInt(attributeValue, 10);

                if (value < minVal || (value % 2) != 0) {
                    valid = false;
                }
            } catch (Exception e) {
                valid = false;
            }

            if (!valid) {
                msgText = "Size Attribute \"" + currentAttrName + "\" must "
                        + "contain a valid even integer value.";
                mLogger.debug("SSP: " + msgText);
                DetailedLogMessageCollection.getInstance()
                        .addMessage(new LogMessage(MessageType.FAILED, msgText));
            }

        }
    }
}

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.//w w w .  j  av  a 2  s.c  o m
 * 
 * @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.RulesValidator.java

/**
 * Retrieves the value of the desired attribute.
 *
 * @param iNode Node which contains the attributes.
 *
 * @param iAttribute Name of the attribute desired
 *
 * @return String: Value of the desired attribute
 *//*from  ww w.j  a v  a 2s.  co m*/
protected String getAttribute(Node iNode, String iAttribute) {
    String returnValue = "";

    // grab attributes of the node
    Attr attrs[] = sortAttributes(iNode.getAttributes());

    // now see if the asked for attribute exists and send
    // back the value
    Attr attribute;
    for (Attr attr : attrs) {
        attribute = attr;

        //if ( attribute.getName().equals( theAttribute ) )
        if (attribute.getLocalName().equals(iAttribute)) {
            returnValue = attribute.getValue();
            break;
        }
    }
    return returnValue;
}

From source file:org.adl.validator.sequence.SequenceValidator.java

/**
  * This method validates the attribute values based on the rules defined
  * in the SCORM Application Profile rules.
  */* w  w w .  j a  v  a 2s. c om*/
  * @param iNode element parent node of the attribute being validated
  * @param iNodeName Parent element node name
  * @param iPath path of the rule to compare to
  *
  * @return True if the value is a valid vocab token,
  * false otherwise.
  *
  */
public boolean checkAttributes(Node iNode, String iNodeName, String iPath) {
    String dataType = null;
    boolean result = true;
    String msgText = "";
    int multiplicityUsed = -1;

    NamedNodeMap attrList = iNode.getAttributes();
    int numAttr = attrList.getLength();
    log.debug("There are " + numAttr + " attributes of " + iNodeName + " to test");

    // SPECIAL CASE: check for mandatory/shall not exist attributes on
    // sequencingCollection child elements

    if (iNodeName.equalsIgnoreCase("sequencing") && iPath.equals("sequencingCollection")) {

        multiplicityUsed = getMultiplicityUsed(attrList, "ID");

        msgText = Messages.getString("SequenceValidator.145");
        log.debug("INFO: " + msgText);
        DetailedLogMessageCollection.getInstance().addMessage(new LogMessage(MessageType.INFO, msgText));

        if (multiplicityUsed < 1) {

            msgText = Messages.getString("SequenceValidator.147");
            log.debug("FAILED: " + msgText);
            DetailedLogMessageCollection.getInstance().addMessage(new LogMessage(MessageType.FAILED, msgText));

            result = false;

        } else {
            msgText = Messages.getString("SequenceValidator.149");

            log.debug("PASSED: " + msgText);
            DetailedLogMessageCollection.getInstance().addMessage(new LogMessage(MessageType.PASSED, msgText));
            result = true && result;
        }

        // IDRef is not allowed to be present
        multiplicityUsed = getMultiplicityUsed(attrList, "IDRef");
        if (multiplicityUsed >= 1) {
            msgText = Messages.getString("SequenceValidator.152");
            log.debug("FAILED: " + msgText);
            DetailedLogMessageCollection.getInstance().addMessage(new LogMessage(MessageType.FAILED, msgText));
            result = false;
        }

    }

    Attr currentAttrNode;
    String currentNodeName;
    String attributeValue = null;
    int minRule = -1;
    int maxRule = -1;
    int spmRule = -1;

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

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

        // make sure that this is a SCORM recognized attribute
        if (!dataType.equalsIgnoreCase("-1")) {
            msgText = Messages.getString("SequenceValidator.156", currentNodeName);
            log.debug("INFO: " + msgText);
            DetailedLogMessageCollection.getInstance().addMessage(new LogMessage(MessageType.INFO, msgText));

            // check for multiplicity if the attribute is not deprecated
            if (!dataType.equalsIgnoreCase("deprecated")) {
                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(iNodeName, iPath, "min", currentNodeName));
                //get the max rule and convert to an int
                maxRule = Integer
                        .parseInt(mRulesValidator.getRuleValue(iNodeName, iPath, "max", currentNodeName));

                if ((minRule != -1) || (maxRule != -1)) {
                    if (multiplicityUsed >= minRule && multiplicityUsed <= maxRule) {
                        msgText = Messages.getString("SequenceValidator.162", currentNodeName);
                        log.debug("PASSED: " + msgText);
                        DetailedLogMessageCollection.getInstance()
                                .addMessage(new LogMessage(MessageType.PASSED, msgText));
                    } else {
                        msgText = Messages.getString("SequenceValidator.165", currentNodeName);
                        log.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(iNodeName, iPath, "spm", currentNodeName));

                attributeValue = currentAttrNode.getValue();
            }

            // check the contents of the attribute
            if (dataType.equalsIgnoreCase("idref")) {
                // This is a IDREF data type
            } else if (dataType.equalsIgnoreCase("id")) {
                // This is a ID data type
            } 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 = Messages.getString("SequenceValidator.172", currentNodeName);
                log.debug("INFO: " + msgText);
                DetailedLogMessageCollection.getInstance()
                        .addMessage(new LogMessage(MessageType.INFO, msgText));

                List<String> vocabAttribValues = mRulesValidator.getAttribVocabRuleValues(iNodeName, 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("deprecated")) {
                // This is a deprecated attribute
                msgText = Messages.getString("SequenceValidator.176", currentNodeName);
                log.debug("FAILED: " + msgText);
                DetailedLogMessageCollection.getInstance()
                        .addMessage(new LogMessage(MessageType.FAILED, msgText));
                result = false;
            } 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;
                // we have to store the referencedObjective attribute to
                // validate that it references a primary or objective identifier
                if (currentNodeName.equals("referencedObjective")) {
                    mReferencedObjectiveList.add(attributeValue);
                }
            } else if (dataType.equalsIgnoreCase("boolean")) {
                //This is a BOOLEAN data type
            } else if (dataType.equalsIgnoreCase("decimal")) {
                //This is a DECIMAL data type
            } else if (dataType.equalsIgnoreCase("integer")) {
                //This is a INTEGER data type
            } else if (dataType.equalsIgnoreCase("duration") || dataType.equalsIgnoreCase("dateTime")) {
                msgText = Messages.getString("SequenceValidator.185", currentNodeName);
                log.debug("INFO: " + msgText);
                DetailedLogMessageCollection.getInstance()
                        .addMessage(new LogMessage(MessageType.INFO, msgText));
                // We can assume that the schema validation has validated
                // the format.
                msgText = Messages.getString("SequenceValidator.188", currentNodeName);
                log.debug("PASSED: " + msgText);
                DetailedLogMessageCollection.getInstance()
                        .addMessage(new LogMessage(MessageType.PASSED, msgText));

                if (currentNodeName.equals("attemptExperiencedDurationLimit")
                        || currentNodeName.equals("activityAbsoluteDurationLimit")
                        || currentNodeName.equals("activityExperiencedDurationLimit")
                        || currentNodeName.equals("beginTimeLimit") || currentNodeName.equals("endTimeLimit")) {

                    // this attribute is out of scope of SCORM
                    msgText = Messages.getString("SequenceValidator.196", currentNodeName);
                    log.warn("WARNING: " + msgText);
                    DetailedLogMessageCollection.getInstance()
                            .addMessage(new LogMessage(MessageType.WARNING, msgText));

                }
            } else {
                // it is an extension element
            }
        }
    }
    return result;
}