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.parsers.dom.DOMTreeUtility.java

/**
 * This method returns the desired node which is determined by the
 * provided node name and namespace./*from w ww .  ja v a2 s. c o m*/
 *
 * @param iNode The provided node structure to be traversed.
 * @param iNodeName The name of the node being searched for.
 *
 * @return Returns the desired node.
 */
public static Node getNode(Node iNode, String iNodeName) {
    log.debug("DOMTreeUtility getNode()");
    Node result = null;

    if (iNode != null) {
        log.debug("Parent Node: " + iNode.getLocalName());
        log.debug("Node being searched for: " + iNodeName);

        // Get the children of the current node
        NodeList children = iNode.getChildNodes();

        // If there are children, loop through the children nodes looking
        // for the appropriate node
        if (children != null) {
            for (int i = 0; i < children.getLength(); i++) {
                // Get the child node
                Node currentChild = children.item(i);

                // Get the current child node's local name
                String currentChildName = currentChild.getLocalName();
                log.debug("Child #" + i + ": " + currentChildName);

                if (currentChildName != null) {
                    // Determine if the current child node is the one that
                    // is being looked for
                    if (currentChildName.equalsIgnoreCase(iNodeName)) {
                        result = currentChild;
                        break;
                    }
                }
            } // end looping of children
        }
    }

    // return the resulting vector of nodes
    return result;
}

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

/**
 * This method returns an ordered list containing the desired nodes which is
 * determined by the provided node name and namespace.
 *
 * @param iNode The provided node structure to be traversed.
 * @param iNodeName The name of the node being searched for.
 *
 * @return Returns an ordered list containing the desired nodes.
 *//*from  ww  w .  jav a2 s  . c o  m*/
public static List<Node> getNodes(Node iNode, String iNodeName) {
    log.debug("DOMTreeUtility getNodes()");
    // Create a vector to hold the results of the method
    List<Node> result = new ArrayList<Node>();

    // Check to see if the input node is null
    if (iNode != null) {
        log.debug("Parent Node: " + iNode.getLocalName());
        log.debug("Node being searched for: " + iNodeName);
        // Get the set of child nodes of the input node
        NodeList children = iNode.getChildNodes();

        // If there are children nodes loop through them looking for
        // the node matching the name and namespace
        if (children != null) {
            int numChildren = children.getLength();

            // Loop over the children searching for the desired node
            for (int i = 0; i < numChildren; i++) {
                // get the current child in the list
                Node currentChild = children.item(i);

                // Get the local name of the child node
                String currentChildName = currentChild.getLocalName();

                if (currentChildName != null) {
                    // Determine if the current child node is the one that
                    // is being looked for
                    if (currentChildName.equalsIgnoreCase(iNodeName)) {
                        result.add(currentChild);
                    }
                }
            }
        }
    }
    return result;
}

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

/**
 * This method determins if a node in the DOM Tree <code>(iNode)</code> is
 * the node we are looking for.  This is done by comparing the node's
 * local name and namespace with a given node name <code>(iNodeName)</code>
 * and namespace <code>(iNamespace)</code>.
 *
 * @param iNode The Node we are trying to determine if it is the correct
 *              node/*from w  w w .j  a v a2s.c  om*/
 * @param iNodeName The name of the node we are looking for.
 * @param iNamespace The namespace of the node we are looking for.
 *
 * @return A boolean value indicating whether or not this is the
 *         correct node we are looking for
 */
public static boolean isAppropriateElement(Node iNode, String iNodeName, String iNamespace) {
    log.debug("DOMTreeUtility isAppropriateElement()");
    log.debug("Input Parent Node: " + iNode.getLocalName());
    log.debug("Input Node being searched for: " + iNodeName);
    log.debug("Input Namespace of node being searched for: " + iNamespace);

    boolean result = false;

    if (iNode.getNodeType() == Node.ATTRIBUTE_NODE) {
        if (iNode.getNamespaceURI() == null) {
            // Attribute has been passed in and its namepsace is null, get the
            // attributes parent's namespace
            String parentsNamespace = ((Attr) iNode).getOwnerElement().getNamespaceURI();
            if ((iNode.getLocalName().equals(iNodeName)) && (parentsNamespace.equals(iNamespace))) {
                result = true;
            }
        } else {
            if ((iNode.getLocalName().equals(iNodeName)) && (iNode.getNamespaceURI().equals(iNamespace))) {
                result = true;
            }
        }
    } else if ((iNode.getLocalName().equals(iNodeName)) && (iNode.getNamespaceURI().equals(iNamespace))) {
        result = true;
    }

    return result;
}

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

