當前位置: 首頁>>代碼示例>>Java>>正文


Java XMLEventReader.peek方法代碼示例

本文整理匯總了Java中javax.xml.stream.XMLEventReader.peek方法的典型用法代碼示例。如果您正苦於以下問題:Java XMLEventReader.peek方法的具體用法?Java XMLEventReader.peek怎麽用?Java XMLEventReader.peek使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.xml.stream.XMLEventReader的用法示例。


在下文中一共展示了XMLEventReader.peek方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testNextTagWPeek

import javax.xml.stream.XMLEventReader; //導入方法依賴的package包/類
@Test
public void testNextTagWPeek() {
    try {
        XMLEventReader er = getReader();
        er.nextTag();
        er.nextTag();

        er.peek();
        System.out.println(er.getElementText());
        er.nextTag();
        System.out.println(er.getElementText());

    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:Bug6668115Test.java

示例2: read

import javax.xml.stream.XMLEventReader; //導入方法依賴的package包/類
private XmlDocument read(XMLEventReader staxEventReader, Origin origin) {
	XMLEvent event;
	try {
		event = staxEventReader.peek();
		while ( event != null && !event.isStartElement() ) {
			staxEventReader.nextEvent();
			event = staxEventReader.peek();
		}
	}
	catch ( Exception e ) {
		throw new InvalidMappingException( "Error accessing stax stream", origin, e );
	}

	if ( event == null ) {
		throw new InvalidMappingException( "Could not locate root element", origin );
	}

	final String rootElementName = event.asStartElement().getName().getLocalPart();

	if ( "entity-mappings".equals( rootElementName ) ) {
		final Attribute attribute = event.asStartElement().getAttributeByName( ORM_VERSION_ATTRIBUTE_QNAME );
		final String explicitVersion = attribute == null ? null : attribute.getValue();
		validateMapping(
				SupportedOrmXsdVersion.parse( explicitVersion, origin ),
				staxEventReader,
				origin
		);
	}

	return new XmlDocumentImpl( toDom4jDocument( staxEventReader, origin ), origin );
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:32,代碼來源:MappingReader.java

示例3: unmarshal

import javax.xml.stream.XMLEventReader; //導入方法依賴的package包/類
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:SunburstApps,項目名稱:OpenJSharp,代碼行數:40,代碼來源:ExternalAttachmentsUnmarshaller.java

示例4: unmarshalModel

import javax.xml.stream.XMLEventReader; //導入方法依賴的package包/類
/**
 * 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,代碼行數:43,代碼來源:XmlPolicyModelUnmarshaller.java

示例5: unmarshal0

import javax.xml.stream.XMLEventReader; //導入方法依賴的package包/類
private Object unmarshal0(XMLEventReader reader,JaxBeanInfo expectedType) throws JAXBException {
    if (reader == null) {
        throw new IllegalArgumentException(
                Messages.format(Messages.NULL_READER));
    }

    try {
        XMLEvent event = reader.peek();

        if (!event.isStartElement() && !event.isStartDocument()) {
            // TODO: convert event into event name
            throw new IllegalStateException(
                Messages.format(
                    Messages.ILLEGAL_READER_STATE,event.getEventType()));
        }

        // Quick hack until SJSXP fixes 6270116
        boolean isZephyr = reader.getClass().getName().equals("com.sun.xml.internal.stream.XMLReaderImpl");
        XmlVisitor h = createUnmarshallerHandler(null,false,expectedType);
        if(!isZephyr) {
            h = new InterningXmlVisitor(h);
        }
        new StAXEventConnector(reader,h).bridge();
        return h.getContext().getResult();
    } catch (XMLStreamException e) {
        throw handleStreamException(e);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:29,代碼來源:UnmarshallerImpl.java

示例6: StAXSource

import javax.xml.stream.XMLEventReader; //導入方法依賴的package包/類
/**
 * <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:SunburstApps,項目名稱:OpenJSharp,代碼行數:50,代碼來源:StAXSource.java

示例7: parse

import javax.xml.stream.XMLEventReader; //導入方法依賴的package包/類
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:SunburstApps,項目名稱:OpenJSharp,代碼行數:78,代碼來源:StAXSchemaParser.java


注:本文中的javax.xml.stream.XMLEventReader.peek方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。