Author: rwesten
Date: Fri Dec 9 14:24:09 2011
New Revision: 1212436
URL: http://svn.apache.org/viewvc?rev=1212436&view=rev
Log:
* stanbol.css: added a textarea.input template that formats textarea like
typical input in browsers.
* ContextHelper now also internally uses the utility method to get the
BundleContext
* Request: added a .withFormContent(String…values) method
Modified:
incubator/stanbol/trunk/commons/testing/http/src/main/java/org/apache/stanbol/commons/testing/http/Request.java
incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/ContextHelper.java
incubator/stanbol/trunk/commons/web/home/src/main/resources/org/apache/stanbol/commons/web/home/static/style/stanbol.css
Modified:
incubator/stanbol/trunk/commons/testing/http/src/main/java/org/apache/stanbol/commons/testing/http/Request.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/testing/http/src/main/java/org/apache/stanbol/commons/testing/http/Request.java?rev=1212436&r1=1212435&r2=1212436&view=diff
==============================================================================
---
incubator/stanbol/trunk/commons/testing/http/src/main/java/org/apache/stanbol/commons/testing/http/Request.java
(original)
+++
incubator/stanbol/trunk/commons/testing/http/src/main/java/org/apache/stanbol/commons/testing/http/Request.java
Fri Dec 9 14:24:09 2011
@@ -17,6 +17,7 @@
package org.apache.stanbol.commons.testing.http;
import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
@@ -70,7 +71,41 @@ public class Request {
public Request withContent(String content) throws
UnsupportedEncodingException {
return withEntity(new StringEntity(content, "UTF-8"));
}
-
+ /**
+ * Encodes the parsed form content. Strings at even indexes are interpreted
+ * as names. Values are {@link URLEncoder#encode(String, String) url
encoded}.
+ * @param values the [{key-1},{value-1},...,{key-n},{key-n}] values for
the form
+ * @return the Request with the form content added as {@link StringEntity}.
+ * @throws UnsupportedEncodingException if UTF-8 is not supported
+ * @throws IllegalArgumentException if an uneven number of elements are in
the
+ * parsed values or if any parsed key is <code>null</code> or empty.
+ */
+ public Request withFormContent(String...values) throws
UnsupportedEncodingException{
+ if(values == null || values.length == 0){
+ return withContent("");
+ }
+ if((values.length%2) != 0){
+ throw new IllegalArgumentException("The number of values MUST BE
an even number");
+ }
+ StringBuilder content = new StringBuilder();
+ for(int i = 0;i<values.length;i+=2){
+ if(values[i] == null || values[i].isEmpty()){
+ throw new IllegalArgumentException("The name of the '"+(i/2)+
+ "' parameter MUST NOT be NULL nor empty (value='"+
+ values[i+1]+"')!");
+ }
+ if(i > 0){
+ content.append('&');
+ }
+ content.append(values[i]);
+ if(values[i+1] != null && !values[i+1].isEmpty()){
+ content.append('=')
+ .append(URLEncoder.encode(values[i+1], "UTF-8"));
+ }
+
+ }
+ return withContent(content.toString());
+ }
public Request withEntity(HttpEntity e) {
getHttpEntityEnclosingRequestBase().setEntity(e);
return this;
Modified:
incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/ContextHelper.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/ContextHelper.java?rev=1212436&r1=1212435&r2=1212436&view=diff
==============================================================================
---
incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/ContextHelper.java
(original)
+++
incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/ContextHelper.java
Fri Dec 9 14:24:09 2011
@@ -37,7 +37,7 @@ public class ContextHelper {
*/
@SuppressWarnings("unchecked")
public static <T> T getServiceFromContext(Class<T> clazz, ServletContext
context) {
- BundleContext bundleContext = (BundleContext)
context.getAttribute(BundleContext.class.getName());
+ BundleContext bundleContext = getBundleContext(context);
ServiceReference reference =
bundleContext.getServiceReference(clazz.getName());
//TODO: returning the service will cause the service reference not to
be
// released bundleContext.ungetService(reference) will not be called!
Modified:
incubator/stanbol/trunk/commons/web/home/src/main/resources/org/apache/stanbol/commons/web/home/static/style/stanbol.css
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/web/home/src/main/resources/org/apache/stanbol/commons/web/home/static/style/stanbol.css?rev=1212436&r1=1212435&r2=1212436&view=diff
==============================================================================
---
incubator/stanbol/trunk/commons/web/home/src/main/resources/org/apache/stanbol/commons/web/home/static/style/stanbol.css
(original)
+++
incubator/stanbol/trunk/commons/web/home/src/main/resources/org/apache/stanbol/commons/web/home/static/style/stanbol.css
Fri Dec 9 14:24:09 2011
@@ -58,6 +58,11 @@ textarea {
width: 100%;
}
+textarea.input {
+ style="background-color: #fff;
+ border: 2px inset;
+}
+
pre {
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */