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.validator.sequence.SequenceValidator.java

/**
 * This method validates the sequencingcollection, if it exists, against the
 * rules defined in the Sequence Application Profile.
 *
 * @param iSequencingcollectionNode  The sequencingCollection node
 *
 * @return Boolean describing if the sequencingCollection element is
 * value or not./*from   w  w  w. j  a  v a2  s. c om*/
 */
private boolean checkSequencingcollection(Node iSequencingcollectionNode) {
    boolean result = true;
    boolean foundSequencing = false;
    String msgText = "";

    // loop through children and call compare
    NodeList kids = iSequencingcollectionNode.getChildNodes();
    Node currentNode = null;

    //cycle through all children of node to find the <sequencing> nodes
    if (kids != null) {
        int n = kids.getLength();

        for (int i = 0; i < n - 1; i++) {
            currentNode = kids.item(i);

            // find the <sequencing> nodes
            if (currentNode.getLocalName().equals("sequencing")) {
                foundSequencing = true;
                // validate to the application profiles
                result = compareToRules(currentNode, "sequencingCollection") && result;
            }
        }
    }
    if (!foundSequencing) {
        //report an error for not having mandatory sequencing children
        result = false;
        msgText = Messages.getString("SequenceValidator.15");
        log.debug("FAILED: " + msgText);
        DetailedLogMessageCollection.getInstance().addMessage(new LogMessage(MessageType.FAILED, msgText));
    }
    return result;
}

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

/**
 * A recursive method that is driven by the test subject dom.
 * This method performs the application profiles rules checks.
 *
 * @param iTestSubjectNode Test Subject DOM
 * @param iPath Path of the rule to compare to
 *
 * @return - Boolean result of the checks performed
 *
 *///  w ww .  ja  v a 2s.  com