/**
 * This method determines whether or not the current node is a SCORM
 * Application Profile node.  The parent node is needed for cases where the
 * current node is an attribute node//  w  ww . j  a va 2 s.  c  om
 * 
 * @param iCurrentNode The current node being processed
 * @param iParentNode The parent of the current node being processed
 * @return Returns whether or not (true/false) the current node is a SCORM
 * application profile node
 */
public static boolean isSCORMAppProfileNode(Node iCurrentNode, Node iParentNode) {
    log.debug("DOMTreeUtility isSCORMAppProfileNode");
    log.debug("Input Current Node: " + iCurrentNode.getLocalName());
    log.debug("Input Parent Node: " + iParentNode.getLocalName());

    boolean result = false;

    // If the current node is from one of the known SCORM testable
    // namespaces then return true
    String namespace = iCurrentNode.getNamespaceURI();

    if (namespace == null) {
        String parentsNamespace = StringUtils.trimToEmpty(iParentNode.getNamespaceURI());

        // Check the parent nodes namespace
        if ((parentsNamespace.equals(ADLCP_NAMESPACE)) || (parentsNamespace.equals(IMSCP_NAMESPACE))
                || (parentsNamespace.equals(ADLNAV_NAMESPACE)) || (parentsNamespace.equals(IEEE_LOM_NAMESPACE))
                || (parentsNamespace.equals(ADLSEQ_NAMESPACE))
                || (parentsNamespace.equals("http://www.w3.org/XML/1998/namespace"))
                || (parentsNamespace.equals("http://www.w3.org/2001/XMLSchema-instance"))
                || (parentsNamespace.equals("http://www.w3.org/2000/xmlns/"))
                || (parentsNamespace.equals(IMSSSP_NAMESPACE)) || (parentsNamespace.equals(IMSSS_NAMESPACE))) {
            result = true;
        }
    } else if ((namespace.equals(ADLCP_NAMESPACE)) || (namespace.equals(IMSCP_NAMESPACE))
            || (namespace.equals(IEEE_LOM_NAMESPACE)) || (namespace.equals(ADLNAV_NAMESPACE))
            || (namespace.equals(ADLSEQ_NAMESPACE))
            || (namespace.equals("http://www.w3.org/XML/1998/namespace"))
            || (namespace.equals("http://www.w3.org/2001/XMLSchema-instance"))
            || (namespace.equals("http://www.w3.org/2000/xmlns/")) || (namespace.equals(IMSSSP_NAMESPACE))
            || (namespace.equals(IMSSS_NAMESPACE))) {
        result = true;
    }

    return result;
}

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

/**
 * Initializes one activity (<code>SeqActivity</code>) that will be added to
 * an activity tree.//from  www .j  a  v  a2s  .com
 * 
 * @param iNode   A node from the DOM tree of an element containing
 *                sequencing information.
 * 
 * @param iColl   The collection of reusable sequencing information.
 * 
 * @return An initialized activity (<code>SeqActivity</code>), or <code>
 *         null</code> if there was an error initializing the activity.
 */
