You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ko...@apache.org on 2014/02/18 09:21:28 UTC
[3/6] [OLINGO-63] Uri Parser: add percent decoding
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8a63a58/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceLambdaAllImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceLambdaAllImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceLambdaAllImpl.java
new file mode 100644
index 0000000..6d4cd76
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceLambdaAllImpl.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * 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.odata4.server.core.uri.apiimpl;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmProperty;
+import org.apache.olingo.odata4.commons.api.edm.EdmType;
+import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
+import org.apache.olingo.odata4.server.api.uri.UriResourceKind;
+import org.apache.olingo.odata4.server.api.uri.UriResourceLambdaAll;
+import org.apache.olingo.odata4.server.api.uri.queryoption.expression.Expression;
+import org.apache.olingo.odata4.server.core.uri.queryoption.expression.ExpressionImpl;
+
+public class UriResourceLambdaAllImpl extends UriResourceTypedImpl implements UriResourceLambdaAll {
+ protected EdmProperty property;
+ private String lamdaVariable;
+ private ExpressionImpl expression;
+
+ public UriResourceLambdaAllImpl() {
+ super(UriResourceKind.lambdaAll);
+ }
+
+ @Override
+ public EdmType getType() {
+ return EdmPrimitiveTypeKind.Boolean.getEdmPrimitiveTypeInstance();
+ }
+
+ @Override
+ public boolean isCollection() {
+ return false;
+ }
+
+ @Override
+ public String getLamdaVariable() {
+ return lamdaVariable;
+ }
+
+ public UriResourceLambdaAllImpl setLamdaVariable(final String lamdaVariable) {
+ this.lamdaVariable = lamdaVariable;
+ return this;
+ };
+
+ @Override
+ public Expression getExpression() {
+ return expression;
+ }
+
+ public UriResourceLambdaAllImpl setExpression(final ExpressionImpl expression) {
+ this.expression = expression;
+ return this;
+ };
+
+ @Override
+ public String toString() {
+ return "all";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8a63a58/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceLambdaAnyImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceLambdaAnyImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceLambdaAnyImpl.java
new file mode 100644
index 0000000..d67bc77
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceLambdaAnyImpl.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.odata4.server.core.uri.apiimpl;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmProperty;
+import org.apache.olingo.odata4.commons.api.edm.EdmType;
+import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
+import org.apache.olingo.odata4.server.api.uri.UriResourceKind;
+import org.apache.olingo.odata4.server.api.uri.UriResourceLambdaAny;
+import org.apache.olingo.odata4.server.api.uri.queryoption.expression.Expression;
+import org.apache.olingo.odata4.server.core.uri.queryoption.expression.ExpressionImpl;
+
+public class UriResourceLambdaAnyImpl extends UriResourceTypedImpl implements UriResourceLambdaAny {
+ protected EdmProperty property;
+ private String lamdaVariable;
+ private ExpressionImpl expression;
+
+ public UriResourceLambdaAnyImpl() {
+ super(UriResourceKind.lambdaAny);
+ }
+
+ @Override
+ public EdmType getType() {
+ return EdmPrimitiveTypeKind.Boolean.getEdmPrimitiveTypeInstance();
+ }
+
+ @Override
+ public boolean isCollection() {
+ return false;
+ }
+
+ @Override
+ public String getLamdaVariable() {
+ return lamdaVariable;
+ }
+
+ public UriResourceLambdaAnyImpl setLamdaVariable(final String lamdaVariable) {
+ this.lamdaVariable = lamdaVariable;
+ return this;
+ };
+
+ @Override
+ public Expression getExpression() {
+ return expression;
+ }
+
+ public UriResourceLambdaAnyImpl setExpression(final ExpressionImpl expression) {
+ this.expression = expression;
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return "any";
+ };
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8a63a58/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceLambdaVarImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceLambdaVarImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceLambdaVarImpl.java
new file mode 100644
index 0000000..87d0d6e
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceLambdaVarImpl.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * 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.odata4.server.core.uri.apiimpl;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmType;
+import org.apache.olingo.odata4.server.api.uri.UriResourceKind;
+import org.apache.olingo.odata4.server.api.uri.UriResourceLambdaRef;
+
+public class UriResourceLambdaVarImpl extends UriResourceTypedImpl implements UriResourceLambdaRef {
+
+ private EdmType type;
+ private boolean isCollection;
+ private String variableText;
+
+ public UriResourceLambdaVarImpl() {
+ super(UriResourceKind.lambdaVariable);
+ }
+
+ @Override
+ public String getVariableText() {
+ return variableText;
+ }
+
+ public UriResourceLambdaVarImpl setVariableText(final String variableText) {
+ this.variableText = variableText;
+ return this;
+ }
+
+ @Override
+ public EdmType getType() {
+ return type;
+ }
+
+ public UriResourceLambdaVarImpl setType(final EdmType type) {
+ this.type = type;
+ return this;
+
+ }
+
+ @Override
+ public boolean isCollection() {
+ return isCollection;
+ }
+
+ public UriResourceLambdaVarImpl setCollection(final boolean isCollection) {
+ this.isCollection = isCollection;
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return variableText;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8a63a58/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceNavigationPropertyImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceNavigationPropertyImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceNavigationPropertyImpl.java
new file mode 100644
index 0000000..0530e1b
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceNavigationPropertyImpl.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * 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.odata4.server.core.uri.apiimpl;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata4.commons.api.edm.EdmType;
+import org.apache.olingo.odata4.server.api.uri.UriResourceKind;
+import org.apache.olingo.odata4.server.api.uri.UriResourceNavigation;
+
+public class UriResourceNavigationPropertyImpl extends UriResourceWithKeysImpl implements UriResourceNavigation {
+
+ protected EdmNavigationProperty navigationProperty;
+
+ public UriResourceNavigationPropertyImpl() {
+ super(UriResourceKind.navigationProperty);
+ }
+
+ @Override
+ public EdmNavigationProperty getProperty() {
+ return navigationProperty;
+ }
+
+ public UriResourceNavigationPropertyImpl setNavigationProperty(final EdmNavigationProperty property) {
+ navigationProperty = property;
+ return this;
+
+ }
+
+ @Override
+ public EdmType getType() {
+ return navigationProperty.getType();
+ }
+
+ @Override
+ public boolean isCollection() {
+ if (keyPredicates != null) {
+ return false;
+ }
+ return navigationProperty.isCollection();
+ }
+
+ @Override
+ public String toString() {
+ return navigationProperty.getName();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8a63a58/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourcePrimitivePropertyImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourcePrimitivePropertyImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourcePrimitivePropertyImpl.java
new file mode 100644
index 0000000..ade9929
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourcePrimitivePropertyImpl.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * 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.odata4.server.core.uri.apiimpl;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmProperty;
+import org.apache.olingo.odata4.commons.api.edm.EdmType;
+import org.apache.olingo.odata4.server.api.uri.UriResourceKind;
+import org.apache.olingo.odata4.server.api.uri.UriResourcePrimitiveProperty;
+
+public class UriResourcePrimitivePropertyImpl extends UriResourceTypedImpl implements UriResourcePrimitiveProperty {
+
+ EdmProperty property;
+
+ public UriResourcePrimitivePropertyImpl() {
+ super(UriResourceKind.primitiveProperty);
+ }
+
+ @Override
+ public EdmProperty getProperty() {
+ return property;
+ }
+
+ public UriResourcePrimitivePropertyImpl setProperty(final EdmProperty property) {
+ this.property = property;
+ return this;
+ }
+
+ @Override
+ public EdmType getType() {
+ return property.getType();
+ }
+
+ @Override
+ public boolean isCollection() {
+ return property.isCollection();
+ }
+
+ @Override
+ public String toString() {
+ return property.getName();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8a63a58/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceRefImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceRefImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceRefImpl.java
new file mode 100644
index 0000000..5f39a87
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceRefImpl.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.odata4.server.core.uri.apiimpl;
+
+import org.apache.olingo.odata4.server.api.uri.UriResourceKind;
+import org.apache.olingo.odata4.server.api.uri.UriResourceRef;
+
+public class UriResourceRefImpl extends UriResourceImpl implements UriResourceRef {
+
+ public UriResourceRefImpl() {
+ super(UriResourceKind.ref);
+
+ }
+
+ @Override
+ public String toString() {
+ return "$ref";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8a63a58/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceRootImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceRootImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceRootImpl.java
new file mode 100644
index 0000000..66c7da3
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceRootImpl.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * 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.odata4.server.core.uri.apiimpl;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmType;
+import org.apache.olingo.odata4.server.api.uri.UriResourceKind;
+import org.apache.olingo.odata4.server.api.uri.UriResourceRoot;
+
+public class UriResourceRootImpl extends UriResourceWithKeysImpl implements UriResourceRoot {
+
+ private EdmType type;
+ private boolean isCollection;
+
+ public UriResourceRootImpl() {
+ super(UriResourceKind.root);
+ }
+
+ @Override
+ public EdmType getType() {
+ return type;
+ }
+
+ public UriResourceRootImpl setType(final EdmType type) {
+ this.type = type;
+ return this;
+ }
+
+ @Override
+ public boolean isCollection() {
+ if (keyPredicates != null) {
+ return false;
+ }
+ return isCollection;
+ }
+
+ public UriResourceRootImpl setCollection(final boolean isCollection) {
+ this.isCollection = isCollection;
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return "$root";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8a63a58/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceSingletonImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceSingletonImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceSingletonImpl.java
new file mode 100644
index 0000000..d05e772
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceSingletonImpl.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * 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.odata4.server.core.uri.apiimpl;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmEntityType;
+import org.apache.olingo.odata4.commons.api.edm.EdmSingleton;
+import org.apache.olingo.odata4.commons.api.edm.EdmType;
+import org.apache.olingo.odata4.server.api.uri.UriResourceKind;
+import org.apache.olingo.odata4.server.api.uri.UriResourceSingleton;
+
+public class UriResourceSingletonImpl extends UriResourceTypedImpl implements UriResourceSingleton {
+
+ private EdmSingleton singleton;
+
+ public UriResourceSingletonImpl() {
+ super(UriResourceKind.singleton);
+ }
+
+ @Override
+ public EdmSingleton getSingleton() {
+ return singleton;
+ }
+
+ public UriResourceSingletonImpl setSingleton(final EdmSingleton singleton) {
+
+ this.singleton = singleton;
+ return this;
+ }
+
+ @Override
+ public EdmEntityType getEntityTypeFilter() {
+ return (EdmEntityType) typeFilter;
+ }
+
+ @Override
+ public EdmType getType() {
+ return singleton.getEntityType();
+ }
+
+ @Override
+ public EdmEntityType getEntityType() {
+ return singleton.getEntityType();
+ }
+
+ @Override
+ public boolean isCollection() {
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return singleton.getName();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8a63a58/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceStartingTypeFilterImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceStartingTypeFilterImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceStartingTypeFilterImpl.java
new file mode 100644
index 0000000..b1781de
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceStartingTypeFilterImpl.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * 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.odata4.server.core.uri.apiimpl;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmType;
+import org.apache.olingo.odata4.server.api.uri.UriResourceKind;
+import org.apache.olingo.odata4.server.api.uri.UriResourceStartingTypeFilter;
+
+public class UriResourceStartingTypeFilterImpl extends UriResourceWithKeysImpl
+ implements UriResourceStartingTypeFilter {
+
+ private EdmType type;
+ private boolean isCollection;
+
+ public UriResourceStartingTypeFilterImpl() {
+ super(UriResourceKind.startingTypeFilter);
+ }
+
+ @Override
+ public UriResourceKind getKind() {
+ return kind;
+ }
+
+ @Override
+ public EdmType getType() {
+ return type;
+ }
+
+ public UriResourceStartingTypeFilterImpl setType(final EdmType type) {
+ this.type = type;
+ return this;
+ }
+
+ @Override
+ public boolean isCollection() {
+ if (keyPredicates != null) {
+ return false;
+ }
+ return isCollection;
+ }
+
+ public UriResourceStartingTypeFilterImpl setCollection(final boolean isCollection) {
+ this.isCollection = isCollection;
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return type.getNamespace() + "." + type.getName();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8a63a58/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceTypedImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceTypedImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceTypedImpl.java
new file mode 100644
index 0000000..10330f3
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceTypedImpl.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * 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.odata4.server.core.uri.apiimpl;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmStructuralType;
+import org.apache.olingo.odata4.commons.api.edm.EdmType;
+import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
+import org.apache.olingo.odata4.server.api.uri.UriResourceKind;
+import org.apache.olingo.odata4.server.api.uri.UriResourcePartTyped;
+
+public abstract class UriResourceTypedImpl extends UriResourceImpl implements UriResourcePartTyped {
+
+ protected EdmType typeFilter = null;
+
+ public UriResourceTypedImpl(final UriResourceKind kind) {
+ super(kind);
+ }
+
+ public EdmType getTypeFilter() {
+ return typeFilter;
+ }
+
+ public UriResourceTypedImpl setTypeFilter(final EdmStructuralType typeFilter) {
+ this.typeFilter = typeFilter;
+ return this;
+ }
+
+ @Override
+ public String toString(final boolean includeFilters) {
+ if (includeFilters) {
+ if (typeFilter != null) {
+ return toString() + "/" + getFQN(typeFilter).toString();
+ } else {
+ return toString();
+ }
+ }
+ return toString();
+ }
+
+ private FullQualifiedName getFQN(final EdmType type) {
+ return new FullQualifiedName(type.getNamespace(), type.getName());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8a63a58/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceValueImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceValueImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceValueImpl.java
new file mode 100644
index 0000000..2377ff8
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceValueImpl.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.odata4.server.core.uri.apiimpl;
+
+import org.apache.olingo.odata4.server.api.uri.UriResourceKind;
+import org.apache.olingo.odata4.server.api.uri.UriResourceValue;
+
+public class UriResourceValueImpl extends UriResourceImpl implements UriResourceValue {
+
+ public UriResourceValueImpl() {
+ super(UriResourceKind.value);
+
+ }
+
+ @Override
+ public String toString() {
+ return "$value";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8a63a58/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceWithKeysImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceWithKeysImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceWithKeysImpl.java
new file mode 100644
index 0000000..66c3867
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/apiimpl/UriResourceWithKeysImpl.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * 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.odata4.server.core.uri.apiimpl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmType;
+import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
+import org.apache.olingo.odata4.server.api.uri.UriParameter;
+import org.apache.olingo.odata4.server.api.uri.UriResourceKind;
+import org.apache.olingo.odata4.server.api.uri.UriResourcePartTyped;
+
+public abstract class UriResourceWithKeysImpl extends UriResourceImpl implements UriResourcePartTyped {
+
+ protected EdmType collectionTypeFilter = null;
+ protected List<UriParameterImpl> keyPredicates = null;
+ protected EdmType entryTypeFilter = null;
+
+ public UriResourceWithKeysImpl(final UriResourceKind kind) {
+ super(kind);
+ }
+
+ public EdmType getTypeFilterOnCollection() {
+ return collectionTypeFilter;
+ }
+
+ public EdmType getTypeFilterOnEntry() {
+ return entryTypeFilter;
+ }
+
+ public List<UriParameter> getKeyPredicates() {
+ List<UriParameter> retList = new ArrayList<UriParameter>();
+ for (UriParameterImpl item : keyPredicates) {
+ retList.add(item);
+ }
+ return retList;
+ }
+
+ public UriResourceWithKeysImpl setKeyPredicates(final List<UriParameterImpl> list) {
+ keyPredicates = list;
+ return this;
+ }
+
+ public UriResourceWithKeysImpl setEntryTypeFilter(final EdmType entryTypeFilter) {
+ this.entryTypeFilter = entryTypeFilter;
+ return this;
+ }
+
+ public UriResourceWithKeysImpl setCollectionTypeFilter(final EdmType collectionTypeFilter) {
+ this.collectionTypeFilter = collectionTypeFilter;
+ return this;
+ }
+
+ public String toString(final boolean includeFilters) {
+
+ if (includeFilters == true) {
+ String tmp = "";
+ if (collectionTypeFilter != null) {
+ tmp += getFQN(collectionTypeFilter).toString();
+ }
+
+ if (entryTypeFilter != null) {
+ if (tmp.length() == 0) {
+ tmp = getFQN(entryTypeFilter).toString();
+ } else {
+ tmp += "/()" + getFQN(entryTypeFilter).toString();
+ }
+ }
+ if (tmp.length() != 0) {
+ return toString() + "/" + tmp;
+ }
+ }
+
+ return toString();
+ }
+
+ private FullQualifiedName getFQN(final EdmType type) {
+ return new FullQualifiedName(type.getNamespace(), type.getName());
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8a63a58/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/parser/Parser.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/parser/Parser.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/parser/Parser.java
new file mode 100644
index 0000000..ad1b2de
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/parser/Parser.java
@@ -0,0 +1,450 @@
+/*******************************************************************************
+ * 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.odata4.server.core.uri.parser;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.antlr.v4.runtime.ANTLRInputStream;
+import org.antlr.v4.runtime.BailErrorStrategy;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.antlr.v4.runtime.ParserRuleContext;
+import org.antlr.v4.runtime.Token;
+import org.antlr.v4.runtime.atn.PredictionMode;
+import org.antlr.v4.runtime.misc.ParseCancellationException;
+import org.apache.olingo.odata4.commons.api.edm.Edm;
+import org.apache.olingo.odata4.server.api.uri.UriInfo;
+import org.apache.olingo.odata4.server.api.uri.UriInfoKind;
+import org.apache.olingo.odata4.server.api.uri.UriResource;
+import org.apache.olingo.odata4.server.api.uri.UriResourcePartTyped;
+import org.apache.olingo.odata4.server.core.uri.UriParserException;
+import org.apache.olingo.odata4.server.core.uri.UriParserSyntaxException;
+import org.apache.olingo.odata4.server.core.uri.antlr.UriLexer;
+import org.apache.olingo.odata4.server.core.uri.antlr.UriParserParser;
+import org.apache.olingo.odata4.server.core.uri.antlr.UriParserParser.*;
+import org.apache.olingo.odata4.server.core.uri.apiimpl.UriInfoImpl;
+import org.apache.olingo.odata4.server.core.uri.apiimpl.UriResourceImpl;
+import org.apache.olingo.odata4.server.core.uri.queryoption.CustomQueryOptionImpl;
+import org.apache.olingo.odata4.server.core.uri.queryoption.ExpandOptionImpl;
+import org.apache.olingo.odata4.server.core.uri.queryoption.FilterOptionImpl;
+import org.apache.olingo.odata4.server.core.uri.queryoption.FormatOptionImpl;
+import org.apache.olingo.odata4.server.core.uri.queryoption.IdOptionImpl;
+import org.apache.olingo.odata4.server.core.uri.queryoption.InlineCountOptionImpl;
+import org.apache.olingo.odata4.server.core.uri.queryoption.LevelsOptionImpl;
+import org.apache.olingo.odata4.server.core.uri.queryoption.OrderByOptionImpl;
+import org.apache.olingo.odata4.server.core.uri.queryoption.SelectOptionImpl;
+import org.apache.olingo.odata4.server.core.uri.queryoption.SkipOptionImpl;
+import org.apache.olingo.odata4.server.core.uri.queryoption.SkipTokenOptionImpl;
+import org.apache.olingo.odata4.server.core.uri.queryoption.TopOptionImpl;
+
+public class Parser {
+ int logLevel = 0;
+
+ private enum ParserEntryRules {
+ All, Batch, CrossJoin, Entity, ExpandItems, FilterExpression, Metadata, PathSegment, Orderby, Select
+ };
+
+ public Parser setLogLevel(int logLevel) {
+ this.logLevel = logLevel;
+ return this;
+ }
+
+ public UriInfo parseUri(final String input, Edm edm)
+ throws UriParserException {
+
+ boolean readQueryParameter = false;
+ boolean readFragment = false;
+
+ UriContext context = new UriContext();
+ UriParseTreeVisitor uriParseTreeVisitor = new UriParseTreeVisitor(edm,context );
+
+ try {
+ RawUri uri = UriDecoder.decodeUri(input, 0); // -> 0 segments are before the service url
+
+ // first, read the decoded path segments
+ String firstSegment = "";
+ if (uri.pathSegmentListDecoded.size() > 0) {
+ firstSegment = uri.pathSegmentListDecoded.get(0);
+ }
+
+ if (firstSegment.startsWith("$batch")) {
+ BatchEOFContext ctxBatchEOF =
+ (BatchEOFContext) parseRule(uri.pathSegmentListDecoded.get(0), ParserEntryRules.Batch);
+
+ uriParseTreeVisitor.visitBatchEOF(ctxBatchEOF);
+ } else if (firstSegment.startsWith("$metadata")) {
+ MetadataEOFContext ctxMetadataEOF =
+ (MetadataEOFContext) parseRule(uri.pathSegmentListDecoded.get(0), ParserEntryRules.Metadata);
+
+ uriParseTreeVisitor.visitMetadataEOF(ctxMetadataEOF);
+ readQueryParameter = true;
+ readFragment = true;
+ } else if (firstSegment.startsWith("$entity")) {
+
+ context.contextUriInfo = new UriInfoImpl().setKind(UriInfoKind.entityId);
+ if (uri.pathSegmentListDecoded.size() > 1) {
+ EntityEOFContext ctxEntityEOF =
+ (EntityEOFContext) parseRule(uri.pathSegmentListDecoded.get(1), ParserEntryRules.Entity);
+ uriParseTreeVisitor.visitEntityEOF(ctxEntityEOF);
+
+ }
+ readQueryParameter = true;
+
+ } else if (firstSegment.startsWith("$all")) {
+ AllEOFContext ctxResourcePathEOF =
+ (AllEOFContext) parseRule(uri.pathSegmentListDecoded.get(0), ParserEntryRules.All);
+
+ uriParseTreeVisitor.visitAllEOF(ctxResourcePathEOF);
+ readQueryParameter = true;
+ } else if (firstSegment.startsWith("$crossjoin")) {
+ CrossjoinEOFContext ctxResourcePathEOF =
+ (CrossjoinEOFContext) parseRule(uri.pathSegmentListDecoded.get(0), ParserEntryRules.CrossJoin);
+
+ uriParseTreeVisitor.visitCrossjoinEOF(ctxResourcePathEOF);
+ readQueryParameter = true;
+ } else {
+ List<PathSegmentEOFContext> ctxPathSegments = new ArrayList<PathSegmentEOFContext>();
+ for (String pathSegment : uri.pathSegmentListDecoded) {
+ PathSegmentEOFContext ctxPathSegment =
+ (PathSegmentEOFContext) parseRule(pathSegment, ParserEntryRules.PathSegment);
+ ctxPathSegments.add(ctxPathSegment);
+ }
+
+ context.contextUriInfo = new UriInfoImpl().setKind(UriInfoKind.resource);
+
+ for (PathSegmentEOFContext ctxPathSegment : ctxPathSegments) {
+ // add checks for batcvh entity metadata, all crossjsoin
+ uriParseTreeVisitor.visitPathSegmentEOF(ctxPathSegment);
+ }
+
+ UriResource lastSegment = context.contextUriInfo.getLastResourcePart();
+ if (lastSegment instanceof UriResourcePartTyped) {
+ UriResourcePartTyped typed = (UriResourcePartTyped) lastSegment;
+
+ UriParseTreeVisitor.TypeInformation myType = uriParseTreeVisitor.getTypeInformation((UriResourceImpl) typed);
+ UriParseTreeVisitor.TypeInformation typeInfo =
+ uriParseTreeVisitor.new TypeInformation(myType.type, typed.isCollection());
+ context.contextTypes.push(typeInfo);
+
+ }
+
+ readQueryParameter = true;
+
+ }
+
+ if (readQueryParameter) {
+ // second, read the simple systemQueryOptions and the Custom QueryOptions
+ for (RawUri.QueryOption option : uri.queryOptionListDecoded) {
+ if (!option.name.startsWith("$")) {
+ CustomQueryOptionImpl customOption = new CustomQueryOptionImpl();
+ customOption.setName(option.name);
+ customOption.setText(option.value);
+ context.contextUriInfo.addCustomQueryOption(customOption);
+ } else if (option.name.equals("$filter")) {
+ FilterExpressionEOFContext ctxFilterExpression =
+ (FilterExpressionEOFContext) parseRule(option.value, ParserEntryRules.FilterExpression);
+
+ FilterOptionImpl filterOption =
+ (FilterOptionImpl) uriParseTreeVisitor.visitFilterExpressionEOF(ctxFilterExpression);
+
+ context.contextUriInfo.setSystemQueryOption(filterOption);
+
+ } else if (option.name.equals("$format")) {
+ FormatOptionImpl formatOption = new FormatOptionImpl();
+ formatOption.setName(option.name);
+ formatOption.setText(option.value);
+ formatOption.setFormat(option.value);
+ context.contextUriInfo.setSystemQueryOption(formatOption);
+
+ } else if (option.name.equals("$expand")) {
+ ExpandItemsEOFContext ctxExpandItems =
+ (ExpandItemsEOFContext) parseRule(option.value, ParserEntryRules.ExpandItems);
+
+ ExpandOptionImpl expandOption =
+ (ExpandOptionImpl) uriParseTreeVisitor.visitExpandItemsEOF(ctxExpandItems);
+
+ context.contextUriInfo.setSystemQueryOption(expandOption);
+
+ } else if (option.name.equals("$id")) {
+ IdOptionImpl idOption = new IdOptionImpl();
+ idOption.setName(option.name);
+ idOption.setText(option.value);
+ idOption.setValue(option.value);
+ context.contextUriInfo.setSystemQueryOption(idOption);
+ } else if (option.name.equals("$inlinecount")) {
+ InlineCountOptionImpl inlineCountOption = new InlineCountOptionImpl();
+ inlineCountOption.setName(option.name);
+ inlineCountOption.setText(option.value);
+ inlineCountOption.setValue(option.value.equals("true") ? true : false);
+ context.contextUriInfo.setSystemQueryOption(inlineCountOption);
+ } else if (option.name.equals("$orderby")) {
+ OrderByEOFContext ctxFilterExpression =
+ (OrderByEOFContext) parseRule(option.value, ParserEntryRules.Orderby);
+
+ OrderByOptionImpl filterOption =
+ (OrderByOptionImpl) uriParseTreeVisitor.visitOrderByEOF(ctxFilterExpression);
+
+ context.contextUriInfo.setSystemQueryOption(filterOption);
+ } else if (option.name.equals("$search")) {
+ // TODO not supported yet
+ } else if (option.name.equals("$select")) {
+ SelectEOFContext ctxSelectEOF =
+ (SelectEOFContext) parseRule(option.value, ParserEntryRules.Select);
+
+ SelectOptionImpl expandOption =
+ (SelectOptionImpl) uriParseTreeVisitor.visitSelectEOF(ctxSelectEOF);
+
+ context.contextUriInfo.setSystemQueryOption(expandOption);
+ } else if (option.name.equals("$skip")) {
+ SkipOptionImpl inlineCountOption = new SkipOptionImpl();
+ inlineCountOption.setName(option.name);
+ inlineCountOption.setText(option.value);
+ inlineCountOption.setValue(option.value);
+ context.contextUriInfo.setSystemQueryOption(inlineCountOption);
+ } else if (option.name.equals("$skiptoken")) {
+ SkipTokenOptionImpl inlineCountOption = new SkipTokenOptionImpl();
+ inlineCountOption.setName(option.name);
+ inlineCountOption.setText(option.value);
+ inlineCountOption.setValue(option.value);
+ context.contextUriInfo.setSystemQueryOption(inlineCountOption);
+ } else if (option.name.equals("$top")) {
+ TopOptionImpl inlineCountOption = new TopOptionImpl();
+ inlineCountOption.setName(option.name);
+ inlineCountOption.setText(option.value);
+ inlineCountOption.setValue(option.value);
+ context.contextUriInfo.setSystemQueryOption(inlineCountOption);
+ } else if (option.name.equals("$count")) {
+ // todo create CountOption
+ InlineCountOptionImpl inlineCountOption = new InlineCountOptionImpl();
+ inlineCountOption.setName(option.name);
+ inlineCountOption.setText(option.value);
+ inlineCountOption.setValue(option.value.equals("true") ? true : false);
+ context.contextUriInfo.setSystemQueryOption(inlineCountOption);
+ } else if (option.name.equals("$level")) {
+ LevelsOptionImpl inlineCountOption = new LevelsOptionImpl();
+ inlineCountOption.setName(option.name);
+ inlineCountOption.setText(option.value);
+ if (option.value.equals("max")) {
+ inlineCountOption.setMax();
+ } else {
+ inlineCountOption.setLevel(Integer.parseInt(option.value));
+ }
+
+ context.contextUriInfo.setSystemQueryOption(inlineCountOption);
+ }
+
+ }
+ }
+
+ if (readFragment) {
+ context.contextUriInfo.setFragment(uri.fragment);
+ }
+
+ return context.contextUriInfo;
+ } catch (ParseCancellationException e) {
+ Throwable cause = e.getCause();
+ if (cause instanceof UriParserException) {
+ throw (UriParserException) cause;
+ }
+ }
+ return null;
+ }
+
+ private ParserRuleContext parseRule(final String input, ParserEntryRules entryPoint)
+ throws UriParserSyntaxException {
+ UriParserParser parser = null;
+ UriLexer lexer = null;
+ ParserRuleContext ret = null;
+
+ // Use 2 stage approach to improve performance
+ // see https://github.com/antlr/antlr4/issues/192
+
+ // stage = 1
+ try {
+
+ // create parser
+ if (logLevel > 0) {
+ lexer = new UriLexer(new ANTLRInputStream(input));
+ showTokens(input, lexer.getAllTokens());
+ }
+
+ lexer = new UriLexer(new ANTLRInputStream(input));
+ parser = new UriParserParser(new CommonTokenStream(lexer));
+
+ // Set error strategy
+ addStage1ErrorStategy(parser);
+
+ // Set error collector
+ addStage1ErrorListener(parser);
+
+ // user the faster LL parsing
+ parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
+
+ // parse
+ switch (entryPoint) {
+ case All:
+ ret = parser.allEOF();
+ break;
+ case Batch:
+ ret = parser.batchEOF();
+ break;
+ case CrossJoin:
+ ret = parser.crossjoinEOF();
+ break;
+ case Metadata:
+ ret = parser.metadataEOF();
+ break;
+ case PathSegment:
+ ret = parser.pathSegmentEOF();
+ break;
+ case FilterExpression:
+ lexer.mode(UriLexer.DEFAULT_MODE);
+ ret = parser.filterExpressionEOF();
+ break;
+ case Orderby:
+ lexer.mode(UriLexer.DEFAULT_MODE);
+ ret = parser.orderByEOF();
+ break;
+ case ExpandItems:
+ lexer.mode(UriLexer.DEFAULT_MODE);
+ ret = parser.expandItemsEOF();
+ break;
+ case Entity:
+ ret = parser.entityEOF();
+ break;
+ case Select:
+ ret = parser.selectEOF();
+ break;
+ default:
+ break;
+
+ }
+
+ } catch (ParseCancellationException hardException) {
+ // stage = 2
+ try {
+
+ // create parser
+ lexer = new UriLexer(new ANTLRInputStream(input));
+ parser = new UriParserParser(new CommonTokenStream(lexer));
+
+ // Set error strategy
+ addStage2ErrorStategy(parser);
+
+ // Set error collector
+ addStage2ErrorListener(parser);
+
+ // Use the slower SLL parsing
+ parser.getInterpreter().setPredictionMode(PredictionMode.LL);
+
+ // parse
+ switch (entryPoint) {
+ case All:
+ ret = parser.allEOF();
+ break;
+ case Batch:
+ ret = parser.batchEOF();
+ break;
+ case CrossJoin:
+ ret = parser.crossjoinEOF();
+ break;
+ case Metadata:
+ ret = parser.metadataEOF();
+ break;
+ case PathSegment:
+ ret = parser.pathSegmentEOF();
+ break;
+ case FilterExpression:
+ lexer.mode(UriLexer.DEFAULT_MODE);
+ ret = parser.filterExpressionEOF();
+ break;
+ case Orderby:
+ lexer.mode(UriLexer.DEFAULT_MODE);
+ ret = parser.orderByEOF();
+ break;
+ case ExpandItems:
+ lexer.mode(UriLexer.DEFAULT_MODE);
+ ret = parser.expandItemsEOF();
+ break;
+ case Entity:
+ ret = parser.entityEOF();
+ break;
+ case Select:
+ ret = parser.selectEOF();
+ break;
+ default:
+ break;
+ }
+
+ } catch (Exception weakException) {
+ throw new UriParserSyntaxException("Error in syntax", weakException);
+
+ // exceptionOnStage = 2;
+ }
+ } catch (Exception hardException) {
+ throw new UriParserSyntaxException("Error in syntax", hardException);
+ }
+
+ return ret;
+ }
+
+ protected void addStage1ErrorStategy(UriParserParser parser) {
+ // Throw exception at first syntax error
+ parser.setErrorHandler(new BailErrorStrategy());
+
+ }
+
+ protected void addStage2ErrorStategy(UriParserParser parser) {
+ // Throw exception at first syntax error
+ parser.setErrorHandler(new BailErrorStrategy());
+ }
+
+ protected void addStage1ErrorListener(UriParserParser parser) {
+ // No error logging to System.out or System.err, only exceptions used (depending on ErrorStrategy)
+ parser.removeErrorListeners();
+ }
+
+ protected void addStage2ErrorListener(UriParserParser parser) {
+ // No error logging to System.out or System.err, only exceptions used (depending on ErrorStrategy)
+ parser.removeErrorListeners();
+ }
+
+ public void showTokens(String input, List<? extends Token> list) {
+ boolean first = true;
+ System.out.println("input: " + input);
+ String nL = "\n";
+ String out = "[" + nL;
+ for (Token token : list) {
+ if (!first) {
+ out += ",";
+ first = false;
+ }
+ int index = token.getType();
+ if (index != -1) {
+ out += "\"" + token.getText() + "\"" + " " + UriLexer.tokenNames[index] + nL;
+ } else {
+ out += "\"" + token.getText() + "\"" + " " + index + nL;
+ }
+ }
+ out += ']';
+ System.out.println("tokens: " + out);
+ return;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8a63a58/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/parser/RawUri.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/parser/RawUri.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/parser/RawUri.java
new file mode 100644
index 0000000..a4d93c1
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/parser/RawUri.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * 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.odata4.server.core.uri.parser;
+
+import java.util.List;
+
+public class RawUri {
+ public String uri;
+ public String sheme;
+ public String authority;
+ public String path;
+ public String queryOptionString;
+ public String fragment;
+ public List<QueryOption> queryOptionList;
+ public List<QueryOption> queryOptionListDecoded;
+
+ public List<String> pathSegmentList;
+ public List<String> pathSegmentListDecoded;
+
+ public static class QueryOption {
+ public String name;
+ public String value;
+
+ QueryOption(String name, String value) {
+ this.name = name;
+ this.value = value;
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8a63a58/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/parser/UriContext.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/parser/UriContext.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/parser/UriContext.java
new file mode 100644
index 0000000..52f9cf2
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/parser/UriContext.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * 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.odata4.server.core.uri.parser;
+
+import java.util.Stack;
+
+import org.apache.olingo.odata4.commons.api.edm.Edm;
+import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.odata4.commons.api.edm.EdmType;
+import org.apache.olingo.odata4.server.core.uri.apiimpl.UriInfoImpl;
+import org.apache.olingo.odata4.server.core.uri.parser.UriParseTreeVisitor.TypeInformation;
+import org.apache.olingo.odata4.server.core.uri.queryoption.ExpandItemImpl;
+import org.apache.olingo.odata4.server.core.uri.queryoption.SelectItemImpl;
+
+public class UriContext {
+
+ public static class LambdaVariables {
+ public boolean isCollection;
+ public String name;
+ public EdmType type;
+ }
+
+
+ /**
+ * Hold all currently allowed lambda variables
+ * As lambda functions can be nested there may be more than one allowed lambda variables at a time while parsing a
+ * $filter or $orderby expressions.
+ */
+ public Stack<LambdaVariables> allowedLambdaVariables;
+ /**
+ * Used to stack type information for nested $expand, $filter query options and other cases.
+ */
+ public Stack<TypeInformation> contextTypes;
+ /**
+ * Set within method {@link #visitExpandItem(ExpandPathContext ctx)} and {@link #visitExpandPathExtension(final
+ * ExpandPathExtensionContext ctx)} to allow nodes
+ * deeper in the expand tree at {@link #visitExpandPathExtension(ExpandPathExtensionContext ctx)} appending path
+ * segments to the currently processed {@link ExpandItemImpl}.
+ */
+ public ExpandItemImpl contextExpandItemPath;
+ /**
+ * Set within method {@link #visitSelectItem(SelectItemContext ctx)} to allow nodes
+ * deeper in the expand tree at {@link #visitSelectSegment(SelectSegmentContext ctx)} appending path segments to the
+ * currently processed {@link SelectItemImpl}.
+ */
+ public SelectItemImpl contextSelectItem;
+ /**
+ * Stores the currently processed UriInfo objects. There is one URI Info object for the resource path
+ * and one for each new first member access within $filter and $orderBy options.
+ */
+ public UriInfoImpl contextUriInfo;
+ public boolean contextReadingFunctionParameters;
+
+ public UriContext() {
+
+ this.contextExpandItemPath = null;
+ this.contextReadingFunctionParameters = false;
+ this.contextSelectItem = null;
+ this.contextTypes = new Stack<UriParseTreeVisitor.TypeInformation>();
+ this.allowedLambdaVariables = new Stack<UriContext.LambdaVariables>();
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8a63a58/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/parser/UriDecoder.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/parser/UriDecoder.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/parser/UriDecoder.java
new file mode 100644
index 0000000..28876c2
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/parser/UriDecoder.java
@@ -0,0 +1,140 @@
+/*******************************************************************************
+ * 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.odata4.server.core.uri.parser;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.olingo.odata4.server.core.uri.UriParserSyntaxException;
+import org.apache.olingo.odata4.server.core.uri.parser.RawUri.QueryOption;
+
+public class UriDecoder {
+
+ static Pattern uriPattern = Pattern.compile("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?");
+
+ public static RawUri decodeUri(String uri, int scipSegments) throws UriParserSyntaxException {
+ RawUri rawUri = new RawUri();
+
+ Matcher m = uriPattern.matcher(uri);
+ if (m.matches()) {
+ rawUri.sheme = m.group(2);
+ rawUri.authority = m.group(4);
+ rawUri.path = m.group(5);
+ rawUri.queryOptionString = m.group(7);
+ rawUri.fragment = m.group(9);
+ }
+
+ splittPath(rawUri, scipSegments);
+ splittOptions(rawUri);
+ decode(rawUri);
+
+ return rawUri;
+ }
+
+ private static void decode(RawUri rawUri) throws UriParserSyntaxException {
+ rawUri.pathSegmentListDecoded = new ArrayList<String>();
+ for ( String segment: rawUri.pathSegmentList) {
+ rawUri.pathSegmentListDecoded.add(decode(segment));
+ }
+
+ rawUri.queryOptionListDecoded = new ArrayList<QueryOption>();
+ for ( QueryOption optionPair: rawUri.queryOptionList) {
+ rawUri.queryOptionListDecoded.add(new QueryOption(
+ decode(optionPair.name),
+ decode(optionPair.value)));
+ }
+ }
+
+ private static void splittOptions(RawUri rawUri) {
+ rawUri.queryOptionList = new ArrayList<RawUri.QueryOption>();
+
+ if (rawUri.queryOptionString == null) {
+ return;
+ }
+
+ List<String> options = splitt(rawUri.queryOptionString, '&');
+
+ for (String option : options) {
+ if (option.length() != 0) {
+ List<String> pair = splittFirst(option, '=');
+ rawUri.queryOptionList.add(
+ new RawUri.QueryOption(pair.get(0), pair.get(1)));
+ }
+ }
+ }
+
+ private static List<String> splittFirst(String input, char c) {
+ int pos = input.indexOf(c, 0);
+ if (pos >= 0) {
+ return Arrays.asList(input.substring(0, pos), input.substring(pos + 1));
+ } else {
+ return Arrays.asList(input, "");
+ }
+ }
+
+ public static void splittPath(RawUri rawUri, int scipSegments) {
+ List<String> list = splitt(rawUri.path, '/');
+
+ if (list.size() > 0) {
+ if (list.get(0).length() == 0) {
+ scipSegments++;
+ }
+ }
+
+ if (scipSegments > 0) {
+ rawUri.pathSegmentList = list.subList(scipSegments, list.size());
+ } else {
+ rawUri.pathSegmentList = list;
+ }
+ }
+
+ public static List<String> splitt(String input, char c) {
+
+ List<String> list = new LinkedList<String>();
+
+ int start = 0;
+ int end = -1;
+
+ while ((end = input.indexOf(c, start)) >= 0) {
+ list.add(input.substring(start, end));
+ start = end + 1;
+ }
+
+ if (end == -1) {
+ list.add(input.substring(start));
+ }
+
+ return list;
+ }
+
+ public static String decode(String encoded) throws UriParserSyntaxException {
+ try {
+ return URLDecoder.decode(encoded, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new UriParserSyntaxException("Error while decoding");
+ }
+ }
+
+}