private boolean compareToRules(Node iTestSubjectNode, String iPath) {
    // looks exactly like prunetree as we walk down the tree
    log.debug("compareToRules");

    boolean result = true;
    String msgText = "";

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

    int type = iTestSubjectNode.getNodeType();

    switch (type) {
    // element with attributes
    case Node.ELEMENT_NODE: {
        String parentNodeName = iTestSubjectNode.getLocalName();

        result = checkAttributes(iTestSubjectNode, parentNodeName, iPath) && result;

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

        // 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("") || parentNodeName.equalsIgnoreCase("sequencing")) {
                // the Node is a DOCUMENT OR
                // the Node is a <manifest>

                path = parentNodeName;
            } else {
                path = iPath + "." + parentNodeName;
            }

            // SPECIAL CASE: check for mandatory elements
            // there are currently no mandatory elements

            for (int z = 0; z < numChildren; z++) {
                Node currentChild = children.item(z);
                String currentChildName = currentChild.getLocalName();

                // must enforce that the adlseq namespaced elements exist
                // as a child of sequencing only.
                if (((currentChildName.equals("constrainedChoiceConsiderations"))
                        || (currentChildName.equals("rollupConsiderations")))
                        && (!parentNodeName.equals("sequencing"))) {

                    result = false;

                    msgText = Messages.getString("SequenceValidator.8", currentChildName, "sequencing");

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

                dataType = mRulesValidator.getRuleValue(currentChildName, path, "datatype");

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

                    // check for multiplicity if the element is not deprecated
                    if (!dataType.equalsIgnoreCase("deprecated")) {
                        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("SequenceValidator.36", currentChildName);
                                log.debug("PASSED: " + msgText);
                                DetailedLogMessageCollection.getInstance()
                                        .addMessage(new LogMessage(MessageType.PASSED, msgText));
                            } else {
                                msgText = Messages.getString("SequenceValidator.39", currentChildName);
                                log.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("SequenceValidator.36", currentChildName);
                                log.debug("PASSED: " + msgText);
                                DetailedLogMessageCollection.getInstance()
                                        .addMessage(new LogMessage(MessageType.PASSED, msgText));
                            } else {
                                msgText = Messages.getString("SequenceValidator.39", currentChildName);
                                log.debug("FAILED: " + msgText);
                                DetailedLogMessageCollection.getInstance()
                                        .addMessage(new LogMessage(MessageType.FAILED, msgText));
                                result = false;
                            }
                        }
                    }

                    // check the contents of the attribute
                    if (dataType.equalsIgnoreCase("parent")) {
                        //This is a parent element

                        // special validation for sequencingCollection
                        if (currentChildName.equals("sequencingCollection") && iPath.equals("")) {

                            result = checkSequencingcollection(currentChild) && result;
                        }

                        if (currentChildName.equals("objectives")) {
                            // we must enforce that objectiveIDs must be unique
                            // for a given activity only.
                            result = checkObjectiveIDsForUniqueness(currentChild) && result;
                        }

                        // objectiveID is mandatory for primaryObjective 
                        // only if it contains a mapInfo as a child
                        if (currentChildName.equals("primaryObjective")) {
                            // Test the child Nodes
                            NodeList objChildren = currentChild.getChildNodes();

                            boolean isObjectiveIDMandatory = false;
                            for (int i = 0; i < objChildren.getLength(); i++) {
                                Node objChild = objChildren.item(i);
                                String objChildName = objChild.getLocalName();

                                if (objChildName.equals("mapInfo")) {
                                    isObjectiveIDMandatory = true;
                                }
                            }

                            if (isObjectiveIDMandatory) {
                                // ObjectiveID attribute is mandatory if mapInfo
                                // child elements are present.
                                Attr currAttribute = DOMTreeUtility.getAttribute(currentChild, "objectiveID");

                                if (currAttribute == null) {
                                    result = result && false;
                                    msgText = Messages.getString("SequenceValidator.55");

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

                                }
                            }

                        }

                        // special validation for global objectives
                        if (currentChildName.equals("objectives") && path.equals("sequencing")) {
                            msgText = Messages.getString("SequenceValidator.59");
                            log.debug("INFO: " + msgText);
                            DetailedLogMessageCollection.getInstance()
                                    .addMessage(new LogMessage(MessageType.INFO, msgText));

                            mObjectiveInfo.populateObjectiveMap(currentChild);

                            result = mObjectiveInfo.validateObjectiveMaps(mObjectiveInfo) && result;
                        }

                        if (currentChildName.equals("auxiliaryResources") && path.equals("sequencing")) {
                            // this element is out of scope of SCORM
                            msgText = Messages.getString("SequenceValidator.63", currentChildName);
                            log.debug("WARNING: " + msgText);
                            DetailedLogMessageCollection.getInstance()
                                    .addMessage(new LogMessage(MessageType.WARNING, msgText));
                        }

                        result = compareToRules(currentChild, path) && result;

                    } else if (dataType.equalsIgnoreCase("deprecated")) {
                        // This is a deprecated element
                        msgText = Messages.getString("SequenceValidator.67", currentChildName);
                        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 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("SequenceValidator.73", currentChildName);
                        log.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;
                    }
                    if (dataType.equalsIgnoreCase("decimal")) {
                        //This is a decimal element
                    } else if (dataType.equalsIgnoreCase("leaf")) {
                        // This is a leaf data type, must check attributes
                        result = checkAttributes(currentChild, currentChildName, path) && result;
                    } else {
                        // This is an extension element
                        // no additional checks needed
                    }
                }
            }
        }
        break;
    }

    default: {
        break;
    }
    }

    log.debug("compareToRules()");

    return result;
}

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

/**
* This method is called to initiate the validation process.
* This method will trigger the parsing activity done by the 
* <code>ADLSCORMValidator</code>. Next, the DOM will be used to validate 
* the remaining checks required for full SCORM Validation.
*
* @param iRootNode Root sequence element.
*
* @return - Boolean value indicating the outcome of the validation checks.
*///from   w  w  w .j av a  2  s  . c  o m
public boolean validate(Node iRootNode) {
    boolean validateResult = true;
    String msgText;
    String nodeName = iRootNode.getLocalName();

    log.debug("validate()");

    log.debug("      iRootNodeName coming in is " + nodeName);

    mRulesValidator.readInRules("sequence");

    // check the parent and make sure it is in the right place
    String parentNodeName = iRootNode.getParentNode().getLocalName();

    if (nodeName.equals("sequencingCollection")) {
        if (!parentNodeName.equals("manifest")) {
            msgText = Messages.getString("SequenceValidator.8", "sequencingCollection", "manifest");
            log.debug("FAILED: " + msgText);
            DetailedLogMessageCollection.getInstance().addMessage(new LogMessage(MessageType.FAILED, msgText));
            validateResult = false;
        }

    }
    // check the <sequencing> element and its children
    validateResult = compareToRules(iRootNode, "") && validateResult;
    // continuation of the application profile check, must validate that the 
    // referencedObjective attribute references an objective 
    //attribute (primary / objective)
    validateResult = checkReferencedObjectives() && validateResult;

    log.debug("validate()");

    return validateResult;
}

