当前位置: 首页>>代码示例>>Java>>正文


Java XMLStreamConstants.START_DOCUMENT属性代码示例

本文整理汇总了Java中javax.xml.stream.XMLStreamConstants.START_DOCUMENT属性的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamConstants.START_DOCUMENT属性的具体用法?Java XMLStreamConstants.START_DOCUMENT怎么用?Java XMLStreamConstants.START_DOCUMENT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在javax.xml.stream.XMLStreamConstants的用法示例。


在下文中一共展示了XMLStreamConstants.START_DOCUMENT属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: pullNextEvent

@Override
protected int pullNextEvent() {
    try {
        switch (in.next()) {
        case XMLStreamConstants.START_DOCUMENT:
        case XMLStreamConstants.START_ELEMENT:
            return START_NODE;
        case XMLStreamConstants.END_DOCUMENT:
        case XMLStreamConstants.END_ELEMENT:
            return END_NODE;
        case XMLStreamConstants.CHARACTERS:
            return TEXT;
        case XMLStreamConstants.COMMENT:
            return COMMENT;
        default:
            return OTHER;
        }
    } catch (final XMLStreamException e) {
        throw new StreamException(e);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:StaxReader.java

示例2: StAXSource

/**
 * Creates a new {@link javax.xml.transform.Source} for the given
 * {@link XMLStreamReader}.
 *
 * The XMLStreamReader must be pointing at either a
 * {@link javax.xml.stream.XMLStreamConstants#START_DOCUMENT} or
 * {@link javax.xml.stream.XMLStreamConstants#START_ELEMENT} event.
 *
 * @param reader XMLStreamReader that will be exposed as a Source
 * @param eagerQuit if true, when the conversion is completed, leave the cursor to the last
 *                  event that was fired (such as end element)
 * @param inscope inscope Namespaces
 *                array of the even length of the form { prefix0, uri0, prefix1, uri1, ... }
 * @throws IllegalArgumentException iff the reader is null
 * @throws IllegalStateException iff the reader is not pointing at either a
 * START_DOCUMENT or START_ELEMENT event
 */
public StAXSource(XMLStreamReader reader, boolean eagerQuit, @NotNull String[] inscope) {
    if( reader == null )
        throw new IllegalArgumentException();
    this.staxReader = reader;

    int eventType = reader.getEventType();
    if (!(eventType == XMLStreamConstants.START_DOCUMENT)
        && !(eventType == XMLStreamConstants.START_ELEMENT)) {
        throw new IllegalStateException();
    }

    this.reader = new XMLStreamReaderToContentHandler(reader,repeater,eagerQuit,false,inscope);

    super.setXMLReader(pseudoParser);
    // pass a dummy InputSource. We don't care
    super.setInputSource(new InputSource());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:StAXSource.java

示例3: getXMLs

@DataProvider(name = "xmls")
public Object[][] getXMLs() {

    return new Object[][]{
        {"<?xml version='1.0'?><foo/>",
            XMLStreamConstants.START_DOCUMENT, XMLStreamConstants.START_ELEMENT},
        {"<foo/>",
            XMLStreamConstants.START_DOCUMENT, XMLStreamConstants.START_ELEMENT},
        {"<?xml version='1.0'?>"
            + "<?xml-stylesheet href=\"bar.xsl\" type=\"text/xsl\"?>" +
                "<foo/>",
            XMLStreamConstants.START_DOCUMENT, XMLStreamConstants.PROCESSING_INSTRUCTION},
        {"<?xml-stylesheet href=\"bar.xsl\" type=\"text/xsl\"?>" +
                "<foo/>",
            XMLStreamConstants.START_DOCUMENT, XMLStreamConstants.PROCESSING_INSTRUCTION},
    };
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:BugTest.java

示例4: getEventName

/**
 * Get the human readable event name for the numeric event id
 */
public static String getEventName(int eventId) {
	switch (eventId) {
		case XMLStreamConstants.START_ELEMENT:
			return "StartElementEvent";
		case XMLStreamConstants.END_ELEMENT:
			return "EndElementEvent";
		case XMLStreamConstants.PROCESSING_INSTRUCTION:
			return "ProcessingInstructionEvent";
		case XMLStreamConstants.CHARACTERS:
			return "CharacterEvent";
		case XMLStreamConstants.COMMENT:
			return "CommentEvent";
		case XMLStreamConstants.START_DOCUMENT:
			return "StartDocumentEvent";
		case XMLStreamConstants.END_DOCUMENT:
			return "EndDocumentEvent";
		case XMLStreamConstants.ENTITY_REFERENCE:
			return "EntityReferenceEvent";
		case XMLStreamConstants.ATTRIBUTE:
			return "AttributeBase";
		case XMLStreamConstants.DTD:
			return "DTDEvent";
		case XMLStreamConstants.CDATA:
			return "CDATA";
	}
	return "UNKNOWN_EVENT_TYPE";
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:XMLStreamConstantsUtils.java

示例5: getEventTypeString

public final static String getEventTypeString(int eventType) {
    switch (eventType){
        case XMLStreamConstants.START_ELEMENT:
            return "START_ELEMENT";
        case XMLStreamConstants.END_ELEMENT:
            return "END_ELEMENT";
        case XMLStreamConstants.PROCESSING_INSTRUCTION:
            return "PROCESSING_INSTRUCTION";
        case XMLStreamConstants.CHARACTERS:
            return "CHARACTERS";
        case XMLStreamConstants.COMMENT:
            return "COMMENT";
        case XMLStreamConstants.START_DOCUMENT:
            return "START_DOCUMENT";
        case XMLStreamConstants.END_DOCUMENT:
            return "END_DOCUMENT";
        case XMLStreamConstants.ENTITY_REFERENCE:
            return "ENTITY_REFERENCE";
        case XMLStreamConstants.ATTRIBUTE:
            return "ATTRIBUTE";
        case XMLStreamConstants.DTD:
            return "DTD";
        case XMLStreamConstants.CDATA:
            return "CDATA";
    }
    return "UNKNOWN_EVENT_TYPE";
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:Util.java

示例6: unmarshalModel

/**
 * See {@link PolicyModelUnmarshaller#unmarshalModel(Object) base method documentation}.
 */
public PolicySourceModel unmarshalModel(final Object storage) throws PolicyException {
    final XMLEventReader reader = createXMLEventReader(storage);
    PolicySourceModel model = null;

    loop:
    while (reader.hasNext()) {
        try {
            final XMLEvent event = reader.peek();
            switch (event.getEventType()) {
                case XMLStreamConstants.START_DOCUMENT:
                case XMLStreamConstants.COMMENT:
                    reader.nextEvent();
                    break; // skipping the comments and start document events
                case XMLStreamConstants.CHARACTERS:
                    processCharacters(ModelNode.Type.POLICY, event.asCharacters(), null);
                    // we advance the reader only if there is no exception thrown from
                    // the processCharacters(...) call. Otherwise we don't modify the stream
                    reader.nextEvent();
                    break;
                case XMLStreamConstants.START_ELEMENT:
                    if (NamespaceVersion.resolveAsToken(event.asStartElement().getName()) == XmlToken.Policy) {
                        StartElement rootElement = reader.nextEvent().asStartElement();

                        model = initializeNewModel(rootElement);
                        unmarshalNodeContent(model.getNamespaceVersion(), model.getRootNode(), rootElement.getName(), reader);

                        break loop;
                    } else {
                        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0048_POLICY_ELEMENT_EXPECTED_FIRST()));
                    }
                default:
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0048_POLICY_ELEMENT_EXPECTED_FIRST()));
            }
        } catch (XMLStreamException e) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0068_FAILED_TO_UNMARSHALL_POLICY_EXPRESSION(), e));
        }
    }
    return model;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:42,代码来源:XmlPolicyModelUnmarshaller.java

