You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2014/04/02 10:55:50 UTC
[2/2] git commit: [OLINGO-231] Initial PoC. Read metadata from
Android work
[OLINGO-231] Initial PoC. Read metadata from Android work
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/fe9e2edc
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/fe9e2edc
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/fe9e2edc
Branch: refs/heads/OLINGO-231_PocForAndroid
Commit: fe9e2edc83f8d8187d06c26cc1cc1366690c46e9
Parents: 1f37db3
Author: Michael Bolz <mi...@apache.org>
Authored: Wed Apr 2 10:50:03 2014 +0200
Committer: Michael Bolz <mi...@apache.org>
Committed: Wed Apr 2 10:53:47 2014 +0200
----------------------------------------------------------------------
odata2-android/pom.xml | 99 +++++++
.../odata2/android/xml/AndroidXmlReader.java | 297 +++++++++++++++++++
.../android/xml/AndroidXmlReaderFactory.java | 12 +
.../odata2/api/edm/provider/EdmProvider.java | 4 +-
.../olingo/odata2/core/commons/XmlHelper.java | 19 +-
.../provider/EdmServiceMetadataImplProv.java | 10 +-
.../odata2/core/edm/provider/EdmxProvider.java | 25 +-
.../odata2/core/ep/BasicEntityProvider.java | 9 +-
.../consumer/AtomServiceDocumentConsumer.java | 36 +--
.../core/ep/consumer/XmlEntityConsumer.java | 5 +-
.../core/ep/consumer/XmlEntryConsumer.java | 9 +-
.../ep/consumer/XmlErrorDocumentConsumer.java | 17 +-
.../core/ep/consumer/XmlFeedConsumer.java | 7 +-
.../core/ep/consumer/XmlLinkConsumer.java | 7 +-
.../core/ep/consumer/XmlMetadataConsumer.java | 7 +-
.../core/ep/consumer/XmlPropertyConsumer.java | 7 +-
.../core/ep/producer/XmlMetadataProducer.java | 8 +-
.../odata2/core/xml/JavaxStaxReaderWrapper.java | 234 +++++++++++++++
.../odata2/core/xml/JavaxStaxWriterWrapper.java | 171 +++++++++++
.../odata2/core/xml/NamespaceContext.java | 28 ++
.../apache/olingo/odata2/core/xml/QName.java | 33 +++
.../odata2/core/xml/XMLStreamConstants.java | 39 +++
.../odata2/core/xml/XMLStreamException.java | 36 +++
.../olingo/odata2/core/xml/XMLStreamReader.java | 101 +++++++
.../olingo/odata2/core/xml/XMLStreamWriter.java | 72 +++++
.../odata2/core/xml/XMLStreamWriterFactory.java | 44 +++
.../odata2/core/commons/XmlHelperTest.java | 211 -------------
.../core/ep/consumer/AbstractConsumerTest.java | 48 +--
.../AtomServiceDocumentConsumerTest.java | 11 +-
.../core/ep/consumer/XmlLinkConsumerTest.java | 3 +-
.../ep/consumer/XmlMetadataConsumerTest.java | 59 +---
.../ep/consumer/XmlPropertyConsumerTest.java | 3 +-
.../ep/producer/XmlMetadataProducerTest.java | 12 +-
33 files changed, 1285 insertions(+), 398 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-android/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-android/pom.xml b/odata2-android/pom.xml
new file mode 100644
index 0000000..4448fd8
--- /dev/null
+++ b/odata2-android/pom.xml
@@ -0,0 +1,99 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+-->
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-parent</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>olingo-odata2-android</artifactId>
+ <name>${project.artifactId}</name>
+
+<properties>
+ <version.android>4.1.1.4</version.android>
+</properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <executions>
+ <execution>
+ <id>bundle-manifest</id>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>manifest</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.apache.olingo.odata2.annotation.processor.core.rt;resolution:=optional,
+ *
+ </Import-Package>
+ <Export-Package>
+ org.apache.olingo.odata2.android.xml;version=${project.version},
+ org.apache.olingo.odata2.android.xml.*;version=${project.version}
+ </Export-Package>
+ <Bundle-DocURL>${project.url}</Bundle-DocURL>
+ <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.google.android</groupId>
+ <artifactId>android</artifactId>
+ <version>${version.android}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlReader.java
----------------------------------------------------------------------
diff --git a/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlReader.java b/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlReader.java
new file mode 100644
index 0000000..9f9741b
--- /dev/null
+++ b/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlReader.java
@@ -0,0 +1,297 @@
+package org.apache.olingo.odata2.android.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.olingo.odata2.core.xml.NamespaceContext;
+import org.apache.olingo.odata2.core.xml.QName;
+import org.apache.olingo.odata2.core.xml.XMLStreamConstants;
+import org.apache.olingo.odata2.core.xml.XMLStreamException;
+import org.apache.olingo.odata2.core.xml.XMLStreamReader;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+import android.util.Xml;
+
+public class AndroidXmlReader extends XMLStreamReader {
+
+ private final InputStream xmlContentStream;
+ private final XmlPullParser parser;
+
+ public AndroidXmlReader(Object content) {
+ if(content instanceof InputStream) {
+ parser = Xml.newPullParser();
+ this.xmlContentStream = (InputStream) content;
+
+ try {
+ parser.setInput(xmlContentStream, null);
+ } catch (XmlPullParserException e) {
+ throw new RuntimeException("Error during AndroidXmlReader init", e);
+ }
+ } else {
+ throw new IllegalArgumentException("Unsupported input content. Only InputStream is supported.");
+ }
+ }
+
+ @Override
+ public void close() throws XMLStreamException {
+ }
+
+ @Override
+ public int getAttributeCount() {
+ return parser.getAttributeCount();
+ }
+
+ @Override
+ public String getAttributeLocalName(int arg0) {
+ return parser.getAttributeName(arg0);
+ }
+
+ @Override
+ public String getAttributeNamespace(int arg0) {
+ return parser.getAttributeName(arg0);
+ }
+
+ @Override
+ public String getAttributePrefix(int arg0) {
+ return parser.getAttributePrefix(arg0);
+ }
+
+ @Override
+ public String getAttributeValue(int arg0) {
+ return parser.getAttributeValue(arg0);
+ }
+
+ @Override
+ public String getAttributeValue(String arg0, String arg1) {
+ String attributeValue = parser.getAttributeValue(arg0, arg1);
+ return attributeValue;
+ }
+
+ @Override
+ public String getElementText() throws XMLStreamException {
+ // FIXME
+ return parser.getText();
+ }
+
+ @Override
+ public String getLocalName() {
+ // FIXME
+ String name = parser.getName();
+ return name;
+ }
+
+ @Override
+ public QName getName() {
+ // FIXME
+ QName qname = new QName(getNamespaceURI()) {};
+ return qname;
+ }
+
+ @Override
+ public NamespaceContext getNamespaceContext() {
+ String tmp = null;
+ try {
+ int depth = parser.getDepth();
+ tmp = parser.getNamespacePrefix(depth);
+ } catch (XmlPullParserException e) {
+ e.printStackTrace();
+ }
+ final String prefix = tmp;
+ // TODO Auto-generated method stub
+ NamespaceContext nctx = new NamespaceContext() {
+ @Override
+ public String getPrefix(String arg0) {
+ return prefix;
+ }
+ };
+ return nctx;
+ }
+
+ @Override
+ public int getNamespaceCount() {
+ // FIXME
+ try {
+ int depth = parser.getDepth();
+ int nsStart = parser.getNamespaceCount(depth-1);
+ int nsEnd = parser.getNamespaceCount(depth);
+ int nsCount = nsEnd - nsStart;
+ return nsCount;
+ } catch (XmlPullParserException e) {
+ e.printStackTrace();
+ return -1;
+ }
+ }
+
+ @Override
+ public String getNamespacePrefix(int arg0) {
+ // FIXME
+ try {
+ return parser.getNamespacePrefix(arg0);
+ } catch (XmlPullParserException e) {
+ e.printStackTrace();
+ throw new RuntimeException("Android", e);
+ }
+ }
+
+ @Override
+ public String getNamespaceURI() {
+ // FIXME
+// try {
+// int depth = parser.getDepth();
+// String nsUri = parser.getNamespaceUri(depth);
+// return nsUri;
+// } catch (XmlPullParserException e) {
+// e.printStackTrace();
+// throw new RuntimeException("Android", e);
+// }
+ String nsUri = parser.getNamespace();
+ return nsUri;
+ }
+
+
+
+ @Override
+ public String getNamespaceURI(int index) {
+ // FIXME
+ try {
+ int nsCount = getNamespaceCount();
+ if(index > nsCount) {
+ throw new RuntimeException("Out of namespace index");
+ }
+ int depthAndIndex = parser.getDepth() + index;
+ String namespaceUri = parser.getNamespaceUri(depthAndIndex);
+ return namespaceUri;
+ } catch (XmlPullParserException e) {
+ e.printStackTrace();
+ throw new RuntimeException("Android", e);
+ }
+ }
+
+ @Override
+ public String getNamespaceURI(String arg0) {
+ // FIXME
+ String namespaceUri = parser.getNamespace(arg0);
+ return namespaceUri;
+ }
+
+ @Override
+ public String getPrefix() {
+ return parser.getPrefix();
+ }
+
+ @Override
+ public String getText() {
+ return parser.getText();
+ }
+
+ @Override
+ public boolean hasName() {
+ // FIXME
+ return parser.getName() != null;
+ }
+
+ @Override
+ public boolean hasNext() throws XMLStreamException {
+ // TODO Auto-generated method stub
+ int eventType;
+ try {
+ eventType = parser.getEventType();
+ } catch (XmlPullParserException e) {
+ throw new RuntimeException("Android", e);
+ }
+ return eventType != XmlPullParser.END_DOCUMENT;
+ }
+
+ @Override
+ public boolean isCharacters() {
+ // FIXME
+ try {
+ return !parser.isWhitespace();
+ } catch (XmlPullParserException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ @Override
+ public boolean isEndElement() {
+ // TODO Auto-generated method stub
+ try {
+ int eventType = parser.getEventType();
+ return eventType == XmlPullParser.END_DOCUMENT
+ || eventType == XmlPullParser.END_TAG;
+ } catch (XmlPullParserException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ throw new RuntimeException("Android", e);
+ }
+ }
+
+ @Override
+ public boolean isStartElement() {
+ try {
+ int eventType = parser.getEventType();
+ return eventType == XmlPullParser.START_DOCUMENT
+ || eventType == XmlPullParser.START_TAG;
+ } catch (XmlPullParserException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ throw new RuntimeException("Android", e);
+ }
+ }
+
+ @Override
+ public void next() throws XMLStreamException {
+ try {
+ parser.next();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ throw new RuntimeException("Android", e);
+ }
+ }
+
+ @Override
+ public int nextTag() throws XMLStreamException {
+ try {
+ return parser.nextTag();
+ } catch (XmlPullParserException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ throw new RuntimeException("Android", e);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ throw new RuntimeException("Android", e);
+ }
+ }
+
+ @Override
+ public void require(int eventType, String arg1, String arg2) throws XMLStreamException {
+ // TODO Auto-generated method stub
+ try {
+ int xmlPullEventType = mapEventType(eventType);
+ parser.require(xmlPullEventType, arg1, arg2);
+ } catch (XmlPullParserException e) {
+ throw new XMLStreamException("Requirement not fulfilled", e) {};
+ } catch (IOException e) {
+ throw new RuntimeException("Android", e);
+ }
+ }
+
+ private int mapEventType(int eventType) {
+ switch (eventType) {
+ case XMLStreamConstants.START_ELEMENT: return XmlPullParser.START_TAG;
+ case XMLStreamConstants.END_ELEMENT: return XmlPullParser.END_TAG;
+ case XMLStreamConstants.START_DOCUMENT: return XmlPullParser.START_DOCUMENT;
+ case XMLStreamConstants.END_DOCUMENT: return XmlPullParser.END_DOCUMENT;
+ case XMLStreamConstants.DTD: return XmlPullParser.DOCDECL;
+ default:
+ throw new IllegalArgumentException("Unknown event type ('" +
+ eventType + "') for mapping.");
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlReaderFactory.java
----------------------------------------------------------------------
diff --git a/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlReaderFactory.java b/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlReaderFactory.java
new file mode 100644
index 0000000..9bc0035
--- /dev/null
+++ b/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlReaderFactory.java
@@ -0,0 +1,12 @@
+package org.apache.olingo.odata2.android.xml;
+
+import org.apache.olingo.odata2.core.xml.XMLStreamReader;
+import org.apache.olingo.odata2.core.xml.XMLStreamReader.XMLStreamReaderFactory;
+
+public class AndroidXmlReaderFactory implements XMLStreamReaderFactory {
+
+ @Override
+ public XMLStreamReader createXMLStreamReader(Object content) {
+ return new AndroidXmlReader(content);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/provider/EdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/provider/EdmProvider.java b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/provider/EdmProvider.java
index 5795369..28d7513 100644
--- a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/provider/EdmProvider.java
+++ b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/provider/EdmProvider.java
@@ -18,11 +18,11 @@
******************************************************************************/
package org.apache.olingo.odata2.api.edm.provider;
-import java.util.List;
-
import org.apache.olingo.odata2.api.edm.FullQualifiedName;
import org.apache.olingo.odata2.api.exception.ODataException;
+import java.util.List;
+
/**
* Default EDM Provider which is to be extended by the application
*
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/XmlHelper.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/XmlHelper.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/XmlHelper.java
index 3433186..c068f2f 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/XmlHelper.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/XmlHelper.java
@@ -18,12 +18,6 @@
******************************************************************************/
package org.apache.olingo.odata2.core.commons;
-import java.io.InputStream;
-
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
import org.apache.olingo.odata2.api.ep.EntityProviderException;
public class XmlHelper {
@@ -31,7 +25,14 @@ public class XmlHelper {
/** Default used charset for reader */
private static final String DEFAULT_CHARSET = "UTF-8";
- public static XMLStreamReader createStreamReader(final Object content) throws EntityProviderException {
+ public static org.apache.olingo.odata2.core.xml.XMLStreamReader createStreamReader(final Object content)
+ throws EntityProviderException {
+ return org.apache.olingo.odata2.core.xml.XMLStreamReader.createXMLStreamReader(content);
+ }
+
+
+ /*
+ public static XMLStreamReader createStreamReaderJavax(final Object content) throws EntityProviderException {
if (content == null) {
throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT
.addContent("Got not allowed NULL parameter for creation of XMLStreamReader."));
@@ -45,7 +46,7 @@ public class XmlHelper {
factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
if (content instanceof InputStream) {
- streamReader = factory.createXMLStreamReader((InputStream) content, DEFAULT_CHARSET);
+ streamReader = factory.createXMLStreamWriter((InputStream) content, DEFAULT_CHARSET);
// verify charset encoding set in content is supported (if not set UTF-8 is used as defined in
// v'http://www.w3.org/TR/2008/REC-xml-20081126/')
String characterEncodingInContent = streamReader.getCharacterEncodingScheme();
@@ -63,5 +64,5 @@ public class XmlHelper {
.getSimpleName()), e);
}
}
-
+*/
}
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/provider/EdmServiceMetadataImplProv.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/provider/EdmServiceMetadataImplProv.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/provider/EdmServiceMetadataImplProv.java
index 16262fc..c1de8fe 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/provider/EdmServiceMetadataImplProv.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/provider/EdmServiceMetadataImplProv.java
@@ -25,10 +25,6 @@ import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
import org.apache.olingo.odata2.api.ODataServiceVersion;
import org.apache.olingo.odata2.api.edm.EdmEntitySetInfo;
import org.apache.olingo.odata2.api.edm.EdmServiceMetadata;
@@ -43,6 +39,9 @@ import org.apache.olingo.odata2.api.ep.EntityProviderException;
import org.apache.olingo.odata2.api.exception.ODataException;
import org.apache.olingo.odata2.core.ep.producer.XmlMetadataProducer;
import org.apache.olingo.odata2.core.ep.util.CircleStreamBuffer;
+import org.apache.olingo.odata2.core.xml.XMLStreamException;
+import org.apache.olingo.odata2.core.xml.XMLStreamWriter;
+import org.apache.olingo.odata2.core.xml.XMLStreamWriterFactory;
/**
*
@@ -71,7 +70,8 @@ public class EdmServiceMetadataImplProv implements EdmServiceMetadata {
try {
writer = new OutputStreamWriter(csb.getOutputStream(), "UTF-8");
- XMLStreamWriter xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+ XMLStreamWriterFactory xmlStreamWriterFactory = XMLStreamWriterFactory.create();
+ XMLStreamWriter xmlStreamWriter = xmlStreamWriterFactory.createXMLStreamWriter(writer);
XmlMetadataProducer.writeMetadata(metadata, xmlStreamWriter, null);
return csb.getInputStream();
} catch (XMLStreamException e) {
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/provider/EdmxProvider.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/provider/EdmxProvider.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/provider/EdmxProvider.java
index f7aba8f..06c7e06 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/provider/EdmxProvider.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/provider/EdmxProvider.java
@@ -18,36 +18,23 @@
******************************************************************************/
package org.apache.olingo.odata2.core.edm.provider;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.stream.XMLStreamReader;
-
import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.AliasInfo;
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.DataServices;
-import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
-import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
-import org.apache.olingo.odata2.api.edm.provider.EntitySet;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
-import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.api.edm.provider.*;
import org.apache.olingo.odata2.api.ep.EntityProviderException;
import org.apache.olingo.odata2.api.exception.ODataException;
import org.apache.olingo.odata2.core.commons.XmlHelper;
import org.apache.olingo.odata2.core.ep.consumer.XmlMetadataConsumer;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
public class EdmxProvider extends EdmProvider {
private DataServices dataServices;
public EdmxProvider parse(final InputStream in, final boolean validate) throws EntityProviderException {
XmlMetadataConsumer parser = new XmlMetadataConsumer();
- XMLStreamReader streamReader = XmlHelper.createStreamReader(in);
+ org.apache.olingo.odata2.core.xml.XMLStreamReader streamReader = XmlHelper.createStreamReader(in);
dataServices = parser.readMetadata(streamReader, validate);
return this;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/BasicEntityProvider.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/BasicEntityProvider.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/BasicEntityProvider.java
index a32b916..467201d 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/BasicEntityProvider.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/BasicEntityProvider.java
@@ -31,9 +31,6 @@ import java.util.List;
import java.util.Map;
import javax.xml.stream.FactoryConfigurationError;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
import org.apache.olingo.odata2.api.ODataServiceVersion;
import org.apache.olingo.odata2.api.commons.HttpContentType;
@@ -53,6 +50,9 @@ import org.apache.olingo.odata2.api.processor.ODataResponse;
import org.apache.olingo.odata2.api.processor.ODataResponse.ODataResponseBuilder;
import org.apache.olingo.odata2.core.ep.producer.XmlMetadataProducer;
import org.apache.olingo.odata2.core.ep.util.CircleStreamBuffer;
+import org.apache.olingo.odata2.core.xml.XMLStreamException;
+import org.apache.olingo.odata2.core.xml.XMLStreamWriter;
+import org.apache.olingo.odata2.core.xml.XMLStreamWriterFactory;
/**
* Provider for all basic (content type independent) entity provider methods.
@@ -247,7 +247,8 @@ public class BasicEntityProvider {
CircleStreamBuffer csb = new CircleStreamBuffer();
try {
writer = new OutputStreamWriter(csb.getOutputStream(), DEFAULT_CHARSET);
- XMLStreamWriter xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+ XMLStreamWriterFactory xmlStreamWriterFactory = XMLStreamWriterFactory.create();
+ XMLStreamWriter xmlStreamWriter = xmlStreamWriterFactory.createXMLStreamWriter(writer);
XmlMetadataProducer.writeMetadata(metadata, xmlStreamWriter, predefinedNamespaces);
} catch (UnsupportedEncodingException e) {
throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass()
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/AtomServiceDocumentConsumer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/AtomServiceDocumentConsumer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/AtomServiceDocumentConsumer.java
index 4ce8a9c..5dcbc19 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/AtomServiceDocumentConsumer.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/AtomServiceDocumentConsumer.java
@@ -18,37 +18,19 @@
******************************************************************************/
package org.apache.olingo.odata2.core.ep.consumer;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
import org.apache.olingo.odata2.api.edm.Edm;
import org.apache.olingo.odata2.api.ep.EntityProviderException;
-import org.apache.olingo.odata2.api.servicedocument.Accept;
-import org.apache.olingo.odata2.api.servicedocument.Categories;
-import org.apache.olingo.odata2.api.servicedocument.Category;
-import org.apache.olingo.odata2.api.servicedocument.Collection;
-import org.apache.olingo.odata2.api.servicedocument.ExtensionAttribute;
-import org.apache.olingo.odata2.api.servicedocument.ExtensionElement;
-import org.apache.olingo.odata2.api.servicedocument.Fixed;
-import org.apache.olingo.odata2.api.servicedocument.Workspace;
+import org.apache.olingo.odata2.api.servicedocument.*;
import org.apache.olingo.odata2.core.commons.XmlHelper;
import org.apache.olingo.odata2.core.ep.util.FormatXml;
-import org.apache.olingo.odata2.core.servicedocument.AcceptImpl;
-import org.apache.olingo.odata2.core.servicedocument.AtomInfoImpl;
-import org.apache.olingo.odata2.core.servicedocument.CategoriesImpl;
-import org.apache.olingo.odata2.core.servicedocument.CategoryImpl;
-import org.apache.olingo.odata2.core.servicedocument.CollectionImpl;
-import org.apache.olingo.odata2.core.servicedocument.CommonAttributesImpl;
-import org.apache.olingo.odata2.core.servicedocument.ExtensionAttributeImpl;
-import org.apache.olingo.odata2.core.servicedocument.ExtensionElementImpl;
-import org.apache.olingo.odata2.core.servicedocument.ServiceDocumentImpl;
-import org.apache.olingo.odata2.core.servicedocument.TitleImpl;
-import org.apache.olingo.odata2.core.servicedocument.WorkspaceImpl;
+import org.apache.olingo.odata2.core.servicedocument.*;
+import org.apache.olingo.odata2.core.xml.XMLStreamConstants;
+import org.apache.olingo.odata2.core.xml.XMLStreamException;
+import org.apache.olingo.odata2.core.xml.XMLStreamReader;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
public class AtomServiceDocumentConsumer {
private String currentHandledStartTagName;
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlEntityConsumer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlEntityConsumer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlEntityConsumer.java
index c7fca98..3034574 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlEntityConsumer.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlEntityConsumer.java
@@ -23,9 +23,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.edm.EdmException;
import org.apache.olingo.odata2.api.edm.EdmProperty;
@@ -36,6 +33,8 @@ import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
import org.apache.olingo.odata2.api.ep.feed.ODataDeltaFeed;
import org.apache.olingo.odata2.core.commons.XmlHelper;
import org.apache.olingo.odata2.core.ep.aggregator.EntityInfoAggregator;
+import org.apache.olingo.odata2.core.xml.XMLStreamException;
+import org.apache.olingo.odata2.core.xml.XMLStreamReader;
/**
* Xml entity (content type dependent) consumer for reading input (from <code>content</code>).
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlEntryConsumer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlEntryConsumer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlEntryConsumer.java
index 6b9cd5f..e514b89 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlEntryConsumer.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlEntryConsumer.java
@@ -23,11 +23,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
import org.apache.olingo.odata2.api.edm.Edm;
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.edm.EdmException;
@@ -55,6 +50,10 @@ import org.apache.olingo.odata2.core.ep.feed.FeedMetadataImpl;
import org.apache.olingo.odata2.core.ep.feed.ODataDeltaFeedImpl;
import org.apache.olingo.odata2.core.ep.util.FormatXml;
import org.apache.olingo.odata2.core.uri.ExpandSelectTreeNodeImpl;
+import org.apache.olingo.odata2.core.xml.NamespaceContext;
+import org.apache.olingo.odata2.core.xml.XMLStreamConstants;
+import org.apache.olingo.odata2.core.xml.XMLStreamException;
+import org.apache.olingo.odata2.core.xml.XMLStreamReader;
/**
* Atom/XML format reader/consumer for entries.
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlErrorDocumentConsumer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlErrorDocumentConsumer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlErrorDocumentConsumer.java
index 661e5c7..e87494a 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlErrorDocumentConsumer.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlErrorDocumentConsumer.java
@@ -18,21 +18,20 @@
******************************************************************************/
package org.apache.olingo.odata2.core.ep.consumer;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
import org.apache.olingo.odata2.api.edm.Edm;
import org.apache.olingo.odata2.api.ep.EntityProviderException;
import org.apache.olingo.odata2.api.processor.ODataErrorContext;
import org.apache.olingo.odata2.core.commons.ContentType;
import org.apache.olingo.odata2.core.commons.XmlHelper;
import org.apache.olingo.odata2.core.ep.util.FormatXml;
+import org.apache.olingo.odata2.core.xml.XMLStreamConstants;
+import org.apache.olingo.odata2.core.xml.XMLStreamException;
+import org.apache.olingo.odata2.core.xml.XMLStreamReader;
+
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
/**
* Consuming (read / deserialization) for OData error document in XML format.
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlFeedConsumer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlFeedConsumer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlFeedConsumer.java
index 2ffec2e..790c45c 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlFeedConsumer.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlFeedConsumer.java
@@ -24,10 +24,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
import org.apache.olingo.odata2.api.edm.Edm;
import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
@@ -42,6 +38,9 @@ import org.apache.olingo.odata2.core.ep.entry.DeletedEntryMetadataImpl;
import org.apache.olingo.odata2.core.ep.feed.FeedMetadataImpl;
import org.apache.olingo.odata2.core.ep.feed.ODataDeltaFeedImpl;
import org.apache.olingo.odata2.core.ep.util.FormatXml;
+import org.apache.olingo.odata2.core.xml.XMLStreamConstants;
+import org.apache.olingo.odata2.core.xml.XMLStreamException;
+import org.apache.olingo.odata2.core.xml.XMLStreamReader;
/**
* Atom/XML format reader/consumer for feeds.
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlLinkConsumer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlLinkConsumer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlLinkConsumer.java
index 404a05a..66e6112 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlLinkConsumer.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlLinkConsumer.java
@@ -21,14 +21,13 @@ package org.apache.olingo.odata2.core.ep.consumer;
import java.util.ArrayList;
import java.util.List;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
import org.apache.olingo.odata2.api.edm.Edm;
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.ep.EntityProviderException;
import org.apache.olingo.odata2.core.ep.util.FormatXml;
+import org.apache.olingo.odata2.core.xml.XMLStreamConstants;
+import org.apache.olingo.odata2.core.xml.XMLStreamException;
+import org.apache.olingo.odata2.core.xml.XMLStreamReader;
/**
*
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlMetadataConsumer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlMetadataConsumer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlMetadataConsumer.java
index e8677a1..9768bb0 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlMetadataConsumer.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlMetadataConsumer.java
@@ -25,10 +25,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
import org.apache.olingo.odata2.api.edm.Edm;
import org.apache.olingo.odata2.api.edm.EdmAction;
import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
@@ -66,6 +62,9 @@ import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
import org.apache.olingo.odata2.api.edm.provider.Using;
import org.apache.olingo.odata2.api.ep.EntityProviderException;
import org.apache.olingo.odata2.core.ep.util.XmlMetadataConstants;
+import org.apache.olingo.odata2.core.xml.XMLStreamConstants;
+import org.apache.olingo.odata2.core.xml.XMLStreamException;
+import org.apache.olingo.odata2.core.xml.XMLStreamReader;
public class XmlMetadataConsumer {
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlPropertyConsumer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlPropertyConsumer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlPropertyConsumer.java
index 28cacef..f7a1683 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlPropertyConsumer.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlPropertyConsumer.java
@@ -21,10 +21,6 @@ package org.apache.olingo.odata2.core.ep.consumer;
import java.util.HashMap;
import java.util.Map;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
import org.apache.olingo.odata2.api.edm.Edm;
import org.apache.olingo.odata2.api.edm.EdmException;
import org.apache.olingo.odata2.api.edm.EdmFacets;
@@ -38,6 +34,9 @@ import org.apache.olingo.odata2.core.ep.aggregator.EntityInfoAggregator;
import org.apache.olingo.odata2.core.ep.aggregator.EntityPropertyInfo;
import org.apache.olingo.odata2.core.ep.aggregator.EntityTypeMapping;
import org.apache.olingo.odata2.core.ep.util.FormatXml;
+import org.apache.olingo.odata2.core.xml.XMLStreamConstants;
+import org.apache.olingo.odata2.core.xml.XMLStreamException;
+import org.apache.olingo.odata2.core.xml.XMLStreamReader;
/**
*
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/XmlMetadataProducer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/XmlMetadataProducer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/XmlMetadataProducer.java
index 4ad3e3e..e144c1b 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/XmlMetadataProducer.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/XmlMetadataProducer.java
@@ -24,10 +24,6 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
-import javax.xml.stream.FactoryConfigurationError;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
import org.apache.olingo.odata2.api.edm.Edm;
import org.apache.olingo.odata2.api.edm.EdmFacets;
import org.apache.olingo.odata2.api.edm.provider.AnnotationAttribute;
@@ -59,6 +55,8 @@ import org.apache.olingo.odata2.api.edm.provider.Using;
import org.apache.olingo.odata2.api.ep.EntityProviderException;
import org.apache.olingo.odata2.core.ep.util.XmlMetadataConstants;
import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
+import org.apache.olingo.odata2.core.xml.XMLStreamException;
+import org.apache.olingo.odata2.core.xml.XMLStreamWriter;
public class XmlMetadataProducer {
@@ -421,8 +419,6 @@ public class XmlMetadataProducer {
xmlStreamWriter.flush();
} catch (XMLStreamException e) {
throw new EntityProviderException(EntityProviderException.COMMON, e);
- } catch (FactoryConfigurationError e) {
- throw new EntityProviderException(EntityProviderException.COMMON, e);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxReaderWrapper.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxReaderWrapper.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxReaderWrapper.java
new file mode 100644
index 0000000..f2a40c2
--- /dev/null
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxReaderWrapper.java
@@ -0,0 +1,234 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.odata2.core.xml;
+
+import org.apache.olingo.odata2.api.ep.EntityProviderException;
+
+import javax.xml.stream.XMLInputFactory;
+import java.io.InputStream;
+
+/**
+ */
+public class JavaxStaxReaderWrapper extends XMLStreamReader {
+
+ /** Default used charset for reader */
+ private static final String DEFAULT_CHARSET = "UTF-8";
+
+ public static XMLStreamReader createStreamReader(final Object content) throws EntityProviderException {
+ if (content == null) {
+ throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT
+ .addContent("Got not allowed NULL parameter for creation of XMLStreamReader."));
+ }
+ javax.xml.stream.XMLStreamReader streamReader;
+ try {
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ factory.setProperty(XMLInputFactory.IS_VALIDATING, false);
+ factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
+ factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
+ factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
+
+ if (content instanceof InputStream) {
+ streamReader = factory.createXMLStreamReader((InputStream) content, DEFAULT_CHARSET);
+ // verify charset encoding set in content is supported (if not set UTF-8 is used as defined in
+ // v'http://www.w3.org/TR/2008/REC-xml-20081126/')
+ String characterEncodingInContent = streamReader.getCharacterEncodingScheme();
+ if (characterEncodingInContent != null && !DEFAULT_CHARSET.equalsIgnoreCase(characterEncodingInContent)) {
+ throw new EntityProviderException(EntityProviderException
+ .UNSUPPORTED_CHARACTER_ENCODING.addContent(characterEncodingInContent));
+ }
+ } else {
+ throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT
+ .addContent("Found not supported content of class '" + content.getClass() + "' to de-serialize."));
+ }
+ return new JavaxStaxReaderWrapper(streamReader);
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass()
+ .getSimpleName()), e);
+ }
+ }
+
+ private final javax.xml.stream.XMLStreamReader reader;
+
+ public JavaxStaxReaderWrapper(javax.xml.stream.XMLStreamReader reader) {
+ this.reader = reader;
+ }
+
+ public String getLocalName() {
+ return reader.getLocalName();
+ }
+
+ public String getNamespaceURI() {
+ return reader.getNamespaceURI();
+ }
+
+ public String getNamespaceURI(int pos) {
+ return reader.getNamespaceURI(pos);
+ }
+
+ public void require(int startDocument, String namespace, String tag) throws XMLStreamException {
+ try {
+ reader.require(startDocument, namespace, tag);
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ public int nextTag() throws XMLStreamException {
+ try {
+ return reader.nextTag();
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ public boolean hasNext() throws XMLStreamException {
+ try {
+ return reader.hasNext();
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ public String getAttributeValue(String o, String atomRel) {
+ return reader.getAttributeValue(o, atomRel);
+ }
+
+ @Override
+ public String getAttributeValue(int pos) {
+ return reader.getAttributeValue(pos);
+ }
+
+ public String getElementText() throws XMLStreamException {
+ try {
+ return reader.getElementText();
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ public boolean isStartElement() {
+ return reader.isStartElement();
+ }
+
+ public void next() throws XMLStreamException {
+ try {
+ reader.next();
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ public boolean isEndElement() {
+ return reader.isEndElement();
+ }
+
+ public int getNamespaceCount() {
+ return reader.getNamespaceCount();
+ }
+
+ public String getNamespacePrefix(int i) {
+ return reader.getNamespacePrefix(i);
+ }
+
+ public NamespaceContext getNamespaceContext() {
+ return new JavaxNamespaceContext(reader.getNamespaceContext());
+ }
+
+ public QName getName() {
+ return new JavaxQName(reader.getName());
+ }
+
+ public String getNamespaceURI(String customPrefix) {
+ return reader.getNamespaceURI(customPrefix);
+ }
+
+ public boolean hasName() {
+ return reader.hasName();
+ }
+
+
+
+ @Override
+ public void close() throws XMLStreamException {
+ try {
+ reader.close();
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ @Override
+ public String getText() {
+ return reader.getText();
+ }
+
+ @Override
+ public boolean isCharacters() {
+ return reader.isCharacters();
+ }
+
+ @Override
+ public String getAttributeLocalName(int i) {
+ return reader.getAttributeLocalName(i);
+ }
+
+ @Override
+ public String getAttributeNamespace(int i) {
+ return reader.getAttributeNamespace(i);
+ }
+
+ @Override
+ public String getAttributePrefix(int i) {
+ return reader.getAttributePrefix(i);
+ }
+
+ @Override
+ public int getAttributeCount() {
+ return reader.getAttributeCount();
+ }
+
+ @Override
+ public String getPrefix() {
+ return reader.getPrefix();
+ }
+
+
+ public static class JavaxNamespaceContext extends NamespaceContext {
+ javax.xml.namespace.NamespaceContext namespaceContext;
+
+ public JavaxNamespaceContext(javax.xml.namespace.NamespaceContext namespaceContext) {
+ this.namespaceContext = namespaceContext;
+ }
+
+ @Override
+ public String getPrefix(String customNamespaceURI) {
+ return this.namespaceContext.getPrefix(customNamespaceURI);
+ }
+ }
+
+ public static class JavaxQName extends QName {
+ public JavaxQName(javax.xml.namespace.QName qname) {
+ this(qname.getNamespaceURI());
+ }
+
+ protected JavaxQName(String namespaceURI) {
+ super(namespaceURI);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxWriterWrapper.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxWriterWrapper.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxWriterWrapper.java
new file mode 100644
index 0000000..c686195
--- /dev/null
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxWriterWrapper.java
@@ -0,0 +1,171 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.odata2.core.xml;
+
+import javax.xml.stream.XMLOutputFactory;
+import java.io.OutputStream;
+import java.io.Writer;
+
+/**
+ */
+public class JavaxStaxWriterWrapper extends XMLStreamWriter {
+ private javax.xml.stream.XMLStreamWriter xmlStreamWriter;
+
+ @Override
+ public XMLStreamWriter createXMLStreamWriter(Object content) throws XMLStreamException {
+ if(content == null) {
+ throw new IllegalArgumentException("Unsupported NULL input content.");
+ }
+
+ try {
+ XMLOutputFactory xouf = XMLOutputFactory.newFactory();
+ if (content instanceof OutputStream) {
+ xmlStreamWriter = xouf.createXMLStreamWriter((OutputStream) content);
+ } else if (content instanceof Writer) {
+ xmlStreamWriter = xouf.createXMLStreamWriter((Writer) content);
+ } else {
+ throw new IllegalArgumentException("Unsupported input content with class type '" +
+ content.getClass() + "'.");
+ }
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new XMLStreamException(e);
+ }
+ return this;
+ }
+
+ public static XMLStreamWriter create(Object content) throws XMLStreamException {
+ return new JavaxStaxWriterWrapper().createXMLStreamWriter(content);
+ }
+
+ public void writeStartDocument() throws XMLStreamException {
+ try {
+ xmlStreamWriter.writeStartDocument();
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ public void setPrefix(String prefix, String uri) throws XMLStreamException {
+ try {
+ xmlStreamWriter.setPrefix(prefix, uri);
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new XMLStreamException(e);
+ }
+
+ }
+
+ public void setDefaultNamespace(String defaultNamespace) throws XMLStreamException {
+ try {
+ xmlStreamWriter.setDefaultNamespace(defaultNamespace);
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ public void writeStartElement(String namespaceUri, String localName) throws XMLStreamException {
+ try {
+ xmlStreamWriter.writeStartElement(namespaceUri, localName);
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ public void writeAttribute(String name, String value) throws XMLStreamException {
+ try {
+ xmlStreamWriter.writeAttribute(name, value);
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ public void writeAttribute(String prefix, String namespace, String name, String value) throws XMLStreamException {
+ try {
+ xmlStreamWriter.writeAttribute(prefix, namespace, name, value);
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ public void writeNamespace(String prefix, String namespace) throws XMLStreamException {
+ try {
+ xmlStreamWriter.writeNamespace(prefix, namespace);
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new XMLStreamException(e);
+ }
+
+ }
+
+ public void writeStartElement(String name) throws XMLStreamException {
+ try {
+ xmlStreamWriter.writeStartElement(name);
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new XMLStreamException(e);
+ }
+
+ }
+
+ public void writeDefaultNamespace(String namespace) throws XMLStreamException {
+ try {
+ xmlStreamWriter.writeDefaultNamespace(namespace);
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new XMLStreamException(e);
+ }
+
+ }
+
+ public void writeEndElement() throws XMLStreamException {
+ try {
+ xmlStreamWriter.writeEndElement();
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ public void writeEndDocument() throws XMLStreamException {
+ try {
+ xmlStreamWriter.writeEndDocument();
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ public void flush() throws XMLStreamException {
+ try {
+ xmlStreamWriter.flush();
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ public void writeCharacters(String text) throws XMLStreamException {
+ try {
+ xmlStreamWriter.writeCharacters(text);
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ public void writeStartElement(String prefix, String name, String namespace) throws XMLStreamException {
+ try {
+ xmlStreamWriter.writeStartElement(prefix, name, namespace);
+ } catch (javax.xml.stream.XMLStreamException e) {
+ throw new XMLStreamException(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/NamespaceContext.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/NamespaceContext.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/NamespaceContext.java
new file mode 100644
index 0000000..d4f4329
--- /dev/null
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/NamespaceContext.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.odata2.core.xml;
+
+/**
+ */
+public abstract class NamespaceContext {
+ protected String prefix;
+ public String getPrefix(String customNamespaceURI) {
+ return prefix;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/QName.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/QName.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/QName.java
new file mode 100644
index 0000000..a18384e
--- /dev/null
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/QName.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.odata2.core.xml;
+
+/**
+ */
+public abstract class QName {
+ private String namespaceURI;
+
+ protected QName(String namespaceURI) {
+ this.namespaceURI = namespaceURI;
+ }
+
+ public String getNamespaceURI() {
+ return namespaceURI;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamConstants.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamConstants.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamConstants.java
new file mode 100644
index 0000000..5ff403e
--- /dev/null
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamConstants.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.odata2.core.xml;
+
+/**
+ */
+public interface XMLStreamConstants {
+ int START_ELEMENT = 1;
+ int END_ELEMENT = 2;
+// int PROCESSING_INSTRUCTION = 3;
+// int CHARACTERS = 4;
+// int COMMENT = 5;
+// int SPACE = 6;
+ int START_DOCUMENT = 7;
+ int END_DOCUMENT = 8;
+// int ENTITY_REFERENCE = 9;
+// int ATTRIBUTE = 10;
+ int DTD = 11;
+// int CDATA = 12;
+// int NAMESPACE = 13;
+// int NOTATION_DECLARATION = 14;
+// int ENTITY_DECLARATION = 15;
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamException.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamException.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamException.java
new file mode 100644
index 0000000..5a13f96
--- /dev/null
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamException.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.odata2.core.xml;
+
+/**
+ */
+public class XMLStreamException extends Exception {
+ public XMLStreamException() {
+ super();
+ }
+ public XMLStreamException(Throwable e) {
+ super(e);
+ }
+ public XMLStreamException(String message) {
+ super(message);
+ }
+ public XMLStreamException(String message, Throwable e) {
+ super(message, e);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamReader.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamReader.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamReader.java
new file mode 100644
index 0000000..083b2d5
--- /dev/null
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamReader.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.odata2.core.xml;
+
+
+import org.apache.olingo.odata2.api.ep.EntityProviderException;
+
+/**
+ */
+public abstract class XMLStreamReader {
+
+ public static final String XML_STREAM_READER_FACTORY_CLASS = "XMLStreamReaderFactoryClass";
+
+ public static XMLStreamReader createXMLStreamReader(Object content) throws EntityProviderException {
+ String factory = System.getProperty(XML_STREAM_READER_FACTORY_CLASS);
+ if(factory != null) {
+ try {
+// System.out.println("Load stream reader factory class: " + factory);
+ Class factoryClass = Class.forName(factory);
+ XMLStreamReaderFactory factoryInstance = (XMLStreamReaderFactory) factoryClass.newInstance();
+ return factoryInstance.createXMLStreamReader(content);
+ } catch (Exception e) {
+ throw new EntityProviderException(
+ EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getMessage()));
+ }
+ }
+ return JavaxStaxReaderWrapper.createStreamReader(content);
+ }
+
+ public interface XMLStreamReaderFactory {
+ XMLStreamReader createXMLStreamReader(Object content);
+ }
+
+ public abstract String getLocalName();
+
+ public abstract String getNamespaceURI();
+
+ public abstract String getNamespaceURI(int pos);
+
+ public abstract void require(int startDocument, String namespace, String tag) throws XMLStreamException;
+
+ public abstract int nextTag() throws XMLStreamException;
+
+ public abstract boolean hasNext() throws XMLStreamException;
+
+ public abstract String getAttributeValue(String o, String atomRel);
+
+ public abstract String getAttributeValue(int pos);
+
+ public abstract String getElementText() throws XMLStreamException;
+
+ public abstract boolean isStartElement();
+
+ public abstract void next() throws XMLStreamException;
+
+ public abstract boolean isEndElement();
+
+ public abstract int getNamespaceCount();
+
+ public abstract String getNamespacePrefix(int i);
+
+ public abstract NamespaceContext getNamespaceContext();
+
+ public abstract QName getName();
+
+ public abstract String getNamespaceURI(String customPrefix);
+
+ public abstract boolean hasName();
+
+ public abstract void close() throws XMLStreamException;
+
+ public abstract String getText();
+
+ public abstract boolean isCharacters();
+
+ public abstract String getAttributeLocalName(int i);
+
+ public abstract String getAttributeNamespace(int i);
+
+ public abstract String getAttributePrefix(int i);
+
+ public abstract int getAttributeCount();
+
+ public abstract String getPrefix();
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamWriter.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamWriter.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamWriter.java
new file mode 100644
index 0000000..0726350
--- /dev/null
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamWriter.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.odata2.core.xml;
+
+/**
+ */
+public abstract class XMLStreamWriter extends XMLStreamWriterFactory {
+
+// public static XMLStreamWriter createXMLStreamWriter(Object content)
+// throws EntityProviderException, XMLStreamException {
+//
+// String factory = System.getProperty(XML_STREAM_WRITER_FACTORY_CLASS);
+// if (factory != null) {
+// try {
+// Class factoryClass = Class.forName(factory);
+// XMLStreamWriterFactory factoryInstance = (XMLStreamWriterFactory) factoryClass.newInstance();
+// return factoryInstance.createXMLStreamWriter(content);
+// } catch (Exception e) {
+// throw new EntityProviderException(
+// EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getMessage()));
+// }
+// }
+// return new JavaxStaxWriterWrapper.createXmlStreamReader(content);
+// }
+
+
+
+ public abstract void writeStartDocument() throws XMLStreamException;
+
+ public abstract void setPrefix(String prefixEdmx, String namespaceEdmx200706) throws XMLStreamException;
+
+ public abstract void setDefaultNamespace(String defaultNamespace) throws XMLStreamException;
+
+ public abstract void writeStartElement(String namespaceEdmx200706, String edmx) throws XMLStreamException;
+
+ public abstract void writeAttribute(String name, String value) throws XMLStreamException;
+
+ public abstract void writeAttribute(String prefix, String namespace, String name, String
+ value) throws XMLStreamException;
+
+ public abstract void writeNamespace(String prefix, String namespace) throws XMLStreamException;
+
+ public abstract void writeStartElement(String name) throws XMLStreamException;
+
+ public abstract void writeDefaultNamespace(String namespace) throws XMLStreamException;
+
+ public abstract void writeEndElement() throws XMLStreamException;
+
+ public abstract void writeEndDocument() throws XMLStreamException;
+
+ public abstract void flush() throws XMLStreamException;
+
+ public abstract void writeCharacters(String text) throws XMLStreamException;
+
+ public abstract void writeStartElement(String prefix, String name, String namespace) throws XMLStreamException;
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamWriterFactory.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamWriterFactory.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamWriterFactory.java
new file mode 100644
index 0000000..4875d44
--- /dev/null
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamWriterFactory.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.odata2.core.xml;
+
+import org.apache.olingo.odata2.api.ep.EntityProviderException;
+
+/**
+ * Created by d046871 on 02.04.14.
+ */
+public abstract class XMLStreamWriterFactory {
+ public static final String XML_STREAM_WRITER_FACTORY_CLASS = "XML_STREAM_WRITER_FACTORY_CLASS";
+
+ public abstract XMLStreamWriter createXMLStreamWriter(Object content) throws XMLStreamException;
+
+ public static XMLStreamWriterFactory create() throws EntityProviderException {
+ String factory = System.getProperty(XML_STREAM_WRITER_FACTORY_CLASS);
+ if (factory != null) {
+ try {
+ Class factoryClass = Class.forName(factory);
+ return (XMLStreamWriterFactory) factoryClass.newInstance();
+ } catch (Exception e) {
+ throw new EntityProviderException(
+ EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getMessage()));
+ }
+ }
+ return new JavaxStaxWriterWrapper();
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/XmlHelperTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/XmlHelperTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/XmlHelperTest.java
deleted file mode 100644
index dc8fb77..0000000
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/XmlHelperTest.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.olingo.odata2.core.commons;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.ep.EntityProvider;
-import org.apache.olingo.odata2.api.ep.EntityProviderException;
-import org.apache.olingo.odata2.api.ep.EntityProviderReadProperties;
-import org.apache.olingo.odata2.testutil.mock.MockFacade;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import com.ctc.wstx.exc.WstxParsingException;
-
-public class XmlHelperTest {
-
- public static String XML =
- "<?xml version=\"1.0\"?>" +
- "<extract>" +
- " <data>&rules;</data>" +
- "</extract>";
-
- public static String XML_XXE =
- "<?xml version=\"1.0\"?>" +
- " <!DOCTYPE foo [" +
- " <!ENTITY rules SYSTEM \"" + XmlHelperTest.class.getResource("/xxe.xml").toString() + "\">" +
- " ]>" +
- "<extract>" +
- " <data>&rules;</data>" +
- "</extract>";
-
- public static String XML_LOL =
- "<?xml version=\"1.0\"?>" +
- " <!DOCTYPE lolz [" +
- " <!ENTITY lol \"lol\">" +
- " <!ELEMENT lolz (#PCDATA)>" +
- " <!ENTITY lol1 \"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;\">" +
- " <!ENTITY lol2 \"&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;\">" +
- " <!ENTITY lol3 \"&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;\">" +
- " <!ENTITY lol4 \"&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;\">" +
- " <!ENTITY lol5 \"&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;\">" +
- " <!ENTITY lol6 \"&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;\">" +
- " <!ENTITY lol7 \"&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;\">" +
- " <!ENTITY lol8 \"&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;\">" +
- " <!ENTITY lol9 \"&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;\">" +
- " ]>" +
- " <lolz>&lol9;</lolz>";
-
- public static String XML_DOCTYPE =
- "<?xml version=\"1.0\" standalone=\"yes\"?>" +
- "<!DOCTYPE hallo [<!ELEMENT hallo (#PCDATA)>]>" +
- "<hallo>Hallo Welt!</hallo>";
-
- public static String XML_PROCESSING =
- "<?xml version=\"1.0\"?>" +
- "<?apache include file=\"somefile.html\" ?>" +
- "<extract>" +
- " <data>&rules;</data>" +
- "</extract>";
-
- @BeforeClass
- public static void beforeClass() {
- // CHECKSTYLE:OFF
- System.setProperty("javax.xml.stream.XMLInputFactory", "com.ctc.wstx.stax.WstxInputFactory"); // NOSONAR
- // CHECKSTYLE:ON
- }
-
- @Test
- public void createReader() throws Exception {
- InputStream content = new ByteArrayInputStream(XML.getBytes("UTF-8"));
- XMLStreamReader streamReader = XmlHelper.createStreamReader(content);
- assertNotNull(streamReader);
- }
-
- @Test
- public void xxeWithoutProtection() throws Exception {
- InputStream content = new ByteArrayInputStream(XML_XXE.getBytes("UTF-8"));
- XMLStreamReader streamReader = createStreamReaderWithExternalEntitySupport(content);
-
- boolean foundExternalEntity = false;
-
- while (streamReader.hasNext()) {
- streamReader.next();
-
- if (streamReader.hasText() && "some text".equals(streamReader.getText())) {
- foundExternalEntity = true;
- break;
- }
-
- }
- assertTrue(foundExternalEntity);
- }
-
- @Test(expected = XMLStreamException.class)
- public void xxeWithProtection() throws Exception {
- InputStream content = new ByteArrayInputStream(XML_XXE.getBytes("UTF-8"));
- XMLStreamReader streamReader = XmlHelper.createStreamReader(content);
-
- while (streamReader.hasNext()) {
- streamReader.next();
- }
- }
-
- public XMLStreamReader createStreamReaderWithExternalEntitySupport(final InputStream content) throws Exception {
- XMLStreamReader streamReader;
- XMLInputFactory factory = XMLInputFactory.newInstance();
- factory.setProperty(XMLInputFactory.IS_VALIDATING, false);
- factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
- factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, true);
- factory.setProperty(XMLInputFactory.SUPPORT_DTD, true);
-
- streamReader = factory.createXMLStreamReader(content, "UTF-8");
- return streamReader;
- }
-
- @Test(expected = XMLStreamException.class)
- public void lolWithProtection() throws Exception {
- InputStream content = new ByteArrayInputStream(XML_LOL.getBytes("UTF-8"));
- XMLStreamReader streamReader = XmlHelper.createStreamReader(content);
-
- while (streamReader.hasNext()) {
- streamReader.next();
- }
- }
-
- @Test
- public void lolApiWithProtection() throws Exception {
- try {
- InputStream content = new ByteArrayInputStream(XML_LOL.getBytes("UTF-8"));
- EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
- EntityProvider.readEntry("application/xml", entitySet, content, EntityProviderReadProperties.init().build());
-
- fail();
- } catch (EntityProviderException e) {
- assertEquals(WstxParsingException.class, e.getCause().getClass());
- }
- }
-
- @Test
- public void xxeApiWithProtection() throws Exception {
- try {
- InputStream content = new ByteArrayInputStream(XML_XXE.getBytes("UTF-8"));
- EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
-
- EntityProvider.readEntry("application/xml", entitySet, content, EntityProviderReadProperties.init().build());
-
- fail();
- } catch (EntityProviderException e) {
- assertEquals(WstxParsingException.class, e.getCause().getClass());
- }
- }
-
- @Test
- public void xmlDoctypeApiWithProtection() throws Exception {
- try {
- InputStream content = new ByteArrayInputStream(XML_DOCTYPE.getBytes("UTF-8"));
- EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
-
- EntityProvider.readEntry("application/xml", entitySet, content, EntityProviderReadProperties.init().build());
-
- fail();
- } catch (EntityProviderException e) {
- assertEquals(WstxParsingException.class, e.getCause().getClass());
- }
- }
-
- @Test
- @Ignore("not way to disable in parser")
- public void xmlProcessingApiWithProtection() throws Exception {
- try {
- InputStream content = new ByteArrayInputStream(XML_PROCESSING.getBytes("UTF-8"));
- EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
-
- EntityProvider.readEntry("application/xml", entitySet, content, EntityProviderReadProperties.init().build());
-
- fail();
- } catch (EntityProviderException e) {
- e.printStackTrace();
- assertEquals(WstxParsingException.class, e.getCause().getClass());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe9e2edc/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/AbstractConsumerTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/AbstractConsumerTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/AbstractConsumerTest.java
index 37a352c..67bcd56 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/AbstractConsumerTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/AbstractConsumerTest.java
@@ -18,20 +18,6 @@
******************************************************************************/
package org.apache.olingo.odata2.core.ep.consumer;
-import static org.junit.Assert.assertNotNull;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringReader;
-import java.io.UnsupportedEncodingException;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.edm.EdmException;
import org.apache.olingo.odata2.api.ep.EntityProviderException;
@@ -39,9 +25,20 @@ import org.apache.olingo.odata2.api.ep.EntityProviderReadProperties;
import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
import org.apache.olingo.odata2.api.ep.feed.ODataFeed;
import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.core.xml.XMLStreamException;
+import org.apache.olingo.odata2.core.xml.XMLStreamReader;
import org.apache.olingo.odata2.testutil.fit.BaseTest;
import org.apache.olingo.odata2.testutil.mock.MockFacade;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertNotNull;
+
/**
*
*/
@@ -50,19 +47,24 @@ public abstract class AbstractConsumerTest extends BaseTest {
protected static final EntityProviderReadProperties DEFAULT_PROPERTIES = EntityProviderReadProperties.init()
.mergeSemantic(false).build();
- protected XMLStreamReader createReaderForTest(final String input) throws XMLStreamException {
+ protected XMLStreamReader createReaderForTest(final String input) throws XMLStreamException, EntityProviderException {
return createReaderForTest(input, false);
}
protected XMLStreamReader createReaderForTest(final String input, final boolean namespaceAware)
- throws XMLStreamException {
- XMLInputFactory factory = XMLInputFactory.newInstance();
- factory.setProperty(XMLInputFactory.IS_VALIDATING, false);
- factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, namespaceAware);
-
- XMLStreamReader streamReader = factory.createXMLStreamReader(new StringReader(input));
-
- return streamReader;
+ throws XMLStreamException, EntityProviderException {
+// XMLInputFactory factory = XMLInputFactory.newInstance();
+// factory.setProperty(XMLInputFactory.IS_VALIDATING, false);
+// factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, namespaceAware);
+//
+// XMLStreamReader streamReader = factory.createXMLStreamWriter(new StringReader(input));
+//
+// return streamReader;
+ if(input == null) {
+ return XMLStreamReader.createXMLStreamReader(null);
+ }
+ return XMLStreamReader.createXMLStreamReader(new ByteArrayInputStream(input.getBytes()));
+// return XMLStreamReader.createXMLStreamWriter(new StringReader(input));
}
protected Map<String, Object> createTypeMappings(final String key, final Object value) {