private static SeqActivity buildActivityNode(Node iNode, Node iColl) {

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

    SeqActivity act = new SeqActivity();

    boolean error = false;

    String tempVal = null;

    // Set the activity's ID -- this is a required attribute
    act.setID(ADLSeqUtilities.getAttribute(iNode, "identifier"));

    // Get the activity's resource ID -- if it exsits
    tempVal = ADLSeqUtilities.getAttribute(iNode, "identifierref");
    if (tempVal != null) {
        if (!isEmpty(tempVal)) {
            act.setResourceID(tempVal);
        }
    }

    // Check if the activity is visible
    tempVal = ADLSeqUtilities.getAttribute(iNode, "isvisible");
    if (tempVal != null) {
        if (!isEmpty(tempVal)) {
            act.setIsVisible((Boolean.valueOf(tempVal)).booleanValue());
        }
    }

    // Get the children elements of this activity 
    NodeList children = iNode.getChildNodes();

    // Initalize this activity from the information in the DOM  
    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("item")) {

                if (_Debug) {
                    System.out.println("  ::--> Found an <item> element");
                }

                // Initialize the nested activity
                SeqActivity nestedAct = ADLSeqUtilities.buildActivityNode(curNode, iColl);

                // Make sure this activity was created successfully
                if (nestedAct != null) {
                    if (_Debug) {
                        System.out.println("  ::--> Adding child");
                    }

                    act.addChild(nestedAct);

                } else {
                    error = true;
                }
            } else if (curNode.getLocalName().equals("title")) {

                if (_Debug) {
                    System.out.println("  ::--> Found the <title> element");
                }

                act.setTitle(ADLSeqUtilities.getElementText(curNode, null));
            } else if (curNode.getLocalName().equals("sequencing")) {

                if (_Debug) {
                    System.out.println("  ::--> Found the <sequencing> element");
                }

                Node seqInfo = curNode;

                // Check to see if the sequencing information is referenced in 
                // the <sequencingCollection>
                tempVal = ADLSeqUtilities.getAttribute(curNode, "IDRef");
                if (tempVal != null) {
                    // Combine local and global sequencing information
                    // Get the referenced Global sequencing information
                    String search = "imsss:sequencing[@ID='" + tempVal + "']";

                    if (_Debug) {
                        System.out.println("  ::--> Looking for XPATH --> " + search);
                    }

                    // Use the referenced set of sequencing information
                    Node seqGlobal = null;

                    XPathFactory pathFactory = XPathFactory.newInstance();
                    XPath path = pathFactory.newXPath();

                    try {
                        seqGlobal = (Node) path.evaluate(search, iColl, XPathConstants.NODE);
                        //XPathAPI.selectSingleNode(iColl, search);
                    } catch (Exception e) {
                        if (_Debug) {
                            System.out.println("  ::--> ERROR : In transform");
                            e.printStackTrace();
                        }
                    }

                    if (seqGlobal != null) {
                        if (_Debug) {
                            System.out.println("  ::--> FOUND");
                        }
                    } else {
                        if (_Debug) {
                            System.out.println("  ::--> ERROR: Not Found");
                        }

                        seqInfo = null;
                        error = true;
                    }

                    if (!error) {

                        // Clone the global node
                        seqInfo = seqGlobal.cloneNode(true);

                        // Loop through the local sequencing element
                        NodeList seqChildren = curNode.getChildNodes();
                        for (int j = 0; j < seqChildren.getLength(); j++) {

                            Node curChild = seqChildren.item(j);

                            // Check to see if this is an element node.
                            if (curChild.getNodeType() == Node.ELEMENT_NODE) {
                                if (_Debug) {
                                    System.out.println("  ::--> Local definition");
                                    System.out.println("  ::-->   " + j);
                                    System.out.println("  ::-->  <" + curChild.getLocalName() + ">");
                                }

                                // Add this to the global sequencing info
                                try {
                                    seqInfo.appendChild(curChild);
                                } catch (org.w3c.dom.DOMException e) {
                                    if (_Debug) {
                                        System.out.println("  ::--> ERROR: ");
                                        e.printStackTrace();
                                    }

                                    error = true;
                                    seqInfo = null;
                                }
                            }
                        }
                    }
                }

                // If we have an node to look at, extract its sequencing info
                if (seqInfo != null) {
                    // Record this activity's sequencing XML fragment
                    //                  XMLSerializer serializer = new XMLSerializer();

                    // -+- TODO -+-
                    //                  serializer.setNewLine("CR-LF");
                    //                  act.setXMLFragment(serializer.writeToString(seqInfo));

                    // Extract the sequencing information for this activity
                    error = !ADLSeqUtilities.extractSeqInfo(seqInfo, act);

                    if (_Debug) {
                        System.out.println("  ::--> Extracted Sequencing Info");
                    }
                }
            }
        }
    }

    // Make sure this activity either has an associated resource or children
    if (act.getResourceID() == null && !act.hasChildren(true)) {
        // This is not a vaild activity -- ignore it
        error = true;
    }

    // If the activity failed to initialize, clear the variable
    if (error) {
        act = null;
    }

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

    return act;
}

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

