Example usage for com.google.gwt.xml.client Document createComment

List of usage examples for com.google.gwt.xml.client Document createComment

Introduction

In this page you can find the example usage for com.google.gwt.xml.client Document createComment.

Prototype

Comment createComment(String data);

Source Link

Document

This method creates a new Comment.

Usage

From source file:com.sensia.gwt.relaxNG.RNGInstanceWriter.java

License:Open Source License

protected String writeRNGTag(RNGTag tag, Document dom, Node parentNode) {
    String text = null;//from www .  j  av  a2 s . com
    String error = null;

    if (tag instanceof RNGElement) {
        RNGElement elt = (RNGElement) tag;
        Element newElt = dom.createElement(getFullName(elt.getNamespace(), elt.getName()));
        parentNode.appendChild(newElt);
        ensureNamespaceDecl(elt.getNamespace());
        for (RNGTag child : elt.getChildren())
            writeRNGTag(child, dom, newElt);
    }

    else if (tag instanceof RNGAttribute) {
        RNGAttribute att = (RNGAttribute) tag;
        String name = getFullName(att.getNamespace(), att.getName());
        String value = writeRNGTag(att.getChildren().get(0), dom, null);
        ((Element) parentNode).setAttribute(name, value);
        ensureNamespaceDecl(att.getNamespace());
    }

    else if (tag instanceof RNGGroup) {
        RNGGroup grp = (RNGGroup) tag;
        for (RNGTag child : grp.getChildren())
            writeRNGTag(child, dom, parentNode);
    }

    else if (tag instanceof RNGOptional) {
        RNGOptional opt = (RNGOptional) tag;
        if (opt.isSelected())
            for (RNGTag child : opt.getChildren())
                writeRNGTag(child, dom, parentNode);
    }

    else if (tag instanceof RNGChoice) {
        RNGChoice choice = (RNGChoice) tag;
        if (choice.isSelected())
            text = writeRNGTag(choice.getSelectedPattern(), dom, parentNode);
        else
            error = NO_CHOICE;
    }

    else if (tag instanceof RNGZeroOrMore) {
        RNGZeroOrMore multiple = (RNGZeroOrMore) tag;
        for (List<RNGTag> tagList : multiple.getPatternInstances()) {
            for (RNGTag item : tagList)
                text = writeRNGTag(item, dom, parentNode);
        }
    }

    else if (tag instanceof RNGList) {
        RNGList list = (RNGList) tag;
        StringBuilder buf = new StringBuilder();

        for (RNGTag child : list.getChildren()) {
            String val = writeRNGTag(child, dom, null);
            if (val != null) {
                buf.append(val);
                buf.append(' ');
            }
        }

        if (buf.length() > 0)
            text = buf.toString();
    }

    else if (tag instanceof RNGRef) {
        RNGRef ref = (RNGRef) tag;
        if (ref.getPattern() != null) {
            for (RNGTag child : ref.getPattern().getChildren())
                writeRNGTag(child, dom, parentNode);
        } else
            error = NO_REF;
    }

    else if (tag instanceof RNGValue) {
        text = ((RNGValue) tag).getText();
        if (text == null)
            error = NO_VALUE;
    }

    else if (tag instanceof RNGText) {
        text = ((RNGText) tag).getText();
        if (text == null)
            error = NO_VALUE;
    }

    else if (tag instanceof RNGData<?>) {
        Object val = ((RNGData<?>) tag).getValue();
        if (val != null)
            text = val.toString();
        else
            error = NO_VALUE;
    }

    // deal with text nodes or attribute values
    if (text != null && text.length() > 0) {
        if (parentNode != null) {
            Text node = dom.createTextNode(text);
            parentNode.appendChild(node);
        } else
            return text;
    }

    // deal with error text
    if (error != null) {
        if (parentNode != null) {
            Comment c = dom.createComment(error);
            parentNode.appendChild(c);
        } else
            return error;
    }

    return null;
}