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


Java XMLStreamReader.getEventType方法代码示例

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


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

示例1: readRequest

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
void readRequest( Object[] args, XMLStreamReader r, AttachmentSet att) throws JAXBException {
    Object obj = null;
    AttachmentUnmarshallerImpl au = (att != null)?new AttachmentUnmarshallerImpl(att):null;
    if (bridge instanceof RepeatedElementBridge) {
        RepeatedElementBridge rbridge = (RepeatedElementBridge)bridge;
        ArrayList list = new ArrayList();
        QName name = r.getName();
        while (r.getEventType()==XMLStreamReader.START_ELEMENT && name.equals(r.getName())) {
            list.add(rbridge.unmarshal(r, au));
            XMLStreamReaderUtil.toNextTag(r, name);
        }
        obj = rbridge.collectionHandler().convert(list);
    } else {
        obj = bridge.unmarshal(r, au);
    }
    setter.put(obj,args);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:EndpointArgumentsBuilder.java

示例2: toNextTag

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
public static void toNextTag(XMLStreamReader reader, QName name) {
    // skip any whitespace
    if (reader.getEventType() != XMLStreamConstants.START_ELEMENT &&
            reader.getEventType() != XMLStreamConstants.END_ELEMENT) {
        XMLStreamReaderUtil.nextElementContent(reader);
    }
    if(reader.getEventType() == XMLStreamConstants.END_ELEMENT && name.equals(reader.getName())) {
        XMLStreamReaderUtil.nextElementContent(reader);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:XMLStreamReaderUtil.java

示例3: configureExternalMetadataReader

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
protected ExternalMetadataFeature configureExternalMetadataReader(XMLStreamReader reader) {

        ExternalMetadataFeature.Builder featureBuilder = null;
        while (QNAME_EXT_METADA.equals(reader.getName())) {

            if (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
                Attributes attrs = XMLStreamReaderUtil.getAttributes(reader);
                String file = getAttribute(attrs, ATTR_FILE);
                if (file != null) {
                    if (featureBuilder == null) {
                        featureBuilder = ExternalMetadataFeature.builder();
                    }
                    featureBuilder.addFiles(new File(file));
                }

                String res = getAttribute(attrs, ATTR_RESOURCE);
                if (res != null) {
                    if (featureBuilder == null) {
                        featureBuilder = ExternalMetadataFeature.builder();
                    }
                    featureBuilder.addResources(res);
                }
            }

            XMLStreamReaderUtil.nextElementContent(reader);
        }

        return buildFeature(featureBuilder);
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:DeploymentDescriptorParser.java

示例4: createElementFragment

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/**
 * Creates the buffer from a stream reader that is an element fragment.
 * <p>
 * The stream reader will be moved to the position of the next start of
 * an element if the stream reader is not already positioned at the start
 * of an element.
 * <p>
 * The element and all its children will be stored and after storing the stream
 * will be positioned at the next event after the end of the element.
 * <p>
 * @param storeInScopeNamespaces true if in-scope namespaces of the element
 *        fragment should be stored.
 * @return the mutable stream buffer.
 * @throws XMLStreamException if the stream reader cannot be positioned at
 *         the start of an element.
 */
public MutableXMLStreamBuffer createElementFragment(XMLStreamReader reader,
        boolean storeInScopeNamespaces) throws XMLStreamException {
    if (_buffer == null) {
        createBuffer();
    }

    if (!reader.hasNext()) {
        return _buffer;
    }

    _storeInScopeNamespacesOnElementFragment = storeInScopeNamespaces;

    _eventType = reader.getEventType();
    if (_eventType != XMLStreamReader.START_ELEMENT) {
        do {
            _eventType = reader.next();
        } while(_eventType != XMLStreamReader.START_ELEMENT && _eventType != XMLStreamReader.END_DOCUMENT);
    }

    if (storeInScopeNamespaces) {
        _inScopePrefixes = new HashMap<String,Integer>();
    }

    storeElementAndChildren(reader);

    return getXMLStreamBuffer();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:44,代码来源:StreamReaderBufferCreator.java

示例5: getSheetId

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/**
 * Helper method to read the "workbook.xml" in the document and find out the sheet id for
 * given sheet name, or the first sheet if sheetName is null or empty.
 * @param workbook InputStream of the workbook. Caller is responsible for closing it.
 * @param sheetName Sheet name to lookup.
 * @return Non-null value if found a sheet with given name. Otherwise null
 * @throws XMLStreamException
 */
public static String getSheetId(final InputStream workbook, final String sheetName) throws XMLStreamException {
  checkNotNull(workbook);

  final XMLStreamReader wbReader  = XML_INPUT_FACTORY.createXMLStreamReader(workbook);
  final boolean retrieveFirstSheet = sheetName == null || sheetName.isEmpty();

  while (wbReader.hasNext()) {
    wbReader.next();
    final int event = wbReader.getEventType();
    switch (event) {
      case START_ELEMENT: {
        final String name = wbReader.getLocalName();
        if (SHEET.equals(name)) {
          String sheet = wbReader.getAttributeValue(/*namespaceURI=*/null, SHEET_NAME);
          // Sheet names are case insensitive
          if (retrieveFirstSheet || sheetName.equalsIgnoreCase(sheet)) {
            return wbReader.getAttributeValue(SHEET_ID_NS, SHEET_ID);
          }
        }
        break;
      }
    }
  }

  return null;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:35,代码来源:ExcelUtil.java

示例6: test1

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/**
 * Verifies that the initial event of an XMLStreamReader instance is
 * START_DOCUMENT.
 *
 * @param xml the xml input
 * @param type1 the type of the 1st event
 * @param type2 the type of the 2nd event
 * @throws Exception if the test fails to run properly
 */
@Test(dataProvider = "xmls")
public static void test1(String xml, int type1, int type2) throws Exception {
   XMLInputFactory factory = XMLInputFactory.newFactory();

   XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(xml));
   int type1stEvent = reader.getEventType();
   int type2ndEvent = reader.next();
   System.out.println("First event: " + type1stEvent);
   System.out.println("2nd event: " + type2ndEvent);
   Assert.assertEquals(type1, type1stEvent);
   Assert.assertEquals(type2, type2ndEvent);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:BugTest.java

示例7: verifyReaderState

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
public static void verifyReaderState(XMLStreamReader reader, int expectedState) {
    int state = reader.getEventType();
    if (state != expectedState) {
        throw new XMLStreamReaderException(
            "xmlreader.unexpectedState",
            getStateName(expectedState), getStateName(state));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:XMLStreamReaderUtil.java

示例8: getAttribute

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
@Nullable
public String getAttribute(@NotNull String nsUri, @NotNull String localName) {
    try {
        XMLStreamReader sr = epr.read("EndpointReference"/*doesn't matter*/);
        while(sr.getEventType()!= XMLStreamConstants.START_ELEMENT)
            sr.next();

        return sr.getAttributeValue(nsUri,localName);
    } catch (XMLStreamException e) {
        // since we are reading from buffer, this can't happen.
        throw new AssertionError(e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:EPRHeader.java

示例9: currentWhiteSpaceContent

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/**
 * Read spaces from the reader as long as to the next element, starting from
 * current position. Comments are ignored.
 * @param reader
 * @return
 */
public static String currentWhiteSpaceContent(XMLStreamReader reader) {

    // since the there might be several valid chunks (spaces/comment/spaces)
    // StringBuilder must be used; it's initialized lazily, only when needed
    StringBuilder whiteSpaces = null;

    for (;;) {
        switch (reader.getEventType()) {
            case START_ELEMENT:
            case END_ELEMENT:
            case END_DOCUMENT:
                return whiteSpaces == null ? null : whiteSpaces.toString();
            case CHARACTERS:
                if (reader.isWhiteSpace()) {
                    if (whiteSpaces == null) {
                        whiteSpaces = new StringBuilder();
                    }
                    whiteSpaces.append(reader.getText());
                } else {
                    throw new XMLStreamReaderException(
                            "xmlreader.unexpectedCharacterContent", reader.getText());
                }
        }
        next(reader);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:XMLStreamReaderUtil.java

示例10: readRest

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
public static void readRest(XMLStreamReader reader) {
    try {
        while(reader.getEventType() != XMLStreamConstants.END_DOCUMENT) {
            reader.next();
        }
    } catch (XMLStreamException e) {
        throw wrapException(e);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:XMLStreamReaderUtil.java

示例11: post

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
private boolean post(QName tagName, XMLStreamReader xsr, boolean result) {
    if(!tagName.equals(xsr.getName()))
        return foundFool();
    if(result) {
        if(xsr.getEventType()!=XMLStreamConstants.END_ELEMENT)
            foundFool();
    } else {
        if(xsr.getEventType()!=XMLStreamConstants.START_ELEMENT)
            foundFool();
    }
    return result;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:FoolProofParserExtension.java

示例12: getAndVerifyText

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/**
 * Method that not only gets currently available text from the reader, but
 * also checks that its consistenly accessible using different StAX methods.
 */
protected static String getAndVerifyText(XMLStreamReader sr) throws XMLStreamException {
    String text = sr.getText();

    /*
     * 05-Apr-2006, TSa: Although getText() is available for DTD and
     * ENTITY_REFERENCE, getTextXxx() are not. Thus, can not do more checks
     * for those types.
     */
    int type = sr.getEventType();
    if (type != ENTITY_REFERENCE && type != DTD) {
        Assert.assertNotNull("getText() should never return null.", text);
        int expLen = sr.getTextLength();
        /*
         * Hmmh. Can only return empty text for CDATA (since empty blocks
         * are legal).
         */
        /*
         * !!! 01-Sep-2004, TSa: note: theoretically, in coalescing mode, it
         * could be possible to have empty CDATA section(s) get converted to
         * CHARACTERS, which would be empty... may need to enhance this to
         * check that mode is not coalescing? Or something
         */
        if (sr.getEventType() == CHARACTERS) {
            if (expLen == 0) {
                Assert.fail("Stream reader should never return empty Strings.");
            }
        }
        Assert.assertEquals(expLen, text.length(), "Expected text length of " + expLen + ", got " + text.length());
        char[] textChars = sr.getTextCharacters();
        int start = sr.getTextStart();
        String text2 = new String(textChars, start, expLen);
        Assert.assertEquals("Expected getText() and getTextCharacters() to return same value for event of type (" + tokenTypeDesc(sr.getEventType()) + ")",
                text, text2);
    } else { // DTD or ENTITY_REFERENCE
        // not sure if null is legal for these either, but...
        if (text == null) { // let's prevent an NPE at caller
            text = "";
        }
    }
    return text;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:46,代码来源:BaseStAXUT.java

示例13: accept

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
public boolean accept(XMLStreamReader r) {
    return types[r.getEventType()];
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:HasNextTypeFilter.java

示例14: printEvent

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
public static void printEvent(XMLStreamReader xmlr, boolean showEvents) {
  if (showEvents) {
    System.out.print("EVENT:[" + xmlr.getLocation().getLineNumber() + "]["
        + xmlr.getLocation().getColumnNumber() + "] [" + getEventTypeName(xmlr.getEventType())
        + "]");
    System.out.print(" [");
  }
  switch (xmlr.getEventType()) {
    case XMLStreamConstants.START_ELEMENT:
      System.out.print("<");
      printName(xmlr);
      printNamespaces(xmlr);
      printAttributes(xmlr);
      System.out.print(">");
      break;
    case XMLStreamConstants.END_ELEMENT:
      System.out.print("</");
      printName(xmlr);
      System.out.print(">");
      break;
    case XMLStreamConstants.SPACE:
    case XMLStreamConstants.CHARACTERS:
      int start = xmlr.getTextStart();
      int length = xmlr.getTextLength();
      System.out.print(new String(xmlr.getTextCharacters(), start, length));
      break;
    case XMLStreamConstants.PROCESSING_INSTRUCTION:
      System.out.print("<?");
      if (xmlr.hasText())
        System.out.print(xmlr.getText());
      System.out.print("?>");
      break;
    case XMLStreamConstants.CDATA:
      System.out.print("<![CDATA[");
      start = xmlr.getTextStart();
      length = xmlr.getTextLength();
      System.out.print(new String(xmlr.getTextCharacters(), start, length));
      System.out.print("]]>");
      break;
    case XMLStreamConstants.COMMENT:
      System.out.print("<!--");
      if (xmlr.hasText())
        System.out.print(xmlr.getText());
      System.out.print("-->");
      break;
    case XMLStreamConstants.ENTITY_REFERENCE:
      System.out.print(xmlr.getLocalName() + "=");
      if (xmlr.hasText())
        System.out.print("[" + xmlr.getText() + "]");
      break;
    case XMLStreamConstants.START_DOCUMENT:
      System.out.print("<?xml");
      System.out.print(" version='" + xmlr.getVersion() + "'");
      System.out.print(" encoding='" + xmlr.getCharacterEncodingScheme() + "'");
      if (xmlr.isStandalone())
        System.out.print(" standalone='yes'");
      else
        System.out.print(" standalone='no'");
      System.out.print("?>");
      break;
  }
  System.out.println("]");
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:64,代码来源:XMLStreamHelper.java

示例15: getAttributes

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/**
 * Read all attributes into an data structure. Note that this method cannot
 * be called multiple times to get the same list of attributes.
 */
public static Attributes getAttributes(XMLStreamReader reader) {
    return (reader.getEventType() == START_ELEMENT ||
            reader.getEventType() == ATTRIBUTE) ?
            new AttributesImpl(reader) : null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:XMLStreamReaderUtil.java


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