/**
 * Extracts the contents of the IMS SS <code>&lt;sequencing&gt;</code> 
 * element and initializes the associated activity.
 * /*from   www. j a  va  2s  .  co m*/
 * @param iNode The DOM node associated with the IMS SS 
 *        <code>&lt;sequencing&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 extractSeqInfo(Node iNode, SeqActivity ioAct) {
    if (_Debug) {
        System.out.println("  :: ADLSeqUtilities  --> BEGIN - " + "extractSeqInfo");
    }

    boolean ok = true;
    String tempVal = null;

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

    // Initalize this activity's sequencing information  
    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("controlMode")) {

                if (_Debug) {
                    System.out.println("  ::--> Found the <controlMode> element");
                }

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

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

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

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

                // Look for 'useCurrentAttemptObjectiveInfo'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "useCurrentAttemptObjectiveInfo");

                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        ioAct.setUseCurObjective((Boolean.valueOf(tempVal)).booleanValue());
                    }
                }

                // Look for 'useCurrentAttemptProgressInfo'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "useCurrentAttemptProgressInfo");

                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        ioAct.setUseCurProgress((Boolean.valueOf(tempVal)).booleanValue());
                    }
                }
            } else if (curNode.getLocalName().equals("sequencingRules")) {

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

                ok = ADLSeqUtilities.getSequencingRules(curNode, ioAct);
            } else if (curNode.getLocalName().equals("limitConditions")) {

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

                // Look for 'attemptLimit'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "attemptLimit");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        ioAct.setAttemptLimit(Long.valueOf(tempVal));
                    }
                }

                // Look for 'attemptAbsoluteDurationLimit'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "attemptAbsoluteDurationLimit");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        ioAct.setAttemptAbDur(tempVal);
                    }
                }

                // Look for 'attemptExperiencedDurationLimit'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "attemptExperiencedDurationLimit");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        ioAct.setAttemptExDur(tempVal);
                    }
                }

                // Look for 'activityAbsoluteDurationLimit'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "activityAbsoluteDurationLimit");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        ioAct.setActivityAbDur(tempVal);
                    }
                }

                // Look for 'activityExperiencedDurationLimit'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "activityExperiencedDurationLimit");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        ioAct.setActivityExDur(tempVal);
                    }
                }

                // Look for 'beginTimeLimit'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "beginTimeLimit");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        ioAct.setBeginTimeLimit(tempVal);
                    }
                }

                // Look for 'endTimeLimit'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "endTimeLimit");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        ioAct.setEndTimeLimit(tempVal);
                    }
                }
            } else if (curNode.getLocalName().equals("auxiliaryResources")) {

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

                ok = ADLSeqUtilities.getAuxResources(curNode, ioAct);
            } else if (curNode.getLocalName().equals("rollupRules")) {

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

                ok = ADLSeqUtilities.getRollupRules(curNode, ioAct);

            } else if (curNode.getLocalName().equals("objectives")) {

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

                ok = ADLSeqUtilities.getObjectives(curNode, ioAct);

            } else if (curNode.getLocalName().equals("randomizationControls")) {

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

                // Look for 'randomizationTiming'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "randomizationTiming");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        ioAct.setRandomTiming(tempVal);
                    }
                }

                // Look for 'selectCount'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "selectCount");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        ioAct.setSelectCount((Integer.valueOf(tempVal)).intValue());
                    }
                }

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

                // Look for 'selectionTiming'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "selectionTiming");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        ioAct.setSelectionTiming(tempVal);
                    }
                }
            } else if (curNode.getLocalName().equals("deliveryControls")) {

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

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

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

                // Look for 'objectiveSetByContent'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "objectiveSetByContent");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        ioAct.setSetObjective((Boolean.valueOf(tempVal)).booleanValue());
                    }
                }
            } else if (curNode.getLocalName().equals("constrainedChoiceConsiderations")) {

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

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

                // Look for 'constrainChoice'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "constrainChoice");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        ioAct.setConstrainChoice((Boolean.valueOf(tempVal)).booleanValue());
                    }
                }
            } else if (curNode.getLocalName().equals("rollupConsiderations")) {

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

                // Look for 'requiredForSatisfied'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "requiredForSatisfied");

                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        ioAct.setRequiredForSatisfied(tempVal);
                    }
                }

                // Look for 'requiredForNotSatisfied'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "requiredForNotSatisfied");

                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        ioAct.setRequiredForNotSatisfied(tempVal);
                    }
                }

                // Look for 'requiredForCompleted'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "requiredForCompleted");

                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        ioAct.setRequiredForCompleted(tempVal);
                    }
                }

                // Look for 'requiredForIncomplete'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "requiredForIncomplete");

                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        ioAct.setRequiredForIncomplete(tempVal);
                    }
                }

                // Look for 'measureSatisfactionIfActive'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "measureSatisfactionIfActive");

                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        ioAct.setSatisfactionIfActive((Boolean.valueOf(tempVal)).booleanValue());
                    }
                }
            }
        }
    }

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

    return ok;
}

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

