You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by kn...@apache.org on 2008/11/16 23:50:44 UTC
svn commit: r718135 - in
/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket:
request/ request/handler/impl/ request/handler/resource/ resource/
Author: knopp
Date: Sun Nov 16 14:50:43 2008
New Revision: 718135
URL: http://svn.apache.org/viewvc?rev=718135&view=rev
Log:
resources... kinda
Added:
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/handler/resource/
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/handler/resource/ResourceRequestHandler.java (with props)
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/resource/
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/resource/Resource.java (with props)
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/resource/ResourceReference.java (with props)
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/resource/ResourceReferenceRegistry.java (with props)
Modified:
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/handler/impl/RenderPageRequestHandler.java
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/url-format.txt
Modified: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/handler/impl/RenderPageRequestHandler.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/handler/impl/RenderPageRequestHandler.java?rev=718135&r1=718134&r2=718135&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/handler/impl/RenderPageRequestHandler.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/handler/impl/RenderPageRequestHandler.java Sun Nov 16 14:50:43 2008
@@ -144,6 +144,11 @@
return null;
}
+ protected void storeBufferedResponse(Url url, BufferedWebResponse response)
+ {
+ // TODO:
+ }
+
/**
* Renders page to a {@link BufferedWebResponse}. All URLs in page will be rendered relative to
* <code>targetUrl</code>
@@ -184,11 +189,6 @@
}
}
- protected void storeBufferedResponse(Url url, BufferedWebResponse response)
- {
- // TODO:
- }
-
private void redirectTo(Url url, RequestCycle requestCycle)
{
WebResponse response = (WebResponse)requestCycle.getResponse();
Added: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/handler/resource/ResourceRequestHandler.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/handler/resource/ResourceRequestHandler.java?rev=718135&view=auto
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/handler/resource/ResourceRequestHandler.java (added)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/handler/resource/ResourceRequestHandler.java Sun Nov 16 14:50:43 2008
@@ -0,0 +1,69 @@
+/*
+ * 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._wicket.request.handler.resource;
+
+import java.util.Locale;
+
+import org.apache._wicket.PageParameters;
+import org.apache._wicket.RequestCycle;
+import org.apache._wicket.request.RequestHandler;
+import org.apache._wicket.resource.Resource;
+
+/**
+ * Request handler that renders a resource.
+ *
+ * @author Matej Knopp
+ */
+public class ResourceRequestHandler implements RequestHandler
+{
+ private final Resource resource;
+ private final Locale locale;
+ private final String style;
+ private final PageParameters pageParameters;
+
+ /**
+ * Construct.
+ *
+ * @param resource
+ * @param locale
+ * @param style
+ * @param pageParameters
+ */
+ public ResourceRequestHandler(Resource resource, Locale locale, String style,
+ PageParameters pageParameters)
+ {
+ if (resource == null)
+ {
+ throw new IllegalArgumentException("Argument 'resource' may not be null.");
+ }
+ this.resource = resource;
+ this.locale = locale;
+ this.style = style;
+ this.pageParameters = pageParameters != null ? pageParameters : new PageParameters();
+ }
+
+ public void respond(RequestCycle requestCycle)
+ {
+ Resource.Attributes a = new Resource.Attributes(requestCycle.getRequest(),
+ requestCycle.getResponse(), locale, style, pageParameters);
+ resource.respond(a);
+ }
+
+ public void detach(RequestCycle requestCycle)
+ {
+ }
+}
Propchange: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/handler/resource/ResourceRequestHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/url-format.txt
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/url-format.txt?rev=718135&r1=718134&r2=718135&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/url-format.txt (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/url-format.txt Sun Nov 16 14:50:43 2008
@@ -63,3 +63,10 @@
mount path can also contain parameter placeholders
e.g. when mount path is /foo/${bar}/baz and the incomming url is /foo/abc/baz the extracted page parameters will
contain named parameter bar="abc".
+
+RESOURCES
+---------
+/wicket/resource/org.apache.wicket.ResourceScope/resource/path.xyz?en_EN-style
+/mounted/resource?en_EN-style
+/mounted/resource/with/locale/and/style
+
Added: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/resource/Resource.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/resource/Resource.java?rev=718135&view=auto
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/resource/Resource.java (added)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/resource/Resource.java Sun Nov 16 14:50:43 2008
@@ -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._wicket.resource;
+
+import java.io.Serializable;
+import java.util.Locale;
+
+import org.apache._wicket.PageParameters;
+import org.apache._wicket.request.handler.resource.ResourceRequestHandler;
+import org.apache._wicket.request.request.Request;
+import org.apache._wicket.request.response.Response;
+
+/**
+ * Resource is an object capable of writing output to response.
+ *
+ * @author Matej Knopp
+ */
+public interface Resource extends Serializable
+{
+ /**
+ * Attributes that are provided to resource in the {@link Resource#respond(Attributes)}
+ * method. Attributes are set by the {@link ResourceRequestHandler}.
+ *
+ * @author Matej Knopp
+ */
+ public static class Attributes
+ {
+ private final Request request;
+ private final Response response;
+ private final Locale locale;
+ private final String style;
+ private final PageParameters parameters;
+
+ /**
+ * Construct.
+ *
+ * @param request
+ *
+ * @param response
+ * @param locale
+ * @param style
+ * @param parameters
+ */
+ public Attributes(Request request, Response response, Locale locale, String style,
+ PageParameters parameters)
+ {
+ if (request == null)
+ {
+ throw new IllegalArgumentException("Argument 'request' may not be null.");
+ }
+ if (response == null)
+ {
+ throw new IllegalArgumentException("Argument 'response' may not be null.");
+ }
+ if (locale == null)
+ {
+ throw new IllegalArgumentException("Argument 'locale' may not be null.");
+ }
+ this.request = request;
+ this.response = response;
+ this.locale = locale;
+ this.style = style;
+ this.parameters = parameters;
+ }
+
+ /**
+ * Returns current request.
+ *
+ * @return current request
+ */
+ public Request getRequest()
+ {
+ return request;
+ }
+
+ /**
+ * Returns current response. The resource must write output to the response.
+ *
+ * @return response
+ */
+ public Response getResponse()
+ {
+ return response;
+ }
+
+ /**
+ * Returns requested locale. The locale is never null.
+ *
+ * @return locale
+ */
+ public Locale getLocale()
+ {
+ return locale;
+ }
+
+ /**
+ * If specified returns requested style. The style is optional.
+ *
+ * @return style or <code>null</code>
+ */
+ public String getStyle()
+ {
+ return style;
+ }
+
+ /**
+ * Returns additional parameters extracted from the request. If resource is mounted,
+ * this method returns all (indexed and query) parameters after the mount path.
+ * For non mounted global resources this method will only return the query parameters.
+ * For component specific resources the behavior depends on the component.
+ *
+ * @return page parameters or <code>null</code>
+ */
+ public PageParameters getParameters()
+ {
+ return parameters;
+ }
+ };
+
+ /**
+ * Renders this resource to response using the provided attributes.
+ *
+ * @param attributes
+ */
+ public void respond(Attributes attributes);
+}
Propchange: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/resource/Resource.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/resource/ResourceReference.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/resource/ResourceReference.java?rev=718135&view=auto
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/resource/ResourceReference.java (added)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/resource/ResourceReference.java Sun Nov 16 14:50:43 2008
@@ -0,0 +1,100 @@
+/*
+ * 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._wicket.resource;
+
+import java.util.Locale;
+
+import org.apache.wicket.util.lang.Classes;
+
+/**
+ * Reference to a resource. Can be used to reference global resources.
+ *
+ * @author Matej Knopp
+ */
+public abstract class ResourceReference
+{
+ private final String scope;
+ private final String path;
+ private final Locale locale;
+ private String style;
+
+ /**
+ * Creates new {@link ResourceReference} instance.
+ *
+ * @param scope
+ * mandatory parameter
+ * @param path
+ * mandatory parameter
+ * @param locale
+ * @param style
+ */
+ public ResourceReference(Class<?> scope, String path, Locale locale, String style)
+ {
+ if (scope == null)
+ {
+ throw new IllegalArgumentException("Argument 'scope' can not be null.");
+ }
+ this.scope = scope.getName();
+
+ if (path == null)
+ {
+ throw new IllegalArgumentException("Argument 'path' can not be null.");
+ }
+ this.path = path;
+ this.locale = locale;
+ this.style = style;
+ }
+
+ /**
+ * @return path
+ */
+ public String getPath()
+ {
+ return path;
+ }
+
+ /**
+ * @return scope
+ */
+ public Class<?> getScope()
+ {
+ return Classes.resolveClass(scope);
+ }
+
+ /**
+ * @return locale
+ */
+ public Locale getLocale()
+ {
+ return locale;
+ }
+
+ /**
+ * @return style
+ */
+ public String getStyle()
+ {
+ return style;
+ }
+
+ /**
+ * Creates new resource.
+ *
+ * @return new resource instance
+ */
+ public abstract Resource getResource();
+}
Propchange: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/resource/ResourceReference.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/resource/ResourceReferenceRegistry.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/resource/ResourceReferenceRegistry.java?rev=718135&view=auto
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/resource/ResourceReferenceRegistry.java (added)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/resource/ResourceReferenceRegistry.java Sun Nov 16 14:50:43 2008
@@ -0,0 +1,149 @@
+/*
+ * 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._wicket.resource;
+
+import java.util.Locale;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.wicket.util.lang.Objects;
+
+/**
+ * Allows to register and lookup {@link ResourceReference}s.
+ *
+ * @author Matej Knopp
+ */
+public class ResourceReferenceRegistry
+{
+ private static class Key
+ {
+ private final String scope;
+ private final String path;
+ private final Locale locale;
+ private final String style;
+
+ public Key(String scope, String path, Locale locale, String style)
+ {
+ if (scope == null)
+ {
+ throw new IllegalArgumentException("Argument 'scope' can not be null.");
+ }
+ this.scope = scope.toString();
+
+ if (path == null)
+ {
+ throw new IllegalArgumentException("Argument 'path' can not be null.");
+ }
+ this.path = path;
+ this.locale = locale;
+ this.style = style;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj instanceof Key)
+ {
+ return false;
+ }
+ Key that = (Key)obj;
+ return Objects.equal(scope, that.scope) && //
+ Objects.equal(path, that.path) && //
+ Objects.equal(locale, that.locale) && //
+ Objects.equal(style, that.style);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Objects.hashCode(scope, path, locale, style);
+ }
+ };
+
+ private static Map<Key, ResourceReference> map = new ConcurrentHashMap<Key, ResourceReference>();
+
+ /**
+ * Registers the given {@link ResourceReference}.
+ *
+ * @param reference
+ */
+ public void registerResourceReference(ResourceReference reference)
+ {
+ if (reference == null)
+ {
+ throw new IllegalArgumentException("Argument 'reference' may not be null.");
+ }
+ Key key = new Key(reference.getScope().getName(), reference.getPath(),
+ reference.getLocale(), reference.getStyle());
+ map.put(key, reference);
+ }
+
+ /**
+ * Looks up resource reference with specified attributes. If the reference is not found and
+ * <code>strict</code> is set to <code>false</code>, result of
+ * {@link #createDefaultResourceReference(Class, String, Locale, String)} is returned.
+ *
+ * @param scope
+ * mandatory parameter
+ * @param name
+ * mandatory parameter
+ * @param locale
+ * @param style
+ * @param strict
+ * if <code>strict</code> is <code>true</code> only resources that match exactly
+ * are returened. Otherwise if there is no resource registered that is an exact
+ * match, also resources with <code>null</code> style and locale are tried. If
+ * still no resource is found, result of
+ * {@link #createDefaultResourceReference(Class, String, Locale, String)} is
+ * returned.
+ * @return {@link ResourceReference} or <code>null</code>
+ */
+ public ResourceReference getResourceReference(Class<?> scope, String name, Locale locale,
+ String style, boolean strict)
+ {
+ Key key = new Key(scope.getName(), name, locale, style);
+ ResourceReference res = map.get(key);
+ if (strict || res != null)
+ {
+ return res;
+ }
+ else
+ {
+ res = getResourceReference(scope, name, locale, null, true);
+ if (res == null)
+ {
+ res = getResourceReference(scope, name, null, null, true);
+ }
+ if (res == null)
+ {
+ res = createDefaultResourceReference(scope, name, locale, style);
+ }
+ return res;
+ }
+ }
+
+ protected ResourceReference createDefaultResourceReference(Class<?> scope, String name,
+ Locale locale, String style)
+ {
+ // override in superclass to e.g. return PackageResourceReference if there is one
+ return null;
+ }
+}
Propchange: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/resource/ResourceReferenceRegistry.java
------------------------------------------------------------------------------
svn:mime-type = text/plain