From source file:org.alfresco.web.forms.xforms.Schema2XForms.java

/**
 * Generate the XForm based on a user supplied XML Schema.
 *
 * @param instanceDocument The document source for the XML Schema.
 * @param schemaDocument Schema document
 * @param rootElementName Name of the root element
 * @param resourceBundle Strings to use/*from   ww w.j  a  v a2 s .c o m*/
 * @return The Document containing the XForm.
 * @throws org.chiba.tools.schemabuilder.FormBuilderException
 *          If an error occurs building the XForm.
 */
public Pair<Document, XSModel> buildXForm(final Document instanceDocument, final Document schemaDocument,
        String rootElementName, final ResourceBundle resourceBundle) throws FormBuilderException {
    final XSModel schema = SchemaUtil.parseSchema(schemaDocument, true);
    this.typeTree = SchemaUtil.buildTypeTree(schema);

    //refCounter = 0;
    this.counter.clear();

    final Document xformsDocument = this.createFormTemplate(rootElementName);

    //find form element: last element created
    final Element formSection = (Element) xformsDocument.getDocumentElement().getLastChild();
    final Element modelSection = (Element) xformsDocument.getDocumentElement()
            .getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, "model").item(0);

    //add XMLSchema if we use schema types      
    final Element importedSchemaDocumentElement = (Element) xformsDocument
            .importNode(schemaDocument.getDocumentElement(), true);
    importedSchemaDocumentElement.setAttributeNS(null, "id", "schema-1");

    NodeList nl = importedSchemaDocumentElement.getChildNodes();
    boolean hasExternalSchema = false;

    for (int i = 0; i < nl.getLength(); i++) {
        Node current = nl.item(i);
        if (current.getNamespaceURI() != null
                && current.getNamespaceURI().equals(NamespaceConstants.XMLSCHEMA_NS)) {
            String localName = current.getLocalName();
            if (localName.equals("include") || localName.equals("import")) {
                hasExternalSchema = true;
                break;
            }
        }
    }

    // ALF-8105 / ETWOTWO-1384: Only embed the schema if it does not reference externals
    if (!hasExternalSchema) {
        modelSection.appendChild(importedSchemaDocumentElement);
    }

    //check if target namespace
    final StringList schemaNamespaces = schema.getNamespaces();
    final HashMap<String, String> schemaNamespacesMap = new HashMap<String, String>();
    if (schemaNamespaces.getLength() != 0) {
        // will return null if no target namespace was specified
        this.targetNamespace = schemaNamespaces.item(0);

        if (LOGGER.isDebugEnabled())
            LOGGER.debug("[buildXForm] using targetNamespace " + this.targetNamespace);

        for (int i = 0; i < schemaNamespaces.getLength(); i++) {
            if (schemaNamespaces.item(i) == null) {
                continue;
            }
            final String prefix = addNamespace(xformsDocument.getDocumentElement(),
                    schemaDocument.lookupPrefix(schemaNamespaces.item(i)), schemaNamespaces.item(i));
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("[buildXForm] adding namespace " + schemaNamespaces.item(i) + " with prefix "
                        + prefix + " to xform and default instance element");
            }
            schemaNamespacesMap.put(prefix, schemaNamespaces.item(i));
        }
    }

    //if target namespace & we use the schema types: add it to form ns declarations
    //   if (this.targetNamespace != null && this.targetNamespace.length() != 0)
    //       envelopeElement.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
    //                  "xmlns:schema",
    //                  this.targetNamespace);

    final XSElementDeclaration rootElementDecl = schema.getElementDeclaration(rootElementName,
            this.targetNamespace);
    if (rootElementDecl == null) {
        throw new FormBuilderException("Invalid root element tag name [" + rootElementName
                + ", targetNamespace = " + this.targetNamespace + "]");
    }

    rootElementName = this.getElementName(rootElementDecl, xformsDocument);
    final Element instanceElement = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
            NamespaceConstants.XFORMS_PREFIX + ":instance");
    modelSection.appendChild(instanceElement);
    this.setXFormsId(instanceElement);

    final Element defaultInstanceDocumentElement = xformsDocument.createElement(rootElementName);
    addNamespace(defaultInstanceDocumentElement, NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX,
            NamespaceConstants.XMLSCHEMA_INSTANCE_NS);
    if (this.targetNamespace != null) {
        final String targetNamespacePrefix = schemaDocument.lookupPrefix(this.targetNamespace);

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("[buildXForm] adding target namespace " + this.targetNamespace + " with prefix "
                    + targetNamespacePrefix + " to xform and default instance element");
        }

        addNamespace(defaultInstanceDocumentElement, targetNamespacePrefix, this.targetNamespace);
        addNamespace(xformsDocument.getDocumentElement(), targetNamespacePrefix, this.targetNamespace);
    }

    Element prototypeInstanceElement = null;
    if (instanceDocument == null || instanceDocument.getDocumentElement() == null) {
        instanceElement.appendChild(defaultInstanceDocumentElement);
    } else {
        Element instanceDocumentElement = instanceDocument.getDocumentElement();
        if (!instanceDocumentElement.getNodeName().equals(rootElementName)) {
            throw new IllegalArgumentException("instance document root tag name invalid.  " + "expected "
                    + rootElementName + ", got " + instanceDocumentElement.getNodeName());
        }

        if (LOGGER.isDebugEnabled())
            LOGGER.debug("[buildXForm] importing rootElement from other document");

        prototypeInstanceElement = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
                NamespaceConstants.XFORMS_PREFIX + ":instance");
        modelSection.appendChild(prototypeInstanceElement);
        this.setXFormsId(prototypeInstanceElement, "instance_prototype");
        prototypeInstanceElement.appendChild(defaultInstanceDocumentElement);
    }

    final Element rootGroup = this.addElement(xformsDocument, modelSection, defaultInstanceDocumentElement,
            formSection, schema, rootElementDecl, "/" + this.getElementName(rootElementDecl, xformsDocument),
            new SchemaUtil.Occurrence(1, 1), resourceBundle);
    if (rootGroup.getNodeName() != NamespaceConstants.XFORMS_PREFIX + ":group") {
        throw new FormBuilderException("Expected root form element to be a " + NamespaceConstants.XFORMS_PREFIX
                + ":group, not a " + rootGroup.getNodeName() + ".  Ensure that "
                + this.getElementName(rootElementDecl, xformsDocument)
                + " is a concrete type that has no extensions.  "
                + "Types with extensions are not supported for " + "the root element of a form.");
    }
    this.setXFormsId(rootGroup, "alfresco-xforms-root-group");

    if (prototypeInstanceElement != null) {
        Schema2XForms.rebuildInstance(prototypeInstanceElement, instanceDocument, instanceElement,
                schemaNamespacesMap);
    }

    this.createSubmitElements(xformsDocument, modelSection, rootGroup);
    this.createTriggersForRepeats(xformsDocument, rootGroup);

    final Comment comment = xformsDocument.createComment(
            "This XForm was generated by " + this.getClass().getName() + " on " + (new Date()) + " from the '"
                    + rootElementName + "' element of the '" + this.targetNamespace + "' XML Schema.");
    xformsDocument.getDocumentElement().insertBefore(comment,
            xformsDocument.getDocumentElement().getFirstChild());
    xformsDocument.normalizeDocument();

    if (LOGGER.isDebugEnabled())
        LOGGER.debug("[buildXForm] Returning XForm =\n" + XMLUtil.toString(xformsDocument));

    return new Pair<Document, XSModel>(xformsDocument, schema);
}