/**
 * Extracts the conditions assoicated with a sequencing rule.
 * /*  w w w  . j a  v a2 s. co m*/
 * @param iNode  The DOM node associated with one of the IMS SS <code>
 *               &lt;ruleConditions&gt;</code> element.
 * 
 * @return The condition set (<code>SeqConditionSet</code>) assoicated with
 *         the rule.
 */
private static SeqConditionSet extractSeqRuleConditions(Node iNode) {

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

    String tempVal = null;
    SeqConditionSet condSet = new SeqConditionSet();

    List<SeqCondition> conditions = new ArrayList<SeqCondition>();

    // Look for 'conditionCombination'
    tempVal = ADLSeqUtilities.getAttribute(iNode, "conditionCombination");
    if (tempVal != null) {
        if (!isEmpty(tempVal)) {
            condSet.mCombination = tempVal;
        }
    } else {
        // Enforce Default
        condSet.mCombination = SeqConditionSet.COMBINATION_ALL;
    }

    NodeList condInfo = iNode.getChildNodes();

    for (int i = 0; i < condInfo.getLength(); i++) {

        Node curCond = condInfo.item(i);

        // Check to see if this is an element node.
        if (curCond.getNodeType() == Node.ELEMENT_NODE) {

            if (curCond.getLocalName().equals("ruleCondition")) {

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

                SeqCondition cond = new SeqCondition();

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

                // Look for 'referencedObjective'
                tempVal = ADLSeqUtilities.getAttribute(curCond, "referencedObjective");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        cond.mObjID = tempVal;
                    }
                }

                // Look for 'measureThreshold'
                tempVal = ADLSeqUtilities.getAttribute(curCond, "measureThreshold");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        cond.mThreshold = (new Double(tempVal)).doubleValue();
                    }
                }

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

                conditions.add(cond);
            }
        }
    }

    if (conditions.size() > 0) {
        // Add the conditions to the condition set 
        condSet.mConditions = conditions;
    } else {
        condSet = null;
    }

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

    return condSet;
}

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

