本文整理汇总了Java中org.codehaus.stax2.XMLStreamReader2.getEventType方法的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamReader2.getEventType方法的具体用法?Java XMLStreamReader2.getEventType怎么用?Java XMLStreamReader2.getEventType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.stax2.XMLStreamReader2
的用法示例。
在下文中一共展示了XMLStreamReader2.getEventType方法的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: 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)");
}
示例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: 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)");
}
示例7: 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)");
}
示例8: parseKeyInfo
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
private List<X509Certificate> parseKeyInfo(XMLStreamReader2 parser)
throws XMLStreamException, CertificateException {
ArrayList<X509Certificate> certs = new ArrayList<>();
for (int event = parser.getEventType(); event != XMLStreamConstants.END_ELEMENT
|| !"KeyDescriptor".equals(parser.getLocalName()); event = parser.next()) {
// Ignore everything but a start element
if (event != XMLStreamConstants.START_ELEMENT) {
continue;
}
String localName = parser.getLocalName();
switch (localName) {
case "X509Certificate":
String certString = parser.getElementText().replaceAll("\\s", "");
CertificateFactory fact = CertificateFactory.getInstance("X.509");
X509Certificate signingCert = (X509Certificate) fact
.generateCertificate(new ByteArrayInputStream(Base64.getDecoder().decode(certString.getBytes())));
certs.add(signingCert);
break;
default:
// Do nothing
break;
}
}
return certs;
}
示例9: 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;
}
示例10: 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;
}
示例11: 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;
}
示例12: parseSRG
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseSRG(NetPlan netPlan, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
long srgId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "id"));
double meanTimeToFailInHours = xmlStreamReader.getAttributeAsDouble(xmlStreamReader.getAttributeIndex(null, "meanTimeToFailInHours"));
double meanTimeToRepairInHours = xmlStreamReader.getAttributeAsDouble(xmlStreamReader.getAttributeIndex(null, "meanTimeToRepairInHours"));
SharedRiskGroup newSRG = netPlan.addSRG(meanTimeToFailInHours, meanTimeToRepairInHours, null);
mapOldId2Srg.put (srgId , newSRG);
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"));
newSRG.setAttribute(key, name);
break;
case "node":
long nodeId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "id"));
newSRG.addNode(mapOldId2Node.get(nodeId));
break;
case "link":
// long layerId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "layerId"));
long linkId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "linkId"));
newSRG.addLink(mapOldId2Link.get(linkId));
break;
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("srg")) return;
break;
}
}
throw new RuntimeException("'SRG' element not parsed correctly (end tag not found)");
}
示例13: parseDemand
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseDemand(NetPlan netPlan, long layerId, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
long demandId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "id"));
long ingressNodeId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "ingressNodeId"));
long egressNodeId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "egressNodeId"));
double offeredTraffic = xmlStreamReader.getAttributeAsDouble(xmlStreamReader.getAttributeIndex(null, "offeredTraffic"));
// netPlan.nextDemandId.put(layerId, demandId);
Demand newDemand = netPlan.addDemand(mapOldId2Node.get(ingressNodeId), mapOldId2Node.get(egressNodeId), offeredTraffic, null , mapOldId2Layer.get(layerId));
mapOldId2Demand.put (Pair.of (layerId , demandId) , newDemand);
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"));
newDemand.setAttribute(key, name);
break;
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("demand")) return;
break;
}
}
throw new RuntimeException("'Demand' element not parsed correctly (end tag not found)");
}
示例14: parseSpDescriptor
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
private SpSsoDescriptor parseSpDescriptor(XMLStreamReader2 parser)
throws XMLStreamException, CertificateException, NumberFormatException {
SpSsoDescriptor descriptor = new SpSsoDescriptor();
ArrayList<Endpoint> endpoints = new ArrayList<>();
List<String> nameIdFormats = new ArrayList<>();
for (int event = parser.getEventType(); event != XMLStreamConstants.END_ELEMENT
|| !"SPSSODescriptor".equals(parser.getLocalName()); event = parser.next()) {
// Ignore everything but a start element
if (event != XMLStreamConstants.START_ELEMENT) {
continue;
}
String localName = parser.getLocalName();
switch (localName) {
case "SPSSODescriptor":
descriptor.setAuthentRequestSigned(
Boolean.parseBoolean(parser.getAttributeValue(null, "AuthnRequestsSigned")));
descriptor.setWantAssertionsSigned(
Boolean.parseBoolean(parser.getAttributeValue(null, "WantAssertionsSigned")));
break;
case "KeyDescriptor":
if ("signing".equals(parser.getAttributeValue(null, "use"))) {
descriptor.setSigningCertificates(parseKeyInfo(parser));
}
break;
case "AssertionConsumerService":
Endpoint endpoint = new Endpoint();
endpoint.setBinding(parser.getAttributeValue(null, "Binding"));
endpoint.setLocation(parser.getAttributeValue(null, "Location"));
endpoint.setIndex(Integer.parseInt(parser.getAttributeValue(null, "index")));
endpoint.setDefault(Boolean.parseBoolean(parser.getAttributeValue(null, "isDefault")));
endpoints.add(endpoint);
break;
case "NameIDFormat":
nameIdFormats.add(parser.getElementText());
break;
default:
// Do nothing
break;
}
}
descriptor.setAssertionConsumerService(endpoints);
descriptor.setNameIDFormat(nameIdFormats);
return descriptor;
}
示例15: parseLink
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseLink(NetPlan netPlan, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
Map<String, String> attributeMap = new LinkedHashMap<String, String>();
double linkCapacity = 0;
double linkLengthInKm = 0;
long originNodeId = -1;
long destinationNodeId = -1;
int numAttributes = xmlStreamReader.getAttributeCount();
for(int i = 0; i < numAttributes; i++)
{
String localName = xmlStreamReader.getAttributeLocalName(i);
switch(localName)
{
case "originNodeId":
originNodeId = xmlStreamReader.getAttributeAsLong(i);
break;
case "destinationNodeId":
destinationNodeId = xmlStreamReader.getAttributeAsLong(i);
break;
case "linkCapacityInErlangs":
linkCapacity = xmlStreamReader.getAttributeAsDouble(i);
break;
case "linkLengthInKm":
linkLengthInKm = xmlStreamReader.getAttributeAsDouble(i);
break;
default:
attributeMap.put(localName, xmlStreamReader.getAttributeValue(i));
break;
}
}
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
throw new RuntimeException("No nested elements allowed for 'Link' element");
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("link"))
{
netPlan.addLink(netPlan.nodes.get((int) originNodeId), netPlan.nodes.get((int) destinationNodeId), linkCapacity, linkLengthInKm, 200000 , attributeMap);
return;
}
break;
}
}
throw new RuntimeException("'Link' element not parsed correctly (end tag not found)");
}