Example usage for com.google.gwt.xml.client Node getPrefix

List of usage examples for com.google.gwt.xml.client Node getPrefix

Introduction

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

Prototype

String getPrefix();

Source Link

Document

This method retrieves the prefix.

Usage

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

License:Open Source License

protected RNGGrammar parseGrammar(String url, Element grammarElt) {
    grammar = new RNGGrammar();
    grammar.setId(url);// w ww .jav a 2  s.c  o  m

    // figure out base URL
    int lastSlash = url.lastIndexOf('/');
    String baseUrl = (lastSlash > 0) ? url.substring(0, lastSlash + 1) : "";

    // namespaces
    NamedNodeMap atts = grammarElt.getAttributes();
    for (int i = 0; i < atts.getLength(); i++) {
        Node node = atts.item(i);
        if (node.getPrefix() != null && node.getPrefix().equals("xmlns")) {
            String prefix = node.getNodeName().substring(node.getNodeName().indexOf(':') + 1);
            String uri = node.getNodeValue();

            if (uri.equals(RNGParser.RNG_NS_URI) || uri.equals(RNGParser.ANNOT_NS_URI))
                continue;

            grammar.addNamespace(prefix, uri);
        }
    }

    // get included grammars
    List<Element> includeElts = new ArrayList<Element>();
    NodeList children = grammarElt.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        if (children.item(i).getNodeType() != Node.ELEMENT_NODE)
            continue;

        Element child = (Element) children.item(i);
        String childName = child.getNodeName();

        if (childName.equals("include"))
            includeElts.add(child);
    }
    numIncludes = includeElts.size();

    // finish parsing now if no includes
    if (numIncludes == 0)
        finishParsing(grammarElt);

    // else parse all included grammar asynchronously
    // we will finish parsing on callback when all includes are loaded
    else
        for (Element includeElt : includeElts)
            parseIncludedGrammar(baseUrl, includeElt);

    return grammar;
}

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

License:Open Source License

/**
 * Creates the grammar.// w  w  w  . j a va 2s . com
 *
 * @param url the url
 * @param root the root
 */
public void createGrammar(String url, Element root) {
    grammar = new RNGGrammar();
    grammar.setId(url);

    // namespaces
    NamedNodeMap atts = root.getAttributes();
    for (int i = 0; i < atts.getLength(); i++) {
        Node node = atts.item(i);
        if (node.getPrefix() != null && node.getPrefix().equals("xmlns")) {
            String prefix = node.getNodeName().substring(node.getNodeName().indexOf(':') + 1);
            String uri = node.getNodeValue();

            if (uri.equals(RNGParser.RNG_NS_URI) || uri.equals(RNGParser.ANNOT_NS_URI))
                continue;

            grammar.addNamespace(prefix, uri);
        }
    }
    RNGGroup startPattern = new RNGGroup();

    RNGElement rngElt = new RNGElement();
    QName qName = parseName(root.getNodeName());

    rngElt.setName(qName.localName);
    rngElt.setNamespace(qName.namespaceURI);
    ((RNGTagList) startPattern).add(rngElt);

    parseChildren(rngElt, root);
    grammar.setStartPattern(startPattern);

    grammarCache.put(grammar.getId(), grammar);
    if (callback != null) {
        callback.onParseDone(grammar);
    }
}