Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2013 SAP AG Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 package com.sap.core.odata.core.ep.consumer;
 
 import java.util.List;
 import java.util.Map;
 
 
 
 public class XmlFeedConsumer {

  
 
   public ODataFeed readFeed(final XMLStreamReader readerfinal EntityInfoAggregator eiafinal EntityProviderReadProperties readPropertiesthrows EntityProviderException {
     try {
       // read xml tag
       reader.require(.nullnull);
       reader.nextTag();
 
       // read feed tag
       Map<StringStringfoundPrefix2NamespaceUri = extractNamespacesFromTag(reader);
       foundPrefix2NamespaceUri.putAll(readProperties.getValidatedPrefixNamespaceUris());
       checkAllMandatoryNamespacesAvailable(foundPrefix2NamespaceUri);
       EntityProviderReadProperties entryReadProperties =
           EntityProviderReadProperties.initFrom(readProperties).addValidatedPrefixes(foundPrefix2NamespaceUri).build();
 
       // read feed data (metadata and entries)
       return readFeedData(readereiaentryReadProperties);
     } catch (XMLStreamException e) {
     }
   }

  
Read all feed specific data (like inline count and next link) as well as all feed entries (entry).

Parameters:
reader
eia
entryReadProperties
Returns:
Throws:
javax.xml.stream.XMLStreamException
com.sap.core.odata.api.ep.EntityProviderException
 
   private ODataFeed readFeedData(final XMLStreamReader readerfinal EntityInfoAggregator eiafinal EntityProviderReadProperties entryReadPropertiesthrows XMLStreamExceptionEntityProviderException {
     FeedMetadataImpl metadata = new FeedMetadataImpl();
     XmlEntryConsumer xec = new XmlEntryConsumer();
     List<ODataEntryresults = new ArrayList<ODataEntry>();
 
     while (reader.hasNext() && !isFeedEndTag(reader)) {
       if (..equals(reader.getLocalName())) {
         ODataEntry entry = xec.readEntry(readereiaentryReadProperties);
         results.add(entry);
       } else if (..equals(reader.getLocalName())) {
 
         reader.next();
         if (reader.hasText()) {
          String inlineCount = reader.getText();
          metadata.setInlineCount(Integer.valueOf(inlineCount));
        }
      } else if (..equals(reader.getLocalName())) {
        final String rel = reader.getAttributeValue(null.);
        if (..equals(rel)) {
          final String uri = reader.getAttributeValue(null.);
          metadata.setNextLink(uri);
        }
        reader.next();
      } else {
        reader.next();
      }
      readTillNextStartTag(reader);
    }
    return new ODataFeedImpl(resultsmetadata);
  }
  private void readTillNextStartTag(final XMLStreamReader readerthrows XMLStreamException {
    while (reader.hasNext() && !reader.isStartElement()) {
      reader.next();
    }
  }
  private boolean isFeedEndTag(final XMLStreamReader reader) {
    return reader.isEndElement()
        && ..equals(reader.getNamespaceURI())
        && ..equals(reader.getLocalName());
  }

  

Parameters:
reader
Returns:
Throws:
com.sap.core.odata.api.ep.EntityProviderException
    // collect namespaces
    Map<StringStringfoundPrefix2NamespaceUri = new HashMap<StringString>();
    int namespaceCount = reader.getNamespaceCount();
    for (int i = 0; i < namespaceCounti++) {
      String namespacePrefix = reader.getNamespacePrefix(i);
      String namespaceUri = reader.getNamespaceURI(i);
      foundPrefix2NamespaceUri.put(namespacePrefixnamespaceUri);
    }
    return foundPrefix2NamespaceUri;
  }

  

Parameters:
foundPrefix2NamespaceUri
Throws:
com.sap.core.odata.api.ep.EntityProviderException
  private void checkAllMandatoryNamespacesAvailable(final Map<StringStringfoundPrefix2NamespaceUrithrows EntityProviderException {
    if (!foundPrefix2NamespaceUri.containsValue(.)) {
    } else if (!foundPrefix2NamespaceUri.containsValue(.)) {
    } else if (!foundPrefix2NamespaceUri.containsValue(.)) {
    }
  }
New to GrepCode? Check out our FAQ X