/**
 * Extracts the descriptions of auxiliary resoures associated with the       
 * activity from the activiy's associated element in the DOM.
 * //from  w  w  w  .j av a  2 s.  c o m
 * @param iNode The DOM node associated with the IMS SS <code>
 *              &lt;dataMap&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 getAuxResources(Node iNode, SeqActivity ioAct) {

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

    boolean ok = true;
    String tempVal = null;

    // List of auxiliary resources
    List<ADLAuxiliaryResource> auxRes = new ArrayList<ADLAuxiliaryResource>();

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

    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("auxiliaryResource")) {
                // Build a new data mapping rule
                if (_Debug) {
                    System.out.println("  ::--> Found a <auxiliaryResource> " + "element");
                }

                ADLAuxiliaryResource res = new ADLAuxiliaryResource();

                // Get the resource's purpose
                tempVal = ADLSeqUtilities.getAttribute(curNode, "purpose");
                if (tempVal != null) {
                    res.mType = tempVal;
                }

                // Get the resource's ID
                tempVal = ADLSeqUtilities.getAttribute(curNode, "auxiliaryResourceID");
                if (tempVal != null) {
                    res.mResourceID = tempVal;
                }

                // Add this datamap to the list associated with this activity
                auxRes.add(res);
            }
        }
    }

    // Add the set of auxiliary resources to the activity
    ioAct.setAuxResources(auxRes);

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

    return ok;
}

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

/**
 * Attempts to find the indicated subelement of the current node and
 * extact its value.//from  ww  w  . java 2 s. co m
 *
 * @param iNode    The DOM node of the target element.
 *
 * @param iElement The requested subelement.
 *
 * @return The value of the requested subelement of target element, or
 *         <code>null</code> if the subelement does not exist.
 */
private static String getElementText(Node iNode, String iElement) {

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

    StringBuilder value = new StringBuilder();
    Node curNode = null;
    NodeList children = null;

    if (iElement != null && iNode != null) {
        children = iNode.getChildNodes();

        // Locate the target subelement
        for (int i = 0; i < children.getLength(); i++) {
            curNode = children.item(i);

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

                if (curNode.getLocalName().equals(iElement)) {
                    if (_Debug) {
                        System.out.println("  ::--> Found <" + iElement + ">");
                    }

                    break;
                }
            }
        }

        if (curNode != null) {
            String comp = curNode.getLocalName();

            if (comp != null) {
                // Make sure we found the subelement
                if (!comp.equals(iElement)) {
                    curNode = null;
                }
            } else {
                curNode = null;
            }
        }
    } else {
        curNode = iNode;
    }

    if (curNode != null) {
        if (_Debug) {
            System.out.println("  ::--> Looking at children");
        }

        // Extract the element's text value.
        children = curNode.getChildNodes();

        // Cycle through all children of node to get the text
        if (children != null) {
            // There must be a value
            value = new StringBuilder();

            for (int i = 0; i < children.getLength(); i++) {
                curNode = children.item(i);

                // make sure we have a 'text' element
                if ((curNode.getNodeType() == Node.TEXT_NODE)
                        || (curNode.getNodeType() == Node.CDATA_SECTION_NODE)) {
                    value.append(curNode.getNodeValue());
                }
            }
        }
    }

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

    return value.toString();
}

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

/**
 * Extracts the objective maps associated with a specific objective from the
 * <code>&lt;objectives&gt;</code> element of the DOM.
 *
 * @param iNode The DOM node associated with an objective.=
 *
 * @return The set (<code>List</code>) of objective maps extracted
 *         successfully, otherwise <code>null</code>.
 *///  w  w w .ja v  a 2s  . c  o m
private static List<SeqObjectiveMap> getObjectiveMaps(Node iNode) {

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

    String tempVal = null;
    List<SeqObjectiveMap> maps = new ArrayList<SeqObjectiveMap>();

    // Get the children elements of this objective
    NodeList children = iNode.getChildNodes();

    // Initalize this objective's objective maps
    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("mapInfo")) {
                if (_Debug) {
                    System.out.println("  ::--> Found a <mapInfo> " + "element");
                }

                SeqObjectiveMap map = new SeqObjectiveMap();

                // Look for 'targetObjectiveID'
                tempVal = ADLSeqUtilities.getAttribute(curNode, "targetObjectiveID");
                if (tempVal != null) {
                    if (!isEmpty(tempVal)) {
                        map.mGlobalObjID = tempVal;
                    }
                }

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

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

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

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

                maps.add(map);
            }
        }
    }

    // Don't return an empty set.
    if (maps.size() == 0) {
        maps = null;
    }

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

    return maps;
}