You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2017/01/21 23:30:54 UTC

[28/48] incubator-juneau git commit: Rename server and client projects.

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest/src/main/java/org/apache/juneau/rest/labels/NameDescription.java
----------------------------------------------------------------------
diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/labels/NameDescription.java b/juneau-rest/src/main/java/org/apache/juneau/rest/labels/NameDescription.java
new file mode 100644
index 0000000..ab4f598
--- /dev/null
+++ b/juneau-rest/src/main/java/org/apache/juneau/rest/labels/NameDescription.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.juneau.rest.labels;
+
+import org.apache.juneau.annotation.*;
+
+/**
+ * Simple bean with {@code name} and {@code description} properties.
+ * <p>
+ * 	Primarily used for constructing tables with name/description columns on REST OPTIONS requests.
+ */
+@Bean(properties="name,description")
+public class NameDescription {
+
+	private Object name;
+	private Object description;
+
+	/** No-arg constructor.  Used for JUnit testing of OPTIONS pages. */
+	public NameDescription() {}
+
+	/**
+	 * Constructor.
+	 * @param name A name.
+	 * @param description A description.
+	 */
+	public NameDescription(Object name, Object description) {
+		this.name = name;
+		this.description = description;
+	}
+
+	/**
+	 * Returns the name field on this label.
+	 * @return The name.
+	 */
+	public Object getName() {
+		return name;
+	}
+
+	/**
+	 * Sets the name field on this label to a new value.
+	 * @param name The new name.
+	 */
+	public void setName(Object name) {
+		this.name = name;
+	}
+
+	/**
+	 * Returns the description field on this label.
+	 * @return The description.
+	 */
+	public Object getDescription() {
+		return description;
+	}
+
+	/**
+	 * Sets the description field on this label to a new value.
+	 * @param description The new description.
+	 */
+	public void setDescription(Object description) {
+		this.description = description;
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest/src/main/java/org/apache/juneau/rest/labels/ResourceDescription.java
----------------------------------------------------------------------
diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/labels/ResourceDescription.java b/juneau-rest/src/main/java/org/apache/juneau/rest/labels/ResourceDescription.java
new file mode 100644
index 0000000..f99c3c9
--- /dev/null
+++ b/juneau-rest/src/main/java/org/apache/juneau/rest/labels/ResourceDescription.java
@@ -0,0 +1,106 @@
+// ***************************************************************************************************************************
+// * 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.juneau.rest.labels;
+
+import org.apache.juneau.dto.*;
+import org.apache.juneau.rest.*;
+
+/**
+ * Shortcut label for child resources.  Typically used in router resources.
+ *
+ * <h6 class='topic'>Example:</h6>
+ * <p class='bcode'>
+ * 	<jc>// Instead of this...</jc>
+ * 	<jk>new</jk> NameDescription(<jk>new</jk> Link(<js>"httpTool"</js>, uri + <js>"/httpTool"</js>), <js>"HTTP request test client"</js>);
+ *
+ * 	<jc>// ...use this simpler equivalent...</jc>
+ * 	<jk>new</jk> ResourceLink(uri, <js>"httpTool"</js>, <js>"HTTP request test client"</js>);
+ * </p>
+ */
+public final class ResourceDescription extends NameDescription implements Comparable<ResourceDescription> {
+
+	/**
+	 * Constructor.
+	 *
+	 * @param rootUrl The root URI of the child resource (e.g. the URI of the parent resource).
+	 * 		Must not end with <js>'/'</js>.
+	 * 		Must be URL-Encoded.
+	 * @param name The name of the child resource.
+	 * 		This will be URL-encoded and appended onto the root URL to create the hyperlink for the resource.
+	 * @param description The description of the child resource.
+	 */
+	public ResourceDescription(String rootUrl, String name, String description) {
+		super(new Link(name, (rootUrl.equals("/") || rootUrl.isEmpty() ? "/" : rootUrl + "/") + RestUtils.encode(name)), description);
+	}
+
+	/**
+	 * Constructor for resources that are children of a REST resource.
+	 *
+	 * @param req The HTTP request.
+	 * @param childPath The childPath The path of the child resource relative to the servlet.
+	 * @param description The description of the child resource.
+	 */
+	public ResourceDescription(RestRequest req, String childPath, String description) {
+		super(new Link(calcName(childPath), calcHref(req, childPath)), description);
+	}
+
+	private static String calcName(String childPath) {
+		return RestUtils.decode(childPath.indexOf('/') == -1 ? childPath : childPath.substring(childPath.lastIndexOf('/')+1));
+	}
+
+	private static String calcHref(RestRequest req, String childPath) {
+		return req.getServletURIBuilder().append('/').append(childPath).toString();
+	}
+
+	/**
+	 * Constructor.
+	 *
+	 * @param name The name of the child resource.
+	 * @param description The description of the child resource.
+	 */
+	public ResourceDescription(String name, String description) {
+		super(new Link(name, name), description);
+	}
+
+	/** No-arg constructor.  Used for JUnit testing of OPTIONS pages. */
+	public ResourceDescription() {}
+
+	@Override /* NameDescription */
+	public Link getName() {
+		return (Link)super.getName();
+	}
+
+	/**
+	 * Overridden setter.
+	 *
+	 * @param name The new name.
+	 */
+	public void setName(Link name) {
+		super.setName(name);
+	}
+
+	@Override /* Comparable */
+	public int compareTo(ResourceDescription o) {
+		return getName().compareTo(o.getName());
+	}
+
+	@Override /* Object */
+	public boolean equals(Object o) {
+		return (o instanceof ResourceDescription) && ((ResourceDescription)o).getName().equals(getName());
+	}
+
+	@Override /* Object */
+	public int hashCode() {
+		return getName().hashCode();
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest/src/main/java/org/apache/juneau/rest/labels/ResourceLink.java
----------------------------------------------------------------------
diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/labels/ResourceLink.java b/juneau-rest/src/main/java/org/apache/juneau/rest/labels/ResourceLink.java
new file mode 100644
index 0000000..4c3e234
--- /dev/null
+++ b/juneau-rest/src/main/java/org/apache/juneau/rest/labels/ResourceLink.java
@@ -0,0 +1,66 @@
+// ***************************************************************************************************************************
+// * 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.juneau.rest.labels;
+
+import java.text.*;
+
+import org.apache.juneau.dto.*;
+import org.apache.juneau.rest.*;
+
+/**
+ * A simple link to a child of a parent resource.
+ */
+public class ResourceLink extends Link {
+
+	/**
+	 * Constructor.
+	 *
+	 * @param req The HTTP request from the parent resource.
+	 * @param childPath The child resource path.
+	 * @param args Optional {@link MessageFormat}-style arguments in the child path.
+	 */
+	public ResourceLink(RestRequest req, String childPath, Object...args) {
+		super(getName(getPath(childPath,args)), getHref(req, getPath(childPath,args)));
+	}
+
+	/**
+	 * Constructor.
+	 *
+	 * @param label The label for the link.
+	 * @param req The HTTP request from the parent resource.
+	 * @param childPath The child resource path.
+	 * @param args Optional {@link MessageFormat}-style arguments in the child path.
+	 */
+	public ResourceLink(String label, RestRequest req, String childPath, Object...args) {
+		super(label, getHref(req, getPath(childPath,args)));
+	}
+
+	private static String getName(String childPath) {
+		String s = childPath;
+		if (childPath.indexOf('/') == -1)
+			s = childPath;
+		else
+			s = childPath.substring(childPath.lastIndexOf('/')+1);
+		return RestUtils.decode(s);
+	}
+
+	private static String getHref(RestRequest req, String childPath) {
+		return req.getServletURIBuilder().append('/').append(childPath).toString();
+	}
+
+	private static String getPath(String childPath, Object...args) {
+		if (args.length > 0)
+			childPath = MessageFormat.format(childPath, args);
+		return childPath;
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest/src/main/java/org/apache/juneau/rest/labels/package.html
----------------------------------------------------------------------
diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/labels/package.html b/juneau-rest/src/main/java/org/apache/juneau/rest/labels/package.html
new file mode 100644
index 0000000..4e03390
--- /dev/null
+++ b/juneau-rest/src/main/java/org/apache/juneau/rest/labels/package.html
@@ -0,0 +1,41 @@
+<!DOCTYPE HTML>
+<!--
+/***************************************************************************************************************************
+ * 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.
+ *
+ ***************************************************************************************************************************/
+ -->
+<html>
+<head>
+	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+	<style type="text/css">
+		/* For viewing in Page Designer */
+		@IMPORT url("../../../../javadoc.css");
+
+		/* For viewing in REST interface */
+		@IMPORT url("../htdocs/javadoc.css");
+		body { 
+			margin: 20px; 
+		}	
+	</style>
+	<script>
+		/* Replace all @code and @link tags. */	
+		window.onload = function() {
+			document.body.innerHTML = document.body.innerHTML.replace(/\{\@code ([^\}]+)\}/g, '<code>$1</code>');
+			document.body.innerHTML = document.body.innerHTML.replace(/\{\@link (([^\}]+)\.)?([^\.\}]+)\}/g, '<code>$3</code>');
+		}
+	</script>
+</head>
+<body>
+<p>Various REST interface label classes</p>
+</body>
+</html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest/src/main/java/org/apache/juneau/rest/matchers/MultipartFormDataMatcher.java
----------------------------------------------------------------------
diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/matchers/MultipartFormDataMatcher.java b/juneau-rest/src/main/java/org/apache/juneau/rest/matchers/MultipartFormDataMatcher.java
new file mode 100644
index 0000000..a27d0f1
--- /dev/null
+++ b/juneau-rest/src/main/java/org/apache/juneau/rest/matchers/MultipartFormDataMatcher.java
@@ -0,0 +1,26 @@
+// ***************************************************************************************************************************
+// * 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.juneau.rest.matchers;
+
+import org.apache.juneau.rest.*;
+
+/**
+ * Predefined matcher for matching requests with content type <js>"multipart/form-data"</js>.
+ */
+public class MultipartFormDataMatcher extends RestMatcher {
+	@Override /* RestMatcher */
+	public boolean matches(RestRequest req) {
+		String contentType = req.getContentType();
+		return contentType != null && contentType.startsWith("multipart/form-data"); //$NON-NLS-1$
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest/src/main/java/org/apache/juneau/rest/matchers/UrlEncodedFormMatcher.java
----------------------------------------------------------------------
diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/matchers/UrlEncodedFormMatcher.java b/juneau-rest/src/main/java/org/apache/juneau/rest/matchers/UrlEncodedFormMatcher.java
new file mode 100644
index 0000000..6a39db6
--- /dev/null
+++ b/juneau-rest/src/main/java/org/apache/juneau/rest/matchers/UrlEncodedFormMatcher.java
@@ -0,0 +1,26 @@
+// ***************************************************************************************************************************
+// * 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.juneau.rest.matchers;
+
+import org.apache.juneau.rest.*;
+
+/**
+ * Predefined matcher for matching requests with content type <js>"application/x-www-form-urlencoded"</js>.
+ */
+public class UrlEncodedFormMatcher extends RestMatcher {
+	@Override /* RestMatcher */
+	public boolean matches(RestRequest req) {
+		String contentType = req.getContentType();
+		return contentType != null && contentType.equals("application/x-www-form-urlencoded"); //$NON-NLS-1$
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest/src/main/java/org/apache/juneau/rest/matchers/package.html
----------------------------------------------------------------------
diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/matchers/package.html b/juneau-rest/src/main/java/org/apache/juneau/rest/matchers/package.html
new file mode 100644
index 0000000..7eacf3a
--- /dev/null
+++ b/juneau-rest/src/main/java/org/apache/juneau/rest/matchers/package.html
@@ -0,0 +1,34 @@
+<!DOCTYPE HTML>
+<!--
+/***************************************************************************************************************************
+ * 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.
+ *
+ ***************************************************************************************************************************/
+ -->
+<html>
+<head>
+	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+	<style type="text/css">
+		/* For viewing in Page Designer */
+		@IMPORT url("../../../../../javadoc.css");
+
+		/* For viewing in REST interface */
+		@IMPORT url("../htdocs/javadoc.css");
+		body { 
+			margin: 20px; 
+		}	
+	</style>
+</head>
+<body>
+<p>Predefined Matchers</p>
+</body>
+</html>
\ No newline at end of file