本文整理汇总了Java中org.codehaus.stax2.XMLStreamReader2.hasNext方法的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamReader2.hasNext方法的具体用法?Java XMLStreamReader2.hasNext怎么用?Java XMLStreamReader2.hasNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.stax2.XMLStreamReader2
的用法示例。
在下文中一共展示了XMLStreamReader2.hasNext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseGsafeedElement
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
private Feed parseGsafeedElement(String datasource, String feedtype, XMLStreamReader2 xmlReader) throws XMLStreamException, ParseFeedException {
List<FeedGroup> groups = new ArrayList<FeedGroup>();
while (xmlReader.hasNext()) {
xmlReader.next();
if (xmlReader.getEventType() == XMLStreamConstants.START_ELEMENT) {
if (XML_GSAFEED.equals(xmlReader.getLocalName())) {
//Ignored
}
if (XML_HEADER.equals(xmlReader.getLocalName())) {
//datasource
//feedtype
}
if (XML_GROUP.equals(xmlReader.getLocalName())) {
FeedGroup group = this.parseGroupElement(datasource, feedtype, xmlReader);
groups.add(group);
}
}
}
return new FeedImpl(datasource, feedtype, groups);
}
示例2: parseGroupElement
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
private FeedGroup parseGroupElement(String datasource, String feedtype, XMLStreamReader2 xmlReader) throws ParseFeedException, XMLStreamException {
List<FeedRecord> records = new ArrayList<FeedRecord>();
String action = xmlReader.getAttributeValue("", XML_GROUP_ACTION);
while (xmlReader.hasNext()) {
xmlReader.next();
if (xmlReader.getEventType() == XMLStreamConstants.START_ELEMENT) {
if (XML_RECORD.equals(xmlReader.getLocalName())) {
FeedRecord record = this.parseRecordElement(datasource, feedtype, action, xmlReader);
records.add(record);
}
}
if (xmlReader.getEventType() == XMLStreamConstants.END_ELEMENT) {
if (XML_GROUP.equals(xmlReader.getLocalName())) {
break;
}
}
}
FeedGroup group = new FeedGroupImpl(action, records);
return group;
}
示例3: parseMetadataElement
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
private FeedMetadata parseMetadataElement(XMLStreamReader2 xmlReader) throws ParseFeedException, XMLStreamException {
//in metadata element
List<FeedMeta> metas = new ArrayList<FeedMeta>();
while (xmlReader.hasNext()) {
xmlReader.next();
if (xmlReader.getEventType() == XMLStreamConstants.START_ELEMENT) {
if (XML_META.equals(xmlReader.getLocalName())) {
FeedMeta meta = this.parseMetaElement(xmlReader);
metas.add(meta);
}
}
if (xmlReader.getEventType() == XMLStreamConstants.END_ELEMENT) {
if (XML_METADATA.equals(xmlReader.getLocalName())) {
break;
}
}
}
FeedMetadata metadata = new FeedMetadataImpl(metas);
return metadata;
}
示例4: parseNode
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseNode(NetPlan netPlan, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
long nodeId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "id"));
double xCoord = xmlStreamReader.getAttributeAsDouble(xmlStreamReader.getAttributeIndex(null, "xCoord"));
double yCoord = xmlStreamReader.getAttributeAsDouble(xmlStreamReader.getAttributeIndex(null, "yCoord"));
String nodeName = xmlStreamReader.getAttributeValue(xmlStreamReader.getAttributeIndex(null, "name"));
Node newNode = netPlan.addNode(xCoord, yCoord, nodeName, null);
mapOldId2Node.put (nodeId , newNode);
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
String startElementName = xmlStreamReader.getName().toString();
switch(startElementName)
{
case "attribute":
String key = xmlStreamReader.getAttributeValue(xmlStreamReader.getAttributeIndex(null, "key"));
String name = xmlStreamReader.getAttributeValue(xmlStreamReader.getAttributeIndex(null, "value"));
newNode.setAttribute(key, name);
break;
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("node")) return;
break;
}
}
throw new RuntimeException("'Node' element not parsed correctly (end tag not found)");
}
示例5: parseDemandSet
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseDemandSet(NetPlan netPlan, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
String startElementName = xmlStreamReader.getName().toString();
switch(startElementName)
{
case "demandEntry":
parseDemand(netPlan, xmlStreamReader);
break;
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("demandSet")) return;
break;
}
}
throw new RuntimeException("'Demand set' element not parsed correctly (end tag not found)");
}
示例6: parseSourceRouting
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseSourceRouting(NetPlan netPlan, long layerId, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
netPlan.setRoutingType (RoutingType.SOURCE_ROUTING , mapOldId2Layer.get(layerId));
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
String startElementName = xmlStreamReader.getName().toString();
switch(startElementName)
{
case "protectionSegment":
parseProtectionSegment(netPlan, layerId, xmlStreamReader);
break;
case "route":
parseRoute(netPlan, layerId, xmlStreamReader);
break;
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("sourceRouting")) return;
break;
}
}
throw new RuntimeException("'Source routing' element not parsed correctly (end tag not found)");
}
示例7: parsePhysicalTopology
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parsePhysicalTopology(NetPlan netPlan, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
String startElementName = xmlStreamReader.getName().toString();
switch(startElementName)
{
case "node":
parseNode(netPlan, xmlStreamReader);
break;
case "link":
parseLink(netPlan, xmlStreamReader);
break;
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("physicalTopology")) return;
break;
}
}
throw new RuntimeException("'Physical topology' element not parsed correctly (end tag not found)");
}
示例8: parseProtectionInfo
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseProtectionInfo(NetPlan netPlan, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
String startElementName = xmlStreamReader.getName().toString();
switch(startElementName)
{
case "protectionSegment":
parseProtectionSegment(netPlan, xmlStreamReader);
break;
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("protectionInfo")) return;
break;
}
}
throw new RuntimeException("'Protection info' element not parsed correctly (end tag not found)");
}
示例9: parseRoutingInfo
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseRoutingInfo(NetPlan netPlan, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
String startElementName = xmlStreamReader.getName().toString();
switch(startElementName)
{
case "route":
parseRoute(netPlan, xmlStreamReader);
break;
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("routingInfo")) return;
break;
}
}
throw new RuntimeException("'Routing info' element not parsed correctly (end tag not found)");
}
示例10: parseSRGInfo
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseSRGInfo(NetPlan netPlan, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
String startElementName = xmlStreamReader.getName().toString();
switch(startElementName)
{
case "srg":
parseSRG(netPlan, xmlStreamReader);
break;
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("srgInfo")) return;
break;
}
}
throw new RuntimeException("'SRG info' element not parsed correctly (end tag not found)");
}
示例11: getSchemaLocation
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
/**
* Get the xsi:schemaLocation for the OAI response
*
* @return the xsi:schemaLocation value
*/
public String getSchemaLocation() throws TransformerException, ParserConfigurationException, SAXException, IOException, XMLStreamException {
if (this.schemaLocation == null) {
if (hasDocument()) {
this.schemaLocation = getSingleString("/*/@xsi:schemaLocation");
logger.debug("found schemaLocation["+schemaLocation+"] in the XML tree");
} else {
XMLInputFactory2 xmlif = (XMLInputFactory2) XMLInputFactory2.newInstance();
xmlif.configureForConvenience();
XMLStreamReader2 xmlr = (XMLStreamReader2) xmlif.createXMLStreamReader(getStream());
int state = 1; // 1:START 0:STOP -1:ERROR
while (state > 0) {
int eventType = xmlr.getEventType();
switch (eventType) {
case XMLEvent2.START_ELEMENT:
schemaLocation = xmlr.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance","schemaLocation");
if (schemaLocation != null)
state = 0;
break;
}
if (xmlr.hasNext())
xmlr.next();
else
state = state == 1? 0: -1;// if START then STOP else ERROR
}
xmlr.close();
logger.debug("found schemaLocation["+schemaLocation+"] in the XML stream");
}
// The URIs in xsi:schemaLocation are separated by (any kind
// of) white space. Normalize it to a single space.
this.schemaLocation = schemaLocation.trim().replaceAll("\\s+", " ");
}
return schemaLocation;
}
示例12: verifyFailure
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void verifyFailure(String xml, XMLValidationSchema schema, String failMsg,
String failPhrase, boolean strict) throws XMLStreamException
{
XMLStreamReader2 sr = constructStreamReader(getInputFactory(), xml);
sr.validateAgainst(schema);
try {
while (sr.hasNext()) {
/* int type = */sr.next();
}
fail("Expected validity exception for " + failMsg);
} catch (XMLValidationException vex) {
String origMsg = vex.getMessage();
String msg = (origMsg == null) ? "" : origMsg.toLowerCase();
if (msg.indexOf(failPhrase.toLowerCase()) < 0) {
String actualMsg = "Expected validation exception for "
+ failMsg + ", containing phrase '" + failPhrase
+ "': got '" + origMsg + "'";
if (strict) {
fail(actualMsg);
}
warn("suppressing failure due to MSV bug, failure: '"
+ actualMsg + "'");
}
// should get this specific type; not basic stream exception
} catch (XMLStreamException sex) {
fail("Expected XMLValidationException for " + failMsg
+ "; instead got " + sex.getMessage());
}
}
示例13: parseRecordElement
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
private FeedRecord parseRecordElement(String datasource, String feedtype, String groupAction, XMLStreamReader2 xmlReader)
throws ParseFeedException, XMLStreamException {
//in record element
List<FeedContent> contents = new ArrayList<FeedContent>();
List<FeedMetadata> metadatas = new ArrayList<FeedMetadata>();
String url = xmlReader.getAttributeValue("", XML_RECORD_URL);
String displayurl = xmlReader.getAttributeValue("", XML_RECORD_DISPLAYURL);
String action = xmlReader.getAttributeValue("", XML_RECORD_ACTION);
String mimetype = xmlReader.getAttributeValue("", XML_RECORD_MIMETYPE);
String authmethod = xmlReader.getAttributeValue("", XML_RECORD_AUTHMETHOD);
String lastModified = xmlReader.getAttributeValue("", XML_RECORD_LAST_MODIFIED);
String lock = xmlReader.getAttributeValue("", XML_RECORD_LOCK);
while (xmlReader.hasNext()) {
xmlReader.next();
if (xmlReader.getEventType() == XMLStreamConstants.START_ELEMENT) {
if (XML_METADATA.equals(xmlReader.getLocalName())) {
FeedMetadata metadata = parseMetadataElement(xmlReader);
metadatas.add(metadata);
}
if (XML_CONTENT.equals(xmlReader.getLocalName())) {
FeedContent content = parseContentElement(xmlReader);
contents.add(content);
}
}
if (xmlReader.getEventType() == XMLStreamConstants.END_ELEMENT) {
if (XML_RECORD.equals(xmlReader.getLocalName())) {
break;
}
}
}
FeedRecord record = new FeedRecordImpl(datasource, feedtype, groupAction, url, displayurl, action, mimetype, lastModified, lock, authmethod,
contents, metadatas);
return record;
}
示例14: parseContentElement
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
private FeedContent parseContentElement(XMLStreamReader2 xmlReader) throws ParseFeedException, XMLStreamException {
//in content element
String encoding = xmlReader.getAttributeValue("", XML_CONTENT_ENCODING);
while (xmlReader.hasNext()) {
xmlReader.next();
if (xmlReader.getEventType() == XMLStreamConstants.CHARACTERS || xmlReader.getEventType() == XMLStreamConstants.CDATA) {
File temp = null;
try {
temp = File.createTempFile("constellio-feedprocessor", ".bin");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(temp);
Writer writer = new OutputStreamWriter(new BufferedOutputStream(fos));
xmlReader.getText(writer, false);
writer.flush();
} finally {
IOUtils.closeQuietly(fos);
}
FeedContent content = new FeedContentImpl(temp, encoding);
return content;
} catch (Exception e) {
FileUtils.deleteQuietly(temp);
e.printStackTrace();
}
}
if (xmlReader.getEventType() == XMLStreamConstants.END_ELEMENT) {
if (XML_CONTENT.equals(xmlReader.getLocalName())) {
break;
}
}
}
return null;
}
示例15: parse
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
public void parse(InputStream is) {
try {
XMLInputFactory2 inputFactory = XMLInputFactory2.class.cast(XMLInputFactory.newInstance());
XMLStreamReader2 reader =
XMLStreamReader2.class.cast(inputFactory.createXMLStreamReader(is, "UTF8"));
List<String> currentRow = null;
int columnIndex = -1;
int valueCount = -1;
int size = 0;
long startTime = 0;
StringBuilder currentValue = null;
while (reader.hasNext()) {
int type = reader.next();
switch (type) {
case XMLStreamReader.START_ELEMENT:
switch (reader.getLocalName()) {
case "table_data":
String tableName = reader.getAttributeValue(null, "name");
table = replicator.getTable(tableName);
rows = replicator.getS3Writer().getRowEnqueuer(table, finished);
startTime = System.currentTimeMillis() / 1000l;
populateColumnMap();
break;
case "field":
String fieldName = reader.getAttributeValue(null, "name");
columnIndex = columnMap.getOrDefault(fieldName, new Integer(-1));
break;
case "row":
currentRow = new ArrayList<>();
for (int i = 0, len = columnMap.size(); i != len; i++) {
currentRow.add(null);
}
rowIndex++;
valueCount = columnMap.size();
break;
}
break;
case XMLStreamReader.END_ELEMENT:
switch (reader.getLocalName()) {
case "table_data":
enqueueCurrentRows();
replicator.getRedshift().recordTableSize(table.name, System.currentTimeMillis() / 1000l - startTime);
table = null;
break;
case "row":
rows.add(currentRow);
if (valueCount != 0)
throw new RuntimeException(
String.format(
"value count was expected to be 0, was instead %s for table %s", valueCount, table.name));
size += currentRow.stream().mapToInt(v -> v == null ? 4 : v.length()).sum();
if (size > replicator.getConfig().s3.minimumSegmentSize) {
enqueueCurrentRows();
size = 0;
}
break;
case "field":
if (columnIndex != -1) {
currentRow.set(columnIndex, currentValue == null ? null : currentValue.toString());
currentValue = null;
valueCount--;
columnIndex = -1;
}
break;
}
break;
case XMLStreamReader.CHARACTERS:
if (columnIndex != -1) {
if (currentValue == null) currentValue = new StringBuilder();
currentValue.append(reader.getText());
}
break;
}
}
flush();
} catch (XMLStreamException e) {
throw new RuntimeException(e);
}
}