示例7: StAXSource

/**
 * <p>Creates a new instance of a <code>StAXSource</code>
 * by supplying an {@link XMLEventReader}.</p>
 *
 * <p><code>XMLEventReader</code> must be a
 * non-<code>null</code> reference.</p>
 *
 * <p><code>XMLEventReader</code> must be in
 * {@link XMLStreamConstants#START_DOCUMENT} or
 * {@link XMLStreamConstants#START_ELEMENT} state.</p>
 *
 * @param xmlEventReader <code>XMLEventReader</code> used to create
 *   this <code>StAXSource</code>.
 *
 * @throws XMLStreamException If <code>xmlEventReader</code> access
 *   throws an <code>Exception</code>.
 * @throws IllegalArgumentException If <code>xmlEventReader</code> ==
 *   <code>null</code>.
 * @throws IllegalStateException If <code>xmlEventReader</code>
 *   is not in <code>XMLStreamConstants.START_DOCUMENT</code> or
 *   <code>XMLStreamConstants.START_ELEMENT</code> state.
 */
public StAXSource(final XMLEventReader xmlEventReader)
    throws XMLStreamException {

    if (xmlEventReader == null) {
        throw new IllegalArgumentException(
                "StAXSource(XMLEventReader) with XMLEventReader == null");
    }

    // TODO: This is ugly ...
    // there is no way to know the current position(event) of
    // XMLEventReader.  peek() is the only way to know the next event.
    // The next event on the input stream should be
    // XMLStreamConstants.START_DOCUMENT or
    // XMLStreamConstants.START_ELEMENT.
    XMLEvent event = xmlEventReader.peek();
    int eventType = event.getEventType();
    if (eventType != XMLStreamConstants.START_DOCUMENT
            && eventType != XMLStreamConstants.START_ELEMENT) {
        throw new IllegalStateException(
            "StAXSource(XMLEventReader) with XMLEventReader "
            + "not in XMLStreamConstants.START_DOCUMENT or "
            + "XMLStreamConstants.START_ELEMENT state");
    }

    this.xmlEventReader = xmlEventReader;
    systemId = event.getLocation().getSystemId();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:49,代码来源:StAXSource.java

示例8: nextTag

/** Skips any insignificant space events until a START_ELEMENT or
 * END_ELEMENT is reached. If anything other than space characters are
 * encountered, an exception is thrown. This method should
 * be used when processing element-only content because
 * the parser is not able to recognize ignorable whitespace if
 * the DTD is missing or not interpreted.
 * @throws XMLStreamException if anything other than space characters are encountered
 */
public XMLEvent nextTag() throws XMLStreamException {
    //its really a pain if there is peeked event before calling nextTag()
    if(fPeekedEvent != null){
        //check the peeked event first.
        XMLEvent event = fPeekedEvent;
        fPeekedEvent = null ;
        int eventType = event.getEventType();
        //if peeked event is whitespace move to the next event
        //if peeked event is PI or COMMENT move to the next event
        if( (event.isCharacters() && event.asCharacters().isWhiteSpace())
        || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
        || eventType == XMLStreamConstants.COMMENT
        || eventType == XMLStreamConstants.START_DOCUMENT){
            event = nextEvent();
            eventType = event.getEventType();
        }

        //we have to have the while loop because there can be many PI or comment event in sucession
        while((event.isCharacters() && event.asCharacters().isWhiteSpace())
        || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
        || eventType == XMLStreamConstants.COMMENT){

            event = nextEvent();
            eventType = event.getEventType();
        }

        if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {
            throw new XMLStreamException("expected start or end tag", event.getLocation());
        }
        return event;
    }

    //if there is no peeked event -- delegate the work of getting next event to fXMLReader
    fXMLReader.nextTag();
    return (fLastEvent = fXMLEventAllocator.allocate(fXMLReader));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:44,代码来源:XMLEventReaderImpl.java

示例9: unmarshal

private Map<URI, Policy> unmarshal(final XMLEventReader reader, final StartElement parentElement) throws PolicyException {
    XMLEvent event = null;
    while (reader.hasNext()) {
        try {
            event = reader.peek();
            switch (event.getEventType()) {
                case XMLStreamConstants.START_DOCUMENT:
                case XMLStreamConstants.COMMENT:
                    reader.nextEvent();
                    break;

                case XMLStreamConstants.CHARACTERS:
                    processCharacters(event.asCharacters(), parentElement, map);
                    reader.nextEvent();
                    break;

                case XMLStreamConstants.END_ELEMENT:
                    processEndTag(event.asEndElement(), parentElement);
                    reader.nextEvent();
                    return map;

                case XMLStreamConstants.START_ELEMENT:
                    final StartElement element = event.asStartElement();
                    processStartTag(element, parentElement, reader, map);
                    break;

                case XMLStreamConstants.END_DOCUMENT:
                    return map;

                default:
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0087_UNKNOWN_EVENT(event)));
            }
        } catch (XMLStreamException e) {
            final Location location = event == null ? null : event.getLocation();
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0088_FAILED_PARSE(location)), e);
        }
    }
    return map;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:ExternalAttachmentsUnmarshaller.java

