Example usage for javax.xml.stream XMLStreamConstants CHARACTERS

List of usage examples for javax.xml.stream XMLStreamConstants CHARACTERS

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamConstants CHARACTERS.

Prototype

int CHARACTERS

To view the source code for javax.xml.stream XMLStreamConstants CHARACTERS.

Click Source Link

Document

Indicates an event is characters

Usage

From source file:org.slc.sli.modeling.wadl.reader.WadlReader.java

private static final Include readInclude(final XMLStreamReader reader) throws XMLStreamException {
    assertName(WadlElementName.INCLUDE, reader);
    final String href = getHRef(reader);
    final List<Documentation> doc = new LinkedList<Documentation>();
    while (reader.hasNext()) {
        reader.next();/*w w  w .  j a  v a 2 s .  c o m*/
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(WadlElementName.DOCUMENTATION, reader)) {
                doc.add(readDocumentation(reader));
            } else {
                skipForeignNamespaceElement(reader);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(WadlElementName.INCLUDE, reader);
            return new Include(href, doc);
        }
        case XMLStreamConstants.CHARACTERS: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

From source file:org.slc.sli.modeling.wadl.reader.WadlReader.java

private static final Method readMethod(final XMLStreamReader reader) throws XMLStreamException {
    assertName(WadlElementName.METHOD, reader);
    final String id = getId(reader);
    final String name = getName(reader, null);
    @SuppressWarnings("unused")
    final String href = getHRef(reader, null);
    final List<Documentation> doc = new LinkedList<Documentation>();
    Request request = null;//from  w  w w.j  a  v  a 2  s . c  o m
    final List<Response> responses = new LinkedList<Response>();
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(WadlElementName.REQUEST, reader)) {
                request = readRequest(reader);
            } else if (match(WadlElementName.RESPONSE, reader)) {
                responses.add(readResponse(reader));
            } else if (match(WadlElementName.DOCUMENTATION, reader)) {
                doc.add(readDocumentation(reader));
            } else {
                skipForeignNamespaceElement(reader);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(WadlElementName.METHOD, reader);
            return new Method(id, name, doc, request, responses);
        }
        case XMLStreamConstants.CHARACTERS: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

From source file:org.slc.sli.modeling.wadl.reader.WadlReader.java

private static final DmElement readMixedElement(final XMLStreamReader reader) throws XMLStreamException {
    final QName name = reader.getName();
    final List<DmNode> children = new LinkedList<DmNode>();
    while (reader.hasNext()) {
        reader.next();//from   w  w  w.  j  a  v  a 2 s.c  o  m
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            children.add(readMixedElement(reader));
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            if (name.equals(reader.getName())) {
                return new DmElement(name, children);
            } else {
                throw new AssertionError(reader.getLocalName());
            }
        }
        case XMLStreamConstants.CHARACTERS: {
            // Assume that the element will coalesce text nodes.
            children.add(new DmText(reader.getText()));
            break;
        }
        case XMLStreamConstants.COMMENT: {
            // Ignore for now.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

From source file:org.slc.sli.modeling.wadl.reader.WadlReader.java

private static final Param readParam(final XMLStreamReader reader) throws XMLStreamException {
    assertName(WadlElementName.PARAM, reader);
    final String name = getName(reader, null);
    final ParamStyle style = getParamStyle(reader, WadlAttributeName.STYLE);
    final String id = getId(reader);
    final QName type = getQNameAttribute(WadlAttributeName.TYPE,
            new QName("http://www.w3.org/2001/XMLSchema", "string"), reader);
    final String defaultValue = getStringAttribute(WadlAttributeName.DEFAULT_VALUE, null, reader);
    final boolean required = getBooleanAttribute(WadlAttributeName.REQUIRED, false, reader);
    final boolean repeating = getBooleanAttribute(WadlAttributeName.REPEATING, false, reader);
    final String fixed = getStringAttribute(WadlAttributeName.FIXED, null, reader);
    final String path = getStringAttribute(WadlAttributeName.PATH, null, reader);
    final List<Documentation> doc = new LinkedList<Documentation>();
    final List<Option> options = new LinkedList<Option>();
    final Link link = null;
    while (reader.hasNext()) {
        reader.next();/*from  w w  w  .  j a  v  a  2s  . c  om*/
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(WadlElementName.DOCUMENTATION, reader)) {
                doc.add(readDocumentation(reader));
            } else if (match(WadlElementName.OPTION, reader)) {
                options.add(readOption(reader));
            } else {
                skipForeignNamespaceElement(reader);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(WadlElementName.PARAM, reader);
            return new Param(name, style, id, type, defaultValue, required, repeating, fixed, path, doc,
                    options, link);
        }
        case XMLStreamConstants.CHARACTERS: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

From source file:org.slc.sli.modeling.wadl.reader.WadlReader.java

private static final Representation readRepresentation(final XMLStreamReader reader) throws XMLStreamException {
    assertName(WadlElementName.REPRESENTATION, reader);
    final String id = getId(reader);
    final QName element = getQNameAttribute(WadlAttributeName.ELEMENT, null, reader);
    final String mediaType = getStringAttribute(WadlAttributeName.MEDIA_TYPE, null, reader);
    @SuppressWarnings("unused")
    final String href = getHRef(reader, null);
    final List<String> profiles = getStringListType(WadlAttributeName.PROFILE, reader);
    final List<Param> params = new LinkedList<Param>();
    final List<Documentation> documentation = new LinkedList<Documentation>();
    while (reader.hasNext()) {
        reader.next();/*from   w  w w  .  j  a v  a2 s . com*/
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            skipForeignNamespaceElement(reader);
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(WadlElementName.REPRESENTATION, reader);
            return new Representation(id, element, mediaType, profiles, documentation, params);
        }
        case XMLStreamConstants.CHARACTERS: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

From source file:org.slc.sli.modeling.wadl.reader.WadlReader.java

private static final Request readRequest(final XMLStreamReader reader) throws XMLStreamException {
    assertName(WadlElementName.REQUEST, reader);
    final List<Param> params = new LinkedList<Param>();
    final List<Representation> representations = new LinkedList<Representation>();
    final List<Documentation> documentation = new LinkedList<Documentation>();
    while (reader.hasNext()) {
        reader.next();//from www. j ava 2  s .  c  o  m
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(WadlElementName.REPRESENTATION, reader)) {
                representations.add(readRepresentation(reader));
            } else if (match(WadlElementName.PARAM, reader)) {
                params.add(readParam(reader));
            } else {
                skipForeignNamespaceElement(reader);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(WadlElementName.REQUEST, reader);
            return new Request(documentation, params, representations);
        }
        case XMLStreamConstants.CHARACTERS: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

From source file:org.slc.sli.modeling.wadl.reader.WadlReader.java

private static final Resource readResource(final XMLStreamReader reader) throws XMLStreamException {
    assertName(WadlElementName.RESOURCE, reader);
    final String id = getId(reader);
    final List<String> type = getStringListType(WadlAttributeName.TYPE, reader);
    final String queryType = getQueryType(reader, WadlSyntax.QUERY_TYPE_APPLICATION_X_WWW_FORM_URLENCODED);
    final String path = getStringAttribute(WadlAttributeName.PATH, null, reader);
    final String resourceClass = getStringAttribute(WadlAttributeName.RESOURCE_CLASS, null, reader);
    final List<Documentation> documentation = new LinkedList<Documentation>();
    final List<Param> params = new LinkedList<Param>();
    final List<Method> methods = new LinkedList<Method>();
    final List<Resource> resources = new LinkedList<Resource>();
    while (reader.hasNext()) {
        reader.next();//  w w w.j a  v a  2s  . c  o  m
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(WadlElementName.RESOURCE, reader)) {
                resources.add(readResource(reader));
            } else if (match(WadlElementName.DOCUMENTATION, reader)) {
                documentation.add(readDocumentation(reader));
            } else if (match(WadlElementName.PARAM, reader)) {
                params.add(readParam(reader));
            } else if (match(WadlElementName.METHOD, reader)) {
                methods.add(readMethod(reader));
            } else {
                skipForeignNamespaceElement(reader);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(WadlElementName.RESOURCE, reader);
            return new Resource(id, type, queryType, path, documentation, params, methods, resources,
                    resourceClass);
        }
        case XMLStreamConstants.CHARACTERS:
        case XMLStreamConstants.COMMENT: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

From source file:org.slc.sli.modeling.wadl.reader.WadlReader.java

private static final Resources readResources(final XMLStreamReader reader) throws XMLStreamException {
    assertName(WadlElementName.RESOURCES, reader);
    final String base = getBase(reader, null);
    final List<Documentation> documentation = new LinkedList<Documentation>();
    final List<Resource> resources = new LinkedList<Resource>();
    while (reader.hasNext()) {
        reader.next();//from w  w w .j a  v  a2s.  c  o  m
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(WadlElementName.RESOURCE, reader)) {
                resources.add(readResource(reader));
            } else if (match(WadlElementName.DOCUMENTATION, reader)) {
                documentation.add(readDocumentation(reader));
            } else {
                skipForeignNamespaceElement(reader);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(WadlElementName.RESOURCES, reader);
            return new Resources(base, documentation, resources);
        }
        case XMLStreamConstants.CHARACTERS: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

From source file:org.slc.sli.modeling.wadl.reader.WadlReader.java

private static final Response readResponse(final XMLStreamReader reader) throws XMLStreamException {
    assertName(WadlElementName.RESPONSE, reader);
    final List<String> statusCodes = new LinkedList<String>();
    final List<Param> params = new LinkedList<Param>();
    final List<Representation> representations = new LinkedList<Representation>();
    final List<Documentation> documentation = new LinkedList<Documentation>();
    while (reader.hasNext()) {
        reader.next();//from  w  w w  .  j  av a 2s.c  om
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(WadlElementName.REPRESENTATION, reader)) {
                representations.add(readRepresentation(reader));
            } else if (match(WadlElementName.PARAM, reader)) {
                params.add(readParam(reader));
            } else if (match(WadlElementName.DOCUMENTATION, reader)) {
                documentation.add(readDocumentation(reader));
            } else {
                skipForeignNamespaceElement(reader);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(WadlElementName.RESPONSE, reader);
            return new Response(statusCodes, documentation, params, representations);
        }
        case XMLStreamConstants.CHARACTERS: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

From source file:org.slc.sli.modeling.wadl.reader.WadlReader.java

/**
 * Skips (recursively) over the element in question. Also useful during development.
 *
 * @param reader//ww  w  . j ava  2  s.  c  o m
 *            The StAX {@link XMLStreamReader}.
 */
private static final void skipElementReally(final XMLStreamReader reader) throws XMLStreamException {
    final String localName = reader.getLocalName();
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            skipElementReally(reader);
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            if (localName.equals(reader.getLocalName())) {
                return;
            } else {
                throw new AssertionError(reader.getLocalName());
            }
        }
        case XMLStreamConstants.CHARACTERS:
        case XMLStreamConstants.COMMENT: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}