From source file:org.anhonesteffort.flock.webdav.caldav.CalDavStore.java

public static List<CalDavCollection> getCollectionsFromMultiStatusResponses(CalDavStore store,
        MultiStatusResponse[] msResponses) {
    List<CalDavCollection> collections = new LinkedList<CalDavCollection>();

    for (MultiStatusResponse msResponse : msResponses) {
        DavPropertySet foundProperties = msResponse.getProperties(DavServletResponse.SC_OK);
        String collectionUri = msResponse.getHref();

        for (Status status : msResponse.getStatus()) {
            if (status.getStatusCode() == DavServletResponse.SC_OK) {

                boolean isCalendarCollection = false;
                DavPropertySet collectionProperties = new DavPropertySet();

                DavProperty resourceTypeProperty = foundProperties.get(DavPropertyName.RESOURCETYPE);
                if (resourceTypeProperty != null) {

                    Object resourceTypeValue = resourceTypeProperty.getValue();
                    if (resourceTypeValue instanceof ArrayList) {
                        for (Node child : (ArrayList<Node>) resourceTypeValue) {
                            if (child instanceof Element) {
                                String localName = child.getLocalName();
                                if (localName != null) {
                                    isCalendarCollection = localName
                                            .equals(CalDavConstants.RESOURCE_TYPE_CALENDAR)
                                            || localName
                                                    .equals(CalDavConstants.RESOURCE_TYPE_CALENDAR_PROXY_READ)
                                            || localName
                                                    .equals(CalDavConstants.RESOURCE_TYPE_CALENDAR_PROXY_WRITE);
                                }/*from   w w w .  j av  a 2s  . com*/
                            }
                        }
                    }
                }

                if (isCalendarCollection) {
                    for (DavProperty property : foundProperties) {
                        if (property != null)
                            collectionProperties.add(property);
                    }
                    collections.add(new CalDavCollection(store, collectionUri, collectionProperties));
                }

            }
        }
    }

    return collections;
}