示例10: unmarshal0

public Object unmarshal0(XMLStreamReader reader, JaxBeanInfo expectedType) throws JAXBException {
    if (reader == null) {
        throw new IllegalArgumentException(
            Messages.format(Messages.NULL_READER));
    }

    int eventType = reader.getEventType();
    if (eventType != XMLStreamConstants.START_ELEMENT
        && eventType != XMLStreamConstants.START_DOCUMENT) {
        // TODO: convert eventType into event name
        throw new IllegalStateException(
            Messages.format(Messages.ILLEGAL_READER_STATE,eventType));
    }

    XmlVisitor h = createUnmarshallerHandler(null,false,expectedType);
    StAXConnector connector=StAXStreamConnector.create(reader,h);

    try {
        connector.bridge();
    } catch (XMLStreamException e) {
        throw handleStreamException(e);
    }

    Object retVal = h.getContext().getResult();
    h.getContext().clearResult();
    return retVal;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:UnmarshallerImpl.java

示例11: bridge

public void bridge() throws XMLStreamException {

        try {
            // remembers the nest level of elements to know when we are done.
            int depth=0;

            // if the parser is at the start tag, proceed to the first element
            int event = staxStreamReader.getEventType();
            if(event == XMLStreamConstants.START_DOCUMENT) {
                // nextTag doesn't correctly handle DTDs
                while( !staxStreamReader.isStartElement() )
                    event = staxStreamReader.next();
            }


            if( event!=XMLStreamConstants.START_ELEMENT)
                throw new IllegalStateException("The current event is not START_ELEMENT\n but " + event);

            handleStartDocument(staxStreamReader.getNamespaceContext());

            OUTER:
            while(true) {
                // These are all of the events listed in the javadoc for
                // XMLEvent.
                // The spec only really describes 11 of them.
                switch (event) {
                    case XMLStreamConstants.START_ELEMENT :
                        handleStartElement();
                        depth++;
                        break;
                    case XMLStreamConstants.END_ELEMENT :
                        depth--;
                        handleEndElement();
                        if(depth==0)    break OUTER;
                        break;
                    case XMLStreamConstants.CHARACTERS :
                    case XMLStreamConstants.CDATA :
                    case XMLStreamConstants.SPACE :
                        handleCharacters();
                        break;
                    // otherwise simply ignore
                }

                event=staxStreamReader.next();
            }

            staxStreamReader.next();    // move beyond the end tag.

            handleEndDocument();
        } catch (SAXException e) {
            throw new XMLStreamException(e);
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:53,代码来源:StAXStreamConnector.java

示例12: add

public void add(XMLEvent event) throws XMLStreamException {
    if (event.getEventType() == XMLStreamConstants.START_DOCUMENT) {
        version = ((StartDocument) event).getVersion();
        encoding = ((StartDocument) event).getCharacterEncodingScheme();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:VersionEventWriter.java

示例13: parse

public void parse(XMLEventReader input) throws XMLStreamException, XNIException {
    XMLEvent currentEvent = input.peek();
    if (currentEvent != null) {
        int eventType = currentEvent.getEventType();
        if (eventType != XMLStreamConstants.START_DOCUMENT &&
            eventType != XMLStreamConstants.START_ELEMENT) {
            throw new XMLStreamException();
        }
        fLocationWrapper.setLocation(currentEvent.getLocation());
        fSchemaDOMParser.startDocument(fLocationWrapper, null, fNamespaceContext, null);
        loop: while (input.hasNext()) {
            currentEvent = input.nextEvent();
            eventType = currentEvent.getEventType();
            switch (eventType) {
            case XMLStreamConstants.START_ELEMENT:
                ++fDepth;
                StartElement start = currentEvent.asStartElement();
                fillQName(fElementQName, start.getName());
                fLocationWrapper.setLocation(start.getLocation());
                fNamespaceContext.setNamespaceContext(start.getNamespaceContext());
                fillXMLAttributes(start);
                fillDeclaredPrefixes(start);
                addNamespaceDeclarations();
                fNamespaceContext.pushContext();
                fSchemaDOMParser.startElement(fElementQName, fAttributes, null);
                break;
            case XMLStreamConstants.END_ELEMENT:
                EndElement end = currentEvent.asEndElement();
                fillQName(fElementQName, end.getName());
                fillDeclaredPrefixes(end);
                fLocationWrapper.setLocation(end.getLocation());
                fSchemaDOMParser.endElement(fElementQName, null);
                fNamespaceContext.popContext();
                --fDepth;
                if (fDepth <= 0) {
                    break loop;
                }
                break;
            case XMLStreamConstants.CHARACTERS:
                sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
                break;
            case XMLStreamConstants.SPACE:
                sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), true);
                break;
            case XMLStreamConstants.CDATA:
                fSchemaDOMParser.startCDATA(null);
                sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
                fSchemaDOMParser.endCDATA(null);
                break;
            case XMLStreamConstants.PROCESSING_INSTRUCTION:
                ProcessingInstruction pi = (ProcessingInstruction)currentEvent;
                fillProcessingInstruction(pi.getData());
                fSchemaDOMParser.processingInstruction(pi.getTarget(), fTempString, null);
                break;
            case XMLStreamConstants.DTD:
                /* There shouldn't be a DTD in the schema */
                break;
            case XMLStreamConstants.ENTITY_REFERENCE:
                /* Not needed for schemas */
                break;
            case XMLStreamConstants.COMMENT:
                /* No point in sending comments */
                break;
            case XMLStreamConstants.START_DOCUMENT:
                fDepth++;
                /* We automatically call startDocument before the loop */
                break;
            case XMLStreamConstants.END_DOCUMENT:
                /* We automatically call endDocument after the loop */
                break;
            }
        }
        fLocationWrapper.setLocation(null);
        fNamespaceContext.setNamespaceContext(null);
        fSchemaDOMParser.endDocument(null);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:77,代码来源:StAXSchemaParser.java

示例14: bridge

public void bridge() throws XMLStreamException {
    try {
        // remembers the nest level of elements to know when we are done.
        int depth=0;

        // if the parser is at the start tag, proceed to the first element
        int event = fastInfosetStreamReader.getEventType();
        if(event == XMLStreamConstants.START_DOCUMENT) {
            // nextTag doesn't correctly handle DTDs
            while( !fastInfosetStreamReader.isStartElement() )
                event = fastInfosetStreamReader.next();
        }


        if( event!=XMLStreamConstants.START_ELEMENT)
            throw new IllegalStateException("The current event is not START_ELEMENT\n but " + event);

        // TODO: we don't have to rely on this hack --- we can just emulate
        // start/end prefix mappings. But for now, I'll rely on this hack.
        handleStartDocument(fastInfosetStreamReader.getNamespaceContext());

        OUTER:
        while(true) {
            // These are all of the events listed in the javadoc for
            // XMLEvent.
            // The spec only really describes 11 of them.
            switch (event) {
                case XMLStreamConstants.START_ELEMENT :
                    handleStartElement();
                    depth++;
                    break;
                case XMLStreamConstants.END_ELEMENT :
                    depth--;
                    handleEndElement();
                    if(depth==0)    break OUTER;
                    break;
                case XMLStreamConstants.CHARACTERS :
                case XMLStreamConstants.CDATA :
                case XMLStreamConstants.SPACE :
                    if (predictor.expectText()) {
                        // Peek at the next event to see if there are
                        // fragmented characters
                        event = fastInfosetStreamReader.peekNext();
                        if (event == XMLStreamConstants.END_ELEMENT)
                            processNonIgnorableText();
                        else if (event == XMLStreamConstants.START_ELEMENT)
                            processIgnorableText();
                        else
                            handleFragmentedCharacters();
                    }
                    break;
                // otherwise simply ignore
            }

            event=fastInfosetStreamReader.next();
        }

        fastInfosetStreamReader.next();    // move beyond the end tag.

        handleEndDocument();
    } catch (SAXException e) {
        throw new XMLStreamException(e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:64,代码来源:FastInfosetConnector.java


注:本文中的javax.xml.stream.XMLStreamConstants.START_DOCUMENT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。