You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/02/24 22:34:02 UTC
[isis] 03/07: ISIS-1880 Internal API: introduce _Resource for
storing application scoped parameters
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
commit ed46579232ae58b089768dc35dcb418257891ad3
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sat Feb 24 23:24:35 2018 +0100
ISIS-1880 Internal API: introduce _Resource for storing application
scoped parameters
---
.../isis/applib/internal/resources/_Resource.java | 80 ++++++++++++++++++++++
.../internal/resources/_Resource_ContextPath.java | 43 ++++++++++++
.../applib/internal/resources/_Resource_Path.java | 62 +++++++++++++++++
.../internal/resources/_Resource_RestfulPath.java | 43 ++++++++++++
.../applib/internal/resources/package-info.java | 28 ++++++++
5 files changed, 256 insertions(+)
diff --git a/core/applib/src/main/java/org/apache/isis/applib/internal/resources/_Resource.java b/core/applib/src/main/java/org/apache/isis/applib/internal/resources/_Resource.java
new file mode 100644
index 0000000..8ba3ad9
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/internal/resources/_Resource.java
@@ -0,0 +1,80 @@
+/*
+ * 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.isis.applib.internal.resources;
+
+import org.apache.isis.applib.internal.context._Context;
+
+/**
+ * <h1>- internal use only -</h1>
+ * <p>
+ * Utilities for storing and locating resources.
+ * </p>
+ * <p>
+ * <b>WARNING</b>: Do <b>NOT</b> use any of the classes provided by this package! <br/>
+ * These may be changed or removed without notice!
+ * </p>
+ * @since 2.0.0
+ */
+public final class _Resource {
+
+ // -- CONTEXT PATH RESOURCE
+
+ public final static String getContextPathIfAny() {
+ final _Resource_ContextPath resource = _Context.getIfAny(_Resource_ContextPath.class);
+ return resource!=null ? resource.getContextPath() : null;
+ }
+
+ public final static void putContextPath(String contextPath) {
+ _Context.put(_Resource_ContextPath.class, new _Resource_ContextPath(contextPath), false);
+ }
+
+ public final static String prependContextPathIfPresent(String path) {
+
+ if(path==null) {
+ return null;
+ }
+
+ final String contextPath = getContextPathIfAny();
+
+ if(contextPath==null) {
+ return path;
+ }
+
+ if(!path.startsWith("/")) {
+ return contextPath + "/" + path;
+ } else {
+ return "/" + contextPath + path;
+ }
+ }
+
+ // -- RESTFUL PATH RESOURCE
+
+ public final static String getRestfulPathIfAny() {
+ final _Resource_RestfulPath resource = _Context.getIfAny(_Resource_RestfulPath.class);
+ return resource!=null ? resource.getRestfulPath() : null;
+ }
+
+ public final static void putRestfulPath(String restfulPath) {
+ _Context.put(_Resource_RestfulPath.class, new _Resource_RestfulPath(restfulPath), false);
+ }
+
+ // --
+
+}
diff --git a/core/applib/src/main/java/org/apache/isis/applib/internal/resources/_Resource_ContextPath.java b/core/applib/src/main/java/org/apache/isis/applib/internal/resources/_Resource_ContextPath.java
new file mode 100644
index 0000000..7a722f5
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/internal/resources/_Resource_ContextPath.java
@@ -0,0 +1,43 @@
+/*
+ * 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.isis.applib.internal.resources;
+
+/**
+ *
+ * package private helper class to store application scoped context-path (if any)
+ *
+ */
+class _Resource_ContextPath extends _Resource_Path {
+
+ public _Resource_ContextPath(String contextPath) {
+ super(contextPath);
+ }
+
+ public String getContextPath() {
+ return path;
+ }
+
+ @Override
+ protected String resourceName() {
+ return "context-path";
+ }
+
+}
diff --git a/core/applib/src/main/java/org/apache/isis/applib/internal/resources/_Resource_Path.java b/core/applib/src/main/java/org/apache/isis/applib/internal/resources/_Resource_Path.java
new file mode 100644
index 0000000..abd19de
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/internal/resources/_Resource_Path.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.isis.applib.internal.resources;
+
+import org.apache.isis.applib.internal.base._Strings;
+
+/**
+ *
+ * package private abstract helper class to store application scoped path objects
+ *
+ */
+abstract class _Resource_Path {
+
+ protected final String path;
+
+ protected abstract String resourceName();
+
+ public _Resource_Path(String contextPath) {
+
+ if(_Strings.isEmpty(contextPath))
+ throw new IllegalArgumentException(resourceName()+" can not be empty");
+
+ contextPath = contextPath.trim();
+
+ if(_Strings.isEmpty(contextPath))
+ throw new IllegalArgumentException(resourceName()+" can not be empty");
+
+ while(contextPath.startsWith("/")) {
+ contextPath = contextPath.substring(1);
+ }
+
+ while(contextPath.endsWith("/")) {
+ contextPath = contextPath.substring(0, contextPath.length()-1);
+ }
+
+ contextPath = _Strings.condenseWhitespaces(contextPath, " ");
+
+ if(contextPath.indexOf(' ')>-1)
+ throw new IllegalArgumentException(resourceName()+" can not contain any white-spaces");
+
+ this.path = contextPath;
+ }
+
+}
diff --git a/core/applib/src/main/java/org/apache/isis/applib/internal/resources/_Resource_RestfulPath.java b/core/applib/src/main/java/org/apache/isis/applib/internal/resources/_Resource_RestfulPath.java
new file mode 100644
index 0000000..e5fb3d9
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/internal/resources/_Resource_RestfulPath.java
@@ -0,0 +1,43 @@
+/*
+ * 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.isis.applib.internal.resources;
+
+/**
+ *
+ * package private helper class to store application scoped context-path (if any)
+ *
+ */
+class _Resource_RestfulPath extends _Resource_Path {
+
+ public _Resource_RestfulPath(String contextPath) {
+ super(contextPath);
+ }
+
+ public String getRestfulPath() {
+ return path;
+ }
+
+ @Override
+ protected String resourceName() {
+ return "restful-path";
+ }
+
+}
diff --git a/core/applib/src/main/java/org/apache/isis/applib/internal/resources/package-info.java b/core/applib/src/main/java/org/apache/isis/applib/internal/resources/package-info.java
new file mode 100644
index 0000000..a6e3073
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/internal/resources/package-info.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.
+ */
+/**
+ * <h1>Internal API</h1>
+ * Internal classes, contributing to the internal proprietary API.
+ * These may be changed or removed without notice!
+ * <p>
+ * <b>WARNING</b>:
+ * Do NOT use any of the classes provided by this package!
+ * </p>
+ */
+package org.apache.isis.applib.internal.resources;
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
ahuber@apache.org.