From source file:org.anhonesteffort.flock.webdav.carddav.CardDavStore.java

public static List<CardDavCollection> getCollectionsFromMultiStatusResponses(CardDavStore store,
        MultiStatusResponse[] msResponses) {
    List<CardDavCollection> collections = new LinkedList<CardDavCollection>();

    for (MultiStatusResponse msResponse : msResponses) {
        DavPropertySet foundProperties = msResponse.getProperties(DavServletResponse.SC_OK);
        String collectionUri = msResponse.getHref();

        for (Status status : msResponse.getStatus()) {
            if (status.getStatusCode() == DavServletResponse.SC_OK) {

                boolean isAddressbookCollection = false;
                DavPropertySet collectionProperties = new DavPropertySet();

                DavProperty resourceTypeProperty = foundProperties.get(DavPropertyName.RESOURCETYPE);
                if (resourceTypeProperty != null) {

                    Object resourceTypeValue = resourceTypeProperty.getValue();
                    if (resourceTypeValue instanceof ArrayList) {
                        for (Node child : (ArrayList<Node>) resourceTypeValue) {
                            if (child instanceof Element) {
                                String localName = child.getLocalName();
                                if (localName != null)
                                    isAddressbookCollection = localName
                                            .equals(CardDavConstants.RESOURCE_TYPE_ADDRESSBOOK);
                            }/*from  w  w w .  j  a  v  a  2s .co m*/
                        }
                    }
                }

                if (isAddressbookCollection) {
                    for (DavProperty property : foundProperties) {
                        if (property != null)
                            collectionProperties.add(property);
                    }
                    collections.add(new CardDavCollection(store, collectionUri, collectionProperties));
                }

            }
        }
    }

    return collections;
}

From source file:org.apache.axis.message.MessageElement.java

/**
 * @see org.w3c.dom.Element#getElementsByTagName(String)
 * @param tagName tag to look for.//from  w w w  . j a va  2 s .com
 * @return a list of elements
 */
public NodeList getElementsByTagName(String tagName) {
    NodeListImpl nodelist = new NodeListImpl();
    for (int i = 0; children != null && i < children.size(); i++) {
        if (children.get(i) instanceof Node) {
            Node el = (Node) children.get(i);
            if (el.getLocalName() != null && el.getLocalName().equals(tagName))
                nodelist.addNode(el);
            if (el instanceof Element) {
                NodeList grandchildren = ((Element) el).getElementsByTagName(tagName);
                for (int j = 0; j < grandchildren.getLength(); j++) {
                    nodelist.addNode(grandchildren.item(j));
                }
            }
        }
    }
    return nodelist;
}

From source file:org.apache.axis.message.MessageElement.java

/**
 * recursive copy/*w ww.j  a v  a 2 s  .c om*/
 * @param dest element to copy into
 * @param source child element
 */
private void copyNode(MessageElement dest, org.w3c.dom.Node source) {
    dest.setPrefix(source.getPrefix());
    if (source.getLocalName() != null) {
        dest.setQName(new QName(source.getNamespaceURI(), source.getLocalName()));
    } else {
        dest.setQName(new QName(source.getNamespaceURI(), source.getNodeName()));
    }

    NamedNodeMap attrs = source.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Node att = attrs.item(i);
        if (att.getNamespaceURI() != null && att.getPrefix() != null
                && att.getNamespaceURI().equals(Constants.NS_URI_XMLNS) && "xmlns".equals(att.getPrefix())) {
            Mapping map = new Mapping(att.getNodeValue(), att.getLocalName());
            dest.addMapping(map);
        }
        if (att.getLocalName() != null) {
            dest.addAttribute(att.getPrefix(), (att.getNamespaceURI() != null ? att.getNamespaceURI() : ""),
                    att.getLocalName(), att.getNodeValue());
        } else if (att.getNodeName() != null) {
            dest.addAttribute(att.getPrefix(), (att.getNamespaceURI() != null ? att.getNamespaceURI() : ""),
                    att.getNodeName(), att.getNodeValue());
        }
    }

    NodeList children = source.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child.getNodeType() == TEXT_NODE || child.getNodeType() == CDATA_SECTION_NODE
                || child.getNodeType() == COMMENT_NODE) {
            org.apache.axis.message.Text childElement = new org.apache.axis.message.Text((CharacterData) child);
            dest.appendChild(childElement);
        } else {
            MessageElement childElement = new MessageElement();
            dest.appendChild(childElement);
            copyNode(childElement, child);
        }
    }
}

From source file:org.apache.axis.wsdl.fromJava.Types.java

/**
 * Load the types from the input wsdl file.
 *
 * @param inputWSDL file or URL//from ww w.ja v  a  2 s .  c o  m
 * @throws IOException
 * @throws WSDLException
 * @throws SAXException
 * @throws ParserConfigurationException
 */
public void loadInputTypes(String inputWSDL)
        throws IOException, WSDLException, SAXException, ParserConfigurationException {

    // Read the input wsdl file into a Document
    Document doc = XMLUtils.newDocument(inputWSDL);

    // Search for the 'types' element
    NodeList elements = doc.getChildNodes();

    if ((elements.getLength() > 0) && elements.item(0).getLocalName().equals("definitions")) {
        elements = elements.item(0).getChildNodes();

        for (int i = 0; (i < elements.getLength()) && (wsdlTypesElem == null); i++) {
            Node node = elements.item(i);

            if ((node.getLocalName() != null) && node.getLocalName().equals("types")) {
                wsdlTypesElem = (Element) node;
            }
        }
    }

    // If types element not found, there is no need to continue.
    if (wsdlTypesElem == null) {
        return;
    }

    // Import the types element into the Types docHolder document
    wsdlTypesElem = (Element) docHolder.importNode(wsdlTypesElem, true);

    docHolder.appendChild(wsdlTypesElem);

    // Create a symbol table and populate it with the input wsdl document
    BaseTypeMapping btm = new BaseTypeMapping() {

        public String getBaseName(QName qNameIn) {

            QName qName = new QName(qNameIn.getNamespaceURI(), qNameIn.getLocalPart());
            Class cls = tm.getClassForQName(qName);

            if (cls == null) {
                return null;
            } else {
                return JavaUtils.getTextClassName(cls.getName());
            }
        }
    };
    SymbolTable symbolTable = new SymbolTable(btm, true, false, false);

    symbolTable.populate(null, doc);
    processSymTabEntries(symbolTable);
}

From source file:org.apache.axis.wsdl.toJava.Utils.java

/**
* Determines if the DOM Node represents an xs:<node>
*//*w  w w.j  av a  2 s. com*/
public static boolean isXsNode(Node node, String nameName) {
    return (node.getLocalName().equals(nameName) && Constants.isSchemaXSD(node.getNamespaceURI()));
}